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:
parent
2ff579dd39
commit
4404936dfd
@ -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
|
||||||
|
|||||||
@ -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
13
include/GameRegistrar.h
Normal 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(); });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -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; }
|
|
||||||
);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user