Skip to main content
edited title
Link
javaLover
  • 227
  • 1
  • 5

Place to store definition of "blueprint" of object (e.g. mesh)? ... in top header = bad compile time

Source Link
javaLover
  • 227
  • 1
  • 5

Place to store definition of "blueprint" of object (e.g. mesh)? ... in top header = bad compile time

In my game engine, here is my mesh factory :-

//GraphicFactory.h
class GraphicFactory{
    enum blueprint{
        TURRET_01,CUBE,GRASS    //a lot of things
    }
    void initialize();  
    BlueprintDatabase db;
}
//GraphicFactory.cpp
void GraphicFactory::initialize{ 
    db.add(TURRET_01,  very long definition about mesh e.g. material color ...);
    db.add(CUBE,       very long definition about mesh ....   );
}

To use, it is easy as :-

graphicFactory()->create(TURRET_01 /* happy ctrl+space */, position, rotation, scale);

Here, I have a problem about compile time:-

The GraphicFactory can be seen from most game systems
because they want to create some graphics.
Thus GraphicFactory.h must be included into every system's .cpp either directly or indirectly.

When one of the systems want a new type of mesh e.g. IRON_BOX,
I have to add IRON_BOX to blueprint in the GraphicFactory's header.
As a result, I have to recompile most of systems.

Question: Where should I store the declation / definition of mesh?
I also faces this issue for managing material, physic object, and game object.

My poor solution: Use string instead of enum - register by string and query by string.