Re: OTCreateSystemTask() Replacement?
Re: OTCreateSystemTask() Replacement?
- Subject: Re: OTCreateSystemTask() Replacement?
- From: email@hidden
- Date: Sat, 7 Apr 2007 22:39:49 -0600
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.
Now I might offend some people, but I must say that Apple really has
been letting me down on stuff like this the last few years. If you
look at trends in languages like javascript and lua, people are going
to coroutines and functional programming and methodologies that avoid
multithreading altogether. Multithreading is a disaster. It has its
place, but general programming, especially a simple game loop, is a
shining example of where the best practices just aren't good enough.
We shouldn't have to learn the intricacies of synchronization and
mutexes and atomicity and on and on just to get 2 games to talk to
one another, but that's where we're at.
I have just been noticing this gradual increase in complexity
throughout the Mac OS the last few years. We've traded intuitiveness
for what somebody thinks is the future, but it's the future circa
1995. NetSprocket was a real step forward, but they axed it for
CFNetwork. OTCreateSystemTask() would solve my problem brilliantly,
but now I am told to rewrite everything to be "modern." Blah. I
find myself yearning for the good ol' days when we did everything the
wrong way but somehow got stuff done.
P.S. Whatever happened to Return to Dark Castle?
It's actually finished. We are working with the original guys now to
get it distributed, hopefully in the next month or two :-)
------------------------------------------------------------------------
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