Removed some agame things; Added VSYNC

This commit is contained in:
2026-03-18 08:44:30 +01:00
parent def737316c
commit e4004bbfe8
16 changed files with 354 additions and 77 deletions

View File

@@ -7,7 +7,9 @@
namespace Game::AGame {
GAME_ENTITY(Background)
private:
Object::Sound mSound;
public:
void onWindowResized(int newWidth, int newHeight) override;
private:
Object::Sound mSound;
END_GAME_ENTITY()
}

View File

@@ -1,19 +0,0 @@
#pragma once
#include <object/entity.hpp>
#include <renderer/texture.hpp>
#include <renderer/font.hpp>
#include <object/sound.hpp>
namespace Game::AGame {
GAME_ENTITY(CamController)
public:
void onWindowResized(int newWidth, int newHeight) override {
mScreenW = newWidth;
mScreenH = newHeight;
}
private:
int mScreenW, mScreenH;
END_GAME_ENTITY()
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include <object/ui/uitextbox.hpp>
namespace Game::AGame {
class SampleTextBox : public Object::UITextBox {
using Object::UITextBox::UITextBox; // Inherit constructors
public:
~SampleTextBox() override = default;
void start() override {
// Call the base class start to initialize the text box
mZIndex = 1000; // Ensure it renders on top of most other entities
Object::UITextBox::start();
setText("Hello, World!");
mIsActive = false;
}
void update(float deltaTime) override {
// Call the base class update to handle input and text refreshing
Object::UITextBox::update(deltaTime);
}
};
}

View File

@@ -11,9 +11,23 @@
#include <game/input.hpp>
#include <unordered_map>
#include <memory>
#include <type_traits>
namespace Game {
using clock = std::chrono::steady_clock;
enum class GameStateEnum {
RUNNING,
PAUSED,
STOPPED
};
enum class SharedDataType {
STRING,
INT,
FLOAT,
BOOL
};
class GameManager {
public:
@@ -27,14 +41,77 @@ namespace Game {
int getTargetUpdatesPerSecond() { return mTargetUpdatesPerSecond; }
float getLastDelta() { return mLastDelta; }
static void setSharedData(const std::string& key, std::string data);
static std::string getSharedData(const std::string& key);
static void removeSharedData(const std::string& key);
template<typename T>
static void setSharedData(const std::string& key, T data);
template<typename T>
static T getSharedData(const std::string& key);
static void removeSharedData(const std::string& key, SharedDataType type);
static GameStateEnum getCurrentGameState() { return mCurrentGameState; }
static void setCurrentGameState(GameStateEnum newState) { mCurrentGameState = newState; }
private:
int mTargetUpdatesPerSecond = TARGET_UPDATE_RATE;
clock::time_point mLastUpdate;
static std::unordered_map<std::string, std::string> mSharedStrings;
static std::unordered_map<std::string, int> mSharedInts;
static std::unordered_map<std::string, float> mSharedFloats;
static std::unordered_map<std::string, bool> mSharedBools;
static GameStateEnum mCurrentGameState;
float mLastDelta = 0.f;
};
template<typename T>
void GameManager::setSharedData(const std::string& key, T data) {
if constexpr (std::is_same_v<T, std::string>) {
mSharedStrings[key] = data;
} else if constexpr (std::is_same_v<T, int>) {
mSharedInts[key] = data;
} else if constexpr (std::is_same_v<T, float>) {
mSharedFloats[key] = data;
} else if constexpr (std::is_same_v<T, bool>) {
mSharedBools[key] = data;
}
}
template<typename T>
T GameManager::getSharedData(const std::string& key) {
if constexpr (std::is_same_v<T, std::string>) {
auto it = mSharedStrings.find(key);
if (it != mSharedStrings.end()) {
return it->second;
} else {
return "";
}
} else if constexpr (std::is_same_v<T, int>) {
auto it = mSharedInts.find(key);
if (it != mSharedInts.end()) {
return it->second;
} else {
return 0;
}
} else if constexpr (std::is_same_v<T, float>) {
auto it = mSharedFloats.find(key);
if (it != mSharedFloats.end()) {
return it->second;
} else {
return 0.0f;
}
} else if constexpr (std::is_same_v<T, bool>) {
auto it = mSharedBools.find(key);
if (it != mSharedBools.end()) {
return it->second;
} else {
return false;
}
}
static_assert(
std::is_same_v<T, std::string> || std::is_same_v<T, int> ||
std::is_same_v<T, float> || std::is_same_v<T, bool>,
"Unsupported type for shared data"
);
return T{};
}
}