Author Topic: Display Timer - Way to optimize ?  (Read 2262 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Display Timer - Way to optimize ?
« on: November 27, 2007 »
i want to display a timer in a game which may look like this:

00:00:00     the 1st 00 block are the minutes, the 2nd 00 block are the seconds and the last are the mseconds.


Now the way i thought how to calculate and draw this timing with formating the string is following but i am not sure if there is a better (optimized and faster) way.

Code: [Select]
if dig1 = 10 : dig1 = 0 : dig2 + 1 : endif
if dig2 =  6  : dig2 = 0 : dig3 + 1 : endif
if dig3 = 10 : dig3 = 0 : dig4 + 1 : endif
if dig4 =  6  : dig4= 0 : dig5 + 1 : endif
if dig5 = 10  : dig5= 0 : dig6 + 1 : endif
if dig6 =  6  : game_completed=true : endif

dig1 + 1 
DrawString( Str(dig6) + Str(dig5) + ":" + Str(dig4) + Str(dig3) + ":" + Str(dig2) + Str(dig1) )

hope the source is correct, because i typed here while sitting not in front of my pc :P
I still thought if there is another (better and possible faster way) using pointers but i am not really sure atm...

- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Display Timer - Way to optimize ?
« Reply #1 on: November 27, 2007 »
In C, you can do
sprintf(timestring, "%02d:%02d:%02d", hours, minutes, seconds);
In BASIC, try looking up the docs for
Print Using

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Display Timer - Way to optimize ?
« Reply #2 on: November 28, 2007 »
thx. when seeing the c codesnip i like C/CPP ;)
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won: