96 lines
2.2 KiB
Text
96 lines
2.2 KiB
Text
|
|
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;
|
||
|
|
}
|