Cocoa message loop? (vs. windows message loop)

前端 未结 2 1610
闹比i
闹比i 2021-02-07 11:46

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(.         


        
2条回答
  •  盖世英雄少女心
    2021-02-07 12:27

    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.

提交回复
热议问题