I'm making a 2D engine in C++, and I want to be able to supply a .dll and a .lib so that games can just include those and everything is fine and dandy.
I've looked at how Ogre does it, and it results in ugliness like this:
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
// Create application object
ShadowsApplication app;
try {
app.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
While my engine currently does this:
MAIN
{
Game* game = Game::Create();
Engine::Init();
game->Init();
while (Engine::running)
{
if (Engine::PreRender())
{
game->Update();
Engine::Render();
}
Engine::ShutDown();
return 0;
}
}
Which means a clean game looks like this:
class BouncingBalls : public Game
{
public:
BouncingBalls() { }
void Init();
void Update();
};
Game* Game::Create() { return (new BouncingBalls()); }
Now, one major drawback: because I'm defining main
in the engine instead of the game, I can't put all the necessary libraries in the engine. Every game has to load in a specific set of libraries, which is going to be hell when that list changes.
Is there a way to keep the syntax like this while also loading in the .lib's in the engine instead of the game?
Thanks in advance.
EDIT: It seems things were not clear. My eventual goal is to have a single Visual Studio project that contains all of the engine functions, which compiles to a .lib or a .dll (not a .exe). If someone wants to make a game, he can simply include Engine.lib in his project and Engine.dll in his project folder and get going.
It should be as easy as possible to start up a new project, without having to worry about low-level C++.