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

Re: [pygame] Training Pong MVC



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 know how to messure it. I tried following:

class RedrawController:
def __init__(self, eventManager):
self.eventManager = eventManager
self.eventManager.RegisterListener(self)
self._clock = pygame.time.Clock()
def Notify(self, event):
"""
Redraw all updated surfaces
"""
if isinstance(event, RedrawEvent):
game.pong_static_group.draw(game.screen)
dirty_rects = game.pong_dynamic_group.draw(game.screen)
pygame.display.update(dirty_rects)
self._clock.tick()
pygame.display.set_caption(str(self._clock.get_fps()))



and in the CpuController.Run() I commentet out the two lines after the while keyword.
I do not know if this is the correct framerate. (putting the clock into the CPUController.Run() is not the right place because not all deliverd events are RedrawEvents).



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?)


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?) )

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


~DR0ID





Chris Ashurst schrieb:
Just to confirm: Yes, that's the tutorial.

It's a little confusing if you follow his example, but as long as you walk
away with the concept of having an event manager that listens for events
sent by controllers, you will also walk away with the fact that you won't
have to use the usual "while 1:" method of looping.

In fact, I would like to share my MVC Pong program, as I think it's been
simplified and commented enough to explain what's going on. It's at
http://telestatic.net/python/pong.py

I'm not claiming that it's the ultimate superior last-word in pygame
programming, or even of the MVC model, but it gets the message across :)


~Chris

-----Original Message-----
From: owner-pygame-users@xxxxxxxx [mailto:owner-pygame-users@xxxxxxxx]On
Behalf Of Laura Creighton
Sent: Tuesday, April 25, 2006 00:53
To: pygame-users@xxxxxxxx
Cc: lac@xxxxxxxxxx
Subject: Re: [pygame] Training



In a message of Mon, 24 Apr 2006 22:34:06 EDT, "R. Alan Monroe" writes:
As far as my personal extra 0.02 goes, I found the tutorial for using t
he
MVC model with Pygame incredibly useful.
URL?

Alan

I am not the original poster, but I suspect he or she means: http://sjbrown.ezide.com/games/writing-games.html

Laura




CONFIDENTIAL NOTICE: This email including any attachments, contains confidential information belonging to the sender. It may also be privileged or otherwise protected by work product immunity or other legal rules. This information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this emailed information is strictly prohibited. If you have received this email in error, please immediately notify us by reply email of the error and then delete this email immediately.