From 4e78815965dfa07a691579c60634e7af6c54f0f8 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sat, 29 Nov 2025 03:21:18 -0800 Subject: [PATCH 01/42] Renamed atlas::scene_scope to atlas::scene --- atlas/core/scene/scene.hpp | 6 +++--- atlas/core/scene/world.hpp | 14 +++++++------- atlas/core/serialize/serializer.hpp | 4 ++-- editor/level_scene.cpp | 2 +- editor/level_scene.hpp | 2 +- src/atlas/core/application.cpp | 2 +- src/atlas/core/scene/scene.cpp | 4 +++- src/atlas/core/scene/world.cpp | 2 +- src/atlas/core/serialize/serializer.cpp | 4 ++-- src/atlas/drivers/vulkan-cpp/vk_renderer.cpp | 4 ++-- tests/jolt_engine.test.cpp | 6 +++--- tests/scene.test.cpp | 3 +-- 12 files changed, 27 insertions(+), 26 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index 12af1a79..cf6bf597 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -23,18 +23,18 @@ namespace atlas { * helps manages these scenes and consider them as contexts that can be * switched/toggled based on users transforms. */ - class scene_scope { + class scene { public: /** * @param p_name is the name given to this scene * @param p_bus is the globalized event bus that is given access to the * scene to subscribe events to it. */ - scene_scope(const std::string& p_name, event::event_bus& p_bus) + scene(const std::string& p_name, event::event_bus& p_bus) : m_name(p_name) , m_bus(&p_bus) {} - virtual ~scene_scope() = default; + virtual ~scene() = default; /** * @brief Used to creating a game object diff --git a/atlas/core/scene/world.hpp b/atlas/core/scene/world.hpp index 8a3bda8d..9ad179a6 100644 --- a/atlas/core/scene/world.hpp +++ b/atlas/core/scene/world.hpp @@ -45,13 +45,13 @@ namespace atlas { * scenes as this is quite problematic. Should direct attention to this * soon. */ - void add_scene(const ref& p_scene_context); + void add_scene(const ref& p_scene_context); template - ref create_custom_scene(const std::string& p_name) { + ref create_custom_scene(const std::string& p_name) { static_assert( - std::is_base_of_v, - "Must be a scene that inherits from scene_scope as a base class"); + std::is_base_of_v, + "Must be a scene that inherits from scene as a base class"); m_scene_container[p_name] = create_ref(p_name); return m_scene_container[p_name]; } @@ -64,17 +64,17 @@ namespace atlas { * the player is in within the world, then provide the current scene * based on that information */ - ref get_scene(const std::string& p_tag) { + ref get_scene(const std::string& p_tag) { if (!m_scene_container.contains(p_tag)) { throw std::runtime_error( - "Could not access ref from " + "Could not access ref from " "world_scope::get_scene(const string& p_tag)!!!"); } return m_scene_container[p_tag]; } private: - std::map> m_scene_container; + std::map> m_scene_container; ref m_world_shared_instance; std::string m_name = "Undefined Tag"; }; diff --git a/atlas/core/serialize/serializer.hpp b/atlas/core/serialize/serializer.hpp index 4abf817b..ac5c09ba 100644 --- a/atlas/core/serialize/serializer.hpp +++ b/atlas/core/serialize/serializer.hpp @@ -24,7 +24,7 @@ namespace atlas { * @param p_scene_ctx is the current scene to perform * serialization/deserialization to */ - serializer(const ref& p_scene_ctx); + serializer(const ref& p_scene_ctx); /** * @param p_filepath is the specified path to save the file @@ -42,7 +42,7 @@ namespace atlas { const flecs::world& p_registry); private: - ref m_current_scene_ctx; + ref m_current_scene_ctx; }; }; // namespace atlas \ No newline at end of file diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 18947d46..47dfe1ef 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -6,7 +6,7 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) - : atlas::scene_scope(p_name, p_bus) { + : atlas::scene(p_name, p_bus) { m_camera = create_object("Editor Camera"); m_camera->add>(); m_camera->set({ diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index 17f26faa..4c519cc9 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -18,7 +18,7 @@ * */ -class level_scene final : public atlas::scene_scope { +class level_scene final : public atlas::scene { public: level_scene(const std::string& p_tag, atlas::event::event_bus& p_bus); diff --git a/src/atlas/core/application.cpp b/src/atlas/core/application.cpp index 4116f29a..6f968009 100644 --- a/src/atlas/core/application.cpp +++ b/src/atlas/core/application.cpp @@ -83,7 +83,7 @@ namespace atlas { ref current_world = system_registry::get_world("Editor World"); - ref current_scene = current_world->get_scene("LevelScene"); + ref current_scene = current_world->get_scene("LevelScene"); flecs::world current_world_scope = *current_scene; diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index db4886bb..aa2c405f 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -1,3 +1,5 @@ #include -namespace atlas {}; \ No newline at end of file +namespace atlas { + +}; \ No newline at end of file diff --git a/src/atlas/core/scene/world.cpp b/src/atlas/core/scene/world.cpp index 340a661c..8b343b74 100644 --- a/src/atlas/core/scene/world.cpp +++ b/src/atlas/core/scene/world.cpp @@ -16,7 +16,7 @@ namespace atlas { * TODO: Have a way of allowing creation and management of those * created-scenes be done through world_scope */ - void world_scope::add_scene(const ref& p_scene_context) { + void world_scope::add_scene(const ref& p_scene_context) { m_scene_container.emplace(p_scene_context->name(), p_scene_context); } }; \ No newline at end of file diff --git a/src/atlas/core/serialize/serializer.cpp b/src/atlas/core/serialize/serializer.cpp index 2830bd9e..83f4d3a5 100644 --- a/src/atlas/core/serialize/serializer.cpp +++ b/src/atlas/core/serialize/serializer.cpp @@ -147,7 +147,7 @@ namespace atlas { } } - serializer::serializer(const ref& p_scene_ctx) + serializer::serializer(const ref& p_scene_ctx) : m_current_scene_ctx(p_scene_ctx) {} void serializer::save(const std::filesystem::path& p_filepath) { @@ -161,7 +161,7 @@ namespace atlas { //! entities that the engine (user creates through our API) // ref world_object = // system_registry::get_world("Editor World"); - // ref current_scene = + // ref current_scene = // world_object->get_scene("LevelScene"); // flecs::query<> q = diff --git a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp index 260d3f9d..d9282f19 100644 --- a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp +++ b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp @@ -215,7 +215,7 @@ namespace atlas::vk { // set 1 -- material uniforms ref current_world = system_registry::get_world("Editor World"); - ref current_scene = current_world->get_scene("LevelScene"); + ref current_scene = current_world->get_scene("LevelScene"); flecs::query<> caching = current_scene->query_builder().build(); @@ -485,7 +485,7 @@ namespace atlas::vk { ref current_world = system_registry::get_world("Editor World"); - ref current_scene = current_world->get_scene("LevelScene"); + ref current_scene = current_world->get_scene("LevelScene"); // query all entities that have a point light flecs::query query_point_lights = diff --git a/tests/jolt_engine.test.cpp b/tests/jolt_engine.test.cpp index 1c042211..706124ea 100644 --- a/tests/jolt_engine.test.cpp +++ b/tests/jolt_engine.test.cpp @@ -25,10 +25,10 @@ namespace atlas { boost::ut::suite<"physics_engine_integration"> engine_test = [] { using namespace boost::ut; - class test_scene : public scene_scope { + class test_scene : public scene { public: test_scene(const std::string& p_tag, event::event_bus& p_bus) - : scene_scope(p_tag, p_bus) {}; + : scene(p_tag, p_bus) {}; std::pmr::polymorphic_allocator<> m_object_allocator; }; @@ -50,7 +50,7 @@ namespace atlas { /** * @bug FIXME: This does not work because the operator in - * scene_scope: + * scene: * operator flecs::world() { return m_registry; } * * Returns a copy of the flecs world. This can be an invalid diff --git a/tests/scene.test.cpp b/tests/scene.test.cpp index de1c0013..e9487d67 100644 --- a/tests/scene.test.cpp +++ b/tests/scene.test.cpp @@ -5,8 +5,7 @@ boost::ut::suite<"::scene"> scene_test = []() { using namespace boost::ut; atlas::event::event_bus test_event_bus; - atlas::scene_scope test_scope = - atlas::scene_scope("Mock Scene 1", test_event_bus); + atlas::scene test_scope = atlas::scene("Mock Scene 1", test_event_bus); "create_object"_test = [&test_scope]() { atlas::strong_ref test_object = From 2583b0495fd87ead7244892c7093c17db9299d91 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 04:33:06 -0800 Subject: [PATCH 02/42] Refactored the scene class and scene_object class to not be wrapped around strong_ptr --- atlas/core/scene/scene.hpp | 16 +++++++-------- editor/level_scene.cpp | 36 ++++++++++++---------------------- editor/level_scene.hpp | 19 +++++++++--------- src/CMakeLists.txt | 2 ++ src/atlas/core/scene/scene.cpp | 17 +++++++++++++++- 5 files changed, 49 insertions(+), 41 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index cf6bf597..d0be21b7 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace atlas { @@ -30,9 +31,7 @@ namespace atlas { * @param p_bus is the globalized event bus that is given access to the * scene to subscribe events to it. */ - scene(const std::string& p_name, event::event_bus& p_bus) - : m_name(p_name) - , m_bus(&p_bus) {} + scene(const std::string& p_name, event::event_bus& p_bus); virtual ~scene() = default; @@ -43,10 +42,11 @@ namespace atlas { * * @return strong_ptr */ - strong_ref create_object(const std::string& p_name) { - return create_strong_ref( - m_allocator, &m_registry, p_name); - } + // strong_ref create_object(const std::string& p_name); + + scene_object_exp create(const std::string& p_name); + + /** * @brief subscribes an event to the event::bus to get invoked when @@ -134,7 +134,7 @@ namespace atlas { operator world&() { return m_registry; } private: - std::pmr::polymorphic_allocator<> m_allocator; + // std::pmr::polymorphic_allocator<> m_allocator; world m_registry; std::string m_name; event::event_bus* m_bus = nullptr; diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 47dfe1ef..364db009 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -7,7 +7,7 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) : atlas::scene(p_name, p_bus) { - m_camera = create_object("Editor Camera"); + m_camera = create("Editor Camera"); m_camera->add>(); m_camera->set({ .position = { 3.50f, 4.90f, 36.40f }, @@ -19,7 +19,10 @@ level_scene::level_scene(const std::string& p_name, .field_of_view = 45.f, }); - m_viking_room = create_object("Viking Room"); + m_bob_object = create("Bob"); + m_bob_object->add(); + + m_viking_room = create("Viking Room"); m_viking_room->add(); m_viking_room->set({ .position = { -2.70f, 2.70, -8.30f }, @@ -37,7 +40,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_cube = create_object("Aircraft"); + m_cube = create("Aircraft"); m_cube->set({ .position = { 0.f, 2.10f, -7.30f }, @@ -53,15 +56,7 @@ level_scene::level_scene(const std::string& p_name, // .diffuse = "assets/models/E-45-steel detail_2_col.jpg", }); - // atlas::material_metadata data = { - // .ambient = {0.2f, 0.2f, 0.2f}, - // .diffuse = {0.5f, 0.5f, 0.5f}, - // .specular = {1.0f, 1.0f, 1.0f}, - // .shininess = 64.f, - // }; - // m_cube->set(data); - - m_robot_model = create_object("Cube"); + m_robot_model = create("Cube"); m_robot_model->add(); // m_robot_model->add(); m_robot_model->set({ @@ -83,10 +78,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_child_object = create_object("Child"); - m_child_object->child_of(m_robot_model); - - m_platform = create_object("Platform"); + m_platform = create("Platform"); m_platform->set({ .scale = { 15.f, 0.30f, 10.0f }, @@ -102,7 +94,7 @@ level_scene::level_scene(const std::string& p_name, .half_extent = { 15.f, 0.30f, 10.0f }, }); - m_point_light = create_object("Point Light 1"); + m_point_light = create("Point Light 1"); m_point_light->set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, @@ -115,7 +107,7 @@ level_scene::level_scene(const std::string& p_name, m_point_light->add(); // for(size_t i = 0; i < 26; i++) { - // auto obj = create_object(std::format("Object #{}", i)); + // auto obj = create(std::format("Object #{}", i)); // obj->set({ // .restitution = 1.25f, // .body_movement_type = atlas::dynamic, @@ -140,10 +132,7 @@ level_scene::level_scene(const std::string& p_name, // m_many_objects.emplace_back(obj); // } - // Just adding this here, for testing purposes - // Basic serialization for testing to conform how the editor may work - // TODO -- have a stream writer/reader that can take a given scene structure - // for serialization + // TODO: Move this outside of level_scene m_deserializer_test = atlas::serializer(); subscribe(this, @@ -315,7 +304,8 @@ level_scene::on_ui_update() { if (ImGui::MenuItem("Create Empty Entity")) { // TODO -- Converting the operation to use strong_ptr to make // these operation more conformed - m_create_entity = create_object("Empty Entity"); + // m_create_entity = create("Empty Entity"); + m_current_entity = create("Empty Entity"); } ImGui::EndPopup(); } diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index 4c519cc9..56cf335c 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -46,16 +46,17 @@ class level_scene final : public atlas::scene { bool m_blink = false; atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - // TEMP: this is only for when creating an entity in the editor-space - atlas::optional_ref m_create_entity; - atlas::optional_ref m_child_object; - atlas::optional_ref m_viking_room; - atlas::optional_ref m_cube; - atlas::optional_ref m_robot_model; - atlas::optional_ref m_platform; + + atlas::scene_object_exp m_viking_room; + atlas::scene_object_exp m_cube; + atlas::scene_object_exp m_robot_model; + atlas::scene_object_exp m_platform; std::pmr::polymorphic_allocator<> m_allocator; - atlas::optional_ref m_camera; - atlas::optional_ref m_point_light; + atlas::scene_object_exp m_camera; + atlas::scene_object_exp m_point_light; + // atlas::scene_object_exp m_bob_object; + atlas::scene_object_exp m_bob_object; + atlas::scene_object_exp m_current_entity; float m_movement_speed = 10.f; // std::vector> m_many_objects; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4cb81c9..5e53d959 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,8 @@ set( ${SRC_DIR}/core/platforms/win32.cpp # System-related stuff + ${SRC_DIR}/core/scene/scene.cpp + ${SRC_DIR}/core/scene/game_object.cpp ${SRC_DIR}/core/scene/scene_object.cpp ${SRC_DIR}/core/system/registry.cpp diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index aa2c405f..df260f10 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -1,5 +1,20 @@ #include namespace atlas { - + scene::scene(const std::string& p_name, event::event_bus& p_bus) : m_name(p_name), m_bus(&p_bus) {} + + // strong_ref scene::create_object(const std::string& p_name) { + // return create_strong_ref( + // m_allocator, &m_registry, p_name); + // } + + // custom_entity scene::create(const std::string& p_name) { + // flecs::entity e = m_registry.entity(p_name.c_str()); + // return custom_entity(e); + // } + + scene_object_exp scene::create(const std::string& p_name) { + return scene_object_exp(m_registry.entity(p_name.c_str())); + } + }; \ No newline at end of file From 5f19d2d414b1f50dd74409edf27e8e18d693a08a Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 04:37:43 -0800 Subject: [PATCH 03/42] Added experimental game_objects.hpp/.cpp file for creating game objects --- atlas/core/scene/game_object.hpp | 39 ++++++++++++++++++++++++++++ src/atlas/core/scene/game_object.cpp | 35 +++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 atlas/core/scene/game_object.hpp create mode 100644 src/atlas/core/scene/game_object.cpp diff --git a/atlas/core/scene/game_object.hpp b/atlas/core/scene/game_object.hpp new file mode 100644 index 00000000..79fa49b1 --- /dev/null +++ b/atlas/core/scene/game_object.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include + +namespace atlas { + class scene_object_exp : public flecs::entity { + public: + scene_object_exp() = default; + scene_object_exp(flecs::world_t* p_registry, flecs::entity_t p_id); + + scene_object_exp(const flecs::entity& p_base); + + explicit scene_object_exp(flecs::entity& p_base); + + flecs::entity* operator->(); + }; + + // class scene_object_exp { + // public: + // scene_object_exp() = default; + // scene_object_exp(custom_entity& p_entity) : m_entity(&p_entity) {} + + + // custom_entity* operator->() const& { + // if(m_entity == nullptr) { + // throw std::runtime_error("Invalid access to game object!!"); + // } + + // return m_entity; + // } + + // operator custom_entity*() { + // return m_entity; + // } + + // private: + // custom_entity* m_entity; + // }; +}; \ No newline at end of file diff --git a/src/atlas/core/scene/game_object.cpp b/src/atlas/core/scene/game_object.cpp new file mode 100644 index 00000000..dc0eef68 --- /dev/null +++ b/src/atlas/core/scene/game_object.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +namespace atlas { + scene_object_exp::scene_object_exp( + flecs::world_t* p_registry, + flecs::entity_t p_id) + : flecs::entity(p_registry, p_id) { + add(); + } + + scene_object_exp::scene_object_exp( + const flecs::entity& p_base) + : flecs::entity(p_base) { + add(); + } + + scene_object_exp::scene_object_exp(flecs::entity& p_base) : flecs::entity(p_base) { + add(); + } + + flecs::entity* scene_object_exp::operator->() { + // We want to check if this game object is accessible or else throw an + // exception if invalid or nullptr + flecs::entity* e = this; + if (e == nullptr) { + throw std::runtime_error( + "Invalid access to an invalid pointer to game object"); + } + + return e; + } +}; \ No newline at end of file From 1a1ca16bf5215efcfe55eb4499a9cfce07eb3ef8 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 05:06:30 -0800 Subject: [PATCH 04/42] Updated includes and updated scene_object to work the same as game_object --- atlas/core/common.hpp | 1 + atlas/core/scene/game_object.hpp | 39 ----- atlas/core/scene/scene.hpp | 18 +-- atlas/core/scene/scene_object.hpp | 162 ++++--------------- atlas/core/ui/widgets.hpp | 2 +- editor/level_scene.hpp | 18 +-- src/CMakeLists.txt | 1 - src/atlas/core/scene/game_object.cpp | 35 ---- src/atlas/core/scene/scene.cpp | 4 +- src/atlas/core/scene/scene_object.cpp | 37 +++-- src/atlas/core/scene/world.cpp | 4 - src/atlas/drivers/vulkan-cpp/vk_renderer.cpp | 8 +- 12 files changed, 74 insertions(+), 255 deletions(-) delete mode 100644 atlas/core/scene/game_object.hpp delete mode 100644 src/atlas/core/scene/game_object.cpp diff --git a/atlas/core/common.hpp b/atlas/core/common.hpp index 65f3fea8..eee99ad2 100644 --- a/atlas/core/common.hpp +++ b/atlas/core/common.hpp @@ -2,6 +2,7 @@ // core includes #include +#include #include #include #include diff --git a/atlas/core/scene/game_object.hpp b/atlas/core/scene/game_object.hpp deleted file mode 100644 index 79fa49b1..00000000 --- a/atlas/core/scene/game_object.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -namespace atlas { - class scene_object_exp : public flecs::entity { - public: - scene_object_exp() = default; - scene_object_exp(flecs::world_t* p_registry, flecs::entity_t p_id); - - scene_object_exp(const flecs::entity& p_base); - - explicit scene_object_exp(flecs::entity& p_base); - - flecs::entity* operator->(); - }; - - // class scene_object_exp { - // public: - // scene_object_exp() = default; - // scene_object_exp(custom_entity& p_entity) : m_entity(&p_entity) {} - - - // custom_entity* operator->() const& { - // if(m_entity == nullptr) { - // throw std::runtime_error("Invalid access to game object!!"); - // } - - // return m_entity; - // } - - // operator custom_entity*() { - // return m_entity; - // } - - // private: - // custom_entity* m_entity; - // }; -}; \ No newline at end of file diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index d0be21b7..67469a76 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -1,11 +1,9 @@ #pragma once #include -#include -#include #include #include #include -#include +#include namespace atlas { @@ -36,17 +34,9 @@ namespace atlas { virtual ~scene() = default; /** - * @brief Used to creating a game object - * - * @param p_name is specified when creating or searching the object - * - * @return strong_ptr - */ - // strong_ref create_object(const std::string& p_name); - - scene_object_exp create(const std::string& p_name); - - + * @brief create a new entity (game object) + */ + scene_object create(const std::string& p_name); /** * @brief subscribes an event to the event::bus to get invoked when diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index 3c8bf869..504e4bfe 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -1,96 +1,20 @@ #pragma once -#include + +#include #include -#include #include -#include -#include namespace atlas { - - /** - * @brief scene_object represents a game obejct that is associated to a - * specific scene. - * - * This class is a wrapper around flecs::entity that provides API's useful - * for the user to perform specific operations. - * - * Operations that are included is iterations over children entities if the - * specific entity is a parent over any specified entity. - * - * atlas::scene_object are represented through the strong_ptr type to ensure - * for memory safety. Ensuring objects that are being created are not - * temporary, but also do not invoke default construction. - * - * - * Example Usage: - * - * ```C++ - * strong_ptr obj1 = scene->create_object("Cube"); - * obj1->add(); - * ``` - * - * TOOD: Need attention into revising how this is currently designed. - */ - class scene_object { + class scene_object : public flecs::entity { public: - /*** - * @param p_registry is the address to the ecs registry - * @param p_name is the name supplied to the entity - */ - scene_object(flecs::world* p_registry, const std::string& p_name); - - /*** - * @param p_registry is the address to the ecs registry - * @param p_name is the name supplied to the entity - * @param p_lookup is the tag to indicate lookup for alread-existing - * entity in flecs::world - */ - scene_object(flecs::world* p_registry, - const std::string& p_name, - bool p_lookup); - - /** - * @param p_registry is a strong_ptr that is expected to be always valid - * and manages this entity when application closes - */ - scene_object(strong_ref& p_registry, - const std::string& p_name); - - ~scene_object(); - - //! @brief adds a component to the entity - template - void add() { - m_entity.add(); - } - - //! @brief adds a component with an assigned value to the entity - template - void add(UComponent p_component_value) const { - m_entity.add(p_component_value); - } - - //! @brief sets the scene object to correspond to a specified parent - void child_of(const strong_ref& p_parent) { - flecs::entity e = *p_parent; - m_entity.add(flecs::ChildOf, e); - } + scene_object() = default; + scene_object(flecs::world_t* p_registry, flecs::entity_t p_id); - //! @brief iterates the entity children entities - template - void children(UFunction&& p_callback) { - m_entity.children(p_callback); - } + scene_object(const flecs::entity& p_base); - //! @return the entity's ID - [[nodiscard]] uint32_t id() const { return m_entity.id(); } + explicit scene_object(flecs::entity& p_base); - //! @return true if entity is alive, otherwise return false - [[nodiscard]] bool is_alive() const { return m_entity.is_alive(); } - - //! @return true if entity is valid, otherwise return false - [[nodiscard]] bool is_valid() const { return m_entity.is_valid(); } + void child_of(const scene_object& p_entity); /** * @brief Adds multiple components with no values assigned to them @@ -113,7 +37,7 @@ namespace atlas { [&](const auto& p_component) { std::apply( [&](auto&... p_placeholder) { - (m_entity.add>(), + (add>(), ...); }, p_component); @@ -121,57 +45,33 @@ namespace atlas { conditions); } - //! @return nullptr if entity is not found, otherwise return view of the - //! component - template - [[nodiscard]] const UComponent* get() const { - return m_entity.get(); - } - - //! @return nullptr if entity is not found, otherwise return mutable - //! component - template - [[nodiscard]] UComponent* get_mut() { - return m_entity.get_mut(); + template + void children(UFunction&& p_callback) { + children(p_callback); } - //! @brief is true if component stored in this entity - template - bool has() { - return m_entity.has(); - } + flecs::entity* operator->(); + }; - /** - * @brief set is used to set a component and to set the values of - * that specified component to the entity as an entire operation - * - * @tparam UComponent is the type of component - * - */ - template - void set(const UComponent& p_component) { - m_entity.set(p_component); - } + // class scene_object_exp { + // public: + // scene_object_exp() = default; + // scene_object_exp(custom_entity& p_entity) : m_entity(&p_entity) {} - //! @brief removes specified component from the entity - template - [[nodiscard]] flecs::entity& remove() const { - return m_entity.remove(); - } - //! @brief Explicitly for deleting the entity - void destruct() const { m_entity.destruct(); } + // custom_entity* operator->() const& { + // if(m_entity == nullptr) { + // throw std::runtime_error("Invalid access to game object!!"); + // } - //! @brief treating atlas::scene_object class as a const flecs::entity - //! for ease of access, if we do not want to modify this overload - //! specifically - operator flecs::entity() const { return m_entity; } + // return m_entity; + // } - //! @brief treating atlas::scene_object class as a flecs::entity for - //! ease of access - operator flecs::entity() { return m_entity; } + // operator custom_entity*() { + // return m_entity; + // } - private: - entity_t m_entity; - }; -}; // namespace atlas \ No newline at end of file + // private: + // custom_entity* m_entity; + // }; +}; \ No newline at end of file diff --git a/atlas/core/ui/widgets.hpp b/atlas/core/ui/widgets.hpp index 483e16bf..066bb23e 100644 --- a/atlas/core/ui/widgets.hpp +++ b/atlas/core/ui/widgets.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace atlas::ui { diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index 56cf335c..2f031b4f 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -47,16 +47,16 @@ class level_scene final : public atlas::scene { atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - atlas::scene_object_exp m_viking_room; - atlas::scene_object_exp m_cube; - atlas::scene_object_exp m_robot_model; - atlas::scene_object_exp m_platform; + atlas::scene_object m_viking_room; + atlas::scene_object m_cube; + atlas::scene_object m_robot_model; + atlas::scene_object m_platform; std::pmr::polymorphic_allocator<> m_allocator; - atlas::scene_object_exp m_camera; - atlas::scene_object_exp m_point_light; - // atlas::scene_object_exp m_bob_object; - atlas::scene_object_exp m_bob_object; - atlas::scene_object_exp m_current_entity; + atlas::scene_object m_camera; + atlas::scene_object m_point_light; + // atlas::scene_object m_bob_object; + atlas::scene_object m_bob_object; + atlas::scene_object m_current_entity; float m_movement_speed = 10.f; // std::vector> m_many_objects; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e53d959..9d711978 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,6 @@ set( # System-related stuff ${SRC_DIR}/core/scene/scene.cpp - ${SRC_DIR}/core/scene/game_object.cpp ${SRC_DIR}/core/scene/scene_object.cpp ${SRC_DIR}/core/system/registry.cpp diff --git a/src/atlas/core/scene/game_object.cpp b/src/atlas/core/scene/game_object.cpp deleted file mode 100644 index dc0eef68..00000000 --- a/src/atlas/core/scene/game_object.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include - -namespace atlas { - scene_object_exp::scene_object_exp( - flecs::world_t* p_registry, - flecs::entity_t p_id) - : flecs::entity(p_registry, p_id) { - add(); - } - - scene_object_exp::scene_object_exp( - const flecs::entity& p_base) - : flecs::entity(p_base) { - add(); - } - - scene_object_exp::scene_object_exp(flecs::entity& p_base) : flecs::entity(p_base) { - add(); - } - - flecs::entity* scene_object_exp::operator->() { - // We want to check if this game object is accessible or else throw an - // exception if invalid or nullptr - flecs::entity* e = this; - if (e == nullptr) { - throw std::runtime_error( - "Invalid access to an invalid pointer to game object"); - } - - return e; - } -}; \ No newline at end of file diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index df260f10..3cd81277 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -13,8 +13,8 @@ namespace atlas { // return custom_entity(e); // } - scene_object_exp scene::create(const std::string& p_name) { - return scene_object_exp(m_registry.entity(p_name.c_str())); + scene_object scene::create(const std::string& p_name) { + return scene_object(m_registry.entity(p_name.c_str())); } }; \ No newline at end of file diff --git a/src/atlas/core/scene/scene_object.cpp b/src/atlas/core/scene/scene_object.cpp index e974d0e6..6d1dd10b 100644 --- a/src/atlas/core/scene/scene_object.cpp +++ b/src/atlas/core/scene/scene_object.cpp @@ -1,28 +1,39 @@ #include #include +#include +#include namespace atlas { - scene_object::scene_object(flecs::world* p_registry, - const std::string& p_name) { - m_entity = p_registry->entity(p_name.c_str()); + scene_object::scene_object( + flecs::world_t* p_registry, + flecs::entity_t p_id) + : flecs::entity(p_registry, p_id) { add(); } - scene_object::scene_object(flecs::world* p_registry, - const std::string& p_name, - [[maybe_unused]] bool p_lookup) { - m_entity = p_registry->lookup(p_name.c_str()); + scene_object::scene_object( + const flecs::entity& p_base) + : flecs::entity(p_base) { + add(); } - scene_object::scene_object(strong_ref& p_registry, - const std::string& p_name) { - m_entity = p_registry->entity(p_name.c_str()); + scene_object::scene_object(flecs::entity& p_base) : flecs::entity(p_base) { add(); } - scene_object::~scene_object() { - if (m_entity.is_alive()) { - m_entity.destruct(); + void scene_object::child_of(const scene_object& p_parent) { + add(flecs::ChildOf, p_parent); + } + + flecs::entity* scene_object::operator->() { + // We want to check if this game object is accessible or else throw an + // exception if invalid or nullptr + flecs::entity* e = this; + if (e == nullptr) { + throw std::runtime_error( + "Invalid access to an invalid pointer to game object"); } + + return e; } }; \ No newline at end of file diff --git a/src/atlas/core/scene/world.cpp b/src/atlas/core/scene/world.cpp index 8b343b74..ed4ed409 100644 --- a/src/atlas/core/scene/world.cpp +++ b/src/atlas/core/scene/world.cpp @@ -7,10 +7,6 @@ namespace atlas { world_scope::world_scope(const std::string& p_name) : m_name(p_name) {} - world_scope::~world_scope() { - console_log_trace("~world_scope called!!!"); - } - /** * @brief Currently how to pass in the scene context to the world * TODO: Have a way of allowing creation and management of those diff --git a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp index d9282f19..d5510fa7 100644 --- a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp +++ b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp @@ -1,12 +1,8 @@ -#include -#include -#include - +#include #include +#include #include #include -#include - #include namespace atlas::vk { From 8b4b1e2a3663c5b28f17a9fb372355059d63eafc Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 05:10:28 -0800 Subject: [PATCH 05/42] Updated world.hpp with updated includes and added commented code to widgets.cpp --- atlas/core/scene/world.hpp | 3 +- src/atlas/core/ui/widgets.cpp | 56 ++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/atlas/core/scene/world.hpp b/atlas/core/scene/world.hpp index 9ad179a6..1bed730c 100644 --- a/atlas/core/scene/world.hpp +++ b/atlas/core/scene/world.hpp @@ -33,7 +33,8 @@ namespace atlas { * with it */ world_scope(const std::string& p_name); - ~world_scope(); + + virtual ~world_scope() = default; //! @return the name of world_scope [[nodiscard]] std::string name() const { return m_name; } diff --git a/src/atlas/core/ui/widgets.cpp b/src/atlas/core/ui/widgets.cpp index 5239ed14..d495bfa1 100644 --- a/src/atlas/core/ui/widgets.cpp +++ b/src/atlas/core/ui/widgets.cpp @@ -220,11 +220,59 @@ namespace atlas::ui { ImGui::PopID(); } - void draw_input_text(std::string& p_value) { - // std::string value = ""; - // // ImGui::Text("%s", p_value.c_str()); - if (ImGui::InputText("##Tag", p_value.data(), p_value.size() + 1)) { + void draw_input_text(std::string&) { + // 1. Define the buffer constraints + // This size is critical: it defines the maximum length ImGui will allow. + /* + constexpr size_t max_string_length = 255; + + // 2. Get the current entity name + // std::string current_name = p_selected_entity.name(); + + // 3. Create a temporary, mutable std::string for ImGui's buffer + // This string must be pre-sized to hold the entity name AND the extra space + // ImGui will use for new input, plus the null terminator. + std::string input_buffer = p_value; + + // Pad the string with null terminators to guarantee the maximum size for ImGui. + // This is the cleanest way to create a fixed-size 'char*' buffer using only std::string. + // We add one extra for safety, but ImGui will respect max_string_length. + input_buffer.resize(max_string_length + 1, '\0'); + + // 4. Use ImGui::InputText + // We pass the raw mutable pointer to the start of the string's buffer. + // .data() returns a non-const char* for non-const std::string in C++17+. + ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue; + + if (ImGui::InputText( + "##Name", + input_buffer.data(), // Crucial: Mutable char* access + max_string_length + 1, // Crucial: The fixed buffer size + flags) + ) { + // 5. Trim the std::string to the actual user input + // The buffer contains the new name followed by a null-terminator. + // We find the null-terminator and resize the string to that point. + // C++23: std::string::resize_and_overwrite could be used here, but + // a standard find and resize is clearer for this context. + + // Find the first null character, which marks the end of the user's input + size_t new_len = input_buffer.find('\0'); + + if (new_len != std::string::npos) { + input_buffer.resize(new_len); // Resize to the actual name length + } + else { + // Should not happen if ImGui works correctly, but safe guard against non-terminated string + input_buffer.resize(max_string_length); + } + + // 6. Commit the change to the flecs entity's name + // Use the newly resized and managed std::string. + // UNCOMMENT THIS TO GET DIS TO WORK! + // p_selected_entity.set_name(input_buffer.c_str()); } + */ } void draw_text(const std::string& p_value) { From f38eb84cc9841fd52ceee02603e25716e11b864f Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 05:13:32 -0800 Subject: [PATCH 06/42] Deleted unecessary files that were not supposed to be added --- atlas/objects_10.engine | 210 ---------------------- atlas/objects_20.engine | 381 ---------------------------------------- 2 files changed, 591 deletions(-) delete mode 100644 atlas/objects_10.engine delete mode 100644 atlas/objects_20.engine diff --git a/atlas/objects_10.engine b/atlas/objects_10.engine deleted file mode 100644 index 0c752c66..00000000 --- a/atlas/objects_10.engine +++ /dev/null @@ -1,210 +0,0 @@ -Scene: Untitled -Entities: - - Entity: 13670344671586780811 - Tag Component: - Tag: Actor 10 - TransformComponent: - Translation: [-0.600000024, 6.4000001, 0] - Rotation: [0, 0, 0.466002911] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.276053309, 0.759803891, 0.245818913, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 565836664600690285 - Tag Component: - Tag: Actor 9 - TransformComponent: - Translation: [-1.5, 5.0999999, 0] - Rotation: [0, 0, 0.588175952] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.123798534, 0.789215684, 0.123798534, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 11429847431533605332 - Tag Component: - Tag: Actor 8 - TransformComponent: - Translation: [1.20000005, 4.5999999, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.769607842, 0.27539891, 0.27539891, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 5257323963177412509 - Tag Component: - Tag: Actor 7 - TransformComponent: - Translation: [-2, 3.9000001, 0] - Rotation: [0, 0, 0.752236903] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.663481951, 0.159602046, 0.79411763, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 5806905725956582174 - Tag Component: - Tag: Actor 6 - TransformComponent: - Translation: [0.300000012, 5.5, 0] - Rotation: [0, 0, 0.542797387] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.389081091, 0.528394043, 0.862745106, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 12473161709214016708 - Tag Component: - Tag: Actor 5 - TransformComponent: - Translation: [-1.60000002, 2.5999999, 0] - Rotation: [0, 0, 0.706858337] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.42892158, 0.857843161, 0.529844284, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 266257173355641678 - Tag Component: - Tag: Actor 4 - TransformComponent: - Translation: [0.400000006, 2.79999995, 0] - Rotation: [0, 0.104719758, 0.778416812] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.344675094, 0.732204258, 0.799019575, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 4527899839142223245 - Tag Component: - Tag: Actor 3 - TransformComponent: - Translation: [-0.600000024, 3.70000005, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.63233602, 0.41522494, 0.784313738, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 10652494166102869686 - Tag Component: - Tag: Actor 2 - TransformComponent: - Translation: [-0.0891839564, 1.15999997, 0] - Rotation: [0, 0, 0.125115439] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.941176474, 0.226066872, 0.226066872, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 8530241877619612650 - Tag Component: - Tag: Camera - TransformComponent: - Translation: [0, 0, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - CameraComponent: - Camera: - ProjectionType: 1 - PerspectiveFOV: 0.785398185 - PerspectiveNear: 0.00999999978 - PerspectiveFar: 1000 - OrthographicSize: 10 - OrthographicNear: -1 - OrthographicFar: 1 - Primary: true - FixedAspectRatio: false - - Entity: 4010856451712828404 - Tag Component: - Tag: Actor 1 - TransformComponent: - Translation: [1.4940106e-08, -1.10000014, 0] - Rotation: [0, 0, 0.125663668] - Scale: [7.30000067, 0.5, 5.19999981] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Static - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 \ No newline at end of file diff --git a/atlas/objects_20.engine b/atlas/objects_20.engine deleted file mode 100644 index 705bf4d2..00000000 --- a/atlas/objects_20.engine +++ /dev/null @@ -1,381 +0,0 @@ -Scene: Untitled -Entities: - - Entity: 17198966059941728731 - Tag Component: - Tag: Actor 20 - TransformComponent: - Translation: [1.20000005, 8, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 6801278441136382236 - Tag Component: - Tag: Actor 19 - TransformComponent: - Translation: [-1.60000002, 6.5, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 5027702570458899016 - Tag Component: - Tag: Actor 18 - TransformComponent: - Translation: [3, 9.5, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 924190211859625645 - Tag Component: - Tag: Actor 17 - TransformComponent: - Translation: [1.39999998, 0.200000003, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 14096078862407024834 - Tag Component: - Tag: Actor 16 - TransformComponent: - Translation: [0, 0, 0] - Rotation: [0, 0, 0.600393295] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 4325675049849306465 - Tag Component: - Tag: Actor 15 - TransformComponent: - Translation: [0, 9.39999962, 0] - Rotation: [0, 0, 0.612610519] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 13455568828216614227 - Tag Component: - Tag: Actor 14 - TransformComponent: - Translation: [0.899999976, 6.69999981, 0] - Rotation: [0, 0, 0.565486729] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.284265667, 0.380295038, 0.828431368, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 7728243223071681250 - Tag Component: - Tag: Actor 13 - TransformComponent: - Translation: [-1.39999998, 8.39999962, 0] - Rotation: [0, 0, 0.35953784] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.862745106, 0.186082274, 0.604021192, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 17907352828054141178 - Tag Component: - Tag: Actor 12 - TransformComponent: - Translation: [0, 8.30000019, -1.39999998] - Rotation: [0, 0, 0.617846549] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.877451003, 0.768655181, 0.137639359, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 1 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 1 - TransformComponent: - Translation: [1.4940106e-08, -3.5999999, 0] - Rotation: [0, 0, 0.125663668] - Scale: [23.6000004, 2.0999999, 5.19999981] - SpriteRendererComponent: - Color: [1, 1, 1, 1] - RigidBody2DComponent: - BodyType: Static - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Camera - TransformComponent: - Translation: [0, 0, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - CameraComponent: - Camera: - ProjectionType: 1 - PerspectiveFOV: 0.785398185 - PerspectiveNear: 0.00999999978 - PerspectiveFar: 1000 - OrthographicSize: 10 - OrthographicNear: -1 - OrthographicFar: 1 - Primary: true - FixedAspectRatio: false - - Entity: 891104325792 - Tag Component: - Tag: Actor 2 - TransformComponent: - Translation: [-0.0891839564, 1.15999997, 0] - Rotation: [0, 0, 0.125115439] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.941176474, 0.226066872, 0.226066872, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 3 - TransformComponent: - Translation: [-0.600000024, 3.70000005, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.63233602, 0.41522494, 0.784313738, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 4 - TransformComponent: - Translation: [0.400000006, 2.79999995, 0] - Rotation: [0, 0.104719758, 0.778416812] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.344675094, 0.732204258, 0.799019575, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 5 - TransformComponent: - Translation: [-1.60000002, 2.5999999, 0] - Rotation: [0, 0, 0.706858337] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.42892158, 0.857843161, 0.529844284, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 6 - TransformComponent: - Translation: [0.300000012, 5.5, 0] - Rotation: [0, 0, 0.542797387] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.389081091, 0.528394043, 0.862745106, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 7 - TransformComponent: - Translation: [-2, 3.9000001, 0] - Rotation: [0, 0, 0.752236903] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.663481951, 0.159602046, 0.79411763, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 8 - TransformComponent: - Translation: [1.20000005, 4.5999999, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.769607842, 0.27539891, 0.27539891, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 9 - TransformComponent: - Translation: [-1.5, 5.0999999, 0] - Rotation: [0, 0, 0.588175952] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.123798534, 0.789215684, 0.123798534, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 - - Entity: 891104325792 - Tag Component: - Tag: Actor 10 - TransformComponent: - Translation: [-0.600000024, 6.4000001, 0] - Rotation: [0, 0, 0.466002911] - Scale: [1, 1, 1] - SpriteRendererComponent: - Color: [0.276053309, 0.759803891, 0.245818913, 1] - RigidBody2DComponent: - BodyType: Dynamic - FixedRotation: false - BoxCollider2DComponent: - Offset: [0, 0] - Size: [0.5, 0.5] - Density: 0.5 - Friction: 0.5 - Resitution: 0 - ResitutionThreshold: 0.5 \ No newline at end of file From c545a65e2ebe77d94fb5d2c307833710d33237de Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 05:17:36 -0800 Subject: [PATCH 07/42] Removed unused files --- editor/level_scene-new.cpp | 719 ------------------------------------- editor/level_scene-new.hpp | 77 ---- 2 files changed, 796 deletions(-) delete mode 100644 editor/level_scene-new.cpp delete mode 100644 editor/level_scene-new.hpp diff --git a/editor/level_scene-new.cpp b/editor/level_scene-new.cpp deleted file mode 100644 index 4e2681a8..00000000 --- a/editor/level_scene-new.cpp +++ /dev/null @@ -1,719 +0,0 @@ -#include "level_scene.hpp" -#include -#include -#include -#include - -level_scene::level_scene(const std::string& p_name, - atlas::event::event_bus& p_bus) - : atlas::scene_scope(p_name, p_bus) { - m_camera = create_object("Editor Camera"); - m_camera->add>(); - m_camera->set({ - .position = { 3.50f, 4.90f, 36.40f }, - .scale{ 1.f }, - }); - m_camera->set({ - .plane = { 0.1f, 5000.f }, - .is_active = true, - .field_of_view = 45.f, - }); - - m_object = create("Bob"); - - m_object2 = create2("Bob2"); - - m_viking_room = create_object("Viking Room"); - m_viking_room->add(); - m_viking_room->set({ - .position = { -2.70f, 2.70, -8.30f }, - .rotation = { 2.30f, 95.90f, 91.80f }, - .scale{ 1.f }, - }); - - m_viking_room->set({ - .radius = 1.0f, - }); - - m_viking_room->set({ - .friction = 15.f, - .restitution = 0.3f, - .body_movement_type = atlas::dynamic, - }); - - m_cube = create_object("Aircraft"); - - m_cube->set({ - .position = { 0.f, 2.10f, -7.30f }, - .scale = { 0.9f, 0.9f, 0.9f }, - }); - - m_cube->set({ - .color = { 1.f, 1.f, 1.f, 1.f }, - // .model_path = "assets/models/E 45 Aircraft_obj.obj", - .model_path = "assets/backpack/backpack.obj", - .diffuse = "assets/backpack/diffuse.jpg", - .specular = "assets/backpack/specular.jpg" - // .diffuse = "assets/models/E-45-steel detail_2_col.jpg", - }); - - // atlas::material_metadata data = { - // .ambient = {0.2f, 0.2f, 0.2f}, - // .diffuse = {0.5f, 0.5f, 0.5f}, - // .specular = {1.0f, 1.0f, 1.0f}, - // .shininess = 64.f, - // }; - // m_cube->set(data); - - m_robot_model = create_object("Cube"); - m_robot_model->add(); - // m_robot_model->add(); - m_robot_model->set({ - .position = { -2.70, 3.50f, 4.10f }, - .scale = { 1.f, 1.f, 1.f }, - }); - - m_robot_model->set( - { .color = { 1.f, 1.f, 1.f, 1.f }, - .model_path = "assets/models/cube.obj", - .diffuse = "assets/models/container_diffuse.png", - .specular = "assets/models/container_specular.png" }); - - m_robot_model->set({ - .half_extent = { 1.f, 1.f, 1.f }, - }); - m_robot_model->set({ - // .restitution = 1.f, - .body_movement_type = atlas::dynamic, - }); - - m_child_object = create_object("Child"); - m_child_object->child_of(m_robot_model); - - m_platform = create_object("Platform"); - - m_platform->set({ - .scale = { 15.f, 0.30f, 10.0f }, - }); - m_platform->set({ - .model_path = "assets/models/cube.obj", - .diffuse = "assets/models/wood.png", - }); - m_platform->set({ - .body_movement_type = atlas::fixed, - }); - m_platform->set({ - .half_extent = { 15.f, 0.30f, 10.0f }, - }); - - m_point_light = create_object("Point Light 1"); - m_point_light->set({ - .position = { 0.f, 2.10f, -7.30f }, - .scale = { 0.9f, 0.9f, 0.9f }, - }); - - m_point_light->set({ - .model_path = "assets/models/cube.obj", - .diffuse = "assets/models/wood.png", - }); - m_point_light->add(); - - // for(size_t i = 0; i < 26; i++) { - // auto obj = create_object(std::format("Object #{}", i)); - // obj->set({ - // .restitution = 1.25f, - // .body_movement_type = atlas::dynamic, - // }); - - // obj->set( - // { - // .radius = 1.0f, - // }); - - // glm::vec3 pos = {float(0*1.4),float(0 * 1.4),float(0 * -3) }; - - // obj->set({ - // .position = pos, - // .rotation = {.3f, 0.0f, 0.0f}, - // }); - - // obj->set({ - // .model_path = "assets/models/Ball OBJ.obj", - // .diffuse = "assets/models/clear.png", - // }); - // m_many_objects.emplace_back(obj); - // } - - // Just adding this here, for testing purposes - // Basic serialization for testing to conform how the editor may work - // TODO -- this would be done through either a stream_writer that can - // look at the structure of the graph and serialize according - // m_post_serializer_test = serializer(current_scene); - // m_post_serializer_test.save("LevelScene"); - m_deserializer_test = atlas::serializer(); - m_current_selected_file = "LevelScene"; - - subscribe(this, - &level_scene::collision_enter); - - atlas::register_start(this, &level_scene::start); - atlas::register_physics(this, &level_scene::physics_update); - atlas::register_update(this, &level_scene::on_update); - atlas::register_ui(this, &level_scene::on_ui_update); -} - -void -level_scene::collision_enter(atlas::event::collision_enter& p_event) { - console_log_warn("collision_enter event!!!"); - flecs::world registry = *this; - flecs::entity e1 = registry.entity(p_event.entity1); - flecs::entity e2 = registry.entity(p_event.entity2); - - console_log_warn("Entity1 = {}", e1.name().c_str()); - console_log_warn("Entity2 = {}", e2.name().c_str()); -} - -void -level_scene::collision_persisted(atlas::event::collision_persisted& p_event) { - console_log_warn("collision_persisted(p_event) invoked!!"); - flecs::world registry = *this; - flecs::entity e1 = registry.entity(p_event.entity1); - flecs::entity e2 = registry.entity(p_event.entity2); - - console_log_warn("Entity1 = {}", e1.name().c_str()); - console_log_warn("Entity2 = {}", e2.name().c_str()); -} - -void -level_scene::runtime_start() { - // runs the physics simulation - m_physics_is_runtime = true; - - m_physics_engine_handler.start(); -} - -void -level_scene::runtime_stop() { - m_physics_is_runtime = false; - - m_physics_engine_handler.stop(); - - reset_objects(); -} - -void -level_scene::reset_objects() { - - if (!m_deserializer_test.load("LevelScene", *this)) { - console_log_error("Could not load yaml file LevelScene!!!"); - } -} - -void -ui_component_list(flecs::entity& p_selected_entity) { - std::string entity_name = p_selected_entity.name().c_str(); - atlas::ui::draw_input_text(entity_name); - - ImGui::SameLine(); - ImGui::PushItemWidth(-1); - if (ImGui::Button("Add Component")) { - ImGui::OpenPopup("Add Component"); - } - - if (ImGui::BeginPopup("Add Component")) { - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Perspective Camera")) { - p_selected_entity.add< - flecs::pair>(); - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Mesh Source")) { - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Point Light")) { - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Serialize")) { - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Physics Body")) { - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Box Collider")) { - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Sphere Collider")) { - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - - if (!p_selected_entity.has()) { - if (ImGui::MenuItem("Capsule Collider")) { - p_selected_entity.add(); - ImGui::CloseCurrentPopup(); - } - } - ImGui::EndPopup(); - } - - ImGui::PopItemWidth(); -} - -void -level_scene::on_ui_update() { - - // setting up the dockspace UI widgets at the window toolbar - m_editor_dockspace.begin(); - - try { - m_editor_menu.begin(); - } - catch (const atlas::ui::menu_bar_exception& e) { - } - - // specify the label and the state to execute when this specific widget has - // been triggered - m_editor_menu.add_child("Exit", []() { - glfwSetWindowShouldClose(atlas::application::get_window(), true); - }); - m_editor_menu.end(); - - if (ImGui::Begin("Viewport")) { - glm::vec2 viewport_panel_size = - glm::vec2{ atlas::application::get_window().width(), - atlas::application::get_window().height() }; - - ImGui::End(); - } - - defer_begin(); - auto query_builder = this->query_builder().build(); - - if (ImGui::Begin("Scene Heirarchy")) { - // @note right click on blank space - // @param string_id - // @param popup_flags - will be the mouse flag (0=right, 1=left) - if (atlas::ui::begin_popup_context_window(nullptr, 1, false)) { - if (ImGui::MenuItem("Create Empty Entity")) { - // TODO -- Converting the operation to use strong_ptr to make - // these operation more conformed - m_create_entity = create_object("Empty Entity"); - } - ImGui::EndPopup(); - } - - query_builder.each([&](flecs::entity p_entity, atlas::transform&) { - // We set the imgui flags for our scene heirarchy panel - // TODO -- Make the scene heirarchy panel a separate class that is - // used for specify the layout and other UI elements here - ImGuiTreeNodeFlags flags = - ((m_selected_entity == p_entity) ? ImGuiTreeNodeFlags_Selected - : 0) | - ImGuiTreeNodeFlags_OpenOnArrow; - flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - flags |= ImGuiWindowFlags_Popup; - bool opened = ImGui::TreeNodeEx(p_entity.name().c_str(), flags); - if (ImGui::IsItemClicked()) { - m_selected_entity = p_entity; - // m_create_entity = search_entity(p_entity.name().c_str()); - } - - bool delete_entity = false; - if (ImGui::BeginPopupContextItem()) { - if (ImGui::MenuItem("Delete Entity")) { - delete_entity = true; - } - ImGui::EndPopup(); - } - - if (delete_entity) { - // _context->destroyEntity(entity); - m_selected_entity.destruct(); - } - - if (opened) { - flags = ImGuiTreeNodeFlags_OpenOnArrow | - ImGuiTreeNodeFlags_SpanAvailWidth; - auto query_children_builder = - this->query_builder().with(flecs::ChildOf, p_entity).build(); - int32_t child_count = query_children_builder.count(); - - // // Only show children in scene heirarchy panel if there are - // children entities - if (child_count > 0) { - m_selected_entity.children([&](flecs::entity p_child) { - opened = - ImGui::TreeNodeEx(p_child.name().c_str(), flags); - if (opened) { - if (ImGui::IsItemClicked()) { - m_selected_entity = p_child; - } - ImGui::TreePop(); - } - }); - } - - ImGui::TreePop(); - } - }); - - defer_end(); - ImGui::End(); - } - - if (ImGui::Begin("Properties")) { - if (m_selected_entity.is_alive()) { - ui_component_list(m_selected_entity); - - atlas::ui::draw_component( - "transform", - m_selected_entity, - [](atlas::transform* p_transform) { - atlas::ui::draw_vec3("Position", p_transform->position); - atlas::ui::draw_vec3("Scale", p_transform->scale); - atlas::ui::draw_vec3("Rotation", p_transform->rotation); - }); - - atlas::ui::draw_component( - "camera", - m_selected_entity, - [this](atlas::perspective_camera* p_camera) { - atlas::ui::draw_float("field of view", - p_camera->field_of_view); - ImGui::Checkbox("is_active", &p_camera->is_active); - ImGui::DragFloat("Speed", &m_movement_speed); - }); - - /* - atlas::ui::draw_component("Directional - Light", m_selected_entity, [](atlas::directional_light* - p_dir_light){ ImGui::DragFloat4("Direction", - glm::value_ptr(p_dir_light->direction)); ImGui::DragFloat4("View - Pos", glm::value_ptr(p_dir_light->view_position)); - ImGui::DragFloat4("Color", glm::value_ptr(p_dir_light->color)); - ImGui::DragFloat4("Ambient", - glm::value_ptr(p_dir_light->ambient)); ImGui::DragFloat4("Diffuse", - glm::value_ptr(p_dir_light->diffuse)); ImGui::DragFloat4("Specular", - glm::value_ptr(p_dir_light->specular)); - }); - */ - - atlas::ui::draw_component( - "Point Light", - m_selected_entity, - [](atlas::point_light* p_dir_light) { - ImGui::DragFloat4( - "Color", glm::value_ptr(p_dir_light->color), 0.01); - ImGui::DragFloat( - "Attenuation", &p_dir_light->attenuation, 0.001); - ImGui::DragFloat4( - "Ambient", glm::value_ptr(p_dir_light->ambient), 0.01); - ImGui::DragFloat4( - "Diffuse", glm::value_ptr(p_dir_light->diffuse), 0.01); - ImGui::DragFloat4( - "Specular", glm::value_ptr(p_dir_light->specular), 0.01); - ImGui::DragFloat("Constant", &p_dir_light->constant, 0.01); - ImGui::DragFloat("Linear", &p_dir_light->linear, 0.01); - ImGui::DragFloat("Quadratic", &p_dir_light->quadratic, 0.01); - }); - - atlas::ui::draw_component( - "atlas::mesh_source", - m_selected_entity, - [](atlas::mesh_source* p_source) { - atlas::ui::draw_input_text(p_source->model_path); - atlas::ui::draw_vec4("Color", p_source->color); - }); - - atlas::ui::draw_component( - "material", - m_selected_entity, - [](atlas::material_metadata* p_source) { - float speed = 0.01f; - ImGui::DragFloat4( - "Ambient", glm::value_ptr(p_source->ambient), speed); - ImGui::DragFloat4( - "Diffuse", glm::value_ptr(p_source->diffuse), speed); - ImGui::DragFloat4( - "Specular", glm::value_ptr(p_source->specular), speed); - atlas::ui::draw_float("Shininess", p_source->shininess); - }); - - atlas::ui::draw_component( - "Physics Body", - m_selected_entity, - [](atlas::physics_body* p_body) { - std::array items = { - "Static", - "Kinematic", - "Dynamic", - }; - std::string combo_preview = items[p_body->body_movement_type]; - - // Begin the combo box - if (ImGui::BeginCombo("Body Type", combo_preview.data())) { - for (int n = 0; n < 3; n++) { - // Check if the current item is selected - const bool is_selected = - (p_body->body_movement_type == n); - if (ImGui::Selectable(items[n].data(), is_selected)) { - // Update the current type when a new item is - // selected - p_body->body_movement_type = - static_cast(n); - } - - // Set the initial focus when the combo box is first - // opened - if (is_selected) { - ImGui::SetItemDefaultFocus(); - } - } - ImGui::EndCombo(); - } - - // physics body parameters - atlas::ui::draw_vec3("Linear Velocity", - p_body->linear_velocity); - atlas::ui::draw_vec3("Angular Velocity", - p_body->angular_velocity); - atlas::ui::draw_vec3("Force", p_body->force); - atlas::ui::draw_vec3("Impulse", p_body->impulse); - atlas::ui::draw_vec3("Torque", p_body->torque); - atlas::ui::draw_vec3("Center Mass", - p_body->center_mass_position); - }); - - atlas::ui::draw_component( - "Box Collider", - m_selected_entity, - [](atlas::box_collider* p_collider) { - atlas::ui::draw_vec3("Half Extent", p_collider->half_extent); - }); - - atlas::ui::draw_component( - "Box Collider", - m_selected_entity, - [](atlas::sphere_collider* p_collider) { - atlas::ui::draw_float("Radius", p_collider->radius); - }); - - atlas::ui::draw_component( - "Box Collider", - m_selected_entity, - [](atlas::capsule_collider* p_collider) { - atlas::ui::draw_float("Half Height", p_collider->half_height); - atlas::ui::draw_float("Radius", p_collider->radius); - }); - - atlas::ui::draw_component( - "Serialize", - m_selected_entity, - [](atlas::tag::serialize* p_serialize) { - ImGui::Checkbox("Enable", &p_serialize->enable); - }); - } - - ImGui::End(); - - // Note --- just added this temporarily for testing - // auto time = atlas::application::delta_time(); - - // if((int)(time * 10.0f) % 8 > 4) { - // m_blink = !m_blink; - // } - - // auto width = atlas::application::get_window().width(); - // auto height = atlas::application::get_window().height(); - - // ImGui::SetNextWindowPos(ImVec2(static_cast(width) * 0.5f, - // static_cast(height) * 0.5f), ImGuiCond_Always, ImVec2(0.5f, - // 0.5f)); ImGui::SetNextWindowSize(ImVec2(200, 20), ImGuiCond_Always); - // ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | - // ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs; - // ImGui::SetNextWindowBgAlpha(0.f); - - // if(ImGui::Begin("Testing", nullptr, flags)) { - // ImGui::ProgressBar(10.f); - - // auto pos = ImGui::GetWindowPos(); - // pos.x += (float)width * 0.5f - 300.0f; - // pos.y += 50.0f; - // if(m_blink){ - // ImGui::GetForegroundDrawList()->AddText(m_font, 120.0f, - // pos, 0xffffffff, "Click to Play!"); - // } - - // ImGui::End(); - // } - } - - m_editor_dockspace.end(); -} - -void -level_scene::start() { - m_deserializer_test = atlas::serializer(); - - if (!m_deserializer_test.load("LevelScene", *this)) { - console_log_error("Could not load yaml file LevelScene!!!"); - } - - // testing the flip parameter inside atlas::mesh_source - m_viking_room->set({ - .flip = true, - .color = { 1.f, 1.f, 1.f, 1.f }, - .model_path = "assets/models/viking_room.obj", - .diffuse = "assets/models/viking_room.png", - // .model_path = "assets/models/Ball OBJ.obj", - // .diffuse = "assets/models/clear.png", - }); - - // TODO: Make this contain an atlas::directional_light - // If the scene opject dooes not have a atlas::directional_light, then we - // set the default values to 1.0f m_robot_model sets the cube.obj 3d model - // and loads it - m_robot_model->set({ - .shininess = 64.f, - }); - - // Initiating physics system - atlas::physics::jolt_settings settings = {}; - flecs::world registry = *this; - m_physics_engine_handler = - atlas::physics::physics_engine(settings, registry, *event_handle()); - - // Note -- just added for temporary - // ImGuiIO io = ImGui::GetIO(); - // m_font = io.Fonts->AddFontFromFileTTF("assets/OpenSans-Regular.ttf", - // 120.0f); -} - -void -level_scene::on_update() { - - auto query_cameras = - query_builder().build(); - - query_cameras.each([this](atlas::perspective_camera& p_camera, - atlas::transform& p_transform) { - if (!p_camera.is_active) { - return; - } - - float dt = atlas::application::delta_time(); - float default_speed = 10.f; // current default movement speed that does - // not applied modified speed - float rotation_speed = 1.f; - float velocity = default_speed * dt; - if (atlas::event::is_mouse_pressed(mouse_button_middle)) { - velocity = m_movement_speed * dt; - } - float rotation_velocity = rotation_speed * dt; - - glm::quat to_quaternion = atlas::to_quat(p_transform.quaternion); - - glm::vec3 up = glm::rotate(to_quaternion, atlas::math::up()); - glm::vec3 forward = glm::rotate(to_quaternion, atlas::math::backward()); - glm::vec3 right = glm::rotate(to_quaternion, atlas::math::right()); - - if (atlas::event::is_key_pressed(key_left_shift)) { - p_transform.position += up * velocity; - } - - if (atlas::event::is_key_pressed(key_space)) { - p_transform.position -= up * velocity; - } - - if (atlas::event::is_key_pressed(key_w)) { - p_transform.position += forward * velocity; - } - if (atlas::event::is_key_pressed(key_s)) { - p_transform.position -= forward * velocity; - } - - if (atlas::event::is_key_pressed(key_d)) { - p_transform.position += right * velocity; - } - if (atlas::event::is_key_pressed(key_a)) { - p_transform.position -= right * velocity; - } - - if (atlas::event::is_key_pressed(key_q)) { - p_transform.rotation.y += rotation_velocity; - } - if (atlas::event::is_key_pressed(key_e)) { - p_transform.rotation.y -= rotation_velocity; - } - - p_transform.set_rotation(p_transform.rotation); - }); -} - -void -level_scene::physics_update() { - float dt = atlas::application::delta_time(); - if (atlas::event::is_key_pressed(key_r) and !m_physics_is_runtime) { - runtime_start(); - } - - atlas::physics_body* sphere_body = - m_viking_room->get_mut(); - // U = +up - // J = -up - // H = +left - // L = -Left - if (atlas::event::is_key_pressed(key_space)) { - glm::vec3 linear_velocity = { 0.f, 10.0f, 0.f }; - sphere_body->linear_velocity = linear_velocity; - sphere_body->impulse = linear_velocity; - } - - if (atlas::event::is_key_pressed(key_j)) { - glm::vec3 angular_vel = { -10.f, 0.f, 0.f }; - sphere_body->angular_velocity = angular_vel; - } - - if (atlas::event::is_key_pressed(key_h)) { - glm::vec3 angular_vel = { 10.f, 0.f, 0.f }; - sphere_body->angular_velocity = angular_vel; - } - - if (atlas::event::is_key_pressed(key_l)) { - glm::vec3 angular_vel = { -0.1f, 0.f, 0.f }; - sphere_body->angular_velocity = angular_vel; - } - - if (m_physics_is_runtime) { - m_physics_engine_handler.update(dt); - } - - if (atlas::event::is_key_pressed(key_l) and m_physics_is_runtime) { - runtime_stop(); - } -} diff --git a/editor/level_scene-new.hpp b/editor/level_scene-new.hpp deleted file mode 100644 index 344e1a0e..00000000 --- a/editor/level_scene-new.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * @brief Implementation of a custom scene - * - * Represent a scene with an associated game objects that correspond to this - * game object. - * - */ - -class level_scene final : public atlas::scene_scope { -public: - level_scene(const std::string& p_tag, atlas::event::event_bus& p_bus); - - ~level_scene() override = default; - - void start(); - - void on_update(); - - void on_ui_update(); - - void physics_update(); - - void runtime_start(); - - void runtime_stop(); - - void reset_objects(); - - void collision_enter(atlas::event::collision_enter& p_event); - - void collision_persisted(atlas::event::collision_persisted& p_event); - -private: - bool m_blink = false; - atlas::serializer m_deserializer_test; - flecs::entity m_selected_entity; - // TEMP: this is only for when creating an entity in the editor-space - atlas::optional_ref m_create_entity; - atlas::optional_ref m_child_object; - atlas::optional_ref m_viking_room; - atlas::optional_ref m_cube; - atlas::optional_ref m_robot_model; - atlas::optional_ref m_platform; - std::pmr::polymorphic_allocator<> m_allocator; - atlas::optional_ref m_camera; - atlas::optional_ref m_point_light; - atlas::scene_object_view m_object; - flecs::atlas_entity m_object2; - float m_movement_speed = 10.f; - // std::vector> m_many_objects; - - // Setting physics system - // TODO -- when refactoring this would be at atlas::world layer - atlas::physics::physics_engine m_physics_engine_handler; - - bool m_physics_is_runtime = false; - - atlas::ui::dockspace m_editor_dockspace; - atlas::ui::menu_item m_editor_menu; - - // Note -- Added this temporarily - // ImFont* m_font; - - std::filesystem::path m_current_selected_file; -}; From 883e3458e1fadf8789905fe967edbce218a39ac2 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 05:35:55 -0800 Subject: [PATCH 08/42] Added exception header and updated scene object's documentation comments --- atlas/core/scene/exceptions.hpp | 17 ++++++ atlas/core/scene/scene_object.hpp | 95 +++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 atlas/core/scene/exceptions.hpp diff --git a/atlas/core/scene/exceptions.hpp b/atlas/core/scene/exceptions.hpp new file mode 100644 index 00000000..f8aa47a0 --- /dev/null +++ b/atlas/core/scene/exceptions.hpp @@ -0,0 +1,17 @@ +#pragma once + +namespace atlas { + struct exception_block { + const char* data=nullptr; + }; + + class object_accessor_exception { + public: + object_accessor_exception(const char* p_data) : m_data(p_data) {} + + [[nodiscard]] const char* what() const { return m_data.data; } + + private: + exception_block m_data; + }; +}; \ No newline at end of file diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index 504e4bfe..f1a973c1 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -1,50 +1,106 @@ #pragma once - #include #include #include namespace atlas { + + /** + * @brief Creates a game object that extends the flecs::entity + * + * Provides our own construct of API's that handles any workload around some + * of the raw flecs API's that can still be used by other flecs API's + * without completely interacting touching raw flecs API + */ class scene_object : public flecs::entity { public: scene_object() = default; + scene_object(flecs::world_t* p_registry, flecs::entity_t p_id); scene_object(const flecs::entity& p_base); explicit scene_object(flecs::entity& p_base); - void child_of(const scene_object& p_entity); - /** * @brief Adds multiple components with no values assigned to them - * EXPERIEMENTAL: Function to add multiple components but still in its - * experiemental stages. * * Ideally this would be a shorthand for adding in multiple components * onto a single given entity * * Example: + * + * * ```C++ - * m_entity_example->add_query(); + * + * atlas::scene_object entity_example = create("New Entity"); + * + * // adds both transform and rigidbody to "entity_example" + * entity_example->add(); + * * ``` */ template - void add_query() { + void add() { using tuple_variadic = std::tuple; std::variant conditions; std::visit( [&](const auto& p_component) { std::apply( [&](auto&... p_placeholder) { - (add>(), - ...); + (add>(), ...); }, p_component); }, conditions); } + /** + * @brief sets the entity to be a parent of the specified entity + * + * @param p_entity is the specified entity to specify as the parent. + * + * + * Example Usage: + * + * ```C++ + * + * atlas::scene_object obj1 = create("Parent"); + * + * atlas::scene_object obj2 = create("Chlid"); + * + * // obj2 is the child of obj1 + * // As obj1 is a parent node + * obj2.child_of(obj1); + * + * ``` + * + */ + void child_of(const scene_object& p_parent); + + /** + * @brief iterates through all children entities if the given entity is + * a parent of any given entities + * + * + * Example Usage: + * + * ```C++ + * + * atlas::scene_object obj1 = create("Parent Node"); + * atlas::scene_object obj2 = create("Chlid Node"); + * + * // obj1 is the parent of obj2. + * obj2.child_of(parent); + * + * // iteration should only include for "Child Node" + * obj1.children([](flecs::entity p_child){ + * // do stuff with the child entity + * }); + * + * ``` + * + */ template void children(UFunction&& p_callback) { children(p_callback); @@ -53,25 +109,4 @@ namespace atlas { flecs::entity* operator->(); }; - // class scene_object_exp { - // public: - // scene_object_exp() = default; - // scene_object_exp(custom_entity& p_entity) : m_entity(&p_entity) {} - - - // custom_entity* operator->() const& { - // if(m_entity == nullptr) { - // throw std::runtime_error("Invalid access to game object!!"); - // } - - // return m_entity; - // } - - // operator custom_entity*() { - // return m_entity; - // } - - // private: - // custom_entity* m_entity; - // }; }; \ No newline at end of file From dcac3c3eaa3c19211bb67b8982919af8ac53bb1d Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 30 Nov 2025 05:44:45 -0800 Subject: [PATCH 09/42] Added documentation comments to atlas::scene --- atlas/core/scene/scene.hpp | 41 +++++++++++++++++++++++++++------- src/atlas/core/scene/scene.cpp | 11 +++++++-- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index 67469a76..65923f5a 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -35,7 +35,7 @@ namespace atlas { /** * @brief create a new entity (game object) - */ + */ scene_object create(const std::string& p_name); /** @@ -86,11 +86,38 @@ namespace atlas { std::forward(args)...); } + /** + * @return the number of children entities + * + * Example Usage: + * + * + * ```C++ + * + * atlas::scene scene("New Scene"); + * + * // creating obj1 (parent) and obj2 (child) + * atlas::scene_object obj1 = scene.create("Parent"); + * + * atlas::scene_object obj2 = scene.create("Chlid"); + * + * // obj2 is the child of obj1 + * // As obj1 is a parent node + * + * obj2.child_of(obj1); + * + * // Returns 1 + * uint32_t obj1_children = scene.children_count(obj1); + * + * ``` + */ + uint32_t children_count(scene_object p_parent); + /** * @brief Defer operations until end of frame. - * When this operation is invoked while iterating, operations inbetween - * the defer_begin() and defer_end() operations are executed at the end - * of the frame. + * When this operation is invoked while iterating, operations + * inbetween the defer_begin() and defer_end() operations are executed + * at the end of the frame. * * This operation is thread safe. * @@ -110,11 +137,10 @@ namespace atlas { */ bool defer_end() { return m_registry.defer_end(); } - //! @return the name of atlas::scene_object + //! @return the name of the scene [[nodiscard]] std::string name() const { return m_name; } - //! @return the event::bus handle to do the subscription operation of - //! events + //! @return the event::bus handle for subscribing events [[nodiscard]] event::event_bus* event_handle() const { return m_bus; } /** @@ -124,7 +150,6 @@ namespace atlas { operator world&() { return m_registry; } private: - // std::pmr::polymorphic_allocator<> m_allocator; world m_registry; std::string m_name; event::event_bus* m_bus = nullptr; diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index 3cd81277..c84ebe2f 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -1,9 +1,12 @@ #include namespace atlas { - scene::scene(const std::string& p_name, event::event_bus& p_bus) : m_name(p_name), m_bus(&p_bus) {} + scene::scene(const std::string& p_name, event::event_bus& p_bus) + : m_name(p_name) + , m_bus(&p_bus) {} - // strong_ref scene::create_object(const std::string& p_name) { + // strong_ref scene::create_object(const std::string& p_name) + // { // return create_strong_ref( // m_allocator, &m_registry, p_name); // } @@ -17,4 +20,8 @@ namespace atlas { return scene_object(m_registry.entity(p_name.c_str())); } + uint32_t scene::children_count(scene_object p_parent) { + return query_builder().with(flecs::ChildOf, p_parent).build().count(); + } + }; \ No newline at end of file From c6f989eb3ee8f5a7ed116b96ef998521cf2a12f2 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 2 Dec 2025 10:41:00 -0800 Subject: [PATCH 10/42] Removed unused API that was was causing a stack overflow error --- atlas/core/scene/scene_object.hpp | 33 ------------------------------- 1 file changed, 33 deletions(-) diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index f1a973c1..61558961 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -22,39 +22,6 @@ namespace atlas { explicit scene_object(flecs::entity& p_base); - /** - * @brief Adds multiple components with no values assigned to them - * - * Ideally this would be a shorthand for adding in multiple components - * onto a single given entity - * - * Example: - * - * - * ```C++ - * - * atlas::scene_object entity_example = create("New Entity"); - * - * // adds both transform and rigidbody to "entity_example" - * entity_example->add(); - * - * ``` - */ - template - void add() { - using tuple_variadic = std::tuple; - std::variant conditions; - std::visit( - [&](const auto& p_component) { - std::apply( - [&](auto&... p_placeholder) { - (add>(), ...); - }, - p_component); - }, - conditions); - } - /** * @brief sets the entity to be a parent of the specified entity * From f8105b92c80078e4ea1c78c4d83360b905f5c57c Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 2 Dec 2025 11:26:09 -0800 Subject: [PATCH 11/42] Added a fix for modifying entity names through the UI editor to match correctly --- atlas/core/ui/widgets.hpp | 8 +++-- src/atlas/core/ui/widgets.cpp | 68 ++++++++++------------------------- 2 files changed, 23 insertions(+), 53 deletions(-) diff --git a/atlas/core/ui/widgets.hpp b/atlas/core/ui/widgets.hpp index 066bb23e..3c5d4d2b 100644 --- a/atlas/core/ui/widgets.hpp +++ b/atlas/core/ui/widgets.hpp @@ -64,11 +64,13 @@ namespace atlas::ui { float p_reset_value = 0.f); /** - * @brief For UI rendering text as input + * @brief UI rendering input text + * * - * @param p_value is specified string for drawing input text to imgui's + * @param p_dst is the destination string to be changed + * @param p_src is the original string that was previously given */ - void draw_input_text(std::string& p_value); + void draw_input_text(std::string& p_dst, std::string& p_src); /** * @brief For UI rendering text to display and not input diff --git a/src/atlas/core/ui/widgets.cpp b/src/atlas/core/ui/widgets.cpp index d495bfa1..2fa9e0ba 100644 --- a/src/atlas/core/ui/widgets.cpp +++ b/src/atlas/core/ui/widgets.cpp @@ -2,6 +2,8 @@ #include // Used to include "PushMultiItemsWidths" namespace atlas::ui { + using ::ImGui::InputText; + bool begin_popup_context_window(const char* str_id, ImGuiMouseButton mb, bool over_items) { @@ -220,59 +222,25 @@ namespace atlas::ui { ImGui::PopID(); } - void draw_input_text(std::string&) { - // 1. Define the buffer constraints - // This size is critical: it defines the maximum length ImGui will allow. - /* - constexpr size_t max_string_length = 255; - - // 2. Get the current entity name - // std::string current_name = p_selected_entity.name(); - - // 3. Create a temporary, mutable std::string for ImGui's buffer - // This string must be pre-sized to hold the entity name AND the extra space - // ImGui will use for new input, plus the null terminator. - std::string input_buffer = p_value; - - // Pad the string with null terminators to guarantee the maximum size for ImGui. - // This is the cleanest way to create a fixed-size 'char*' buffer using only std::string. - // We add one extra for safety, but ImGui will respect max_string_length. - input_buffer.resize(max_string_length + 1, '\0'); - - // 4. Use ImGui::InputText - // We pass the raw mutable pointer to the start of the string's buffer. - // .data() returns a non-const char* for non-const std::string in C++17+. + void draw_input_text(std::string& p_dst, std::string& p_src) { + std::string input_buffer = p_src; + ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue; - - if (ImGui::InputText( - "##Name", - input_buffer.data(), // Crucial: Mutable char* access - max_string_length + 1, // Crucial: The fixed buffer size - flags) - ) { - // 5. Trim the std::string to the actual user input - // The buffer contains the new name followed by a null-terminator. - // We find the null-terminator and resize the string to that point. - // C++23: std::string::resize_and_overwrite could be used here, but - // a standard find and resize is clearer for this context. - - // Find the first null character, which marks the end of the user's input - size_t new_len = input_buffer.find('\0'); - - if (new_len != std::string::npos) { - input_buffer.resize(new_len); // Resize to the actual name length - } - else { - // Should not happen if ImGui works correctly, but safe guard against non-terminated string - input_buffer.resize(max_string_length); - } + input_buffer.resize(255); // resize to allocate for 255 in the char array since this should be long enough + + if(ImGui::InputText("##Name", (char*)input_buffer.c_str(), input_buffer.size() + 1, flags)) { + p_dst = input_buffer; + } + + if(p_dst.empty()) { + p_dst = p_src; + return; + } - // 6. Commit the change to the flecs entity's name - // Use the newly resized and managed std::string. - // UNCOMMENT THIS TO GET DIS TO WORK! - // p_selected_entity.set_name(input_buffer.c_str()); + if(p_dst == p_src) { + p_dst = p_src; + return; } - */ } void draw_text(const std::string& p_value) { From a86759de0bd362abf3b0e368f0bb3d5acad2b374 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 2 Dec 2025 11:26:50 -0800 Subject: [PATCH 12/42] Added view of the entity ID's to the editor scene heirarchy panel --- editor/level_scene.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 364db009..a9db6e35 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -3,6 +3,7 @@ #include #include #include +#include level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) @@ -194,7 +195,10 @@ level_scene::reset_objects() { void ui_component_list(flecs::entity& p_selected_entity) { std::string entity_name = p_selected_entity.name().c_str(); - atlas::ui::draw_input_text(entity_name); + std::string new_entity_name = ""; + atlas::ui::draw_input_text(new_entity_name, entity_name); + + p_selected_entity.set_name(new_entity_name.c_str()); ImGui::SameLine(); ImGui::PushItemWidth(-1); @@ -302,9 +306,6 @@ level_scene::on_ui_update() { // @param popup_flags - will be the mouse flag (0=right, 1=left) if (atlas::ui::begin_popup_context_window(nullptr, 1, false)) { if (ImGui::MenuItem("Create Empty Entity")) { - // TODO -- Converting the operation to use strong_ptr to make - // these operation more conformed - // m_create_entity = create("Empty Entity"); m_current_entity = create("Empty Entity"); } ImGui::EndPopup(); @@ -320,10 +321,13 @@ level_scene::on_ui_update() { ImGuiTreeNodeFlags_OpenOnArrow; flags |= ImGuiTreeNodeFlags_SpanAvailWidth; flags |= ImGuiWindowFlags_Popup; + flags |= ImGuiTreeNodeFlags_AllowItemOverlap; + + // std::string fmt = std::format("{} ({})", p_entity.name().c_str(), p_entity.id()); bool opened = ImGui::TreeNodeEx(p_entity.name().c_str(), flags); + if (ImGui::IsItemClicked()) { m_selected_entity = p_entity; - // m_create_entity = search_entity(p_entity.name().c_str()); } bool delete_entity = false; @@ -339,6 +343,9 @@ level_scene::on_ui_update() { m_selected_entity.destruct(); } + ImGui::SameLine(); + ImGui::TextDisabled("(%llu)", p_entity.id()); + if (opened) { flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth; @@ -429,7 +436,7 @@ level_scene::on_ui_update() { "atlas::mesh_source", m_selected_entity, [](atlas::mesh_source* p_source) { - atlas::ui::draw_input_text(p_source->model_path); + // atlas::ui::draw_input_text(p_source->model_path, p_source->model_path); atlas::ui::draw_vec4("Color", p_source->color); }); From b7d3ce3de22039956959a2846c344126119437f0 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 2 Dec 2025 21:56:41 -0800 Subject: [PATCH 13/42] Created custom exception and ensures atlas::scene_object throws when an invalid access occurs --- atlas/core/scene/exceptions.hpp | 11 +++++++---- atlas/core/scene/scene_object.hpp | 18 +++++++++++++++--- src/atlas/core/scene/scene_object.cpp | 18 +++++++++--------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/atlas/core/scene/exceptions.hpp b/atlas/core/scene/exceptions.hpp index f8aa47a0..b48b0f48 100644 --- a/atlas/core/scene/exceptions.hpp +++ b/atlas/core/scene/exceptions.hpp @@ -1,17 +1,20 @@ #pragma once +#include namespace atlas { struct exception_block { const char* data=nullptr; }; - class object_accessor_exception { + class invalid_access_exception : public std::exception { public: - object_accessor_exception(const char* p_data) : m_data(p_data) {} + invalid_access_exception() = default; + invalid_access_exception(const char* p_data) : m_block(p_data) {} - [[nodiscard]] const char* what() const { return m_data.data; } + //! @return message given when this exception gets triggered + [[nodiscard]] const char* what() const override { return m_block.data; } private: - exception_block m_data; + exception_block m_block; }; }; \ No newline at end of file diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index 61558961..183a2ce7 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -1,12 +1,13 @@ #pragma once #include -#include -#include namespace atlas { /** - * @brief Creates a game object that extends the flecs::entity + * @brief Creates a pointer wrapper which extends capabilities of + * flecs::entity + * + * Wrapper that provides * * Provides our own construct of API's that handles any workload around some * of the raw flecs API's that can still be used by other flecs API's @@ -73,6 +74,17 @@ namespace atlas { children(p_callback); } + /** + * @brief Since we do not have a way to ensure that the access point to + * this object is invalid, we use the -> operator to ensure the object + * is valid. + * + * Including cannot overload the `.` operator, to ensure object if it is valid. + * + * The `->` operator will throw std::runtime_error exception if object's + * invalid or return the object + * + */ flecs::entity* operator->(); }; diff --git a/src/atlas/core/scene/scene_object.cpp b/src/atlas/core/scene/scene_object.cpp index 6d1dd10b..976ceea5 100644 --- a/src/atlas/core/scene/scene_object.cpp +++ b/src/atlas/core/scene/scene_object.cpp @@ -1,23 +1,21 @@ +#include #include #include #include -#include namespace atlas { - scene_object::scene_object( - flecs::world_t* p_registry, - flecs::entity_t p_id) + scene_object::scene_object(flecs::world_t* p_registry, flecs::entity_t p_id) : flecs::entity(p_registry, p_id) { add(); } - scene_object::scene_object( - const flecs::entity& p_base) + scene_object::scene_object(const flecs::entity& p_base) : flecs::entity(p_base) { add(); } - scene_object::scene_object(flecs::entity& p_base) : flecs::entity(p_base) { + scene_object::scene_object(flecs::entity& p_base) + : flecs::entity(p_base) { add(); } @@ -29,8 +27,10 @@ namespace atlas { // We want to check if this game object is accessible or else throw an // exception if invalid or nullptr flecs::entity* e = this; - if (e == nullptr) { - throw std::runtime_error( + + // We only want to access this entity if it is alive and valid! + if (!e->is_valid() and !e->is_alive()) { + throw invalid_access_exception( "Invalid access to an invalid pointer to game object"); } From 00e57b477b339cf5f223d231e1e794e520219d96 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 2 Dec 2025 21:57:49 -0800 Subject: [PATCH 14/42] Code cleanup and added a few minor changes to editor/level_scene.cpp --- editor/level_scene.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index 2f031b4f..1a58da90 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -54,7 +54,6 @@ class level_scene final : public atlas::scene { std::pmr::polymorphic_allocator<> m_allocator; atlas::scene_object m_camera; atlas::scene_object m_point_light; - // atlas::scene_object m_bob_object; atlas::scene_object m_bob_object; atlas::scene_object m_current_entity; float m_movement_speed = 10.f; From d49f38a9de769d061adeca47f2e5569fc8b2801d Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 2 Dec 2025 22:19:25 -0800 Subject: [PATCH 15/42] Renamed API for creating and fetching entities with an entity(const string&) API instead of calling it create(const string&) --- atlas/core/scene/scene.hpp | 10 ++++++---- atlas/core/scene/types.hpp | 10 ---------- src/atlas/core/scene/scene.cpp | 13 +------------ 3 files changed, 7 insertions(+), 26 deletions(-) delete mode 100644 atlas/core/scene/types.hpp diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index 65923f5a..3fde1f1e 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include #include @@ -35,8 +34,11 @@ namespace atlas { /** * @brief create a new entity (game object) + * + * Will create an entity (game object) or retrieve existing entity if + * the name for that entity exists within the ecs registry. */ - scene_object create(const std::string& p_name); + scene_object entity(const std::string& p_name); /** * @brief subscribes an event to the event::bus to get invoked when @@ -147,10 +149,10 @@ namespace atlas { * @brief Requires to return flecs::world is returned by reference to * prevent making copies of flecs::world */ - operator world&() { return m_registry; } + operator flecs::world&() { return m_registry; } private: - world m_registry; + flecs::world m_registry; std::string m_name; event::event_bus* m_bus = nullptr; }; diff --git a/atlas/core/scene/types.hpp b/atlas/core/scene/types.hpp deleted file mode 100644 index fb0e7b6f..00000000 --- a/atlas/core/scene/types.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include - -namespace atlas { - // Alias to flecs::entity - using entity_t = flecs::entity; - - // Alias to flecs::world - using world = flecs::world; -}; \ No newline at end of file diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index c84ebe2f..549ae673 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -5,18 +5,7 @@ namespace atlas { : m_name(p_name) , m_bus(&p_bus) {} - // strong_ref scene::create_object(const std::string& p_name) - // { - // return create_strong_ref( - // m_allocator, &m_registry, p_name); - // } - - // custom_entity scene::create(const std::string& p_name) { - // flecs::entity e = m_registry.entity(p_name.c_str()); - // return custom_entity(e); - // } - - scene_object scene::create(const std::string& p_name) { + scene_object scene::entity(const std::string& p_name) { return scene_object(m_registry.entity(p_name.c_str())); } From 96d9579eb7fdb0737e83260cdac7ae25ea801768 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 2 Dec 2025 22:20:45 -0800 Subject: [PATCH 16/42] Renamed atlas::world_scope to atlas::world for simplicity and did some variable name changes in level_scene.cpp --- atlas/core/scene/world.hpp | 16 ++++----- atlas/core/system/registry.hpp | 20 ++++++------ editor/editor_world.hpp | 4 +-- editor/level_scene.cpp | 34 ++++++++++---------- editor/level_scene.hpp | 6 ++-- src/atlas/core/application.cpp | 2 +- src/atlas/core/scene/world.cpp | 6 ++-- src/atlas/core/system/registry.cpp | 16 ++++----- src/atlas/drivers/vulkan-cpp/vk_renderer.cpp | 4 +-- 9 files changed, 51 insertions(+), 57 deletions(-) diff --git a/atlas/core/scene/world.hpp b/atlas/core/scene/world.hpp index 1bed730c..66c8cfc3 100644 --- a/atlas/core/scene/world.hpp +++ b/atlas/core/scene/world.hpp @@ -24,19 +24,19 @@ namespace atlas { * * */ - class world_scope { + class world { public: - world_scope() = delete; + world() = delete; /** - * @brief construct a new world_scope with a specified name associated + * @brief construct a new world with a specified name associated * with it */ - world_scope(const std::string& p_name); + world(const std::string& p_name); - virtual ~world_scope() = default; + virtual ~world() = default; - //! @return the name of world_scope + //! @return the name of world [[nodiscard]] std::string name() const { return m_name; } /** @@ -69,14 +69,14 @@ namespace atlas { if (!m_scene_container.contains(p_tag)) { throw std::runtime_error( "Could not access ref from " - "world_scope::get_scene(const string& p_tag)!!!"); + "world::get_scene(const string& p_tag)!!!"); } return m_scene_container[p_tag]; } private: std::map> m_scene_container; - ref m_world_shared_instance; + ref m_world_shared_instance; std::string m_name = "Undefined Tag"; }; }; // namespace atlas \ No newline at end of file diff --git a/atlas/core/system/registry.hpp b/atlas/core/system/registry.hpp index 0c7382d4..5333f255 100644 --- a/atlas/core/system/registry.hpp +++ b/atlas/core/system/registry.hpp @@ -37,7 +37,7 @@ namespace atlas { */ /** - * @brief constructs a new world_scope + * @brief constructs a new world * * Initially this was used to create a world with a specified name * associated with it @@ -45,30 +45,30 @@ namespace atlas { * This was used for getting world to be maintained implicitly by * system_registry, though this will be changing. */ - static ref create_world(const std::string& p_tag); + static ref create_world(const std::string& p_tag); - //! @brief Searches and returns world_scope if found - //! @brief Returns nullptr if world_scope not found + //! @brief Searches and returns world if found + //! @brief Returns nullptr if world not found /** * @brief searches in getting the world and looks up based on its * specified name * * @return nullptr if not found, otherwise return - * shared_ptr + * shared_ptr */ - static ref get_world(const std::string& p_tag); + static ref get_world(const std::string& p_tag); private: - ref search_world(const std::string& p_tag); + ref search_world(const std::string& p_tag); - void append_world(const ref& p_world); + // void append_world(const ref& p_world); - ref append_world_scope(const ref& p_world); + ref append_world_and_get(const ref& p_world); private: static system_registry* s_instance; std::string m_tag = "Undefined"; - std::map> m_world_registered; + std::map> m_world_registered; }; }; \ No newline at end of file diff --git a/editor/editor_world.hpp b/editor/editor_world.hpp index 29460b02..94ff24ea 100644 --- a/editor/editor_world.hpp +++ b/editor/editor_world.hpp @@ -9,9 +9,7 @@ class editor_world { editor_world(const std::string& p_tag); private: - // atlas::ref m_main_world; - atlas::ref m_main_world; - //! TODO: Would be handled by our system registry + atlas::ref m_main_world; atlas::ref m_first_scene; atlas::event::event_bus m_bus; diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index a9db6e35..e50ef052 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -8,7 +8,7 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) : atlas::scene(p_name, p_bus) { - m_camera = create("Editor Camera"); + m_camera = entity("Editor Camera"); m_camera->add>(); m_camera->set({ .position = { 3.50f, 4.90f, 36.40f }, @@ -20,10 +20,10 @@ level_scene::level_scene(const std::string& p_name, .field_of_view = 45.f, }); - m_bob_object = create("Bob"); + m_bob_object = entity("Bob"); m_bob_object->add(); - m_viking_room = create("Viking Room"); + m_viking_room = entity("Viking Room"); m_viking_room->add(); m_viking_room->set({ .position = { -2.70f, 2.70, -8.30f }, @@ -41,7 +41,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_cube = create("Aircraft"); + m_cube = entity("Aircraft"); m_cube->set({ .position = { 0.f, 2.10f, -7.30f }, @@ -57,7 +57,7 @@ level_scene::level_scene(const std::string& p_name, // .diffuse = "assets/models/E-45-steel detail_2_col.jpg", }); - m_robot_model = create("Cube"); + m_robot_model = entity("Cube"); m_robot_model->add(); // m_robot_model->add(); m_robot_model->set({ @@ -79,7 +79,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_platform = create("Platform"); + m_platform = entity("Platform"); m_platform->set({ .scale = { 15.f, 0.30f, 10.0f }, @@ -95,7 +95,7 @@ level_scene::level_scene(const std::string& p_name, .half_extent = { 15.f, 0.30f, 10.0f }, }); - m_point_light = create("Point Light 1"); + m_point_light = entity("Point Light 1"); m_point_light->set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, @@ -170,16 +170,16 @@ level_scene::collision_persisted(atlas::event::collision_persisted& p_event) { void level_scene::runtime_start() { // runs the physics simulation - m_physics_is_runtime = true; + m_physics_runtime = true; - m_physics_engine_handler.start(); + m_physics_engine.start(); } void level_scene::runtime_stop() { - m_physics_is_runtime = false; + m_physics_runtime = false; - m_physics_engine_handler.stop(); + m_physics_engine.stop(); reset_objects(); } @@ -306,7 +306,7 @@ level_scene::on_ui_update() { // @param popup_flags - will be the mouse flag (0=right, 1=left) if (atlas::ui::begin_popup_context_window(nullptr, 1, false)) { if (ImGui::MenuItem("Create Empty Entity")) { - m_current_entity = create("Empty Entity"); + m_current_entity = entity("Empty Entity"); } ImGui::EndPopup(); } @@ -595,7 +595,7 @@ level_scene::start() { // Initiating physics system atlas::physics::jolt_settings settings = {}; flecs::world registry = *this; - m_physics_engine_handler = + m_physics_engine = atlas::physics::physics_engine(settings, registry, *event_handle()); // Note -- just added for temporary @@ -668,7 +668,7 @@ level_scene::on_update() { void level_scene::physics_update() { float dt = atlas::application::delta_time(); - if (atlas::event::is_key_pressed(key_r) and !m_physics_is_runtime) { + if (atlas::event::is_key_pressed(key_r) and !m_physics_runtime) { runtime_start(); } @@ -699,11 +699,11 @@ level_scene::physics_update() { sphere_body->angular_velocity = angular_vel; } - if (m_physics_is_runtime) { - m_physics_engine_handler.update(dt); + if (m_physics_runtime) { + m_physics_engine.update(dt); } - if (atlas::event::is_key_pressed(key_l) and m_physics_is_runtime) { + if (atlas::event::is_key_pressed(key_l) and m_physics_runtime) { runtime_stop(); } } diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index 1a58da90..f2c1e31c 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -38,6 +38,7 @@ class level_scene final : public atlas::scene { void reset_objects(); +private: void collision_enter(atlas::event::collision_enter& p_event); void collision_persisted(atlas::event::collision_persisted& p_event); @@ -51,7 +52,6 @@ class level_scene final : public atlas::scene { atlas::scene_object m_cube; atlas::scene_object m_robot_model; atlas::scene_object m_platform; - std::pmr::polymorphic_allocator<> m_allocator; atlas::scene_object m_camera; atlas::scene_object m_point_light; atlas::scene_object m_bob_object; @@ -61,9 +61,9 @@ class level_scene final : public atlas::scene { // Setting physics system // TODO -- when refactoring this would be at atlas::world layer - atlas::physics::physics_engine m_physics_engine_handler; + atlas::physics::physics_engine m_physics_engine; - bool m_physics_is_runtime = false; + bool m_physics_runtime = false; atlas::ui::dockspace m_editor_dockspace; atlas::ui::menu_item m_editor_menu; diff --git a/src/atlas/core/application.cpp b/src/atlas/core/application.cpp index 6f968009..3026b7c2 100644 --- a/src/atlas/core/application.cpp +++ b/src/atlas/core/application.cpp @@ -81,7 +81,7 @@ namespace atlas { m_renderer->preload( m_window->current_swapchain().swapchain_renderpass()); - ref current_world = + ref current_world = system_registry::get_world("Editor World"); ref current_scene = current_world->get_scene("LevelScene"); diff --git a/src/atlas/core/scene/world.cpp b/src/atlas/core/scene/world.cpp index ed4ed409..62d43aff 100644 --- a/src/atlas/core/scene/world.cpp +++ b/src/atlas/core/scene/world.cpp @@ -4,15 +4,15 @@ namespace atlas { - world_scope::world_scope(const std::string& p_name) + world::world(const std::string& p_name) : m_name(p_name) {} /** * @brief Currently how to pass in the scene context to the world * TODO: Have a way of allowing creation and management of those - * created-scenes be done through world_scope + * created-scenes be done through world */ - void world_scope::add_scene(const ref& p_scene_context) { + void world::add_scene(const ref& p_scene_context) { m_scene_container.emplace(p_scene_context->name(), p_scene_context); } }; \ No newline at end of file diff --git a/src/atlas/core/system/registry.cpp b/src/atlas/core/system/registry.cpp index 84215993..c0ccf02a 100644 --- a/src/atlas/core/system/registry.cpp +++ b/src/atlas/core/system/registry.cpp @@ -12,24 +12,20 @@ namespace atlas { system_registry::~system_registry() = default; - ref system_registry::create_world(const std::string& p_tag) { - return s_instance->append_world_scope(create_ref(p_tag)); + ref system_registry::create_world(const std::string& p_tag) { + return s_instance->append_world_and_get(create_ref(p_tag)); } - ref system_registry::get_world(const std::string& p_tag) { + ref system_registry::get_world(const std::string& p_tag) { return s_instance->search_world(p_tag); } - ref system_registry::search_world(const std::string& p_tag) { + ref system_registry::search_world(const std::string& p_tag) { return m_world_registered[p_tag]; } - void system_registry::append_world(const ref& p_world) { - m_world_registered.emplace(p_world->name(), p_world); - } - - ref system_registry::append_world_scope( - const ref& p_world) { + ref system_registry::append_world_and_get( + const ref& p_world) { m_world_registered.emplace(p_world->name(), p_world); return m_world_registered[p_world->name()]; } diff --git a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp index d5510fa7..89a21d62 100644 --- a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp +++ b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp @@ -209,7 +209,7 @@ namespace atlas::vk { void vk_renderer::preload_assets(const VkRenderPass& p_renderpass) { m_final_renderpass = p_renderpass; // set 1 -- material uniforms - ref current_world = + ref current_world = system_registry::get_world("Editor World"); ref current_scene = current_world->get_scene("LevelScene"); @@ -479,7 +479,7 @@ namespace atlas::vk { // m_global_uniforms.update(bytes_data.data()); m_global_uniforms.update(&global_frame_ubo); - ref current_world = + ref current_world = system_registry::get_world("Editor World"); ref current_scene = current_world->get_scene("LevelScene"); From 686465eed19119cf59da18a966976d7ec0cfa9ee Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Wed, 3 Dec 2025 19:02:22 -0800 Subject: [PATCH 17/42] WIP for getting std::optional to work --- atlas/core/scene/scene.hpp | 18 +++++++++++++++--- atlas/core/scene/scene_object.hpp | 10 +++------- editor/level_scene.cpp | 26 +++++++++++--------------- editor/level_scene.hpp | 16 ++++++++-------- src/atlas/core/scene/scene.cpp | 10 +++++++++- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index 3fde1f1e..d699bd21 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -35,11 +35,23 @@ namespace atlas { /** * @brief create a new entity (game object) * - * Will create an entity (game object) or retrieve existing entity if - * the name for that entity exists within the ecs registry. + * If entity with the specified name exists, retrieve that specific + * entity. If entity does not exist, create that entity + * + * @param p_name is the name of the entity */ scene_object entity(const std::string& p_name); + /** + * @brief create a new entity or retrieve already-existent entity by ID + * + * @param p_entity_id is the entity ID to retrieve if it exists, if not + * create it. + */ + scene_object entity(uint64_t p_entity_id); + + std::optional entity_optional(const std::string& p_name); + /** * @brief subscribes an event to the event::bus to get invoked when * publishers notify all subscribers when an update is incoming @@ -113,7 +125,7 @@ namespace atlas { * * ``` */ - uint32_t children_count(scene_object p_parent); + uint32_t children_count(const scene_object& p_parent); /** * @brief Defer operations until end of frame. diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index 183a2ce7..322e988f 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -7,15 +7,13 @@ namespace atlas { * @brief Creates a pointer wrapper which extends capabilities of * flecs::entity * - * Wrapper that provides - * * Provides our own construct of API's that handles any workload around some * of the raw flecs API's that can still be used by other flecs API's * without completely interacting touching raw flecs API */ class scene_object : public flecs::entity { public: - scene_object() = default; + scene_object() = delete; scene_object(flecs::world_t* p_registry, flecs::entity_t p_id); @@ -50,11 +48,10 @@ namespace atlas { * @brief iterates through all children entities if the given entity is * a parent of any given entities * - * * Example Usage: + * * * ```C++ - * * atlas::scene_object obj1 = create("Parent Node"); * atlas::scene_object obj2 = create("Chlid Node"); * @@ -65,9 +62,8 @@ namespace atlas { * obj1.children([](flecs::entity p_child){ * // do stuff with the child entity * }); - * + * * ``` - * */ template void children(UFunction&& p_callback) { diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index e50ef052..618efddf 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -8,7 +8,7 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) : atlas::scene(p_name, p_bus) { - m_camera = entity("Editor Camera"); + m_camera = entity_optional("Editor Camera"); m_camera->add>(); m_camera->set({ .position = { 3.50f, 4.90f, 36.40f }, @@ -20,10 +20,10 @@ level_scene::level_scene(const std::string& p_name, .field_of_view = 45.f, }); - m_bob_object = entity("Bob"); + m_bob_object = entity_optional("Bob"); m_bob_object->add(); - m_viking_room = entity("Viking Room"); + m_viking_room = entity_optional("Viking Room"); m_viking_room->add(); m_viking_room->set({ .position = { -2.70f, 2.70, -8.30f }, @@ -41,7 +41,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_cube = entity("Aircraft"); + m_cube = entity_optional("Aircraft"); m_cube->set({ .position = { 0.f, 2.10f, -7.30f }, @@ -57,7 +57,7 @@ level_scene::level_scene(const std::string& p_name, // .diffuse = "assets/models/E-45-steel detail_2_col.jpg", }); - m_robot_model = entity("Cube"); + m_robot_model = entity_optional("Cube"); m_robot_model->add(); // m_robot_model->add(); m_robot_model->set({ @@ -79,7 +79,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_platform = entity("Platform"); + m_platform = entity_optional("Platform"); m_platform->set({ .scale = { 15.f, 0.30f, 10.0f }, @@ -95,7 +95,7 @@ level_scene::level_scene(const std::string& p_name, .half_extent = { 15.f, 0.30f, 10.0f }, }); - m_point_light = entity("Point Light 1"); + m_point_light = entity_optional("Point Light 1"); m_point_light->set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, @@ -148,9 +148,8 @@ level_scene::level_scene(const std::string& p_name, void level_scene::collision_enter(atlas::event::collision_enter& p_event) { console_log_warn("collision_enter event!!!"); - flecs::world registry = *this; - flecs::entity e1 = registry.entity(p_event.entity1); - flecs::entity e2 = registry.entity(p_event.entity2); + atlas::scene_object e1 = entity(p_event.entity1); + atlas::scene_object e2 = entity(p_event.entity2); console_log_warn("Entity1 = {}", e1.name().c_str()); console_log_warn("Entity2 = {}", e2.name().c_str()); @@ -159,9 +158,8 @@ level_scene::collision_enter(atlas::event::collision_enter& p_event) { void level_scene::collision_persisted(atlas::event::collision_persisted& p_event) { console_log_warn("collision_persisted(p_event) invoked!!"); - flecs::world registry = *this; - flecs::entity e1 = registry.entity(p_event.entity1); - flecs::entity e2 = registry.entity(p_event.entity2); + atlas::scene_object e1 = entity(p_event.entity1); + atlas::scene_object e2 = entity(p_event.entity2); console_log_warn("Entity1 = {}", e1.name().c_str()); console_log_warn("Entity2 = {}", e2.name().c_str()); @@ -323,7 +321,6 @@ level_scene::on_ui_update() { flags |= ImGuiWindowFlags_Popup; flags |= ImGuiTreeNodeFlags_AllowItemOverlap; - // std::string fmt = std::format("{} ({})", p_entity.name().c_str(), p_entity.id()); bool opened = ImGui::TreeNodeEx(p_entity.name().c_str(), flags); if (ImGui::IsItemClicked()) { @@ -339,7 +336,6 @@ level_scene::on_ui_update() { } if (delete_entity) { - // _context->destroyEntity(entity); m_selected_entity.destruct(); } diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index f2c1e31c..db07512a 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -48,14 +48,14 @@ class level_scene final : public atlas::scene { atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - atlas::scene_object m_viking_room; - atlas::scene_object m_cube; - atlas::scene_object m_robot_model; - atlas::scene_object m_platform; - atlas::scene_object m_camera; - atlas::scene_object m_point_light; - atlas::scene_object m_bob_object; - atlas::scene_object m_current_entity; + std::optional m_viking_room; + std::optional m_cube; + std::optional m_robot_model; + std::optional m_platform; + std::optional m_camera; + std::optional m_point_light; + std::optional m_bob_object; + std::optional m_current_entity; float m_movement_speed = 10.f; // std::vector> m_many_objects; diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index 549ae673..caca1010 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -8,9 +8,17 @@ namespace atlas { scene_object scene::entity(const std::string& p_name) { return scene_object(m_registry.entity(p_name.c_str())); } + + scene_object scene::entity(uint64_t p_entity_id) { + return scene_object(m_registry.entity(p_entity_id)); + } - uint32_t scene::children_count(scene_object p_parent) { + uint32_t scene::children_count(const scene_object& p_parent) { return query_builder().with(flecs::ChildOf, p_parent).build().count(); } + std::optional scene::entity_optional(const std::string& p_name) { + return std::make_optional(m_registry.entity(p_name.c_str())); + } + }; \ No newline at end of file From 2f1c1c609d042759c642858c5b936e0eda7d0154 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Wed, 3 Dec 2025 19:21:31 -0800 Subject: [PATCH 18/42] WIP uscene_objects and fixed up API's to only enable creating game objects through uscene_object and the entity API from the scene class --- atlas/core/scene/scene.hpp | 6 ++--- atlas/core/scene/scene_object.hpp | 27 ++++++++-------------- editor/level_scene.cpp | 33 +++++++++++++++------------ editor/level_scene.hpp | 16 ++++++------- src/atlas/core/scene/scene.cpp | 8 ++----- src/atlas/core/scene/scene_object.cpp | 14 ------------ 6 files changed, 40 insertions(+), 64 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index d699bd21..bccd3598 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -40,7 +40,7 @@ namespace atlas { * * @param p_name is the name of the entity */ - scene_object entity(const std::string& p_name); + uscene_object entity(const std::string& p_name); /** * @brief create a new entity or retrieve already-existent entity by ID @@ -48,9 +48,7 @@ namespace atlas { * @param p_entity_id is the entity ID to retrieve if it exists, if not * create it. */ - scene_object entity(uint64_t p_entity_id); - - std::optional entity_optional(const std::string& p_name); + uscene_object entity(uint64_t p_entity_id); /** * @brief subscribes an event to the event::bus to get invoked when diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index 322e988f..b70fdcfe 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include namespace atlas { @@ -13,6 +14,7 @@ namespace atlas { */ class scene_object : public flecs::entity { public: + //! @brief Should not construct a scene object not created through flecs::world scene_object() = delete; scene_object(flecs::world_t* p_registry, flecs::entity_t p_id); @@ -31,9 +33,9 @@ namespace atlas { * * ```C++ * - * atlas::scene_object obj1 = create("Parent"); + * atlas::uscene_object obj1 = entity("Parent"); * - * atlas::scene_object obj2 = create("Chlid"); + * atlas::uscene_object obj2 = entity("Chlid"); * * // obj2 is the child of obj1 * // As obj1 is a parent node @@ -52,8 +54,8 @@ namespace atlas { * * * ```C++ - * atlas::scene_object obj1 = create("Parent Node"); - * atlas::scene_object obj2 = create("Chlid Node"); + * atlas::uscene_object obj1 = entity("Parent Node"); + * atlas::uscene_object obj2 = entity("Chlid Node"); * * // obj1 is the parent of obj2. * obj2.child_of(parent); @@ -69,19 +71,10 @@ namespace atlas { void children(UFunction&& p_callback) { children(p_callback); } - - /** - * @brief Since we do not have a way to ensure that the access point to - * this object is invalid, we use the -> operator to ensure the object - * is valid. - * - * Including cannot overload the `.` operator, to ensure object if it is valid. - * - * The `->` operator will throw std::runtime_error exception if object's - * invalid or return the object - * - */ - flecs::entity* operator->(); }; + /** + * @brief game object type exposed to the user as an alias to game objects + */ + using uscene_object = std::optional; }; \ No newline at end of file diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 618efddf..5ddac9bd 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -8,7 +8,7 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) : atlas::scene(p_name, p_bus) { - m_camera = entity_optional("Editor Camera"); + m_camera = entity("Editor Camera"); m_camera->add>(); m_camera->set({ .position = { 3.50f, 4.90f, 36.40f }, @@ -20,10 +20,10 @@ level_scene::level_scene(const std::string& p_name, .field_of_view = 45.f, }); - m_bob_object = entity_optional("Bob"); + m_bob_object = entity("Bob"); m_bob_object->add(); - m_viking_room = entity_optional("Viking Room"); + m_viking_room = entity("Viking Room"); m_viking_room->add(); m_viking_room->set({ .position = { -2.70f, 2.70, -8.30f }, @@ -41,7 +41,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_cube = entity_optional("Aircraft"); + m_cube = entity("Aircraft"); m_cube->set({ .position = { 0.f, 2.10f, -7.30f }, @@ -57,7 +57,7 @@ level_scene::level_scene(const std::string& p_name, // .diffuse = "assets/models/E-45-steel detail_2_col.jpg", }); - m_robot_model = entity_optional("Cube"); + m_robot_model = entity("Cube"); m_robot_model->add(); // m_robot_model->add(); m_robot_model->set({ @@ -79,7 +79,7 @@ level_scene::level_scene(const std::string& p_name, .body_movement_type = atlas::dynamic, }); - m_platform = entity_optional("Platform"); + m_platform = entity("Platform"); m_platform->set({ .scale = { 15.f, 0.30f, 10.0f }, @@ -95,7 +95,7 @@ level_scene::level_scene(const std::string& p_name, .half_extent = { 15.f, 0.30f, 10.0f }, }); - m_point_light = entity_optional("Point Light 1"); + m_point_light = entity("Point Light 1"); m_point_light->set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, @@ -133,6 +133,9 @@ level_scene::level_scene(const std::string& p_name, // m_many_objects.emplace_back(obj); // } + atlas::uscene_object gerald = entity("Gerald"); + gerald->add(); + // TODO: Move this outside of level_scene m_deserializer_test = atlas::serializer(); @@ -148,21 +151,21 @@ level_scene::level_scene(const std::string& p_name, void level_scene::collision_enter(atlas::event::collision_enter& p_event) { console_log_warn("collision_enter event!!!"); - atlas::scene_object e1 = entity(p_event.entity1); - atlas::scene_object e2 = entity(p_event.entity2); + atlas::uscene_object e1 = entity(p_event.entity1); + atlas::uscene_object e2 = entity(p_event.entity2); - console_log_warn("Entity1 = {}", e1.name().c_str()); - console_log_warn("Entity2 = {}", e2.name().c_str()); + console_log_warn("Entity1 = {}", e1->name().c_str()); + console_log_warn("Entity2 = {}", e2->name().c_str()); } void level_scene::collision_persisted(atlas::event::collision_persisted& p_event) { console_log_warn("collision_persisted(p_event) invoked!!"); - atlas::scene_object e1 = entity(p_event.entity1); - atlas::scene_object e2 = entity(p_event.entity2); + atlas::uscene_object e1 = entity(p_event.entity1); + atlas::uscene_object e2 = entity(p_event.entity2); - console_log_warn("Entity1 = {}", e1.name().c_str()); - console_log_warn("Entity2 = {}", e2.name().c_str()); + console_log_warn("Entity1 = {}", e1->name().c_str()); + console_log_warn("Entity2 = {}", e2->name().c_str()); } void diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index db07512a..1b2c766d 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -48,14 +48,14 @@ class level_scene final : public atlas::scene { atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - std::optional m_viking_room; - std::optional m_cube; - std::optional m_robot_model; - std::optional m_platform; - std::optional m_camera; - std::optional m_point_light; - std::optional m_bob_object; - std::optional m_current_entity; + atlas::uscene_object m_viking_room; + atlas::uscene_object m_cube; + atlas::uscene_object m_robot_model; + atlas::uscene_object m_platform; + atlas::uscene_object m_camera; + atlas::uscene_object m_point_light; + atlas::uscene_object m_bob_object; + atlas::uscene_object m_current_entity; float m_movement_speed = 10.f; // std::vector> m_many_objects; diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index caca1010..3e1f456b 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -5,11 +5,11 @@ namespace atlas { : m_name(p_name) , m_bus(&p_bus) {} - scene_object scene::entity(const std::string& p_name) { + uscene_object scene::entity(const std::string& p_name) { return scene_object(m_registry.entity(p_name.c_str())); } - scene_object scene::entity(uint64_t p_entity_id) { + uscene_object scene::entity(uint64_t p_entity_id) { return scene_object(m_registry.entity(p_entity_id)); } @@ -17,8 +17,4 @@ namespace atlas { return query_builder().with(flecs::ChildOf, p_parent).build().count(); } - std::optional scene::entity_optional(const std::string& p_name) { - return std::make_optional(m_registry.entity(p_name.c_str())); - } - }; \ No newline at end of file diff --git a/src/atlas/core/scene/scene_object.cpp b/src/atlas/core/scene/scene_object.cpp index 976ceea5..0cb2be75 100644 --- a/src/atlas/core/scene/scene_object.cpp +++ b/src/atlas/core/scene/scene_object.cpp @@ -22,18 +22,4 @@ namespace atlas { void scene_object::child_of(const scene_object& p_parent) { add(flecs::ChildOf, p_parent); } - - flecs::entity* scene_object::operator->() { - // We want to check if this game object is accessible or else throw an - // exception if invalid or nullptr - flecs::entity* e = this; - - // We only want to access this entity if it is alive and valid! - if (!e->is_valid() and !e->is_alive()) { - throw invalid_access_exception( - "Invalid access to an invalid pointer to game object"); - } - - return e; - } }; \ No newline at end of file From b5d0d1a8d2e60c36fe14471f06de4ce91667900a Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Wed, 3 Dec 2025 19:41:57 -0800 Subject: [PATCH 19/42] WIP changed parameters from using atlas::scene_object to atlas::uscene_object --- atlas/core/scene/scene.hpp | 2 +- atlas/core/scene/scene_object.hpp | 16 ++++++++++------ src/atlas/core/scene/scene.cpp | 4 ++-- src/atlas/core/scene/scene_object.cpp | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index bccd3598..de78d7a1 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -123,7 +123,7 @@ namespace atlas { * * ``` */ - uint32_t children_count(const scene_object& p_parent); + uint32_t children_count(const uscene_object& p_parent); /** * @brief Defer operations until end of frame. diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index b70fdcfe..211634c7 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -14,7 +14,8 @@ namespace atlas { */ class scene_object : public flecs::entity { public: - //! @brief Should not construct a scene object not created through flecs::world + //! @brief Should not construct a scene object not created through + //! flecs::world scene_object() = delete; scene_object(flecs::world_t* p_registry, flecs::entity_t p_id); @@ -44,14 +45,14 @@ namespace atlas { * ``` * */ - void child_of(const scene_object& p_parent); + void child_of(const std::optional& p_parent); /** * @brief iterates through all children entities if the given entity is * a parent of any given entities * * Example Usage: - * + * * * ```C++ * atlas::uscene_object obj1 = entity("Parent Node"); @@ -64,7 +65,7 @@ namespace atlas { * obj1.children([](flecs::entity p_child){ * // do stuff with the child entity * }); - * + * * ``` */ template @@ -74,7 +75,10 @@ namespace atlas { }; /** - * @brief game object type exposed to the user as an alias to game objects - */ + * @brief Alias to std::optional + * + * Restrict from enabling creating empty game objects that is not valid to + * access its members to perform operations with + */ using uscene_object = std::optional; }; \ No newline at end of file diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index 3e1f456b..8517582f 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -13,8 +13,8 @@ namespace atlas { return scene_object(m_registry.entity(p_entity_id)); } - uint32_t scene::children_count(const scene_object& p_parent) { - return query_builder().with(flecs::ChildOf, p_parent).build().count(); + uint32_t scene::children_count(const uscene_object& p_parent) { + return query_builder().with(flecs::ChildOf, p_parent.value()).build().count(); } }; \ No newline at end of file diff --git a/src/atlas/core/scene/scene_object.cpp b/src/atlas/core/scene/scene_object.cpp index 0cb2be75..30cef70c 100644 --- a/src/atlas/core/scene/scene_object.cpp +++ b/src/atlas/core/scene/scene_object.cpp @@ -19,7 +19,7 @@ namespace atlas { add(); } - void scene_object::child_of(const scene_object& p_parent) { - add(flecs::ChildOf, p_parent); + void scene_object::child_of(const std::optional& p_parent) { + add(flecs::ChildOf, p_parent.value()); } }; \ No newline at end of file From cd65f269b71310e8f734aee4ebe295b07af1aa64 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Wed, 3 Dec 2025 20:25:07 -0800 Subject: [PATCH 20/42] Updated test cases to conform to the new API's for scenes and scene object creations --- tests/entity_component_system.test.cpp | 40 +++++++------- tests/jolt_engine.test.cpp | 75 +++++--------------------- tests/scene.test.cpp | 15 +++--- 3 files changed, 40 insertions(+), 90 deletions(-) diff --git a/tests/entity_component_system.test.cpp b/tests/entity_component_system.test.cpp index f1e825b4..239a4089 100644 --- a/tests/entity_component_system.test.cpp +++ b/tests/entity_component_system.test.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include namespace atlas { @@ -82,39 +82,39 @@ namespace atlas { //! @note Each scene will define flecs::world typically //! @note flecs::world is how flecs (ECS) stores entities and components - flecs::world scene_registry; + atlas::event::event_bus test_event_bus; + atlas::scene test_scene = atlas::scene("Mock Scene", test_event_bus); - "create_entity::add"_test = [&scene_registry] { + "create_entity::add"_test = [&test_scene] { // flecs::entity entity = scene_registry.entity("Mock Entity"); - atlas::scene_object entity = - atlas::scene_object(&scene_registry, "Mock Entity"); + atlas::uscene_object entity = test_scene.entity("Mock Entity"); // expect(entity.is_alive()); - entity.add(); - expect(entity.has()); + entity->add(); + expect(entity->has()); }; - "create_entity::get"_test = [&scene_registry]() { - atlas::scene_object entity = - atlas::scene_object(&scene_registry, "Mock Entity2"); - entity.add(); - //! @note Flecs require you to get the component for the use of only - //! reading the data from component - //! @note To actually set values to that component you use the set - //! usnig their API they specify - entity.set({ .tag = "New Entity" }); + "create_entity::get"_test = [&test_scene]() { + atlas::uscene_object entity = test_scene.entity("Mock Entity 2"); + entity->add(); + // flecs requires reading only operations are through the get API + // to write or set new parameters you can use get_mut or + // set(T&&); in this case, I use set in this test case + entity->set({ .tag = "New Entity" }); const test_tag_component* get_tag = - entity.get(); + entity->get(); expect(get_tag->tag == "New Entity"); }; - "create_entity::set"_test = [&scene_registry]() { - atlas::scene_object entity = - atlas::scene_object(&scene_registry, "New Entity"); + "create_entity::set"_test = [&test_scene]() { + atlas::uscene_object entity = test_scene.entity("New Entity"); mock_projectile projectile; projectile.on_update(); + entity->set(projectile); + + expect(entity->has()); // test_transform transform; // transform.position = projectile.position(); diff --git a/tests/jolt_engine.test.cpp b/tests/jolt_engine.test.cpp index 706124ea..ed7ba575 100644 --- a/tests/jolt_engine.test.cpp +++ b/tests/jolt_engine.test.cpp @@ -1,19 +1,14 @@ -#include - -#include - -#include +#include #include #include -#include -#include -#include -#include #include +#include +#include #include #include -#include + +#include namespace atlas { @@ -25,58 +20,16 @@ namespace atlas { boost::ut::suite<"physics_engine_integration"> engine_test = [] { using namespace boost::ut; - class test_scene : public scene { - public: - test_scene(const std::string& p_tag, event::event_bus& p_bus) - : scene(p_tag, p_bus) {}; - - std::pmr::polymorphic_allocator<> m_object_allocator; - }; - - class editor_world : public world_scope { - public: - editor_world(const std::string& p_tag) - : world_scope(p_tag) {}; - }; - - "initialize_engine with physics_world and setup object"_test = [] { - system_registry m_log_registery = system_registry("Registry"); - - editor_world editor = editor_world("Editor World"); - - // ref physics_world = - // editor.create_custom_scene("LevelScene"); - // expect(eq(physics_world->get_tag(), std::string("LevelScene"))); - - /** - * @bug FIXME: This does not work because the operator in - * scene: - * operator flecs::world() { return m_registry; } - * - * Returns a copy of the flecs world. This can be an invalid - * state. Instead have a get_world() function. - */ - // flecs::world test_world = *physics_world; - - // expect(test_world.get_info() != nullptr); - - // strong_ref physics_setup = - // physics_world->create_object("Physics Tooling"); - - // // Add required config components - // physics_setup->add(); - // physics_setup->add(); - - // // Now initialize the physics engine using that setup - // optional_ref engine = - // atlas::physics::initialize_engine(physics_world->m_object_allocator,physics_setup, - // test_world); + // Setup to do testing and assume we have a specified current scene that + // gets provided to you during that runtime + atlas::event::event_bus bus; + atlas::scene test_environment_scene = atlas::scene("Mock 1", bus); - // expect(engine != nullptr); + // Do some testing if these two collides or something like that + // atlas::uscene_object obj1 = test_environment_scene.entity("Entity + // 1"); atlas::uscene_object obj2 = + // test_environment_scene.entity("Entity 2"); - // engine->start_runtime(); - // engine->physics_step(); - // engine->stop_runtime(); - }; + "on_collision_enter"_test = [] {}; }; }; \ No newline at end of file diff --git a/tests/scene.test.cpp b/tests/scene.test.cpp index e9487d67..028bc4fc 100644 --- a/tests/scene.test.cpp +++ b/tests/scene.test.cpp @@ -1,20 +1,17 @@ #include #include #include +#include boost::ut::suite<"::scene"> scene_test = []() { using namespace boost::ut; atlas::event::event_bus test_event_bus; - atlas::scene test_scope = atlas::scene("Mock Scene 1", test_event_bus); + atlas::scene test_scene = atlas::scene("Mock Scene 1", test_event_bus); - "create_object"_test = [&test_scope]() { - atlas::strong_ref test_object = - test_scope.create_object("Entity 1"); + "create_object"_test = [&test_scene]() { + atlas::uscene_object test_object = test_scene.entity("Entity 1"); + test_object->add(); - test_object->set({ .position{ 1.f } }); - glm::vec3 mock_pos{ 1.f }; - - const atlas::transform* t = test_object->get(); - expect(mock_pos == t->position); + expect(test_object->has()); }; }; From d7a90388dd2edaf690a3d89cfb779b8f961f9096 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Wed, 3 Dec 2025 20:32:00 -0800 Subject: [PATCH 21/42] Updated order of rendering components in the UI editor --- editor/level_scene.cpp | 45 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 5ddac9bd..aeeceb8d 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -398,6 +398,29 @@ level_scene::on_ui_update() { ImGui::DragFloat("Speed", &m_movement_speed); }); + atlas::ui::draw_component( + "atlas::mesh_source", + m_selected_entity, + [](atlas::mesh_source* p_source) { + std::string mesh_src = p_source->model_path; + atlas::ui::draw_input_text(p_source->model_path, mesh_src); + atlas::ui::draw_vec4("Color", p_source->color); + }); + + atlas::ui::draw_component( + "material", + m_selected_entity, + [](atlas::material_metadata* p_source) { + float speed = 0.01f; + ImGui::DragFloat4( + "Ambient", glm::value_ptr(p_source->ambient), speed); + ImGui::DragFloat4( + "Diffuse", glm::value_ptr(p_source->diffuse), speed); + ImGui::DragFloat4( + "Specular", glm::value_ptr(p_source->specular), speed); + atlas::ui::draw_float("Shininess", p_source->shininess); + }); + /* atlas::ui::draw_component("Directional Light", m_selected_entity, [](atlas::directional_light* @@ -431,28 +454,6 @@ level_scene::on_ui_update() { ImGui::DragFloat("Quadratic", &p_dir_light->quadratic, 0.01); }); - atlas::ui::draw_component( - "atlas::mesh_source", - m_selected_entity, - [](atlas::mesh_source* p_source) { - // atlas::ui::draw_input_text(p_source->model_path, p_source->model_path); - atlas::ui::draw_vec4("Color", p_source->color); - }); - - atlas::ui::draw_component( - "material", - m_selected_entity, - [](atlas::material_metadata* p_source) { - float speed = 0.01f; - ImGui::DragFloat4( - "Ambient", glm::value_ptr(p_source->ambient), speed); - ImGui::DragFloat4( - "Diffuse", glm::value_ptr(p_source->diffuse), speed); - ImGui::DragFloat4( - "Specular", glm::value_ptr(p_source->specular), speed); - atlas::ui::draw_float("Shininess", p_source->shininess); - }); - atlas::ui::draw_component( "Physics Body", m_selected_entity, From f4beb63551afee42ea0e22ee009e9e45173e0121 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Wed, 3 Dec 2025 22:12:36 -0800 Subject: [PATCH 22/42] Renamed atlas::uscene_object to atlas::game_object --- atlas/core/scene/scene.hpp | 8 ++++---- atlas/core/scene/scene_object.hpp | 10 +++++----- editor/level_scene.cpp | 10 +++++----- editor/level_scene.hpp | 16 ++++++++-------- src/atlas/core/scene/scene.cpp | 13 ++++++++----- tests/entity_component_system.test.cpp | 6 +++--- tests/jolt_engine.test.cpp | 4 ++-- tests/scene.test.cpp | 2 +- 8 files changed, 36 insertions(+), 33 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index de78d7a1..e92f7158 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -40,15 +40,15 @@ namespace atlas { * * @param p_name is the name of the entity */ - uscene_object entity(const std::string& p_name); + game_object entity(const std::string& p_name); /** * @brief create a new entity or retrieve already-existent entity by ID - * + * * @param p_entity_id is the entity ID to retrieve if it exists, if not * create it. */ - uscene_object entity(uint64_t p_entity_id); + game_object entity(uint64_t p_entity_id); /** * @brief subscribes an event to the event::bus to get invoked when @@ -123,7 +123,7 @@ namespace atlas { * * ``` */ - uint32_t children_count(const uscene_object& p_parent); + uint32_t children_count(const game_object& p_parent); /** * @brief Defer operations until end of frame. diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index 211634c7..24cfb3f3 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -34,9 +34,9 @@ namespace atlas { * * ```C++ * - * atlas::uscene_object obj1 = entity("Parent"); + * atlas::game_object obj1 = entity("Parent"); * - * atlas::uscene_object obj2 = entity("Chlid"); + * atlas::game_object obj2 = entity("Chlid"); * * // obj2 is the child of obj1 * // As obj1 is a parent node @@ -55,8 +55,8 @@ namespace atlas { * * * ```C++ - * atlas::uscene_object obj1 = entity("Parent Node"); - * atlas::uscene_object obj2 = entity("Chlid Node"); + * atlas::game_object obj1 = entity("Parent Node"); + * atlas::game_object obj2 = entity("Chlid Node"); * * // obj1 is the parent of obj2. * obj2.child_of(parent); @@ -80,5 +80,5 @@ namespace atlas { * Restrict from enabling creating empty game objects that is not valid to * access its members to perform operations with */ - using uscene_object = std::optional; + using game_object = std::optional; }; \ No newline at end of file diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index aeeceb8d..2709b937 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -133,7 +133,7 @@ level_scene::level_scene(const std::string& p_name, // m_many_objects.emplace_back(obj); // } - atlas::uscene_object gerald = entity("Gerald"); + atlas::game_object gerald = entity("Gerald"); gerald->add(); // TODO: Move this outside of level_scene @@ -151,8 +151,8 @@ level_scene::level_scene(const std::string& p_name, void level_scene::collision_enter(atlas::event::collision_enter& p_event) { console_log_warn("collision_enter event!!!"); - atlas::uscene_object e1 = entity(p_event.entity1); - atlas::uscene_object e2 = entity(p_event.entity2); + atlas::game_object e1 = entity(p_event.entity1); + atlas::game_object e2 = entity(p_event.entity2); console_log_warn("Entity1 = {}", e1->name().c_str()); console_log_warn("Entity2 = {}", e2->name().c_str()); @@ -161,8 +161,8 @@ level_scene::collision_enter(atlas::event::collision_enter& p_event) { void level_scene::collision_persisted(atlas::event::collision_persisted& p_event) { console_log_warn("collision_persisted(p_event) invoked!!"); - atlas::uscene_object e1 = entity(p_event.entity1); - atlas::uscene_object e2 = entity(p_event.entity2); + atlas::game_object e1 = entity(p_event.entity1); + atlas::game_object e2 = entity(p_event.entity2); console_log_warn("Entity1 = {}", e1->name().c_str()); console_log_warn("Entity2 = {}", e2->name().c_str()); diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index 1b2c766d..15d781f2 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -48,14 +48,14 @@ class level_scene final : public atlas::scene { atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - atlas::uscene_object m_viking_room; - atlas::uscene_object m_cube; - atlas::uscene_object m_robot_model; - atlas::uscene_object m_platform; - atlas::uscene_object m_camera; - atlas::uscene_object m_point_light; - atlas::uscene_object m_bob_object; - atlas::uscene_object m_current_entity; + atlas::game_object m_viking_room; + atlas::game_object m_cube; + atlas::game_object m_robot_model; + atlas::game_object m_platform; + atlas::game_object m_camera; + atlas::game_object m_point_light; + atlas::game_object m_bob_object; + atlas::game_object m_current_entity; float m_movement_speed = 10.f; // std::vector> m_many_objects; diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index 8517582f..ecc3a45d 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -5,16 +5,19 @@ namespace atlas { : m_name(p_name) , m_bus(&p_bus) {} - uscene_object scene::entity(const std::string& p_name) { + game_object scene::entity(const std::string& p_name) { return scene_object(m_registry.entity(p_name.c_str())); } - - uscene_object scene::entity(uint64_t p_entity_id) { + + game_object scene::entity(uint64_t p_entity_id) { return scene_object(m_registry.entity(p_entity_id)); } - uint32_t scene::children_count(const uscene_object& p_parent) { - return query_builder().with(flecs::ChildOf, p_parent.value()).build().count(); + uint32_t scene::children_count(const game_object& p_parent) { + return query_builder() + .with(flecs::ChildOf, p_parent.value()) + .build() + .count(); } }; \ No newline at end of file diff --git a/tests/entity_component_system.test.cpp b/tests/entity_component_system.test.cpp index 239a4089..ac4d8d54 100644 --- a/tests/entity_component_system.test.cpp +++ b/tests/entity_component_system.test.cpp @@ -87,7 +87,7 @@ namespace atlas { "create_entity::add"_test = [&test_scene] { // flecs::entity entity = scene_registry.entity("Mock Entity"); - atlas::uscene_object entity = test_scene.entity("Mock Entity"); + atlas::game_object entity = test_scene.entity("Mock Entity"); // expect(entity.is_alive()); @@ -96,7 +96,7 @@ namespace atlas { }; "create_entity::get"_test = [&test_scene]() { - atlas::uscene_object entity = test_scene.entity("Mock Entity 2"); + atlas::game_object entity = test_scene.entity("Mock Entity 2"); entity->add(); // flecs requires reading only operations are through the get API // to write or set new parameters you can use get_mut or @@ -109,7 +109,7 @@ namespace atlas { }; "create_entity::set"_test = [&test_scene]() { - atlas::uscene_object entity = test_scene.entity("New Entity"); + atlas::game_object entity = test_scene.entity("New Entity"); mock_projectile projectile; projectile.on_update(); entity->set(projectile); diff --git a/tests/jolt_engine.test.cpp b/tests/jolt_engine.test.cpp index ed7ba575..c20aa02d 100644 --- a/tests/jolt_engine.test.cpp +++ b/tests/jolt_engine.test.cpp @@ -26,8 +26,8 @@ namespace atlas { atlas::scene test_environment_scene = atlas::scene("Mock 1", bus); // Do some testing if these two collides or something like that - // atlas::uscene_object obj1 = test_environment_scene.entity("Entity - // 1"); atlas::uscene_object obj2 = + // atlas::game_object obj1 = test_environment_scene.entity("Entity + // 1"); atlas::game_object obj2 = // test_environment_scene.entity("Entity 2"); "on_collision_enter"_test = [] {}; diff --git a/tests/scene.test.cpp b/tests/scene.test.cpp index 028bc4fc..182829c2 100644 --- a/tests/scene.test.cpp +++ b/tests/scene.test.cpp @@ -9,7 +9,7 @@ boost::ut::suite<"::scene"> scene_test = []() { atlas::scene test_scene = atlas::scene("Mock Scene 1", test_event_bus); "create_object"_test = [&test_scene]() { - atlas::uscene_object test_object = test_scene.entity("Entity 1"); + atlas::game_object test_object = test_scene.entity("Entity 1"); test_object->add(); expect(test_object->has()); From eb913704a60b107c6d5917d4ead31ce729bca4b7 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Thu, 4 Dec 2025 00:50:51 -0800 Subject: [PATCH 23/42] Code cleaned up atlas::world and did some minor refactor to the editor world and application code --- atlas/core/scene/world.hpp | 9 --------- editor/application.cpp | 18 ++++++++++++++++-- editor/editor_world.cpp | 5 +++-- editor/editor_world.hpp | 2 -- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/atlas/core/scene/world.hpp b/atlas/core/scene/world.hpp index 66c8cfc3..436c6ff0 100644 --- a/atlas/core/scene/world.hpp +++ b/atlas/core/scene/world.hpp @@ -48,15 +48,6 @@ namespace atlas { */ void add_scene(const ref& p_scene_context); - template - ref create_custom_scene(const std::string& p_name) { - static_assert( - std::is_base_of_v, - "Must be a scene that inherits from scene as a base class"); - m_scene_container[p_name] = create_ref(p_name); - return m_scene_container[p_name]; - } - /** * @brief get_scene allows for specifically querying for current scenes * diff --git a/editor/application.cpp b/editor/application.cpp index efb8950f..4bd55bb8 100644 --- a/editor/application.cpp +++ b/editor/application.cpp @@ -1,15 +1,29 @@ #include #include "editor_world.hpp" +#include +#include +/** + * This represents our editor's application + * + * TODO: Add a preload API to preload the application. For providing user + * preferences, project settings, or other configuration settings that are + * projects-related + */ class editor_application : public atlas::application { public: editor_application(const atlas::application_settings& p_settings) : application(p_settings) { - m_world = atlas::create_ref("Editor World"); + std::pmr::monotonic_buffer_resource resource{ 4096 }; + m_allocator.construct(&resource); + + m_world = + atlas::create_strong_ref(m_allocator, "Editor World"); } private: - atlas::ref m_world; + std::pmr::polymorphic_allocator m_allocator; + atlas::optional_ref m_world; }; namespace atlas { diff --git a/editor/editor_world.cpp b/editor/editor_world.cpp index 2a96082f..85f6361c 100644 --- a/editor/editor_world.cpp +++ b/editor/editor_world.cpp @@ -1,6 +1,7 @@ #include "editor_world.hpp" #include #include +#include "level_scene.hpp" editor_world::editor_world() { console_log_fatal("Instantiate Default editor_world!"); @@ -15,6 +16,6 @@ editor_world::editor_world(const std::string& p_tag) { m_bus.create_listener(); m_bus.create_listener(); - m_first_scene = atlas::create_ref("LevelScene", m_bus); - m_main_world->add_scene(m_first_scene); + atlas::ref first_scene = atlas::create_ref("LevelScene", m_bus); + m_main_world->add_scene(first_scene); } \ No newline at end of file diff --git a/editor/editor_world.hpp b/editor/editor_world.hpp index 94ff24ea..4426dbc7 100644 --- a/editor/editor_world.hpp +++ b/editor/editor_world.hpp @@ -1,5 +1,4 @@ #pragma once -#include "level_scene.hpp" #include #include @@ -10,7 +9,6 @@ class editor_world { private: atlas::ref m_main_world; - atlas::ref m_first_scene; atlas::event::event_bus m_bus; }; \ No newline at end of file From 6bf0b572733fedd515b6221802cc8220fca5cf51 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sat, 6 Dec 2025 01:08:47 -0800 Subject: [PATCH 24/42] Changed game object code in editor/level_scene.cpp --- editor/level_scene.cpp | 102 ++++++++++++++++++++--------------------- editor/level_scene.hpp | 14 +++--- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 2709b937..5dcea593 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -8,47 +8,47 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) : atlas::scene(p_name, p_bus) { - m_camera = entity("Editor Camera"); - m_camera->add>(); - m_camera->set({ + atlas::game_object camera = entity("Editor Camera"); + camera->add>(); + camera->set({ .position = { 3.50f, 4.90f, 36.40f }, .scale{ 1.f }, }); - m_camera->set({ + camera->set({ .plane = { 0.1f, 5000.f }, .is_active = true, .field_of_view = 45.f, }); - m_bob_object = entity("Bob"); - m_bob_object->add(); + atlas::game_object bob_object = entity("Bob"); + bob_object->add(); - m_viking_room = entity("Viking Room"); - m_viking_room->add(); - m_viking_room->set({ + atlas::game_object viking_room = entity("Viking Room"); + viking_room->add(); + viking_room->set({ .position = { -2.70f, 2.70, -8.30f }, .rotation = { 2.30f, 95.90f, 91.80f }, .scale{ 1.f }, }); - m_viking_room->set({ + viking_room->set({ .radius = 1.0f, }); - m_viking_room->set({ + viking_room->set({ .friction = 15.f, .restitution = 0.3f, .body_movement_type = atlas::dynamic, }); - m_cube = entity("Aircraft"); + atlas::game_object cube = entity("Aircraft"); - m_cube->set({ + cube->set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, }); - m_cube->set({ + cube->set({ .color = { 1.f, 1.f, 1.f, 1.f }, // .model_path = "assets/models/E 45 Aircraft_obj.obj", .model_path = "assets/backpack/backpack.obj", @@ -57,58 +57,75 @@ level_scene::level_scene(const std::string& p_name, // .diffuse = "assets/models/E-45-steel detail_2_col.jpg", }); - m_robot_model = entity("Cube"); - m_robot_model->add(); - // m_robot_model->add(); - m_robot_model->set({ + atlas::game_object robot_model = entity("Cube"); + robot_model->add(); + // robot_model->add(); + robot_model->set({ .position = { -2.70, 3.50f, 4.10f }, .scale = { 1.f, 1.f, 1.f }, }); - m_robot_model->set( + robot_model->set( { .color = { 1.f, 1.f, 1.f, 1.f }, .model_path = "assets/models/cube.obj", .diffuse = "assets/models/container_diffuse.png", .specular = "assets/models/container_specular.png" }); - m_robot_model->set({ + robot_model->set({ .half_extent = { 1.f, 1.f, 1.f }, }); - m_robot_model->set({ + robot_model->set({ // .restitution = 1.f, .body_movement_type = atlas::dynamic, }); - m_platform = entity("Platform"); + atlas::game_object platform = entity("Platform"); - m_platform->set({ + platform->set({ .scale = { 15.f, 0.30f, 10.0f }, }); - m_platform->set({ + platform->set({ .model_path = "assets/models/cube.obj", .diffuse = "assets/models/wood.png", }); - m_platform->set({ + platform->set({ .body_movement_type = atlas::fixed, }); - m_platform->set({ + platform->set({ .half_extent = { 15.f, 0.30f, 10.0f }, }); - m_point_light = entity("Point Light 1"); - m_point_light->set({ + atlas::game_object point_light = entity("Point Light 1"); + point_light->set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, }); - m_point_light->set({ + point_light->set({ .model_path = "assets/models/cube.obj", .diffuse = "assets/models/wood.png", }); - m_point_light->add(); + point_light->add(); + + + // benchmark + + // auto start = std::chrono::high_resolution_clock::now(); + // TEMP Code + // [[maybe_unused]] atlas::game_object point_light_test = entity("Point Light 1"); + // auto end = std::chrono::high_resolution_clock::now(); + // auto duration = (end - start); + + // auto seconds = std::chrono::duration_cast(duration).count(); + // auto nanoseconds = std::chrono::duration_cast(duration).count(); + // auto microseconds = std::chrono::duration_cast(duration).count(); + + // console_log_fatal("Seconds = {:.1f}", static_cast(seconds)); + // console_log_fatal("Nanoseconds = {:.1f}", static_cast(nanoseconds)); + // console_log_fatal("Microseconds = {:.1f}", static_cast(microseconds)); // for(size_t i = 0; i < 26; i++) { - // auto obj = create(std::format("Object #{}", i)); + // auto obj = entity(std::format("Object #{}", i)); // obj->set({ // .restitution = 1.25f, // .body_movement_type = atlas::dynamic, @@ -130,7 +147,6 @@ level_scene::level_scene(const std::string& p_name, // .model_path = "assets/models/Ball OBJ.obj", // .diffuse = "assets/models/clear.png", // }); - // m_many_objects.emplace_back(obj); // } atlas::game_object gerald = entity("Gerald"); @@ -574,24 +590,6 @@ level_scene::start() { console_log_error("Could not load yaml file LevelScene!!!"); } - // testing the flip parameter inside atlas::mesh_source - m_viking_room->set({ - .flip = true, - .color = { 1.f, 1.f, 1.f, 1.f }, - .model_path = "assets/models/viking_room.obj", - .diffuse = "assets/models/viking_room.png", - // .model_path = "assets/models/Ball OBJ.obj", - // .diffuse = "assets/models/clear.png", - }); - - // TODO: Make this contain an atlas::directional_light - // If the scene opject dooes not have a atlas::directional_light, then we - // set the default values to 1.0f m_robot_model sets the cube.obj 3d model - // and loads it - m_robot_model->set({ - .shininess = 64.f, - }); - // Initiating physics system atlas::physics::jolt_settings settings = {}; flecs::world registry = *this; @@ -672,8 +670,10 @@ level_scene::physics_update() { runtime_start(); } + atlas::game_object viking_room = entity("Viking Room").value(); + atlas::physics_body* sphere_body = - m_viking_room->get_mut(); + viking_room->get_mut(); // U = +up // J = -up // H = +left diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index 15d781f2..ce429366 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -48,13 +48,13 @@ class level_scene final : public atlas::scene { atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - atlas::game_object m_viking_room; - atlas::game_object m_cube; - atlas::game_object m_robot_model; - atlas::game_object m_platform; - atlas::game_object m_camera; - atlas::game_object m_point_light; - atlas::game_object m_bob_object; + // atlas::game_object m_viking_room; + // atlas::game_object m_cube; + // atlas::game_object m_robot_model; + // atlas::game_object m_platform; + // atlas::game_object m_camera; + // atlas::game_object m_point_light; + // atlas::game_object m_bob_object; atlas::game_object m_current_entity; float m_movement_speed = 10.f; // std::vector> m_many_objects; From a9ce5dd3d06646a2b7275a2dbd514932ae5195d4 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sat, 6 Dec 2025 23:40:38 -0800 Subject: [PATCH 25/42] Added some testing experimentation code to the editor's UI --- editor/level_scene.cpp | 22 +++++++++++++++++----- editor/level_scene.hpp | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 5dcea593..47a0af04 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) @@ -299,11 +301,21 @@ level_scene::on_ui_update() { catch (const atlas::ui::menu_bar_exception& e) { } - // specify the label and the state to execute when this specific widget has - // been triggered - m_editor_menu.add_child("Exit", []() { - glfwSetWindowShouldClose(atlas::application::get_window(), true); - }); + if(ImGui::BeginMenu("File")) { + if(ImGui::MenuItem("Save")) { + // m_deserializer_test.save("LevelScene"); + } + + ImGui::Separator(); + + if(ImGui::MenuItem("Exit")) { + glfwSetWindowShouldClose(atlas::application::get_window(), true); + } + + ImGui::EndMenu(); + } + + m_editor_menu.end(); if (ImGui::Begin("Viewport")) { diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index ce429366..a3d6f486 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -44,7 +44,7 @@ class level_scene final : public atlas::scene { void collision_persisted(atlas::event::collision_persisted& p_event); private: - bool m_blink = false; + // bool m_blink = false; atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; From cf5568a148d871e549178b6c0c6eeefcaeaf545d Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 00:00:50 -0800 Subject: [PATCH 26/42] Reverted editor_world to not being wrapped around strong_ptr as its not needed --- editor/application.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/editor/application.cpp b/editor/application.cpp index 4bd55bb8..318ec5a8 100644 --- a/editor/application.cpp +++ b/editor/application.cpp @@ -14,16 +14,15 @@ class editor_application : public atlas::application { public: editor_application(const atlas::application_settings& p_settings) : application(p_settings) { - std::pmr::monotonic_buffer_resource resource{ 4096 }; - m_allocator.construct(&resource); + // std::pmr::monotonic_buffer_resource resource{ 4096 }; + // m_allocator.construct(&resource); - m_world = - atlas::create_strong_ref(m_allocator, "Editor World"); + m_world = editor_world("Editor World"); } private: std::pmr::polymorphic_allocator m_allocator; - atlas::optional_ref m_world; + editor_world m_world; }; namespace atlas { From b3e2920541aed146a4249cb18577ad2406484f7b Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 00:18:36 -0800 Subject: [PATCH 27/42] Formatted code using clang-format --- atlas/core/scene/exceptions.hpp | 5 ++-- atlas/core/scene/world.hpp | 2 +- atlas/core/ui/widgets.hpp | 2 +- editor/editor_world.cpp | 3 +- editor/level_scene.cpp | 30 +++++++++++--------- src/atlas/core/application.cpp | 3 +- src/atlas/core/ui/widgets.cpp | 12 +++++--- src/atlas/drivers/vulkan-cpp/vk_renderer.cpp | 6 ++-- 8 files changed, 34 insertions(+), 29 deletions(-) diff --git a/atlas/core/scene/exceptions.hpp b/atlas/core/scene/exceptions.hpp index b48b0f48..80cb4ffa 100644 --- a/atlas/core/scene/exceptions.hpp +++ b/atlas/core/scene/exceptions.hpp @@ -3,13 +3,14 @@ namespace atlas { struct exception_block { - const char* data=nullptr; + const char* data = nullptr; }; class invalid_access_exception : public std::exception { public: invalid_access_exception() = default; - invalid_access_exception(const char* p_data) : m_block(p_data) {} + invalid_access_exception(const char* p_data) + : m_block(p_data) {} //! @return message given when this exception gets triggered [[nodiscard]] const char* what() const override { return m_block.data; } diff --git a/atlas/core/scene/world.hpp b/atlas/core/scene/world.hpp index 436c6ff0..f8fd96fb 100644 --- a/atlas/core/scene/world.hpp +++ b/atlas/core/scene/world.hpp @@ -33,7 +33,7 @@ namespace atlas { * with it */ world(const std::string& p_name); - + virtual ~world() = default; //! @return the name of world diff --git a/atlas/core/ui/widgets.hpp b/atlas/core/ui/widgets.hpp index 3c5d4d2b..3043670c 100644 --- a/atlas/core/ui/widgets.hpp +++ b/atlas/core/ui/widgets.hpp @@ -65,7 +65,7 @@ namespace atlas::ui { /** * @brief UI rendering input text - * + * * * @param p_dst is the destination string to be changed * @param p_src is the original string that was previously given diff --git a/editor/editor_world.cpp b/editor/editor_world.cpp index 85f6361c..b0b070ef 100644 --- a/editor/editor_world.cpp +++ b/editor/editor_world.cpp @@ -16,6 +16,7 @@ editor_world::editor_world(const std::string& p_tag) { m_bus.create_listener(); m_bus.create_listener(); - atlas::ref first_scene = atlas::create_ref("LevelScene", m_bus); + atlas::ref first_scene = + atlas::create_ref("LevelScene", m_bus); m_main_world->add_scene(first_scene); } \ No newline at end of file diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 47a0af04..d3cc2e5b 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -109,22 +109,25 @@ level_scene::level_scene(const std::string& p_name, }); point_light->add(); - // benchmark // auto start = std::chrono::high_resolution_clock::now(); // TEMP Code - // [[maybe_unused]] atlas::game_object point_light_test = entity("Point Light 1"); - // auto end = std::chrono::high_resolution_clock::now(); - // auto duration = (end - start); + // [[maybe_unused]] atlas::game_object point_light_test = entity("Point + // Light 1"); auto end = std::chrono::high_resolution_clock::now(); auto + // duration = (end - start); - // auto seconds = std::chrono::duration_cast(duration).count(); - // auto nanoseconds = std::chrono::duration_cast(duration).count(); - // auto microseconds = std::chrono::duration_cast(duration).count(); + // auto seconds = + // std::chrono::duration_cast(duration).count(); auto + // nanoseconds = + // std::chrono::duration_cast(duration).count(); + // auto microseconds = + // std::chrono::duration_cast(duration).count(); // console_log_fatal("Seconds = {:.1f}", static_cast(seconds)); - // console_log_fatal("Nanoseconds = {:.1f}", static_cast(nanoseconds)); - // console_log_fatal("Microseconds = {:.1f}", static_cast(microseconds)); + // console_log_fatal("Nanoseconds = {:.1f}", + // static_cast(nanoseconds)); console_log_fatal("Microseconds = + // {:.1f}", static_cast(microseconds)); // for(size_t i = 0; i < 26; i++) { // auto obj = entity(std::format("Object #{}", i)); @@ -301,21 +304,20 @@ level_scene::on_ui_update() { catch (const atlas::ui::menu_bar_exception& e) { } - if(ImGui::BeginMenu("File")) { - if(ImGui::MenuItem("Save")) { + if (ImGui::BeginMenu("File")) { + if (ImGui::MenuItem("Save")) { // m_deserializer_test.save("LevelScene"); } ImGui::Separator(); - if(ImGui::MenuItem("Exit")) { + if (ImGui::MenuItem("Exit")) { glfwSetWindowShouldClose(atlas::application::get_window(), true); } - + ImGui::EndMenu(); } - m_editor_menu.end(); if (ImGui::Begin("Viewport")) { diff --git a/src/atlas/core/application.cpp b/src/atlas/core/application.cpp index 3026b7c2..a5161eac 100644 --- a/src/atlas/core/application.cpp +++ b/src/atlas/core/application.cpp @@ -81,8 +81,7 @@ namespace atlas { m_renderer->preload( m_window->current_swapchain().swapchain_renderpass()); - ref current_world = - system_registry::get_world("Editor World"); + ref current_world = system_registry::get_world("Editor World"); ref current_scene = current_world->get_scene("LevelScene"); flecs::world current_world_scope = *current_scene; diff --git a/src/atlas/core/ui/widgets.cpp b/src/atlas/core/ui/widgets.cpp index 2fa9e0ba..9a134699 100644 --- a/src/atlas/core/ui/widgets.cpp +++ b/src/atlas/core/ui/widgets.cpp @@ -226,18 +226,22 @@ namespace atlas::ui { std::string input_buffer = p_src; ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue; - input_buffer.resize(255); // resize to allocate for 255 in the char array since this should be long enough + input_buffer.resize(255); // resize to allocate for 255 in the char + // array since this should be long enough - if(ImGui::InputText("##Name", (char*)input_buffer.c_str(), input_buffer.size() + 1, flags)) { + if (ImGui::InputText("##Name", + (char*)input_buffer.c_str(), + input_buffer.size() + 1, + flags)) { p_dst = input_buffer; } - if(p_dst.empty()) { + if (p_dst.empty()) { p_dst = p_src; return; } - if(p_dst == p_src) { + if (p_dst == p_src) { p_dst = p_src; return; } diff --git a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp index 89a21d62..09a3b1b1 100644 --- a/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp +++ b/src/atlas/drivers/vulkan-cpp/vk_renderer.cpp @@ -209,8 +209,7 @@ namespace atlas::vk { void vk_renderer::preload_assets(const VkRenderPass& p_renderpass) { m_final_renderpass = p_renderpass; // set 1 -- material uniforms - ref current_world = - system_registry::get_world("Editor World"); + ref current_world = system_registry::get_world("Editor World"); ref current_scene = current_world->get_scene("LevelScene"); flecs::query<> caching = @@ -479,8 +478,7 @@ namespace atlas::vk { // m_global_uniforms.update(bytes_data.data()); m_global_uniforms.update(&global_frame_ubo); - ref current_world = - system_registry::get_world("Editor World"); + ref current_world = system_registry::get_world("Editor World"); ref current_scene = current_world->get_scene("LevelScene"); // query all entities that have a point light From b1b43687bdc81c6d8b6e42619b11b29669026b58 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 00:37:37 -0800 Subject: [PATCH 28/42] Added noexcept to invalid_access_exception to be synced with definition of the std::exception as its base class --- atlas/core/scene/exceptions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas/core/scene/exceptions.hpp b/atlas/core/scene/exceptions.hpp index 80cb4ffa..37389181 100644 --- a/atlas/core/scene/exceptions.hpp +++ b/atlas/core/scene/exceptions.hpp @@ -13,7 +13,7 @@ namespace atlas { : m_block(p_data) {} //! @return message given when this exception gets triggered - [[nodiscard]] const char* what() const override { return m_block.data; } + [[nodiscard]] const char* what() const noexcept override { return m_block.data; } private: exception_block m_block; From 839bc3830e912a27be209ce0788d6df4d023b0c1 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 00:38:06 -0800 Subject: [PATCH 29/42] Formatted code using clang-format --- atlas/core/scene/exceptions.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/atlas/core/scene/exceptions.hpp b/atlas/core/scene/exceptions.hpp index 37389181..bbacc037 100644 --- a/atlas/core/scene/exceptions.hpp +++ b/atlas/core/scene/exceptions.hpp @@ -13,7 +13,9 @@ namespace atlas { : m_block(p_data) {} //! @return message given when this exception gets triggered - [[nodiscard]] const char* what() const noexcept override { return m_block.data; } + [[nodiscard]] const char* what() const noexcept override { + return m_block.data; + } private: exception_block m_block; From 28933f2c06a75f5ae6f9d017b69cd2eb6680ac7b Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 01:11:23 -0800 Subject: [PATCH 30/42] Removed unecessary includes from level_scene.cpp --- editor/level_scene.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index d3cc2e5b..4ca265a0 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -4,8 +4,6 @@ #include #include #include -#include -#include level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) From c50ad00396ec70f21517ca99ad3e773e09b794f5 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 15:39:39 -0800 Subject: [PATCH 31/42] Removed commented code that are no longer needed from editor/level_scene.cpp --- editor/level_scene.hpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index a3d6f486..e8bbda45 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -44,23 +44,14 @@ class level_scene final : public atlas::scene { void collision_persisted(atlas::event::collision_persisted& p_event); private: - // bool m_blink = false; atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - // atlas::game_object m_viking_room; - // atlas::game_object m_cube; - // atlas::game_object m_robot_model; - // atlas::game_object m_platform; - // atlas::game_object m_camera; - // atlas::game_object m_point_light; - // atlas::game_object m_bob_object; atlas::game_object m_current_entity; float m_movement_speed = 10.f; - // std::vector> m_many_objects; // Setting physics system - // TODO -- when refactoring this would be at atlas::world layer + // TODO -- when refactoring this would be at atlas::world level atlas::physics::physics_engine m_physics_engine; bool m_physics_runtime = false; From fcda87c4fe377a3f21561f7f01caaf6eb1a34a29 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 22:52:10 -0800 Subject: [PATCH 32/42] Make editor_world a strong_ptr as a temp fix for early construction that will be fixed when adding in the level streamer --- editor/application.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/editor/application.cpp b/editor/application.cpp index 318ec5a8..1e0cbd41 100644 --- a/editor/application.cpp +++ b/editor/application.cpp @@ -14,15 +14,16 @@ class editor_application : public atlas::application { public: editor_application(const atlas::application_settings& p_settings) : application(p_settings) { - // std::pmr::monotonic_buffer_resource resource{ 4096 }; - // m_allocator.construct(&resource); + std::pmr::monotonic_buffer_resource resource{ 4096 }; + m_allocator.construct(&resource); - m_world = editor_world("Editor World"); + // TODO -- this is going to be changed with the use of the level streamer API + m_world = atlas::create_strong_ref(m_allocator, "Editor World"); } private: std::pmr::polymorphic_allocator m_allocator; - editor_world m_world; + atlas::optional_ref m_world; }; namespace atlas { From fd9ac1c46abfde7b31d169bc4afba3d1214b1265 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 22:53:00 -0800 Subject: [PATCH 33/42] Formatted code using clang-format --- editor/application.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/editor/application.cpp b/editor/application.cpp index 1e0cbd41..6c9ccc3e 100644 --- a/editor/application.cpp +++ b/editor/application.cpp @@ -17,8 +17,10 @@ class editor_application : public atlas::application { std::pmr::monotonic_buffer_resource resource{ 4096 }; m_allocator.construct(&resource); - // TODO -- this is going to be changed with the use of the level streamer API - m_world = atlas::create_strong_ref(m_allocator, "Editor World"); + // TODO -- this is going to be changed with the use of the level + // streamer API + m_world = + atlas::create_strong_ref(m_allocator, "Editor World"); } private: From bd385973467b500b438b25e4d6d311ad18dd96e2 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 23:12:59 -0800 Subject: [PATCH 34/42] Updated some documentation comments to atlas::scene --- atlas/core/scene/scene.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index e92f7158..0abec035 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -33,20 +33,19 @@ namespace atlas { virtual ~scene() = default; /** - * @brief create a new entity (game object) + * @brief Retrieves if an entity already exists within the registry, + * create new entity otherwise * - * If entity with the specified name exists, retrieve that specific - * entity. If entity does not exist, create that entity - * - * @param p_name is the name of the entity + * @param p_name is a string to set the name of the entity */ game_object entity(const std::string& p_name); /** - * @brief create a new entity or retrieve already-existent entity by ID + * @brief Retrieves if an entity already exists within the registry, + * create new entity otherwise * - * @param p_entity_id is the entity ID to retrieve if it exists, if not - * create it. + * @param p_entity_id is the ID to retrieve an entity if it exists, + * otherwise returns a new entity. */ game_object entity(uint64_t p_entity_id); @@ -61,6 +60,7 @@ namespace atlas { * callback belongs to * @param p_callback is the callback that contains an arbitrary task * that gets invoked when incoming updates occur from the publisher + * */ template void subscribe(UObject* p_instance, const UCallback& p_callback) { From c78844d1e200d44c5f939100aa745ee28f1dc084 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Sun, 7 Dec 2025 23:16:01 -0800 Subject: [PATCH 35/42] Code formatted using clang-format --- atlas/core/scene/scene.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index 0abec035..724158ca 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -60,7 +60,7 @@ namespace atlas { * callback belongs to * @param p_callback is the callback that contains an arbitrary task * that gets invoked when incoming updates occur from the publisher - * + * */ template void subscribe(UObject* p_instance, const UCallback& p_callback) { From 01c8f565aa8c242a650bdaff0302e1260a109efd Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Mon, 8 Dec 2025 00:55:50 -0800 Subject: [PATCH 36/42] Updated documentation for atlas::game_object --- atlas/core/scene/scene_object.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/scene_object.hpp index 24cfb3f3..78102dd2 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/scene_object.hpp @@ -77,8 +77,8 @@ namespace atlas { /** * @brief Alias to std::optional * - * Restrict from enabling creating empty game objects that is not valid to - * access its members to perform operations with + * This alias serves as a representation of game objects users can create + * and manage components with */ using game_object = std::optional; }; \ No newline at end of file From 4d1fecbd2c30870529f5619abb489daaead78fc7 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Tue, 9 Dec 2025 08:54:52 -0800 Subject: [PATCH 37/42] Set flip flag to true to flip texture coordinates --- editor/level_scene.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 4ca265a0..8547e3fc 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -602,6 +602,10 @@ level_scene::start() { console_log_error("Could not load yaml file LevelScene!!!"); } + atlas::game_object viking_room = entity("Viking Room"); + atlas::mesh_source* src = viking_room->get_mut(); + src->flip = true; + // Initiating physics system atlas::physics::jolt_settings settings = {}; flecs::world registry = *this; From 018c9a8324fd7b4e1c08720c0631ebccd82a3a1a Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Mon, 15 Dec 2025 11:16:25 -0800 Subject: [PATCH 38/42] Renamed atlas::scene_object to atlas::game_object --- .../{scene_object.hpp => game_object.hpp} | 16 ++--- atlas/core/scene/scene.hpp | 10 +-- editor/level_scene.cpp | 69 ++++++++++--------- editor/level_scene.hpp | 3 +- src/CMakeLists.txt | 2 +- .../{scene_object.cpp => game_object.cpp} | 10 +-- src/atlas/core/scene/scene.cpp | 12 ++-- 7 files changed, 62 insertions(+), 60 deletions(-) rename atlas/core/scene/{scene_object.hpp => game_object.hpp} (82%) rename src/atlas/core/scene/{scene_object.cpp => game_object.cpp} (54%) diff --git a/atlas/core/scene/scene_object.hpp b/atlas/core/scene/game_object.hpp similarity index 82% rename from atlas/core/scene/scene_object.hpp rename to atlas/core/scene/game_object.hpp index 78102dd2..972a33b0 100644 --- a/atlas/core/scene/scene_object.hpp +++ b/atlas/core/scene/game_object.hpp @@ -12,17 +12,17 @@ namespace atlas { * of the raw flecs API's that can still be used by other flecs API's * without completely interacting touching raw flecs API */ - class scene_object : public flecs::entity { + class game_object : public flecs::entity { public: //! @brief Should not construct a scene object not created through //! flecs::world - scene_object() = delete; + game_object() = delete; - scene_object(flecs::world_t* p_registry, flecs::entity_t p_id); + game_object(flecs::world_t* p_registry, flecs::entity_t p_id); - scene_object(const flecs::entity& p_base); + game_object(const flecs::entity& p_base); - explicit scene_object(flecs::entity& p_base); + explicit game_object(flecs::entity& p_base); /** * @brief sets the entity to be a parent of the specified entity @@ -45,7 +45,7 @@ namespace atlas { * ``` * */ - void child_of(const std::optional& p_parent); + void child_of(const std::optional& p_parent); /** * @brief iterates through all children entities if the given entity is @@ -75,10 +75,10 @@ namespace atlas { }; /** - * @brief Alias to std::optional + * @brief Alias to std::optional * * This alias serves as a representation of game objects users can create * and manage components with */ - using game_object = std::optional; + using game_object_optional = std::optional; }; \ No newline at end of file diff --git a/atlas/core/scene/scene.hpp b/atlas/core/scene/scene.hpp index 724158ca..68f67083 100644 --- a/atlas/core/scene/scene.hpp +++ b/atlas/core/scene/scene.hpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include namespace atlas { @@ -38,7 +38,7 @@ namespace atlas { * * @param p_name is a string to set the name of the entity */ - game_object entity(const std::string& p_name); + game_object entity(std::string_view p_name); /** * @brief Retrieves if an entity already exists within the registry, @@ -47,7 +47,7 @@ namespace atlas { * @param p_entity_id is the ID to retrieve an entity if it exists, * otherwise returns a new entity. */ - game_object entity(uint64_t p_entity_id); + game_object entity(uint64_t p_id); /** * @brief subscribes an event to the event::bus to get invoked when @@ -109,9 +109,9 @@ namespace atlas { * atlas::scene scene("New Scene"); * * // creating obj1 (parent) and obj2 (child) - * atlas::scene_object obj1 = scene.create("Parent"); + * atlas::game_object obj1 = scene.create("Parent"); * - * atlas::scene_object obj2 = scene.create("Chlid"); + * atlas::game_object obj2 = scene.create("Chlid"); * * // obj2 is the child of obj1 * // As obj1 is a parent node diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index 8547e3fc..f39cf7c3 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -8,34 +8,36 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) : atlas::scene(p_name, p_bus) { - atlas::game_object camera = entity("Editor Camera"); - camera->add>(); - camera->set({ + auto editor_camera = entity("Editor Camera"); + editor_camera.add>(); + editor_camera.set({ .position = { 3.50f, 4.90f, 36.40f }, .scale{ 1.f }, }); - camera->set({ + editor_camera.set({ .plane = { 0.1f, 5000.f }, .is_active = true, .field_of_view = 45.f, }); + atlas::game_object bob_object = entity("Bob"); - bob_object->add(); + + bob_object.add(); atlas::game_object viking_room = entity("Viking Room"); - viking_room->add(); - viking_room->set({ + viking_room.add(); + viking_room.set({ .position = { -2.70f, 2.70, -8.30f }, .rotation = { 2.30f, 95.90f, 91.80f }, .scale{ 1.f }, }); - viking_room->set({ + viking_room.set({ .radius = 1.0f, }); - viking_room->set({ + viking_room.set({ .friction = 15.f, .restitution = 0.3f, .body_movement_type = atlas::dynamic, @@ -43,12 +45,12 @@ level_scene::level_scene(const std::string& p_name, atlas::game_object cube = entity("Aircraft"); - cube->set({ + cube.set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, }); - cube->set({ + cube.set({ .color = { 1.f, 1.f, 1.f, 1.f }, // .model_path = "assets/models/E 45 Aircraft_obj.obj", .model_path = "assets/backpack/backpack.obj", @@ -58,54 +60,56 @@ level_scene::level_scene(const std::string& p_name, }); atlas::game_object robot_model = entity("Cube"); - robot_model->add(); - // robot_model->add(); - robot_model->set({ + robot_model.add(); + // robot_model.add(); + robot_model.set({ .position = { -2.70, 3.50f, 4.10f }, .scale = { 1.f, 1.f, 1.f }, }); - robot_model->set( + robot_model.set( { .color = { 1.f, 1.f, 1.f, 1.f }, .model_path = "assets/models/cube.obj", .diffuse = "assets/models/container_diffuse.png", .specular = "assets/models/container_specular.png" }); - robot_model->set({ + robot_model.set({ .half_extent = { 1.f, 1.f, 1.f }, }); - robot_model->set({ + robot_model.set({ // .restitution = 1.f, .body_movement_type = atlas::dynamic, }); atlas::game_object platform = entity("Platform"); - platform->set({ + platform.set({ .scale = { 15.f, 0.30f, 10.0f }, }); - platform->set({ + platform.set({ .model_path = "assets/models/cube.obj", .diffuse = "assets/models/wood.png", }); - platform->set({ + platform.set({ .body_movement_type = atlas::fixed, }); - platform->set({ + platform.set({ .half_extent = { 15.f, 0.30f, 10.0f }, }); atlas::game_object point_light = entity("Point Light 1"); - point_light->set({ + point_light.set({ .position = { 0.f, 2.10f, -7.30f }, .scale = { 0.9f, 0.9f, 0.9f }, }); - point_light->set({ + point_light.set({ .model_path = "assets/models/cube.obj", .diffuse = "assets/models/wood.png", }); - point_light->add(); + point_light.add(); + + // benchmark @@ -153,7 +157,7 @@ level_scene::level_scene(const std::string& p_name, // } atlas::game_object gerald = entity("Gerald"); - gerald->add(); + gerald.add(); // TODO: Move this outside of level_scene m_deserializer_test = atlas::serializer(); @@ -173,8 +177,8 @@ level_scene::collision_enter(atlas::event::collision_enter& p_event) { atlas::game_object e1 = entity(p_event.entity1); atlas::game_object e2 = entity(p_event.entity2); - console_log_warn("Entity1 = {}", e1->name().c_str()); - console_log_warn("Entity2 = {}", e2->name().c_str()); + console_log_warn("Entity1 = {}", e1.name().c_str()); + console_log_warn("Entity2 = {}", e2.name().c_str()); } void @@ -183,8 +187,8 @@ level_scene::collision_persisted(atlas::event::collision_persisted& p_event) { atlas::game_object e1 = entity(p_event.entity1); atlas::game_object e2 = entity(p_event.entity2); - console_log_warn("Entity1 = {}", e1->name().c_str()); - console_log_warn("Entity2 = {}", e2->name().c_str()); + console_log_warn("Entity1 = {}", e1.name().c_str()); + console_log_warn("Entity2 = {}", e2.name().c_str()); } void @@ -603,7 +607,7 @@ level_scene::start() { } atlas::game_object viking_room = entity("Viking Room"); - atlas::mesh_source* src = viking_room->get_mut(); + atlas::mesh_source* src = viking_room.get_mut(); src->flip = true; // Initiating physics system @@ -686,10 +690,9 @@ level_scene::physics_update() { runtime_start(); } - atlas::game_object viking_room = entity("Viking Room").value(); + auto viking_room = entity("Viking Room"); - atlas::physics_body* sphere_body = - viking_room->get_mut(); + atlas::physics_body* sphere_body = viking_room.get_mut(); // U = +up // J = -up // H = +left diff --git a/editor/level_scene.hpp b/editor/level_scene.hpp index e8bbda45..5891afec 100644 --- a/editor/level_scene.hpp +++ b/editor/level_scene.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include #include #include @@ -47,7 +46,7 @@ class level_scene final : public atlas::scene { atlas::serializer m_deserializer_test; flecs::entity m_selected_entity; - atlas::game_object m_current_entity; + atlas::game_object_optional m_current_entity; float m_movement_speed = 10.f; // Setting physics system diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d711978..96322730 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ set( # System-related stuff ${SRC_DIR}/core/scene/scene.cpp - ${SRC_DIR}/core/scene/scene_object.cpp + ${SRC_DIR}/core/scene/game_object.cpp ${SRC_DIR}/core/system/registry.cpp # math sources diff --git a/src/atlas/core/scene/scene_object.cpp b/src/atlas/core/scene/game_object.cpp similarity index 54% rename from src/atlas/core/scene/scene_object.cpp rename to src/atlas/core/scene/game_object.cpp index 30cef70c..397f2072 100644 --- a/src/atlas/core/scene/scene_object.cpp +++ b/src/atlas/core/scene/game_object.cpp @@ -1,25 +1,25 @@ #include -#include +#include #include #include namespace atlas { - scene_object::scene_object(flecs::world_t* p_registry, flecs::entity_t p_id) + game_object::game_object(flecs::world_t* p_registry, flecs::entity_t p_id) : flecs::entity(p_registry, p_id) { add(); } - scene_object::scene_object(const flecs::entity& p_base) + game_object::game_object(const flecs::entity& p_base) : flecs::entity(p_base) { add(); } - scene_object::scene_object(flecs::entity& p_base) + game_object::game_object(flecs::entity& p_base) : flecs::entity(p_base) { add(); } - void scene_object::child_of(const std::optional& p_parent) { + void game_object::child_of(const std::optional& p_parent) { add(flecs::ChildOf, p_parent.value()); } }; \ No newline at end of file diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index ecc3a45d..ad1ed9e8 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -5,17 +5,17 @@ namespace atlas { : m_name(p_name) , m_bus(&p_bus) {} - game_object scene::entity(const std::string& p_name) { - return scene_object(m_registry.entity(p_name.c_str())); + game_object scene::entity(std::string_view p_name) { + return game_object(m_registry.entity(p_name.data())); } - - game_object scene::entity(uint64_t p_entity_id) { - return scene_object(m_registry.entity(p_entity_id)); + + game_object scene::entity(uint64_t p_id) { + return game_object(m_registry.entity(p_id)); } uint32_t scene::children_count(const game_object& p_parent) { return query_builder() - .with(flecs::ChildOf, p_parent.value()) + .with(flecs::ChildOf, p_parent) .build() .count(); } From 77f3b910cdff8aa5e91b0a67b4b69ac3e9722929 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Mon, 15 Dec 2025 11:18:42 -0800 Subject: [PATCH 39/42] Formatted code using clang-format --- editor/level_scene.cpp | 9 ++++----- src/atlas/core/scene/scene.cpp | 7 ++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/editor/level_scene.cpp b/editor/level_scene.cpp index f39cf7c3..dacac959 100644 --- a/editor/level_scene.cpp +++ b/editor/level_scene.cpp @@ -9,7 +9,8 @@ level_scene::level_scene(const std::string& p_name, atlas::event::event_bus& p_bus) : atlas::scene(p_name, p_bus) { auto editor_camera = entity("Editor Camera"); - editor_camera.add>(); + editor_camera + .add>(); editor_camera.set({ .position = { 3.50f, 4.90f, 36.40f }, .scale{ 1.f }, @@ -20,7 +21,6 @@ level_scene::level_scene(const std::string& p_name, .field_of_view = 45.f, }); - atlas::game_object bob_object = entity("Bob"); bob_object.add(); @@ -109,8 +109,6 @@ level_scene::level_scene(const std::string& p_name, }); point_light.add(); - - // benchmark // auto start = std::chrono::high_resolution_clock::now(); @@ -692,7 +690,8 @@ level_scene::physics_update() { auto viking_room = entity("Viking Room"); - atlas::physics_body* sphere_body = viking_room.get_mut(); + atlas::physics_body* sphere_body = + viking_room.get_mut(); // U = +up // J = -up // H = +left diff --git a/src/atlas/core/scene/scene.cpp b/src/atlas/core/scene/scene.cpp index ad1ed9e8..6cb57848 100644 --- a/src/atlas/core/scene/scene.cpp +++ b/src/atlas/core/scene/scene.cpp @@ -8,16 +8,13 @@ namespace atlas { game_object scene::entity(std::string_view p_name) { return game_object(m_registry.entity(p_name.data())); } - + game_object scene::entity(uint64_t p_id) { return game_object(m_registry.entity(p_id)); } uint32_t scene::children_count(const game_object& p_parent) { - return query_builder() - .with(flecs::ChildOf, p_parent) - .build() - .count(); + return query_builder().with(flecs::ChildOf, p_parent).build().count(); } }; \ No newline at end of file From 362cd1824ff5c118a0340f10f0770f39741df230 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Mon, 15 Dec 2025 11:25:43 -0800 Subject: [PATCH 40/42] Updated conanfile version to 0.f due to core API changes --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 43acfe52..cdeaeada 100644 --- a/conanfile.py +++ b/conanfile.py @@ -6,7 +6,7 @@ class AtlasRecipe(ConanFile): name = "atlas" - version = "0.3" + version = "0.4" package_type = "library" license = "Apache-2.0" homepage = "https://github.com/engine3d-dev/TheAtlasEngine" From 0c33d5e855ab016646635d4bf11fc5c73a42fd43 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Mon, 15 Dec 2025 13:50:30 -0800 Subject: [PATCH 41/42] Updated test cases to conform to new game object API's --- tests/entity_component_system.test.cpp | 16 ++++++++-------- tests/jolt_type_conversion.test.cpp | 1 - tests/scene.test.cpp | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/entity_component_system.test.cpp b/tests/entity_component_system.test.cpp index ac4d8d54..4e5b6ec5 100644 --- a/tests/entity_component_system.test.cpp +++ b/tests/entity_component_system.test.cpp @@ -91,20 +91,20 @@ namespace atlas { // expect(entity.is_alive()); - entity->add(); - expect(entity->has()); + entity.add(); + expect(entity.has()); }; "create_entity::get"_test = [&test_scene]() { atlas::game_object entity = test_scene.entity("Mock Entity 2"); - entity->add(); + entity.add(); // flecs requires reading only operations are through the get API // to write or set new parameters you can use get_mut or // set(T&&); in this case, I use set in this test case - entity->set({ .tag = "New Entity" }); + entity.set({ .tag = "New Entity" }); const test_tag_component* get_tag = - entity->get(); + entity.get(); expect(get_tag->tag == "New Entity"); }; @@ -112,9 +112,9 @@ namespace atlas { atlas::game_object entity = test_scene.entity("New Entity"); mock_projectile projectile; projectile.on_update(); - entity->set(projectile); + entity.set(projectile); - expect(entity->has()); + expect(entity.has()); // test_transform transform; // transform.position = projectile.position(); @@ -125,7 +125,7 @@ namespace atlas { // expect(transform.position == projectile.position()); // expect(mock_velocity.position == - // entity.get()->position); + // entity.get().position); }; }; }; // namespace atlas diff --git a/tests/jolt_type_conversion.test.cpp b/tests/jolt_type_conversion.test.cpp index 350db5b9..76f52f79 100644 --- a/tests/jolt_type_conversion.test.cpp +++ b/tests/jolt_type_conversion.test.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/tests/scene.test.cpp b/tests/scene.test.cpp index 182829c2..32e567ec 100644 --- a/tests/scene.test.cpp +++ b/tests/scene.test.cpp @@ -10,8 +10,8 @@ boost::ut::suite<"::scene"> scene_test = []() { "create_object"_test = [&test_scene]() { atlas::game_object test_object = test_scene.entity("Entity 1"); - test_object->add(); + test_object.add(); - expect(test_object->has()); + expect(test_object.has()); }; }; From 5604dee84c2a953001f8a96fa51e1f36b9d2cba7 Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Mon, 15 Dec 2025 15:20:54 -0800 Subject: [PATCH 42/42] Removed tinygltf dependency from project cmake and conanfile --- CMakeLists.txt | 5 ----- conanfile.py | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 166f01a2..7d56cfc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,20 +39,15 @@ build_core_library( tests/scene.test.cpp tests/jolt_type_conversion.test.cpp tests/jolt_engine.test.cpp - # tests/object.test.cpp PACKAGES tinyobjloader - TinyGLTF - # shaderc # uncomment to use shaderc ${SHADERC_PACKAGE} watcher vulkan-cpp LINK_PACKAGES tinyobjloader::tinyobjloader - TinyGLTF::TinyGLTF - # shaderc::shaderc # uncomment to use shaderc ${SHADERC_LINK_PACKAGE} watcher::watcher vulkan-cpp::vulkan-cpp diff --git a/conanfile.py b/conanfile.py index cdeaeada..e3006948 100644 --- a/conanfile.py +++ b/conanfile.py @@ -33,7 +33,7 @@ def requirements(self): self.requires("imguidocking/2.0") self.requires("flecs/4.0.4") self.requires("glfw/3.4") - self.requires("spdlog/1.15.1") + self.requires("spdlog/1.16.0") self.requires("glm/1.0.1") self.requires("yaml-cpp/0.8.0") @@ -41,7 +41,6 @@ def requirements(self): self.requires("vulkan-headers/1.3.290.0") self.requires("vulkan-cpp/3.0") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("tinygltf/2.9.0") self.requires("stb/cci.20230920") self.requires("nfd/1.0")