I'm building a simple 2D Engine, and I would like some input on my idea for the engine structure and also possibly other ideas that may be better.
Currently I have a header file which is used everywhere in my engine. It defines things that are universal such as struct Point or struct Image and other things such as enums and all that jazz.
Next I have an Engine class that's a singleton. It houses everything that is my engine and is the main interface through which you work with.
The final pieces are the important components that relate to different sections of the engine. They are their own class and can be accessed through gets in my Engine class. Here are some examples.
VideoInterface
- Handles rendering.
ObjectInterface
- Deals with the objects and instances
There is a lot more that is yet implemented such as input, networking, logic, sound, etc.. etc.
Here is an example of my main.cpp
Engine* g_pEngine;
ObjectInterface* g_pObjectInterface;
VideoInterface* g_pVideoInterface;
void MyStepFunc( double dTickStartTime )
{
printf( "Render Speed: %fFPS\nGame Speed: %fFPS\n\n", g_pVideoInterface->GetFPS(), g_pEngine->GetGameSpeed() );
}
int main()
{
//Set up Engine
g_pEngine = Engine::GetEngine();
g_pObjectInterface = g_pEngine->GetObjectInterface();
g_pVideoInterface = g_pEngine->GetVideoInterface();
g_pEngine->SetStepFunc( &MyStepFunc );
//Engine initialization
g_pEngine->Init( 640, 480, 640, 480, (char*)"Test Engine" );
unsigned int uiObject = g_pObjectInterface->CreateObject();
g_pObjectInterface->SetObjectTexture( (char*)"test.png", uiObject, 64, 64 );
g_pObjectInterface->CreateAnimation( uiObject, 2 );
g_pObjectInterface->AddAnimationFrame( uiObject, 0, Point( 0, 0 ), Point( 32, 64 ) );
g_pObjectInterface->AddAnimationFrame( uiObject, 1, Point( 32, 64 ), Point( 64, 64 ) );
unsigned int uiInstance = g_pObjectInterface->CreateInstance( uiObject );
g_pObjectInterface->SetPosition( uiInstance, CluPoint( 0, 0 ) );
//Engine main game loop
g_pEngine->GameLoop();
g_pEngine->Drop();
delete g_pEngine;
return -1;
}
What it does right now is create the game with a window of x and y size, x and y resolution, and a name. It then creates an object and creates an animation and then creates an instance of that object and set's the instances position.
g_pEngine->SetStepFunc( &MyStepFunc ); allows the setting of hooks. This hook is called every game step( 1/60th of a second ).
I just wanted input on if this was a good way of doing it, or if there is a better way that would allow more control by game developers. For example I can see just hooks being a limiting factor so I may try to code with polymorphism in mind and allower setter functions for the various interfaces.