diff --git a/src/assets.hpp b/src/assets.hpp index 34aa3ee..04eccb5 100644 --- a/src/assets.hpp +++ b/src/assets.hpp @@ -14,7 +14,8 @@ struct TextureAtlasLayout struct Texture { - // SDL_Texture* sdl_texture; + uint8_t* data; + uint32_t data_length; TextureAtlasLayout texture_atlas_layout; }; diff --git a/src/main.cpp b/src/main.cpp index 5ab7032..345f78e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "physics.hpp" #include "render.hpp" +#include #include void increment_ticks(entt::registry& registry) @@ -85,10 +86,11 @@ int main() PhysicsModule::RemoveCollisionMarker(registry); PhysicsModule::CollisionCheck(registry); - // SDL_RenderClear(sdl_handles.renderer); + Hall::Clear(0); RenderModule::RenderSprites(registry); RenderModule::RenderScore(registry); - // SDL_RenderPresent(sdl_handles.renderer); + Hall::SetCommandSwapBuffers(); + Hall::GetVSync(); } return 0; diff --git a/src/render.cpp b/src/render.cpp index 779221a..519e87f 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -5,6 +5,8 @@ #include "physics.hpp" #include "sprite.hpp" +#include + #include RenderModule::RenderModule(entt::registry& registry) @@ -13,47 +15,29 @@ RenderModule::RenderModule(entt::registry& registry) void RenderModule::RenderSprites(entt::registry& registry) { - // auto const& sdl_handles = registry.ctx().get(); auto const& game = registry.ctx().get(); auto sprites_view = registry.view(entt::exclude); auto background_view = registry.view(); - for (auto [entity, pos, size, sprite] : background_view.each()) - { + auto render_sprite = [](entt::entity entity, Position const& pos, Size const& size, Sprite const&sprite){ TextureAtlasLayout layout = sprite.texture->texture_atlas_layout; uint8_t row = sprite.texture_atlas_index / layout.columns; uint8_t column = sprite.texture_atlas_index % layout.columns; - // SDL_FRect srcrect{static_cast(column * layout.width), - // static_cast(row * layout.height), - // static_cast(layout.width), - // static_cast(layout.height)}; + // Problemchen: Wir können die Sprites nicht strecken... hat keiner Interpolation + // implementiert? + Hall::Draw(reinterpret_cast(sprite.texture->data), // Das ist 100% UB + column * layout.width, + row * layout.height, + pos.x, + pos.y, + layout.width, + layout.height, + sprite.texture->data_length); + }; - // SDL_FRect dstrect{static_cast(pos.x), - // static_cast(pos.y), - // static_cast(size.w), - // static_cast(size.h)}; - - // SDL_RenderTexture(sdl_handles.renderer, sprite.texture->sdl_texture, &srcrect, &dstrect); - } - - for (auto [entity, pos, size, sprite] : sprites_view.each()) - { - TextureAtlasLayout layout = sprite.texture->texture_atlas_layout; - uint8_t row = sprite.texture_atlas_index / layout.columns; - uint8_t column = sprite.texture_atlas_index % layout.columns; - // SDL_FRect srcrect{static_cast(column * layout.width), - // static_cast(row * layout.height), - // static_cast(layout.width), - // static_cast(layout.height)}; - - // SDL_FRect dstrect{static_cast(pos.x), - // static_cast(pos.y), - // static_cast(size.w), - // static_cast(size.h)}; - - // SDL_RenderTexture(sdl_handles.renderer, sprite.texture->sdl_texture, &srcrect, &dstrect); - } + background_view.each(render_sprite); + sprites_view.each(render_sprite); } void RenderModule::RenderScore(entt::registry& registry)