IonicWind Software

Creative Basic => GUI Programs => Topic started by: GWS on February 22, 2008, 12:23:00 PM

Title: Sleep DLL
Post by: GWS on February 22, 2008, 12:23:00 PM
Here's another little routine which just encapsulates the GetTickCount() stuff to wait for 'n' millisecs.

The dll is sleep.dll, the test program is 'sleeptest.cba' and the code from the EBasic routine is sleepdll.txt, all zipped.

At some point, if they work OK, these little routines could be packaged in one DLL to give a few more useful functions in CBasic.

best wishes,  :)

Graham
Title: Re: Sleep DLL
Post by: Ionic Wind Support Team on February 22, 2008, 01:55:34 PM
CBasic can use API imports so why the encapsulation of GetTickCount?
Title: Re: Sleep DLL
Post by: GWS on February 22, 2008, 02:11:22 PM
It's nothing amazing I agree, it just does the timing comparison in one statement to save typing the routine  each time you need a pause.

Sleep(1000)

is just neater ..  :)

Graham
Title: Re: Sleep DLL
Post by: Mike Stefanik on February 25, 2008, 04:30:30 PM
There's Sleep and SleepEx functions that are part of the base operating system, exported from Kernel32.dll. Looping around calling GetTickCount is just going to burn CPU cycles; calling Sleep actually allows the scheduler to put the thread to sleep for that period of time.
Title: Re: Sleep DLL
Post by: GWS on February 26, 2008, 01:51:54 AM
Yep .. OK thanks Mike.  No point in thrashing the CPU just to pause for a second or two ..  :)

I have seen the looping method used for game timing though - no harm done if the machine is being paused anyway.

What's missing there is a 'Check(1000)' function that can be put in a game loop IF statement, that only executes an IF block if Check() returns a 1.  Trouble is, that needs the Check() routine to remember when it was first called, and I haven't thought of a way of doing that yet.

I've changed to using the Sleep API in the attached zip ..

best wishes, :)

Graham