From 8d759c8b9c9282dac4e55fde5c9ea2bbb35d1b9b Mon Sep 17 00:00:00 2001 From: Lawrence Millar-Madigan Date: Fri, 10 Jul 2020 16:53:23 +1000 Subject: [PATCH 1/2] Rename map_editor classes to entity_viewport It doesn't seem specific to maps. Since it's expected a lot of the functionality will be reused for archetype and pose editors, its name should reflect this. --- lmeditor/CMakeLists.txt | 32 ++++----- .../{map_editor.h => entity_editor.h} | 2 +- lmeditor/src/app/app.cpp | 4 +- lmeditor/src/app/app.h | 2 +- .../entity_editor} | 16 ++--- .../entity_editor.cpp} | 32 +++++---- .../rendering.cpp | 15 ++--- .../entity_editor_controller.cpp} | 46 +++++++------ .../entity_editor_controller.h} | 29 ++++---- .../move_selection.cpp | 12 ++-- .../move_selection_commands.cpp | 30 ++++----- .../states/add_adjacent.cpp | 42 ++++++------ .../states/copy_object.cpp | 42 ++++++------ .../entity_editor/states/reparent.cpp | 46 +++++++++++++ .../states/rotate.cpp | 22 +++---- .../states/scale.cpp | 22 +++---- .../states/select.cpp | 66 +++++++++---------- .../states/translate.cpp | 50 +++++++------- .../viewport_commands.cpp | 23 +++---- .../controller/map_editor/states/reparent.cpp | 46 ------------- .../{map_editor => entity_editor}/test.cpp | 6 +- .../test_case.h} | 8 +-- .../test_move_selection.cpp | 12 ++-- 23 files changed, 301 insertions(+), 304 deletions(-) rename lmeditor/include/lmeditor/component/{map_editor.h => entity_editor.h} (94%) rename lmeditor/src/component/{map_editor/map_editor_component.h => entity_editor/entity_editor} (83%) rename lmeditor/src/component/{map_editor/map_editor_component.cpp => entity_editor/entity_editor.cpp} (79%) rename lmeditor/src/component/{map_editor => entity_editor}/rendering.cpp (89%) rename lmeditor/src/controller/{map_editor/map_editor_controller.cpp => entity_editor/entity_editor_controller.cpp} (79%) rename lmeditor/src/controller/{map_editor/map_editor_controller.h => entity_editor/entity_editor_controller.h} (87%) rename lmeditor/src/controller/{map_editor => entity_editor}/move_selection.cpp (88%) rename lmeditor/src/controller/{map_editor => entity_editor}/move_selection_commands.cpp (57%) rename lmeditor/src/controller/{map_editor => entity_editor}/states/add_adjacent.cpp (53%) rename lmeditor/src/controller/{map_editor => entity_editor}/states/copy_object.cpp (53%) create mode 100644 lmeditor/src/controller/entity_editor/states/reparent.cpp rename lmeditor/src/controller/{map_editor => entity_editor}/states/rotate.cpp (69%) rename lmeditor/src/controller/{map_editor => entity_editor}/states/scale.cpp (72%) rename lmeditor/src/controller/{map_editor => entity_editor}/states/select.cpp (56%) rename lmeditor/src/controller/{map_editor => entity_editor}/states/translate.cpp (57%) rename lmeditor/src/controller/{map_editor => entity_editor}/viewport_commands.cpp (69%) delete mode 100644 lmeditor/src/controller/map_editor/states/reparent.cpp rename lmeditor/test/{map_editor => entity_editor}/test.cpp (76%) rename lmeditor/test/{map_editor/map_editor_controller_test_case.h => entity_editor/test_case.h} (71%) rename lmeditor/test/{map_editor => entity_editor}/test_move_selection.cpp (96%) diff --git a/lmeditor/CMakeLists.txt b/lmeditor/CMakeLists.txt index 821f239..b301abb 100644 --- a/lmeditor/CMakeLists.txt +++ b/lmeditor/CMakeLists.txt @@ -20,25 +20,25 @@ add_library( src/controller/viewport/viewport.cpp - src/controller/map_editor/map_editor_controller.cpp - src/controller/map_editor/move_selection.cpp - src/controller/map_editor/viewport_commands.cpp - src/controller/map_editor/move_selection_commands.cpp - - src/controller/map_editor/states/add_adjacent.cpp - src/controller/map_editor/states/translate.cpp - src/controller/map_editor/states/select.cpp - src/controller/map_editor/states/copy_object.cpp - src/controller/map_editor/states/scale.cpp - src/controller/map_editor/states/rotate.cpp - src/controller/map_editor/states/reparent.cpp + src/controller/entity_editor/entity_editor_controller.cpp + src/controller/entity_editor/move_selection.cpp + src/controller/entity_editor/viewport_commands.cpp + src/controller/entity_editor/move_selection_commands.cpp + + src/controller/entity_editor/states/add_adjacent.cpp + src/controller/entity_editor/states/translate.cpp + src/controller/entity_editor/states/select.cpp + src/controller/entity_editor/states/copy_object.cpp + src/controller/entity_editor/states/scale.cpp + src/controller/entity_editor/states/rotate.cpp + src/controller/entity_editor/states/reparent.cpp src/controller/entity_list/entity_list_controller.cpp src/controller/inspector/inspector_controller.cpp - src/component/map_editor/rendering.cpp - src/component/map_editor/map_editor_component.cpp + src/component/entity_editor/rendering.cpp + src/component/entity_editor/entity_editor.cpp src/component/inspector/inspector_component.cpp @@ -135,8 +135,8 @@ add_executable( test/test_lmeditor.cpp test/test_trimesh.cpp - test/map_editor/test.cpp - test/map_editor/test_move_selection.cpp + test/entity_editor/test.cpp + test/entity_editor/test_move_selection.cpp test/test_entity_list.cpp ) diff --git a/lmeditor/include/lmeditor/component/map_editor.h b/lmeditor/include/lmeditor/component/entity_editor.h similarity index 94% rename from lmeditor/include/lmeditor/component/map_editor.h rename to lmeditor/include/lmeditor/component/entity_editor.h index b2ccb2f..4c90bbe 100644 --- a/lmeditor/include/lmeditor/component/map_editor.h +++ b/lmeditor/include/lmeditor/component/entity_editor.h @@ -7,7 +7,7 @@ namespace lmeditor { -struct map_editor_init +struct entity_editor_init { entt::registry ®istry; orbital_camera_init camera_init; diff --git a/lmeditor/src/app/app.cpp b/lmeditor/src/app/app.cpp index c483f76..e31bf20 100644 --- a/lmeditor/src/app/app.cpp +++ b/lmeditor/src/app/app.cpp @@ -3,9 +3,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -87,7 +87,7 @@ editor_app::editor_app(const std::filesystem::path &project_dir) window_size.height, }; - auto map_editor = map_editor_init{ + auto map_editor = entity_editor_init{ map, orbital_camera_init{ .fov = (float)M_PI / 3, diff --git a/lmeditor/src/app/app.h b/lmeditor/src/app/app.h index d940428..34c0e41 100644 --- a/lmeditor/src/app/app.h +++ b/lmeditor/src/app/app.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lmeditor/src/component/map_editor/map_editor_component.h b/lmeditor/src/component/entity_editor/entity_editor similarity index 83% rename from lmeditor/src/component/map_editor/map_editor_component.h rename to lmeditor/src/component/entity_editor/entity_editor index 49db92c..5b1160d 100644 --- a/lmeditor/src/component/map_editor/map_editor_component.h +++ b/lmeditor/src/component/entity_editor/entity_editor @@ -1,11 +1,11 @@ #pragma once -#include "../../controller/map_editor/map_editor_controller.h" +#include "../../controller/entity_editor/entity_editor_controller.h" #include #include #include #include -#include +#include #include #include #include @@ -20,12 +20,12 @@ namespace lmeditor { -class map_editor_component : public component_interface +class entity_editor : public component_interface { public: - explicit map_editor_component(map_editor_init const &init); - map_editor_component(map_editor_component const &) = delete; - map_editor_component(map_editor_component &&) = delete; + explicit entity_editor(entity_editor_init const &init); + entity_editor(entity_editor const &) = delete; + entity_editor(entity_editor &&) = delete; component_interface &update( lmgl::irenderer *renderer, @@ -38,7 +38,7 @@ class map_editor_component : public component_interface widget_interface & move_resources(lmgl::resource_sink &resource_sink) override; - map_editor_component &set_rect(lm::point2i pos, lm::size2i size) override; + entity_editor &set_rect(lm::point2i pos, lm::size2i size) override; lm::size2i get_size() override; lm::point2i get_position() override; std::vector get_command_descriptions() override; @@ -68,7 +68,7 @@ class map_editor_component : public component_interface lmgl::buffer create_selection_ubuffer(lmgl::irenderer *renderer); lmgl::material create_outline_material(lmgl::irenderer *renderer); - map_editor_controller controller; + entity_editor_controller controller; lmhuv::pvisual_view visual_view; lmgl::material selection_stencil_material, selection_outline_material; lmgl::buffer box_vpositions, box_vnormals, box_indices; diff --git a/lmeditor/src/component/map_editor/map_editor_component.cpp b/lmeditor/src/component/entity_editor/entity_editor.cpp similarity index 79% rename from lmeditor/src/component/map_editor/map_editor_component.cpp rename to lmeditor/src/component/entity_editor/entity_editor.cpp index d311ca9..415d75c 100644 --- a/lmeditor/src/component/map_editor/map_editor_component.cpp +++ b/lmeditor/src/component/entity_editor/entity_editor.cpp @@ -1,4 +1,4 @@ -#include "map_editor_component.h" +#include "entity_editor" #include #include #include @@ -8,12 +8,12 @@ namespace lmeditor { -component map_editor_init::operator()() +component entity_editor_init::operator()() { - return std::make_unique(*this); + return std::make_unique(*this); } -map_editor_component::map_editor_component(map_editor_init const &init) +entity_editor::entity_editor(entity_editor_init const &init) : controller{init.registry, init.camera_init}, visual_view{ lmhuv::create_visual_view(lmhuv::visual_view_init{ @@ -32,7 +32,7 @@ map_editor_component::map_editor_component(map_editor_init const &init) .resource_cache = init.resource_cache, .colour = state_text_colour, .position = init.position + state_text_position, - .text = map_editor_controller::select_state::label, + .text = entity_editor_controller::select_state::label, }}, selection_outline_colour{init.selection_outline_colour}, position{init.position}, @@ -56,7 +56,7 @@ map_editor_component::map_editor_component(map_editor_init const &init) selection_outline_geometry->set_line_width(6.f); } -lmgl::geometry map_editor_component::create_box_geometry( +lmgl::geometry entity_editor::create_box_geometry( lmgl::irenderer *renderer, lmgl::material box_material, lmgl::ibuffer *ubuffer) @@ -74,7 +74,7 @@ lmgl::geometry map_editor_component::create_box_geometry( return geometry; } -void map_editor_component::set_state_text( +void entity_editor::set_state_text( lmgl::irenderer *renderer, std::string new_text, lmgl::resource_sink &resource_sink, @@ -84,7 +84,7 @@ void map_editor_component::set_state_text( *renderer, resource_cache.body_font.get(), new_text, resource_sink); } -component_interface &map_editor_component::update( +component_interface &entity_editor::update( lmgl::irenderer *renderer, lmgl::resource_sink &resource_sink, lmtk::resource_cache const &resource_cache, @@ -97,7 +97,7 @@ component_interface &map_editor_component::update( return *this; } -bool map_editor_component::add_to_frame(lmgl::iframe *frame) +bool entity_editor::add_to_frame(lmgl::iframe *frame) { visual_view->add_to_frame( *controller.map, frame, lmgl::viewport{position, size}); @@ -107,7 +107,7 @@ bool map_editor_component::add_to_frame(lmgl::iframe *frame) } lmtk::widget_interface & - map_editor_component::move_resources(lmgl::resource_sink &resource_sink) + entity_editor::move_resources(lmgl::resource_sink &resource_sink) { resource_sink.add( selection_stencil_material, @@ -123,8 +123,7 @@ lmtk::widget_interface & return *this; } -map_editor_component & - map_editor_component::set_rect(lm::point2i pos, lm::size2i size) +entity_editor &entity_editor::set_rect(lm::point2i pos, lm::size2i size) { position = pos; this->size = size; @@ -133,16 +132,15 @@ map_editor_component & return *this; } -lm::size2i map_editor_component::get_size() { return size; } +lm::size2i entity_editor::get_size() { return size; } -lm::point2i map_editor_component::get_position() { return position; } +lm::point2i entity_editor::get_position() { return position; } -bool map_editor_component::handle(const lmtk::input_event &input_event) +bool entity_editor::handle(const lmtk::input_event &input_event) { return controller.handle(input_event); } -std::vector - map_editor_component::get_command_descriptions() +std::vector entity_editor::get_command_descriptions() { return controller.get_command_descriptions(); } diff --git a/lmeditor/src/component/map_editor/rendering.cpp b/lmeditor/src/component/entity_editor/rendering.cpp similarity index 89% rename from lmeditor/src/component/map_editor/rendering.cpp rename to lmeditor/src/component/entity_editor/rendering.cpp index ec175b0..035a672 100644 --- a/lmeditor/src/component/map_editor/rendering.cpp +++ b/lmeditor/src/component/entity_editor/rendering.cpp @@ -1,5 +1,5 @@ #include "../../model/trimesh/util.h" -#include "map_editor_component.h" +#include "entity_editor" #include #include @@ -17,8 +17,7 @@ struct selection_ubuffer_data namespace lmeditor { -lmgl::buffer - map_editor_component::create_selection_ubuffer(lmgl::irenderer *renderer) +lmgl::buffer entity_editor::create_selection_ubuffer(lmgl::irenderer *renderer) { return renderer->create_buffer(lmgl::buffer_init{ .usage = lmgl::render_buffer_usage::uniform, @@ -26,7 +25,8 @@ lmgl::buffer }); } -lmgl::material map_editor_component::create_selection_stencil_material( +lmgl::material + entity_editor::create_selection_stencil_material( lmgl::irenderer *renderer) { return renderer->create_material(lmgl::material_init{ @@ -54,8 +54,7 @@ lmgl::material map_editor_component::create_selection_stencil_material( }); } -lmgl::material - map_editor_component::create_outline_material(lmgl::irenderer *renderer) +lmgl::material entity_editor::create_outline_material(lmgl::irenderer *renderer) { return renderer->create_material(lmgl::material_init{ .vshader_spirv = lm::raw_array_proxy(stencil_vshader_data), @@ -85,7 +84,7 @@ lmgl::material }); } -void map_editor_component::render_selection_outline( +void entity_editor::render_selection_outline( lmgl::iframe *frame, entt::registry const &map) const { @@ -123,7 +122,7 @@ void map_editor_component::render_selection_outline( frame->add({selection_outline_geometry.get()}, viewport); } -void map_editor_component::render_state_text(lmgl::iframe *frame) +void entity_editor::render_state_text(lmgl::iframe *frame) { state_text_layout.render(frame, position, size); } diff --git a/lmeditor/src/controller/map_editor/map_editor_controller.cpp b/lmeditor/src/controller/entity_editor/entity_editor_controller.cpp similarity index 79% rename from lmeditor/src/controller/map_editor/map_editor_controller.cpp rename to lmeditor/src/controller/entity_editor/entity_editor_controller.cpp index 385eecf..36bb1cd 100644 --- a/lmeditor/src/controller/map_editor/map_editor_controller.cpp +++ b/lmeditor/src/controller/entity_editor/entity_editor_controller.cpp @@ -1,5 +1,5 @@ -#include "map_editor_controller.h" -#include +#include "entity_editor_controller.h" +#include #include #include #include @@ -12,7 +12,7 @@ namespace lmeditor { -map_editor_controller::map_editor_controller( +entity_editor_controller::entity_editor_controller( entt::registry &map, orbital_camera_init const &camera_init) : state{select_state{*this}}, @@ -23,7 +23,7 @@ map_editor_controller::map_editor_controller( { } -bool map_editor_controller::handle(lmtk::input_event const &event) +bool entity_editor_controller::handle(lmtk::input_event const &event) { return std::visit( lm::variant_visitor{ @@ -53,7 +53,7 @@ bool map_editor_controller::handle(lmtk::input_event const &event) state); } -entt::entity map_editor_controller::add_cube( +entt::entity entity_editor_controller::add_cube( entt::registry &map, Eigen::Vector3f const &position, float extent) @@ -79,7 +79,7 @@ entt::entity map_editor_controller::add_cube( return new_cube; } -std::string map_editor_controller::get_unique_name( +std::string entity_editor_controller::get_unique_name( entt::registry const &map, char const *prefix) { @@ -100,7 +100,7 @@ std::string map_editor_controller::get_unique_name( return unique_name; } -entt::entity map_editor_controller::add_adjacent( +entt::entity entity_editor_controller::add_adjacent( entt::registry &map, Eigen::Vector3f const &direction) { @@ -111,7 +111,7 @@ entt::entity map_editor_controller::add_adjacent( return add_cube(map, add_pos, 1.f); } -entt::entity map_editor_controller::copy_entity( +entt::entity entity_editor_controller::copy_entity( entt::registry &map, Eigen::Vector3f const &direction) { @@ -132,7 +132,7 @@ entt::entity map_editor_controller::copy_entity( return new_box; } -void map_editor_controller::translate( +void entity_editor_controller::translate( entt::registry &map, entt::entity entity, Eigen::Vector3f const &vector) @@ -143,7 +143,7 @@ void map_editor_controller::translate( } std::vector - map_editor_controller::get_command_descriptions() + entity_editor_controller::get_command_descriptions() { return state >> lm::variant_visitor{[this](auto &state_alternative) { return get_command_descriptions( @@ -155,8 +155,8 @@ std::vector } std::vector - map_editor_controller::get_command_descriptions( - map_editor_controller::command_list const &list, + entity_editor_controller::get_command_descriptions( + entity_editor_controller::command_list const &list, std::string const &context) { std::vector command_lines; @@ -177,13 +177,12 @@ std::vector } Eigen::Vector3f - map_editor_controller::view_to_axis(Eigen::Vector3f const &view_vector) + entity_editor_controller::view_to_axis(Eigen::Vector3f const &view_vector) { return lm::snap_to_axis(view_to_world(view_vector)); } -Eigen::Vector3f - map_editor_controller::get_selection_extents(entt::registry const &map) const +Eigen::Vector3f entity_editor_controller::get_selection_extents(entt::registry const &map) const { auto selected_box = get_selection(); @@ -198,36 +197,35 @@ Eigen::Vector3f return Eigen::Vector3f{0.f, 0.f, 0.f}; } -void map_editor_controller::select(entt::entity entity) +void entity_editor_controller::select(entt::entity entity) { clear_selection(); map->emplace(entity); } -void map_editor_controller::clear_selection() const { map->clear(); } +void entity_editor_controller::clear_selection() const { map->clear(); } -entt::registry *map_editor_controller::get_registry() const { return map; } +entt::registry *entity_editor_controller::get_registry() const { return map; } -bool map_editor_controller::have_selection() const +bool entity_editor_controller::have_selection() const { return !map->view().empty(); } -entt::entity map_editor_controller::get_selection() const +entt::entity entity_editor_controller::get_selection() const { return lmeditor::get_selection(*map); } -lm::camera map_editor_controller::get_camera() const { return camera; } +lm::camera entity_editor_controller::get_camera() const { return camera; } Eigen::Vector3f - map_editor_controller::view_to_world(const Eigen::Vector3f &view_vector) + entity_editor_controller::view_to_world(const Eigen::Vector3f &view_vector) { return camera.rotation * view_vector; } -Eigen::Vector3f - map_editor_controller::get_selection_position(const entt::registry &map) const +Eigen::Vector3f entity_editor_controller::get_selection_position(const entt::registry &map) const { return lmng::resolve_transform(map, get_selection()).position; } diff --git a/lmeditor/src/controller/map_editor/map_editor_controller.h b/lmeditor/src/controller/entity_editor/entity_editor_controller.h similarity index 87% rename from lmeditor/src/controller/map_editor/map_editor_controller.h rename to lmeditor/src/controller/entity_editor/entity_editor_controller.h index 12a0fa5..6e63048 100644 --- a/lmeditor/src/controller/map_editor/map_editor_controller.h +++ b/lmeditor/src/controller/entity_editor/entity_editor_controller.h @@ -14,10 +14,10 @@ namespace lmeditor { -class map_editor_controller : public viewport +class entity_editor_controller : public viewport { public: - explicit map_editor_controller( + explicit entity_editor_controller( entt::registry &map, orbital_camera_init const &camera_init); @@ -77,7 +77,7 @@ class map_editor_controller : public viewport struct command_args { - class map_editor_controller &controller; + class entity_editor_controller &controller; entt::registry ↦ lmtk::key_down_event const &key_down_event; }; @@ -104,10 +104,11 @@ class map_editor_controller : public viewport constexpr static auto label = ""; template - explicit select_state(other_state_type &, map_editor_controller &model) + explicit select_state(other_state_type &, + entity_editor_controller &model) : select_state{model} {}; - explicit select_state(map_editor_controller &model); + explicit select_state(entity_editor_controller &model); command_list commands; command_map key_command_map; @@ -117,7 +118,7 @@ class map_editor_controller : public viewport using parent_state_type = select_state; constexpr static auto label = "Translate Entity"; - explicit translate_state(select_state &, map_editor_controller &); + explicit translate_state(select_state &, entity_editor_controller &); command_list commands; command_map key_command_map; @@ -128,8 +129,8 @@ class map_editor_controller : public viewport using parent_state_type = select_state; explicit add_adjacent_state( - map_editor_controller::select_state &, - map_editor_controller &model); + entity_editor_controller::select_state &, + entity_editor_controller &model); command_list commands; command_map key_command_map; @@ -140,8 +141,8 @@ class map_editor_controller : public viewport using parent_state_type = select_state; copy_entity_state( - map_editor_controller::select_state &, - map_editor_controller &model); + entity_editor_controller::select_state &, + entity_editor_controller &model); command_list commands; command_map key_command_map; @@ -151,7 +152,7 @@ class map_editor_controller : public viewport constexpr static auto label = "Reparent Entity"; using parent_state_type = select_state; - reparent_state(select_state &, map_editor_controller &model); + reparent_state(select_state &, entity_editor_controller &model); command_list commands; command_map key_command_map; @@ -162,7 +163,7 @@ class map_editor_controller : public viewport constexpr static auto label = "Scale Entity"; using parent_state_type = select_state; - scale_state(select_state &, map_editor_controller &model); + scale_state(select_state &, entity_editor_controller &model); command_list commands; command_map key_command_map; @@ -172,7 +173,7 @@ class map_editor_controller : public viewport constexpr static auto label = "Rotate Entity"; using parent_state_type = select_state; - rotate_state(select_state &, map_editor_controller &model); + rotate_state(select_state &, entity_editor_controller &model); command_list commands; command_map key_command_map; @@ -220,7 +221,7 @@ class map_editor_controller : public viewport }; template -auto map_editor_controller::enter_state(current_state_type ¤t_state) +auto entity_editor_controller::enter_state(current_state_type ¤t_state) { static_assert( std::is_same_v< diff --git a/lmeditor/src/controller/map_editor/move_selection.cpp b/lmeditor/src/controller/entity_editor/move_selection.cpp similarity index 88% rename from lmeditor/src/controller/map_editor/move_selection.cpp rename to lmeditor/src/controller/entity_editor/move_selection.cpp index 7a09313..771e93e 100644 --- a/lmeditor/src/controller/map_editor/move_selection.cpp +++ b/lmeditor/src/controller/entity_editor/move_selection.cpp @@ -1,4 +1,4 @@ -#include "map_editor_controller.h" +#include "entity_editor_controller.h" #include @@ -7,7 +7,7 @@ namespace lmeditor { -entt::entity map_editor_controller::nearest_entity( +entt::entity entity_editor_controller::nearest_entity( entt::registry const &map, entt::entity entity, const Eigen::Vector3f &direction) @@ -45,7 +45,7 @@ entt::entity map_editor_controller::nearest_entity( return nearest_entity; } -entt::entity map_editor_controller::farthest_entity( +entt::entity entity_editor_controller::farthest_entity( entt::registry const &map, const Eigen::Vector3f &direction) { @@ -74,7 +74,7 @@ entt::entity map_editor_controller::farthest_entity( return farthest; } -bool map_editor_controller::move_selection( +bool entity_editor_controller::move_selection( entt::registry const &map, Eigen::Vector3f const &direction) { @@ -97,14 +97,14 @@ bool map_editor_controller::move_selection( return true; } -bool map_editor_controller::move_selection_view( +bool entity_editor_controller::move_selection_view( entt::registry const &map, const Eigen::Vector3f &view_axis) { return move_selection(map, lm::snap_to_axis(camera.rotation * view_axis)); } -void map_editor_controller::set_map(const entt::registry ®istry) +void entity_editor_controller::set_map(const entt::registry ®istry) { state.emplace(*this); clear_selection(); diff --git a/lmeditor/src/controller/map_editor/move_selection_commands.cpp b/lmeditor/src/controller/entity_editor/move_selection_commands.cpp similarity index 57% rename from lmeditor/src/controller/map_editor/move_selection_commands.cpp rename to lmeditor/src/controller/entity_editor/move_selection_commands.cpp index 16a3ea8..b71509d 100644 --- a/lmeditor/src/controller/map_editor/move_selection_commands.cpp +++ b/lmeditor/src/controller/entity_editor/move_selection_commands.cpp @@ -1,57 +1,57 @@ -#include "map_editor_controller.h" +#include "entity_editor_controller.h" namespace lmeditor { -map_editor_controller::command move_selection_back_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_selection_back_command{ + [](entity_editor_controller::command_args const &args) { return args.controller.move_selection_view( args.map, -Eigen::Vector3f::UnitZ()); }, "Move selection back", }; -map_editor_controller::command move_selection_forward_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_selection_forward_command{ + [](entity_editor_controller::command_args const &args) { return args.controller.move_selection_view( args.map, Eigen::Vector3f::UnitZ()); }, "Move selection forward", }; -map_editor_controller::command move_selection_up_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_selection_up_command{ + [](entity_editor_controller::command_args const &args) { return args.controller.move_selection_view( args.map, Eigen::Vector3f::UnitY()); }, "Move selection up", }; -map_editor_controller::command move_selection_down_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_selection_down_command{ + [](entity_editor_controller::command_args const &args) { return args.controller.move_selection_view( args.map, -Eigen::Vector3f::UnitY()); }, "Move selection down", }; -map_editor_controller::command move_selection_left_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_selection_left_command{ + [](entity_editor_controller::command_args const &args) { return args.controller.move_selection_view( args.map, -Eigen::Vector3f::UnitX()); }, "Move selection left", }; -map_editor_controller::command move_selection_right_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_selection_right_command{ + [](entity_editor_controller::command_args const &args) { return args.controller.move_selection_view( args.map, Eigen::Vector3f::UnitX()); }, "Move selection right", }; -map_editor_controller::command_list - map_editor_controller::move_selection_commands{ +entity_editor_controller::command_list + entity_editor_controller::move_selection_commands{ {{lmpl::key_code::U}, move_selection_back_command}, {{lmpl::key_code::O}, move_selection_forward_command}, {{lmpl::key_code::I}, move_selection_up_command}, diff --git a/lmeditor/src/controller/map_editor/states/add_adjacent.cpp b/lmeditor/src/controller/entity_editor/states/add_adjacent.cpp similarity index 53% rename from lmeditor/src/controller/map_editor/states/add_adjacent.cpp rename to lmeditor/src/controller/entity_editor/states/add_adjacent.cpp index f53d36e..1bbc309 100644 --- a/lmeditor/src/controller/map_editor/states/add_adjacent.cpp +++ b/lmeditor/src/controller/entity_editor/states/add_adjacent.cpp @@ -1,11 +1,11 @@ -#include "../map_editor_controller.h" +#include "../entity_editor_controller.h" #include #include namespace lmeditor { void do_add( - map_editor_controller::command_args const &args, + entity_editor_controller::command_args const &args, Eigen::Vector3f const &direction) { auto new_box = args.controller.add_adjacent( @@ -16,63 +16,63 @@ void do_add( args.controller.leave_state(); } -map_editor_controller::command add_above_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command add_above_command{ + [](entity_editor_controller::command_args const &args) { do_add(args, Eigen::Vector3f::UnitY()); return true; }, "Add entity above", }; -map_editor_controller::command add_below_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command add_below_command{ + [](entity_editor_controller::command_args const &args) { do_add(args, -Eigen::Vector3f::UnitY()); return true; }, "Add entity below", }; -map_editor_controller::command add_left_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command add_left_command{ + [](entity_editor_controller::command_args const &args) { do_add(args, -Eigen::Vector3f::UnitX()); return true; }, "Add entity left", }; -map_editor_controller::command add_right_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command add_right_command{ + [](entity_editor_controller::command_args const &args) { do_add(args, Eigen::Vector3f::UnitX()); return true; }, "Add entity right", }; -map_editor_controller::command add_behind_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command add_behind_command{ + [](entity_editor_controller::command_args const &args) { do_add(args, Eigen::Vector3f::UnitZ()); return true; }, "Add entity behind", }; -map_editor_controller::command add_front_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command add_front_command{ + [](entity_editor_controller::command_args const &args) { do_add(args, -Eigen::Vector3f::UnitZ()); return true; }, "Add entity in front", }; -map_editor_controller::command cancel_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command cancel_command{ + [](entity_editor_controller::command_args const &args) { args.controller.leave_state(); return true; }, "Cancel entity add", }; -map_editor_controller::command_list add_adjacent_commands{ +entity_editor_controller::command_list add_adjacent_commands{ {{lmpl::key_code::I}, add_above_command}, {{lmpl::key_code::K}, add_below_command}, {{lmpl::key_code::J}, add_left_command}, @@ -82,10 +82,10 @@ map_editor_controller::command_list add_adjacent_commands{ {{lmpl::key_code::Q}, cancel_command}, }; -map_editor_controller::add_adjacent_state::add_adjacent_state( - map_editor_controller::select_state &, - map_editor_controller &map_editor) - : commands{ranges::views::concat(map_editor_controller::viewport_commands, add_adjacent_commands) | ranges::to()}, +entity_editor_controller::add_adjacent_state::add_adjacent_state( + entity_editor_controller::select_state &, + entity_editor_controller &controller) + : commands{ranges::views::concat(entity_editor_controller::viewport_commands, add_adjacent_commands) | ranges::to()}, key_command_map{ranges::views::all(commands) | ranges::to()} { } diff --git a/lmeditor/src/controller/map_editor/states/copy_object.cpp b/lmeditor/src/controller/entity_editor/states/copy_object.cpp similarity index 53% rename from lmeditor/src/controller/map_editor/states/copy_object.cpp rename to lmeditor/src/controller/entity_editor/states/copy_object.cpp index 3cfe336..b5415aa 100644 --- a/lmeditor/src/controller/map_editor/states/copy_object.cpp +++ b/lmeditor/src/controller/entity_editor/states/copy_object.cpp @@ -1,11 +1,11 @@ -#include "../map_editor_controller.h" +#include "../entity_editor_controller.h" #include #include namespace lmeditor { void do_copy( - map_editor_controller::command_args const &args, + entity_editor_controller::command_args const &args, Eigen::Vector3f const &direction) { auto new_box = args.controller.copy_entity( @@ -16,63 +16,63 @@ void do_copy( args.controller.leave_state(); } -map_editor_controller::command copy_above_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command copy_above_command{ + [](entity_editor_controller::command_args const &args) { do_copy(args, Eigen::Vector3f::UnitY()); return true; }, "Add entity above", }; -map_editor_controller::command copy_below_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command copy_below_command{ + [](entity_editor_controller::command_args const &args) { do_copy(args, -Eigen::Vector3f::UnitY()); return true; }, "Add entity below", }; -map_editor_controller::command copy_left_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command copy_left_command{ + [](entity_editor_controller::command_args const &args) { do_copy(args, -Eigen::Vector3f::UnitX()); return true; }, "Add entity left", }; -map_editor_controller::command copy_right_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command copy_right_command{ + [](entity_editor_controller::command_args const &args) { do_copy(args, Eigen::Vector3f::UnitX()); return true; }, "Add entity right", }; -map_editor_controller::command copy_behind_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command copy_behind_command{ + [](entity_editor_controller::command_args const &args) { do_copy(args, Eigen::Vector3f::UnitZ()); return true; }, "Add entity behind", }; -map_editor_controller::command copy_front_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command copy_front_command{ + [](entity_editor_controller::command_args const &args) { do_copy(args, -Eigen::Vector3f::UnitZ()); return true; }, "Add entity in front", }; -static map_editor_controller::command cancel_command{ - [](map_editor_controller::command_args const &args) { +static entity_editor_controller::command cancel_command{ + [](entity_editor_controller::command_args const &args) { args.controller.leave_state(); return true; }, "Cancel entity add", }; -map_editor_controller::command_list copy_adjacent_commands{ +entity_editor_controller::command_list copy_adjacent_commands{ {{lmpl::key_code::I}, copy_above_command}, {{lmpl::key_code::K}, copy_below_command}, {{lmpl::key_code::J}, copy_left_command}, @@ -82,10 +82,10 @@ map_editor_controller::command_list copy_adjacent_commands{ {{lmpl::key_code::Q}, cancel_command}, }; -map_editor_controller::copy_entity_state::copy_entity_state( - map_editor_controller::select_state &, - map_editor_controller &map_editor) - : commands{ranges::views::concat(map_editor_controller::viewport_commands, copy_adjacent_commands) | ranges::to()}, +entity_editor_controller::copy_entity_state::copy_entity_state( + entity_editor_controller::select_state &, + entity_editor_controller &controller) + : commands{ranges::views::concat(entity_editor_controller::viewport_commands, copy_adjacent_commands) | ranges::to()}, key_command_map{ranges::views::all(commands) | ranges::to()} { } diff --git a/lmeditor/src/controller/entity_editor/states/reparent.cpp b/lmeditor/src/controller/entity_editor/states/reparent.cpp new file mode 100644 index 0000000..8aa252d --- /dev/null +++ b/lmeditor/src/controller/entity_editor/states/reparent.cpp @@ -0,0 +1,46 @@ +#include "../entity_editor_controller.h" +#include +#include +#include + +namespace lmeditor +{ +entity_editor_controller::command select_parent{ + [](entity_editor_controller::command_args const &args) { + auto selected_box = args.controller.get_selection(); + + auto &reparent_state = + std::get(args.controller.state); + + if (selected_box == reparent_state.entity) + return false; + + lmng::reparent(args.map, reparent_state.entity, selected_box); + args.controller.leave_state(); + return true; + }, + "Select new parent", +}; + +entity_editor_controller::command quit_reparent{ + [](entity_editor_controller::command_args const &args) { + args.controller.leave_state(); + return true; + }, + "Cancel reparent", +}; + +entity_editor_controller::command_list reparent_commands{ + {{lmpl::key_code::Enter}, select_parent}, + {{lmpl::key_code::Q}, quit_reparent}, +}; + +entity_editor_controller::reparent_state::reparent_state( + entity_editor_controller::select_state &, + entity_editor_controller &controller) + : commands{ranges::views::concat(entity_editor_controller::move_selection_commands, entity_editor_controller::viewport_commands, reparent_commands) | ranges::to()}, + key_command_map{ranges::views::all(commands) | ranges::to()}, + entity{controller.get_selection()} +{ +} +} // namespace lmeditor diff --git a/lmeditor/src/controller/map_editor/states/rotate.cpp b/lmeditor/src/controller/entity_editor/states/rotate.cpp similarity index 69% rename from lmeditor/src/controller/map_editor/states/rotate.cpp rename to lmeditor/src/controller/entity_editor/states/rotate.cpp index a5ff681..c505f1d 100644 --- a/lmeditor/src/controller/map_editor/states/rotate.cpp +++ b/lmeditor/src/controller/entity_editor/states/rotate.cpp @@ -1,4 +1,4 @@ -#include "../map_editor_controller.h" +#include "../entity_editor_controller.h" #include #include #include @@ -6,10 +6,10 @@ namespace lmeditor { template -map_editor_controller::command create_rotate_command(char const *name) +entity_editor_controller::command create_rotate_command(char const *name) { - return map_editor_controller::command{ - [](map_editor_controller::command_args const &args) { + return entity_editor_controller::command{ + [](entity_editor_controller::command_args const &args) { float amount{0.1f * lm::pi}; if (args.key_down_event.input_state.key_state.shift()) @@ -32,15 +32,15 @@ map_editor_controller::command create_rotate_command(char const *name) }; } -map_editor_controller::command quit_rotate_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command quit_rotate_command{ + [](entity_editor_controller::command_args const &args) { args.controller.leave_state(); return true; }, "Stop rotating entity", }; -map_editor_controller::command_list rotate_commands{ +entity_editor_controller::command_list rotate_commands{ {{lmpl::key_code::K}, create_rotate_command<0, 1>("Rotate around x axis (positive)")}, {{lmpl::key_code::I}, @@ -56,10 +56,10 @@ map_editor_controller::command_list rotate_commands{ {{lmpl::key_code::Q}, quit_rotate_command}, }; -map_editor_controller::rotate_state::rotate_state( - map_editor_controller::select_state &, - map_editor_controller &) - : commands{ranges::views::concat(map_editor_controller::viewport_commands, rotate_commands) | ranges::to()}, +entity_editor_controller::rotate_state::rotate_state( + entity_editor_controller::select_state &, + entity_editor_controller &) + : commands{ranges::views::concat(entity_editor_controller::viewport_commands, rotate_commands) | ranges::to()}, key_command_map{ranges::views::all(commands) | ranges::to()} { } diff --git a/lmeditor/src/controller/map_editor/states/scale.cpp b/lmeditor/src/controller/entity_editor/states/scale.cpp similarity index 72% rename from lmeditor/src/controller/map_editor/states/scale.cpp rename to lmeditor/src/controller/entity_editor/states/scale.cpp index 3c60076..d681fff 100644 --- a/lmeditor/src/controller/map_editor/states/scale.cpp +++ b/lmeditor/src/controller/entity_editor/states/scale.cpp @@ -1,4 +1,4 @@ -#include "../map_editor_controller.h" +#include "../entity_editor_controller.h" #include #include @@ -14,10 +14,10 @@ void do_scale( } template -map_editor_controller::command create_scale_command(char const *name) +entity_editor_controller::command create_scale_command(char const *name) { - return map_editor_controller::command{ - [](map_editor_controller::command_args const &args) { + return entity_editor_controller::command{ + [](entity_editor_controller::command_args const &args) { Eigen::Vector3f *pextents{nullptr}; auto selected_box = args.controller.get_selection(); @@ -45,15 +45,15 @@ map_editor_controller::command create_scale_command(char const *name) }; } -map_editor_controller::command quit_scale_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command quit_scale_command{ + [](entity_editor_controller::command_args const &args) { args.controller.leave_state(); return true; }, "Stop scaling entity", }; -map_editor_controller::command_list scale_commands{ +entity_editor_controller::command_list scale_commands{ {{lmpl::key_code::I}, create_scale_command<1, 1>("Scale up (y)")}, {{lmpl::key_code::K}, create_scale_command<1, -1>("Scale down (y)")}, {{lmpl::key_code::J}, create_scale_command<0, -1>("Scale down (x)")}, @@ -63,10 +63,10 @@ map_editor_controller::command_list scale_commands{ {{lmpl::key_code::Q}, quit_scale_command}, }; -map_editor_controller::scale_state::scale_state( - map_editor_controller::select_state &, - map_editor_controller &) - : commands{ranges::views::concat(map_editor_controller::viewport_commands, scale_commands) | ranges::to()}, +entity_editor_controller::scale_state::scale_state( + entity_editor_controller::select_state &, + entity_editor_controller &) + : commands{ranges::views::concat(entity_editor_controller::viewport_commands, scale_commands) | ranges::to()}, key_command_map{ranges::views::all(commands) | ranges::to()} { } diff --git a/lmeditor/src/controller/map_editor/states/select.cpp b/lmeditor/src/controller/entity_editor/states/select.cpp similarity index 56% rename from lmeditor/src/controller/map_editor/states/select.cpp rename to lmeditor/src/controller/entity_editor/states/select.cpp index 58b686e..93f6a2f 100644 --- a/lmeditor/src/controller/map_editor/states/select.cpp +++ b/lmeditor/src/controller/entity_editor/states/select.cpp @@ -1,11 +1,11 @@ -#include "../map_editor_controller.h" +#include "../entity_editor_controller.h" #include #include namespace lmeditor { -map_editor_controller::command delete_selected_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command delete_selected_command{ + [](entity_editor_controller::command_args const &args) { if (args.controller.have_selection()) { auto selected_box = args.controller.get_selection(); @@ -20,14 +20,14 @@ map_editor_controller::command delete_selected_command{ "Delete selected", }; -map_editor_controller::command add_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command add_command{ + [](entity_editor_controller::command_args const &args) { Eigen::Vector3f add_pos = Eigen::Vector3f::Zero(); if (args.controller.have_selection()) { args.controller - .template enter_state( - std::get( + .template enter_state( + std::get( args.controller.state)); return true; } @@ -41,8 +41,8 @@ map_editor_controller::command add_command{ "Add entity", }; -map_editor_controller::command deselect_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command deselect_command{ + [](entity_editor_controller::command_args const &args) { if (args.controller.have_selection()) { args.controller.clear_selection(); @@ -53,13 +53,13 @@ map_editor_controller::command deselect_command{ "Clear selection", }; -map_editor_controller::command translate_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command translate_command{ + [](entity_editor_controller::command_args const &args) { if (args.controller.have_selection()) { args.controller - .template enter_state( - std::get( + .template enter_state( + std::get( args.controller.state)); return true; } @@ -69,14 +69,14 @@ map_editor_controller::command translate_command{ "Translate entity", }; -map_editor_controller::command copy_entity_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command copy_entity_command{ + [](entity_editor_controller::command_args const &args) { Eigen::Vector3f add_pos = Eigen::Vector3f::Zero(); if (args.controller.have_selection()) { args.controller - .template enter_state( - std::get( + .template enter_state( + std::get( args.controller.state)); return true; } @@ -86,13 +86,13 @@ map_editor_controller::command copy_entity_command{ "Copy entity", }; -map_editor_controller::command reparent_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command reparent_command{ + [](entity_editor_controller::command_args const &args) { if (args.controller.have_selection()) { args.controller - .template enter_state( - std::get( + .template enter_state( + std::get( args.controller.state)); return true; } @@ -102,8 +102,8 @@ map_editor_controller::command reparent_command{ "Reparent entity", }; -map_editor_controller::command scale_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command scale_command{ + [](entity_editor_controller::command_args const &args) { auto selected_box = args.controller.get_selection(); if ( args.controller.have_selection() && @@ -111,8 +111,8 @@ map_editor_controller::command scale_command{ args.map.has(selected_box))) { args.controller - .template enter_state( - std::get( + .template enter_state( + std::get( args.controller.state)); return true; } @@ -122,13 +122,13 @@ map_editor_controller::command scale_command{ "Scale entity", }; -map_editor_controller::command rotate_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command rotate_command{ + [](entity_editor_controller::command_args const &args) { if (args.controller.have_selection()) { args.controller - .template enter_state( - std::get( + .template enter_state( + std::get( args.controller.state)); return true; } @@ -138,7 +138,7 @@ map_editor_controller::command rotate_command{ "Rotate entity", }; -map_editor_controller::command_list select_commands{ +entity_editor_controller::command_list select_commands{ {{lmpl::key_code::X}, delete_selected_command}, {{lmpl::key_code::A}, add_command}, {{lmpl::key_code::N}, deselect_command}, @@ -149,9 +149,9 @@ map_editor_controller::command_list select_commands{ {{lmpl::key_code::LeftShift, lmpl::key_code::R}, rotate_command}, }; -map_editor_controller::select_state::select_state( - map_editor_controller &map_editor) - : commands{ranges::views::concat(map_editor_controller::move_selection_commands, map_editor_controller::viewport_commands, select_commands) | ranges::to()}, +entity_editor_controller::select_state::select_state( + entity_editor_controller &controller) + : commands{ranges::views::concat(entity_editor_controller::move_selection_commands, entity_editor_controller::viewport_commands, select_commands) | ranges::to()}, key_command_map{ranges::views::all(commands) | ranges::to()} { } diff --git a/lmeditor/src/controller/map_editor/states/translate.cpp b/lmeditor/src/controller/entity_editor/states/translate.cpp similarity index 57% rename from lmeditor/src/controller/map_editor/states/translate.cpp rename to lmeditor/src/controller/entity_editor/states/translate.cpp index df95864..9f682da 100644 --- a/lmeditor/src/controller/map_editor/states/translate.cpp +++ b/lmeditor/src/controller/entity_editor/states/translate.cpp @@ -1,4 +1,4 @@ -#include "../map_editor_controller.h" +#include "../entity_editor_controller.h" #include #include #include @@ -6,14 +6,14 @@ namespace lmeditor { Eigen::Vector3f get_translation( - map_editor_controller &map_editor, + entity_editor_controller &controller, entt::registry const &map, lmtk::key_down_event const &key_down_event, Eigen::Vector3f const &direction) { - auto extents = map_editor.get_selection_extents(map); + auto extents = controller.get_selection_extents(map); - auto snapped_direction = map_editor.view_to_axis(direction); + auto snapped_direction = controller.view_to_axis(direction); Eigen::Vector3f translation = snapped_direction.cwiseProduct(extents); if (!key_down_event.input_state.key_state.shift()) @@ -21,12 +21,12 @@ Eigen::Vector3f get_translation( translation.normalize(); translation *= 0.01f; } - auto frame = lmng::get_frame(map, map_editor.get_selection()); + auto frame = lmng::get_frame(map, controller.get_selection()); return frame.rotation.inverse() * translation; } void do_translation( - map_editor_controller::command_args const &args, + entity_editor_controller::command_args const &args, Eigen::Vector3f const &direction) { args.controller.translate( @@ -36,63 +36,63 @@ void do_translation( args.controller, args.map, args.key_down_event, direction)); } -map_editor_controller::command move_up_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_up_command{ + [](entity_editor_controller::command_args const &args) { do_translation(args, Eigen::Vector3f::UnitY()); return true; }, "Move entity up", }; -map_editor_controller::command move_down_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_down_command{ + [](entity_editor_controller::command_args const &args) { do_translation(args, -Eigen::Vector3f::UnitY()); return true; }, "Move entity down", }; -map_editor_controller::command move_left_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_left_command{ + [](entity_editor_controller::command_args const &args) { do_translation(args, -Eigen::Vector3f::UnitX()); return true; }, "Move entity left", }; -map_editor_controller::command move_right_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_right_command{ + [](entity_editor_controller::command_args const &args) { do_translation(args, Eigen::Vector3f::UnitX()); return true; }, "Move entity right", }; -map_editor_controller::command move_forward_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_forward_command{ + [](entity_editor_controller::command_args const &args) { do_translation(args, -Eigen::Vector3f::UnitZ()); return true; }, "Move entity forward", }; -map_editor_controller::command move_back_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_back_command{ + [](entity_editor_controller::command_args const &args) { do_translation(args, Eigen::Vector3f::UnitZ()); return true; }, "Move entity back", }; -map_editor_controller::command quit_move_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command quit_move_command{ + [](entity_editor_controller::command_args const &args) { args.controller.leave_state(); return true; }, "Stop moving entity", }; -map_editor_controller::command_list move_commands{ +entity_editor_controller::command_list move_commands{ {{lmpl::key_code::I}, move_up_command}, {{lmpl::key_code::K}, move_down_command}, {{lmpl::key_code::J}, move_left_command}, @@ -102,10 +102,10 @@ map_editor_controller::command_list move_commands{ {{lmpl::key_code::Q}, quit_move_command}, }; -map_editor_controller::translate_state::translate_state( - map_editor_controller::select_state &, - map_editor_controller &) - : commands{ranges::views::concat(map_editor_controller::viewport_commands, move_commands) | ranges::to()}, +entity_editor_controller::translate_state::translate_state( + entity_editor_controller::select_state &, + entity_editor_controller &) + : commands{ranges::views::concat(entity_editor_controller::viewport_commands, move_commands) | ranges::to()}, key_command_map{ranges::views::all(commands) | ranges::to()} { } diff --git a/lmeditor/src/controller/map_editor/viewport_commands.cpp b/lmeditor/src/controller/entity_editor/viewport_commands.cpp similarity index 69% rename from lmeditor/src/controller/map_editor/viewport_commands.cpp rename to lmeditor/src/controller/entity_editor/viewport_commands.cpp index 41539be..8b5c59b 100644 --- a/lmeditor/src/controller/map_editor/viewport_commands.cpp +++ b/lmeditor/src/controller/entity_editor/viewport_commands.cpp @@ -1,14 +1,14 @@ -#include "map_editor_controller.h" +#include "entity_editor_controller.h" #include namespace lmeditor { template -map_editor_controller::command create_orbit_command(char const *name) +entity_editor_controller::command create_orbit_command(char const *name) { - return map_editor_controller::command{ - [](map_editor_controller::command_args const &args) { + return entity_editor_controller::command{ + [](entity_editor_controller::command_args const &args) { float amount{0.05f}; if (args.key_down_event.input_state.key_state.shift()) @@ -25,24 +25,24 @@ map_editor_controller::command create_orbit_command(char const *name) name, }; } -map_editor_controller::command move_camera_forward_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_camera_forward_command{ + [](entity_editor_controller::command_args const &args) { args.controller.move_camera_closer( args.key_down_event.input_state.key_state.shift() ? 0.5f : 0.1f); return true; }, "Move camera forward", }; -map_editor_controller::command move_camera_back_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_camera_back_command{ + [](entity_editor_controller::command_args const &args) { args.controller.move_camera_further( args.key_down_event.input_state.key_state.shift() ? 0.5f : 0.1f); return true; }, "Move camera back", }; -map_editor_controller::command move_to_selection_command{ - [](map_editor_controller::command_args const &args) { +entity_editor_controller::command move_to_selection_command{ + [](entity_editor_controller::command_args const &args) { if (args.controller.have_selection()) args.controller.camera.move_to_target( lmng::resolve_transform(args.map, args.controller.get_selection()) @@ -52,7 +52,8 @@ map_editor_controller::command move_to_selection_command{ "Move camera to selection", }; -map_editor_controller::command_list map_editor_controller::viewport_commands{ +entity_editor_controller::command_list + entity_editor_controller::viewport_commands{ {{lmpl::key_code::S}, create_orbit_command<1, 1>("Orbit camera right")}, {{lmpl::key_code::F}, create_orbit_command<1, -1>("Orbit camera left")}, {{lmpl::key_code::E}, create_orbit_command<0, 1>("Orbit camera down")}, diff --git a/lmeditor/src/controller/map_editor/states/reparent.cpp b/lmeditor/src/controller/map_editor/states/reparent.cpp deleted file mode 100644 index 86ca827..0000000 --- a/lmeditor/src/controller/map_editor/states/reparent.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "../map_editor_controller.h" -#include -#include -#include - -namespace lmeditor -{ -map_editor_controller::command select_parent{ - [](map_editor_controller::command_args const &args) { - auto selected_box = args.controller.get_selection(); - - auto &reparent_state = - std::get(args.controller.state); - - if (selected_box == reparent_state.entity) - return false; - - lmng::reparent(args.map, reparent_state.entity, selected_box); - args.controller.leave_state(); - return true; - }, - "Select new parent", -}; - -map_editor_controller::command quit_reparent{ - [](map_editor_controller::command_args const &args) { - args.controller.leave_state(); - return true; - }, - "Cancel reparent", -}; - -map_editor_controller::command_list reparent_commands{ - {{lmpl::key_code::Enter}, select_parent}, - {{lmpl::key_code::Q}, quit_reparent}, -}; - -map_editor_controller::reparent_state::reparent_state( - map_editor_controller::select_state &, - map_editor_controller &map_editor) - : commands{ranges::views::concat(map_editor_controller::move_selection_commands, map_editor_controller::viewport_commands, reparent_commands) | ranges::to()}, - key_command_map{ranges::views::all(commands) | ranges::to()}, - entity{map_editor.get_selection()} -{ -} -} // namespace lmeditor diff --git a/lmeditor/test/map_editor/test.cpp b/lmeditor/test/entity_editor/test.cpp similarity index 76% rename from lmeditor/test/map_editor/test.cpp rename to lmeditor/test/entity_editor/test.cpp index 2a43807..898ee2b 100644 --- a/lmeditor/test/map_editor/test.cpp +++ b/lmeditor/test/entity_editor/test.cpp @@ -1,8 +1,8 @@ -#include "map_editor_controller_test_case.h" +#include "test_case.h" #include -TEST_CASE_METHOD(map_editor_controller_test_case, "Add cube position") +TEST_CASE_METHOD(entity_editor_controller_test_case, "Add cube position") { Eigen::Vector3f cube_pos{2.f, 0.f, 0.f}; auto cube_id = controller.add_cube(map, cube_pos, 1.f); @@ -10,7 +10,7 @@ TEST_CASE_METHOD(map_editor_controller_test_case, "Add cube position") REQUIRE(map.get(cube_id).position == cube_pos); } -TEST_CASE_METHOD(map_editor_controller_test_case, "Deselect") +TEST_CASE_METHOD(entity_editor_controller_test_case, "Deselect") { auto cube = controller.add_cube(map, {0.f, 0.f, 0.f}, 1.f); diff --git a/lmeditor/test/map_editor/map_editor_controller_test_case.h b/lmeditor/test/entity_editor/test_case.h similarity index 71% rename from lmeditor/test/map_editor/map_editor_controller_test_case.h rename to lmeditor/test/entity_editor/test_case.h index 08182a5..a1574bc 100644 --- a/lmeditor/test/map_editor/map_editor_controller_test_case.h +++ b/lmeditor/test/entity_editor/test_case.h @@ -1,17 +1,17 @@ #pragma once -#include "../../src/controller/map_editor/map_editor_controller.h" +#include "../../src/controller/entity_editor/entity_editor_controller.h" #include #include -class map_editor_controller_test_case +class entity_editor_controller_test_case { protected: entt::registry map; - lmeditor::map_editor_controller controller; + lmeditor::entity_editor_controller controller; public: - map_editor_controller_test_case() + entity_editor_controller_test_case() : controller{ map, lmeditor::orbital_camera_init{ diff --git a/lmeditor/test/map_editor/test_move_selection.cpp b/lmeditor/test/entity_editor/test_move_selection.cpp similarity index 96% rename from lmeditor/test/map_editor/test_move_selection.cpp rename to lmeditor/test/entity_editor/test_move_selection.cpp index 8fa46ae..a3837ba 100644 --- a/lmeditor/test/map_editor/test_move_selection.cpp +++ b/lmeditor/test/entity_editor/test_move_selection.cpp @@ -1,8 +1,8 @@ -#include "map_editor_controller_test_case.h" +#include "test_case.h" #include #include -TEST_CASE_METHOD(map_editor_controller_test_case, "Move selection") +TEST_CASE_METHOD(entity_editor_controller_test_case, "Move selection") { std::array cubes{ controller.add_cube(map, {0.f, 0.f, 0.f}, 1.f), @@ -113,7 +113,7 @@ TEST_CASE_METHOD(map_editor_controller_test_case, "Move selection") TEST_CASE("Move selection snaps to world axes") { entt::registry map; - lmeditor::map_editor_controller controller{ + lmeditor::entity_editor_controller controller{ map, lmeditor::orbital_camera_init{ .fov = (float)M_PI / 3, @@ -146,7 +146,7 @@ TEST_CASE("Move selection snaps to world axes") } TEST_CASE_METHOD( - map_editor_controller_test_case, + entity_editor_controller_test_case, "Move selection minimum distance") { std::array cubes{ @@ -163,7 +163,7 @@ TEST_CASE_METHOD( } TEST_CASE_METHOD( - map_editor_controller_test_case, + entity_editor_controller_test_case, "Move selection with no selection") { std::array cubes{ @@ -216,7 +216,7 @@ TEST_CASE_METHOD( REQUIRE(controller.get_selection() == cubes[expected_selection]); } -TEST_CASE_METHOD(map_editor_controller_test_case, "Lone entity selection") +TEST_CASE_METHOD(entity_editor_controller_test_case, "Lone entity selection") { lmtk::input_state input_state{}; From 32f9ed0e3142afe6c3732a9f667552c03ef86519 Mon Sep 17 00:00:00 2001 From: Lawrence Millar-Madigan Date: Mon, 27 Jul 2020 21:00:09 +1000 Subject: [PATCH 2/2] WIP: Add configuration to visual registry editor --- .../lmeditor/component/entity_editor.h | 56 +++++++++++++++++++ lmeditor/src/app/app.cpp | 1 + 2 files changed, 57 insertions(+) diff --git a/lmeditor/include/lmeditor/component/entity_editor.h b/lmeditor/include/lmeditor/component/entity_editor.h index 4c90bbe..7e76d2b 100644 --- a/lmeditor/include/lmeditor/component/entity_editor.h +++ b/lmeditor/include/lmeditor/component/entity_editor.h @@ -1,12 +1,67 @@ #pragma once #include "component.h" +#include #include #include #include namespace lmeditor { +struct entity_editor_features +{ + enum class flag + { + // Add non-root entities ie. new children + add, + // Add root entities ie. without a parent + add_root, + reparent, + rotate, + scale, + translate, + n_features + }; + + entity_editor_features &add() + { + flags.set(static_cast(flag::add)); + return *this; + } + + entity_editor_features &add_root() + { + flags.set(static_cast(flag::add_root)); + return *this; + } + + entity_editor_features &reparent() + { + flags.set(static_cast(flag::reparent)); + return *this; + } + + entity_editor_features &rotate() + { + flags.set(static_cast(flag::rotate)); + return *this; + } + + entity_editor_features &scale() + { + flags.set(static_cast(flag::scale)); + return *this; + } + + entity_editor_features &translate() + { + flags.set(static_cast(flag::translate)); + return *this; + } + + std::bitset(flag::n_features)> flags; +}; + struct entity_editor_init { entt::registry ®istry; @@ -16,6 +71,7 @@ struct entity_editor_init lm::point2i position; lm::size2i size; std::array selection_outline_colour; + entity_editor_features features; component operator()(); }; diff --git a/lmeditor/src/app/app.cpp b/lmeditor/src/app/app.cpp index e31bf20..df210a5 100644 --- a/lmeditor/src/app/app.cpp +++ b/lmeditor/src/app/app.cpp @@ -102,6 +102,7 @@ editor_app::editor_app(const std::filesystem::path &project_dir) {0, 0}, map_editor_size, std::array{1.f, 0.f, 0.f}, + entity_editor_features{}.add().add_root().reparent().rotate().scale().translate. }(); auto config_asset_dir = project_config["asset_directory"];