50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3_ttf/SDL_ttf.h>
|
|
#include <iostream>
|
|
#include <thread>
|
|
#include <utils.hpp>
|
|
#include <renderer/renderer.hpp>
|
|
#include <state/gamestate.hpp>
|
|
#include <game/gamemanager.hpp>
|
|
#include <audio/audio.hpp>
|
|
#include <chrono>
|
|
#include <mutex>
|
|
|
|
namespace Game::Window {
|
|
class Window {
|
|
public:
|
|
Window();
|
|
DISABLE_COPY_AND_MOVE(Window)
|
|
~Window();
|
|
|
|
bool init(int width, int height, const std::string& title);
|
|
void run();
|
|
|
|
void setTargetFPS(int fps) { mTargetFPS = fps; }
|
|
int getTargetFPS() { return mTargetFPS; }
|
|
|
|
static SDL_Window* getSDLWindowBackend() { std::scoped_lock lock(sMutex); return sWindowBackend; }
|
|
|
|
Renderer::Renderer* getRenderer() { std::scoped_lock lock(mMutex); return &mRenderer; }
|
|
|
|
private:
|
|
mutable std::mutex mMutex;
|
|
static std::mutex sMutex;
|
|
static inline SDL_Window* sWindowBackend = nullptr;
|
|
SDL_Window* mWindow;
|
|
Renderer::Renderer mRenderer;
|
|
Game::GameManager mGameManager;
|
|
std::jthread mGameThread;
|
|
bool mRunning;
|
|
int mTargetFPS = TARGET_FPS;
|
|
int mEffectiveFrameCap = TARGET_FPS;
|
|
#if DEBUG
|
|
size_t mTelemetryFrameCount = 0;
|
|
double mTelemetryFrameTimeMsTotal = 0.0;
|
|
#endif
|
|
std::chrono::steady_clock::time_point mTelemetryStart = std::chrono::steady_clock::now();
|
|
};
|
|
} |