summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/app.cpp2
-rw-r--r--editor/app.hpp4
-rw-r--r--editor/camera.cpp5
-rw-r--r--editor/imgui-inspect.cpp6
-rw-r--r--editor/imgui-misc.cpp6
-rw-r--r--editor/update.cpp4
-rw-r--r--floormat/app.hpp3
-rw-r--r--serialize/tile.cpp4
-rw-r--r--serialize/tile.hpp7
-rw-r--r--src/global-coords.hpp4
-rw-r--r--src/world.cpp2
-rw-r--r--src/world.hpp2
12 files changed, 36 insertions, 13 deletions
diff --git a/editor/app.cpp b/editor/app.cpp
index 6186beb7..4293708d 100644
--- a/editor/app.cpp
+++ b/editor/app.cpp
@@ -30,7 +30,7 @@ app::app(fm_settings&& opts) :
{
reset_world();
auto& w = M->world();
- constexpr chunk_coords coord{0, 0};
+ constexpr chunk_coords_ coord{0, 0, 0};
maybe_initialize_chunk_(coord, w[coord]);
reset_camera_offset();
inspectors.reserve(16);
diff --git a/editor/app.hpp b/editor/app.hpp
index c5e9f67a..17dd80fe 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -73,8 +73,8 @@ private:
void update_world(float dt);
void update_cursor_tile(const Optional<Vector2i>& pixel);
void set_cursor();
- void maybe_initialize_chunk(const chunk_coords& pos, chunk& c) override;
- void maybe_initialize_chunk_(const chunk_coords& pos, chunk& c);
+ void maybe_initialize_chunk(const chunk_coords_& pos, chunk& c) override;
+ void maybe_initialize_chunk_(const chunk_coords_& pos, chunk& c);
void update_character(float dt);
void reset_world();
void reset_world(struct world&& w);
diff --git a/editor/camera.cpp b/editor/camera.cpp
index b43c7af8..f018ad8c 100644
--- a/editor/camera.cpp
+++ b/editor/camera.cpp
@@ -61,7 +61,10 @@ void app::update_cursor_tile(const Optional<Vector2i>& pixel)
{
cursor.pixel = pixel;
if (pixel)
- cursor.tile = M->pixel_to_tile(Vector2d{*pixel});
+ {
+ auto coord = M->pixel_to_tile(Vector2d{*pixel});
+ cursor.tile = {InPlaceInit, coord.chunk(), coord.local(), _z_level};
+ }
else
cursor.tile = NullOpt;
}
diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp
index 534dd1cf..cb5b9ce7 100644
--- a/editor/imgui-inspect.cpp
+++ b/editor/imgui-inspect.cpp
@@ -33,6 +33,7 @@ void app::draw_inspector()
auto& s = *e;
chunk_coords ch = e->coord.chunk();
local_coords pos = e->coord.local();
+ auto z = e->coord.z();
char buf[32];
snformat(buf, "inspector-{:08x}"_cf, s.id);
@@ -40,7 +41,10 @@ void app::draw_inspector()
auto b1 = push_id(buf);
ImGui::SetNextWindowSize({300*dpi[0], 0});
auto name = loader.strip_prefix(s.atlas->name());
- snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y);
+ if (z == 0)
+ snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y);
+ else
+ snformat(buf, "{} ({}x{}:{} -> {}x{})"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y);
bool is_open = true;
if (s.type() == entity_type::scenery)
diff --git a/editor/imgui-misc.cpp b/editor/imgui-misc.cpp
index 84522f57..22fe3d2f 100644
--- a/editor/imgui-misc.cpp
+++ b/editor/imgui-misc.cpp
@@ -39,7 +39,11 @@ void app::draw_tile_under_cursor()
const auto coord = *cursor.tile;
const auto chunk = coord.chunk();
const auto local = coord.local();
- snformat(buf, "{}:{} - {}:{}"_cf, chunk.x, chunk.y, local.x, local.y);
+ const auto z = coord.z();
+ if (z == 0)
+ snformat(buf, "{}x{} - {}:{}"_cf, chunk.x, chunk.y, local.x, local.y);
+ else
+ snformat(buf, "{}x{}:{} - {}:{}"_cf, chunk.x, chunk.y, (int)z, local.x, local.y);
const auto size = ImGui::CalcTextSize(buf);
const auto window_size = M->window_size();
diff --git a/editor/update.cpp b/editor/update.cpp
index 97d77ffb..6bb1ff66 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -13,7 +13,7 @@ namespace floormat {
//#define FM_NO_BINDINGS
-void app::maybe_initialize_chunk_(const chunk_coords& pos, chunk& c)
+void app::maybe_initialize_chunk_(const chunk_coords_& pos, chunk& c)
{
(void)pos; (void)c;
@@ -39,7 +39,7 @@ void app::maybe_initialize_chunk_(const chunk_coords& pos, chunk& c)
c.mark_modified();
}
-void app::maybe_initialize_chunk([[maybe_unused]] const chunk_coords& pos, [[maybe_unused]] chunk& c)
+void app::maybe_initialize_chunk([[maybe_unused]] const chunk_coords_& pos, [[maybe_unused]] chunk& c)
{
//maybe_initialize_chunk_(pos, c);
}
diff --git a/floormat/app.hpp b/floormat/app.hpp
index f0222e7f..63c8fb81 100644
--- a/floormat/app.hpp
+++ b/floormat/app.hpp
@@ -13,6 +13,7 @@ struct text_editing_event;
union any_event;
struct chunk_coords;
+struct chunk_coords_;
struct chunk;
struct floormat_app
@@ -26,7 +27,7 @@ struct floormat_app
[[deprecated]] floormat_app& operator=(floormat_app&&) = default;
virtual void update(float dt) = 0;
- virtual void maybe_initialize_chunk(const chunk_coords& pos, chunk& c) = 0;
+ virtual void maybe_initialize_chunk(const chunk_coords_& pos, chunk& c) = 0;
virtual void draw() = 0;
virtual void on_mouse_move(const mouse_move_event& event) noexcept = 0;
diff --git a/serialize/tile.cpp b/serialize/tile.cpp
index 1b6158e7..61431e61 100644
--- a/serialize/tile.cpp
+++ b/serialize/tile.cpp
@@ -17,6 +17,7 @@ struct local_coords_ final {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords_, x, y)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y)
+NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords_, x, y, z)
struct global_coords_ final {
chunk_coords chunk;
@@ -40,6 +41,9 @@ void adl_serializer<local_coords>::from_json(const json& j, local_coords& val) {
void adl_serializer<chunk_coords>::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); }
void adl_serializer<chunk_coords>::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); }
+void adl_serializer<chunk_coords_>::to_json(json& j, const chunk_coords_& val) { using nlohmann::to_json; to_json(j, val); }
+void adl_serializer<chunk_coords_>::from_json(const json& j, chunk_coords_& val) { using nlohmann::from_json; from_json(j, val); }
+
void adl_serializer<global_coords>::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); }
void adl_serializer<global_coords>::from_json(const json& j, global_coords& val) { using nlohmann::from_json; global_coords_ x; from_json(j, x); val = {x.chunk, x.local}; }
diff --git a/serialize/tile.hpp b/serialize/tile.hpp
index 66982682..8313e937 100644
--- a/serialize/tile.hpp
+++ b/serialize/tile.hpp
@@ -6,6 +6,7 @@ namespace floormat {
struct tile_image_ref;
struct local_coords;
struct chunk_coords;
+struct chunk_coords_;
struct global_coords;
} // namespace floormat
@@ -31,6 +32,12 @@ struct adl_serializer<floormat::chunk_coords> {
};
template<>
+struct adl_serializer<floormat::chunk_coords_> {
+ static void to_json(json& j, const floormat::chunk_coords_& val);
+ static void from_json(const json& j, floormat::chunk_coords_& val);
+};
+
+template<>
struct adl_serializer<floormat::global_coords> {
static void to_json(json& j, const floormat::global_coords& val);
static void from_json(const json& j, floormat::global_coords& val);
diff --git a/src/global-coords.hpp b/src/global-coords.hpp
index f0d73c6f..9bdc311a 100644
--- a/src/global-coords.hpp
+++ b/src/global-coords.hpp
@@ -32,9 +32,9 @@ struct chunk_coords_ final {
int8_t z = 0;
explicit constexpr operator chunk_coords() const noexcept { return {x, y}; }
- constexpr chunk_coords_(chunk_coords c) noexcept : x{c.x}, y{c.y} {}
constexpr chunk_coords_() noexcept = default;
- constexpr chunk_coords_(int16_t x, int16_t y, int8_t z = 0) : x{x}, y{y}, z{z} {}
+ constexpr chunk_coords_(int16_t x, int16_t y, int8_t z = 0) noexcept : x{x}, y{y}, z{z} {}
+ constexpr chunk_coords_(chunk_coords c, int8_t z = 0) noexcept : x{c.x}, y{c.y}, z{z} {}
constexpr bool operator==(const chunk_coords_&) const noexcept = default;
};
diff --git a/src/world.cpp b/src/world.cpp
index 4e8e0095..ef78f313 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -91,7 +91,7 @@ chunk& world::operator[](chunk_coords_ coord) noexcept
auto world::operator[](global_coords pt) noexcept -> pair
{
- auto& c = operator[](pt.chunk());
+ auto& c = operator[]({pt.chunk(), pt.z()});
return { c, c[pt.local()] };
}
diff --git a/src/world.hpp b/src/world.hpp
index 47e6b01d..793b3605 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -77,7 +77,7 @@ public:
}
std::shared_ptr<T> make_entity(object_id id, global_coords pos, Xs&&... xs)
{
- auto ret = std::shared_ptr<T>(new T{id, operator[](pos.chunk()), std::forward<Xs>(xs)...});
+ auto ret = std::shared_ptr<T>(new T{id, operator[](chunk_coords_{pos.chunk(), pos.z()}), std::forward<Xs>(xs)...});
do_make_entity(std::static_pointer_cast<entity>(ret), pos, sorted);
return ret;
}