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

Re: [pygame] Training Pong MVC



DR0ID <dr0id@xxxxxxxxxx>:

> Hi
>
> Thanks for your tutorial. I'm fascinated by the MVC model, because it
> seems tu run very fast. I wonder, what framerates this game has but dont

Although it is simply wrong, if someone writes, that you can get rid of the
common 'while 1:' event loop. It's still there, just packed in the
CPUController class.

> Some questions:
>
> In the EventManager there ist a self.eventQueue = [] which is not used
> and gave me the idea and question:
> Is it easy to run a controller or any other component in a different
> thread that stuffs the eventmanager's eventqueue? (should be threadsafe
> + EventManager has to change a bit for that) (ok running every component
> in a different thread should be possible or is it not?)

The thread safety can cause several issues, especially, if objects of
various threads process the same event at the same time (concurring
operations could take place). Simon Wittber wrote a nice event management
system[0], which seems to allow concurring operations (no idea, if it uses
threads).

> In your EventManager all registered listners get all events, also if
> they do not use them all. Would it not be a bit slow if there are many
> objects and many events to dispatch? Would it be better to only notify a
> object if it has registered for the event type to dispatch? (ok then you
> have to check befor dispatching and makes things a bit more complicatet
> perhaps using a dict like {eventtype:[listners], ....} (also a weakref
> list?) )

Yes, the scalability goes down the more objects are processed, if you are
using simple lists. Although you only will notice a visible slowdown with
a _lots_ of objects or lots of generated events.
I tend to use separate queues per event type, on which objects register
themselves[1]. It has some runtime overhead of memory, but turns out to be
much faster for my needs.

>
> In a complexer application there can be many more different events, right?

Yes, although this depends on the application and its design. GUI
applications and toolkits[2] for example often have tons of different
events, which will be dispatched (mouse movement events, keyboard input,
interface responses, ...).

[0] http://cheeseshop.python.org/pypi/FibraNet
[1] http://ocemp.sourceforge.net/gui.html
[2] namely PGU, PyUI/2, OcempGUI or non-pygame ones like Gtk+, Qt, et al.

Regards
Marcus