Skip to main content
GameDev.net gamedev.net
🔒 Locked

annoying aspect of observer/multicast pattern...

Started by maximAL May 20, 2005 at 12:20 PM 1 replies 1.3k views
Original Post
maximAL
maximAL
i'm trying get the design of my "engine" clean and theres something i don't like but don't know how to solve... problem: i got plenty of game objects. think of sth. in the scale over 200.000. no, i'm not trying to process them every frame. most of them are static and require attention only on con/de-struction. most of the rest also doesn't need to be processed that often, maybe every few seconds. i itentionly thought of the observer pattern to hook them up with graphis, sound and the like. since this would create an extreme memory overhead (just think of all the references to observes the small suspects had to carry!) i also considered the mulitcast pattern, what basically means a message-based design. sounds like what i need, but one thing just seems "wrong" for both ways: how to track the events? say i got an object with 3 relevant values, whose changes yield to creating an event respectively notifying the observers. i had to implement this mechanism in every "Set()" method. for every new class i introduce. what sucks. it looks like lots of similar, redundant code and it's very prone to mistakes. how to get rid of this? i already thought of some kind of templatized GuardedOBject that implements the notification process. but this way, i could only guard predefined intefaces, for examlple only some "Set" method every object had to use (inluding exactly the same params) - not very good. maybe i missed sth, i've not been working with templates for too long... thoughts?
------------------------------------------------------------Jawohl, Herr Oberst!
haora
haora
I'm really new to patterns, but have you considered using the "FlyWeight" pattern to manage so many objects???

It is supposed to be very efficient when it comes to managing lots and lots of objects...

Well, my 2 cents...
maximAL
maximAL
Quote:
Original post by haorahave you considered using the "FlyWeight" pattern to manage so many objects???


yes, i have. i'm not sure if i really should use it. after all, every flyweight needs a pointer to the actual object. a pointer is 32bit and depending on the object it might be not smaller than a "standalone" object (if you take char & shorts into consideration).
and after all, that's quite another aspect and wouldn't solve my problem.

edit: actually the flyweight pattern brought me to an idea...
in the first moment, when i only thought about the software engineering aspects of the project and ignored the cruel reality of memory & runtime-overhead, i wanted to maintain an own list of observers for every single object. this would ease design a lot, because i'd get rid of mediators between subjects and objects. but the overhead seemed quiet unreasonable, especially since the vast majority of objects would have the same observers.
but actually i could use the flyweight pattern on the observer list (instead of using it on the game objects themselves). changing the observer list would be pretty expensive, but i would take very few memory and - most important - work as if there was a unique one for every object...

why do i always get productive when it's time to sleep...and when the holidays are just about over? darn...

[Edited by - maximAL on May 20, 2005 4:44:56 PM]
------------------------------------------------------------Jawohl, Herr Oberst!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.