Sign in to follow this  

Any Patterns there?

This topic is 4250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this