Refactor code into classes

This commit is contained in:
Lexi / Zoe 2025-11-17 21:17:45 +01:00
parent 0743e6dc62
commit 5c3e0e3a86
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
12 changed files with 584 additions and 190 deletions

95
src/core/engine.cppm Normal file
View file

@ -0,0 +1,95 @@
module;
#include <cassert>
#include <tuple>
#include <SDL3/SDL.h>
export module core.engine;
import config;
import core.renderer;
import core.window;
export namespace core
{
class Engine
{
// Whether this class is currently instantiated (to prevent multiple instances)
static bool instantiated_;
// If this is set to false, the application will exit
bool keep_running_ = true;
Window window_;
Renderer renderer_;
public:
Engine()
{
// Prevent the class from being instantiated multiple times
assert(!instantiated_);
instantiated_ = true;
}
// No copy operations
Engine(const Engine&) = delete;
Engine& operator=(const Engine&) = delete;
// Default move operations
Engine(Engine&&) = default;
Engine& operator=(Engine&&) = default;
~Engine()
{
instantiated_ = false;
}
bool keep_running() const
{
return keep_running_;
}
Window& get_window()
{
return window_;
}
Renderer& get_renderer()
{
return renderer_;
}
// TODO: Should this be moved to the constructor?
void initialize()
{
std::tie(window_, renderer_) = Window::create_window_and_renderer(
config::get_window_title(),
config::window_width,
config::window_height,
0
);
}
// Handles an SDL event. Returns true if the event has been handled.
bool handle_event(const SDL_Event* event)
{
if (event->type == SDL_EVENT_QUIT) {
// Exit the application
keep_running_ = false;
return true;
}
return false;
}
void update()
{
}
void shutdown()
{
}
};
bool Engine::instantiated_ = false;
}