Moved out renderer to being selected in engine constructor based on a parsed enum. Next is to have the renderer initialize in constructor, and probably make game into a templated parameter that does the same along with input processor

This commit is contained in:
2022-01-20 08:20:17 -05:00
parent 1a917af13c
commit bc6fa836b0
4 changed files with 43 additions and 19 deletions

View File

@@ -24,6 +24,11 @@
#define DEFAULT_SHOW_FPS false
#define DEFAULT_FONT_NAME "Consolas-Regular"
#define DEFAULT_FONT_SIZE 12
#define ENGINE_CONFIG_FILE "engine.toml"
enum RendererTypes : int {
SDL_HARDWARE = 0
};
struct EngineConfig {
unsigned int target_fps;
@@ -32,11 +37,12 @@ struct EngineConfig {
bool show_fps;
std::string window_title;
TextRenderDetails default_font;
RendererTypes selected_renderer;
};
class Engine {
public:
Engine(std::unique_ptr<Game> game, std::unique_ptr<Renderer> renderer,
Engine(std::unique_ptr<Game> game,
std::unique_ptr<InputProcessor> input_processor);
void start_loop();
static void load_config(const std::string& path, const std::function<void (toml::table)>& f);
@@ -49,16 +55,18 @@ private:
std::unique_ptr<Renderer> renderer = nullptr;
std::unique_ptr<InputProcessor> input_processor = nullptr;
std::chrono::time_point<std::chrono::system_clock> render_fps(std::chrono::time_point<std::chrono::system_clock> end, std::chrono::time_point<std::chrono::system_clock> lastframe);
void parse_config(const std::string& config_file_path);
void setup_renderer(RendererTypes rendering_engine);
};
class MissingGameException : public std::exception {
public:
const char *what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override;
[[nodiscard]] const char *what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override;
};
class MissingRendererException : public std::exception {
public:
const char *what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override;
[[nodiscard]] const char *what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override;
};