Add wrappers for SDL functions and structs
This commit is contained in:
parent
4277f4c818
commit
d180b8a5b4
18 changed files with 410 additions and 206 deletions
|
|
@ -1,17 +1,19 @@
|
|||
module;
|
||||
|
||||
#include <cassert>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
export module core.engine;
|
||||
|
||||
import config;
|
||||
import core.renderer;
|
||||
import core.window;
|
||||
import wrappers.sdl;
|
||||
|
||||
export namespace core
|
||||
{
|
||||
using Window = sdl::Window;
|
||||
|
||||
class Engine
|
||||
{
|
||||
// Whether this class is currently instantiated (to prevent multiple instances)
|
||||
|
|
@ -23,13 +25,16 @@ export namespace core
|
|||
Window window_;
|
||||
Renderer renderer_;
|
||||
|
||||
// Private constructor
|
||||
Engine(Window&& window, Renderer&& renderer)
|
||||
: window_{std::move(window)},
|
||||
renderer_{std::move(renderer)}
|
||||
{
|
||||
instantiated_ = true;
|
||||
}
|
||||
|
||||
public:
|
||||
Engine()
|
||||
{
|
||||
// Prevent the class from being instantiated multiple times
|
||||
assert(!instantiated_);
|
||||
instantiated_ = true;
|
||||
}
|
||||
Engine() = delete;
|
||||
|
||||
// No copy or move operations
|
||||
Engine(const Engine&) = delete;
|
||||
|
|
@ -42,6 +47,26 @@ export namespace core
|
|||
instantiated_ = false;
|
||||
}
|
||||
|
||||
static std::unique_ptr<Engine> create()
|
||||
{
|
||||
// Prevent the class from being instantiated multiple times
|
||||
assert(!instantiated_);
|
||||
|
||||
auto [sdl_window, sdl_renderer] = sdl::CreateWindowAndRenderer(
|
||||
config::get_window_title(),
|
||||
config::window_width,
|
||||
config::window_height,
|
||||
0
|
||||
);
|
||||
|
||||
return std::unique_ptr<Engine>(
|
||||
new Engine{
|
||||
std::move(sdl_window),
|
||||
Renderer{std::move(sdl_renderer)}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool keep_running() const
|
||||
{
|
||||
return keep_running_;
|
||||
|
|
@ -57,19 +82,8 @@ export namespace core
|
|||
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)
|
||||
bool handle_event(const sdl::Event* event)
|
||||
{
|
||||
if (event->type == SDL_EVENT_QUIT) {
|
||||
// Exit the application
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue