Originally Posted by
Perspective
I'm assuming psycho's diagram doesn't represent inheritance...
Oh, but it does .
Here's the basic setup that i'm talking about in code (albeit extremely condensed):
Code:
class C3dw{
private:
/*loader data here. arrays of structs and such*/
public:
int _3dwShaderID;
/*other data here*/
public:
C3dw(){
//init stuff
}
virtual ~C3dw(){
//delete stuff
}
char Load3DW(std::string filename, /*other args here*/);
void Render3DW(CTextureMgr *texMgr, CGlslMgr *glslMgr);
};
/* same idea for CMs3d and CQ3Bsp */
class CModel : C3dw,CMs3d,CQ3Bsp{
public:
MODEL_TYPE type;
Mat44 matrix;
Vec3 position, rotation, scale;
Vec3 min, max;
bool selected;
/*other data.*/
public:
void RenderModel(CTextureMgr *texMgr, CGlslMgr *glslMgr){
if(MODEL_TYPE==MODEL_3DW){
Render3DW(texMgr, glslMgr);
}
}
/*other funcs for calulating normals, tangents and stuff. call child counterparts like the render func*/
};
class CObject : CModel{
public:
int ID;
std::string name;
public:
void Position(Vec3 pos);
/*other funcs for matrix manipulation here*/
void Render(CTextureMgr *texMgr, CGlslMgr *glslMgr, Vec3 view){
glMultMatrixf(/*args*/);
RenderModel(texMgr, glslMgr);
}
};
/*not much to the staticmesh. light entity includes additional values like diffuse colour and stuff*/
class CStaticMesh : CObject{
public:
CStaticMesh(/*name, file, shader, texture, manager pointers, etc*/){
/*based on MODEL_TYPE, load model. in this example, with Load3DW()*/
}
};
class CWorld{
public:
int numObjects;
std::vector<CObject*> objects;
int numStaticMeshes;
std::vector<CStaticMesh*> staticMeshes;
public:
CWorld(){ /*init stuff*/ }
~CWorld(){ /*delete stuff*/ }
void Render(){
/*for each object, call objects[i]->Render(); (and other GL stuff)*/
}
void UpdatePhysics();
void AddStaticMesh(/*args*/){
staticMeshes.push_back(new CStaticMesh(/*args*/));
staticMeshes[numStaticMeshes]->ID = numStaticMeshes;
objects.push_back(staticMeshes[numStaticMeshes]);
numObjects++; numStaticMeshes++;
}
};
class CWorldMgr{
public:
/*vector of worlds and stuff*/
public:
/*functions to create and delete a world, and get a world ID here*/
void WorldGfx(CWorld *world, /*manager poninters*/){
world->Render(/*args*/);
}
/*funcs for physics and logic here*/
};
That should be enough code. I have anther class called CGfxCtrl that calls CWorldMgr::WorldGfx, passing the current world (tracked in CEngine) as a parameter. CEngine is created by the main application, which in it's contructor creates CGfxCtrl, as well as controllers for physics and stuff. These "controllers" are used for threading of each engine componant. Then in the application loop, I just call something like engine->Run(); which continues down the heirarchy to gfxCtrl->Run(), and so on. Viewport setup and that sort of thing is handled outside of the engine.
Needlessly complicated? Probably. But it works for me ;p.