Search code examples
lazarusfreepascal

TFPTimer not 'Ticking'


I'm writing a game which I've attempted to separate between the interface, and the simulator (both of which run with separate timing circuits - with the theory being animations will sync, and simulation can run only 10 times a second... or something)

I'm having issues with my TFPTimer. Its initialised with the Games constructor like so:

//Create the game timer
InternalTimer := TFPTimer.Create(nil);
//Set the OnTick callback
InternalTimer.OnTimer := @OnTick;
//Set the timer interval
InternalTimer.Interval := DEFAULT_INTERNAL_TIMER; // =10
//Start the timer
InternalTimer.StartTimer;

The problem is OnTick never seems to be called. I've got a seperate loop running under the client with an SDL_Delay in it. Do I need to eventise TFPTimer somehow? Should I give it its own thread (or does it already have one?) Any ideas on making my timer work?

Thanks

Lachlan


Solution

  • Events come from the main event loop. If your program is not eventdriven in the Delphi/Lazarus sense it will probably not work.

    Try an application.processmessages inbetween sleeps