Fruitz of dojo Mac OS X Quake port...

Member
Posts: 129
Joined: 2005.02
Post: #1
Is anyone very familiar with the FoD mac os x quake port? Does he replace the PC event loop with a NSTimer? I'm trying to make a crossplatform engine, but I really hate the idea of creating platform specific event loops. However, I want to utilize the Cocoa event system. Is there a way that I can check for any events in Cocoa, while in my game's event loop? That way I could:

Code:
while (gameLoop)
{
   #ifdef MAC
     (check for Cocoa events here [ie os x system events / keyboard events / mouse clicks)
   #endif
   gameupdate();
   renderupdate();
}
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #2
If I recall, they create a custom subclass of NSApplication and then receive the events from there.
Quote this message in a reply
Member
Posts: 129
Joined: 2005.02
Post: #3
That's just how they receive events. I don't know how they tie into the quake event structure... The thing is I want an infinite loop in my C++ engine, but if I do this, it will never come up for air... (it will never try to receive Cocoa events UNTIL the event loop is over... which basically is when my game is quit).
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #4
maaaaark Wrote:That's just how they receive events. I don't know how they tie into the quake event structure... The thing is I want an infinite loop in my C++ engine, but if I do this, it will never come up for air... (it will never try to receive Cocoa events UNTIL the event loop is over... which basically is when my game is quit).
So why would this be different from any other game loop? You process the events, render, repeat ad infinitum.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #5
maaaaark: You don't want an infinite loop in your game. It's bad design. Just use an NSTimer to call a single rendering routine, like Qcommon_Frame in Quake2. This is what Fruitz does, as well as intercepting events at sendEvent. What you're asking about is pretty well layed out in sys_osx.m in the Fruitz source. If you look at qcommon.h at the bottom you'll find:

void Qcommon_Init (int argc, char **argv);
void Qcommon_Frame (int msec);
void Qcommon_Shutdown (void);

This is central to the idea of abstracting the OS away from the game code. There are other OS wrappers in Quake2 that you should investigate as well. Create as few choke points between the OS abstraction layer and the game and you'll be well prepared to write cross-platform code. Dig deeper into the Quake2 source and you'll find all kinds of goodies. Look very closely at sys_osx.m and you'll see a very good example of how this is all tied together. Trace the calls out of sendEvent. Notice that they set the principle class to Quake2Application in the app target. Use the "find in project" window in Xcode a lot. Blah, blah, blah...
Quote this message in a reply
Member
Posts: 129
Joined: 2005.02
Post: #6
It's not a matter of using NSTimers. I have no problems doing so. I just didn't want to embed platform specific stuff in my game loop, but looking at this, I willl probably have to make seprate (Mac/Win/etc) versions of my game event loop.

But I will keep investigating.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #7
Did you try SDL? I can port any game I've written with it to/from win/linux in (at most) 10 minutes.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Quake II Evolved and XCode ajmas 1 4,655 Aug 21, 2005 09:10 PM
Last Post: OneSadCookie
  BSP (Quake 3) PVS Issues dstaudigel 6 4,063 Jun 20, 2003 11:17 PM
Last Post: gwihlidal
  Simple Quake Variant? deekpyro 8 4,650 Mar 17, 2003 12:21 PM
Last Post: burden