Quesion please.
In Delphi everything I've read and used before uses the application.onidle event for running your game loop.
In C they seem to just do a repeat until style loop.
Which is better?
Quesion please.
In Delphi everything I've read and used before uses the application.onidle event for running your game loop.
In C they seem to just do a repeat until style loop.
Which is better?
Basically the Application.OnIdle is a choice if you don't have anything better and don't want to or don't can use anything else. The OnIdle Event has the problem of having to abuse an event that was intended for "background activities\processing" for doing "a program main loop". Therefore I would mark this a "dirty solution".
Better is the C Program main loop as this does everything just the same way but was intended for this purpose. thus there's no "abuse" of code intended for something else.
Although using the OnIdle event isn't worse than doing a program main loop. But it isn't as clean like the program main loop of C programs.
The more complex a system is, the smaller the bugs get; the smaller the bugs are, the more often they appear.
Thanks for the reply.Originally Posted by BenBE
Could this be why on some machines I appear to get a "clitch" during scrolling in my game? If as you say, it's a "dirty" solution.
What would be the correct code for a Delphi loop? I'm a bit of a beginner here. As I understand it I have to insure windows processes continue okay during my loop, so a....
repeat
doframeofmygame;
until dead;
isn't sufficient is it?! (sorry for my ignorance here!).
Basically the OnIdle event isn't wrong to be used, but you need to ensure Application.ProcessMessages is substituted by PeekMessage, TranslateMessage and DispatchMessage. A better, but more complicate solution to this issue would be to use threads as it wouldn't matter what you are currently working in your program while you draw your frame. If this is to complicated for you I'd suggest, when possible, to do without the VCL since this would be the equivalent of a C Main Loop. Just modify your project main loop to do what you need. But this requieres some Win-API handling. Best is to look for some tutorials on this topic as most do without the VCL
The more complex a system is, the smaller the bugs get; the smaller the bugs are, the more often they appear.
Bookmarks