diff --git a/docs/tasks/core.todo b/docs/tasks/core.todo index 2cadcfa..d54fb5a 100644 --- a/docs/tasks/core.todo +++ b/docs/tasks/core.todo @@ -59,15 +59,16 @@ Core: ☐ Provide Methods that give access to the C++ code ECS: - ☐ Research EnTT for the ECS (https://github.com/skypjack/entt/) - ☐ Research using ECS with a quadtree (regions may essentially be a quadtree) + ✔ Research EnTT for the ECS (https://github.com/skypjack/entt/) @done(22-06-01 14:01) + ✔ Research using ECS with a quadtree (regions may essentially be a quadtree) @done(22-06-01 14:01) ☐ Use 1 Entt registry with a component that stores the region ID (Index?) Enitity: - ☐ Single UUID - ☐ Functionality for adding/working with components (through EnTT) + ✔ Single UUID @done(22-06-01 14:01) + ✔ Functionality for adding/working with components (through EnTT) @done(22-06-01 14:01) Components: + ☐ Tag ☐ Transform ☐ SpriteRenderer ☐ Animation Controller @@ -78,12 +79,15 @@ Core: ☐ Box Collider (Box2D) World (Lunariums version of a "Scene"): - ☐ Track/manage loaded regions - ☐ Render loaded Regions + ☐ Implement the world without Regions first + + Implement Regions: + ☐ Track/manage active regions + ☐ Render active Regions Region: ☐ List of renderable images for each layer - ☐ List of game objects (by reference) in this Region + ☐ List of entities (by entt id) in this Region ☐ Implement image grid within regions [Regions could potentially be split into multiple images (an internal grid). To support larger region sizes without needing single images that are like 1048576x1048576 or some nonsense.] diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index 37b3faa..2d1b688 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -5,6 +5,7 @@ set(EDITOR_SRC "editor_helpers.cpp" "panel_manager.cpp" "project.cpp" +"component_guis.cpp" "panels/about.cpp" "panels/asset_browser.cpp" "panels/world_tree.cpp" diff --git a/src/run_modes/editor/component_guis.cpp b/src/run_modes/editor/component_guis.cpp new file mode 100644 index 0000000..9601e55 --- /dev/null +++ b/src/run_modes/editor/component_guis.cpp @@ -0,0 +1,27 @@ +/****************************************************************************** +* File - component_guis.cpp +* Author - Joey Pollack +* Date - 2022/06/01 (y/m/d) +* Mod Date - 2022/06/01 (y/m/d) +* Description - Functions to render component editing GUIs +******************************************************************************/ + +#include "component_guis.h" +#include +#include +#include + +namespace lunarium { namespace editor +{ + void CompGui::RenderTagComp(TagComponent& comp) + { + ImGui::Text("Tag:"); + ImGui::SameLine(); + ImGui::InputText("##Tag", comp.Info.data(), comp.Info.capacity()) + } + + void CompGui::RenderTransformComp(TransformComponent& comp) + { + + } +}} \ No newline at end of file diff --git a/src/run_modes/editor/component_guis.h b/src/run_modes/editor/component_guis.h new file mode 100644 index 0000000..30950ba --- /dev/null +++ b/src/run_modes/editor/component_guis.h @@ -0,0 +1,25 @@ +/****************************************************************************** +* File - component_guis.h +* Author - Joey Pollack +* Date - 2022/06/01 (y/m/d) +* Mod Date - 2022/06/01 (y/m/d) +* Description - Functions to render component editing GUIs +******************************************************************************/ + +#ifndef LUNARIUM_COMPONENT_GUIS_H_ +#define LUNARIUM_COMPONENT_GUIS_H_ + +#include + +namespace lunarium { namespace editor +{ + class CompGui + { + public: + static void RenderTagComp(TagComponent& comp); + static void RenderTransformComp(TransformComponent& comp); + }; +}} + + +#endif // LUNARIUM_COMPONENT_GUIS_H_ \ No newline at end of file diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index 018cfae..e6a5011 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -28,6 +28,11 @@ #include +// TEST STUFF +#include +#include +#include + using namespace lunarium::gui; // ERROR LOG MACRO @@ -47,7 +52,6 @@ namespace editor OpRes Editor::Initialize() { - LabelComponent test; LogCat = Logger::RegisterCategory("EDITOR"); // Initialize internal data @@ -69,6 +73,12 @@ namespace editor mPanelManager.AddPanel(new WorldView(), mPanels.WorldView).LogIfFailed(LogCat); mPanelManager.AddPanel(new PropertiesView(), mPanels.PropertiesView).LogIfFailed(LogCat); + // TEST ENTITY + mTestWorld = new lunarium::World; + mTestEntity = mTestWorld->CreateEntity(); + mTestWorld->GetEntity(mTestEntity)->AddComponent(); + ((PropertiesView*)mPanelManager.GetPanel(mPanels.PropertiesView))->SetSelection(mTestWorld->GetEntity(mTestEntity)); + return OpRes::OK(); } diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index 3a556df..f634f94 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -10,6 +10,7 @@ #define EDITOR_H_ #include +#include #include #include "project.h" @@ -21,7 +22,7 @@ namespace lunarium { - class FileBrowser; + class World; } namespace lunarium { namespace editor @@ -60,6 +61,7 @@ namespace lunarium { namespace editor private: // Data PanelManager mPanelManager; + lunarium::World* mTestWorld; Project mProject; // Tools @@ -85,6 +87,9 @@ namespace lunarium { namespace editor bool mDoOpenProject; bool mDoSaveProject; bool mDoSaveAs; + + // TEST DATA + LUUID mTestEntity; private: // HELPERS diff --git a/src/run_modes/editor/panels/properties_view.cpp b/src/run_modes/editor/panels/properties_view.cpp index 7f785f0..50eaad9 100644 --- a/src/run_modes/editor/panels/properties_view.cpp +++ b/src/run_modes/editor/panels/properties_view.cpp @@ -10,6 +10,9 @@ #include "properties_view.h" #include #include +#include +#include +#include namespace lunarium { namespace editor { @@ -30,9 +33,30 @@ namespace lunarium { namespace editor return false; } + if (mpSelectedEntity) + { + // TODO: iterate through components + if (mpSelectedEntity->HasComponent()) + { + CompGui::RenderTagComp(mpSelectedEntity->GetComponent()); + } + } + ImGui::End(); return true; } + void PropertiesView::SetSelection(Entity* pEntity) + { + mpSelectedAsset = nullptr; + mpSelectedEntity = pEntity; + } + + void PropertiesView::SetSelection(EditorAsset* pAsset) + { + mpSelectedEntity = nullptr; + mpSelectedAsset = pAsset; + } + }} \ No newline at end of file diff --git a/src/run_modes/editor/panels/properties_view.h b/src/run_modes/editor/panels/properties_view.h index a033533..d35b644 100644 --- a/src/run_modes/editor/panels/properties_view.h +++ b/src/run_modes/editor/panels/properties_view.h @@ -15,19 +15,28 @@ namespace lunarium { + class Entity; namespace editor { class CustromProperty; + class EditorAsset; class PropertiesView : public gui::Panel { public: PropertiesView(); + void SetSelection(Entity* pEntity); + void SetSelection(EditorAsset* pAsset); + bool DoFrame(); private: std::vector mCustomProps; + + // Only ONE of these should be set at a time + Entity* mpSelectedEntity; + EditorAsset* mpSelectedAsset; }; } } diff --git a/src/run_modes/editor/panels/world_tree.cpp b/src/run_modes/editor/panels/world_tree.cpp index ea12ff5..3b21527 100644 --- a/src/run_modes/editor/panels/world_tree.cpp +++ b/src/run_modes/editor/panels/world_tree.cpp @@ -21,12 +21,12 @@ namespace editor } - void WorldTree::SetWorld(lunarium::game::World* pWorld) + void WorldTree::SetWorld(lunarium::World* pWorld) { mpWorld = pWorld; } - lunarium::game::World* WorldTree::GetWorld() + lunarium::World* WorldTree::GetWorld() { return mpWorld; } diff --git a/src/run_modes/editor/panels/world_tree.h b/src/run_modes/editor/panels/world_tree.h index a68b42f..d6dcacc 100644 --- a/src/run_modes/editor/panels/world_tree.h +++ b/src/run_modes/editor/panels/world_tree.h @@ -13,7 +13,7 @@ namespace lunarium { - namespace game { class World; } // TODO: Use the editor::World class instead? + class World; namespace editor { @@ -22,13 +22,13 @@ namespace editor public: WorldTree(); - void SetWorld(lunarium::game::World* pWorld); - lunarium::game::World* GetWorld(); + void SetWorld(lunarium::World* pWorld); + lunarium::World* GetWorld(); bool DoFrame(); private: - lunarium::game::World* mpWorld; + lunarium::World* mpWorld; }; } } diff --git a/src/world/components.h b/src/world/components.h index 2c8bd49..acbb5b5 100644 --- a/src/world/components.h +++ b/src/world/components.h @@ -10,14 +10,38 @@ #define LUNARIUM_COMPONENTS_H_ #include +#include +#include + +#define GLM_ENABLE_EXPERIMENTAL +#include #include namespace lunarium { - struct LabelComponent + struct TagComponent + { + std::string Info; + + TagComponent() + { + Info.reserve(256); + } + }; + + struct TransformComponent { - std::string Label; + glm::vec3 Position = { 0.0f, 0.0f, 0.0f }; + glm::vec3 Rotation = { 0.0f, 0.0f, 0.0f }; + glm::vec3 Scale = { 1.0f, 1.0f, 1.0f };; + + glm::mat4 GetTransform() + { + // Quaternion code taken from Hazel engine + // https://github.com/TheCherno/Hazel/blob/dev/Hazel/src/Hazel/Scene/Components.h + return (glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)) * glm::scale(glm::mat4(1.0f), Scale )); + } }; } diff --git a/src/world/entity.cpp b/src/world/entity.cpp index 05c88af..09f81c3 100644 --- a/src/world/entity.cpp +++ b/src/world/entity.cpp @@ -7,17 +7,30 @@ ******************************************************************************/ #include "entity.h" +#include "world.h" namespace lunarium { - Entity::Entity(entt::registry* r) - : mHandle(entt::null), mpRegistry(r) + Entity::Entity(World& w) + : mHandle(entt::null), mWorld(w) { mUUID = UUID::GetNewID(); + Init(); } - Entity::Entity(entt::registry* r, LUUID uuid) - : mHandle(entt::null), mpRegistry(r), mUUID(uuid) + Entity::Entity(World& w, LUUID uuid, entt::entity handle) + : mHandle(handle), mWorld(w), mUUID(uuid) { + Init(); + } + + void Entity::Init() + { + mHandle = mWorld.GetEntityRegistry()->create(); + } + + LUUID Entity::GetUUID() const + { + return mUUID; } } \ No newline at end of file diff --git a/src/world/entity.h b/src/world/entity.h index 90ad22a..ffb4bdd 100644 --- a/src/world/entity.h +++ b/src/world/entity.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace lunarium { @@ -19,8 +20,8 @@ namespace lunarium { public: // TODO: Maybe change this to take the World instead of the registry - Entity(entt::registry* r); - Entity(entt::registry* r, LUUID uuid); + Entity(World& w); + Entity(World& w, LUUID uuid, entt::entity handle = entt::null); // These component methods are based on methods from the Hazel engine, written by Cherno // https://github.com/TheCherno/Hazel/blob/dev/Hazel/src/Hazel/Scene/Entity.h @@ -29,11 +30,10 @@ namespace lunarium { if (HasComponent()) { - Log::Error(LogCategory::GAME_SYSTEM, "Entity already has component!"); + Logger::Error(LogCategory::GAME_SYSTEM, "Entity already has component!"); return GetComponent(); } - T& component = mpRegistry->emplace(mHandle, std::forward(args)...); - //m_Scene->OnComponentAdded(*this, component); + T& component = mWorld.GetEntityRegistry()->emplace(mHandle, std::forward(args)...); return component; } @@ -42,15 +42,15 @@ namespace lunarium { if (!HasComponent()) { - Log::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); + Logger::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); } - return mpRegistry->get(mHandle); + return mWorld.GetEntityRegistry()->get(mHandle); } template bool HasComponent() { - return mpRegistry->all_of(mHandle); + return mWorld.GetEntityRegistry()->all_of(mHandle); } template @@ -58,15 +58,21 @@ namespace lunarium { if (!HasComponent()) { - Log::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); + Logger::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); } - m_Scene->m_Registry.remove(mHandle); + mWorld.GetEntityRegistry()->remove(mHandle); } + LUUID GetUUID() const; + private: LUUID mUUID; entt::entity mHandle; - entt::registry* mpRegistry; + World& mWorld; // The world the entity is contained within + //entt::registry* mpRegistry; + + private: + void Init(); }; } diff --git a/src/world/world.cpp b/src/world/world.cpp index e943c78..878a416 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -10,17 +10,24 @@ ******************************************************************************/ #include "world.h" +#include #include #include #include #include +#include "entity.h" namespace lunarium { - World::World(Camera* pCam, Sizei region_size, Sizei world_size) - : mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mWorldSize(world_size) + // World::World(Camera* pCam, Sizei region_size, Sizei world_size) + // : mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mWorldSize(world_size) + // { + // mActiveRegion = { 0, 0 }; + // } + + World::World() { - mActiveRegion = { 0, 0 }; + } void World::OnLoad() @@ -69,4 +76,23 @@ namespace lunarium return mpWorldScript; } + entt::registry* World::GetEntityRegistry() + { + return &mECSRegistry; + } + + LUUID World::CreateEntity() + { + //Logger::Error(LogCategory::GAME_SYSTEM, "World::CreateEntity not implemented!"); + Entity* new_ent = new Entity(*this); + mEntities[new_ent->GetUUID()] = new_ent; + return new_ent->GetUUID(); + } + + + Entity* World::GetEntity(LUUID id) + { + return mEntities[id]; + } + } \ No newline at end of file diff --git a/src/world/world.h b/src/world/world.h index 1164bc6..7648b07 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -12,6 +12,7 @@ #ifndef WORLD_H_ #define WORLD_H_ +#include #include #include #include @@ -24,8 +25,9 @@ namespace lunarium class Graphics; class Image; class Script; - class Camera; - class GameObject; + //class Camera; + //class GameObject; + class Entity; } namespace lunarium @@ -35,16 +37,17 @@ namespace lunarium public: struct Region { - lunarium::Script* mRegionScript; - Vec2i mCoords; - std::vector mObjects; + bool IsActive; + lunarium::Script* RegionScript; + Vec2i Coords; + std::vector Entities; std::vector mLayers; - // Colliders }; public: // INTERFACE - World(Camera* pCam, Sizei region_size, Sizei world_size); + //World(Camera* pCam, Sizei region_size, Sizei world_size); + World(); void OnLoad(); void OnUnload(); @@ -59,15 +62,23 @@ namespace lunarium void SetWorldScript(Script* pScript); lunarium::Script* GetWorldScript(); + entt::registry* GetEntityRegistry(); + LUUID CreateEntity(); + Entity* GetEntity(LUUID id); + private: entt::registry mECSRegistry; - Camera* mpCamera; - std::vector mWorldObjects; + //Camera* mpCamera; + //std::vector mWorldObjects; lunarium::Script* mpWorldScript; - Sizei mRegionSize; // in pixels + Sizei mRegionSize; // in tiles Sizei mWorldSize; // num regions ex. 10x10 Vec2i mActiveRegion; + + + // TEST STUFF + std::map mEntities; };