0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 10:13:42 +00:00

Fixed approach to registering Game implementation

This commit is contained in:
Benedikt Galbavy 2025-06-02 23:02:13 +02:00
parent 2ff579dd39
commit 4404936dfd
4 changed files with 17 additions and 27 deletions

View File

@ -1,5 +1,9 @@
#pragma once #pragma once
#include <cstdint>
#include <optional>
#include <string>
class GameInternal; class GameInternal;
// TODO: add managers here // TODO: add managers here

View File

@ -1,10 +1,7 @@
#pragma once #pragma once
#include <cassert> #include <cassert>
#include <iostream>
#include <map>
#include <functional> #include <functional>
#include <string>
#include <stdexcept> #include <stdexcept>
#include "Game.h" #include "Game.h"

13
include/GameRegistrar.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "GameFactory.h"
namespace vego {
template<typename GameType>
struct GameRegistrar {
GameRegistrar() {
static_assert(std::is_base_of<Game, GameType>::value, "Your class must inherit from Game");
GameFactory::instance().registerClass([]() { return new GameType(); });
}
};
}

View File

@ -1,24 +0,0 @@
#pragma once
#include "GameFactory.h"
namespace vego {
template<typename T>
class GameRegistryHelper {
public:
[[deprecated("GameRegistryHelper() does not take a className anymore")]]
GameRegistryHelper(const std::string& className) {
static_assert(std::is_base_of<Game, T>::value, "Your class must inherit from Game");
GameFactory::instance().registerClass(
[]() -> Game* { return new T; }
);
};
GameRegistryHelper() {
static_assert(std::is_base_of<Game, T>::value, "Your class must inherit from Game");
GameFactory::instance().registerClass(
[]() -> Game* { return new T; }
);
};
};
}