diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-28 09:52:39 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-29 11:49:19 +0200 |
commit | 142af4f233cb5eb0b17689226c586b48509f0474 (patch) | |
tree | 5da9322ab1f54753917829bd4104f322fdfce11e /main | |
parent | c3d79fdf679a749d961719ad662b9f46b0f26ec1 (diff) |
split off common code in main draw loop
Diffstat (limited to 'main')
-rw-r--r-- | main/draw.cpp | 74 | ||||
-rw-r--r-- | main/main-impl.hpp | 2 | ||||
-rw-r--r-- | main/projection.cpp | 1 |
3 files changed, 40 insertions, 37 deletions
diff --git a/main/draw.cpp b/main/draw.cpp index 802a4e9d..bf5dfb87 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -1,6 +1,7 @@ #include "main-impl.hpp" #include "src/tile-constants.hpp" #include "floormat/app.hpp" +#include "floormat/draw-bounds.hpp" #include "src/camera-offset.hpp" #include "src/anim-atlas.hpp" #include "main/clickable.hpp" @@ -94,23 +95,11 @@ void main_impl::drawEvent() redraw(); } -void main_impl::draw_world() noexcept +template<typename Function> +void main_impl::draw_world_0(const Function& fun, const draw_bounds& draw_bounds, const z_bounds& z_bounds, Vector2i window_size) { - const auto [z_min, z_max, z_cur, only] = app.get_z_bounds(); - const auto [minx, maxx, miny, maxy] = get_draw_bounds(); - const auto sz = window_size(); - - fm_debug_assert(1 + maxx - minx <= 8); - fm_debug_assert(1 + maxy - miny <= 8); - - arrayResize(_clickable_scenery, 0); -#ifdef FM_USE_DEPTH32 - framebuffer.fb.clearDepth(0); -#else - GL::defaultFramebuffer.clearDepth(0); -#endif - GL::Renderer::enable(GL::Renderer::Feature::DepthTest); - GL::Renderer::setDepthMask(true); + const auto [z_min, z_max, z_cur, only] = z_bounds; + const auto [minx, maxx, miny, maxy] = draw_bounds; for (int8_t z = z_max; z >= z_min; z--) { @@ -130,34 +119,45 @@ void main_impl::draw_world() noexcept bind(); const with_shifted_camera_offset o{_shader, ch, {minx, miny}, {maxx, maxy}}; - if (check_chunk_visible(_shader.camera_offset(), sz)) + if (check_chunk_visible(_shader.camera_offset(), window_size)) { - _ground_mesh.draw(_shader, c); - _wall_mesh.draw(_shader, c); + fun(c, x, y, z); } } } +} - GL::Renderer::setDepthMask(false); - for (int8_t z = z_min; z <= z_max; z++) - for (int16_t y = miny; y <= maxy; y++) - for (int16_t x = minx; x <= maxx; x++) - { - if (only && z != z_cur) - _shader.set_tint({1, 1, 1, 0.75}); - else - _shader.set_tint({1, 1, 1, 1}); +void main_impl::draw_world() noexcept +{ + const auto z_bounds = app.get_z_bounds(); + const auto draw_bounds = get_draw_bounds(); + const auto sz = window_size(); - const chunk_coords_ pos{x, y, z}; - auto* cʹ = _world.at(pos); - if (!cʹ) - continue; - auto& c = *cʹ; - const with_shifted_camera_offset o{_shader, pos, {minx, miny}, {maxx, maxy}}; - if (check_chunk_visible(_shader.camera_offset(), sz)) - _anim_mesh.draw(_shader, sz, c, _clickable_scenery, _do_render_vobjs); - } + fm_assert(1 + draw_bounds.maxx - draw_bounds.minx <= 8); + fm_assert(1 + draw_bounds.maxy - draw_bounds.miny <= 8); + + arrayResize(_clickable_scenery, 0); +#ifdef FM_USE_DEPTH32 + framebuffer.fb.clearDepth(0); +#else + GL::defaultFramebuffer.clearDepth(0); +#endif + GL::Renderer::enable(GL::Renderer::Feature::DepthTest); + GL::Renderer::setDepthMask(true); + + draw_world_0([&](chunk& c, int16_t, int16_t, int8_t) { + _ground_mesh.draw(_shader, c); + _wall_mesh.draw(_shader, c); + }, + draw_bounds, z_bounds, sz); + + draw_world_0([&](chunk& c, int16_t, int16_t, int8_t) { + _anim_mesh.draw(_shader, sz, c, _clickable_scenery, _do_render_vobjs); + }, + draw_bounds, z_bounds, sz); + + GL::Renderer::setDepthMask(false); _shader.set_tint({1, 1, 1, 1}); GL::Renderer::setDepthMask(true); diff --git a/main/main-impl.hpp b/main/main-impl.hpp index 25b3e4ed..3fb8bac5 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -149,6 +149,8 @@ private: void recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept; void draw_world() noexcept; + template<typename Function> void draw_world_0(const Function& fun, const draw_bounds& d_b, const z_bounds& z_b, Vector2i win_size); + draw_bounds get_draw_bounds() const noexcept override; void register_debug_callback(); diff --git a/main/projection.cpp b/main/projection.cpp index 8bb28604..75c53f79 100644 --- a/main/projection.cpp +++ b/main/projection.cpp @@ -1,4 +1,5 @@ #include "main-impl.hpp" +#include "floormat/draw-bounds.hpp" #include "src/tile-constants.hpp" #include "src/point.hpp" #include <algorithm> |