• Welcome to Dark Bit Factory & Gravity.
 

[C++] Timers

Started by Clyde, November 15, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Clyde

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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

Try

GetTickCount()

Jim
Challenge Trophies Won:

Clyde

#2
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;
}
}
}
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: