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

Re: [pygame] Fwd: Soc Simple Networking



As far as passing events and what-not, I can't imagine that bit will be too hard.  I whipped up a recording and playback system in just a couple hours in the crudest manner I could (see below).  Right away, you might point out that I could have serialized the events to save me a rat's nest of if...elif structures.  In this example, pack vectorEvent and unpackVectorEvent both feed from and to a file, but that could just as easily be a UDP socket, which are cheap as chips and twice as easy in Python. 

However, the real trick is when the UDP messages are received out of order, or with a large amount of lag or latency.  Handling those contingencies is my number-one priority when looking at an event handler right now.

Whatever networking system is developed, only proper ordering and management of sockets is really important to me, as a user/developer, at the client side.  I would, however, be very interested in SDL's server networking stuff given a nice Python wrapper.

Thank you,

Andrew Ulysses Baker
"failrate"

if world.PLAYBACK:
                        uve_set = unpackVectorEvent(ticks)
                        if uve_set != None:
                          for uve in uve_set:
                            if uve == 'QUIT':
                                running = 0
                            elif uve == 'KEYDOWN_LEFT':
                                    world.ego.startLeft()
                           
                              <-- snip -->

                            elif uve == 'KEYUP_ACTION_3':
                                    world.ego.stopAction(3)
                    else:
                      for event in pygame.event.get():
                        if event.type == QUIT:
                            if world.RECORD: vectorEvent(ticks, "QUIT")
                            running = 0
                       
                        elif event.type == KEYDOWN:
                           
                            if event.key == profile.keyMap[0]:
                                if world.RECORD: vectorEvent(ticks, "QUIT")
                                running = 0

                              <-- snip -->

                            elif event.key == profile.keyMap[11]:
                                edit.mode = 1
                                edit.indicator.initialize_editing()
                               
                        elif event.type == KEYUP:           
                            if event.key == profile.keyMap[1]:
                                if world.RECORD: vectorEvent(ticks, "KEYUP_LEFT")
                                world.ego.stopLeft()
                           
                                 <-- snip -->

                            elif event.key == profile.keyMap[8]:
                                if world.RECORD: vectorEvent(ticks, "KEYUP_ACTION_3")
                                world.ego.stopAction (3)