On Thu, Mar 6, 2008 at 8:25 PM, Nathan <[EMAIL PROTECTED]> wrote: > I commonly run into this scenario, and I'm wondering what the "best" > pattern is for handling it: > > On my game client, I have collections of things. Often these things > need to access all the other things (for collision detection, mostly). > So I have a list of "other players", a list of rockets, a list of > "lines" which you can walk on, etc. Sometimes I make these lists > global with "global whateverlist" wherever I use it. Sometimes I > attach them to my window (I subclassed the window object, and the main > loop is in my subclassed window's run() method) and they reference > each other through self if both collections are attached to the > window. Sometimes I make the window itself a global var and access > lists attached to the window from lists outside the window that way. > Sometimes I pass the members of one collection as arguments to the > methods of the members of a different collection. And I'm sure I do > even stranger things than that, but that end up working. > > So, what's the "best" way to organize these kinds of things where the > members of one collection often need to iterate through the members of > other closely related collections? And I define best as "a reasonable > balance of elegance (understandability) and performance".
Oh! Oh! No, this is what was the really perplexing thing. In the case above I ought to just make everything members of the window and access eachother through self. The real complex thing that I was trying to figure out was the twisted interaction. Theres a twisted amp protocol instance that handles communication. But the protocol is a separate object from the window object. But the protocol objects receive messages requiring that action be taken on the collections belonging in the window. So right now I just made the window a global, and access it from within the protocol like that. But thinking to what I had to do in twisted to get two-way communications working, I suppose I could do something like: my_window.protocol_obj = protocol_obj protocol_obj.my_window = my_window ...and then each has a reference to the other. Very circular. ~ Nathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
