#include #include #include #include #include "icon.h" #include "Engine/Misc/Logger.hpp" #include "Game.hpp" static std::shared_ptr InitWindow(unsigned int width, unsigned int height, bool fullscreen); int main(int argc, char** argv) { Logger& log = Logger::getInstance(); log.PrintInfo(LOGGER_MSG_FT("Create main window")); std::shared_ptr mainWindow = nullptr; try { mainWindow = InitWindow(1280, 720, false); } catch (const std::exception& ex) { log.PrintCritical(std::string(ex.what())); return EXIT_FAILURE; } log.PrintInfo(LOGGER_MSG_FT("Create game instance")); #ifdef DEBUG Game& arcadeGame = Game::getInstance(mainWindow, true); #else Game& arcadeGame = Game::getInstance(mainWindow, false); #endif GAME_STATUS status = GAME_INIT; for ( ;; ) { sf::Event event; while (mainWindow->pollEvent(event)) { switch (event.type) { case sf::Event::Closed: mainWindow->close(); break; case sf::Event::Resized: //TODO: Recreate window related resource //event.size.width //event.size.height break; //case sf::Event::LostFocus: // EventSuspending(); // break; //case sf::Event::GainedFocus: // EventResuming(); // break; default: break; } // Focus only actions if (mainWindow->hasFocus()) { switch (event.type) { case sf::Event::MouseMoved: arcadeGame.EventMouseMoved(event.mouseMove.x, event.mouseMove.y); break; default: break; } } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { mainWindow->close(); status = GAME_QUIT; } status = arcadeGame.Tick(); if (status == GAME_QUIT) break; } log.PrintInfo(LOGGER_MSG_FT("Bye bye!")); return EXIT_SUCCESS; } static std::shared_ptr InitWindow(unsigned int width, unsigned int height, bool fullscreen) { // Create default game window sf::ContextSettings sWindowSettings; sWindowSettings.depthBits = 0; sWindowSettings.stencilBits = 0; sWindowSettings.antialiasingLevel = 8; sWindowSettings.sRgbCapable = true; sf::Uint32 wndStyle = sf::Style::Close | sf::Style::Titlebar; if(fullscreen) wndStyle = wndStyle | sf::Style::Fullscreen; auto wnd = std::make_shared( sf::VideoMode(width, height), "ProtoTank", wndStyle, sWindowSettings ); if (wnd == nullptr) throw std::runtime_error("Failed to create the window"); wnd->setVerticalSyncEnabled(false); // Never use simultaneously with framerate limiter wnd->setFramerateLimit(60); // Never use simultaneously with VSync wnd->setKeyRepeatEnabled(false); wnd->setMouseCursorVisible(true); wnd->setIcon(64, 64, _aicon_bin); return wnd; }