clooneljump/src/main.cpp

75 lines
2.4 KiB
C++
Raw Normal View History

2014-02-25 10:04:16 +00:00
/*
Copyright 2014 Michele "King_DuckZ" Santullo
This file is part of CloonelJump.
CloonelJump 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.
CloonelJump 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 CloonelJump. If not, see <http://www.gnu.org/licenses/>.
*/
2014-01-09 23:04:39 +00:00
#include "CloonelJumpConfig.h"
2014-02-08 22:11:26 +00:00
#include "sdlmain.hpp"
#include "physicsfswrapper.hpp"
#include "gameplaysceneclassic.hpp"
2014-03-06 10:43:28 +00:00
#include "vector.hpp"
2014-02-08 22:11:26 +00:00
#include <iostream>
2014-01-09 23:04:39 +00:00
#include <stdexcept>
#include <ciso646>
2014-03-28 09:50:33 +00:00
#include <cstdlib>
#include <ctime>
2014-01-09 23:04:39 +00:00
namespace {
2014-03-28 09:50:33 +00:00
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void RunMainLoop (cloonel::GameplaySceneClassic& parGame) {
parGame.Prepare();
do {
parGame.Exec();
} while (not parGame.WantsToQuit());
parGame.Destroy();
}
} //unnamed namespace
2014-03-28 09:50:33 +00:00
///------------------------------------------------------------------------------
///following http://twinklebeardev.blogspot.co.uk/2012/07/lesson-1-hello-world.html
2014-03-28 09:50:33 +00:00
///------------------------------------------------------------------------------
int main (int, char* parArgv[]) {
2014-03-28 09:50:33 +00:00
#if defined(NDEBUG)
std::srand(static_cast<unsigned int>(std::time(nullptr)));
#else
std::srand(static_cast<unsigned int>(DEF_RANDOM_SEED));
#endif
2014-01-09 23:04:39 +00:00
std::cout << GameName << " v" << GameVersionMajor << "." << GameVersionMinor << std::endl;
int retVal = 0;
2014-03-06 10:43:28 +00:00
cloonel::SDLMain sdlmain(GameName, cloonel::ushort2(DEF_WIN_WIDTH, DEF_WIN_HEIGHT), cloonel::ushort2(REFERENCE_WIDTH, REFERENCE_HEIGHT));
2014-01-09 23:04:39 +00:00
try {
cloonel::PhysicsFSWrapper physfs(parArgv[0]);
physfs.Append(GAME_BASE_PATH "/resources/", "resources");
2014-02-08 22:11:26 +00:00
sdlmain.Init();
std::cout << "Using renderer \"" << sdlmain.GetRendererName() << "\"\n";
cloonel::GameplaySceneClassic game(&sdlmain);
RunMainLoop(game);
2014-01-09 23:04:39 +00:00
}
catch (const std::runtime_error& e) {
std::cerr << "Error during SDL2 initialization:\n";
std::cerr << e.what() << std::endl;
retVal = 1;
2014-01-09 23:04:39 +00:00
}
std::cout << "Quitting now" << std::endl;
return retVal;
2014-01-09 23:04:39 +00:00
}