/*
	Copyright 2016, 2017 Michele "King_DuckZ" Santullo

	This file is part of MyCurry.

	MyCurry 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.

	MyCurry 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 MyCurry.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "sdlmain.hpp"
#include "gamescenebase.hpp"
#include "ingamescene.hpp"
#include "death_handler.h"
#include <cstdint>
#include <iostream>
#include <ciso646>

namespace {
	const uint16_t DEF_WIN_WIDTH = 640;
	const uint16_t DEF_WIN_HEIGHT = 480;
	const uint16_t REFERENCE_WIDTH = 800;
	const uint16_t REFERENCE_HEIGHT = 600;
	const char GameName[] = "MyCurry";

	void run_main_loop (curry::GameSceneBase& parGame) {
		parGame.prepare();
		do {
			parGame.exec();
		} while (not parGame.wants_to_quit());
		parGame.destroy();
	}
} //unnamed namespace

int main() {
	cloonel::SDLMain sdl_main(
		GameName,
		cloonel::ushort2(DEF_WIN_WIDTH, DEF_WIN_HEIGHT),
		cloonel::ushort2(REFERENCE_WIDTH, REFERENCE_HEIGHT)
	);

	int ret_val = 0;
	try {
		sdl_main.Init();
		std::cout << "Using renderer \"" << sdl_main.GetRendererName() << "\" ";
		std::cout << "and video driver \"" << sdl_main.GetVideoDriverName() << "\"\n";

		curry::IngameScene game(&sdl_main);
		run_main_loop(game);
	}
	catch (const std::runtime_error& e) {
		std::cerr << "Error during SDL2 initialization:\n";
		std::cerr << e.what() << std::endl;
		ret_val = 1;
	}

	std::cout << "Quitting now" << std::endl;
	return ret_val;;
}
