object oriented design

Started by
4 comments, last by NIm 17 years, 7 months ago
I'm working on a game, and I've decided to actually plan it out this time. Instead of starting with libraries and graphics, I'm starting with the organization of the game, and putting raphics and physics in later, in the places that were left for them. My question is this: should a model be stored unde rthe object it belongs to, or in a seperate place in the graphics enngine?
Advertisement
In the engine that we use ( Crystal Space ) the models are stored as something called "Factories" ( example for Mesh Object Factory). When then use this factory to create instances of a model we are looking for. We preload all of the model factories at startup and create instances as we need them. Our game 'objects' keep a pointer to their 'instance' of that model.
Sometimes this is called a 'mesh exemplar' method - the primary mesh(es) (factory) in Crystalspace terms is not deformed by animation, and each instance carries its own animation states. Basically you don't want to carry around a whole new model for each instance. This is especially true if you're using a vertex animation (mesh tweening) method - they get heavy.

Winterdyne Solutions Ltd is recruiting - this thread for details!
Quote:Original post by NIm
I'm working on a game, and I've decided to actually plan it out this time. Instead of starting with libraries and graphics, I'm starting with the organization of the game, and putting raphics and physics in later, in the places that were left for them. My question is this: should a model be stored unde rthe object it belongs to, or in a seperate place in the graphics enngine?


Absolutely elsewhere. The reason is that you may have 100 of some object, and keeping 100 identical models around is crazy. You might want to either let your rendering code figure it out (for example, it might go "this is a fighter jet, and it's on fire, so let's use the model that came from jet_on_fire.mds"), or you could store the model as just a reference ID to a model factory or a pointer.
Each object should store a reference to its model. There should be some kind of model repository (one model per model file? per object class?) in which the models are actually kept in memory; as others have said, if you have ten cars that use the same model, you only want one copy of that model loaded.
Thank you very much! You've all helped me. I will keep a list of models as part of the graphics system, and each object will keep a reference for which model it needs at which animation frame.

This topic is closed to new replies.

Advertisement