From 234aa4cbaee30c4e7e5d0fbb03740bfe5fd5248e Mon Sep 17 00:00:00 2001 From: Skarn Date: Tue, 13 Oct 2020 12:57:10 +0300 Subject: [PATCH] implement radius based input for hole tool --- src/noggit/MapChunk.cpp | 19 ++++++++++++++++--- src/noggit/MapChunk.h | 2 +- src/noggit/MapView.cpp | 10 ++++++++-- src/noggit/World.cpp | 13 ++++++++++--- src/noggit/World.h | 2 +- src/noggit/ui/ZoneIDBrowser.cpp | 2 +- src/noggit/ui/hole_tool.cpp | 2 +- 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/noggit/MapChunk.cpp b/src/noggit/MapChunk.cpp index 7e017e93..e2b3214f 100644 --- a/src/noggit/MapChunk.cpp +++ b/src/noggit/MapChunk.cpp @@ -1038,7 +1038,7 @@ bool MapChunk::isHole(int i, int j) return (holes & ((1 << ((j * 4) + i)))) != 0; } -void MapChunk::setHole(math::vector_3d const& pos, bool big, bool add) +void MapChunk::setHole(math::vector_3d const& pos, float radius, bool big, bool add) { if (big) { @@ -1046,8 +1046,21 @@ void MapChunk::setHole(math::vector_3d const& pos, bool big, bool add) } else { - int v = 1 << ((int)((pos.z - zbase) / MINICHUNKSIZE) * 4 + (int)((pos.x - xbase) / MINICHUNKSIZE)); - holes = add ? (holes | v) : (holes & ~v); + for (int x = 0; x < 4; ++x) + { + for (int y = 0; y < 4; ++y) + { + if (misc::getShortestDist(pos.x, pos.z, xbase + (MINICHUNKSIZE * x), + zbase + (MINICHUNKSIZE * y), MINICHUNKSIZE) <= radius) + { + int v = 1 << (y * 4 + x); + holes = add ? (holes | v) : (holes & ~v); + } + + } + } + + } initStrip(); diff --git a/src/noggit/MapChunk.h b/src/noggit/MapChunk.h index be65b209..217c6118 100644 --- a/src/noggit/MapChunk.h +++ b/src/noggit/MapChunk.h @@ -174,7 +174,7 @@ public: //! \todo implement Action stack for these bool isHole(int i, int j); - void setHole(math::vector_3d const& pos, bool big, bool add); + void setHole(math::vector_3d const& pos, float radius, bool big, bool add); void setFlag(bool value, uint32_t); diff --git a/src/noggit/MapView.cpp b/src/noggit/MapView.cpp index ea307cde..ebf0bd29 100644 --- a/src/noggit/MapView.cpp +++ b/src/noggit/MapView.cpp @@ -1840,11 +1840,11 @@ void MapView::tick (float dt) // no undermap check here, else it's impossible to remove holes if (_mod_shift_down) { - _world->setHole(_cursor_pos, _mod_alt_down, false); + _world->setHole(_cursor_pos, holeTool->brushRadius(),_mod_alt_down, false); } else if (_mod_ctrl_down && !underMap) { - _world->setHole(_cursor_pos, _mod_alt_down, true); + _world->setHole(_cursor_pos, holeTool->brushRadius(), _mod_alt_down, true); } break; case editing_mode::areaid: @@ -2362,6 +2362,9 @@ void MapView::draw_map() case editing_mode::areaid: radius = ZoneIDBrowser->brushRadius(); break; + case editing_mode::holes: + radius = holeTool->brushRadius(); + break; } //! \note Select terrain below mouse, if no item selected or the item is map. @@ -2723,6 +2726,9 @@ void MapView::mouseMoveEvent (QMouseEvent* event) case editing_mode::areaid: ZoneIDBrowser->changeRadius(relative_movement.dx() / XSENS); break; + case editing_mode::holes: + holeTool->changeRadius(relative_movement.dx() / XSENS); + break; } } diff --git a/src/noggit/World.cpp b/src/noggit/World.cpp index 184d1881..2cb2f2c3 100644 --- a/src/noggit/World.cpp +++ b/src/noggit/World.cpp @@ -1647,14 +1647,21 @@ void World::overwriteTextureAtCurrentChunk(math::vector_3d const& pos, scoped_bl for_chunk_at(pos, [&](MapChunk* chunk) {chunk->switchTexture(oldTexture, std::move (newTexture));}); } -void World::setHole(math::vector_3d const& pos, bool big, bool hole) +void World::setHole(math::vector_3d const& pos, float radius, bool big, bool hole) { - for_chunk_at(pos, [&](MapChunk* chunk) { chunk->setHole(pos, big, hole); }); + for_all_chunks_in_range + ( pos, radius + , [&](MapChunk* chunk) + { + chunk->setHole(pos, radius, big, hole); + return true; + } + ); } void World::setHoleADT(math::vector_3d const& pos, bool hole) { - for_all_chunks_on_tile(pos, [&](MapChunk* chunk) { chunk->setHole(pos, true, hole); }); + for_all_chunks_on_tile(pos, [&](MapChunk* chunk) { chunk->setHole(pos, 1.0f, true, hole); }); } diff --git a/src/noggit/World.h b/src/noggit/World.h index 6726c839..45c169ff 100644 --- a/src/noggit/World.h +++ b/src/noggit/World.h @@ -231,7 +231,7 @@ public: void removeTexDuplicateOnADT(math::vector_3d const& pos); void change_texture_flag(math::vector_3d const& pos, scoped_blp_texture_reference const& tex, std::size_t flag, bool add); - void setHole(math::vector_3d const& pos, bool big, bool hole); + void setHole(math::vector_3d const& pos, float radius, bool big, bool hole); void setHoleADT(math::vector_3d const& pos, bool hole); void addM2 ( std::string const& filename diff --git a/src/noggit/ui/ZoneIDBrowser.cpp b/src/noggit/ui/ZoneIDBrowser.cpp index 7cdf0bff..45e9197c 100644 --- a/src/noggit/ui/ZoneIDBrowser.cpp +++ b/src/noggit/ui/ZoneIDBrowser.cpp @@ -32,7 +32,7 @@ namespace noggit layout->addRow ("Radius:", _radius_spin); _radius_slider = new QSlider (Qt::Orientation::Horizontal, this); - _radius_slider->setRange (0, 100); + _radius_slider->setRange (0, 250); _radius_slider->setSliderPosition (_radius); layout->addRow (_radius_slider); diff --git a/src/noggit/ui/hole_tool.cpp b/src/noggit/ui/hole_tool.cpp index 29a83d99..7f59a051 100644 --- a/src/noggit/ui/hole_tool.cpp +++ b/src/noggit/ui/hole_tool.cpp @@ -20,7 +20,7 @@ namespace noggit layout->addRow ("Radius:", _radius_spin); _radius_slider = new QSlider (Qt::Orientation::Horizontal, this); - _radius_slider->setRange (0, 100); + _radius_slider->setRange (0, 250); _radius_slider->setSliderPosition (_radius); layout->addRow (_radius_slider);