Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on November 15, 2009

Title: [C++] Timers
Post by: Clyde 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.



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.
Title: Re: [C++] Timers
Post by: Jim on November 15, 2009
Try

GetTickCount()

Jim
Title: Re: [C++] Timers
Post by: Clyde on November 15, 2009
Cool, GetTickCount() returns the time in milliseconds.


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;
}
}
}