ProtoTank/Game.hpp
2024-12-03 19:57:33 +01:00

70 lines
1.8 KiB
C++

#pragma once
#include <SFML/Graphics/RenderWindow.hpp>
#include "Engine/Graphics/UI.hpp"
#include "Engine/Graphics/DebugUI.hpp"
#include "Engine/Graphics/3DRenderer.hpp"
#include "Engine/Utils/Timers.hpp"
#define WNDSIZE_DEFAULT_W (1280)
#define WNDSIZE_DEFAULT_H (720)
#define W_RATIO (16.f / 9.f)
#define H_RATIO (9.f / 16.f)
#define TARGET_FPS (60)
typedef enum eGameStatus {
GAME_INIT,
GAME_RUNNING,
GAME_QUIT
} GAME_STATUS;
//TODO: Use thread for Update/Render instance
class Game final {
public:
static Game& getInstance(std::shared_ptr<sf::RenderWindow> mainWnd, bool dbgFlag) {
if (smInstance == nullptr)
smInstance = new Game(mainWnd, dbgFlag);
return *smInstance;
}
~Game() = default;
Game(Game&&) = default;
Game& operator= (Game&&) = default;
Game(Game const&) = delete;
Game& operator= (Game const&) = delete;
static void GetDefaultWindowSize(unsigned int& w, unsigned int& h) noexcept {
w = WNDSIZE_DEFAULT_W; h = WNDSIZE_DEFAULT_H;
}
GAME_STATUS Tick();
void EventMouseMoved(int _x, int _y);
void EventWindowSizeChanged(unsigned int w, unsigned int h);
private:
Game(std::shared_ptr<sf::RenderWindow>& mainWnd, bool dbgFlag) noexcept(false);
static Game* smInstance;
void Update();
void KeyboardInputsCheck();
void Render();
bool mbDbgModeEnabled;
std::unique_ptr<DebugUI> mDbgUI = nullptr;
SysTimer mSysTimer;
SysTimer mKeyEventTimer;
std::unique_ptr<SysTimer> mPerfsTimer = nullptr;
std::shared_ptr<sf::RenderWindow> mMainWindow;
std::shared_ptr<Graphic3DRenderer> mWorld3D;
std::unique_ptr<CockpitUI> mCockpitUI;
std::unique_ptr<WorldUI> mWorldUI;
sf::Vector2i mPrevMousePos = {0, 0};
};