I am writing a game that currently works on both Windows and Mac OS X. My main game loop looks like this:
while(running) { ProcessOSMessages(); // Using Peek/Translate message in Win32 // and nextEventMatchingMask in Cocoa GameUpdate(); GameRender(); }
This is clearly a little simplified, but that's the point. On Windows, where I have full control of the application, it works great. Unfortunately, Apple has its own way of doing something in Cocoa apps.
When I first tried to implement my main loop in Cocoa, I couldn't figure out where to put it, so I created my own NSApplication for this post . I threw my GameFrame() into my run function and everything worked correctly.
However, it does not seem to me that this is the โrightโ way to do this. I would like to play well in the Apple ecosystem, rather than trying to hack into a solution that works.
This apple article describes an old way to do this using NSTimer and a โnewโ way to do it using CVDisplayLink . I plugged in the CVDisplayLink version, but it just feels .... weird. I do not like that my game is controlled by the display, and not vice versa.
Am I using only two CVDisplayLink parameters or overwrite my own NSApplication ? None of these solutions seem completely correct.
source share