[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Re: game lobby



Lee Harr wrote:

Any game lobby project for pygame should probably be written with Twisted.. it would make life easier (all the functionality is really already there, including remote object brokering and such), and the asynchronous nature of Twisted interacts really well with pygame. I've even used Twisted's reactor to make pygame programming easier (i.e. reactor.callLater to schedule events and such).



I agree that Pygame + Twisted works really well.

There are a few examples (Twisted w/ Pygame, and Twisted w/
pygtk) in pygsear:

http://www.nongnu.org/pygsear/

look in  examples/twist_tac_toe/  and  examples/twisted-pygame/
in the distribution.

Excellent. I've been looking for an example of twisted + pygame for a while.

Be good if someone could write a small tutorial for the pygame docs section with a basic game outlined :) Maybe multiplayer chimp ;)

Does twisted have any udp support yet? Last I checked it was minimal, and/or they were changing the api.

enet(which someone posted a python wrapper for a while ago) is ok for udp data. I did a basic test, and it seemed to work ok.


There's two net libraries for sdl as well. I haven't tried either of them:
net2 - http://gameprogrammer.com/game.html
SDL_net - http://www.libsdl.org/projects/SDL_net/

net2 looks fairly good.





Now for some random thoughts on abstraction into pygame events.


What would work good is something which translates network activity into pygame events. Then we handle the events. Translating events into a network connection would be good too. Then this network -> event/event -> network thing could be abstracted over different libraries eg:
twisted (comes with free kitchen sink)
enet(based on udp)
urllib/http (good for going over proxies)
modem
standard udp or tcp
files/pipes
some-other-library.


network_event:
payload - a string. Maybe other types too(eg other event, int, float, list, dict, python object).
time of event - date stamp of when event was generated.
sender_id - an id of the person who sent the event. When sending defaults to self.
receiver_ids - ids of people who should get the event. Can be all.

Maybe a couple of useful events like: disconnected, connected, lag, timeout could be made.

class ANetworkConnection:
def get_network_events(self):
""" returns a list of network events(if any). These events could be inserted into the pygame queue or handled seperately."""

def send_network_event(self, network_event):
""" sends the network event """

def get_receiver_ids(self):
""" returns the ids of all the possible receivers we are connected to """


Each implementation would have it's own connect/authenticate/disconnect methods.

Multiple implementations could be used at the same time. Eg using udp to connect to one person, and a http proxy to connect to another.


A good utility function would be to translate certain network events into local events. Eg translate all network K_a,K_s,K_,K_w events to local events. A reverse function would be needed too. Eg translate all local K_a, K_b events to go to these receiver ids.

To make a two player game which works with one player on the network would be trivial with these helper functions. Of course performance over slow internet connections would not be good at all :) For example to translate chimp to be controlled via the network would only need a few initialise/connect calls added.