From 7ca709069cc280969b8d71bb19a09b8aeb13b859 Mon Sep 17 00:00:00 2001 From: quou Date: Fri, 24 Jan 2025 00:40:06 +1100 Subject: start on physics --- editor.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 4 deletions(-) (limited to 'editor.cpp') diff --git a/editor.cpp b/editor.cpp index 5b96db6..698b5ff 100644 --- a/editor.cpp +++ b/editor.cpp @@ -5,11 +5,16 @@ #include "ui.hpp" #include "world.hpp" +extern "C" { +#include "memory.h" +} + static struct { + Editor_Settings settings; UI* ui; UI::Toolbar* toolbar; - UI::Button* mat_btn, * ent_btn; - UI::Modal* mat_win, * ent_win; + UI::Button* mat_btn, * ent_btn, * phy_btn; + UI::Modal* mat_win, * ent_win, * phy_win; UI::Label* mat_name; UI::Slider* metalness_input; UI::Slider* roughness_input; @@ -131,8 +136,7 @@ static int mat_btn_handler(UI::Element* e, const UI::Message& m) { return 0; } -static int ent_win_handler(UI::Element* e, const UI::Message& m) { - (void)e; +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; @@ -141,6 +145,7 @@ static int ent_win_handler(UI::Element* e, const UI::Message& m) { } static int ent_btn_handler(UI::Element* e, const UI::Message& m) { + (void)e; if (m.type == UI::Message::Type::click) { auto ui = editor.ui; editor.ent_win = ui->create_element( @@ -167,6 +172,47 @@ static int ent_btn_handler(UI::Element* e, const UI::Message& m) { return 0; } +static int phy_win_handler(UI::Element* e, const UI::Message& m) { (void)e; + if (m.type == UI::Message::Type::destroy) { + editor.phy_btn->enable(); + editor.phy_win = 0; + } + return 0; +} + +static int phy_btn_handler(UI::Element* e, const UI::Message& m) { + (void)e; + if (m.type == UI::Message::Type::click) { + auto ui = editor.ui; + editor.phy_win = ui->create_element( + editor.ui->root, + "Physics Debugger" + ); + auto cont = editor.phy_win->contents; + editor.phy_win->handler = phy_win_handler; + editor.phy_btn->disable(); + auto cdebug = ui->create_element(cont, "Debug Draw"); + cdebug->handler = [](UI::Element* e, const UI::Message& m) { + if (m.type == UI::Message::Type::checkbox_changed) { + UI::Checkbox* ch = (UI::Checkbox*)e; + editor.settings.debug_physics = ch->val; + } + return 0; + }; + cdebug->set_val(editor.settings.debug_physics); + auto cpause = ui->create_element(cont, "Pause"); + cpause->set_val(editor.settings.pause_physics); + cpause->handler = [](UI::Element* e, const UI::Message& m) { + if (m.type == UI::Message::Type::checkbox_changed) { + UI::Checkbox* ch = (UI::Checkbox*)e; + editor.settings.pause_physics = ch->val; + } + return 0; + }; + } + return 0; +} + void init_editor(UI* ui, World* world) { editor.ui = ui; editor.toolbar = ui->create_element(ui->root); @@ -180,9 +226,16 @@ void init_editor(UI* ui, World* world) { "Entity Debugger" ); editor.ent_btn->handler = ent_btn_handler; + editor.phy_btn = ui->create_element( + editor.toolbar, + "Physics Debugger" + ); + editor.phy_btn->handler = phy_btn_handler; editor.mat_win = 0; editor.ent_win = 0; + editor.phy_win = 0; editor.world = world; + zero(&editor.settings, sizeof editor.settings); } void deinit_editor() { @@ -215,3 +268,7 @@ void editor_draw(Line_Renderer& lr) { ); } } + +Editor_Settings& editor_settings() { + return editor.settings; +} -- cgit v1.2.3-54-g00ecf