diff options
-rw-r--r-- | editor/camera.cpp | 1 | ||||
-rw-r--r-- | editor/draw.cpp | 1 | ||||
-rw-r--r-- | editor/update.cpp | 1 | ||||
-rw-r--r-- | floormat/app.hpp | 5 | ||||
-rw-r--r-- | floormat/draw-bounds.hpp | 8 | ||||
-rw-r--r-- | floormat/main.hpp | 6 | ||||
-rw-r--r-- | main/draw.cpp | 74 | ||||
-rw-r--r-- | main/main-impl.hpp | 2 | ||||
-rw-r--r-- | main/projection.cpp | 1 |
9 files changed, 56 insertions, 43 deletions
diff --git a/editor/camera.cpp b/editor/camera.cpp index 72b90cc2..14618d5b 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -3,6 +3,7 @@ #include "src/global-coords.hpp" #include "shaders/shader.hpp" #include "floormat/main.hpp" +#include "floormat/draw-bounds.hpp" #include "src/RTree-search.hpp" #include "src/object.hpp" #include "src/world.hpp" diff --git a/editor/draw.cpp b/editor/draw.cpp index 2751360c..051583d1 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -1,6 +1,7 @@ #include "app.hpp" #include "src/tile-constants.hpp" #include "floormat/main.hpp" +#include "floormat/draw-bounds.hpp" #include "shaders/shader.hpp" #include "shaders/texture-unit-cache.hpp" #include "main/clickable.hpp" diff --git a/editor/update.cpp b/editor/update.cpp index 204248c5..25a633a4 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -10,6 +10,7 @@ #include "main/clickable.hpp" #include "floormat/events.hpp" #include "floormat/main.hpp" +#include "floormat/draw-bounds.hpp" #include "src/critter.hpp" #include "src/nanosecond.hpp" #include "src/timer.hpp" diff --git a/floormat/app.hpp b/floormat/app.hpp index e387c0c4..02f7d24c 100644 --- a/floormat/app.hpp +++ b/floormat/app.hpp @@ -17,10 +17,11 @@ struct chunk_coords_; class chunk; struct Ns; +struct z_bounds; +struct draw_bounds; + struct floormat_app { - struct z_bounds final { int8_t min, max, cur; bool only; }; - explicit floormat_app() noexcept; virtual ~floormat_app() noexcept; diff --git a/floormat/draw-bounds.hpp b/floormat/draw-bounds.hpp new file mode 100644 index 00000000..1c37cacf --- /dev/null +++ b/floormat/draw-bounds.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace floormat { + +struct z_bounds final { int8_t min, max, cur; bool only; }; +struct draw_bounds final { int16_t minx, maxx, miny, maxy; }; + +} // namespace floormat diff --git a/floormat/main.hpp b/floormat/main.hpp index 59039152..648cd732 100644 --- a/floormat/main.hpp +++ b/floormat/main.hpp @@ -25,13 +25,11 @@ struct texture_unit_cache; class path_search; class astar; struct point; +struct z_bounds; +struct draw_bounds; struct floormat_main { - struct draw_bounds final - { - int16_t minx, maxx, miny, maxy; - }; struct meshes final { ground_mesh& ground; 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> |