Any Patterns there?

Started by
6 comments, last by Deyja 17 years, 11 months ago
Hello How can I best implement a class model where instances of the same class share the same data resource or lets say a variable/structure. I thought of using statically declared types but this will not work for inheritance asd the newly dervide classes will not have a separate static memeber, which is not practical to create for each dervied class a different static memebr, ... not what I intened to do. The question is there any design-pattern solution that address this issue? To give a clear example: a class reperesnts a general momnster in a game which is the top for all (soldiers, zombies, maniacs, gladiators, ...) BUT an instance of a derived class should use the same texture and model created for that class once, no duplication. Thanks.
Advertisement
Broken.

Monsters/Items/Objects should not care what their representation [model/image/sound] is.
Broken.

Entity Representation classes I meant.
My apologies then.

In that case, you're going to need to provide a more concrete example.
Flyweight, often used in character editors and particle systems. It can enhance performance dramatically as the number of unique objects that share a single conceptual state increases. (It's mostly a performance benefit, as such you should profile to see if the added complexity is worth it in your design)
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
SkinnedMesh class

MonsterRepresent class

GuardRepresent CivilianRepresent classes

For Guard and Civilian class there's a one model uploaded once for each.

Then all objects can access the two models.

The model store or information should be declared somehow in an upper level class so the derived ones should not care about adding such info. And hence the related functions are abstracted in the parent class (SkinnedMesh)

BTW the Flyweight pattern solves something comopletely diffrent than what I'm talking about.

Hope this help.
No, that doesn't much help.

Why are guard and civilian derived from Monster? What different functionality do they provide? What sort of classes derive from guard/civilian, and why are statics [or a shared_ptr return from a factory] not viable?
Why can't the base class just hold a single pointer to some sort of model class? You could shoehorn unigue statics into every derived type with some template trickery sure, but you'd probably use much more memory than that one pointer you're trying to eliminate.

This topic is closed to new replies.

Advertisement