summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-03 21:10:47 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-03 21:10:47 +0100
commit879b4d9c629b59388caa202bfd72e1ca1c5992fa (patch)
tree60d654b7a30b4091c8cd0b098aebbe74c61eac0c
parentf9ada1a260aa978261512573c73f00987a4f875b (diff)
a
-rw-r--r--editor/app.hpp2
-rw-r--r--editor/events.cpp2
-rw-r--r--editor/inspect-draw.cpp55
-rw-r--r--editor/tests/path-test.cpp2
-rw-r--r--editor/tests/raycast-test.cpp33
5 files changed, 76 insertions, 18 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index 80b1047b..2e4eb15c 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -35,6 +35,7 @@ class world;
struct chunk;
class ground_atlas;
class anim_atlas;
+struct object;
struct critter;
struct point;
class editor;
@@ -137,6 +138,7 @@ private:
void draw_editor_pane(float main_menu_height);
void draw_inspector();
static void entity_inspector_name(char* buf, size_t len, object_id id);
+ static void entity_friendly_name(char* buf, size_t len, const object& obj);
bool check_inspector_exists(const popup_target& p);
void set_cursor_from_imgui();
void draw_cursor();
diff --git a/editor/events.cpp b/editor/events.cpp
index 77d9db11..cc1dbb3d 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -189,7 +189,7 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept
auto [x, mods] = resolve_keybinding(event.key, event.mods);
static_assert(key_GLOBAL >= key_NO_REPEAT);
- if (x == key_COUNT && (is_down ? _imgui->handleKeyPressEvent(e) : _imgui->handleKeyReleaseEvent(e)) ||
+ if ((x == key_COUNT || x < key_GLOBAL) && (is_down ? _imgui->handleKeyPressEvent(e) : _imgui->handleKeyReleaseEvent(e)) ||
(x == key_COUNT || x == key_escape) && _editor->mode() == editor_mode::tests && tests_handle_key(event, is_down))
clear_non_global_keys();
else if (x >= key_NO_REPEAT)
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index e47ac692..7b2e5009 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -5,6 +5,9 @@
#include "floormat/main.hpp"
#include "src/world.hpp"
#include "src/object.hpp"
+#include "src/scenery.hpp"
+#include "src/critter.hpp"
+#include "src/light.hpp"
#include "src/anim-atlas.hpp"
#include "imgui-raii.hpp"
#include "loader/loader.hpp"
@@ -31,7 +34,7 @@ void app::draw_inspector()
}
auto& e = *e_;
- char buf[32];
+ char buf[256], buf2[32], buf3[128];
ImGui::SetNextWindowSize({375*dpi[0], 0});
#if 0
auto name = loader.strip_prefix(e.atlas->name());
@@ -43,7 +46,9 @@ auto z = e.coord.z();
else
snformat(buf, "{} ({}x{}:{} -> {}x{})###inspector-{:08x}"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y, e.id);
#else
- entity_inspector_name(buf, sizeof buf, e.id);
+ entity_inspector_name(buf2, sizeof buf2, e.id);
+ entity_friendly_name(buf3, sizeof buf3, e);
+ std::snprintf(buf, std::size(buf), "%s###%s", buf3, buf2);
#endif
bool is_open = true;
@@ -66,4 +71,50 @@ void app::entity_inspector_name(char* buf, size_t len, object_id id)
buf[result.size] = '\0';
}
+void app::entity_friendly_name(char* buf, size_t len, const object& obj)
+{
+ switch (obj.type())
+ {
+ default:
+ std::snprintf(buf, len, "(unknown?)");
+ break;
+ case object_type::critter: {
+ const auto& c = static_cast<const critter&>(obj);
+ std::snprintf(buf, len, "critter %s", c.name.data());
+ break;
+ }
+ case object_type::light: {
+ const auto& L = static_cast<const light&>(obj);
+ const char* type;
+ switch (L.falloff)
+ {
+ case light_falloff::constant: type = "constant"; break;
+ case light_falloff::linear: type = "linear"; break;
+ case light_falloff::quadratic: type = "quadratic"; break;
+ default: type = "(unknown?)"; break;
+ }
+ std::snprintf(buf, len, "light #%hhx%hhx%hhx%hhx %s:%.2f",
+ L.color.r(), L.color.g(), L.color.b(), L.color.a(),
+ type,
+ L.falloff == light_falloff::constant ? 0. : (double)L.max_distance);
+ break;
+ }
+ case object_type::scenery: {
+ const auto& sc = static_cast<const scenery&>(obj);
+ switch (sc.scenery_type())
+ {
+ default:
+ std::snprintf(buf, len, "(unknown?)");
+ break;
+ case scenery_type::door:
+ std::snprintf(buf, len, "door");
+ break;
+ case scenery_type::generic:
+ std::snprintf(buf, len, "scenery %s", sc.atlas->name().data());
+ break;
+ }
+ }
+ }
+}
+
} // namespace floormat
diff --git a/editor/tests/path-test.cpp b/editor/tests/path-test.cpp
index 703a0f3a..43e2b041 100644
--- a/editor/tests/path-test.cpp
+++ b/editor/tests/path-test.cpp
@@ -157,7 +157,7 @@ void path_test::update_post(app& a)
(void)a;
}
-void path_test::draw_ui(app& a, float width)
+void path_test::draw_ui(app&, float)
{
constexpr ImGuiTableFlags table_flags = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_ScrollY;
constexpr auto colflags_1 = ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoReorder | ImGuiTableColumnFlags_NoSort;
diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp
index c813feac..06126354 100644
--- a/editor/tests/raycast-test.cpp
+++ b/editor/tests/raycast-test.cpp
@@ -438,6 +438,24 @@ struct raycast_test : base_test
);
auto signs = ray_aabb_signs(dir_inv_norm);
+ const auto do_check_collider = [&](Vector2 origin, uint64_t data, const Rect& r, bool& b)
+ {
+ auto x = std::bit_cast<collision_data>(data);
+ if (x.data == self || x.pass == (uint64_t)pass_mode::pass)
+ return true;
+ //Debug{} << "item" << Vector2(origin) << Vector2(r.m_min[0], r.m_min[1]);
+ auto ret = ray_aabb_intersection(origin, dir_inv_norm,
+ {{{r.m_min[0], r.m_min[1]},{r.m_max[0], r.m_max[1]}}},
+ signs);
+ if (ret.result)
+ {
+ result.collision = object::normalize_coords(from, Vector2i(dir * (double)ret.tmin));
+ result.collider = x;
+ return b = false;
+ }
+ return true;
+ };
+
for (auto k = 0u; k < nsteps; k++)
{
auto u = Vector2i(Math::round(V * k/(double)nsteps));
@@ -469,20 +487,7 @@ struct raycast_test : base_test
auto ch_off = (chunk_coords(last_ch) - from.chunk()) * chunk_size<int>;
auto origin = Vector2((Vector2i(from.local()) * tile_size<int>) + Vector2i(from.offset()) - ch_off);
r->Search(fmin.data(), fmax.data(), [&](uint64_t data, const Rect& r) {
- auto x = std::bit_cast<collision_data>(data);
- if (x.data == self || x.pass == (uint64_t)pass_mode::pass)
- return true;
- //Debug{} << "item" << Vector2(origin) << Vector2(r.m_min[0], r.m_min[1]);
- auto ret = ray_aabb_intersection(origin, dir_inv_norm,
- {{{r.m_min[0], r.m_min[1]},{r.m_max[0], r.m_max[1]}}},
- signs);
- if (ret.result)
- {
- result.collision = object::normalize_coords(from, Vector2i(dir * (double)ret.tmin));
- result.collider = x;
- return b = false;
- }
- return true;
+ return do_check_collider(origin, data, r, b);
});
if (!b)
goto last;