Add wrappers for SDL functions and structs

This commit is contained in:
Lexi / Zoe 2025-11-23 21:50:57 +01:00
parent 4277f4c818
commit d180b8a5b4
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
18 changed files with 410 additions and 206 deletions

View file

@ -8,7 +8,8 @@ export module game.game;
import core.engine;
import core.renderer;
import game.sprite;
import resources.texture;
import wrappers.sdl;
import wrappers.sdl_image;
export namespace game
{
@ -36,7 +37,8 @@ export namespace game
void initialize()
{
auto texture = resources::Texture::load_from_file(
// TODO: Texture should be a reference/pointer to an object managed by a ResourceManager or similar.
auto texture = sdl_image::LoadTexture(
engine_.get_renderer().get_sdl_renderer(),
"assets/neocat.png"
);
@ -45,7 +47,7 @@ export namespace game
}
// Handles an SDL event. Returns true if the event has been handled.
bool handle_event(const SDL_Event* event) const
bool handle_event(const sdl::Event* event) const
{
if (event->type == SDL_EVENT_MOUSE_MOTION) {
sprite_->move(
@ -64,9 +66,9 @@ export namespace game
void render() const
{
const auto& renderer = engine_.get_renderer();
renderer.clear();
renderer.start_frame();
sprite_->draw(renderer);
renderer.present();
renderer.finish_frame();
}
void shutdown()

View file

@ -1,13 +1,12 @@
module;
#include <string>
#include <utility>
#include <SDL3/SDL.h>
export module game.sprite;
import core.exceptions;
import core.renderer;
import resources.texture;
import wrappers.sdl;
// TODO: Move this to a different namespace (core, drawing, ...?)
export namespace game
@ -15,12 +14,12 @@ export namespace game
class Sprite
{
// TODO: Texture should be a reference/pointer to an object managed by a ResourceManager or similar.
resources::Texture texture_;
SDL_FRect dest_rect_{0, 0, 0, 0};
sdl::Texture texture_;
sdl::FRect dest_rect_{0, 0, 0, 0};
public:
explicit Sprite(
resources::Texture&& texture,
sdl::Texture&& texture,
const int width,
const int height
)
@ -48,7 +47,7 @@ export namespace game
void draw(const core::Renderer& renderer) const
{
renderer.render_texture(texture_.get_sdl_texture(), nullptr, &dest_rect_);
renderer.render_texture(texture_, nullptr, &dest_rect_);
}
};
}