Associate a texture to an object (from a data-model, not graphical point of view).
Posted
by
Raveline
on Game Development
See other posts from Game Development
or by Raveline
Published on 2011-03-01T14:52:54Z
Indexed on
2011/03/01
15:33 UTC
Read the original article
Hit count: 146
c++
|data-structure
I'm writing a roguelike where objects and floor can be made of different materials. For instance, let's say we can have a wooden chair, an iron chair, a golden chair, and so on.
I've got an Object class (I know, the name is terrible), which is more or less using a composite pattern, and a Material class. Material have different important properties (noise, color...). For the time being, there are 5 different instances of materials, created at the initialization of the game.
How would connect an instance of Object with one of the 5 instances of materials ? I see three simple solutions :
- Using a pointer. Simple and brutal.
- Using an integer material-id, then get the materials out of a table when engine manipulates the object for various purposes (display, attack analysis, etc.). Not very beautiful, I think, and not very flexible.
- Using an integer material-id, then get the materials out of a std::map. A bit more flexible, but still not perfect.
Do you see other possibilities ? If not, what would you choose (and why) ? Thanks in advance !
© Game Development or respective owner