While trying to port my game engine to mac, I stumble upon one basic (but big) problem. On windows, my main code looks like this (very simplified):
PeekMessage(.
You could use a Core Foundation runloop instead, and have event sources for your “threads” so that the run loop will wake up and call their processEvents()
methods. This is an improvement over your polling code, since the run loop will let the thread sleep if there are no events waiting.
See CFRunLoopSourceCreate()
, CFRunLoopSourceSignal()
and CFRunLoopWakeUp()
for more information.
Note that, if your application is built on top of the Cocoa framework, you can (and probably should) use the default NSRunLoop
, but this isn’t a problem because you can get the underlying Core Foundation CFRunLoop
by sending it a -getCFRunLoop
message.