summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-01 12:32:37 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-01 12:32:37 +0100
commit7ebee3863c061b1d0b64839b56bbc70ff4e5d924 (patch)
treeac0356bdcbf9f77864cb2cb2a6b5f2798c6fb3db /editor
parent078c376b6255fb6fd24362b27862819444327265 (diff)
move scenery modify logic to scenery_ref
Diffstat (limited to 'editor')
-rw-r--r--editor/app.hpp5
-rw-r--r--editor/draw.cpp13
-rw-r--r--editor/scenery-editor.cpp6
-rw-r--r--editor/update.cpp53
4 files changed, 46 insertions, 31 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index ff98ce99..c958fdf4 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -31,8 +31,7 @@ struct cursor_state final {
bool in_imgui = false;
};
-template<typename Atlas, typename T> struct clickable;
-using clickable_scenery = clickable<anim_atlas, scenery>;
+struct clickable;
enum class Cursor: std::uint32_t {
Arrow, TextInput, Wait, Crosshair, WaitArrow,
@@ -86,7 +85,7 @@ private:
void do_camera(float dt, const key_set& cmds, int mods);
void reset_camera_offset();
- clickable_scenery* find_clickable_scenery(const Optional<Vector2i>& pixel);
+ clickable* find_clickable_scenery(const Optional<Vector2i>& pixel);
void do_quicksave();
void do_quickload();
diff --git a/editor/draw.cpp b/editor/draw.cpp
index 41a5c713..77d3f665 100644
--- a/editor/draw.cpp
+++ b/editor/draw.cpp
@@ -144,25 +144,22 @@ void app::draw()
render_menu();
}
-clickable_scenery* app::find_clickable_scenery(const Optional<Vector2i>& pixel_)
+clickable* app::find_clickable_scenery(const Optional<Vector2i>& pixel_)
{
if (!pixel_ || _editor.mode() != editor_mode::none)
return nullptr;
const auto pixel = Vector2ui(*pixel_);
- clickable_scenery* item = nullptr;
+ clickable* item = nullptr;
float depth = -1;
const auto array = M->clickable_scenery();
- for (clickable_scenery& c : array)
+ for (clickable& c : array)
if (c.depth > depth && c.dest.contains(pixel))
{
const auto pos_ = pixel - c.dest.min() + c.src.min();
- const auto pos = c.atlas.group(c.item.r).mirror_from.isEmpty()
- ? pos_
- : Vector2ui(c.src.sizeX() - 1 - pos_[0], pos_[1]);
- const auto stride = c.atlas.info().pixel_size[0];
- std::size_t idx = pos.y() * stride + pos.x();
+ const auto pos = !c.mirrored ? pos_ : Vector2ui(c.src.sizeX() - 1 - pos_[0], pos_[1]);
+ std::size_t idx = pos.y() * c.stride + pos.x();
fm_debug_assert(idx < c.bitmask.size());
if (c.bitmask[idx])
{
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp
index f9a0678e..1d0635a6 100644
--- a/editor/scenery-editor.cpp
+++ b/editor/scenery-editor.cpp
@@ -3,6 +3,7 @@
#include "loader/loader.hpp"
#include "compat/assert.hpp"
#include "src/world.hpp"
+#include "rotation.inl"
namespace floormat {
@@ -21,7 +22,10 @@ scenery_editor::scenery_editor() noexcept
void scenery_editor::set_rotation(rotation_ r)
{
- _selected.proto.frame.rotate(r);
+ auto& s = _selected.proto.frame;
+ s.bbox_offset = rotate_point(s.bbox_offset, s.r, r);
+ s.bbox_size = rotate_size(s.bbox_size, s.r, r);
+ s.r = r;
}
rotation_ scenery_editor::rotation() const
diff --git a/editor/update.cpp b/editor/update.cpp
index afc3b6cc..35170ffc 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -49,6 +49,7 @@ void app::do_mouse_move(int mods)
void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods)
{
+ auto& w = M->world();
update_cursor_tile(cursor.pixel);
if (is_down && cursor.tile && !cursor.in_imgui)
@@ -59,13 +60,18 @@ void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods)
break;
case editor_mode::none:
if (button == mouse_button_left)
- if (auto* s = find_clickable_scenery(*cursor.pixel); s && s->item.can_activate(s->atlas))
- return (void)s->item.activate(s->atlas);
+ {
+ if (auto* cl = find_clickable_scenery(*cursor.pixel))
+ {
+ auto [c, t] = w[{cl->chunk, cl->pos}];
+ if (auto s = t.scenery())
+ return (void)s.activate();
+ }
+ }
break;
case editor_mode::floor:
case editor_mode::walls:
case editor_mode::scenery:
- auto& w = M->world();
auto pos = *cursor.tile;
switch (button)
{
@@ -94,12 +100,13 @@ void app::do_rotate(bool backward)
else if (cursor.tile)
{
auto [c, t] = M->world()[*cursor.tile];
- if (auto [atlas, s] = t.scenery(); atlas)
+ if (auto sc = t.scenery())
{
+ auto [atlas, s] = sc;
auto r = backward ? atlas->prev_rotation_from(s.r) : atlas->next_rotation_from(s.r);
if (r != s.r)
{
- s.rotate(r);
+ sc.rotate(r);
c.mark_scenery_modified();
}
}
@@ -157,15 +164,16 @@ void app::update_world(float dt)
for (std::int16_t y = miny; y <= maxy; y++)
for (std::int16_t x = minx; x <= maxx; x++)
for (auto& c = world[chunk_coords{x, y}]; auto [x, k, pt] : c)
- if (auto [atlas, scenery] = x.scenery(); atlas != nullptr)
+ if (auto sc = x.scenery())
{
- auto pass0 = scenery.passability;
- auto offset0 = scenery.offset;
- auto bb_offset0 = scenery.bbox_offset;
- auto bb_size0 = scenery.bbox_size;
- scenery.update(dt, *atlas);
- if (pass0 != scenery.passability || offset0 != scenery.offset ||
- bb_offset0 != scenery.bbox_offset || bb_size0 != scenery.bbox_size)
+ auto [atlas, s] = x.scenery();
+ auto pass0 = s.passability;
+ auto offset0 = s.offset;
+ auto bb_offset0 = s.bbox_offset;
+ auto bb_size0 = s.bbox_size;
+ sc.update(dt);
+ if (pass0 != s.passability || offset0 != s.offset ||
+ bb_offset0 != s.bbox_offset || bb_size0 != s.bbox_size)
c.mark_scenery_modified();
}
}
@@ -179,12 +187,19 @@ void app::update(float dt)
if (!cursor.in_imgui)
{
- auto* s = find_clickable_scenery(cursor.pixel);
-
- if (s && s->item.can_activate(s->atlas))
- M->set_cursor(std::uint32_t(Cursor::Hand));
- else
- set_cursor_from_imgui();
+ if (auto* cl = find_clickable_scenery(cursor.pixel))
+ {
+ auto& w = M->world();
+ auto [c, t] = w[{cl->chunk, cl->pos}];
+ if (auto sc = t.scenery())
+ {
+ auto [atlas, s] = sc;
+ if (sc && sc.can_activate())
+ M->set_cursor(std::uint32_t(Cursor::Hand));
+ else
+ set_cursor_from_imgui();
+ }
+ }
}
M->world().maybe_collect();