Skip to content

Commit

Permalink
Game: Move main function into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelheilmann committed Sep 23, 2017
1 parent c432ac7 commit 62b1f99
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 66 deletions.
1 change: 1 addition & 0 deletions game/game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ xcopy /y "$(SolutionDir)external\SDL2_ttf-2.0.12\VisualC\external\lib\$(Platform
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\game\Main.cpp" />
<ClCompile Include="src\game\Module\AnimatedTiles.cpp" />
<ClCompile Include="src\game\Module\Fog.cpp" />
<ClCompile Include="src\game\Module\Water.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions game/game.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@
<ClCompile Include="src\game\Module\Weather.cpp">
<Filter>Game Sources\Module</Filter>
</ClCompile>
<ClCompile Include="src\game\Main.cpp">
<Filter>Game Sources</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\game\egoboo.h">
Expand Down
66 changes: 0 additions & 66 deletions game/src/game/Core/GameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,72 +575,6 @@ std::shared_ptr<PlayingState> GameEngine::getActivePlayingState() const
return std::dynamic_pointer_cast<PlayingState>(_currentGameState);
}

/**
* @brief
* The entry point of the program.
* @param argc
* the number of command-line arguments (number of elements in the array pointed by @a argv)
* @param argv
* the command-line arguments (a static constant array of @a argc pointers to static constant zero-terminated strings)
* @return
* EXIT_SUCCESS upon regular termination, EXIT_FAILURE otherwise
*/
int SDL_main(int argc, char **argv)
{
try
{
Ego::Core::System::initialize(std::string(argv[0]));
try
{
_gameEngine = std::make_unique<GameEngine>();

_gameEngine->start();
}
catch (...)
{
Ego::Core::System::uninitialize();
std::rethrow_exception(std::current_exception());
}
Ego::Core::System::uninitialize();
}
catch (const id::exception& ex)
{
std::cerr << "unhandled exception: " << std::endl
<< ex.to_string() << std::endl;

SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Unhandled Exception",
ex.to_string().c_str(),
nullptr);

return EXIT_FAILURE;
}
catch (const std::exception& ex)
{
std::cerr << "unhandled exception: " << std::endl
<< ex.what() << std::endl;

SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Unhandled asException",
ex.what(),
nullptr);

return EXIT_FAILURE;
}
catch (...)
{
std::cerr << "unhandled exception" << std::endl;

SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Unhandled Exception",
"Unknown exception type",
nullptr);

return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

uint32_t GameEngine::getCurrentUpdateFrame() const
{
return update_wld;
Expand Down
89 changes: 89 additions & 0 deletions game/src/game/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//********************************************************************************************
//*
//* This file is part of Egoboo.
//*
//* Egoboo is free software: you can redistribute it and/or modify it
//* under the terms of the GNU General Public License as published by
//* the Free Software Foundation, either version 3 of the License, or
//* (at your option) any later version.
//*
//* Egoboo is distributed in the hope that it will be useful, but
//* WITHOUT ANY WARRANTY; without even the implied warranty of
//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//* General Public License for more details.
//*
//* You should have received a copy of the GNU General Public License
//* along with Egoboo. If not, see <https://www.gnu.org/licenses/>.
//*
//********************************************************************************************
/// @author Johan Jansen
/// @author Michael Heilmann

#include "game/Core/GameEngine.hpp"
#include "game/GUI/UIManager.hpp"

/**
* @brief
* The entry point of the program.
* @param argc
* the number of command-line arguments (number of elements in the array pointed by @a argv)
* @param argv
* the command-line arguments (a static constant array of @a argc pointers to static constant zero-terminated strings)
* @return
* EXIT_SUCCESS upon regular termination, EXIT_FAILURE otherwise
*/
int SDL_main(int argc, char **argv)
{
try
{
Ego::Core::System::initialize(std::string(argv[0]));
try
{
_gameEngine = std::make_unique<GameEngine>();

_gameEngine->start();
}
catch (...)
{
Ego::Core::System::uninitialize();
std::rethrow_exception(std::current_exception());
}
Ego::Core::System::uninitialize();
}
catch (const id::exception& ex)
{
std::cerr << "unhandled exception: " << std::endl
<< ex.to_string() << std::endl;

SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Unhandled Exception",
ex.to_string().c_str(),
nullptr);

return EXIT_FAILURE;
}
catch (const std::exception& ex)
{
std::cerr << "unhandled exception: " << std::endl
<< ex.what() << std::endl;

SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Unhandled asException",
ex.what(),
nullptr);

return EXIT_FAILURE;
}
catch (...)
{
std::cerr << "unhandled exception" << std::endl;

SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Unhandled Exception",
"Unknown exception type",
nullptr);

return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

0 comments on commit 62b1f99

Please sign in to comment.