From 8dc6330879215470975bbdff0c352464f89f2a08 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Tue, 7 Sep 2021 23:49:08 +0100 Subject: [PATCH] add imgui entity list --- CMakeLists.txt | 3 ++- demo/main.cpp | 35 ++++++++++++++++++++--------- fggl/debug/CMakeLists.txt | 1 + fggl/debug/ecs.cpp | 23 +++++++++++++++++++ fggl/debug/ecs.hpp | 17 ++++++++++++++ fggl/ecs2/CMakeLists.txt | 2 +- vendor/flecs/modules/CMakeLists.txt | 5 +++++ 7 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 fggl/debug/ecs.cpp create mode 100644 fggl/debug/ecs.hpp create mode 100644 vendor/flecs/modules/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index aecfefa..5a8aeff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,11 +28,12 @@ endif () add_subdirectory(vendor/imgui/) add_subdirectory(vendor/flecs/core) +add_subdirectory(vendor/flecs/modules) # engine #set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*") add_subdirectory(fggl) # extras -add_subdirectory(tests) +#add_subdirectory(tests) add_subdirectory(demo) diff --git a/demo/main.cpp b/demo/main.cpp index f68e289..066522d 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -12,6 +12,7 @@ #include <fggl/gfx/ecs-cam.hpp> #include <fggl/math/ecs.hpp> +#include <fggl/debug/ecs.hpp> #include <fggl/data/procedural.hpp> #include <fggl/debug/debug.h> @@ -217,15 +218,6 @@ int main(int argc, char* argv[]) { camEnt.set<fggl::components::Camera>({}); } - auto floorEnt = world.create(); - { - floorEnt.set<fggl::math::Transform>( {} ); - - fggl::data::Mesh mesh = fggl::data::make_quad_xz(); - auto token = meshRenderer.upload( mesh ); - floorEnt.set<fggl::components::GfxToken>( token ); - } - // bunker prefab constexpr float HALF_PI = M_PI / 2.0f; constexpr int nSections = 2; @@ -262,15 +254,35 @@ int main(int argc, char* argv[]) { } // create testing bunkers - int nCubes = 3; + int nCubes = 1; for ( int i=0; i<nCubes; i++ ) { auto bunker = world.create(bunkerPrototype); - //bunker.add<fggl::components::GfxMat>(); auto trans = bunker.get_mut<fggl::components::Transform>(); trans->origin( glm::vec3( i * 5.0f, 0.0f, 0.0f) ); } + auto floorEnt = world.create("floor"); + { + floorEnt.set<fggl::math::Transform>( {} ); + floorEnt.set<fggl::components::GfxMat>( {} ); + + auto trans = floorEnt.get_mut<fggl::components::Transform>(); + trans->origin( glm::vec3( 10.0f, 0.0f, 0.0f) ); + + // create mesh + fggl::data::Mesh mesh; + fggl::data::make_cube( mesh, fggl::math::mat4(1.0f) ); + for (int i=0; i<10; i++ ) { + fggl::data::make_cube( mesh, glm::translate( fggl::math::mat4( 1.0f ), fggl::math::vec3( 0.0f, i * 1.0f, 0.0f) ) ); + } + mesh.removeDups(); + + auto token = meshRenderer.upload( mesh ); + token.pipeline = cache.get("phong"); + + floorEnt.set<fggl::components::GfxToken>( token ); + } fggl::gfx::Input& input = fggl::gfx::Input::instance(); @@ -291,6 +303,7 @@ int main(int argc, char* argv[]) { // imgui demos debugJoystickWindow( &joystickWindow, input ); debugGamepadWindow( &gamepadWindow, input ); + fggl::debug::showEntityList(world.ecs()); // render step ogl.clear(); diff --git a/fggl/debug/CMakeLists.txt b/fggl/debug/CMakeLists.txt index 50de25c..c448086 100644 --- a/fggl/debug/CMakeLists.txt +++ b/fggl/debug/CMakeLists.txt @@ -2,6 +2,7 @@ target_sources(fggl PRIVATE debug.cpp + ecs.cpp ) target_link_libraries(fggl imgui) diff --git a/fggl/debug/ecs.cpp b/fggl/debug/ecs.cpp new file mode 100644 index 0000000..185af4d --- /dev/null +++ b/fggl/debug/ecs.cpp @@ -0,0 +1,23 @@ +#include <fggl/debug/ecs.hpp> +#include <fggl/math/ecs.hpp> + +#include <string> +#include <imgui.h> + +namespace fggl::debug { + + void showEntityList(flecs::world &world) { + auto query = world.query<const fggl::components::Transform>(); + bool visible = true; + + ImGui::Begin("Entity List", &visible); + query.iter([&visible](flecs::iter& it, const fggl::components::Transform* t) { + for ( auto i : it ) { + auto entity = it.entity(i); + ImGui::Text("%s (#%lu)", entity.name().c_str(), entity.id() ); + } + }); + ImGui::End(); + } + +} diff --git a/fggl/debug/ecs.hpp b/fggl/debug/ecs.hpp new file mode 100644 index 0000000..9a59942 --- /dev/null +++ b/fggl/debug/ecs.hpp @@ -0,0 +1,17 @@ +#include <flecs.h> +#include <flecs_meta.h> + +namespace fggl::debug { + void showEntityList(flecs::world& world); +} + +namespace fggl::systems { + + class Editor { + inline Editor(flecs::world& world) { + world.system<Editor>(); + + flecs::import<flecs::components::meta>(world); + } + }; +} diff --git a/fggl/ecs2/CMakeLists.txt b/fggl/ecs2/CMakeLists.txt index 1b492b6..1c2d488 100644 --- a/fggl/ecs2/CMakeLists.txt +++ b/fggl/ecs2/CMakeLists.txt @@ -3,4 +3,4 @@ target_sources(fggl PRIVATE ecs.cpp ) -target_link_libraries(fggl flecs) +target_link_libraries(fggl flecs flecsmodules) diff --git a/vendor/flecs/modules/CMakeLists.txt b/vendor/flecs/modules/CMakeLists.txt new file mode 100644 index 0000000..ec65c27 --- /dev/null +++ b/vendor/flecs/modules/CMakeLists.txt @@ -0,0 +1,5 @@ +project(flecsmodules LANGUAGES C) + +add_library(flecsmodules STATIC src/flecs_meta.c ) +target_include_directories(flecsmodules PUBLIC include/) +target_link_libraries(flecsmodules flecs) -- GitLab