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

Re: [pygame] Easy networking module - feedback needed



Here is the fastevent article:
http://gameprogrammer.com/fastevents/fastevents1.html

See these in src/ for details: fastevent.c fastevents.c fastevent.h


On Tue, Jul 3, 2012 at 10:13 AM, René Dudfield <renesd@xxxxxxxxx> wrote:
Because it's easy.  All types of events can be handled in the same place, making it conceptually simpler.

if e.type in [NETWORK, KEYUP]:
    dosomething()

Appropriate placing of client.step should be able to allow other events to be handled correctly without loss... I think.  Network packet loss is a normal part of life, and needs to be handled.  pygame.fastevent was designed to help with networking, and can do over 40,000 events per second with ease.


cya.


On Tue, Jul 3, 2012 at 3:38 AM, Ryan Hope <rmh3093@xxxxxxxxx> wrote:
Can someone explain to me why integrating network packets with pygame
events is a good idea? It was my understanding that the pygame event
buffer can only hold a limited number of events before events get
lost.

On Mon, Jul 2, 2012 at 8:19 PM, Szymon Wróblewski <bluex0@xxxxxxxxx> wrote:
> Hi,
>
> Networking module is finally in state allowing to test it and show something
> working, so I wrote new blog post describing changes and showing features.
> You can find it here:
> http://pygame-networking.blogspot.com/2012/07/gsoc-journal-client-tests.html
>
> Greetings,
> Szymon Wróblewski
>
> 2012/6/21 Szymon Wróblewski <bluex0@xxxxxxxxx>
>>
>> I added documentation about available events:
>>
>> http://pygame_network.readthedocs.org/en/latest/source/pygame_network.html#events
>>
>> 2012/6/21 Szymon Wróblewski <bluex0@xxxxxxxxx>:
>> >> connection.register('echo', ('user', 'msg'))
>> >
>> >> You would also probably want a separate 'protocol' object on which you
>> >> would register the messages, so
>> >> that you can reuse it for several connections.
>> >
>> > pygame_network.register method is in fact
>> > pygame_network.packets.PacketManager.register, which stores all
>> > registered packet types and maps them to integers to reduce packet
>> > size (those integers must be unique), but if you see use for separate
>> > managers all I need to do is define __init__ for it, to override class
>> > variables with instance variables.
>> >
>> >> connection = pygame_network.connect('localhost', 10000)
>> >
>> > I plan to create Connection class so pygame_network.connect will just
>> > init global connection variable to use by Receiver and SyncObject (it
>> > can be overridden with initialization parameter) and you can create
>> > more connections with this class.
>> > example:
>> > connection = pygame_network.Connection('localhost', 10000)
>> >
>> > I chose pyenet as a low level socket library, so protocol (UDP,
>> > Reliable UDP and other variants) can be selected with enet flags
>> > during creation of packet or sending it. This is my answer for need of
>> > both TCP and UDP protocols.
>> >
>> >> The network events then would have a connection property telling you
>> >> from which connection they came.
>> >
>> > I agree with idea of adding connection to network event. So summing
>> > up, it will look like this:
>> > e.type = NETWORK # event type
>> > e.connection # weakref of connection from which the packet comes
>> > e.channel # channel of connection
>> > e.packet # packet object
>> > e.packet_id # packet identifier
>> > e.net # packet type (to allow e.net == echo)
>> >
>> > 2012/6/21 Radomir Dopieralski <pygame@xxxxxxxxxxxx>
>> >>
>> >> On Wed, Jun 20, 2012 at 8:02 PM, Szymon Wróblewski <bluex0@xxxxxxxxx>
>> >> wrote:
>> >> > I focused currently on creating client api and not everything is
>> >> > complete
>> >> > yet, but client side could look like this:
>> >> > (same code with syntax highlighting: http://pastebin.com/CiypsKpC)
>> >> >
>> >> > import pygame
>> >> > import pygame_network
>> >> >
>> >> > pygame.init()
>> >> > # create connection
>> >> > pygame_network.connect('localhost', 10000)
>> >> > # connection overlay
>> >> > host = pygame_network.client.Host()
>> >> > # register new packet type
>> >> > # it will call pygame_network.packets.PacketManager.register()
>> >> > echo = pygame_network.register('echo', ('user', 'msg'))
>> >> > name = raw_input('name: ')
>> >>
>> >> I really hate to see the globals here. Wouldn't it be better to have
>> >> it something like this?
>> >>
>> >> connection = pygame_network.connect('localhost', 10000)
>> >> connection.register('echo', ('user', 'msg'))
>> >>
>> >> then you can connect to different servers with different protocols at
>> >> the same time.
>> >> The network events then would have a connection property telling you
>> >> from which connection they came.
>> >> You can also then close one of the connections independently from
>> >> others.
>> >> You would also probably want a separate 'protocol' object on which you
>> >> would register the messages, so
>> >> that you can reuse it for several connections.
>> >>
>> >> What do you think?
>> >>
>> >>
>> >> --
>> >> Radomir Dopieralski
>
>



--
Ryan Hope, M.S.
CogWorks Lab
Cognitive Science Department
Rensselaer Polytechnic Institute