Author Topic: [C++] Timers  (Read 3140 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
[C++] Timers
« on: November 15, 2009 »
In FreeBasic I use the following timing method alot, and I'd love to know how to convert it for use with C.

Code: [Select]

demo_timer=timer()
int demo_duration=24000; ( 24 seconds )

while not keyhit(escape)

running_timer=timer()

if ( demo_timer + demo_duration ) <= (running_timer*1000.00f) then
perform_actions()
demo_timer=running_timer*1000.f
end if
wend

Thanks alot,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++] Timers
« Reply #1 on: November 15, 2009 »
Try

GetTickCount()

Jim
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [C++] Timers
« Reply #2 on: November 15, 2009 »
Cool, GetTickCount() returns the time in milliseconds.

Code: [Select]
void run_demo()
{
             unsigned long running_timer=0;
unsigned long demo_timer=GetTickCount();

int duration=30000; // aka 30 seconds.

while (1)
{
running_timer=GetTickCount();

clear_gfx_buffer( screen_buffer, 0 );

if ( (demo_timer + duration) <= running_timer )
{
image_pos_x=random_int(0,2);
demo_timer=running_timer;
}
}
}
« Last Edit: November 15, 2009 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: