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

Re: [pygame] SOC Proposal: Networking for Pygame



On 5/8/06, Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
On 5/7/06, Rene Dudfield <renesd@xxxxxxxxx> wrote:
>  Using the pygame event queue means that all event management is done
> through the same api.  So people who already understand pygame events
> can use networking too.
>
That's a Red Herring, and it doesn't apply to the issue I'm talking
about. You don't need to use the same event queue in order to get the
benefit of people's knowledge and understanding. If you have the
network have it's own seperate queue that acts similarly to the pygame
one, but can be read and processed in a seperate loop, then it's still
true that "people who already understand pygame events can use
networking too"

The issue I'm talking about is whether pygame.event.poll and
pygame.event.get would be the only functions that can get network
packets and/or lobby/matchmaking events...I still don't see any reason
why a single line of game code to process packets should be sitting in
my main event loop.

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.


...I'm just working through what code I would write in my pygame.event.get loop if net messages came through there, and it would just be something that buffers the net messages so the code that actually uses it can read it, or forwards them on to registered listeners... So why shouldn't the "simple to use networking" module help me out by not making me write that extra boilerplate?


By having it come from the same place as the rest of the events you can dispatch them as needed. Using the same method of dispatch as your other events.

I can see that it would be easier to process the net stuff in that
main loop if you are writing a small example, or a pygame app that's
all in one file, but is there anybody here who would write anything
more than either message dispatch/buffering for net events in their
main event loop in a real network game?


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

eg.
class SomeThing1:
   def handle_events(events):
       for e in events:
           if e.type == NETWORK:
               print e

class SomeThing2:
   def handle_events(events):
       for e in events:
           if e.type == NETWORK:
               if e.channel == CHANNEL_FIRE:
                   print "ouch"


s1 = Something1() s2 = Something2()

events = pygame.event.get()

s1.handle_events(events)
s2.handle_events(events)

So your event processing parts look very similar to a single file
program without adding an extra layer of abstraction.  Each state, or
each object can process events in this same way.

It is one line of code to get the network events if you want.
network_events = filter(lambda x: x.type == NETWORK, events)




> SDL_net does use the event queue... well they wrote a different
> implementation of it which they call fast events.
>
Are we talking about the same SDL_net? Do you mean this one:
http://www.libsdl.org/projects/SDL_net/

because that SDL_net sure looks like nothing more than a very thin
(simple?) wrapper over TCP and UDP to me

I don't see the word event used anywhere in it's docs
http://jcatki.no-ip.org/SDL_net/SDL_net.html
and I don't see events used in the SDL_net sample code either



I'm sorry, I was thinking about Net2. Not SDL_net. http://www.gameprogrammer.com/net2/net2-1.html

Check out pygame cvs for the fastevents module.  It's not really that
interesting... pretty much the same event functions.



>See the fastevents module in pygame.
>
I don't know anything about fastevents, I can't find the "fastevents"
module in the pygame docs:
http://www.pygame.org/docs/ref/index.html

I'm curious about them though, got a link?


(PS. if there is a better home for discussion/suggestions/criticism of network proposal stuff than being mailed to this list, please let me know where it should go)