0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 05:43:43 +00:00

Merge branch 'game-registration-fix' into dev

This commit is contained in:
Benedikt Galbavy 2025-06-02 23:27:08 +02:00
commit eff959d11e
4 changed files with 17 additions and 27 deletions

View File

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

View File

@ -1,10 +1,7 @@
#pragma once
#include <cassert>
#include <iostream>
#include <map>
#include <functional>
#include <string>
#include <stdexcept>
#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; }
);
};
};
}