gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfxgfx
 
Members, please note that our guidelines are located here.
 
gfx gfx
gfx
484576 Posts in 28410 Topics by 2464 Members - Latest Member: austinrobert February 28, 2020, 02:55:05 PM
*
gfx* Home | Help | Calendar | Login | Register | gfx
gfx
The Gaming Universe  |  The Archives  |  Archived Projects  |  Open Zelda  |  OZ Help (Moderator: red_team316)  |  What method to use for double digits
gfx
gfxgfx
 

Author Topic: What method to use for double digits  (Read 618 times)

Offline KingOfHumans

  • Messiah
  • ******
  • Posts: 17,866
    • View Profile
What method to use for double digits
« on: March 04, 2011, 10:05:37 PM »
I'm trying to increase the FPS a bit with my timebox (the timer that shows up on the last night after 12:00AM).
The original script was this.

Code: [Select]
DrawTimeBox(x,y)
{
new string[9];
new out[2];
new hour = 5 - floatround(GetFloat("this",2));
new min = 59 - floatround(GetFloat("this",1));
new sec = 59 - floatround(GetFloat("this",0));
new thr[3] = "00";
new tmin[3] = "00";
new tsec[3] = "00";

if(hour < 10)
ToString(hour,thr[1]);
else
ToString(hour,thr);
if(min < 10)
ToString(min,tmin[1]);
else
ToString(min,tmin);
if(sec < 10)
ToString(sec,tsec[1]);
else
ToString(sec,tsec);
strcat(string,thr);
strcat(string,tmin);
strcat(string,tsec);
DrawImage("_hudtimerbox",x + 286,y + 424);

if(GetPauseLevel() == 0)
{
if(hour == 0)
{
if(darkness < 550)
{
if(min > 30)
darkness += 100 * GetTimeDelta();
else if(min > 20)
darkness += 150 * GetTimeDelta();
else if(min > 10)
darkness += 200 * GetTimeDelta();
else
darkness += 300 * GetTimeDelta();
}
else
darkness = 0.00;
}
else
darkness = 0.00;
}
new dark = 255;
if(darkness < 255)
dark = (0 - floatround(darkness)) + 255;
else if(darkness < 275)
dark = 0;
else if(darkness < 530)
dark = (floatround(darkness)) - 275;

new bx = x + 288;
for(new n; n < 8; n++)
{
out[0] = string[n];
AdvanceText(out,bx,y + 426,2,255,dark,dark,255,100);
if(n == 1 || n == 3)
{
bx += 8;
AdvanceText(":",bx,y + 426,2,255,dark,dark,255,100);
bx += 8;
}
else
bx += 9;
}
}
but I changed it to this.

Code: [Select]
DrawTimeBox(x,y)
{
new string[9];
new hour = 5 - floatround(GetFloat("this",2));
new min = 59 - floatround(GetFloat("this",1));
new sec = 59 - floatround(GetFloat("this",0));

DrawImage("_hudtimerbox",x + 286,y + 424);

if(GetPauseLevel() == 0)
{
if(hour == 0)
{
if(darkness < 550)
darkness += (min > 30 ? 100 : min > 20 ? 150 : min > 10 ? 200 : 300) * GetTimeDelta();
else
darkness = 0.00;
}
else
darkness = 0.00;
}
new dark = 255;
if(darkness < 255)
dark = clamp((0 - floatround(darkness)) + 255,0,255);
else
dark = clamp((floatround(darkness)) - 295,0,255);//stay dark for extra time

new bx = x + 288;
strformat(string,9,"%d:%d:%d",hour,min,sec);
AdvanceText(string,bx,y + 426,2,255,dark,dark,255,100);
}

Look at the line where I did min > 30 ? 100 min > 20,.... This method is experimental but after looping 1000 times it looks a little faster then using 3 if statements and an else.

Anyways I'm wondering how I should return double digits for the hour, min, sec when it's less then 10.
If the hour is 9 it will return 9 but I want it to return 09.

The Gaming Universe  |  The Archives  |  Archived Projects  |  Open Zelda  |  OZ Help (Moderator: red_team316)  |  What method to use for double digits
 

gfxgfx
gfx
SMF 2.0.17 | SMF © 2019, Simple Machines Page created in 0.163 seconds with 24 queries.
Helios Multi © Bloc
gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!