First ECS test in the editor working (Tag component editable using a temp-testing entity in the editor)

gui_api_redesign
Joey Pollack 4 years ago
parent e237d0dcb5
commit 9dede57b96

@ -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.]

@ -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"

@ -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 <editor/editor.h>
#include <utils/logger.h>
#include <dearimgui/imgui.h>
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)
{
}
}}

@ -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 <world/components.h>
namespace lunarium { namespace editor
{
class CompGui
{
public:
static void RenderTagComp(TagComponent& comp);
static void RenderTransformComp(TransformComponent& comp);
};
}}
#endif // LUNARIUM_COMPONENT_GUIS_H_

@ -28,6 +28,11 @@
#include <world/components.h>
// TEST STUFF
#include <world/world.h>
#include <world/entity.h>
#include <world/components.h>
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<TagComponent>();
((PropertiesView*)mPanelManager.GetPanel(mPanels.PropertiesView))->SetSelection(mTestWorld->GetEntity(mTestEntity));
return OpRes::OK();
}

@ -10,6 +10,7 @@
#define EDITOR_H_
#include <core/run_mode.h>
#include <core/common_defs.h>
#include <utils/op_res.h>
#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
@ -86,6 +88,9 @@ namespace lunarium { namespace editor
bool mDoSaveProject;
bool mDoSaveAs;
// TEST DATA
LUUID mTestEntity;
private: // HELPERS
void RenderWindow();

@ -10,6 +10,9 @@
#include "properties_view.h"
#include <dearimgui/imgui.h>
#include <editor/editor.h>
#include <world/entity.h>
#include <world/components.h>
#include <editor/component_guis.h>
namespace lunarium { namespace editor
{
@ -30,9 +33,30 @@ namespace lunarium { namespace editor
return false;
}
if (mpSelectedEntity)
{
// TODO: iterate through components
if (mpSelectedEntity->HasComponent<TagComponent>())
{
CompGui::RenderTagComp(mpSelectedEntity->GetComponent<TagComponent>());
}
}
ImGui::End();
return true;
}
void PropertiesView::SetSelection(Entity* pEntity)
{
mpSelectedAsset = nullptr;
mpSelectedEntity = pEntity;
}
void PropertiesView::SetSelection(EditorAsset* pAsset)
{
mpSelectedEntity = nullptr;
mpSelectedAsset = pAsset;
}
}}

@ -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<CustromProperty*> mCustomProps;
// Only ONE of these should be set at a time
Entity* mpSelectedEntity;
EditorAsset* mpSelectedAsset;
};
}
}

@ -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;
}

@ -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;
};
}
}

@ -10,14 +10,38 @@
#define LUNARIUM_COMPONENTS_H_
#include <core/common_defs.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/quaternion.hpp>
#include <string>
namespace lunarium
{
struct LabelComponent
struct TagComponent
{
std::string Info;
TagComponent()
{
Info.reserve(256);
}
};
struct TransformComponent
{
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()
{
std::string Label;
// 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 ));
}
};
}

@ -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;
}
}

@ -12,6 +12,7 @@
#include <utils/uuid.h>
#include <utils/logger.h>
#include <entt/entt.hpp>
#include <world/world.h>
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<T>())
{
Log::Error(LogCategory::GAME_SYSTEM, "Entity already has component!");
Logger::Error(LogCategory::GAME_SYSTEM, "Entity already has component!");
return GetComponent<T>();
}
T& component = mpRegistry->emplace<T>(mHandle, std::forward<Args>(args)...);
//m_Scene->OnComponentAdded<T>(*this, component);
T& component = mWorld.GetEntityRegistry()->emplace<T>(mHandle, std::forward<Args>(args)...);
return component;
}
@ -42,15 +42,15 @@ namespace lunarium
{
if (!HasComponent<T>())
{
Log::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!");
Logger::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!");
}
return mpRegistry->get<T>(mHandle);
return mWorld.GetEntityRegistry()->get<T>(mHandle);
}
template<typename T>
bool HasComponent()
{
return mpRegistry->all_of<T>(mHandle);
return mWorld.GetEntityRegistry()->all_of<T>(mHandle);
}
template<typename T>
@ -58,15 +58,21 @@ namespace lunarium
{
if (!HasComponent<T>())
{
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<T>(mHandle);
mWorld.GetEntityRegistry()->remove<T>(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();
};
}

@ -10,17 +10,24 @@
******************************************************************************/
#include "world.h"
#include <utils/logger.h>
#include <assets/types/script.h>
#include <assets/types/image.h>
#include <graphics/graphics.h>
#include <graphics/camera.h>
#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];
}
}

@ -12,6 +12,7 @@
#ifndef WORLD_H_
#define WORLD_H_
#include <core/common_defs.h>
#include <core/types.h>
#include <utils/op_res.h>
#include <entt/entt.hpp>
@ -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<GameObject*> mObjects;
bool IsActive;
lunarium::Script* RegionScript;
Vec2i Coords;
std::vector<Entity*> Entities;
std::vector<lunarium::Image*> 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,17 +62,25 @@ 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<GameObject*> mWorldObjects;
//Camera* mpCamera;
//std::vector<GameObject*> mWorldObjects;
lunarium::Script* mpWorldScript;
Sizei mRegionSize; // in pixels
Sizei mRegionSize; // in tiles
Sizei mWorldSize; // num regions ex. 10x10
Vec2i mActiveRegion;
// TEST STUFF
std::map<LUUID, Entity*> mEntities;
};
}

Loading…
Cancel
Save