DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Tutorial] Adjusting HUD display for scores over a million
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Andy_Nonymous
Moderator
<B>Moderator</B>


Joined: 02 Apr 2003
Last Visit: 17 Feb 2015

Topics: 99
Posts: 589
Location: New Jersey, USA
usa.gif

PostPosted: Sat Jan 05, 2013 5:22 am
   Subject: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

Have you ever played an old mod where the score goes over a million but the display on the HUD rolls over to zero? Even though the final score is recorded correctly in High Scores, we'd like to see it in the HUD too, without making it look unbalanced. This tutorial assumes the original status bar is being used.

Note: A much better solution than this was posted below by Chris on 23 August.

All the changes/additions go in WL_AGENT.CPP and are in blue.

For starters, let's define a new function:
::: CODE :::
void StatusDrawPic (unsigned x, unsigned y, unsigned picnum)
{
    LatchDrawPicScaledCoord ((screenWidth-scaleFactor*320)/16 + scaleFactor*x,
        screenHeight-scaleFactor*(STATUSLINES-y),picnum);
}

void StatusDrawPic2 (unsigned x, unsigned y, unsigned picnum) // Adjust score for 1,000,000+
{
    LatchDrawPicScaledCoord ((screenWidth-scaleFactor*320)/16 + scaleFactor*x+1,
        screenHeight-scaleFactor*(STATUSLINES-y),picnum);
}

void StatusDrawFace(unsigned picnum)

Right below the LatchNumber function, add this new one:
::: CODE :::
/*
===============
=
= LatchNumber2     // Adjusts score alignment when it goes over a million
=
= right justifies and pads with blanks
=
===============
*/

static void LatchNumber2 (int x, int y, unsigned width, int32_t number)
{
    unsigned length,c;
    char    str[20];

    ltoa (number,str,10);

    length = (unsigned) strlen (str);

    while (length<width)
    {
        StatusDrawPic2 (x,y,N_BLANKPIC);
        x++;
        width--;
    }

    c = length <= width ? 0 : length-width;

    while (c<length)
    {
        StatusDrawPic2 (x,y,str[c]-'0'+ N_0PIC);
        x++;
        c++;
    }
}


Finally, make use of this in the DrawScore routine:
::: CODE :::
void DrawScore (void)
{
    if(viewsize == 21 && ingame) return;

    if (gamestate.score >= 1000000)               
        LatchNumber2 (5,16,7,gamestate.score);
    else

        LatchNumber (6,16,6,gamestate.score);
}

The score appears as always until you hit the million mark, at which point the extra digit is added and the whole score field is centered properly.

Andy


Last edited by Andy_Nonymous on Mon Aug 26, 2013 7:15 am; edited 1 time in total
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 18 Jul 2018

Topics: 55
Posts: 2135
Location: Canada
blank.gif

PostPosted: Sat Jan 05, 2013 5:54 am
   Subject: Re: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Great idea! Even in the original wolf3d and spear you could go over 1 million points, I remember the first time it happening to me as a kid in Episode 2 (which did display all 7 numbers in wolf3d v1.1 but they started going off the status bar). I've never been able to get it to look good in Dos without making the status bar longer though. Do you have a screenshot of this? Maybe I'll try it out later.
Andy_Nonymous
Moderator
<B>Moderator</B>


Joined: 02 Apr 2003
Last Visit: 17 Feb 2015

Topics: 99
Posts: 589
Location: New Jersey, USA
usa.gif

PostPosted: Sat Jan 05, 2013 6:39 am
   Subject: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Andy_Nonymous
Moderator
<B>Moderator</B>


Joined: 02 Apr 2003
Last Visit: 17 Feb 2015

Topics: 99
Posts: 589
Location: New Jersey, USA
usa.gif

PostPosted: Fri Apr 12, 2013 3:22 pm
   Subject: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

There's a possibility of being killed soon after going over a million points, and when the game restarts, your score is less than a million. The leading one and trailing zero are still displayed with the current score superimposed over them.

To get rid of this mess, we'll reset/refresh the score before the level begins.

Note: A better solution than this was posted on 13 July below.

Note: A much better solution than this was posted below by Chris on 23 August.

Added/changed code is blue.

In WL_DEF.H:
::: CODE :::
void    DrawScore (void);
void    ResetScore (void);
void    DrawWeapon (void);

In WL_GAME.CPP:
::: CODE :::
restartgame:
    ClearMemory ();
    SETFONTCOLOR(0,15);
    VW_FadeOut();
    DrawPlayScreen ();
    died = false;
    do
    {
        if (!loadedgame)
            gamestate.score = gamestate.oldscore;
        if(!died || viewsize != 21)
        {
            ResetScore();
            DrawScore();
        }

        startgame = false;

In WL_AGENT.CPP, I altered LatchNumber2 to write all blanks when called by ResetScore().

Under DrawScore, place this new function:
::: CODE :::
/*
===============
=
= ResetScore
=
===============
*/

void ResetScore (void)
{
    if(viewsize == 21 && ingame) return;

        LatchNumber2 (5,16,77,0);
}

And the update to LatchNumber2:
::: CODE :::
static void LatchNumber2 (int x, int y, unsigned width, int32_t number)
{
    unsigned length,c;
    char    str[20];

    if (width == 77)
    {
        while (width>70)
        {
            StatusDrawPic2 (x,y,N_BLANKPIC);
            x++;
            width--;
        }
        return;
    }


    ltoa (number,str,10);

This code feels dirty to me, but it works.

If you design your own HUD this is all unnecessary! Razz

Andy


Last edited by Andy_Nonymous on Mon Aug 26, 2013 7:16 am; edited 3 times in total
Soldat 555
Guest



Last Visit:





PostPosted: Wed Apr 24, 2013 4:44 pm
   Subject: Re: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Question... Doesn't changing this...
::: CODE :::
void DrawScore (void)
{
    if(viewsize == 21 && ingame) return;
    LatchNumber (6,16,6,gamestate.score);
}

To this...
::: CODE :::
void DrawScore (void)
{
    if(viewsize == 21 && ingame) return;
    LatchNumber (6,16,7,gamestate.score);
}


Work just as well? It's a serious question, I've never got over a million points myself but trying to cut down on bugs in my mods. Smile
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 0:22 ago.

Topics: 38
Posts: 2459
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Wed Apr 24, 2013 4:51 pm
   Subject: Re: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

It works fine as far as it actually shows the score, but with the default status bar pic it causes the last number to be drawn over the line separating the score from the current level, which is a little messy.
Andy_Nonymous
Moderator
<B>Moderator</B>


Joined: 02 Apr 2003
Last Visit: 17 Feb 2015

Topics: 99
Posts: 589
Location: New Jersey, USA
usa.gif

PostPosted: Sat Jul 13, 2013 7:22 am
   Subject: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

The ResetScore scheme works, but this is a much cleaner fix for the mess that occurs if your score dips below 1 million:

Note: A much better solution than this was posted below by Chris on 23 August.

In WL_GAME.CPP:
::: CODE :::
restartgame:
    ClearMemory ();
    SETFONTCOLOR(0,15);
    VW_FadeOut();
    DrawPlayScreen ();
    died = false;
    do
    {
        if (!loadedgame)
            gamestate.score = gamestate.oldscore;
        if(!died || viewsize != 21)
        {
            DrawPlayScreen();    // added to clean up score when it dips below 1 million
            DrawScore();
        }

        startgame = false;


Last edited by Andy_Nonymous on Mon Aug 26, 2013 7:16 am; edited 1 time in total
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 18 Jul 2018

Topics: 55
Posts: 2135
Location: Canada
blank.gif

PostPosted: Fri Aug 23, 2013 9:37 am
   Subject: Re: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Heh. I didn't like how your '0' touched/overlapped the right border, so I dug deeper into the depths of id_vh.cpp:

::: CODE :::
void LatchDrawPicScaledCoord (unsigned scx, unsigned scy, unsigned picnum)
{
    if (gamestate.score < 0)
        VL_LatchToScreenScaledCoord (latchpics[2+picnum-LATCHPICS_LUMP_START], (scx*8+3*scaleFactor), scy);
    else

        VL_LatchToScreenScaledCoord (latchpics[2+picnum-LATCHPICS_LUMP_START], scx*8, scy);
}

::: CODE :::
void DrawScore (void)
{
    if(viewsize == 21 && ingame) return;

    if (gamestate.score >= 1000000)
    {
        gamestate.score = -gamestate.score;     // temp marker
        LatchNumber (5,16,7,gamestate.score);
        gamestate.score = -gamestate.score;
    }
    else

    {
       if (gamestate.score == gamestate.oldscore)   // clear score area
       {
           gamestate.score = -(gamestate.score+1);
           LatchNumber (5,16,7,1);
           gamestate.score = -(gamestate.score+1);
       }

       LatchNumber (6,16,6,gamestate.score);
    }

}



I think it looks ok now ^^ The idea should work in 320x200 mode also

edit: Old blue code VWB_Bar(43,177,56,15,0x97) replaced with LatchNumber for "resf" (March 17th, 2015).


Last edited by Chris on Tue Mar 17, 2015 4:25 pm; edited 1 time in total
Andy_Nonymous
Moderator
<B>Moderator</B>


Joined: 02 Apr 2003
Last Visit: 17 Feb 2015

Topics: 99
Posts: 589
Location: New Jersey, USA
usa.gif

PostPosted: Mon Aug 26, 2013 7:13 am
   Subject: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Chris,

I just had a chance to try out your fix, and it works fine. It's certainly a more robust and cleaner way of doing it than my way. Thanks for putting in the legwork on making this better. I'll incorporate this into future SDL conversions.

In my defense, though, the other way doesn't always make the score touch the right edge (I don't know why), and I have found it useful to use StatusDrawPic2 for shifting the weapons over a bit in some of the Barry Christian mods where there are 4 keys, 2 on each side of the weapon image on the HUD.

In any case, it's better for modders to redesign their own HUDs, and as you pointed out in this thread, if either of these fixes are present, it may cause them confusion when doing so.

Andy
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 18 Jul 2018

Topics: 55
Posts: 2135
Location: Canada
blank.gif

PostPosted: Mon Aug 26, 2013 4:01 pm
   Subject: Re: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Andy, here's what your score (and maybe weapons?) code is doing, if you're curious:

::: CODE :::
(scaleFactor*x+1)*8 vs. (scaleFactor*x)*8+3*scaleFactor

1  -   320x200 - (5+1)*8 =  48 (48)     vs.   5*8+3 =  43 (43)
2  -   640x400 - (10+1)*8 =  88 (44)     vs.  10*8+6 =  86 (43)
3  -   960x600 - (15+1)*8 = 128 (42.666) vs.  15*8+9 = 129 (43)
4  -  1280x800 - (20+1)*8 = 168 (42)     vs. 20*8+12 = 172 (43)
5  - 1600x1000 - (25+1)*8 = 208 (41.6)   vs. 25*8+15 = 215 (43)
6  - 1920x1200 - (30+1)*8 = 248 (41.333) vs. 30*8+18 = 258 (43)
16 - 5120x3200 - (80+1)*8 = 648 (40.5)   vs. 80*8+48 = 688 (43)

Your score code (blue) progressively moves left as you increase resolution, and never reaches the target x-location (43), which is the only exact spot it can be to not touch/overwrite the borders and look good, I believe. A 7-digit score CAN fit exactly into the border, though, as we've figured out (and something I may have never realized if you didn't start this thread). :)
Andy_Nonymous
Moderator
<B>Moderator</B>


Joined: 02 Apr 2003
Last Visit: 17 Feb 2015

Topics: 99
Posts: 589
Location: New Jersey, USA
usa.gif

PostPosted: Mon Aug 26, 2013 4:39 pm
   Subject: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

%#$#%!! That's why it didn't always touch the side! I've been running in windowed 960x600 most of the time. Doh!

Nice detective work, Chris!
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:42 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Mon Aug 26, 2013 5:31 pm
   Subject: Re: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Nicely done, Chris. I honestly didn't use the code Andy posted, because I had a custom-made statusbar in the game engine (to support four keys). But it's always helpful to have. Smile
Officer-Michael John
Banned
Banned


Joined: 19 Dec 2014
Last Visit: 18 Feb 2017

Topics: 66
Posts: 280

blank.gif

Currently banned
PostPosted: Sat Dec 20, 2014 2:31 am
   Subject: Re: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

In which file can be found this:(scaleFactor*x+1)*8 vs. (scaleFactor*x)*8+3*scaleFactor

1 - 320x200 - (5+1)*8 = 48 (4Cool vs. 5*8+3 = 43 (43)
2 - 640x400 - (10+1)*8 = 88 (44) vs. 10*8+6 = 86 (43)
3 - 960x600 - (15+1)*8 = 128 (42.666) vs. 15*8+9 = 129 (43)
4 - 1280x800 - (20+1)*8 = 168 (42) vs. 20*8+12 = 172 (43)
5 - 1600x1000 - (25+1)*8 = 208 (41.6) vs. 25*8+15 = 215 (43)
6 - 1920x1200 - (30+1)*8 = 248 (41.333) vs. 30*8+18 = 258 (43)
16 - 5120x3200 - (80+1)*8 = 648 (40.5) vs. 80*8+48 = 688 (43)
Andy_Nonymous
Moderator
<B>Moderator</B>


Joined: 02 Apr 2003
Last Visit: 17 Feb 2015

Topics: 99
Posts: 589
Location: New Jersey, USA
usa.gif

PostPosted: Sat Dec 20, 2014 2:43 am
   Subject: [Tutorial] Adjusting HUD display for scores over a million
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

That's just Chris's calculations. It's not code at all.
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Announcement: Wolf3d & Spear of Destiny Shareware SDL Downloads
Author: BrotherTank
10 14640 Tue Aug 24, 2010 10:18 am
dcbasic View latest post
No new posts Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 22956 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [Help] Hud Question
Author: RichterBelmont12
3 868 Wed Jul 23, 2008 4:29 am
RichterBelmont12 View latest post
No new posts [Help] Problem with Checkweaponchange function (wolf4sdl)
Author: Mortimer
4 3026 Sat May 17, 2008 11:26 am
Mortimer View latest post
No new posts [SDL] Apply 2nd ScaleFactor to selected (hi-res) vga gfx
Author: Andy_Nonymous
9 4247 Sun Apr 27, 2008 2:30 am
AlumiuN View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group