[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] SOC Proposal: Networking for Pygame



On 5/8/06, Bryce Allen <pygame@xxxxxxxxxx> wrote:
I also don't like the idea of handling data in events in the main loop. I
would be more inclined to create a custom protocol object that posts my own
application specific objects to the SDL event queue, based on what comes in
on the network. There could be a standard protocol class that allows you to
send any event object over the network and it gets posted to the remote queue
if it matches a list of allowed network events. That way games with basic
needs can simply use the standard event propagation protocol, and games with
more complex network needs can implement a custom protocol, possible
inheriting from existing protocols.

Something like this sounds like the best, to me. Events if you want
them, but you can get & process your packets in a special network loop
(which is what I believe all the game programmers would up doing)


It would be useful to act like all the other events.  So your
application could be sleeping, and when it gets an event wakes up.  It
also means you have one place to capture outside events.  Which makes
filtering, recording, inspection and playback of events easier.

thanks Rene, now I see where you (and others) are coming from with the
waking up thing. If you are going to design a passive gui app or an
OS, it's really the only thing that makes sense.

...although I can confidently say I would never write any pygame code
(neither game client nor game server) that would sleep and wait until
it wakes up through an external event. Like Pete said, real games
don't do that. I'd always want my games to run at a regular rate,
whether events happen or not.

For the recording of events thing, that's another interesting point I
hadn't thought of. It makes some sense for regression testing, but
that sounds like the much rarer situation, so it should get special
coding, not vice-versa. For game event playback/recording, I would
probably not do any of it there because the signal to noise coming
through the event loop for game events is really rather low, and I've
always recorded much higher level stuff anyways

The desire for events strikes me as coding for the theoretical
possibilities about what a game Might like to do - as opposed to what
games Actually do.... I am really curious to know, does anybody here
use pygame.event.wait in their main loop?

bottom line, I guess I don't see a reason why net packets shouldn't be
able to come through the event loop if it's what you want, I just
think that making them have to come through there doesn't fit any of
the "simple" uses I would want.

You can pass an event list on to other methods to process.

The code you posted Rene, is a perfect example of the unneccessary
boilerplate that every single game I'd write would have, if net events
had to work that way. I say if you got to write boilerplate, write
some to get it into the event loop, not to get it out.