diff options
-rw-r--r-- | editor/camera.cpp | 2 | ||||
-rw-r--r-- | editor/draw.cpp | 85 | ||||
-rw-r--r-- | editor/update.cpp | 1 | ||||
-rw-r--r-- | main/draw.cpp | 1 | ||||
-rw-r--r-- | shaders/tile.cpp | 2 | ||||
-rw-r--r-- | src/camera-offset.cpp | 7 | ||||
-rw-r--r-- | src/global-coords.hpp | 2 |
7 files changed, 53 insertions, 47 deletions
diff --git a/editor/camera.cpp b/editor/camera.cpp index f018ad8c..94f36892 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -63,7 +63,7 @@ void app::update_cursor_tile(const Optional<Vector2i>& pixel) if (pixel) { auto coord = M->pixel_to_tile(Vector2d{*pixel}); - cursor.tile = {InPlaceInit, coord.chunk(), coord.local(), _z_level}; + cursor.tile = global_coords{coord.chunk(), coord.local(), _z_level}; } else cursor.tile = NullOpt; diff --git a/editor/draw.cpp b/editor/draw.cpp index 436283e7..2944eae6 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -77,7 +77,10 @@ void app::draw_collision_boxes() for (int8_t z = z_min; z <= z_max; z++) { - shader.set_tint({0, .5f, 1, 1}); + if (z == _z_level) + shader.set_tint({0, .5f, 1, 1}); + else + shader.set_tint({.7f, .7f, .7f, .6f}); for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) @@ -103,48 +106,52 @@ void app::draw_collision_boxes() }); } } + } - shader.set_tint({1, 0, 1, 1}); + shader.set_tint({1, 0, 1, 1}); - if (cursor.tile) - { - constexpr auto eps = 1e-6f; - constexpr auto m = TILE_SIZE2 * Vector2(1- eps, 1- eps); - const auto tile_ = Vector2(M->pixel_to_tile_(Vector2d(*cursor.pixel))); - const auto tile = *cursor.tile; - const auto curchunk = Vector2(tile.chunk()), curtile = Vector2(tile.local()); - const auto subpixel_ = Vector2(std::fmod(tile_[0], 1.f), std::fmod(tile_[1], 1.f)); - const auto subpixel = m * Vector2(curchunk[0] < 0 ? 1 + subpixel_[0] : subpixel_[0], - curchunk[1] < 0 ? 1 + subpixel_[1] : subpixel_[1]); - for (int16_t y = miny; y <= maxy; y++) - for (int16_t x = minx; x <= maxx; x++) + if (cursor.pixel) + { + auto pos = tile_shader::project(Vector3d{0., 0., -_z_level*dTILE_SIZE[2]}); + auto pixel = Vector2d{*cursor.pixel} + pos; + auto coord = M->pixel_to_tile(pixel); + auto tile = global_coords{coord.chunk(), coord.local(), 0}; + + constexpr auto eps = 1e-6f; + constexpr auto m = TILE_SIZE2 * Vector2(1- eps, 1- eps); + const auto tile_ = Vector2(M->pixel_to_tile_(Vector2d(pixel))); + const auto curchunk = Vector2(tile.chunk()), curtile = Vector2(tile.local()); + const auto subpixel_ = Vector2(std::fmod(tile_[0], 1.f), std::fmod(tile_[1], 1.f)); + const auto subpixel = m * Vector2(curchunk[0] < 0 ? 1 + subpixel_[0] : subpixel_[0], + curchunk[1] < 0 ? 1 + subpixel_[1] : subpixel_[1]); + for (int16_t y = miny; y <= maxy; y++) + for (int16_t x = minx; x <= maxx; x++) + { + const chunk_coords_ c_pos{x, y, _z_level}; + auto* c_ = world.at(c_pos); + if (!c_) + continue; + auto& c = *c_; + c.ensure_passability(); + const with_shifted_camera_offset o{shader, c_pos, {minx, miny}, {maxx, maxy}}; + if (floormat_main::check_chunk_visible(shader.camera_offset(), sz)) { - const chunk_coords_ c_pos{x, y, z}; - auto* c_ = world.at(c_pos); - if (!c_) - continue; - auto& c = *c_; - c.ensure_passability(); - const with_shifted_camera_offset o{shader, c_pos, {minx, miny}, {maxx, maxy}}; - if (floormat_main::check_chunk_visible(shader.camera_offset(), sz)) - { - constexpr auto half_tile = TILE_SIZE2/2; - constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM; - auto chunk_dist = (curchunk - Vector2(c_pos.x, c_pos.y))*chunk_size; - auto t0 = chunk_dist + curtile*TILE_SIZE2 + subpixel - half_tile; - auto t1 = t0+Vector2(1e-4f); - const auto* rtree = c.rtree(); - rtree->Search(t0.data(), t1.data(), [&](uint64_t data, const rect_type& rect) { - [[maybe_unused]] auto x = std::bit_cast<collision_data>(data); - Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]); - auto size = end - start; - auto center = Vector3(start + size*.5f, 0.f); - _wireframe_rect.draw(shader, { center, size, 3 }); - return true; - }); - } + constexpr auto half_tile = TILE_SIZE2/2; + constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM; + auto chunk_dist = (curchunk - Vector2(c_pos.x, c_pos.y))*chunk_size; + auto t0 = chunk_dist + curtile*TILE_SIZE2 + subpixel - half_tile; + auto t1 = t0+Vector2(1e-4f); + const auto* rtree = c.rtree(); + rtree->Search(t0.data(), t1.data(), [&](uint64_t data, const rect_type& rect) { + [[maybe_unused]] auto x = std::bit_cast<collision_data>(data); + Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]); + auto size = end - start; + auto center = Vector3(start + size*.5f, 0.f); + _wireframe_rect.draw(shader, { center, size, 3 }); + return true; + }); } - } + } } shader.set_tint({1, 1, 1, 1}); diff --git a/editor/update.cpp b/editor/update.cpp index 5b5d6662..9384cc17 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -245,6 +245,7 @@ auto app::get_z_bounds() -> z_bounds void app::update(float dt) { + update_cursor_tile(cursor.pixel); apply_commands(keys); update_character(dt); update_world(dt); diff --git a/main/draw.cpp b/main/draw.cpp index e124389f..409164c6 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -142,7 +142,6 @@ void main_impl::draw_world() noexcept const with_shifted_camera_offset o{_shader, pos, {minx, miny}, {maxx, maxy}}; if (check_chunk_visible(_shader.camera_offset(), sz)) { - _wall_mesh.draw(_shader, c); _floor_mesh.draw(_shader, c); } diff --git a/shaders/tile.cpp b/shaders/tile.cpp index d774ddf0..803165d5 100644 --- a/shaders/tile.cpp +++ b/shaders/tile.cpp @@ -75,7 +75,7 @@ void tile_shader::_draw() float tile_shader::depth_value(const local_coords& xy, float offset) noexcept { - return (float)((xy.to_index() + (double)offset) * depth_tile_size); + return (xy.to_index() + offset) * depth_tile_size; } } // namespace floormat diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp index 64e74068..d5073bef 100644 --- a/src/camera-offset.cpp +++ b/src/camera-offset.cpp @@ -10,9 +10,8 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun { fm_assert(shader.depth_offset() == 0.f); - constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE; - auto offset = _camera + tile_shader::project(Vector3d(c_.x, c_.y, 0) * chunk_size); - auto z = (int)(c_.z - chunk_z_min); + auto z = int{c_.z}; + auto offset = _camera + tile_shader::project((Vector3d(c_.x, c_.y, 0) * TILE_MAX_DIM20d + Vector3d(0, 0, z)) * dTILE_SIZE); auto pos = chunk_coords(c_) - first_; auto len = (last_ - first_) + Vector2i(1, 1); constexpr auto depth_start = -1 + 1.111e-16f; @@ -22,7 +21,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun z * (TILE_MAX_DIM+1); #if 0 - if (c_.z == 0) + if (c_ == chunk_coords_{} || c_ == chunk_coords_{0, -1, 1}) printf("c=(%2hd %2hd %2hhd) pos=(%2d %2d) len=(%d %d) --> %d\n", c_.x, c_.y, c_.z, pos.x(), pos.y(), len.x(), len.y(), depth); #endif diff --git a/src/global-coords.hpp b/src/global-coords.hpp index 737fc21b..d1fd2b8d 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -125,7 +125,7 @@ constexpr Vector2i global_coords::to_signed() const noexcept constexpr Vector3i global_coords::to_signed3() const noexcept { - return Vector3i(to_signed(), 0); + return Vector3i(to_signed(), z()); } constexpr global_coords global_coords::operator+(Vector2i vec) const noexcept |