Re: OTCreateSystemTask() Replacement?
Re: OTCreateSystemTask() Replacement?
- Subject: Re: OTCreateSystemTask() Replacement?
- From: email@hidden
- Date: Sat, 7 Apr 2007 23:15:01 -0600
On Apr 7, 2007, at 10:39 PM, email@hidden wrote:
On Apr 7, 2007, at 9:26 PM, Josh Graessley wrote:
On Apr 7, 2007, at 7:59 PM, email@hidden wrote:
On Apr 7, 2007, at 8:21 PM, Josh Graessley wrote:
Are you trying to develop for Mac OS X or Mac OS 9?
For Mac OS X, you should seriously consider switching to a
CFRunLoop and using sockets and CFSocket to handle networking.
NewThread, OTCreateSystemTask, WaitNextEvent, SystemTask are all
a compatibility shim to keep old code limping along. They are
not intended for new code development.
This is for OS X. I started working on networking back in the
90s when it was still a nightmare on the Mac, so it messed up my
methodologies. Now I am just calling sockets directly, but the
problem is really logistics now since I have a udp class that
needs to have its Idle() function called periodically for
polling. It has several dozen functions so it's not feasible to
make the whole thing preemptive. For example, it would just die
right now if I called Idle() from another preemptive thread. It
should be perfectly legal to call Idle() during a dialog's system
task time though. Such a thing should still exist on the mac,
since countless programs bring up dialog boxes in their main
thread. If it doesn't, then it got axed for political reasons
and I just don't know how much more of that I can take.
I guess what I am trying to say is, if the notion of system task
time doesn't exist anymore, then we can't really write
nonblocking code on the main thread that can coexist with system
gui elements. I think that's a big deal, and I hope that there
is a way to do it.
You need to grab a book on OS X. The cooperative/preemptive
threads of yesteryear are gone. Mac OS X has a frightening
compatibility layer that attempts to emulate some of this behavior
for old code. Don't use it. You will run in to buggy behavior and
you won't find anyone that knows how to help you diagnose
problems. It's time to learn about how things are done in Mac OS X
and refactor your code to do the right thing.
Ya I do actually know a fair amount about OS X, but the hard part
is that we just have miles of legacy code, even with the few games
we have. It's not really conceptually hard I guess to use RAEL or
CFRunLoop, but it comes down to, how does the mind work. Each game
has half a dozen screens that normally say while( !done )
doSomething(); and refactoring all of that with event callbacks
just seems like a lot of work, to get what we already have. I
really don't understand why Apple couldn't have made the
WaitNextEvent() sleep parameter in OS X be milliseconds or
microseconds. Then our games could just call it with say 33
milliseconds and get 30fps. Saying that WaitNextEvent() is
"inneficient" is a copout and everyone knows it. The proof is that
I can emulate WNE by writing a routine that uses an inverted RAEL
internally, and now I may just have to do that.
Hah, I figured it out:
pascal void Callback( EventLoopTimerRef theTimer, void *userData )
{
Beep();
}
main()
{
EventLoopTimerUPP myFrameUPP = NewEventLoopTimerUPP( Callback );
EventLoopTimerRef nextFrameTimer;
InstallEventLoopTimer(
GetCurrentEventLoop(),
kEventDurationNoWait,
kEventDurationSecond,
myFrameUPP,
NULL,
&nextFrameTimer);
AlertDialog( "\pTest" ); // our own dialog routine, it calls
RunAppModalLoopForWindow()
}
This beeps every second, even with the mouse down, so I can put my
Idle() function in Callback. I should have realized that the main
event loop is always running. For some reason I was still thinking
that dialogs took over the app. Sorry if I offended anyone, but I do
stand by what I said, in general I find the Mac OS to often be more
complex now in practice, even if conceptually it is easier than in
the classic days. Hope this helps someone down the road.
------------------------------------------------------------------------
Zack Morris Z Sculpt Entertainment This Space
email@hidden http://www.zsculpt.com For Rent
------------------------------------------------------------------------
If the doors of perception were cleansed, everything would appear to man
as it is, infinite. -William Blake, The Marriage of Heaven and Hell
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden