From dfc86452fc5b3bc229d0ac6151a5b3a36d3aea3a Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 30 Mar 2026 10:51:21 -0400 Subject: [PATCH] Had to fix the rendering so that each sprite is rendered separately in sprite_casting during the render phase. --- src/game/worldbuilder.cpp | 4 ++++ src/graphics/raycaster.cpp | 11 +++-------- src/graphics/raycaster.hpp | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/game/worldbuilder.cpp b/src/game/worldbuilder.cpp index 787b207..ee420ea 100644 --- a/src/game/worldbuilder.cpp +++ b/src/game/worldbuilder.cpp @@ -203,6 +203,10 @@ void WorldBuilder::configure_starting_items(DinkyECS::World &world) { auto healing = System::spawn_item(world, "REPAIR_KIT"); inventory.add("inv0", healing); + + healing = System::spawn_item(world, "REPAIR_KIT"); + inventory.add("inv1", healing); + world.make_constant(healing); } diff --git a/src/graphics/raycaster.cpp b/src/graphics/raycaster.cpp index 0956a09..ca800f6 100644 --- a/src/graphics/raycaster.cpp +++ b/src/graphics/raycaster.cpp @@ -121,7 +121,7 @@ inline void set_scale_position(sf::Sprite& sprite, sf::Vector2f& position, sf::V } -void Raycaster::sprite_casting() { +void Raycaster::sprite_casting(sf::RenderTarget& target) { auto& lights = $level.lights->lighting(); auto world = $level.world; $level.collision->distance_sorted($sprite_order, {(size_t)$pos_x, (size_t)$pos_y}, RENDER_DISTANCE); @@ -212,7 +212,6 @@ void Raycaster::sprite_casting() { sf::Vector2f scale{sprite_scale_w, sprite_scale_h}; sf::Vector2f position{x + origin.x * scale.x, y + origin.y * scale.y}; sf::IntRect in_texture{ {tex_x, tex_y}, {tex_render_width, texture_height}}; - shared_ptr effect = System::sprite_effect(rec.entity); if(effect) { @@ -231,7 +230,7 @@ void Raycaster::sprite_casting() { set_scale_position(*sf_sprite, position, scale, in_texture, origin); } - $sprites_to_render.emplace_back(sf_sprite, effect); + target.draw(*sf_sprite, effect.get()); } } } @@ -438,16 +437,12 @@ void Raycaster::update() { draw_ceiling_floor(); cast_rays(); draw_pixel_buffer(); - sprite_casting(); } // BUG: if target is a rendertarget then I can say it has to be the viewport only, then I can get rid of $screen_pos_x/y void Raycaster::render(sf::RenderTarget& target) { target.draw($view_sprite); - - for(auto [sprite, effect] : $sprites_to_render) { - target.draw(*sprite, effect.get()); - } + sprite_casting(target); } void Raycaster::update_sprite(DinkyECS::Entity ent, components::Sprite& sprite) { diff --git a/src/graphics/raycaster.hpp b/src/graphics/raycaster.hpp index 922eda9..d1038cf 100644 --- a/src/graphics/raycaster.hpp +++ b/src/graphics/raycaster.hpp @@ -21,7 +21,7 @@ struct CameraLOL { double target_plane_y = 0.0; }; -using SpriteRender = std::pair, std::shared_ptr>; +using SpriteRender = std::pair>; struct Raycaster { sf::Texture $view_texture; @@ -64,7 +64,7 @@ struct Raycaster { void cast_rays(); void draw_ceiling_floor(); void draw_pixel_buffer(); - void sprite_casting(); + void sprite_casting(sf::RenderTarget& target); void update(); void render(sf::RenderTarget& target);