Files
letnik3koncni-prap/include/window/window.hpp
2026-03-14 22:27:54 +01:00

46 lines
1.3 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;
size_t mFrameCount = 0;
std::chrono::steady_clock::time_point mLastFPSTime;
};
}