summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-01-18 17:05:58 +1100
committerquou <quou@disroot.org>2025-01-18 17:05:58 +1100
commitb2392cf01e6fd0c15bc52941177fbe4b8a5d1a69 (patch)
treee1e34929e8cd636104e583ba1f6245395ee5e431
parentdd4829eb05c9193e37e8dfa952bae967c6ca60c8 (diff)
entity debugger
-rw-r--r--c2.cpp8
-rw-r--r--editor.cpp78
-rw-r--r--editor.hpp4
3 files changed, 76 insertions, 14 deletions
diff --git a/c2.cpp b/c2.cpp
index d686765..28e63b5 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -638,8 +638,10 @@ struct C2 : public App {
per_frame_memory_size
);
clamped_linear = create_clamped_linear(dev);
+ world = (World*)arena_alloc(arena, sizeof *world);
+ world->init(arena);
ui = UI::create(dev, this, &ui_arena, ui_shader->id);
- init_editor(ui);
+ init_editor(ui, world);
lr.init(dev, &assets);
assert(per_frame != 0);
vbo = upload_verts(dev);
@@ -649,8 +651,6 @@ struct C2 : public App {
sky.init(dev, &assets);
eprobe.init(dev, &assets, 256);
camera.init();
- world = (World*)arena_alloc(arena, sizeof *world);
- world->init(arena);
{
monkey = world->create_entity();
auto [_, mod] = world->add<Transform, C_Model>(monkey);
@@ -804,7 +804,7 @@ struct C2 : public App {
mx,
my
);
- editor_on_select(*world, a, b);
+ editor_on_select(a, b);
}
lr.colour(v3f(1.0f, 0.0f, 0.0f));
diff --git a/editor.cpp b/editor.cpp
index a7f3b31..5b96db6 100644
--- a/editor.cpp
+++ b/editor.cpp
@@ -8,12 +8,14 @@
static struct {
UI* ui;
UI::Toolbar* toolbar;
- UI::Button* mat_btn;
- UI::Modal* mat_win;
+ UI::Button* mat_btn, * ent_btn;
+ UI::Modal* mat_win, * ent_win;
UI::Label* mat_name;
UI::Slider* metalness_input;
UI::Slider* roughness_input;
UI::Slider* ao_input;
+ UI::Label* ent_handle, * ent_index, * ent_version, * ent_mask;
+ World* world;
Entity_Id selected;
Model_Instance* selected_inst;
int selected_mesh;
@@ -48,6 +50,21 @@ static void setup_mat_edit() {
}
}
+void setup_ent_debug() {
+ if (editor.selected) {
+ int ind = entity_index(editor.selected);
+ editor.ent_handle->set_hex(editor.selected);
+ editor.ent_version->set_int(entity_version(editor.selected));
+ editor.ent_index->set_int(ind);
+ editor.ent_mask->set_hex(editor.world->masks[ind]);
+ } else {
+ editor.ent_handle->set_text("<null>");
+ editor.ent_version->set_text("<null>");
+ editor.ent_index->set_text("<null>");
+ editor.ent_mask->set_text("<null>");
+ }
+}
+
static int mat_btn_handler(UI::Element* e, const UI::Message& m) {
(void)e;
if (m.type == UI::Message::Type::click) {
@@ -114,26 +131,68 @@ static int mat_btn_handler(UI::Element* e, const UI::Message& m) {
return 0;
}
-void init_editor(UI* ui) {
+static int ent_win_handler(UI::Element* e, const UI::Message& m) {
+ (void)e;
+ if (m.type == UI::Message::Type::destroy) {
+ editor.ent_btn->enable();
+ editor.ent_win = 0;
+ }
+ return 0;
+}
+
+static int ent_btn_handler(UI::Element* e, const UI::Message& m) {
+ if (m.type == UI::Message::Type::click) {
+ auto ui = editor.ui;
+ editor.ent_win = ui->create_element<UI::Modal>(
+ editor.ui->root,
+ "Entity Debugger"
+ );
+ editor.ent_win->handler = ent_win_handler;
+ editor.ent_btn->disable();
+ int rows[] = { 100, 50, 0 };
+ auto tab = ui->create_element<UI::Table>(
+ editor.ent_win->contents,
+ rows
+ );
+ ui->create_element<UI::Label>(tab, "Handle");
+ editor.ent_handle = ui->create_element<UI::Label>(tab, "");
+ ui->create_element<UI::Label>(tab, "Index");
+ editor.ent_index = ui->create_element<UI::Label>(tab, "");
+ ui->create_element<UI::Label>(tab, "Version");
+ editor.ent_version = ui->create_element<UI::Label>(tab, "");
+ ui->create_element<UI::Label>(tab, "Mask");
+ editor.ent_mask = ui->create_element<UI::Label>(tab, "");
+ setup_ent_debug();
+ }
+ return 0;
+}
+
+void init_editor(UI* ui, World* world) {
editor.ui = ui;
editor.toolbar = ui->create_element<UI::Toolbar>(ui->root);
editor.mat_btn = ui->create_element<UI::Button>(
editor.toolbar,
"Edit Material"
);
- editor.mat_win = 0;
editor.mat_btn->handler = mat_btn_handler;
+ editor.ent_btn = ui->create_element<UI::Button>(
+ editor.toolbar,
+ "Entity Debugger"
+ );
+ editor.ent_btn->handler = ent_btn_handler;
+ editor.mat_win = 0;
+ editor.ent_win = 0;
+ editor.world = world;
}
void deinit_editor() {
-
}
-void editor_on_select(World& w, Entity_Id e, int m) {
+void editor_on_select(Entity_Id e, int m) {
if (!editor.ui->hovered) {
editor.selected = e;
- if (e && w.has<C_Model>(e)) {
- auto& cm = w.get<C_Model>(e);
+ if (e && editor.world->has<C_Model>(e)) {
+ auto& cm = editor.world->get<C_Model>(e);
editor.selected_inst = cm.i;
editor.selected_mesh = m;
} else {
@@ -143,6 +202,9 @@ void editor_on_select(World& w, Entity_Id e, int m) {
if (editor.mat_win) {
setup_mat_edit();
}
+ if (editor.ent_win) {
+ setup_ent_debug();
+ }
}
}
diff --git a/editor.hpp b/editor.hpp
index 9443a45..a809d6d 100644
--- a/editor.hpp
+++ b/editor.hpp
@@ -7,9 +7,9 @@ struct UI;
struct Model_Instance;
struct Line_Renderer;
-void init_editor(UI* ui);
+void init_editor(UI* ui, World* w);
void deinit_editor();
-void editor_on_select(World& w, Entity_Id e, int m);
+void editor_on_select(Entity_Id e, int m);
void editor_draw(Line_Renderer& lr);
#endif