diff --git a/Deer/Include/Deer/Asset.h b/Deer/Include/Deer/Asset.h index fc85750..29c9eb2 100755 --- a/Deer/Include/Deer/Asset.h +++ b/Deer/Include/Deer/Asset.h @@ -5,17 +5,18 @@ #include "Deer/DataStore.h" #include "Deer/Log.h" #include "Deer/Path.h" +#include "Deer/Memory.h" // File to manage Assets // TODO: Delete Assets and set a custom method of loading namespace Deer { template - class Asset { + struct Asset { public: - Asset() : m_assetID(0), m_assetLocation("null") {} + Asset() : id(0), name("null") {} Asset(uint32_t id, const std::filesystem::path& assetLocation) - : m_assetID(id), m_assetLocation(assetLocation) { + : id(id), name(assetLocation) { try { uint32_t size; uint8_t* data = DataStore::readFile(assetLocation, &size); @@ -30,31 +31,32 @@ namespace Deer { } } - inline uint32_t getAssetID() const { return m_assetID; } - inline Path& getAssetLocation() { return m_assetLocation; } - - Ref value; + inline uint32_t getAssetID() const { return id; } + inline Path& getAssetLocation() { return name; } + inline T& getValue() { return value; } private: - uint32_t m_assetID; - Path m_assetLocation; + Path name; + uint32_t id; + + Scope value; }; template <> class Asset { public: - Asset() : m_assetID(0), m_assetLocation("null") {} + Asset() : id(0), name("null") {} Asset(uint32_t id, const std::filesystem::path& assetLocation) - : m_assetID(id), m_assetLocation(assetLocation) {} + : id(id), name(assetLocation) {} - inline uint32_t getAssetID() const { return m_assetID; } - inline Path& getAssetLocation() { return m_assetLocation; } + inline uint32_t getAssetID() const { return id; } + inline Path& getAssetLocation() { return name; } Ref value; private: - uint32_t m_assetID; - Path m_assetLocation; + uint32_t id; + Path name; }; namespace AssetManager { diff --git a/Deer/Include/Deer/ComponentScript.h b/Deer/Include/Deer/ComponentScript.h index b4bc771..6051204 100755 --- a/Deer/Include/Deer/ComponentScript.h +++ b/Deer/Include/Deer/ComponentScript.h @@ -35,7 +35,7 @@ namespace Deer { ComponentScriptInstance() = default; ~ComponentScriptInstance(); - void updateInternalVars(); + void tick(); void start(); asIScriptObject* m_object; diff --git a/Deer/Include/Deer/Enviroment.h b/Deer/Include/Deer/Enviroment.h index 6cbac31..7e03a85 100755 --- a/Deer/Include/Deer/Enviroment.h +++ b/Deer/Include/Deer/Enviroment.h @@ -137,7 +137,7 @@ namespace Deer { Entity& getParent() const; inline uint16_t getParentId() const { return m_parentID; } - // TODO, enable transfer entitys from difrent enviroments + // TODO, enable transfer entitys from difrent environments void setParent(Entity& parent); bool isDescendantOf(Entity& parent) const; @@ -147,7 +147,7 @@ namespace Deer { glm::mat4 getWorldMatrix(); glm::mat4 getRelativeMatrix(); - void updateInternalVars(); + void tick(); inline bool isValid() const { return m_exists; } diff --git a/Deer/Include/Deer/Scene.h b/Deer/Include/Deer/Scene.h index 8d5e611..b384a77 100755 --- a/Deer/Include/Deer/Scene.h +++ b/Deer/Include/Deer/Scene.h @@ -9,63 +9,41 @@ #include #include +#include namespace Deer { - class VoxelWorld; - class VoxelWorldProps; class Environment; + class GizmoRenderer; // A scene is a 3d simulation with its environment and voxel world in case // of initialized, here things can be simulated - class Scene { - public: - Scene(); - ~Scene(); - Scene(const Scene&) = delete; - Scene operator=(Scene&) = delete; - - void createVoxelWorld(const VoxelWorldProps&); - void deleteVoxelWorld(); - + namespace Scene { // Resets all scene to 0 but conserving the memory making it much faster // than creating another instance void clear(); // This is the cycle to execution void beginExecution(); - void updateInternalVars(); + void tick(); void endExecution(); - inline Environment& getMainEnviroment() { return *m_enviroment; } - inline VoxelWorld& getVoxelWorld() { return *m_voxelWorld; } - inline bool isVoxelWorldInitialized() { - return m_voxelWorld != nullptr; - } - inline bool getExecutingState() { return m_isExecuting; } + bool getExecutingState(); #ifdef DEER_RENDER - public: // This function renders with the default camera in the environment void render(); void render(SceneCamera); - inline GizmoRenderer& getMainGizmoRenderer() { return m_gizmoRenderer; } - - private: - GizmoRenderer m_gizmoRenderer; + extern GizmoRenderer gizmoRenderer; #endif - private: - Scope m_enviroment; - Scope m_voxelWorld; - - bool m_isExecuting = false; - }; + extern Environment environment; + } // Namespace to manage scenes in memory namespace DataStore { - void loadScene(Scene& scene, const Path& name); - void exportScene(const Scene& scene, const Path& name); + void loadScene(const Path& name); + void exportScene(const Path& name); - void exportRuntimeScene(const Scene& scene); - void importRuntimeScene(Scene& scene); + void exportRuntimeScene(); + void importRuntimeScene(); } // namespace DataStore } // namespace Deer diff --git a/Deer/Include/Deer/ScriptEngine.h b/Deer/Include/Deer/ScriptEngine.h index 2f34b1d..65946ad 100755 --- a/Deer/Include/Deer/ScriptEngine.h +++ b/Deer/Include/Deer/ScriptEngine.h @@ -14,7 +14,6 @@ class asIScriptFunction; class asITypeInfo; namespace Deer { - class Scene; class Entity; class ComponentScript; @@ -24,12 +23,11 @@ namespace Deer { extern asIScriptContext* m_context; extern bool m_isCompilationValid; extern ComponentScriptMap m_componentScripts; - extern Scene* m_scene; void compileScriptEngine(const std::filesystem::path& scriptPath); void shutdownScriptEngine(); - void beginExecutionContext(Scene* executingScene); + void beginExecutionContext(); void endExecutionContext(); inline asIScriptContext* getExecutionContext() { return m_context; } diff --git a/Deer/Include/Deer/VoxelWorld.h b/Deer/Include/Deer/VoxelWorld.h index 10ca9a4..6d1f229 100755 --- a/Deer/Include/Deer/VoxelWorld.h +++ b/Deer/Include/Deer/VoxelWorld.h @@ -143,56 +143,43 @@ namespace Deer { }; // Class to manage the voxels - class VoxelWorld { - public: - // Warning: Do not change the voxel data content since that could make - // undefined behaviour - VoxelWorld(const VoxelWorldProps &props); - ~VoxelWorld(); - // This class can not be copyed - // TODO: Make a function to duplicate a voxel World - VoxelWorld(const VoxelWorld &) = delete; - VoxelWorld &operator=(VoxelWorld &) = delete; + namespace VoxelWorld { + void initialize(const VoxelWorldProps&); + void clear(); // Returns the voxel in a voxel coordinates Voxel readVoxel(VoxelCordinates); // Sets the voxel in the coordinates to the value void setVoxel(VoxelCordinates, Voxel value); - + // Fills a space with the voxel value inside the 2 coordinates // Note that you don't have to give then ordeered by min and max void fillVoxels(VoxelCordinates, VoxelCordinates, Voxel value); - // Remplaces the ref voxel with the value of a space inside the 2 - // coordinates + // Remplaces the ref voxel with the value of a space inside the 2 coordinates // Note that you don't have to give then ordeered by min and max - void remplaceVoxels(VoxelCordinates, VoxelCordinates, Voxel ref, - Voxel value); - + void remplaceVoxels(VoxelCordinates, VoxelCordinates, Voxel ref, Voxel value); + // Returns the layer data of a woorld coordinates // Note out of bounds will return a default Layer Voxel LayerVoxel readLayerVoxel(int x, int z); // Calculates the max height of a layer in a space // Note out of bounds will return a 0 of height - // Tip: this will calculate, you should use the cached height in a layer - // voxel + // Tip: this will calculate, you should use the cached height in a layer voxel uint16_t calculateLayerVoxelHeight(int x, int z); - + // Raycast a ray from a source and dir VoxelRayResult rayCast(glm::vec3 position, glm::vec3 dir, - float maxDistance = 10.0f); - // Raycast a ray from a source and dir ignoring if the ray stats inside - // a voxel + float maxDistance = 10.0f); + // Raycast a ray from a source and dir ignoring if the ray stats inside a voxel VoxelRayResult rayCast_editor(glm::vec3 position, glm::vec3 dir, - float maxDistance = 10.0f); + float maxDistance = 10.0f); + bool isInitialized(); + // Returns the voxel world props used in the voxel world - // Note that you can't change the world size unless you create a new - // Voxel World - inline const VoxelWorldProps &getVoxelWorldProps() const { - return m_worldProps; - } -#ifdef DEER_RENDER - public: + // Note that you can't change the world size unless you create a new Voxel World + const VoxelWorldProps& getWorldProps(); + #ifdef DEER_RENDER // Renders the current voxel world with a specified scene camera void render(const SceneCamera &); // Generates the next chunk mesh @@ -202,9 +189,6 @@ namespace Deer { VoxelLight readLight(VoxelCordinates); VoxelLight &modLight(VoxelCordinates); - private: - Scope m_renderData; - // Chunk vertex creation void genSolidVoxel(ChunkID chunkID, ChunkVoxelID chunkVoxelID); @@ -215,16 +199,11 @@ namespace Deer { void bakeVoxelLightFromPoint(VoxelCordinates); void bakeAmbientLight(int minX, int maxX, int minZ, int maxZ); void bakeAmbientLightFromPoint(int x, int z); - + void resolveNextAmbientLightPropagation(); void resolveNextVoxelLightPropagation(); -#endif - private: - VoxelWorldProps m_worldProps; - - Scope m_chunks; - Scope m_layers; - + #endif + LayerVoxel &modLayerVoxel(int x, int z); - }; + } } // namespace Deer diff --git a/Deer/src/Deer/Scene/Entity.cpp b/Deer/src/Deer/Scene/Entity.cpp index 22ce3c2..45fb2d6 100755 --- a/Deer/src/Deer/Scene/Entity.cpp +++ b/Deer/src/Deer/Scene/Entity.cpp @@ -11,7 +11,7 @@ namespace Deer { void Entity::setParent(Entity& parent) { DEER_CORE_ASSERT(isValid(), "Entity is not valid"); DEER_CORE_ASSERT(parent.m_environment == m_environment, - "Can not set parent from diferent enviroments"); + "Can not set parent from diferent environments"); DEER_CORE_ASSERT(parent.isValid(), "Parent is not valid"); if (parent.getId() == getId()) return; diff --git a/Deer/src/Deer/Scene/Scene.cpp b/Deer/src/Deer/Scene/Scene.cpp index d383beb..ebe4890 100755 --- a/Deer/src/Deer/Scene/Scene.cpp +++ b/Deer/src/Deer/Scene/Scene.cpp @@ -9,55 +9,62 @@ #include "Deer/VoxelWorld.h" #include "Deer/Voxels/Chunk.h" #include "Deer/Voxels/Layer.h" +#include "Deer/Voxels/VoxelWorldData.h" + +#include "Deer/Enviroment.h" + +#include "Deer/Scene/SceneData.h" #ifdef DEER_RENDER #include "DeerRender/Voxels/VoxelWorldRenderData.h" #endif namespace Deer { - Scene::Scene() { - m_enviroment = MakeScope(); - m_voxelWorld = nullptr; + void Scene::clear() { + environment.clear(); + VoxelWorld::clear(); + } + + bool Scene::getExecutingState() { + return isExecuting; } void Scene::beginExecution() { - DEER_CORE_ASSERT(!m_isExecuting, "Deer scene is already executing"); - m_isExecuting = true; + DEER_CORE_ASSERT(!isExecuting, "Deer scene is already executing"); + isExecuting = true; DEER_CORE_INFO("Executing Scene..."); - ScriptEngine::beginExecutionContext(this); + ScriptEngine::beginExecutionContext(); // Instantiate all the scripts - auto view = - m_enviroment->m_registry.view(); + auto view = environment.m_registry.view(); for (auto& entID : view) { auto& tagComponent = view.get(entID); auto& componentScript = view.get(entID); - Entity& entity = m_enviroment->getEntity(tagComponent.entityUID); - componentScript.roeInstance = - ScriptEngine::createComponentScriptInstance( - componentScript.scriptID, entity); + Entity& entity = environment.getEntity(tagComponent.entityUID); + componentScript.roeInstance = + ScriptEngine::createComponentScriptInstance(componentScript.scriptID, entity); componentScript.roeInstance->start(); } } - void Scene::updateInternalVars() { + void Scene::tick() { // Update all scripts - auto view = m_enviroment->m_registry.view(); + auto view = environment.m_registry.view(); for (auto& entID : view) { auto& componentScript = view.get(entID); - componentScript.roeInstance->updateInternalVars(); + componentScript.roeInstance->tick(); } } void Scene::endExecution() { - DEER_CORE_ASSERT(m_isExecuting, "Deer scene is not executing"); - m_isExecuting = false; + DEER_CORE_ASSERT(isExecuting, "Deer scene is not executing"); + isExecuting = false; // Deatach all scripts - auto view = m_enviroment->m_registry.view(); + auto view = environment.m_registry.view(); for (auto& entID : view) { auto& componentScript = view.get(entID); componentScript.roeInstance.reset(); @@ -66,14 +73,4 @@ namespace Deer { DEER_CORE_INFO("Stoping Scene..."); } - void Scene::createVoxelWorld(const VoxelWorldProps& props) { - m_voxelWorld = MakeScope(props); - } - - void Scene::deleteVoxelWorld() { m_voxelWorld.reset(); } - - void Scene::clear() { - m_enviroment->clear(); - m_voxelWorld.reset(); - } } // namespace Deer diff --git a/Deer/src/Deer/Scene/SceneData.cpp b/Deer/src/Deer/Scene/SceneData.cpp new file mode 100644 index 0000000..0a1d285 --- /dev/null +++ b/Deer/src/Deer/Scene/SceneData.cpp @@ -0,0 +1,18 @@ +#include "Deer/Memory.h" +#include "Deer/Enviroment.h" + +#ifdef DEER_RENDER +#include "DeerRender/GizmoRenderer.h" +#endif + +namespace Deer { + namespace Scene { + Environment environment; + bool isExecuting = false; + +#ifdef DEER_RENDER + GizmoRenderer gizmoRenderer; +#endif + } + +} // namespace Deer diff --git a/Deer/src/Deer/Scene/SceneData.h b/Deer/src/Deer/Scene/SceneData.h new file mode 100644 index 0000000..bc70516 --- /dev/null +++ b/Deer/src/Deer/Scene/SceneData.h @@ -0,0 +1,20 @@ +#pragma once +#include "Deer/Memory.h" + +#ifdef DEER_RENDER +#include "DeerRender/GizmoRenderer.h" +#endif + +namespace Deer { + class Environment; + + namespace Scene { + extern Environment environment; + extern bool isExecuting; + +#ifdef DEER_RENDER + extern GizmoRenderer gizmoRenderer; +#endif + } + +} // namespace Deer diff --git a/Deer/src/Deer/Scene/SceneDataStore.cpp b/Deer/src/Deer/Scene/SceneDataStore.cpp index 872f384..dd9f929 100755 --- a/Deer/src/Deer/Scene/SceneDataStore.cpp +++ b/Deer/src/Deer/Scene/SceneDataStore.cpp @@ -7,8 +7,10 @@ #include "cereal/archives/json.hpp" #include "cereal/archives/portable_binary.hpp" +#include "Deer/Scene.h" + namespace Deer { - void DataStore::loadScene(Scene& scene, const Path& name) { + void DataStore::loadScene(const Path& name) { Path realName; realName = Path(DEER_SCENE_PATH) / (name.string() + ".dscn"); @@ -20,40 +22,41 @@ namespace Deer { { cereal::JSONInputArchive archive(stream); - archive(cereal::make_nvp("scene", scene)); + archive(cereal::make_nvp("environment", Scene::environment)); } delete[] data; } - void DataStore::exportScene(const Scene& scene, const Path& name) { + void DataStore::exportScene(const Path& name) { Path realName; realName = Path(DEER_SCENE_PATH) / (name.string() + ".dscn"); std::stringstream output; { cereal::JSONOutputArchive archive(output); - archive(cereal::make_nvp("scene", scene)); + archive(cereal::make_nvp("environment", Scene::environment)); } std::string_view view = output.view(); DataStore::saveFile(realName, (uint8_t*)view.data(), view.size()); } - void DataStore::exportRuntimeScene(const Scene& scene) { + void DataStore::exportRuntimeScene() { Path realName; realName = Path(DEER_TEMP_PATH) / ("temp_scene.dbscn"); std::stringstream output; { cereal::PortableBinaryOutputArchive archive(output); - archive(cereal::make_nvp("scene", scene)); + archive(cereal::make_nvp("environment", Scene::environment)); } std::string_view view = output.view(); DataStore::saveFile(realName, (uint8_t*)view.data(), view.size()); } - void DataStore::importRuntimeScene(Scene& scene) { + + void DataStore::importRuntimeScene() { Path realName; realName = Path(DEER_TEMP_PATH) / ("temp_scene.dbscn"); @@ -65,7 +68,7 @@ namespace Deer { { cereal::PortableBinaryInputArchive archive(stream); - archive(cereal::make_nvp("scene", scene)); + archive(cereal::make_nvp("environment", Scene::environment)); } delete[] data; diff --git a/Deer/src/Deer/Scene/Serialization/SceneSerialization.h b/Deer/src/Deer/Scene/Serialization/SceneSerialization.h deleted file mode 100755 index d006259..0000000 --- a/Deer/src/Deer/Scene/Serialization/SceneSerialization.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include "Deer/Scene.h" - -namespace Deer { - template - void serialize(Archive& archive, Scene& m_scene) { - archive( - cereal::make_nvp("main_environment", m_scene.getMainEnviroment())); - } -} // namespace Deer \ No newline at end of file diff --git a/Deer/src/Deer/Scene/Serialization/Serialization.h b/Deer/src/Deer/Scene/Serialization/Serialization.h index 6b0741a..f1b971e 100755 --- a/Deer/src/Deer/Scene/Serialization/Serialization.h +++ b/Deer/src/Deer/Scene/Serialization/Serialization.h @@ -1,6 +1,5 @@ #pragma once -#include "Deer/Asset.h" #include "cereal/cereal.hpp" #include "cereal/types/string.hpp" #include "cereal/types/vector.hpp" @@ -15,7 +14,6 @@ // SCENE SPECIFIC #include "Deer/Scene/Serialization/EntitySerialization.h" #include "Deer/Scene/Serialization/EnvironmentSerialization.h" -#include "Deer/Scene/Serialization/SceneSerialization.h" // COMPONENTS SPECIFIC #include "Deer/Scene/Serialization/Components/RelationshipComponentSerialization.h" diff --git a/Deer/src/Deer/Scripting/ComponentScript.cpp b/Deer/src/Deer/Scripting/ComponentScript.cpp index 6fbd3bb..e2822af 100755 --- a/Deer/src/Deer/Scripting/ComponentScript.cpp +++ b/Deer/src/Deer/Scripting/ComponentScript.cpp @@ -17,7 +17,7 @@ namespace Deer { m_object->Release(); } - void ComponentScriptInstance::updateInternalVars() { + void ComponentScriptInstance::tick() { if (!m_updateFunction) return; diff --git a/Deer/src/Deer/Scripting/ScriptEngine.cpp b/Deer/src/Deer/Scripting/ScriptEngine.cpp index 5dd0631..2524c62 100755 --- a/Deer/src/Deer/Scripting/ScriptEngine.cpp +++ b/Deer/src/Deer/Scripting/ScriptEngine.cpp @@ -18,7 +18,6 @@ namespace Deer { namespace ScriptEngine { asIScriptEngine* m_scriptEngine; asIScriptModule* m_scriptModule; - Scene* m_scene; bool m_isCompilationValid = false; @@ -32,8 +31,7 @@ namespace Deer { void ScriptEngine::shutdownScriptEngine() { m_componentScripts.clear(); } - void ScriptEngine::beginExecutionContext(Scene* executingScene) { - m_scene = executingScene; + void ScriptEngine::beginExecutionContext() { m_context = m_scriptEngine->CreateContext(); } diff --git a/Deer/src/Deer/Scripting/ScriptEngineFunctions.cpp b/Deer/src/Deer/Scripting/ScriptEngineFunctions.cpp index f420345..1100c00 100755 --- a/Deer/src/Deer/Scripting/ScriptEngineFunctions.cpp +++ b/Deer/src/Deer/Scripting/ScriptEngineFunctions.cpp @@ -33,7 +33,7 @@ namespace Deer { return glm::vec3(); } - Environment& m_environment = ScriptEngine::m_scene->getMainEnviroment(); + Environment& m_environment = Scene::environment; Entity& entt = m_environment.getEntity(entityUID); return entt.getComponent().position; @@ -45,7 +45,7 @@ namespace Deer { return; } - Environment& m_environment = ScriptEngine::m_scene->getMainEnviroment(); + Environment& m_environment = Scene::environment; Entity& entt = m_environment.getEntity(entityUID); entt.getComponent().position = position; @@ -57,7 +57,7 @@ namespace Deer { return glm::vec3(); } - Environment& m_environment = ScriptEngine::m_scene->getMainEnviroment(); + Environment& m_environment = Scene::environment; Entity& entt = m_environment.getEntity(entityUID); return entt.getComponent().scale; @@ -69,7 +69,7 @@ namespace Deer { return; } - Environment& m_environment = ScriptEngine::m_scene->getMainEnviroment(); + Environment& m_environment = Scene::environment; Entity& entt = m_environment.getEntity(entityUID); entt.getComponent().scale = scale; @@ -81,7 +81,7 @@ namespace Deer { return 0; } - Environment& m_environment = ScriptEngine::m_scene->getMainEnviroment(); + Environment& m_environment = Scene::environment; Entity& entt = m_environment.getEntity(entityUID); return entt.getParentId(); @@ -90,7 +90,7 @@ namespace Deer { bool isEntityValid(uint32_t& entityUID) { if (entityUID == 0 || entityUID == 1) return false; - Environment& m_environment = ScriptEngine::m_scene->getMainEnviroment(); + Environment& m_environment = Scene::environment; Entity& entt = m_environment.getEntity(entityUID); return entt.isValid(); diff --git a/Deer/src/Deer/Voxels/VoxelWorld.cpp b/Deer/src/Deer/Voxels/VoxelWorld.cpp index 51bae4b..61c1ac0 100755 --- a/Deer/src/Deer/Voxels/VoxelWorld.cpp +++ b/Deer/src/Deer/Voxels/VoxelWorld.cpp @@ -1,4 +1,5 @@ #include "Deer/VoxelWorld.h" +#include "Deer/Voxels/VoxelWorldData.h" #include "Deer/Log.h" #include "Deer/Voxels/Chunk.h" @@ -14,28 +15,46 @@ #include namespace Deer { - VoxelWorld::VoxelWorld(const VoxelWorldProps& props) : m_worldProps(props) { - m_chunks = MakeScope(m_worldProps.getChunkCount()); - m_layers = MakeScope(m_worldProps.getLayerCount()); + void VoxelWorld::initialize(const VoxelWorldProps& props) { + clear(); + + worldProps = props; + + chunks = MakeScope(worldProps.getChunkCount()); + layers = MakeScope(worldProps.getLayerCount()); + #ifdef DEER_RENDER - m_renderData = - MakeScope(m_worldProps.getChunkCount()); + initializeRenderVars(props); +#endif + initialized = true; + } + + void VoxelWorld::clear() { + chunks.reset(); + layers.reset(); + + initialized = false; +#ifdef DEER_RENDER + clearRenderVars(); #endif } - VoxelWorld::~VoxelWorld() {} - + const VoxelWorldProps& VoxelWorld::getWorldProps() { + return worldProps; + } + uint16_t VoxelWorld::calculateLayerVoxelHeight(int x, int z) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); LayerVoxelID layerVoxelID; LayerID layerID; extractLayerCordinates(x, z, layerID, layerVoxelID); ChunkID chunkID(layerID.x, 0, layerID.z); - for (int y = m_worldProps.chunkSizeY - 1; y >= 0; y--) { + for (int y = worldProps.chunkSizeY - 1; y >= 0; y--) { chunkID.y = y; - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; uint8_t chunkVoxelHeight = chunk.calculateLayerVoxelHeight(layerVoxelID); @@ -43,6 +62,7 @@ namespace Deer { return chunkVoxelHeight + chunkID.y * CHUNK_SIZE_Y; } } + return 0; } } // namespace Deer diff --git a/Deer/src/Deer/Voxels/VoxelWorldData.cpp b/Deer/src/Deer/Voxels/VoxelWorldData.cpp new file mode 100644 index 0000000..2ff9604 --- /dev/null +++ b/Deer/src/Deer/Voxels/VoxelWorldData.cpp @@ -0,0 +1,18 @@ +#include "Deer/Voxels/VoxelWorldData.h" +#include "Deer/Voxels/Chunk.h" +#include "Deer/Voxels/Layer.h" + +namespace Deer { + namespace VoxelWorld { + VoxelWorldProps worldProps; + + Scope chunks; + Scope layers; + + bool initialized; + } + + bool VoxelWorld::isInitialized() { + return initialized; + } +} \ No newline at end of file diff --git a/Deer/src/Deer/Voxels/VoxelWorldData.h b/Deer/src/Deer/Voxels/VoxelWorldData.h new file mode 100644 index 0000000..261d88d --- /dev/null +++ b/Deer/src/Deer/Voxels/VoxelWorldData.h @@ -0,0 +1,13 @@ +#pragma once +#include "Deer/VoxelWorld.h" +#include "Deer/Memory.h" + +namespace Deer { + namespace VoxelWorld { + extern VoxelWorldProps worldProps; + + extern Scope chunks; + extern Scope layers; + extern bool initialized; + } +} \ No newline at end of file diff --git a/Deer/src/Deer/Voxels/VoxelWorld_Raycast.cpp b/Deer/src/Deer/Voxels/VoxelWorld_Raycast.cpp index 8cf46da..123abe6 100644 --- a/Deer/src/Deer/Voxels/VoxelWorld_Raycast.cpp +++ b/Deer/src/Deer/Voxels/VoxelWorld_Raycast.cpp @@ -2,6 +2,7 @@ #include "Deer/Log.h" #include "Deer/Voxels/Chunk.h" #include "Deer/Voxels/Layer.h" +#include "Deer/Voxels/VoxelWorldData.h" #include #include @@ -9,6 +10,8 @@ namespace Deer { VoxelRayResult VoxelWorld::rayCast(glm::vec3 position, glm::vec3 dir, float maxDistance) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + VoxelRayResult result; result.hitPos.x = (int32_t)std::floor(position.x); @@ -78,6 +81,8 @@ namespace Deer { } VoxelRayResult VoxelWorld::rayCast_editor(glm::vec3 position, glm::vec3 dir, float maxDistance) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + VoxelRayResult result; result.hitPos.x = (int32_t)std::floor(position.x); diff --git a/Deer/src/Deer/Voxels/VoxelWorld_VoxelManipultation.cpp b/Deer/src/Deer/Voxels/VoxelWorld_VoxelManipultation.cpp index 13b6c0c..5ea5403 100644 --- a/Deer/src/Deer/Voxels/VoxelWorld_VoxelManipultation.cpp +++ b/Deer/src/Deer/Voxels/VoxelWorld_VoxelManipultation.cpp @@ -3,6 +3,8 @@ #include "Deer/Voxels/Chunk.h" #include "Deer/Voxels/Layer.h" +#include "Deer/Voxels/VoxelWorldData.h" + #ifdef DEER_RENDER #include "DeerRender/Voxels/VoxelWorldRenderData.h" #endif @@ -14,24 +16,28 @@ namespace Deer { Voxel VoxelWorld::readVoxel(VoxelCordinates coords) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + ChunkID chunkID; ChunkVoxelID chunkVoxelID; extractChunkCordinates(coords, chunkID, chunkVoxelID); - if (!m_worldProps.isValid(chunkID)) return emptyVoxel; + if (!worldProps.isValid(chunkID)) return emptyVoxel; - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; return chunk.readVoxel(chunkVoxelID); } void VoxelWorld::setVoxel(VoxelCordinates coords, Voxel info) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + ChunkID chunkID; ChunkVoxelID chunkVoxelID; extractChunkCordinates(coords, chunkID, chunkVoxelID); - if (!m_worldProps.isValid(chunkID)) return; + if (!worldProps.isValid(chunkID)) return; - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; chunk.modVoxel(chunkVoxelID) = info; LayerID layerID; @@ -39,7 +45,7 @@ namespace Deer { extractLayerCordinates(coords.x, coords.z, layerID, layerVoxelID); - Layer& layer = m_layers[m_worldProps.getWorldLayerID(layerID)]; + Layer& layer = layers[worldProps.getWorldLayerID(layerID)]; LayerVoxel& layerVoxel = layer.modLayerVoxel(layerVoxelID); if (!info.isVoxelType()) @@ -48,20 +54,20 @@ namespace Deer { layerVoxel.height = coords.y + 1; #ifdef DEER_RENDER - m_renderData->chunkQueue.addChunk(chunkID); + chunkQueue.addChunk(chunkID); // For every axis, X & Y & Z for (int i = 0; i < 3; i++) { if (chunkVoxelID[i] == 0 && chunkID[i] != 0) { ChunkID nextChunk = chunkID; nextChunk[i]--; - m_renderData->chunkQueue.addChunk(nextChunk); + chunkQueue.addChunk(nextChunk); } if (chunkVoxelID[i] == CHUNK_SIZE(i) && - chunkID[i] != m_worldProps[i] - 1) { + chunkID[i] != worldProps[i] - 1) { ChunkID nextChunk = chunkID; nextChunk[i]++; - m_renderData->chunkQueue.addChunk(nextChunk); + chunkQueue.addChunk(nextChunk); } } @@ -71,14 +77,15 @@ namespace Deer { #endif } - void VoxelWorld::fillVoxels(VoxelCordinates min, VoxelCordinates max, - Voxel info) { + void VoxelWorld::fillVoxels(VoxelCordinates min, VoxelCordinates max, Voxel info) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + ChunkID minChunkID; ChunkID maxChunkID; ChunkVoxelID minChunkVoxelID; ChunkVoxelID maxChunkVoxelID; - m_worldProps.clampAndSetMinMax(min, max); + worldProps.clampAndSetMinMax(min, max); extractChunkCordinates(min, minChunkID, minChunkVoxelID); extractChunkCordinates(max, maxChunkID, maxChunkVoxelID); @@ -89,9 +96,9 @@ namespace Deer { ChunkID workingChunkID(chunkX, chunkY, chunkZ); LayerID workingLayerID(chunkX, chunkZ); Chunk& workingChunk = - m_chunks[m_worldProps.getWorldChunkID(workingChunkID)]; + chunks[worldProps.getWorldChunkID(workingChunkID)]; Layer& workingLayer = - m_layers[m_worldProps.getWorldLayerID(workingLayerID)]; + layers[worldProps.getWorldLayerID(workingLayerID)]; ChunkVoxelID workingMin(0, 0, 0); ChunkVoxelID workingMax(CHUNK_SIZE_X - 1, CHUNK_SIZE_Y - 1, @@ -119,7 +126,7 @@ namespace Deer { workingMinLayer, workingMaxLayer, max.y); #ifdef DEER_RENDER - m_renderData->chunkQueue.addChunk(workingChunkID); + chunkQueue.addChunk(workingChunkID); #endif } } @@ -134,8 +141,8 @@ namespace Deer { maxLightModification[i] += 16; } - m_worldProps.clampCordinates(minLightModification); - m_worldProps.clampCordinates(maxLightModification); + worldProps.clampCordinates(minLightModification); + worldProps.clampCordinates(maxLightModification); bakeAmbientLight(minLightModification.x, maxLightModification.x, minLightModification.z, maxLightModification.z); @@ -145,12 +152,14 @@ namespace Deer { void VoxelWorld::remplaceVoxels(VoxelCordinates min, VoxelCordinates max, Voxel ref, Voxel value) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + ChunkID minChunkID; ChunkID maxChunkID; ChunkVoxelID minChunkVoxelID; ChunkVoxelID maxChunkVoxelID; - m_worldProps.clampAndSetMinMax(min, max); + worldProps.clampAndSetMinMax(min, max); extractChunkCordinates(min, minChunkID, minChunkVoxelID); extractChunkCordinates(max, maxChunkID, maxChunkVoxelID); @@ -160,7 +169,7 @@ namespace Deer { chunkZ++) { ChunkID workingChunkID(chunkX, chunkY, chunkZ); Chunk& workingChunk = - m_chunks[m_worldProps.getWorldChunkID(workingChunkID)]; + chunks[worldProps.getWorldChunkID(workingChunkID)]; ChunkVoxelID workingMin(0, 0, 0); ChunkVoxelID workingMax(CHUNK_SIZE_X - 1, CHUNK_SIZE_Y - 1, @@ -184,7 +193,7 @@ namespace Deer { value); #ifdef DEER_RENDER - m_renderData->chunkQueue.addChunk(workingChunkID); + chunkQueue.addChunk(workingChunkID); #endif } } @@ -196,9 +205,9 @@ namespace Deer { LayerVoxelID layerVoxelID; extractLayerCordinates(xPos, zPos, layerID, layerVoxelID); - int worldLayerID = m_worldProps.getWorldLayerID(layerID); + int worldLayerID = worldProps.getWorldLayerID(layerID); - m_layers[worldLayerID].modLayerVoxel(layerVoxelID).height = + layers[worldLayerID].modLayerVoxel(layerVoxelID).height = calculateLayerVoxelHeight(xPos, zPos); } } @@ -212,8 +221,8 @@ namespace Deer { maxLightModification[i] += 16; } - m_worldProps.clampCordinates(minLightModification); - m_worldProps.clampCordinates(maxLightModification); + worldProps.clampCordinates(minLightModification); + worldProps.clampCordinates(maxLightModification); bakeAmbientLight(minLightModification.x, maxLightModification.x, minLightModification.z, maxLightModification.z); @@ -226,9 +235,9 @@ namespace Deer { LayerVoxelID layerVoxelID; extractLayerCordinates(x, z, layerID, layerVoxelID); - if (!m_worldProps.isValid(layerID)) return LayerVoxel(); + if (!worldProps.isValid(layerID)) return LayerVoxel(); - Layer& layer = m_layers[m_worldProps.getWorldLayerID(layerID)]; + Layer& layer = layers[worldProps.getWorldLayerID(layerID)]; return layer.readLayerVoxel(layerVoxelID); } @@ -237,9 +246,9 @@ namespace Deer { LayerVoxelID layerVoxelID; extractLayerCordinates(x, z, layerID, layerVoxelID); - if (!m_worldProps.isValid(layerID)) return nullLayerVoxel; + if (!worldProps.isValid(layerID)) return nullLayerVoxel; - Layer& layer = m_layers[m_worldProps.getWorldLayerID(layerID)]; + Layer& layer = layers[worldProps.getWorldLayerID(layerID)]; return layer.modLayerVoxel(layerVoxelID); } diff --git a/Deer/src/DeerRender/Scene/Environment.cpp b/Deer/src/DeerRender/Scene/Environment.cpp index 411b74a..df9888c 100755 --- a/Deer/src/DeerRender/Scene/Environment.cpp +++ b/Deer/src/DeerRender/Scene/Environment.cpp @@ -33,18 +33,6 @@ namespace Deer { auto& tag = view.get(entityId); Entity& entity = getEntity(tag.entityUID); - if (entity.hasComponent()) { - TextureBindingComponent& textureBinding = entity.getComponent(); - - for (int x = 0; x < MAX_TEXTURE_BINDINGS; x++) { - if (textureBinding.textureAssetID[x] == 0) - continue; - - Asset& textureAsset = AssetManager::getAsset(textureBinding.textureAssetID[x]); - textureAsset.value->bind(textureBinding.textureBindID[x]); - } - } - glm::mat4 matrix = entity.getWorldMatrix(); //Asset& shaderAsset = AssetManager::getAsset(meshRender.shaderAssetID); diff --git a/Deer/src/DeerRender/Scene/Scene.cpp b/Deer/src/DeerRender/Scene/Scene.cpp index b164dd7..b87ecc8 100755 --- a/Deer/src/DeerRender/Scene/Scene.cpp +++ b/Deer/src/DeerRender/Scene/Scene.cpp @@ -6,13 +6,11 @@ #include "DeerRender/Render/RenderCommand.h" namespace Deer { - Scene::~Scene() {} - void Scene::render() { - uint32_t mainCamera = m_enviroment->tryGetMainCamera(); + uint32_t mainCamera = environment.tryGetMainCamera(); if (mainCamera == 0) return; - Entity& m_cameraEntity = m_enviroment->getEntity(mainCamera); + Entity& m_cameraEntity = environment.getEntity(mainCamera); SceneCamera sceneCamera; sceneCamera.camera = m_cameraEntity.getComponent(); sceneCamera.transform = @@ -23,10 +21,13 @@ namespace Deer { void Scene::render(SceneCamera sceneCamera) { RenderCommand::setDepthBuffer(true); - m_enviroment->render(sceneCamera); - if (m_voxelWorld) m_voxelWorld->render(sceneCamera); + environment.render(sceneCamera); + + if (VoxelWorld::isInitialized()) + VoxelWorld::render(sceneCamera); + RenderCommand::setDepthBuffer(false); - m_gizmoRenderer.render(sceneCamera); + gizmoRenderer.render(sceneCamera); } } // namespace Deer diff --git a/Deer/src/DeerRender/Scene/Serialization/Components/MeshRenderComponentSerialization.h b/Deer/src/DeerRender/Scene/Serialization/Components/MeshRenderComponentSerialization.h index 4a70a2b..c53917b 100755 --- a/Deer/src/DeerRender/Scene/Serialization/Components/MeshRenderComponentSerialization.h +++ b/Deer/src/DeerRender/Scene/Serialization/Components/MeshRenderComponentSerialization.h @@ -1,22 +1,26 @@ #pragma once #include "Deer/Components.h" -#include "Deer/Asset.h" namespace Deer{ template void save(Archive& archive, MeshRenderComponent const& meshRender) { + // TO IMPLEMENT + /* std::string meshLocation = AssetManager::getAssetLocation(meshRender.meshAssetID).generic_string(); archive(cereal::make_nvp("mesh", meshLocation)); std::string shaderLocation = AssetManager::getAssetLocation(meshRender.shaderAssetID).generic_string(); archive(cereal::make_nvp("shader", shaderLocation)); + */ } template void load(Archive& archive, MeshRenderComponent& meshRender) { + // TO IMPLEMENT + /* std::string meshLocation; archive(cereal::make_nvp("mesh", meshLocation)); std::string shaderLocation; @@ -24,5 +28,6 @@ namespace Deer{ meshRender.meshAssetID = AssetManager::loadAsset(std::filesystem::path(meshLocation)); meshRender.shaderAssetID = AssetManager::loadAsset(std::filesystem::path(shaderLocation)); + */ } } \ No newline at end of file diff --git a/Deer/src/DeerRender/Scene/Serialization/Components/TextureBindingSerializationComponent.h b/Deer/src/DeerRender/Scene/Serialization/Components/TextureBindingSerializationComponent.h index 67bf6b7..d2cd09d 100755 --- a/Deer/src/DeerRender/Scene/Serialization/Components/TextureBindingSerializationComponent.h +++ b/Deer/src/DeerRender/Scene/Serialization/Components/TextureBindingSerializationComponent.h @@ -1,6 +1,7 @@ #pragma once #include "Deer/Components.h" #include "DeerRender/Render/Texture.h" + #include #include @@ -26,6 +27,9 @@ namespace Deer { TextureBindingComponent& textureBinding) { std::vector bindings; + // TO IMPLEMENT + /* + archive(cereal::make_nvp("bindings", bindings)); int id = 0; @@ -37,6 +41,8 @@ namespace Deer { std::filesystem::path(binding.texturePath)); textureBinding.textureBindID[id] = binding.bindingID; } + + */ } template @@ -44,6 +50,8 @@ namespace Deer { TextureBindingComponent const& textureBinding) { std::vector bindings; + // TO IMPLEMENT + /* for (int x = 0; x < MAX_TEXTURE_BINDINGS; x++) { if (textureBinding.textureAssetID[x] != 0) { bindings.push_back(TextureBinding( @@ -57,5 +65,6 @@ namespace Deer { return a.bindingID < b.bindingID; }); archive(cereal::make_nvp("bindings", bindings)); + */ } } \ No newline at end of file diff --git a/Deer/src/DeerRender/Voxels/ChunkUpdateQueue.cpp b/Deer/src/DeerRender/Voxels/ChunkUpdateQueue.cpp index 1ed65ac..f2d5578 100755 --- a/Deer/src/DeerRender/Voxels/ChunkUpdateQueue.cpp +++ b/Deer/src/DeerRender/Voxels/ChunkUpdateQueue.cpp @@ -16,6 +16,14 @@ namespace Deer { return chunkID; } + void ChunkUpdateQueue::reset() { + while (!m_updateOrder.empty()) { + m_updateOrder.pop(); + } + + m_containingChunks.clear(); + } + bool ChunkUpdateQueue::hasChunk() { return m_updateOrder.size() > 0; } diff --git a/Deer/src/DeerRender/Voxels/VoxelWorld.cpp b/Deer/src/DeerRender/Voxels/VoxelWorld.cpp index 3cef965..8ddd821 100755 --- a/Deer/src/DeerRender/Voxels/VoxelWorld.cpp +++ b/Deer/src/DeerRender/Voxels/VoxelWorld.cpp @@ -7,6 +7,8 @@ #include "Deer/Memory.h" #include "Deer/Voxel.h" #include "Deer/Voxels/Chunk.h" +#include "Deer/Voxels/VoxelWorldData.h" + #include "DeerRender/Render/Render.h" #include "DeerRender/Render/RenderUtils.h" #include "DeerRender/Render/Texture.h" @@ -18,30 +20,36 @@ namespace Deer { VoxelLight VoxelWorld::readLight(VoxelCordinates coords) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + ChunkID chunkID; ChunkVoxelID chunkVoxelID; extractChunkCordinates(coords, chunkID, chunkVoxelID); - if (!m_worldProps.isValid(chunkID)) return lightVoxel; + if (!worldProps.isValid(chunkID)) return lightVoxel; - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; return chunk.readLight(chunkVoxelID); } VoxelLight& VoxelWorld::modLight(VoxelCordinates coords) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + ChunkID chunkID; ChunkVoxelID chunkVoxelID; extractChunkCordinates(coords, chunkID, chunkVoxelID); - if (!m_worldProps.isValid(chunkID)) return lightVoxel; + if (!worldProps.isValid(chunkID)) return lightVoxel; - m_renderData->chunkQueue.addChunk(chunkID); + chunkQueue.addChunk(chunkID); - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; return chunk.modLight(chunkVoxelID); } void VoxelWorld::render(const SceneCamera& camera) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + glm::mat4 camMatrix = glm::inverse(camera.transform.getMatrix()); glm::mat4 projectionMatrix = camera.camera.getMatrix(); glm::mat4 invertZ = glm::scale(glm::mat4(1.0f), glm::vec3(1, 1, -1)); @@ -61,11 +69,11 @@ namespace Deer { shader->uploadUniformInt("u_textureSize", DataStore::getVoxelTextureAtlasSize()); - for (int x = 0; x < m_worldProps.getChunkCount(); x++) { - ChunkRender& chunkRender = m_renderData->chunksRender[x]; + for (int x = 0; x < worldProps.getChunkCount(); x++) { + ChunkRender& chunkRender = chunksRender[x]; if (!chunkRender.hasData) continue; - ChunkID chunkID = m_worldProps.getChunkID(x); + ChunkID chunkID = worldProps.getChunkID(x); chunkRender.solidVoxel->bind(); shader->uploadUniformInt("u_chunkID_x", chunkID.x); diff --git a/Deer/src/DeerRender/Voxels/VoxelWorldRenderData.cpp b/Deer/src/DeerRender/Voxels/VoxelWorldRenderData.cpp new file mode 100644 index 0000000..c3218d0 --- /dev/null +++ b/Deer/src/DeerRender/Voxels/VoxelWorldRenderData.cpp @@ -0,0 +1,39 @@ +#include "Deer/VoxelWorld.h" +#include "Deer/Voxels/Chunk.h" +#include "DeerRender/Voxels/VoxelWorldRenderData.h" + +namespace Deer { + namespace VoxelWorld { + // Chunk render data + Scope chunksRender; + ChunkUpdateQueue chunkQueue; + + // Voxel creation data + std::vector indices; + std::vector vertexData; + std::queue ambientLightPropagation; + std::queue voxelLightPropagation; + std::vector tmp_voxelLightSource; + } + + void VoxelWorld::clearRenderVars() { + chunksRender.reset(); + chunkQueue.reset(); + + indices.clear(); + vertexData.clear(); + + while (!ambientLightPropagation.empty()) { + ambientLightPropagation.pop(); + } + while (!voxelLightPropagation.empty()) { + voxelLightPropagation.pop(); + } + + tmp_voxelLightSource.clear(); + } + + void VoxelWorld::initializeRenderVars(const VoxelWorldProps& props) { + chunksRender = MakeScope(props.getChunkCount()); + } +} // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerRender/Voxels/VoxelWorldRenderData.h b/Deer/src/DeerRender/Voxels/VoxelWorldRenderData.h index b2109e6..5d7c80a 100644 --- a/Deer/src/DeerRender/Voxels/VoxelWorldRenderData.h +++ b/Deer/src/DeerRender/Voxels/VoxelWorldRenderData.h @@ -6,6 +6,7 @@ #include "Deer/Memory.h" #include "Deer/Voxel.h" #include "DeerRender/Render/VertexArray.h" +#include "Deer/VoxelWorld.h" namespace Deer { struct ChunkRender { @@ -38,6 +39,7 @@ namespace Deer { public: // TODO: Add priority void addChunk(ChunkID); + void reset(); ChunkID pullChunk(); bool hasChunk(); @@ -46,20 +48,21 @@ namespace Deer { std::unordered_set m_containingChunks; }; - struct VoxelWorldRenderData { - VoxelWorldRenderData(size_t chunkCount) { - chunksRender = MakeScope(chunkCount); - } + namespace VoxelWorld { + // Chunk render data + extern Scope chunksRender; + extern ChunkUpdateQueue chunkQueue; + + // Voxel creation data + extern std::vector indices; + extern std::vector vertexData; - // Chunk render data - Scope chunksRender; - ChunkUpdateQueue chunkQueue; + // Voxel temp light variables + extern std::queue ambientLightPropagation; + extern std::queue voxelLightPropagation; + extern std::vector tmp_voxelLightSource; - // Voxel creation data - std::vector indices; - std::vector vertexData; - std::queue ambientLightPropagation; - std::queue voxelLightPropagation; - std::vector tmp_voxelLightSource; - }; + void clearRenderVars(); + void initializeRenderVars(const VoxelWorldProps& props); + } } // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerRender/Voxels/VoxelWorld_AmbientLightPropagation.cpp b/Deer/src/DeerRender/Voxels/VoxelWorld_AmbientLightPropagation.cpp index 0da6334..f306f64 100755 --- a/Deer/src/DeerRender/Voxels/VoxelWorld_AmbientLightPropagation.cpp +++ b/Deer/src/DeerRender/Voxels/VoxelWorld_AmbientLightPropagation.cpp @@ -4,6 +4,8 @@ #include "Deer/Asset.h" #include "Deer/Components.h" +#include "Deer/Voxels/VoxelWorldData.h" + #include "DeerRender/Render/Render.h" #include "DeerRender/Render/RenderUtils.h" #include "DeerRender/Render/Texture.h" @@ -38,8 +40,8 @@ namespace Deer { } maxHeightSorroundings++; - if (maxHeightSorroundings >= CHUNK_SIZE_Y * m_worldProps.chunkSizeY) - maxHeightSorroundings = CHUNK_SIZE_Y * m_worldProps.chunkSizeY - 1; + if (maxHeightSorroundings >= CHUNK_SIZE_Y * worldProps.chunkSizeY) + maxHeightSorroundings = CHUNK_SIZE_Y * worldProps.chunkSizeY - 1; ChunkID chunkID; ChunkVoxelID chunkVoxelID; @@ -49,8 +51,8 @@ namespace Deer { (xPos == minX) || (xPos == maxX) || (zPos == minZ) || (zPos == maxZ); - if (xPos == 0 || zPos == 0 || xPos == CHUNK_SIZE_X * m_worldProps.chunkSizeX - 1 - || zPos == CHUNK_SIZE_Z * m_worldProps.chunkSizeZ - 1) + if (xPos == 0 || zPos == 0 || xPos == CHUNK_SIZE_X * worldProps.chunkSizeX - 1 + || zPos == CHUNK_SIZE_Z * worldProps.chunkSizeZ - 1) isPositionEdge = false; // All light voxelsInfo under the max height must be put to 0 ambient light and above to 255 @@ -61,7 +63,7 @@ namespace Deer { // Empty the ilumination for (; yPos < maxHeight; yPos++) { extractChunkCordinates(xPos, yPos, zPos, chunkID, chunkVoxelID); - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; VoxelLight& voxelLight = chunk.modLight(chunkVoxelID); voxelLight.ambient_light = 0; @@ -70,30 +72,30 @@ namespace Deer { // Add to queue for (; yPos < maxHeight; yPos++) { extractChunkCordinates(xPos, yPos, zPos, chunkID, chunkVoxelID); - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; VoxelLight voxelLight = chunk.readLight(chunkVoxelID); if (voxelLight.ambient_light > 0) - m_renderData->ambientLightPropagation.push(VoxelCordinates(xPos, yPos, zPos)); + ambientLightPropagation.push(VoxelCordinates(xPos, yPos, zPos)); } } // Fill with light voxelsInfo and add queue to update light propagation for (; yPos < maxHeightSorroundings; yPos++) { extractChunkCordinates(xPos, yPos, zPos, chunkID, chunkVoxelID); - Chunk& chunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& chunk = chunks[worldProps.getWorldChunkID(chunkID)]; VoxelLight& voxelLight = chunk.modLight(chunkVoxelID); voxelLight.ambient_light = 255; - m_renderData->ambientLightPropagation.push(VoxelCordinates(xPos, yPos, zPos)); + ambientLightPropagation.push(VoxelCordinates(xPos, yPos, zPos)); } - modLayerVoxel(xPos, zPos).ambient_light_height = CHUNK_SIZE_Y * m_worldProps.chunkSizeY; + modLayerVoxel(xPos, zPos).ambient_light_height = CHUNK_SIZE_Y * worldProps.chunkSizeY; } } //Resolve ambient light propagation - while (!m_renderData->ambientLightPropagation.empty()) { + while (!ambientLightPropagation.empty()) { resolveNextAmbientLightPropagation(); } } @@ -106,17 +108,17 @@ namespace Deer { int maxZ = z + 16; minX = (minX < 0) ? 0 : minX; - maxX = (maxX >= m_worldProps.chunkSizeX * CHUNK_SIZE_X) ? m_worldProps.chunkSizeX * CHUNK_SIZE_X - 1 : maxX; + maxX = (maxX >= worldProps.chunkSizeX * CHUNK_SIZE_X) ? worldProps.chunkSizeX * CHUNK_SIZE_X - 1 : maxX; minZ = (minZ < 0) ? 0 : minZ; - maxZ = (maxZ >= m_worldProps.chunkSizeZ * CHUNK_SIZE_Z) ? m_worldProps.chunkSizeZ * CHUNK_SIZE_Z - 1 : maxZ; + maxZ = (maxZ >= worldProps.chunkSizeZ * CHUNK_SIZE_Z) ? worldProps.chunkSizeZ * CHUNK_SIZE_Z - 1 : maxZ; bakeAmbientLight(minX, maxX, minZ, maxZ); } void VoxelWorld::resolveNextAmbientLightPropagation() { - VoxelCordinates position = m_renderData->ambientLightPropagation.front(); - m_renderData->ambientLightPropagation.pop(); + VoxelCordinates position = ambientLightPropagation.front(); + ambientLightPropagation.pop(); LayerVoxel& layerVoxel = modLayerVoxel(position.x, position.z); @@ -143,7 +145,7 @@ namespace Deer { if (nextLight.ambient_light < nextLightMinValue) { nextLight.ambient_light = nextLightMinValue; - m_renderData->ambientLightPropagation.push(next); + ambientLightPropagation.push(next); } } @@ -172,7 +174,7 @@ namespace Deer { if (nextLight.ambient_light < nextLightMinValue) { nextLight.ambient_light = nextLightMinValue; - m_renderData->ambientLightPropagation.push(next); + ambientLightPropagation.push(next); } } } diff --git a/Deer/src/DeerRender/Voxels/VoxelWorld_SolidVoxelGeneration.cpp b/Deer/src/DeerRender/Voxels/VoxelWorld_SolidVoxelGeneration.cpp index 5a04e0f..a070b7d 100755 --- a/Deer/src/DeerRender/Voxels/VoxelWorld_SolidVoxelGeneration.cpp +++ b/Deer/src/DeerRender/Voxels/VoxelWorld_SolidVoxelGeneration.cpp @@ -3,6 +3,8 @@ #include "Deer/Components.h" #include "Deer/VoxelWorld.h" #include "Deer/Voxels/Chunk.h" +#include "Deer/Voxels/VoxelWorldData.h" + #include "DeerRender/Render/Render.h" #include "DeerRender/Render/RenderUtils.h" #include "DeerRender/Render/Texture.h" @@ -13,12 +15,14 @@ namespace Deer { void VoxelWorld::bakeNextChunk() { - if (!m_renderData->chunkQueue.hasChunk()) return; + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + + if (!chunkQueue.hasChunk()) return; // Pull the next chunk to render - ChunkID nextChunk = m_renderData->chunkQueue.pullChunk(); - m_renderData->vertexData.clear(); - m_renderData->indices.clear(); + ChunkID nextChunk = chunkQueue.pullChunk(); + vertexData.clear(); + indices.clear(); // For each voxel for (int x = 0; x < CHUNK_SIZE_X; x++) { @@ -33,11 +37,11 @@ namespace Deer { Ref va = VertexArray::create(); va->bind(); Ref vb = VertexBuffer::create( - m_renderData->vertexData.data(), - m_renderData->vertexData.size() * sizeof(SolidVoxelVertexData)); + vertexData.data(), + vertexData.size() * sizeof(SolidVoxelVertexData)); Ref ib = - IndexBuffer::create(m_renderData->indices.data(), - m_renderData->indices.size() * sizeof(uint32_t), + IndexBuffer::create(indices.data(), + indices.size() * sizeof(uint32_t), IndexDataType::Unsigned_Int); BufferLayout layout( @@ -81,14 +85,14 @@ namespace Deer { va->setIndexBuffer(ib); // Update the data to the chunk render - int id = m_worldProps.getWorldChunkID(nextChunk); - ChunkRender& chunkRender = m_renderData->chunksRender[id]; + int id = worldProps.getWorldChunkID(nextChunk); + ChunkRender& chunkRender = chunksRender[id]; chunkRender.solidVoxel = va; chunkRender.hasData = true; } void VoxelWorld::genSolidVoxel(ChunkID chunkID, ChunkVoxelID chunkVoxelID) { - Chunk& workingChunk = m_chunks[m_worldProps.getWorldChunkID(chunkID)]; + Chunk& workingChunk = chunks[worldProps.getWorldChunkID(chunkID)]; Voxel voxel = workingChunk.readVoxel(chunkVoxelID); if (!voxel.isVoxelType()) return; @@ -127,7 +131,7 @@ namespace Deer { front2VoxelLight.ambient_light); // Save the vertex id for later - int vertexID = m_renderData->vertexData.size(); + int vertexID = vertexData.size(); int voxel_count[4]; @@ -230,26 +234,26 @@ namespace Deer { vertex_data.u = VERTEX_UV(X_AXIS, v); vertex_data.v = VERTEX_UV(Y_AXIS, v); - m_renderData->vertexData.push_back(vertex_data); + vertexData.push_back(vertex_data); } if (voxel_count[0] + voxel_count[3] > voxel_count[1] + voxel_count[2]) { - m_renderData->indices.push_back(vertexID); - m_renderData->indices.push_back(vertexID + 2); - m_renderData->indices.push_back(vertexID + 1); + indices.push_back(vertexID); + indices.push_back(vertexID + 2); + indices.push_back(vertexID + 1); - m_renderData->indices.push_back(vertexID + 1); - m_renderData->indices.push_back(vertexID + 2); - m_renderData->indices.push_back(vertexID + 3); + indices.push_back(vertexID + 1); + indices.push_back(vertexID + 2); + indices.push_back(vertexID + 3); } else { - m_renderData->indices.push_back(vertexID); - m_renderData->indices.push_back(vertexID + 3); - m_renderData->indices.push_back(vertexID + 1); + indices.push_back(vertexID); + indices.push_back(vertexID + 3); + indices.push_back(vertexID + 1); - m_renderData->indices.push_back(vertexID + 2); - m_renderData->indices.push_back(vertexID + 3); - m_renderData->indices.push_back(vertexID); + indices.push_back(vertexID + 2); + indices.push_back(vertexID + 3); + indices.push_back(vertexID); } } } diff --git a/Deer/src/DeerRender/Voxels/VoxelWorld_VoxelLightPropagation.cpp b/Deer/src/DeerRender/Voxels/VoxelWorld_VoxelLightPropagation.cpp index 2cdd64e..02826b0 100644 --- a/Deer/src/DeerRender/Voxels/VoxelWorld_VoxelLightPropagation.cpp +++ b/Deer/src/DeerRender/Voxels/VoxelWorld_VoxelLightPropagation.cpp @@ -1,21 +1,25 @@ #include "Deer/VoxelWorld.h" +#include "Deer/Log.h" #include "Deer/Voxels/Chunk.h" +#include "Deer/Voxels/VoxelWorldData.h" #include "DeerRender/Voxels/VoxelWorldRenderData.h" namespace Deer { void VoxelWorld::bakeVoxelLightFromPoint(VoxelCordinates coords) { - VoxelCordinates min = - VoxelCordinates(coords.x - 16, coords.y - 16, coords.z - 16); - VoxelCordinates max = - VoxelCordinates(coords.x + 16, coords.y + 16, coords.z + 16); + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); - m_worldProps.clampCordinates(min); - m_worldProps.clampCordinates(max); + VoxelCordinates min = VoxelCordinates(coords.x - 16, coords.y - 16, coords.z - 16); + VoxelCordinates max = VoxelCordinates(coords.x + 16, coords.y + 16, coords.z + 16); + + worldProps.clampCordinates(min); + worldProps.clampCordinates(max); bakeVoxelLight(min, max); } void VoxelWorld::bakeVoxelLight(VoxelCordinates min, VoxelCordinates max) { + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + // We want to make the box 1 layer smaller // For every axis, X & Y & Z for (int i = 0; i < 3; i++) { @@ -30,7 +34,7 @@ namespace Deer { extractChunkCordinates(min, minChunkID, minChunkVoxelID); extractChunkCordinates(max, maxChunkID, maxChunkVoxelID); - m_renderData->tmp_voxelLightSource.clear(); + tmp_voxelLightSource.clear(); // We want to empty the voxel light of the section first ChunkID workingChunkID; @@ -56,10 +60,10 @@ namespace Deer { : CHUNK_SIZE_Z - 1); Chunk& workingChunk = - m_chunks[m_worldProps.getWorldChunkID(workingChunkID)]; + chunks[worldProps.getWorldChunkID(workingChunkID)]; workingChunk.clearVoxelLightAndSaveSources( workingMinVoxelID, workingMaxVoxelID, workingChunkID, - m_renderData->tmp_voxelLightSource); + tmp_voxelLightSource); } } } @@ -75,10 +79,10 @@ namespace Deer { if (minZEdgeLight.b_light || minZEdgeLight.g_light || minZEdgeLight.b_light) - m_renderData->voxelLightPropagation.push(minZEdge); + voxelLightPropagation.push(minZEdge); if (maxZEdgeLight.b_light || maxZEdgeLight.g_light || maxZEdgeLight.b_light) - m_renderData->voxelLightPropagation.push(maxZEdge); + voxelLightPropagation.push(maxZEdge); } } @@ -92,10 +96,10 @@ namespace Deer { if (minYEdgeLight.b_light || minYEdgeLight.g_light || minYEdgeLight.b_light) - m_renderData->voxelLightPropagation.push(minYEdge); + voxelLightPropagation.push(minYEdge); if (maxYEdgeLight.b_light || maxYEdgeLight.g_light || maxYEdgeLight.b_light) - m_renderData->voxelLightPropagation.push(maxYEdge); + voxelLightPropagation.push(maxYEdge); } } @@ -109,14 +113,14 @@ namespace Deer { if (minXEdgeLight.b_light || minXEdgeLight.g_light || minXEdgeLight.b_light) - m_renderData->voxelLightPropagation.push(minXEdge); + voxelLightPropagation.push(minXEdge); if (maxXEdgeLight.b_light || maxXEdgeLight.g_light || maxXEdgeLight.b_light) - m_renderData->voxelLightPropagation.push(maxXEdge); + voxelLightPropagation.push(maxXEdge); } } - for (VoxelCordinates& cordinates : m_renderData->tmp_voxelLightSource) { + for (VoxelCordinates& cordinates : tmp_voxelLightSource) { VoxelLight& voxelLight = modLight(cordinates); Voxel voxel = readVoxel(cordinates); @@ -125,17 +129,19 @@ namespace Deer { voxelLight.g_light = voxelAspect.definition.colorEmission.g_value; voxelLight.b_light = voxelAspect.definition.colorEmission.b_value; - m_renderData->voxelLightPropagation.push(cordinates); + voxelLightPropagation.push(cordinates); } - while (!m_renderData->voxelLightPropagation.empty()) { + while (!voxelLightPropagation.empty()) { resolveNextVoxelLightPropagation(); } } void VoxelWorld::resolveNextVoxelLightPropagation() { - VoxelCordinates position = m_renderData->voxelLightPropagation.front(); - m_renderData->voxelLightPropagation.pop(); + DEER_CORE_ASSERT(initialized, "Voxel World is not initialized"); + + VoxelCordinates position = voxelLightPropagation.front(); + voxelLightPropagation.pop(); VoxelLight currentLight = readLight(position); bool voxelCheck[6] = {false}; @@ -188,7 +194,7 @@ namespace Deer { } if (nextVoxelModified) - m_renderData->voxelLightPropagation.push(next); + voxelLightPropagation.push(next); } return; @@ -235,7 +241,7 @@ namespace Deer { } if (nextVoxelModified) - m_renderData->voxelLightPropagation.push(next); + voxelLightPropagation.push(next); } } } // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/DeerStudio.cpp b/DeerStudio/src/DeerStudio/DeerStudio.cpp index c6b9c6a..17b78f7 100755 --- a/DeerStudio/src/DeerStudio/DeerStudio.cpp +++ b/DeerStudio/src/DeerStudio/DeerStudio.cpp @@ -10,15 +10,11 @@ #include "DeerRender/Mesh.h" #include "DeerStudio/EditorEngine.h" -#include "DeerStudio/Editor/Fonts.h" +#include "DeerStudio/Fonts.h" #include "DeerStudio/Editor/GamePanel.h" #include "DeerStudio/Editor/Icons.h" -#include "DeerStudio/Editor/PropertiesPanel.h" -#include "DeerStudio/Editor/SceneExplorer.h" #include "DeerStudio/Editor/Terrain/TerrainEditor.h" -#include "DeerStudio/Editor/TreePanel.h" #include "DeerStudio/Editor/Viewport.h" -#include "DeerStudio/Project.h" #include "Style.h" namespace Deer { @@ -51,13 +47,14 @@ namespace Deer { io.IniFilename = filenameFLoc; initializeFonts(); - setNatureStyle(); + + SetupImGuiStyle(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20)); auto m_gamePanel = Ref(new GamePanel()); Panels.push_back(m_gamePanel); - Environment& env = Project::m_scene.getMainEnviroment(); + Environment& env = Scene::environment; Entity& exampleObject = env.createEntity("Example"); MeshRenderComponent& renderComponent = exampleObject.addComponent(); @@ -72,8 +69,8 @@ namespace Deer { } void DeerStudioApplication::onShutdown() { - if (Project::m_scene.getExecutingState()) - Project::m_scene.endExecution(); + if (Scene::getExecutingState()) + Scene::endExecution(); ScriptEngine::shutdownScriptEngine(); Panels.clear(); @@ -90,10 +87,11 @@ namespace Deer { } void DeerStudioApplication::onUpdate(Timestep delta) { - if (Project::m_scene.getExecutingState()) - Project::m_scene.updateInternalVars(); - if (Project::m_scene.isVoxelWorldInitialized()) - Project::m_scene.getVoxelWorld().bakeNextChunk(); + if (Scene::getExecutingState()) + Scene::tick(); + + if (VoxelWorld::isInitialized()) + VoxelWorld::bakeNextChunk(); } void DeerStudioApplication::onEvent(Event& e) { @@ -145,13 +143,10 @@ namespace Deer { // ---- PanelS ----- EditorEngine::execute(); - TreePanel::onImgui(); - PropertiesPanel::onImgui(); TerrainEditor::onImGui(); viewport_onImGui(); // ---- PanelS ----- - - Project::m_scene.getMainGizmoRenderer().refresh(); + Scene::gizmoRenderer.refresh(); ImGui::End(); } @@ -178,21 +173,21 @@ namespace Deer { if (ImGui::BeginMenu("Scene")) { if (ImGui::MenuItem("New scene")) { // TODO - Project::m_scene.clear(); - DataStore::exportScene(Project::m_scene, "new_scene"); + Scene::clear(); + DataStore::exportScene("new_scene"); } // if (Project::m_sceneSerializer->getCurrentScenePath() != // "_NO_INITIALIZED_" && ImGui::MenuItem("Save scene")) { // Project::m_sceneSerializer->serialize(Project::m_sceneSerializer->getCurrentScenePath()); // } if (ImGui::MenuItem("Save scene")) { - DataStore::exportScene(Project::m_scene, "saved_scene"); + DataStore::exportScene("saved_scene"); } if (ImGui::MenuItem("Save scene as...")) { // TODO } if (ImGui::MenuItem("Load scene")) { - // Project::m_scene.swap(DataStore::loadScene("new_scene")); + // Scene::swap(DataStore::loadScene("new_scene")); // DataStore::exportScene(Project::m_scene, // "new_scene"); } @@ -232,7 +227,7 @@ namespace Deer { if (ImGui::BeginMenu("Scripts")) { if (ImGui::MenuItem("Reload scripts") && - !Project::m_scene.getExecutingState()) { + !Scene::getExecutingState()) { ScriptEngine::shutdownScriptEngine(); ScriptEngine::compileScriptEngine( std::filesystem::path("scripts")); diff --git a/DeerStudio/src/DeerStudio/Editor/AssetManagerPanel.cpp b/DeerStudio/src/DeerStudio/Editor/AssetManagerPanel.cpp deleted file mode 100755 index b73f5f4..0000000 --- a/DeerStudio/src/DeerStudio/Editor/AssetManagerPanel.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include "AssetManagerPanel.h" -#include "DeerStudio/Project.h" - -#include "Deer/Log.h" -#include "Deer/Asset.h" - -#include "DeerRender/Render/Texture.h" -#include "DeerStudio/Editor/ActiveEntity.h" - -#include "imgui.h" - -#include - -#ifdef WINDOWS -// WINDOWS SPECIFIC -#include -#include -#endif - -namespace Deer { - void openFileExplorer(const std::string& relativePath) { - #ifdef WINDOWS - // Convert std::string to std::wstring - std::wstring widePath(relativePath.begin(), relativePath.end()); - wchar_t buffer[MAX_PATH]; - GetFullPathNameW(widePath.c_str(), MAX_PATH, buffer, nullptr); - - // Open the file explorer at the given path - ShellExecuteW(nullptr, L"open", buffer, nullptr, nullptr, SW_SHOW); - #endif - } - - namespace fs = std::filesystem; - - AssetManagerPanel::AssetManagerPanel() - : m_currentPath(DataStore::rootPath / "assets"){ - - m_folderIcon = Texture2D::create("editor/icons/folder.png"); - m_fileIcon = Texture2D::create("editor/icons/file.png"); - m_scneIcon = Texture2D::create("editor/icons/scene.png"); - m_objectIcon = Texture2D::create("editor/icons/object.png"); - m_shaderIcon = Texture2D::create("editor/icons/shader.png"); - } - - void AssetManagerPanel::onImGui() { - m_clickHandled = false; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(30, 30)); - ImGui::Begin("Assets"); - ImGui::PopStyleVar(); - - float width = ImGui::GetWindowContentRegionWidth(); - - if (width < m_iconMinSize + 40) { - ImGui::Text("Window too small"); - ImGui::End(); - return; - } - - int cols = (int)ceilf(width / (m_iconMinSize + 40)); - float componentWidth = width / (float)cols; - - if (m_currentPath != "assets") { - if (ImGui::Button(m_currentPath.parent_path().string().c_str())) - m_currentPath = m_currentPath.parent_path(); - } - else - ImGui::Button("assets"); - - ImGui::SameLine(); - - if (ImGui::Button("Open File Explorer")) - openFileExplorer(m_currentPath.string()); - - try { - ImGui::Columns(cols, 0, false); - for (const auto& entry : fs::directory_iterator(m_currentPath)) { - if (entry.is_directory()) - drawFolder(entry.path()); - else - drawFile(entry.path()); - - float cursorOffset = (m_iconMinSize - ImGui::CalcTextSize(entry.path().filename().string().c_str()).x) / 2; - ImGui::SetCursorPos(ImVec2(cursorOffset + ImGui::GetCursorPos().x, ImGui::GetCursorPos().y)); - ImGui::Text("%s",entry.path().filename().string().c_str()); - - ImGui::NextColumn(); - } - ImGui::Columns(); - } - catch (const fs::filesystem_error& err) { - DEER_CORE_ERROR("Asset manager filesystem error"); - } - - - if (!m_clickHandled && ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) && - ImGui::IsMouseClicked(ImGuiMouseButton_Right) && - !ImGui::IsAnyItemHovered()) { - - ImGui::OpenPopup("AssetManagerPopUp"); - } - updateContextMenu(); - - ImGui::End(); - } - - void AssetManagerPanel::drawFolder(const std::filesystem::path& path) { - ImGui::Image((void*)(uint64_t)m_folderIcon->getTextureID(), ImVec2(m_iconMinSize , m_iconMinSize), ImVec2(0, 1), ImVec2(1, 0)); - - if (ImGui::IsItemClicked(0) && ImGui::IsMouseDoubleClicked(0)) { - m_currentPath = path; - } - } - - void AssetManagerPanel::updateContextMenu() { - - if (ImGui::BeginPopup("AssetManagerPopUp")) { - if (ImGui::MenuItem("New Folder")) { - - std::filesystem::path path = m_currentPath / "newFolder"; - std::filesystem::create_directory(path); - } - - ImGui::EndPopup(); - } - - } - - void AssetManagerPanel::drawFile(const std::filesystem::path& path) { - std::string extension = path.filename().extension().string(); - - if (extension == ".dscn") { - ImGui::Image((void*)(uint64_t)m_scneIcon->getTextureID(), ImVec2(m_iconMinSize, m_iconMinSize), ImVec2(0, 1), ImVec2(1, 0)); - - // Open scene - if (ImGui::IsItemClicked(0) && ImGui::IsMouseDoubleClicked(0)) { - try { - m_currentScenePath = path; - } - catch ( ... ) { - DEER_CORE_ERROR("Error while loading scene {0}, file might be corrupt", path.string().c_str()); - } - } - } else if (extension == ".obj") { - ImGui::Image((void*)(uint64_t)m_objectIcon->getTextureID(), ImVec2(m_iconMinSize, m_iconMinSize), ImVec2(0, 1), ImVec2(1, 0)); - - if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { - std::string pathString = path.string(); - ImGui::SetDragDropPayload("_MESH", pathString.c_str(), pathString.size() + 1); - ImGui::Text("%s", path.string().c_str()); - ImGui::EndDragDropSource(); - } - } else if (extension == ".glsl") { - ImGui::Image((void*)(uint64_t)m_shaderIcon->getTextureID(), ImVec2(m_iconMinSize, m_iconMinSize), ImVec2(0, 1), ImVec2(1, 0)); - - if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { - std::string pathString = path.string(); - ImGui::SetDragDropPayload("_SHADER", pathString.c_str(), pathString.size() + 1); - ImGui::Text("%s", path.string().c_str()); - ImGui::EndDragDropSource(); - } - } else if (extension == ".png" || extension == ".jpg" || extension == ".jpeg") { - uint32_t textureID = AssetManager::loadAsset(path.string()); - Asset& textureAsset = AssetManager::getAsset(textureID); - - ImGui::Image((void*)(uint64_t)textureAsset.value->getTextureID(), ImVec2(m_iconMinSize, m_iconMinSize), ImVec2(0, 1), ImVec2(1, 0)); - - if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { - std::string pathString = path.string(); - ImGui::SetDragDropPayload("_TEXTURE2D", pathString.c_str(), pathString.size() + 1); - ImGui::Text("%s", path.string().c_str()); - ImGui::EndDragDropSource(); - } - } else { - ImGui::Image((void*)(uint64_t)m_fileIcon->getTextureID(), ImVec2(m_iconMinSize, m_iconMinSize), ImVec2(0, 1), ImVec2(1, 0)); - } - - } -} diff --git a/DeerStudio/src/DeerStudio/Editor/AssetManagerPanel.h b/DeerStudio/src/DeerStudio/Editor/AssetManagerPanel.h deleted file mode 100755 index c3dc104..0000000 --- a/DeerStudio/src/DeerStudio/Editor/AssetManagerPanel.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "DeerStudio/Editor/EditorPanel.h" - -#include "Deer/Memory.h" - -#include - -namespace Deer { - class Texture2D; - class DeerStudioLayer; - class SceneSerializer; - - class AssetManagerPanel : public EditorPanel{ - public: - AssetManagerPanel(); - void onImGui() override; - private: - void drawFolder(const std::filesystem::path&); - void drawFile(const std::filesystem::path&); - void updateContextMenu(); - private: - std::filesystem::path m_currentScenePath; - - std::filesystem::path m_currentPath; // Assets/path... - Ref m_folderIcon; - Ref m_fileIcon; - Ref m_scneIcon; - Ref m_objectIcon; - Ref m_shaderIcon; - - int m_iconMinSize = 110; - bool m_clickHandled = false; - }; -} - diff --git a/DeerStudio/src/DeerStudio/Editor/GamePanel.cpp b/DeerStudio/src/DeerStudio/Editor/GamePanel.cpp index 3a51648..9367bd8 100755 --- a/DeerStudio/src/DeerStudio/Editor/GamePanel.cpp +++ b/DeerStudio/src/DeerStudio/Editor/GamePanel.cpp @@ -5,7 +5,6 @@ #include "Deer/Enviroment.h" #include "Deer/Scene.h" #include "Deer/ScriptEngine.h" -#include "DeerStudio/Project.h" #include "imgui.h" namespace Deer { @@ -20,23 +19,23 @@ namespace Deer { ImGui::Begin("Game Window"); ImGui::PopStyleVar(); - Environment& environment = Project::m_scene.getMainEnviroment(); + Environment& environment = Scene::environment; uint32_t cameraUID = environment.tryGetMainCamera(); if (cameraUID == 0) { ImGui::TextColored(ImVec4(.3f, .3f, .8f, 1.0f), "There is no camera"); - if (!Project::m_scene.getExecutingState()) { + if (!Scene::getExecutingState()) { if (ScriptEngine::isCompilationValid() && ImGui::Button("Execute")) { - DataStore::exportRuntimeScene(Project::m_scene); - Project::m_scene.beginExecution(); + DataStore::exportRuntimeScene(); + Scene::beginExecution(); } } else { if (ImGui::Button("Stop")) { - Project::m_scene.endExecution(); - DataStore::importRuntimeScene(Project::m_scene); + Scene::endExecution(); + DataStore::importRuntimeScene(); } } @@ -67,7 +66,7 @@ namespace Deer { unsigned char clearColor[4]{0, 0, 0, 255}; m_frameBuffer->clearBuffer(0, &clearColor); - Project::m_scene.render(); + Scene::render(); m_frameBuffer->unbind(); ImGui::Image((void*)(uint64_t)m_frameBuffer->getTextureBufferID(0), @@ -75,16 +74,16 @@ namespace Deer { ImGui::SetCursorPos(cursorPos); - if (!Project::m_scene.getExecutingState()) { + if (!Scene::getExecutingState()) { if (ScriptEngine::isCompilationValid() && ImGui::Button("Execute")) { - DataStore::exportRuntimeScene(Project::m_scene); - Project::m_scene.beginExecution(); + DataStore::exportRuntimeScene(); + Scene::beginExecution(); } } else { if (ImGui::Button("Stop")) { - Project::m_scene.endExecution(); - DataStore::importRuntimeScene(Project::m_scene); + Scene::endExecution(); + DataStore::importRuntimeScene(); } } diff --git a/DeerStudio/src/DeerStudio/Editor/GamePanel.h b/DeerStudio/src/DeerStudio/Editor/GamePanel.h index 6973f75..c4b1de8 100755 --- a/DeerStudio/src/DeerStudio/Editor/GamePanel.h +++ b/DeerStudio/src/DeerStudio/Editor/GamePanel.h @@ -7,7 +7,6 @@ #include "glm/glm.hpp" namespace Deer { - class Scene; class FrameBuffer; class GamePanel : public EditorPanel { diff --git a/DeerStudio/src/DeerStudio/Editor/PropertiesPanel.cpp b/DeerStudio/src/DeerStudio/Editor/PropertiesPanel.cpp deleted file mode 100755 index ce1e59d..0000000 --- a/DeerStudio/src/DeerStudio/Editor/PropertiesPanel.cpp +++ /dev/null @@ -1,465 +0,0 @@ -#include "PropertiesPanel.h" - -#include "Deer/Asset.h" -#include "Deer/ScriptEngine.h" -#include "DeerRender/Input.h" -#include "DeerRender/Render/Texture.h" -#include "DeerStudio/Editor/Fonts.h" -#include "DeerStudio/Project.h" -#include "imgui.h" - -namespace Deer { - namespace PropertiesPanel { - void addComponentContext(); - - template - bool collapsingComponentHeader(const std::string& componentName, - bool canDelete = true); - - template - void addComponentButton(const std::string& componentName); - - void addScriptButton(const std::string& scriptID); - - void drawMagicSlider(const std::string& text, float* value); - void drawMagicSlider3f(const std::string& text, float* value, - float defaultValue = 0); - } // namespace PropertiesPanel - - bool* getIsEditingState(ImGuiID id) { - ImGuiStorage* storage = ImGui::GetStateStorage(); - void* ptr = storage->GetVoidPtr(id); - if (ptr) return (bool*)ptr; - - // If state doesn't exist, initialize it - bool* state = new bool(false); - storage->SetVoidPtr(id, state); - return state; - } - - void PropertiesPanel::onImgui() { - ImGui::Begin("Properties"); - - if (ActiveEntity::count() == 0) { - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1), - "No entity selected"); - ImGui::End(); - return; - } - - Entity& activeEntity = ActiveEntity::getEntity(0); - ImGui::PushFont(titleText); - - auto& tag = activeEntity.getComponent(); - if (tag.tag == "") - ImGui::Text("-"); - else - ImGui::Text("%s", tag.tag.c_str()); - - ImGui::PopFont(); - ImGui::Separator(); - - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1), "Id : %u", - tag.entityUID); - - if (activeEntity.isRoot()) { - ImGui::End(); - return; - } - - ImGui::SameLine(); - addComponentContext(); - ImGui::Dummy(ImVec2(0.0f, 10.0f)); - - if (collapsingComponentHeader("Transform Component", - false)) { - auto& transform = activeEntity.getComponent(); - - drawMagicSlider3f("Position", &transform.position.x, 0); - glm::vec3 rotation = transform.getEulerAngles(); - glm::vec3 lastRotation = rotation; - drawMagicSlider3f("Rotation", &rotation.x, 0); - if (rotation != lastRotation) transform.setEulerAngles(rotation); - drawMagicSlider3f("Scale", &transform.scale.x, 1); - - if (rotation != lastRotation) transform.setEulerAngles(rotation); - ImGui::Dummy(ImVec2(0.0f, 5.0f)); - } - - if (collapsingComponentHeader("Script Component")) { - auto& script = activeEntity.getComponent(); - - // ------ MESH ----- - std::string scriptName; - if (script.scriptID == "") - scriptName = " null "; - else - scriptName = script.scriptID; - - ImGui::Text("Script : "); - ImGui::SameLine(); - ImGui::Button(scriptName.c_str()); - - ImGui::Dummy(ImVec2(0.0f, 5.0f)); - } - - if (collapsingComponentHeader( - "Mesh Render Component")) { - auto& mesh = activeEntity.getComponent(); - - // ------ MESH ----- - std::string meshName; - if (mesh.meshAssetID == 0) - meshName = " null "; - else - meshName = AssetManager::getAssetLocation(mesh.meshAssetID) - .generic_string(); - - ImGui::Text("Mesh : "); - ImGui::SameLine(); - ImGui::Button(meshName.c_str()); - if (ImGui::BeginDragDropTarget()) { - if (const ImGuiPayload* payload = - ImGui::AcceptDragDropPayload("_MESH")) { - std::string receivedData = - std::string((const char*)payload->Data); - mesh.meshAssetID = - AssetManager::loadAsset(receivedData); - } - ImGui::EndDragDropTarget(); - } - - // ------ Shader ----- - std::string shaderName; - if (mesh.shaderAssetID == 0) - shaderName = " null "; - else - shaderName = AssetManager::getAssetLocation(mesh.shaderAssetID) - .generic_string(); - - ImGui::Text("Shader : "); - ImGui::SameLine(); - ImGui::Button(shaderName.c_str()); - if (ImGui::BeginDragDropTarget()) { - if (const ImGuiPayload* payload = - ImGui::AcceptDragDropPayload("_SHADER")) { - std::string receivedData = - std::string((const char*)payload->Data); - mesh.shaderAssetID = - AssetManager::loadAsset(receivedData); - } - ImGui::EndDragDropTarget(); - } - - ImGui::Dummy(ImVec2(0.0f, 5.0f)); - } - - if (collapsingComponentHeader( - "Texture Binding Component")) { - TextureBindingComponent& textureBinding = - activeEntity.getComponent(); - - int textureBindingCount = 0; - for (int x = 0; x < MAX_TEXTURE_BINDINGS; x++) { - if (textureBinding.textureAssetID[x] == 0) continue; - - ImGui::PushID(x); - - textureBindingCount++; - - std::string textureBindingName = - AssetManager::getAssetLocation( - textureBinding.textureAssetID[x]) - .generic_string(); - int currentID = textureBinding.textureBindID[x]; - - ImGui::Text("Texture : "); - ImGui::SameLine(); - ImGui::Button(textureBindingName.c_str()); - - if (ImGui::BeginDragDropTarget()) { - if (const ImGuiPayload* payload = - ImGui::AcceptDragDropPayload("_TEXTURE2D")) { - std::string receivedData = - std::string((const char*)payload->Data); - - textureBinding.textureAssetID[x] = - AssetManager::loadAsset( - std::filesystem::path(receivedData)); - } - ImGui::EndDragDropTarget(); - } - - ImGui::Text("Binding location"); - ImGui::SameLine(); - ImGui::InputInt("#bindingInputID", ¤tID, 0); - - currentID = (currentID < 0) ? 0 - : (currentID > 12) ? 12 - : currentID; - textureBinding.textureBindID[x] = currentID; - - if (ImGui::Button("Delete texture binding")) - textureBinding.textureAssetID[x] = 0; - - ImGui::Spacing(); - ImGui::PopID(); - } - - ImGui::Spacing(); - - if (textureBindingCount < 4) { - ImGui::Button("Add texture binding"); - - if (ImGui::BeginDragDropTarget()) { - if (const ImGuiPayload* payload = - ImGui::AcceptDragDropPayload("_TEXTURE2D")) { - std::string receivedData = - std::string((const char*)payload->Data); - - for (int x = 0; x < 4; x++) { - if (textureBinding.textureAssetID[x] != 0) continue; - - textureBinding.textureAssetID[x] = - AssetManager::loadAsset( - std::filesystem::path(receivedData)); - textureBinding.textureBindID[x] = 0; - break; - } - } - ImGui::EndDragDropTarget(); - } - } - - ImGui::Unindent(); - ImGui::Dummy(ImVec2(0.0f, 10.0f)); - } - - if (collapsingComponentHeader("Camera Component")) { - ImGui::Dummy(ImVec2(0.0f, 10.0f)); - ImGui::Indent(); - - auto& camera = activeEntity.getComponent(); - - uint32_t currentMainCamera = - activeEntity.getEnvironment()->tryGetMainCamera(); - if (currentMainCamera == activeEntity.getId()) - ImGui::Button("This is the main camera"); - else if (ImGui::Button("Set main camera")) { - activeEntity.getEnvironment()->setMainCamera(activeEntity); - } - - float fov = glm::degrees(camera.fov); - ImGui::SliderFloat("Fov", &fov, 1, 180); - camera.fov = glm::radians(fov); - ImGui::InputFloat("Z Near", &camera.nearZ, 0, 1000); - ImGui::InputFloat("Z Far", &camera.farZ, 1, 10000); - - ImGui::Unindent(); - ImGui::Dummy(ImVec2(0.0f, 10.0f)); - } - - ImGui::End(); - } - - void PropertiesPanel::drawMagicSlider(const std::string& text, - float* value) { - ImGuiID id = ImGui::GetID(text.c_str()); - - bool* isEditing = getIsEditingState(id); - if (*isEditing) { - if (ImGui::InputFloat(text.c_str(), value, 0.0f, 0.0f, "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue)) - *isEditing = false; - - if (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)) - *isEditing = false; - - return; - } - - ImGui::DragFloat(text.c_str(), value, 0.05f, 0.0f, 0.0f, "%.3f", - ImGuiSliderFlags_NoRoundToFormat); - - if (ImGui::IsItemHovered() && - ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) - *isEditing = true; - } - - void PropertiesPanel::drawMagicSlider3f(const std::string& text, - float* value, float defaultValue) { - ImGui::Columns(4, 0, false); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2()); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, - 0.0f); // Set FrameRounding to 0 for hard edges - - ImGui::Text("%s", text.c_str()); - - ImGui::NextColumn(); - ImGui::PushStyleColor( - ImGuiCol_Button, ImVec4(0.7f, 0.2f, 0.2f, 1.0f)); // Red background - ImGui::PushStyleColor( - ImGuiCol_ButtonHovered, - ImVec4(0.6f, 0.2f, 0.2f, 1.0f)); // Darker red when hovered - ImGui::PushStyleColor( - ImGuiCol_ButtonActive, - ImVec4(0.4f, 0.2f, 0.2f, 1.0f)); // Even darker red when active - - if (ImGui::Button((" X ##" + text).c_str())) *value = defaultValue; - - ImGui::SameLine(); - - ImGui::PopStyleColor(3); // Restore original style - - drawMagicSlider("##" + text + "_x", value); - - ImGui::PushStyleColor( - ImGuiCol_Button, - ImVec4(0.2f, 0.7f, 0.2f, 1.0f)); // Green background - ImGui::PushStyleColor( - ImGuiCol_ButtonHovered, - ImVec4(0.2f, 0.6f, 0.2f, 1.0f)); // Darker green when hovered - ImGui::PushStyleColor( - ImGuiCol_ButtonActive, - ImVec4(0.2f, 0.4f, 0.2f, 1.0f)); // Even darker green when active - - ImGui::NextColumn(); - if (ImGui::Button((" Y ##" + text).c_str())) value[1] = defaultValue; - - ImGui::SameLine(); - ImGui::PopStyleColor(3); // Restore original style - - drawMagicSlider("##" + text + "_y", &value[1]); - - ImGui::PushStyleColor( - ImGuiCol_Button, - ImVec4(0.2f, 0.2f, 0.7f, 1.0f)); // Blue background - ImGui::PushStyleColor( - ImGuiCol_ButtonHovered, - ImVec4(0.2f, 0.2f, 0.6f, 1.0f)); // Darker blue when hovered - ImGui::PushStyleColor( - ImGuiCol_ButtonActive, - ImVec4(0.2f, 0.2f, 0.4f, 1.0f)); // Even darker blue when active - - ImGui::NextColumn(); - if (ImGui::Button((" Z ##" + text).c_str())) value[2] = defaultValue; - - ImGui::SameLine(); - ImGui::PopStyleColor(3); // Restore original style - - drawMagicSlider("##" + text + "_z", &value[2]); - ImGui::Columns(); - ImGui::PopStyleVar(2); - } - - void PropertiesPanel::addComponentContext() { - float buttonWidth = - ImGui::CalcTextSize(" + add Component ").x; // Example button width - float windowWidth = ImGui::GetWindowSize().x; - float availableWidth = windowWidth - ImGui::GetCursorPosX(); - - // Place button at the right, with some padding (e.g., 10px) - ImGui::SetCursorPosX(windowWidth - buttonWidth - 20); - - if (ImGui::Button( - " + add Component ")) { //, - // ImVec2(ImGui::GetWindowContentRegionWidth(), - // 40) - // Opens a popup window when the button is clicked - ImGui::OpenPopup("Add Component Popup"); - } - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10)); - ImGui::SetNextWindowSize(ImVec2(240, 200)); - // Create the popup window - if (ImGui::BeginPopup("Add Component Popup")) { - addComponentButton("Mesh Render Component"); - addComponentButton( - "Texture Binding Component"); - addComponentButton("Camera Component"); - - if (ImGui::BeginMenu("Scripts")) { - for (auto& script : ScriptEngine::getComponentScripts()) - addScriptButton(script.first.c_str()); - - ImGui::EndMenu(); - } - - ImGui::EndPopup(); // End the popup - } - ImGui::PopStyleVar(); - } - - template - inline bool PropertiesPanel::collapsingComponentHeader( - const std::string& componentName, bool canDelete) { - if (!ActiveEntity::shareComponent()) return false; - - ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_CollapsingHeader | - ImGuiTreeNodeFlags_DefaultOpen | - ImGuiTreeNodeFlags_OpenOnArrow; - bool collapsingHeader = ActiveEntity::shareComponent() && - ImGui::TreeNodeEx(componentName.c_str(), flags); - - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { - ImGui::OpenPopup(componentName.c_str()); - } - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10)); - if (ImGui::BeginPopup(componentName.c_str())) { - if (ImGui::Selectable("reset")) { - for (auto& entity : ActiveEntity::entities) - entity->getComponent() = T(); - - ImGui::CloseCurrentPopup(); - } - - if (canDelete && ImGui::Selectable("delete")) { - for (auto& entity : ActiveEntity::entities) - entity->removeComponent(); - - ImGui::CloseCurrentPopup(); - - ImGui::EndPopup(); - ImGui::PopStyleVar(); - return false; - } - - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); - - return collapsingHeader; - } - - void PropertiesPanel::addScriptButton(const std::string& scriptID) { - ImGuiSelectableFlags selectableFlag = - (ActiveEntity::shareComponent()) - ? ImGuiSelectableFlags_Disabled - : ImGuiSelectableFlags_None; - if (ImGui::Selectable(scriptID.c_str(), false, selectableFlag)) { - for (auto& entity : ActiveEntity::entities) { - if (!entity->hasComponent()) - entity->addComponent(scriptID); - } - - ImGui::CloseCurrentPopup(); - } - } - - template - void PropertiesPanel::addComponentButton( - const std::string& componentName) { - ImGuiSelectableFlags selectableFlag = - (ActiveEntity::shareComponent()) ? ImGuiSelectableFlags_Disabled - : ImGuiSelectableFlags_None; - if (ImGui::Selectable(componentName.c_str(), false, selectableFlag)) { - for (auto& entity : ActiveEntity::entities) { - if (!entity->hasComponent()) entity->addComponent(); - } - - ImGui::CloseCurrentPopup(); - } - } -} // namespace Deer diff --git a/DeerStudio/src/DeerStudio/Editor/PropertiesPanel.h b/DeerStudio/src/DeerStudio/Editor/PropertiesPanel.h deleted file mode 100755 index 862f769..0000000 --- a/DeerStudio/src/DeerStudio/Editor/PropertiesPanel.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include "Deer/Memory.h" -#include "DeerStudio/Editor/ActiveEntity.h" -#include "DeerStudio/Editor/EditorPanel.h" - -namespace Deer { - namespace PropertiesPanel { - void onImgui(); - } // namespace PropertiesPanel -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/SceneExplorer.cpp b/DeerStudio/src/DeerStudio/Editor/SceneExplorer.cpp deleted file mode 100755 index 7f0e40a..0000000 --- a/DeerStudio/src/DeerStudio/Editor/SceneExplorer.cpp +++ /dev/null @@ -1,294 +0,0 @@ -#include "SceneExplorer.h" - -#include -#include - -#include "Deer/DataStore.h" -#include "Deer/Log.h" -#include "Deer/Path.h" -#include "Deer/Scene.h" -#include "DeerRender/Render/Texture.h" -#include "DeerStudio/Editor/ActiveEntity.h" -#include "DeerStudio/Project.h" -#include "EditorUtils.h" -#include "Icons.h" -#include "imgui.h" - -namespace Deer { - Path m_currentScenePath("null"); - Path m_currentSceneName; - Path m_loadSceneName; - Path m_deleteSceneName; - Path m_dialogSceneName; - - void drawSceneExplorerFolder(const Path& path); - void drawSceneExplorerScene(const Path& path); - void saveSceneBeforeLoadingPopup(); - void sceneDialogPopup(); - - void saveSceneName(const std::string&); - void createFolderName(const std::string& name); - void saveBeforeCreatingNew(bool save); - void saveSceneNameBeforeCreatingNew(const std::string& name); - void deleteScene(); - - void openFileExplorer(const std::string& relativePath); - - void sceneExplorer_onImGUI() { - if (m_currentScenePath == "null") - m_currentScenePath = DataStore::rootPath / DEER_SCENE_PATH; - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10)); - ImGui::Begin("Scene Explorer", (bool*)0, ImGuiWindowFlags_MenuBar); - ImGui::PopStyleVar(); - - if (ImGui::BeginMenuBar()) { - if (ImGui::MenuItem("Save")) { - if (m_currentSceneName == "") - ImGui::OpenPopup("SAVE_SCENE_NAME"); - else - DataStore::exportScene(Project::m_scene, - m_currentSceneName); - } - - if (ImGui::MenuItem("Save as")) { - ImGui::OpenPopup("SAVE_SCENE_NAME"); - } - if (ImGui::MenuItem("New Scene")) { - ImGui::OpenPopup("SAVE_SCENE_BEFORE_CREATING_NEW"); - } - - if (ImGui::MenuItem("New folder")) { - ImGui::OpenPopup("CREATE_SCENE_FOLDER"); - } - - if (ImGui::MenuItem("Explorer")) { - openFileExplorer(m_currentScenePath.generic_string()); - } - - stringInputPopup("SAVE_SCENE_NAME", "Scene name"); - stringInputPopup("CREATE_SCENE_FOLDER", - "Folder name"); - saveInputPopup( - "SAVE_SCENE_BEFORE_CREATING_NEW", - "Do you want to save the scene before creating new?"); - stringInputPopup( - "SAVE_SCENE_NAME_CREATE_NEW", "Scene name"); - - ImGui::EndMenuBar(); - } - - ImGui::Text("%s", m_currentScenePath.generic_string().c_str()); - - ImGui::TextDisabled("Active Scene : "); - ImGui::SameLine(); - ImGui::TextColored(ImVec4(0.5f, 1.0f, 0.7f, 1), "%s", - m_currentSceneName.generic_string().c_str()); - - setupColumns(ICON_MIN_SIZE + 80); - - if (m_currentScenePath != DEER_SCENE_PATH) { - drawSceneExplorerFolder(".."); - - float cursorOffset = - (ICON_MIN_SIZE - ImGui::CalcTextSize("..").x) / 2; - ImGui::SetCursorPos(ImVec2(cursorOffset + ImGui::GetCursorPos().x, - ImGui::GetCursorPos().y)); - ImGui::Text(".."); - - ImGui::NextColumn(); - } - - for (const auto& entry : - std::filesystem::directory_iterator(m_currentScenePath)) { - if (entry.is_directory()) - drawSceneExplorerFolder(entry.path()); - else { - std::string extension = - entry.path().filename().extension().string(); - if (extension != ".dscn") continue; - - Path sceneName = entry.path().parent_path().lexically_relative( - DEER_SCENE_PATH) / - entry.path().stem(); - drawSceneExplorerScene(sceneName); - } - - float cursorOffset = - (ICON_MIN_SIZE - - ImGui::CalcTextSize(entry.path().stem().string().c_str()).x) / - 2; - ImGui::SetCursorPos(ImVec2(cursorOffset + ImGui::GetCursorPos().x, - ImGui::GetCursorPos().y)); - ImGui::Text("%s", entry.path().stem().string().c_str()); - - ImGui::NextColumn(); - } - ImGui::Columns(); - - saveSceneBeforeLoadingPopup(); - sceneDialogPopup(); - deleteInputPopup( - "DELETE_SCENE", "Are you sure you want to delete the scene?"); - - ImGui::End(); - } - - void drawSceneExplorerFolder(const Path& path) { - ImGui::Image((void*)(uint64_t)Icons::folder_icon->getTextureID(), - ImVec2(ICON_MIN_SIZE, ICON_MIN_SIZE), ImVec2(0, 1), - ImVec2(1, 0)); - - if (ImGui::IsItemClicked(0) && ImGui::IsMouseDoubleClicked(0)) { - if (path == "..") - m_currentScenePath = m_currentScenePath.parent_path(); - else - m_currentScenePath = path; - } - } - - void drawSceneExplorerScene(const Path& path) { - ImGui::Image((void*)(uint64_t)Icons::scene_icon->getTextureID(), - ImVec2(ICON_MIN_SIZE, ICON_MIN_SIZE), ImVec2(0, 1), - ImVec2(1, 0)); - - if (ImGui::IsItemClicked(0) && ImGui::IsMouseDoubleClicked(0)) { - ImGui::OpenPopup("SAVE_SCENE_BEFORE_LOADING"); - m_loadSceneName = path; - } - - if (ImGui::IsItemClicked(1)) { - ImGui::OpenPopup("SCENE_DIALOG"); - m_dialogSceneName = path; - } - } - - std::string sanitizeInput(const std::string& input) { - std::string sanitized; - for (char c : input) { - if (isalnum(c) || c == '_') { - sanitized += c; - } - } - return sanitized; - } - - void saveSceneBeforeLoadingPopup() { - if (ImGui::BeginPopup("SAVE_SCENE_BEFORE_LOADING")) { - if (m_currentSceneName == "") { - DataStore::loadScene(Project::m_scene, m_loadSceneName); - m_currentSceneName = m_loadSceneName; - ImGui::CloseCurrentPopup(); - } - - ImGui::Text("Do you want to save the current scene?"); - - ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(100, 255, 120, 255)); - bool save = ImGui::Button("Save"); - ImGui::PopStyleColor(); - ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 100, 120, 255)); - ImGui::SameLine(); - bool dont_save = ImGui::Button("Don't save"); - ImGui::PopStyleColor(); - ImGui::SameLine(); - bool cancel = ImGui::Button("Cancel"); - - if (save) { - ActiveEntity::clear(); - DataStore::exportScene(Project::m_scene, m_currentSceneName); - DataStore::loadScene(Project::m_scene, m_loadSceneName); - m_currentSceneName = m_loadSceneName; - ImGui::CloseCurrentPopup(); - } else if (dont_save) { - ActiveEntity::clear(); - DataStore::loadScene(Project::m_scene, m_loadSceneName); - m_currentSceneName = m_loadSceneName; - ImGui::CloseCurrentPopup(); - } - if (cancel) { - ImGui::CloseCurrentPopup(); - } - - ImGui::EndPopup(); - } - } - - void sceneDialogPopup() { - if (ImGui::BeginPopup("SCENE_DIALOG")) { - if (ImGui::MenuItem("Rename Scene")) { - ImGui::CloseCurrentPopup(); - } - - if (ImGui::MenuItem("Delete Scene")) { - ImGui::CloseCurrentPopup(); - ImGui::EndPopup(); - - ImGui::OpenPopup("DELETE_SCENE"); - m_deleteSceneName = m_dialogSceneName; - return; - } - ImGui::EndPopup(); - } - } - - // Implement delete scene - void deleteScene() {} - void createFolderName(const std::string& name) { - std::string correctInput = sanitizeInput(name); - - if (name.size() != 0) { - DataStore::createFolder(m_currentScenePath / correctInput); - } - } - void saveSceneName(const std::string& name) { - std::string correctInput = sanitizeInput(name); - - if (name.size() != 0) { - Path fullName; - if (m_currentScenePath == DEER_SCENE_PATH) - fullName = correctInput; - else - fullName = - m_currentScenePath.lexically_relative(DEER_SCENE_PATH) / - correctInput; - - m_currentSceneName = fullName; - DataStore::exportScene(Project::m_scene, fullName); - } - } - void saveBeforeCreatingNew(bool save) { - if (save) { - if (m_currentSceneName == "") { - ImGui::OpenPopup("SAVE_SCENE_NAME_CREATE_NEW"); - return; - } else { - ActiveEntity::clear(); - DataStore::exportScene(Project::m_scene, m_currentSceneName); - Project::m_scene.clear(); - m_currentSceneName = Path(); - } - } else { - ActiveEntity::clear(); - Project::m_scene.clear(); - m_currentSceneName = Path(); - } - } - void saveSceneNameBeforeCreatingNew(const std::string& name) { - std::string correctInput = sanitizeInput(name); - - if (name.size() != 0) { - Path fullName; - if (m_currentScenePath == DEER_SCENE_PATH) - fullName = correctInput; - else - fullName = - m_currentScenePath.lexically_relative(DEER_SCENE_PATH) / - correctInput; - - DataStore::exportScene(Project::m_scene, fullName); - ActiveEntity::clear(); - Project::m_scene.clear(); - m_currentSceneName = Path(); - } - } -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/SceneExplorer.h b/DeerStudio/src/DeerStudio/Editor/SceneExplorer.h deleted file mode 100755 index 2cdfe49..0000000 --- a/DeerStudio/src/DeerStudio/Editor/SceneExplorer.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -namespace Deer { - void sceneExplorer_onImGUI(); -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp index e637de6..6adbec5 100755 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp @@ -10,7 +10,6 @@ #include "DeerStudio/Editor/EditorUtils.h" #include "DeerStudio/Editor/Icons.h" #include "DeerStudio/Editor/Viewport.h" -#include "DeerStudio/Project.h" #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" #include "imgui.h" @@ -24,7 +23,7 @@ namespace Deer { void TerrainEditor::onImGui() { ImGui::Begin("Terrain Editor"); - if (!Project::m_scene.isVoxelWorldInitialized()) { + if (!VoxelWorld::isInitialized()) { ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1), "No voxel world created"); ImGui::Separator(); @@ -38,7 +37,6 @@ namespace Deer { return; } - VoxelWorld& voxelWorld = Project::m_scene.getVoxelWorld(); ImGui::Text("Edit mode: "); setupColumns(ICON_BTN_MIN_SIZE + 16); diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_BoxSelectAction.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_BoxSelectAction.cpp index f15b031..e8bd7f0 100644 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_BoxSelectAction.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_BoxSelectAction.cpp @@ -7,7 +7,6 @@ #include "DeerStudio/Editor/EditorUtils.h" #include "DeerStudio/Editor/Icons.h" #include "DeerStudio/Editor/Viewport.h" -#include "DeerStudio/Project.h" #include "TerrainEditor.h" #include "imgui.h" namespace Deer { @@ -59,8 +58,7 @@ namespace Deer { } else { selectedVoxelEnd = voxelRayCoords; } - Project::m_scene.getVoxelWorld() - .getVoxelWorldProps() + VoxelWorld::getWorldProps() .clampCordinates(selectedVoxelEnd); } @@ -75,8 +73,7 @@ namespace Deer { } void TerrainEditor::boxSelect_Visuals() { - VoxelWorld& voxelWorld = Project::m_scene.getVoxelWorld(); - GizmoRenderer& gizmo = Project::m_scene.getMainGizmoRenderer(); + GizmoRenderer& gizmo = Scene::gizmoRenderer; if (!selectedVoxelStart.isNull() && !selectedVoxelEnd.isNull()) { VoxelCordinates min; diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_CreateVoxelWorldPopup.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_CreateVoxelWorldPopup.cpp index d8a82af..f65559c 100644 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_CreateVoxelWorldPopup.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_CreateVoxelWorldPopup.cpp @@ -4,7 +4,6 @@ #include "Deer/Voxel.h" #include "Deer/VoxelWorld.h" #include "DeerRender/LightVoxel.h" -#include "DeerStudio/Project.h" #include "TerrainEditor.h" #include "imgui.h" @@ -83,8 +82,8 @@ namespace Deer { props.chunkSizeY = values[1]; props.chunkSizeZ = values[2]; - Project::m_scene.createVoxelWorld(props); - Project::m_scene.getVoxelWorld().fillVoxels( + VoxelWorld::initialize(props); + VoxelWorld::fillVoxels( VoxelCordinates(0, 0, 0), VoxelCordinates(31, 8, 31), Voxel(DataStore::getVoxelID("wood"))); diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Empty.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Empty.cpp index a418744..9536bf7 100644 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Empty.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Empty.cpp @@ -5,7 +5,6 @@ #include "DeerStudio/Editor/EditorUtils.h" #include "DeerStudio/Editor/Icons.h" #include "DeerStudio/Editor/Viewport.h" -#include "DeerStudio/Project.h" #include "TerrainEditor.h" #include "imgui.h" @@ -18,7 +17,7 @@ namespace Deer { selectVoxel = voxelRayCoords; clampedCordinates = selectVoxel; - Project::m_scene.getVoxelWorld().getVoxelWorldProps().clampCordinates( + VoxelWorld::getWorldProps().clampCordinates( clampedCordinates); if (clampedCordinates != selectVoxel) return; @@ -32,8 +31,7 @@ namespace Deer { max = VoxelCordinates(selectVoxel.x + 15, selectVoxel.y + 15, selectVoxel.z + 15); } - Project::m_scene.getVoxelWorld().getVoxelWorldProps().clampAndSetMinMax( - min, max); + VoxelWorld::getWorldProps().clampAndSetMinMax(min, max); if (selectVoxel.x < min.x || selectVoxel.x > max.x || selectVoxel.y < min.y || selectVoxel.y > max.y || @@ -41,15 +39,15 @@ namespace Deer { return; for (int i = 0; i < 6; i++) { - Project::m_scene.getMainGizmoRenderer().drawVoxelFace( + Scene::gizmoRenderer.drawVoxelFace( clampedCordinates.x, clampedCordinates.y, clampedCordinates.z, DataStore::getVoxelID("debug"), i, 0); } if (ImGui::GetMouseClickedCount(ImGuiMouseButton_Left)) { Voxel voxel = - Project::m_scene.getVoxelWorld().readVoxel(selectVoxel); - Project::m_scene.getVoxelWorld().remplaceVoxels(min, max, voxel, + VoxelWorld::readVoxel(selectVoxel); + VoxelWorld::remplaceVoxels(min, max, voxel, Voxel(0)); } } diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Fill.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Fill.cpp index 11838ae..58dcf99 100644 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Fill.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Fill.cpp @@ -5,7 +5,6 @@ #include "DeerStudio/Editor/EditorUtils.h" #include "DeerStudio/Editor/Icons.h" #include "DeerStudio/Editor/Viewport.h" -#include "DeerStudio/Project.h" #include "TerrainEditor.h" #include "imgui.h" @@ -52,7 +51,7 @@ namespace Deer { } clampedCordinates = selectVoxel; - Project::m_scene.getVoxelWorld().getVoxelWorldProps().clampCordinates( + VoxelWorld::getWorldProps().clampCordinates( clampedCordinates); if (clampedCordinates != selectVoxel) return; @@ -66,7 +65,7 @@ namespace Deer { max = VoxelCordinates(selectVoxel.x + 15, selectVoxel.y + 15, selectVoxel.z + 15); } - Project::m_scene.getVoxelWorld().getVoxelWorldProps().clampAndSetMinMax( + VoxelWorld::getWorldProps().clampAndSetMinMax( min, max); if (selectVoxel.x < min.x || selectVoxel.x > max.x || @@ -75,15 +74,15 @@ namespace Deer { return; for (int i = 0; i < 6; i++) { - Project::m_scene.getMainGizmoRenderer().drawVoxelFace( + Scene::gizmoRenderer.drawVoxelFace( clampedCordinates.x, clampedCordinates.y, clampedCordinates.z, selectedVoxelID, i, 0); } if (ImGui::GetMouseClickedCount(ImGuiMouseButton_Left)) { Voxel voxel = - Project::m_scene.getVoxelWorld().readVoxel(selectVoxel); - Project::m_scene.getVoxelWorld().remplaceVoxels( + VoxelWorld::readVoxel(selectVoxel); + VoxelWorld::remplaceVoxels( min, max, voxel, Voxel(selectedVoxelID)); } } diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Info.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Info.cpp index 3fd5019..5897e69 100644 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Info.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_Info.cpp @@ -5,7 +5,6 @@ #include "Deer/VoxelWorld.h" #include "DeerStudio/Editor/EditorUtils.h" #include "DeerStudio/Editor/Icons.h" -#include "DeerStudio/Project.h" #include "TerrainEditor.h" #include "imgui.h" @@ -15,8 +14,7 @@ namespace Deer { } void TerrainEditor::info() { - VoxelWorld& voxelWorld = Project::m_scene.getVoxelWorld(); - VoxelWorldProps worldProps = voxelWorld.getVoxelWorldProps(); + VoxelWorldProps worldProps = VoxelWorld::getWorldProps(); ImGui::Text("Voxel world chunk and voxel size:"); ImGui::Text( @@ -75,13 +73,13 @@ namespace Deer { // TEMP if (ImGui::Button("Create Ceiling")) { - Project::m_scene.getVoxelWorld().fillVoxels( + VoxelWorld::fillVoxels( VoxelCordinates(), VoxelCordinates(32 * worldProps.chunkSizeX - 1, 16, 32 * worldProps.chunkSizeZ - 1), Voxel(DataStore::getVoxelID("wood"))); - Project::m_scene.getVoxelWorld().fillVoxels( + VoxelWorld::fillVoxels( VoxelCordinates(1, 8, 1), VoxelCordinates(32 * worldProps.chunkSizeX - 2, 15, 32 * worldProps.chunkSizeZ - 2), @@ -94,6 +92,6 @@ namespace Deer { } void TerrainEditor::deleteVoxelWorld() { - Project::m_scene.deleteVoxelWorld(); + VoxelWorld::clear(); } } // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_VoxelRay.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_VoxelRay.cpp index aa54aeb..992882d 100644 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_VoxelRay.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor_VoxelRay.cpp @@ -3,7 +3,6 @@ #include "Deer/VoxelWorld.h" #include "DeerRender/SceneCamera.h" #include "DeerStudio/Editor/Viewport.h" -#include "DeerStudio/Project.h" #include "TerrainEditor.h" #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" @@ -42,7 +41,7 @@ namespace Deer { glm::vec3 rayDir = farPoint - nearPoint; rayDir = glm::normalize(rayDir); - VoxelRayResult res = Project::m_scene.getVoxelWorld().rayCast_editor( + VoxelRayResult res = VoxelWorld::rayCast_editor( viewport_sceneCamera.transform.position, rayDir, 50); voxelRayCoords.makeNull(); @@ -53,13 +52,13 @@ namespace Deer { VoxelCordinates(res.hitPos.x + NORMAL_DIR(0, res.face), res.hitPos.y + NORMAL_DIR(1, res.face), res.hitPos.z + NORMAL_DIR(2, res.face)); - Project::m_scene.getMainGizmoRenderer().drawVoxelLineFace( + Scene::gizmoRenderer.drawVoxelLineFace( res.hitPos.x, res.hitPos.y, res.hitPos.z, res.face); if (viewport_isActive && ImGui::GetMouseClickedCount(0) > 0) { if (terrainEditMode == TerrainEditMode_Substract) { if (res.hitPos.y >= 0) { - Project::m_scene.getVoxelWorld().setVoxel(res.hitPos, + VoxelWorld::setVoxel(res.hitPos, emptyVoxel); } } else if (terrainEditMode == TerrainEditMode_Add) { @@ -68,7 +67,7 @@ namespace Deer { res.hitPos.y + NORMAL_DIR(1, res.face), res.hitPos.z + NORMAL_DIR(2, res.face)); - Project::m_scene.getVoxelWorld().setVoxel( + VoxelWorld::setVoxel( position, Voxel(selectedVoxelID)); } } diff --git a/DeerStudio/src/DeerStudio/Editor/TreePanel.cpp b/DeerStudio/src/DeerStudio/Editor/TreePanel.cpp deleted file mode 100755 index b4a438f..0000000 --- a/DeerStudio/src/DeerStudio/Editor/TreePanel.cpp +++ /dev/null @@ -1,260 +0,0 @@ -#include "TreePanel.h" - -#include "Deer/Enviroment.h" -#include "Deer/Scene.h" -#include "DeerRender/Input.h" -#include "DeerStudio/Editor/ActiveEntity.h" -#include "DeerStudio/Project.h" -#include "imgui.h" - -namespace Deer { - namespace TreePanel { - void updateEntity(Entity& entity); - void updateReciveDragPayload(Entity& entity); - bool updateDragPayload(Entity* entity, const std::string& name); - void updateContextMenu(); - void clickEntity(Entity& entity); - - bool m_isRightClickHandled; - Entity* m_contextMenuEntity = nullptr; - } // namespace TreePanel - - void TreePanel::onImgui() { - ImGui::Begin("Tree Panel", (bool*)0, ImGuiWindowFlags_MenuBar); - - m_isRightClickHandled = false; - Entity& root = Project::m_scene.getMainEnviroment().getRoot(); - - if (!m_contextMenuEntity) m_contextMenuEntity = &root; - - if (ImGui::BeginMenuBar()) { - if (ImGui::BeginMenu("New")) { - if (ImGui::MenuItem("Entity")) { - Entity& entity = - Project::m_scene.getMainEnviroment().createEntity( - "new entity"); - entity.setParent(root); - } - if (ImGui::MenuItem("Camera")) { - Entity& entity = - Project::m_scene.getMainEnviroment().createEntity( - "new camera"); - entity.addComponent(); - entity.setParent(root); - } - ImGui::EndMenu(); - } - ImGui::EndMenuBar(); - } - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); - RelationshipComponent& relation = - Project::m_scene.getMainEnviroment() - .getRoot() - .getComponent(); - - updateEntity(Project::m_scene.getMainEnviroment().getRoot()); - // for (int i = 0; i < relation.childCount; i++) { - // Entity& childEntity = - // Project::m_scene.getMainEnviroment().getEntity( - // relation.getChildrenId(i)); - // } - ImGui::PopStyleVar(); - - updateContextMenu(); - - ImGui::Spacing(); - ImVec2 spaceSize(ImGui::GetWindowContentRegionWidth(), 80); - - ImGui::InvisibleButton("DragDropSpace", spaceSize); - updateReciveDragPayload(root); - - if (!m_isRightClickHandled && - ImGui::IsWindowHovered( - ImGuiHoveredFlags_AllowWhenBlockedByPopup | - ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) && - ImGui::IsMouseClicked(ImGuiMouseButton_Right) && - !ImGui::IsAnyItemHovered()) { - m_contextMenuEntity = &root; - ImGui::OpenPopup("Entity Context Menu"); - } - - updateReciveDragPayload(root); - ImGui::End(); - } - - void TreePanel::updateEntity(Entity& entity) { - auto& tag = entity.getComponent(); - auto& relationship = entity.getComponent(); - - std::string name = (tag.tag == "") ? "-" : tag.tag; - - const void* entityID = reinterpret_cast( - static_cast(entity.getId())); - - ImGui::Spacing(); - - // End of the tree - if (relationship.childCount == 0 && !entity.isRoot()) { - ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf | - ImGuiTreeNodeFlags_NoTreePushOnOpen | - ImGuiTreeNodeFlags_SpanFullWidth; - if (ActiveEntity::contains(entity)) - flags |= ImGuiTreeNodeFlags_Selected; - - ImGui::TreeNodeEx(entityID, flags, "%s", name.c_str()); - if (!updateDragPayload(&entity, tag.tag)) - updateReciveDragPayload(entity); - - clickEntity(entity); - - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { - m_contextMenuEntity = &entity; - m_isRightClickHandled = true; - ImGui::OpenPopup("Entity Context Menu"); - } - - return; - } - - ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnDoubleClick | - ImGuiTreeNodeFlags_OpenOnArrow | - ImGuiTreeNodeFlags_SpanFullWidth; - if (ActiveEntity::contains(entity)) - flags |= ImGuiTreeNodeFlags_Selected; - - // for the moment i prefer to default open all - flags |= ImGuiTreeNodeFlags_DefaultOpen; - - if (ImGui::TreeNodeEx(entityID, flags, "%s", name.c_str())) { - if (!entity.isRoot()) updateDragPayload(&entity, tag.tag); - updateReciveDragPayload(entity); - - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { - m_contextMenuEntity = &entity; - m_isRightClickHandled = true; - ImGui::OpenPopup("Entity Context Menu"); - } - - clickEntity(entity); - - RelationshipComponent& rc = - entity.getComponent(); - for (int i = 0; i < rc.childCount; i++) { - uint16_t childID = rc.getChildrenId(i); - Entity& childEntity = - m_contextMenuEntity->getEnvironment()->getEntity(childID); - updateEntity(childEntity); - } - updateContextMenu(); - ImGui::TreePop(); - } else { - clickEntity(entity); - - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { - m_contextMenuEntity = &entity; - m_isRightClickHandled = true; - ImGui::OpenPopup("Entity Context Menu"); - } - - if (!entity.isRoot()) updateDragPayload(&entity, tag.tag); - updateReciveDragPayload(entity); - } - } - - void TreePanel::updateReciveDragPayload(Entity& entity) { - if (ImGui::BeginDragDropTarget()) { - if (const ImGuiPayload* payload = - ImGui::AcceptDragDropPayload("_ENTITY")) { - Entity* receivedData = *(Entity**)payload->Data; - - if (!entity.isDescendantOf(*receivedData)) - receivedData->setParent(entity); - } - - ImGui::EndDragDropTarget(); - } - } - - bool TreePanel::updateDragPayload(Entity* entity, - const std::string& name) { - if (!ImGui::BeginDragDropSource()) return false; - - ImGui::SetDragDropPayload("_ENTITY", &entity, sizeof(Entity*)); - - ImGui::Text("%s", name.c_str()); - ImGui::EndDragDropSource(); - return true; - } - - void TreePanel::clickEntity(Entity& entity) { - if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) { - if (!(Input::isKeyPressed(DEER_KEY_LEFT_CONTROL) || - Input::isKeyPressed(DEER_KEY_LEFT_ALT))) - ActiveEntity::clear(); - - if (Input::isKeyPressed(DEER_KEY_LEFT_ALT)) - ActiveEntity::removeEntity(entity); - else - ActiveEntity::addEntity(entity); - } - } - - void TreePanel::updateContextMenu() { - bool callRename = false; - - if (ImGui::BeginPopup("Entity Context Menu")) { - if (ImGui::MenuItem("New Entity")) { - Entity& entity = - Project::m_scene.getMainEnviroment().createEntity( - "new entity"); - entity.setParent(*m_contextMenuEntity); - - ImGui::CloseCurrentPopup(); - } - if (ImGui::MenuItem("New Camera")) { - Entity& entity = - Project::m_scene.getMainEnviroment().createEntity( - "new camera"); - entity.addComponent(); - entity.setParent(*m_contextMenuEntity); - - ImGui::CloseCurrentPopup(); - } - if (!m_contextMenuEntity->isRoot() && ImGui::MenuItem("Delete")) { - m_contextMenuEntity->destroy(); - ActiveEntity::clear(); - ImGui::CloseCurrentPopup(); - } - if (!m_contextMenuEntity->isRoot() && ImGui::MenuItem("Rename")) { - callRename = true; - ImGui::CloseCurrentPopup(); - } - if (!m_contextMenuEntity->isRoot() && - ImGui::MenuItem("Duplicate")) { - m_contextMenuEntity->duplicate(); - ImGui::CloseCurrentPopup(); - } - ImGui::EndPopup(); - } - - if (callRename) ImGui::OpenPopup("Rename Entity Menu"); - - if (ImGui::BeginPopup("Rename Entity Menu")) { - std::string& name = - m_contextMenuEntity->getComponent().tag; - char nameBuffer[256]; - std::strncpy(nameBuffer, name.c_str(), sizeof(nameBuffer) - 1); - - ImGui::Text("Rename"); - if (ImGui::InputText("##", nameBuffer, 256, - ImGuiInputTextFlags_EnterReturnsTrue)) { - m_contextMenuEntity->getComponent().tag = - nameBuffer; - ImGui::CloseCurrentPopup(); - } - - ImGui::EndPopup(); - } - } -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/TreePanel.h b/DeerStudio/src/DeerStudio/Editor/TreePanel.h deleted file mode 100755 index f4dcfcb..0000000 --- a/DeerStudio/src/DeerStudio/Editor/TreePanel.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace Deer { - namespace TreePanel { - void onImgui(); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/Viewport.cpp b/DeerStudio/src/DeerStudio/Editor/Viewport.cpp index 1b7c210..7e114af 100755 --- a/DeerStudio/src/DeerStudio/Editor/Viewport.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Viewport.cpp @@ -11,7 +11,6 @@ #include "DeerRender/Input.h" #include "DeerRender/Render/FrameBuffer.h" #include "DeerStudio/Editor/ActiveEntity.h" -#include "DeerStudio/Project.h" #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" #include "glm/gtc/type_ptr.hpp" @@ -94,7 +93,7 @@ namespace Deer { viewport_relativeXMouse = (mPos.x - wPos.x) / windowSize.x; viewport_relativeYMouse = 1 - (mPos.y - wPos.y) / windowSize.y; - Project::m_scene.render(viewport_sceneCamera); + Scene::render(viewport_sceneCamera); ImGui::Image((void*)(uint64_t)m_frameBuffer->getTextureBufferID(0), windowSize, ImVec2(0, 1), ImVec2(1, 0)); @@ -119,7 +118,7 @@ namespace Deer { if (id >= 0) { Entity& selectedEntity = - Project::m_scene.getMainEnviroment().getEntity( + Scene::environment.getEntity( (uint32_t)id); ActiveEntity::addEntity(selectedEntity); } diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API.h b/DeerStudio/src/DeerStudio/EditorEngine/API.h new file mode 100644 index 0000000..7e3d5e5 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API.h @@ -0,0 +1,9 @@ +#pragma once + +#include "DeerStudio/EditorEngine/API/Debug.h" +#include "DeerStudio/EditorEngine/API/Entity.h" +#include "DeerStudio/EditorEngine/API/Layout.h" +#include "DeerStudio/EditorEngine/API/Menu.h" +#include "DeerStudio/EditorEngine/API/Resource.h" +#include "DeerStudio/EditorEngine/API/UI.h" +#include "DeerStudio/EditorEngine/API/Math.h" \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Component.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Component.h new file mode 100644 index 0000000..e69de29 diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Functions.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Debug.cpp similarity index 75% rename from DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Functions.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/API/Debug.cpp index 5b841ea..eaeaac6 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Functions.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Debug.cpp @@ -1,4 +1,4 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" +#include "DeerStudio/EditorEngine/API/Debug.h" #include "Deer/Log.h" #include "angelscript.h" @@ -12,6 +12,8 @@ namespace Deer { DEER_UI_ENGINE_WARN("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); } else if( msg->type == asMSGTYPE_INFORMATION ) { DEER_UI_ENGINE_ERROR("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); + } else if (msg->type == asMSGTYPE_INFORMATION){ + DEER_UI_ENGINE_TRACE("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); } } diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Debug.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Debug.h new file mode 100644 index 0000000..ce2a234 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Debug.h @@ -0,0 +1,11 @@ +#pragma once +#include + +class asSMessageInfo; +namespace Deer { + namespace EditorEngine { + void errorCallback(const asSMessageInfo *msg, void *param); + // Prints in console a mesage + void print(std::string& msg); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Button.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Button.h deleted file mode 100644 index 49c335a..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Button.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -namespace Deer { - namespace EditorEngine { - // TO IMPLEMENT - bool button(std::string&); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Column.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Column.h deleted file mode 100644 index b9bc5b4..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Column.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -namespace Deer { - namespace EditorEngine { - // Set up the colums to fit the pixelSize elements - void setupAutomaticColumns(int pixelSize); - // Iterates to the next column - void nextColumn(); - // Ends the columns made with setupColumns - void endColumns(); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Environment.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Environment.h deleted file mode 100644 index ee4e72e..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Environment.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include -#include - -namespace Deer { - namespace EditorEngine { - struct EntityStruct { - EntityStruct(uint16_t entId) : entityId(entId) { } - - uint16_t entityId; - - int getChildCount(); - EntityStruct getChild(int); - - std::string getName(); - int getId(); - }; - - EntityStruct getRoot(); - void constructEntityStruct(int id, void* memory); - void copyEntityStruct(int id, void* memory); - - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Functions.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Functions.h deleted file mode 100644 index 96271e6..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Functions.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "DeerStudio/EditorEngine/API/EditorEngine_Button.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Column.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Directory.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Icon.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Input.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Mesh.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Text.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h" - -#include - -class asSMessageInfo; -namespace Deer { - namespace EditorEngine { - void errorCallback(const asSMessageInfo *msg, void *param); - // Prints in console a mesage - void print(std::string& msg); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Icon.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Icon.h deleted file mode 100644 index 1bef780..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Icon.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -namespace Deer { - namespace EditorEngine { - void drawIcon(std::string& iconId, int size); - void drawIconCentered(std::string& iconId, int size); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Input.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Input.h deleted file mode 100644 index 2d2766a..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Input.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -namespace Deer { - namespace EditorEngine { - // Returns if the specified mouse button is clicked on the last element - bool isMouseClicked(int mouse); - - // Returns if the specified mouse button is double clicked - bool isMouseDoubleClicked(int mouse); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h deleted file mode 100644 index 27a7e9e..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include - -namespace Deer { - namespace EditorEngine { - bool menuItem(std::string&); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Mesh.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Mesh.h deleted file mode 100644 index b344d96..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Mesh.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -namespace Deer { - namespace EditorEngine { - - - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Text.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Text.h deleted file mode 100644 index 206e671..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Text.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include - -namespace Deer { - namespace EditorEngine { - - // Renders a text with the defined rgb values from range [0.0, 1.0] - void textColor(float r, float g, float b, std::string& msg); - - // Renders a text - void text(std::string& msg); - - // Renders a text - void textCentered(std::string& msg); - - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h deleted file mode 100644 index 6843851..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include - -class asIScriptFunction; -class CScriptAny; - -namespace Deer { - namespace EditorEngine { - void treeNode(std::string&, int); - void treeNodeRecursive(std::string&, int, CScriptAny*, asIScriptFunction&); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Entity.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Entity.cpp new file mode 100644 index 0000000..29b3654 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Entity.cpp @@ -0,0 +1,141 @@ +#include "DeerStudio/EditorEngine/API/Entity.h" +#include "Deer/Enviroment.h" +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "Deer/Scene.h" + +#define GET_ENTITY(id) Scene::environment.getEntity(id) + +namespace Deer { + namespace EditorEngine { + EntityStruct activeEntity; + + EntityStruct getRoot() { + return EntityStruct(0); + } + + void constructEntityStruct(int id, void* memory) { + new (memory)EntityStruct(id); + } + + int EntityStruct::getId() { + return entityId; + } + + std::string EntityStruct::getName() { + return GET_ENTITY(entityId) + .getComponent() + .tag; + } + + + void EntityStruct::setName(std::string& name) { + GET_ENTITY(entityId) + .getComponent() + .tag = name; + } + + void EntityStruct::destroy() { + GET_ENTITY(entityId) + .destroy(); + } + + bool EntityStruct::isRoot() { + return entityId == 0; + } + + bool EntityStruct::exists() { + return Scene::environment + .entityExists(entityId); + } + + void EntityStruct::setParent(EntityStruct parent_struct) { + Entity& parent = GET_ENTITY(parent_struct.entityId); + + GET_ENTITY(entityId) + .setParent(parent); + } + + EntityStruct EntityStruct::getParent() { + Entity& self = GET_ENTITY(entityId); + if (self.isRoot()) + return *this; + + return EntityStruct(self.getParentId()); + } + + EntityStruct getParent(); + + bool EntityStruct::isDescendantOf(EntityStruct parent_struct) { + Entity& parent = GET_ENTITY(parent_struct.entityId); + + return GET_ENTITY(entityId) + .isDescendantOf(parent); + } + + bool EntityStruct::opEquals(const EntityStruct& other) { + return entityId == other.entityId; + } + + EntityStruct EntityStruct::getSelf() { + return *this; + } + + glm::vec3 TransformComponentStruct::getPosition() { + return GET_ENTITY(entityId).getComponent().position; + } + + glm::vec3 TransformComponentStruct::getScale() { + return GET_ENTITY(entityId).getComponent().scale; + } + + glm::vec3 TransformComponentStruct::getRotation() { + return GET_ENTITY(entityId).getComponent().getEulerAngles(); + } + + void TransformComponentStruct::setPosition(glm::vec3 value) { + GET_ENTITY(entityId).getComponent().position = value; + } + + void TransformComponentStruct::setScale(glm::vec3 value) { + GET_ENTITY(entityId).getComponent().scale = value; + } + + void TransformComponentStruct::setRotation(glm::vec3 value) { + GET_ENTITY(entityId).getComponent().setEulerAngles(value); + } + + int EntityChildArrayStruct::getChildCount() { + return GET_ENTITY(entityId) + .getComponent() + .childCount; + } + + EntityStruct EntityChildArrayStruct::getChild(int i) { + RelationshipComponent& rc = GET_ENTITY(entityId) + .getComponent(); + + if (i < 0 || i >= rc.childCount) { + DEER_UI_ENGINE_ERROR("Error while executing EntityChild.getChild(..), id {0} is invalid for child count of {1}", i, rc.childCount); + if (currentDockPanelExecution) + currentDockPanelExecution->invalidate(); + + return EntityStruct(0); + } + + return EntityStruct(rc.getChildrenId(i)); + } + + EntityStruct EntityStruct::createChild(std::string& name) { + Entity& me = GET_ENTITY(entityId); + + Entity& newEnt = Scene::environment + .createEntity(name); + + newEnt.setParent(me); + + return EntityStruct(newEnt.getId()); + } + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Entity.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Entity.h new file mode 100644 index 0000000..71a25d6 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Entity.h @@ -0,0 +1,75 @@ +#pragma once +#include +#include +#include "glm/glm.hpp" + +namespace Deer { + namespace EditorEngine { + struct EntityStruct; + extern EntityStruct activeEntity; + + // IN ANGEL SCRIPT IT LOOKS LIKE THIS + //class Entity { + // int id; + // string name; + // + // int childCount; + // bool isRoot; + // + // Entity parent; + // Entiy getChild(int); + // Entity createChild(int); + // + // void destroy(); + // bool isDescendantOf + // + // bool == + //} + struct EntityStruct { + EntityStruct(uint16_t entId = 0) : entityId(entId) { } + uint16_t entityId; + + std::string getName(); + void setName(std::string&); + + int getId(); + bool exists(); + + bool isRoot(); + void destroy(); + + EntityStruct createChild(std::string&); + + void setParent(EntityStruct parent); + EntityStruct getParent(); + + bool isDescendantOf(EntityStruct parent); + bool opEquals(const EntityStruct& other); + + // This function can be adapted to get a specific transform since the data is the same + EntityStruct getSelf(); + }; + + struct EntityChildArrayStruct : EntityStruct{ + int getChildCount(); + EntityStruct getChild(int); + }; + + struct TransformComponentStruct : EntityStruct { + glm::vec3 getPosition(); + glm::vec3 getScale(); + glm::vec3 getRotation(); + + void setPosition(glm::vec3); + void setScale(glm::vec3); + void setRotation(glm::vec3); + }; + + EntityStruct getRoot(); + void constructEntityStruct(int id, void* memory); + void copyEntityStruct(int id, void* memory); + + void registerEntityStructs(); + void registerEntityFunctions(); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Entity_Register.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Entity_Register.cpp new file mode 100644 index 0000000..3048d74 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Entity_Register.cpp @@ -0,0 +1,200 @@ +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine/API.h" + +#include "scripthandle.h" +#include "scriptany.h" +#include "angelscript.h" + +namespace Deer { + namespace EditorEngine { + + void registerEntityStructs() { + AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityStruct), + asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); + + AS_CHECK(scriptEngine->RegisterObjectBehaviour( + "Entity", asBEHAVE_CONSTRUCT, "void f(int)", + asFunctionPtr(constructEntityStruct), + asCALL_CDECL_OBJLAST + )); + + AS_CHECK(scriptEngine->RegisterObjectType("EntityChilds", sizeof(EntityStruct), + asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); + + AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(EntityStruct), + asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); + + } + + void registerEntityFunctions() { + // ENTITY + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "string get_name() const property", + asMETHOD(EntityStruct, getName), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "void set_name(string& in) property", + asMETHOD(EntityStruct, setName), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "int get_id() const property", + asMETHOD(EntityStruct, getId), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "Entity createChild(const string& in)", + asMETHOD(EntityStruct, createChild), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "bool get_isRoot() const property", + asMETHOD(EntityStruct, isRoot), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "void destroy()", + asMETHOD(EntityStruct, destroy), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "bool get_exists() const property", + asMETHOD(EntityStruct, exists), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "Entity get_parent() property", + asMETHOD(EntityStruct, getParent), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "void set_parent(Entity) property", + asMETHOD(EntityStruct, setParent), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "bool isDescendantOf(Entity)", + asMETHOD(EntityStruct, isDescendantOf), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "bool opEquals(const Entity &in) const", + asMETHOD(EntityStruct, opEquals), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "EntityChilds get_childs() const property", + asMETHOD(EntityStruct, getSelf), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "Entity", + "TransformComponent get_transform() const property", + asMETHOD(EntityStruct, getSelf), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "Entity getRoot()", + asFUNCTION(getRoot), + asCALL_CDECL + )); + + // ENTITY CHILD + AS_CHECK(scriptEngine->RegisterObjectMethod( + "EntityChilds", + "int get_count() const property", + asMETHOD(EntityChildArrayStruct, getChildCount), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "EntityChilds", + "Entity opIndex(int) const", + asMETHOD(EntityChildArrayStruct, getChild), + asCALL_THISCALL + )); + + // TRANSFORM COMPONENT + AS_CHECK(scriptEngine->RegisterObjectMethod( + "TransformComponent", + "vec3 get_position() const property", + asMETHOD(TransformComponentStruct, getPosition), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "TransformComponent", + "vec3 get_scale() const property", + asMETHOD(TransformComponentStruct, getScale), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "TransformComponent", + "vec3 get_rotation() const property", + asMETHOD(TransformComponentStruct, getRotation), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "TransformComponent", + "void set_position(const vec3) property", + asMETHOD(TransformComponentStruct, setPosition), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "TransformComponent", + "void set_scale(const vec3) property", + asMETHOD(TransformComponentStruct, setScale), + asCALL_THISCALL + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod( + "TransformComponent", + "void set_rotation(const vec3) property", + asMETHOD(TransformComponentStruct, setRotation), + asCALL_THISCALL + )); + } + + void registerTransformComponent() { + AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityStruct), + asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); + + + AS_CHECK(scriptEngine->RegisterObjectBehaviour( + "Entity", asBEHAVE_CONSTRUCT, "void f(int)", + asFunctionPtr(constructEntityStruct), + asCALL_CDECL_OBJLAST + )); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Layout.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Layout.cpp new file mode 100644 index 0000000..69883b4 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Layout.cpp @@ -0,0 +1,137 @@ +#include "DeerStudio/EditorEngine/API/Layout.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine.h" +#include "angelscript.h" +#include "scriptany.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + void treeNode(std::string& txt, bool active) { + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf | + ImGuiTreeNodeFlags_NoTreePushOnOpen | + ImGuiTreeNodeFlags_SpanFullWidth; + + if (active) + flags |= ImGuiTreeNodeFlags_Selected; + + ImGui::TreeNodeEx(txt.c_str(), flags); + } + + bool treeNodeRecursive(std::string& txt, bool active, CScriptAny *data, asIScriptFunction& func) { + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnDoubleClick | + ImGuiTreeNodeFlags_OpenOnArrow | + ImGuiTreeNodeFlags_SpanFullWidth | + ImGuiTreeNodeFlags_DefaultOpen; + + if (active) + flags |= ImGuiTreeNodeFlags_Selected; + + if (ImGui::TreeNodeEx(txt.c_str(), flags)) { + ImGui::PushID(txt.c_str()); + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + AS_CHECK_ADDITIONAL_INFO( + scriptContext->Prepare(&func), + func.GetDeclaration() + ); + + AS_CHECK_ADDITIONAL_INFO( + scriptContext->SetArgObject(0, data), + func.GetDeclaration() + ); + + AS_CHECK_ADDITIONAL_INFO( + scriptContext->Execute(), + func.GetDeclaration() + ); + + scriptContext->PopState(); + } else { + ImGui::Text("Something failed"); + } + + ImGui::PopID(); + ImGui::TreePop(); + + + ImGui::PopStyleVar(); + return true; + } + + ImGui::PopStyleVar(); + return false; + } + + bool componentNode(std::string& txt, CScriptAny* data, asIScriptFunction* func) { + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_SpanAvailWidth | + ImGuiTreeNodeFlags_Framed | + ImGuiTreeNodeFlags_AllowItemOverlap | + ImGuiTreeNodeFlags_FramePadding | + ImGuiTreeNodeFlags_DefaultOpen; + + if (ImGui::TreeNodeEx(txt.c_str(), flags)){ + ImGui::Dummy(ImVec2(0, 10)); + ImGui::PushID(txt.c_str()); + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + + AS_CHECK( scriptContext->Prepare(func)); + + AS_CHECK(scriptContext->SetArgObject(0, data)); + + AS_CHECK(scriptContext->Execute()); + + scriptContext->PopState(); + } else { + ImGui::Text("Something failed"); + } + + ImGui::Dummy(ImVec2(0, 10)); + ImGui::PopID(); + ImGui::TreePop(); + + ImGui::PopStyleVar(2); + return true; + } + + ImGui::PopStyleVar(2); + return false; + } + + void setupColumns(int i) { + ImGui::Columns(i, nullptr, false); + } + + void setupAutomaticColumns(int pixelSize) { + float width = ImGui::GetWindowContentRegionWidth(); + + if (width < pixelSize) { + ImGui::Columns(); + return; + } + + int cols = (int)(width / (pixelSize)); + float componentWidth = width / (float)cols; + + ImGui::Columns(cols, 0, false); + } + + void endColumns() { + ImGui::Columns(); + } + + void nextColumn() { + ImGui::NextColumn(); + } + + void space() { + ImGui::Dummy(ImVec2(10, 10)); + } + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Layout.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Layout.h new file mode 100644 index 0000000..969ba15 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Layout.h @@ -0,0 +1,27 @@ +#pragma once +#include + +class asIScriptFunction; +class CScriptAny; + +namespace Deer { + namespace EditorEngine { + // Set up the colums to fit the pixelSize elements + void setupAutomaticColumns(int pixelSize); + // Set up the colums to the number + void setupColumns(int); + // Iterates to the next column + void nextColumn(); + // Ends the columns made with setupColumns + void endColumns(); + + // Renders a component node + bool componentNode(std::string&, CScriptAny*, asIScriptFunction*); + // Renders a tree leaf + void treeNode(std::string&, bool); + // Renders a tree node with its sub nodes + bool treeNodeRecursive(std::string&, bool, CScriptAny*, asIScriptFunction&); + + void space(); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Math.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Math.cpp new file mode 100644 index 0000000..c0acd86 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Math.cpp @@ -0,0 +1,26 @@ +#include "glm/glm.hpp" +#include "DeerStudio/EditorEngine/API/Math.h" + +namespace Deer { + namespace EditorEngine { + void vec3_constructor(void* mem) { + new (mem) glm::vec3(0, 0, 0); + } + void vec3_constructor_params(float x, float y, float z, void* mem) { + new (mem) glm::vec3(x, y, z); + } + + glm::vec3 vec3_add(glm::vec3& value, glm::vec3& self) { + return self + value; + } + glm::vec3 vec3_sub(const glm::vec3& value, glm::vec3& self) { + return self - value; + } + glm::vec3 vec3_neg(glm::vec3& self) { + return -self; + } + glm::vec3 vec3_mult(float value, glm::vec3& self) { + return self * value; + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Math.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Math.h new file mode 100644 index 0000000..da4a88e --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Math.h @@ -0,0 +1,17 @@ +#pragma once +#include "glm/glm.hpp" + +namespace Deer { + namespace EditorEngine { + void vec3_constructor(void*); + void vec3_constructor_params(float, float, float, void*); + + glm::vec3 vec3_add(glm::vec3&, glm::vec3&); + glm::vec3 vec3_sub(const glm::vec3&, glm::vec3&); + glm::vec3 vec3_neg(glm::vec3&); + glm::vec3 vec3_mult(float, glm::vec3&); + + void registerMathStructs(); + void registerMathFunctions(); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Math_Register.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Math_Register.cpp new file mode 100644 index 0000000..1b01d2a --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Math_Register.cpp @@ -0,0 +1,58 @@ +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine/API.h" + +#include "scripthandle.h" +#include "scriptany.h" +#include "angelscript.h" +#include "glm/glm.hpp" + +namespace Deer { + namespace EditorEngine { + void registerMathStructs() { + AS_CHECK(scriptEngine->RegisterObjectType( + "vec3", + sizeof(glm::vec3), + asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLFLOATS)); + + AS_CHECK(scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, + "void f()", asFUNCTION(vec3_constructor), asCALL_CDECL_OBJLAST)); + + AS_CHECK(scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, + "void f(float, float = 0, float = 0)", asFUNCTION(vec3_constructor_params), asCALL_CDECL_OBJLAST)); + + AS_CHECK(scriptEngine->RegisterObjectProperty("vec3", "float x", asOFFSET(glm::vec3, x))); + AS_CHECK(scriptEngine->RegisterObjectProperty("vec3", "float y", asOFFSET(glm::vec3, y))); + AS_CHECK(scriptEngine->RegisterObjectProperty("vec3", "float z", asOFFSET(glm::vec3, z))); + + } + + void registerMathFunctions() { + AS_CHECK(scriptEngine->RegisterObjectMethod( + "vec3", + "vec3 opAdds(const vec3 &in)", + asFUNCTION(vec3_add), + asCALL_CDECL_OBJLAST + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod("vec3", + "vec3 opSub(const vec3 &in) const", + asFUNCTION(vec3_sub), + asCALL_CDECL_OBJLAST + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod("vec3", + "vec3 opNeg() const", + asFUNCTION(vec3_neg), + asCALL_CDECL_OBJLAST + )); + + AS_CHECK(scriptEngine->RegisterObjectMethod("vec3", + "vec3 opMul(float) const", + asFUNCTION(vec3_mult), + asCALL_CDECL_OBJLAST + )); + + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Menu.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Menu.cpp new file mode 100644 index 0000000..b570383 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Menu.cpp @@ -0,0 +1,160 @@ +#include "DeerStudio/EditorEngine/API/Menu.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "DeerStudio/EditorEngine.h" +#include "angelscript.h" +#include "scriptany.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + namespace MenuContext { + CScriptAny* payload = nullptr; + std::string menuId; + } + + void contextItemPopup(std::string& menu_id, CScriptAny* data, asIScriptFunction* func) { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10)); + if (ImGui::BeginPopupContextItem(menu_id.c_str())) { + + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + + AS_CHECK(scriptContext->Prepare(func)); + + AS_CHECK(scriptContext->SetArgObject(0, data)); + + AS_CHECK(scriptContext->Execute()); + + scriptContext->PopState(); + } else { + ImGui::Text("Something failed"); + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + } + + void contextMenuPopup(std::string& menu_id, CScriptAny* data, asIScriptFunction* func) { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10)); + if (ImGui::BeginPopupContextWindow(menu_id.c_str())) { + + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + + AS_CHECK(scriptContext->Prepare(func)); + + AS_CHECK(scriptContext->SetArgObject(0, data)); + + AS_CHECK(scriptContext->Execute()); + + scriptContext->PopState(); + } else { + ImGui::Text("Something failed"); + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + } + + void closePopup() { + if (MenuContext::payload) { + MenuContext::payload->Release(); + MenuContext::payload = nullptr; + } + + MenuContext::menuId = ""; + ImGui::CloseCurrentPopup(); + } + + void openPopup(std::string& menu_id, CScriptAny* data) { + if (MenuContext::payload) { + MenuContext::payload->Release(); + } + + data->AddRef(); + MenuContext::payload = data; + MenuContext::menuId = menu_id; + } + + void modalPopup(std::string& menu_id, asIScriptFunction* func) { + if (!ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup) && MenuContext::menuId == menu_id) { + ImGui::OpenPopup(menu_id.c_str()); + MenuContext::menuId = ""; + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10)); + if (ImGui::BeginPopupModal(menu_id.c_str())) { + // This should not happen + if (!MenuContext::payload) { + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + ImGui::PopStyleVar(); + + return; + } + + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + AS_CHECK(scriptContext->Prepare(func)); + + AS_CHECK(scriptContext->SetArgObject(0, MenuContext::payload)); + + AS_CHECK(scriptContext->Execute()); + + scriptContext->PopState(); + } else { + ImGui::Text("Something failed"); + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + } + + void simplePopup(std::string& menu_id, asIScriptFunction* func) { + if (!ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup)) { + if (MenuContext::menuId == menu_id) { + ImGui::OpenPopup(menu_id.c_str()); + MenuContext::menuId = ""; + + ImVec2 mouse_pos = ImGui::GetMousePos(); + ImVec2 popup_size = ImVec2(200, 0); + ImVec2 popup_pos = ImVec2(mouse_pos.x - popup_size.x * 0.5f, mouse_pos.y); + ImGui::SetNextWindowSize(popup_size); + ImGui::SetNextWindowPos(popup_pos, ImGuiCond_Appearing); + + // In the case a payload is loaded we unload it + } else if (MenuContext::payload && MenuContext::menuId == "") { + MenuContext::payload->Release(); + MenuContext::payload = nullptr; + } + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10)); + if (ImGui::BeginPopup(menu_id.c_str())) { + // This should not happen + if (!MenuContext::payload) { + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + ImGui::PopStyleVar(); + return; + } + + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + AS_CHECK(scriptContext->Prepare(func)); + + AS_CHECK(scriptContext->SetArgObject(0, MenuContext::payload)); + + AS_CHECK(scriptContext->Execute()); + + scriptContext->PopState(); + } else { + ImGui::Text("Something failed"); + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Menu.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Menu.h new file mode 100644 index 0000000..451ac93 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Menu.h @@ -0,0 +1,17 @@ +#pragma once +#include + +class asIScriptFunction; +class CScriptAny; + +namespace Deer { + namespace EditorEngine { + void contextItemPopup(std::string&, CScriptAny*, asIScriptFunction*); + void contextMenuPopup(std::string&, CScriptAny*, asIScriptFunction*); + void modalPopup(std::string&, asIScriptFunction*); + void simplePopup(std::string&, asIScriptFunction*); + + void openPopup(std::string&, CScriptAny*); + void closePopup(); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Directory.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/Resource.cpp similarity index 99% rename from DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Directory.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/API/Resource.cpp index 88ce34f..ca94dfc 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Directory.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Resource.cpp @@ -1,4 +1,4 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Directory.h" +#include "DeerStudio/EditorEngine/API/Resource.h" #include "DeerStudio/EditorEngine.h" #include "Deer/DataStore.h" #include "DeerStudio/EditorEngine/DockPanelObject.h" diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Directory.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Resource.h similarity index 100% rename from DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Directory.h rename to DeerStudio/src/DeerStudio/EditorEngine/API/Resource.h diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/UI.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API/UI.cpp new file mode 100644 index 0000000..3d80e5d --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/UI.cpp @@ -0,0 +1,345 @@ +#include "DeerStudio/EditorEngine/API/UI.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "DeerStudio/EditorEngine.h" +#include "Deer/Log.h" + +#include "imgui.h" +#include "angelscript.h" +#include "scriptany.h" +#include "DeerStudio/Fonts.h" + +#include + +namespace Deer { + namespace EditorEngine { + namespace DragDropPayload{ + CScriptAny* payload; + } + + void separator() { + ImGui::Separator(); + } + + void title(std::string& txt) { + ImGui::PushFont(titleText); + ImGui::Text("%s", txt.c_str()); + ImGui::PopFont(); + } + + void titleEnd(std::string& txt) { + ImGui::PushFont(titleText); + textEnd(txt); + ImGui::PopFont(); + } + + void titleCenter(std::string& txt) { + ImGui::PushFont(titleText); + textCenter(txt); + ImGui::PopFont(); + } + + void sameLine() { + ImGui::SameLine(); + } + + bool button(std::string& txt) { + return ImGui::Button(txt.c_str()); + } + + bool buttonCenter(std::string& txt) { + float sizeX; + if (ImGui::GetColumnsCount() > 1) + sizeX = ImGui::GetColumnWidth(-1); + else + sizeX = ImGui::GetContentRegionAvail().x; + + float textWidth = ImGui::CalcTextSize(txt.c_str(), nullptr, false).x; + float padding = (sizeX - textWidth - ImGui::GetStyle().FramePadding.x * 2) * 0.5f; + + if (padding > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); + + return ImGui::Button(txt.c_str()); + } + + bool buttonEnd(std::string& txt) { + float sizeX; + if (ImGui::GetColumnsCount() > 1) + sizeX = ImGui::GetColumnWidth(-1); + else + sizeX = ImGui::GetContentRegionAvail().x; + + float textWidth = ImGui::CalcTextSize(txt.c_str(), nullptr, false).x; + float padding = (sizeX - textWidth - ImGui::GetStyle().FramePadding.x * 2); + + if (padding > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); + + return ImGui::Button(txt.c_str()); + } + + void textColor(float r, float g, float b, std::string& msg) { + ImGui::TextColored(ImVec4(r, g, b, 1.0f), "%s", msg.c_str()); + } + + void text(std::string& msg) { + ImGui::Text("%s", msg.c_str()); + } + + void textEnd(std::string& msg) { + float sizeX; + if (ImGui::GetColumnsCount() > 1) + sizeX = ImGui::GetColumnWidth(-1); + else + sizeX = ImGui::GetContentRegionAvail().x; + + float textWidth = ImGui::CalcTextSize(msg.c_str(), nullptr, false).x; + float padding = (sizeX - textWidth); + + if (padding > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); + + ImGui::Text("%s", msg.c_str()); + } + + void textCenter(std::string& msg) { + float sizeX; + if (ImGui::GetColumnsCount() > 1) + sizeX = ImGui::GetColumnWidth(-1); + else + sizeX = ImGui::GetContentRegionAvail().x; + + float textWidth = ImGui::CalcTextSize(msg.c_str(), nullptr, false).x; + float padding = (sizeX - textWidth) * 0.5f; + + if (padding > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); + + ImGui::Text("%s", msg.c_str()); + } + + void drawIcon(std::string& name, int size) { + int iconId = DataStore::getIconId(name); + + if (iconId < 0) { + DEER_UI_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return; + } + + ImGui::Image((void*)(uint64_t)iconId, + ImVec2(size, size), ImVec2(0, 1), + ImVec2(1, 0)); + } + + void drawIconCentered(std::string& name, int size) { + int iconId = DataStore::getIconId(name); + if (iconId < 0) { + DEER_UI_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return; + } + + float sizeX; + if (ImGui::GetColumnsCount() > 1) + sizeX = ImGui::GetColumnWidth(-1); + else + sizeX = ImGui::GetContentRegionAvail().x; + + float iconWidth = size; + float padding = (sizeX - iconWidth) * 0.5f; + + if (padding > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); + + drawIcon(name, size); + } + + bool isItemClicked(int mouse) { + return ImGui::IsItemClicked(mouse); + } + + bool isMouseDoubleClicked(int mouse) { + return ImGui::IsMouseDoubleClicked(mouse); + } + + bool menuItem(std::string& txt) { + return ImGui::MenuItem(txt.c_str()); + } + + void dragDropSource(std::string& id, CScriptAny* data, std::string& debugText) { + if (DragDropPayload::payload && !ImGui::GetDragDropPayload()) { + DragDropPayload::payload->Release(); + DragDropPayload::payload = nullptr; + } + + data->AddRef(); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10)); + if (ImGui::BeginDragDropSource()) { + if (DragDropPayload::payload) + DragDropPayload::payload->Release(); + + DragDropPayload::payload = data; + + ImGui::SetDragDropPayload(id.c_str(), nullptr, 0); + ImGui::Text("%s", debugText.c_str()); + + ImGui::EndDragDropSource(); + } + ImGui::PopStyleVar(); + } + + void dragDropTarget(std::string& id, CScriptAny* data, asIScriptFunction* func) { + if (ImGui::BeginDragDropTarget()) { + if (ImGui::AcceptDragDropPayload(id.c_str()) && DragDropPayload::payload) { + + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + + AS_CHECK(scriptContext->Prepare(func)); + + AS_CHECK(scriptContext->SetArgObject(0, data)); + + AS_CHECK(scriptContext->SetArgObject(1, DragDropPayload::payload)); + + AS_CHECK(scriptContext->Execute()); + + scriptContext->PopState(); + } + + DragDropPayload::payload->Release(); + DragDropPayload::payload = nullptr; + } + ImGui::EndDragDropTarget(); + } + } + + bool inputText(std::string& id, std::string& in, std::string& text) { + static char buffer[256]; + strncpy(buffer, in.c_str(), sizeof(buffer)); + buffer[sizeof(buffer) - 1] = '\0'; + + bool edited = ImGui::InputText(id.c_str(), buffer, sizeof(buffer)); + if (edited) { + text = buffer; + } + + return edited; + } + + #include "imgui.h" + + float magicSlider(std::string& txt, float value, float speed) { + + ImGui::PushID(txt.c_str()); + + static ImGuiID id = 0; + + float tmp = value; + bool value_changed = false; + + ImGui::Text("%s", txt.c_str()); + ImGui::SameLine(); + + if (id == ImGui::GetID(txt.c_str())) + { + // — Input mode — + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::InputFloat("##input", &tmp, 0.0f, 0.0f, "%.2f", + ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) + { + value_changed = true; + id = 0; + } + // Cancel if click away or Esc + if (!ImGui::IsItemActive() && !ImGui::IsItemHovered()){ + value_changed = true; + id = 0; + } + } + else + { + // — Drag mode (unbounded) — + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::DragFloat("##input", &tmp, speed, 0.0f, 0.0f, "%.2f"); + if (ImGui::IsItemActive()) + value_changed = true; + + // Click to enter edit mode + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + id = ImGui::GetID(txt.c_str()); + ImGui::SetKeyboardFocusHere(0); + } + } + + if (value_changed) + value = tmp; + + ImGui::PopID(); + return value; + } + + glm::vec3 magicSlider3(std::string& txt, glm::vec3 value, float speed) { + static ImGuiID id = 0; + + glm::vec3 tmp = value; + bool value_changed = false; + + ImGui::Columns(4, nullptr, false); + + ImGui::PushID(txt.c_str()); + ImGui::Text("%s", txt.c_str()); + ImGui::NextColumn(); + + for (int i = 0; i < 3; i++) { + ImGui::PushID(i); + if (id == ImGui::GetID("##input")) + { + // — Input mode — + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::InputFloat("##input", &tmp[i], 0.0f, 0.0f, "%.2f", + ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) + { + value_changed = true; + id = 0; + } + // Cancel if click away or Esc + if (!ImGui::IsItemActive() && !ImGui::IsItemHovered()){ + value_changed = true; + id = 0; + } + } + else + { + // — Drag mode (unbounded) — + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::DragFloat("##input", &tmp[i], speed, 0.0f, 0.0f, "%.2f"); + if (ImGui::IsItemActive()) + value_changed = true; + + // Click to enter edit mode + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + id = ImGui::GetID("##input"); + ImGui::SetKeyboardFocusHere(-1); + } + } + ImGui::PopID(); + ImGui::NextColumn(); + } + ImGui::Columns(); + ImGui::PopID(); + + if (value_changed) + value = tmp; + + return value; + } + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/UI.h b/DeerStudio/src/DeerStudio/EditorEngine/API/UI.h new file mode 100644 index 0000000..a0e1f84 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/UI.h @@ -0,0 +1,65 @@ +#pragma once +#include +#include "glm/glm.hpp" + +class asIScriptFunction; +class CScriptAny; + +namespace Deer { + namespace EditorEngine { + namespace DragDropPayload { + extern CScriptAny* payload; + } + + // Renders the ui elements in the same line + void sameLine(); + // Renders a line separator + void separator(); + + // Renders a button + bool button(std::string&); + // Renders a button at the end + bool buttonCenter(std::string&); + // Renders a button at the end + bool buttonEnd(std::string&); + + // Renders a text + void text(std::string&); + // Renders a text + void textCenter(std::string&); + // Renders a text + void textEnd(std::string&); + + // Renders a text with the defined rgb values from range [0.0, 1.0] + void textColor(float r, float g, float b, std::string& msg); + // Renders a big text + void title(std::string&); + // Renders a big text + void titleCenter(std::string&); + // Renders a big text + void titleEnd(std::string&); + + // Renders a icon in the specified size in pixels + void drawIcon(std::string& iconId, int size); + // Renders a icon in the specified size in pixels at the center + void drawIconCentered(std::string& iconId, int size); + + // Returns if the specified mouse button is clicked on the last element + bool isItemClicked(int mouse); + // Returns if the specified mouse button is double clicked + bool isMouseDoubleClicked(int mouse); + + // Draws a button for a popup menu + bool menuItem(std::string&); + + // Initializes the drag drop source with the id and the data you want to pass + void dragDropSource(std::string&, CScriptAny*, std::string&); + // Prepares the function to accept payload with the id and calls the function with the data + void dragDropTarget(std::string&, CScriptAny*, asIScriptFunction*); + + bool inputText(std::string& label, std::string&, std::string&); + + float magicSlider(std::string&, float, float); + glm::vec3 magicSlider3(std::string&, glm::vec3, float); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Button.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Button.cpp deleted file mode 100644 index f7de871..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Button.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Button.h" -#include "imgui.h" -#include - -namespace Deer { - namespace EditorEngine { - bool button(std::string& txt) { - return ImGui::Button(txt.c_str()); - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Column.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Column.cpp deleted file mode 100644 index b9be098..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Column.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Column.h" -#include "imgui.h" - -namespace Deer { - namespace EditorEngine { - void setupAutomaticColumns(int pixelSize) { - float width = ImGui::GetWindowContentRegionWidth(); - - if (width < pixelSize) { - ImGui::Columns(); - return; - } - - int cols = (int)(width / (pixelSize)); - float componentWidth = width / (float)cols; - - ImGui::Columns(cols, 0, false); - } - - void endColumns() { - ImGui::Columns(); - } - - void nextColumn() { - ImGui::NextColumn(); - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Environment.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Environment.cpp deleted file mode 100644 index 3559c5b..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Environment.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" -#include "DeerStudio/Project.h" -#include "Deer/Enviroment.h" -#include "DeerStudio/EditorEngine.h" -#include "DeerStudio/EditorEngine/DockPanelObject.h" -#include "Deer/Scene.h" - -namespace Deer { - namespace EditorEngine { - EntityStruct getRoot() { - return EntityStruct(0); - } - - int EntityStruct::getChildCount() { - return Project::m_scene - .getMainEnviroment() - .getEntity(entityId) - .getComponent() - .childCount; - } - - EntityStruct EntityStruct::getChild(int i) { - RelationshipComponent& rc = Project::m_scene - .getMainEnviroment() - .getEntity(entityId) - .getComponent(); - - if (i < 0 || i >= rc.childCount) { - DEER_UI_ENGINE_ERROR("Error while executing Entity.getChild(..), id {0} is invalid for child count of {1}", i, rc.childCount); - if (currentDockPanelExecution) - currentDockPanelExecution->invalidate(); - - return EntityStruct(0); - } - - return EntityStruct(rc.getChildrenId(i)); - } - - void constructEntityStruct(int id, void* memory) { - new (memory)EntityStruct(id); - } - - int EntityStruct::getId() { - return entityId; - } - - std::string EntityStruct::getName() { - return Project::m_scene - .getMainEnviroment() - .getEntity(entityId) - .getComponent() - .tag; - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Icon.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Icon.cpp deleted file mode 100644 index dfad7da..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Icon.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Icon.h" -#include "DeerStudio/EditorEngine.h" -#include "DeerStudio/EditorEngine/DockPanelObject.h" -#include "Deer/Log.h" -#include "Deer/DataStore.h" -#include "imgui.h" - -namespace Deer { - namespace EditorEngine { - void drawIcon(std::string& name, int size) { - int iconId = DataStore::getIconId(name); - - if (iconId < 0) { - DEER_UI_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); - if (currentDockPanelExecution) { - currentDockPanelExecution->invalidate(); - } - return; - } - - ImGui::Image((void*)(uint64_t)iconId, - ImVec2(size, size), ImVec2(0, 1), - ImVec2(1, 0)); - } - - void drawIconCentered(std::string& name, int size) { - int iconId = DataStore::getIconId(name); - if (iconId < 0) { - DEER_UI_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); - if (currentDockPanelExecution) { - currentDockPanelExecution->invalidate(); - } - return; - } - - float sizeX; - if (ImGui::GetColumnsCount() > 1) - sizeX = ImGui::GetColumnWidth(-1); - else - sizeX = ImGui::GetContentRegionAvail().x; - - float iconWidth = size; - float padding = (sizeX - iconWidth) * 0.5f; - - if (padding > 0.0f) - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); - - drawIcon(name, size); - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Input.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Input.cpp deleted file mode 100644 index 6a2d661..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Input.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Input.h" -#include "imgui.h" - -namespace Deer { - namespace EditorEngine { - bool isMouseClicked(int mouse) { - return ImGui::IsItemClicked(mouse); - } - - bool isMouseDoubleClicked(int mouse) { - return ImGui::IsMouseDoubleClicked(mouse); - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_MenuBar.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_MenuBar.cpp deleted file mode 100644 index 4d788c9..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_MenuBar.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h" -#include "imgui.h" - -namespace Deer { - namespace EditorEngine { - bool menuItem(std::string& txt) { - return ImGui::MenuItem(txt.c_str()); - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Mesh.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Mesh.cpp deleted file mode 100644 index f13e5db..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Mesh.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Mesh.h" - -namespace Deer { - namespace EditorEngine { - - - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Text.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Text.cpp deleted file mode 100644 index 318f296..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Text.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Text.h" -#include "imgui.h" - -namespace Deer { - namespace EditorEngine { - void textColor(float r, float g, float b, std::string& msg) { - ImGui::TextColored(ImVec4(r, g, b, 1.0f), "%s", msg.c_str()); - } - - void text(std::string& msg) { - ImGui::Text("%s", msg.c_str()); - } - - void textCentered(std::string& msg) { - float sizeX; - if (ImGui::GetColumnsCount() > 1) - sizeX = ImGui::GetColumnWidth(-1); - else - sizeX = ImGui::GetContentRegionAvail().x; - - float textWidth = ImGui::CalcTextSize(msg.c_str(), nullptr, false).x; - float padding = (sizeX - textWidth) * 0.5f; - - if (padding > 0.0f) - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); - - ImGui::Text("%s", msg.c_str()); - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_TreeNode.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_TreeNode.cpp deleted file mode 100644 index 3d86ffe..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_TreeNode.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h" -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" -#include "DeerStudio/EditorEngine.h" -#include "angelscript.h" -#include "scriptany.h" -#include "imgui.h" - -namespace Deer { - namespace EditorEngine { - void treeNode(std::string& txt, int id) { - ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf | - ImGuiTreeNodeFlags_NoTreePushOnOpen | - ImGuiTreeNodeFlags_SpanFullWidth; - - ImGui::TreeNodeEx((void*)(long long)id, flags, "%s", txt.c_str()); - } - - void treeNodeRecursive(std::string& txt, int id, CScriptAny *data, asIScriptFunction& func) { - ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnDoubleClick | - ImGuiTreeNodeFlags_OpenOnArrow | - ImGuiTreeNodeFlags_SpanFullWidth; - - if (ImGui::TreeNodeEx((void*)(long long)id, flags, "%s", txt.c_str())) { - ImGui::PushID(id); - if (scriptContext && scriptContext->PushState() == asSUCCESS) { - AS_CHECK_ADDITIONAL_INFO( - scriptContext->Prepare(&func), - func.GetDeclaration() - ); - - AS_CHECK_ADDITIONAL_INFO( - scriptContext->SetArgObject(0, data), - func.GetDeclaration() - ); - - AS_CHECK_ADDITIONAL_INFO( - scriptContext->Execute(), - func.GetDeclaration() - ); - - scriptContext->PopState(); - } else { - ImGui::Text("Something failed"); - } - - - ImGui::PopID(); - ImGui::TreePop(); - } - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp index 27f0131..bcad515 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp @@ -1,5 +1,5 @@ #include "DeerStudio/EditorEngine/DockPanelObject.h" -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" #include "DeerStudio/EditorEngine.h" #include "Deer/Log.h" diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp index 04be179..dd1ddc9 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp @@ -1,6 +1,7 @@ #include "DeerStudio/EditorEngine.h" -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine/API.h" + #include "DeerStudio/EditorEngine/DockPanelObject.h" #include "DeerStudio/EditorEngine.h" @@ -34,9 +35,11 @@ namespace Deer { AS_RET_CHECK(scriptEngine->SetMessageCallback(asFUNCTION(Deer::EditorEngine::errorCallback), 0, asCALL_CDECL)); + DEER_CORE_TRACE("Registering Editor Engine interface"); registerEditorEngineStructs(); registerEditorEngineFunctions(); registerDockPanel(); + loadScripts(); scriptModule = scriptEngine->GetModule("DeerModule"); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterFunctions.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterFunctions.cpp deleted file mode 100644 index 93414df..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterFunctions.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" -#include "DeerStudio/EditorEngine.h" -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" - -#include "angelscript.h" - -namespace Deer { - void EditorEngine::registerEditorEngineFunctions() { - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "bool menuItem(const string& in)", - asFUNCTION(menuItem), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void textColor(float, float, float, const string& in)", - asFUNCTION(textColor), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void text(const string& in)", - asFUNCTION(text), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void drawIcon(const string& in, int)", - asFUNCTION(drawIcon), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "bool isMouseClicked(int)", - asFUNCTION( - isMouseClicked - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "bool isMouseDoubleClicked(int)", - asFUNCTION( - isMouseDoubleClicked - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void setupAutomaticColumns(int)", - asFUNCTION( - setupAutomaticColumns - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void endColumns()", - asFUNCTION(endColumns), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void nextColumn()", - asFUNCTION(nextColumn), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void print(const string& in)", - asFUNCTION (print), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void textCentered(const string& in)", - asFUNCTION(textCentered), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void drawIconCentered(const string& in, int)", - asFUNCTION(drawIconCentered), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "int getResourceCount(ResourceType, const string& in)", - asFUNCTION(getResourceCount), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getResourceNameById(ResourceType, const string& in, int)", - asFUNCTION(getResourceNameById), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getResourcePathById(ResourceType, const string& in, int)", - asFUNCTION(getResourcePathById), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "int getDirCount(ResourceType, const string& in)", - asFUNCTION(getDirCount), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getDirPathById(ResourceType, const string& in, int)", - asFUNCTION(getDirPathById), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getDirNameById(ResourceType, const string& in, int)", - asFUNCTION(getDirNameById), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void treeNode(const string& in, int)", - asFUNCTION(treeNode), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterFuncdef("void CallbackFunc(any@)")); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void treeNode(const string& in, int, any@+, CallbackFunc@+)", - asFUNCTION(treeNodeRecursive), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "Entity getRoot()", - asFUNCTION(getRoot), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterObjectMethod( - "Entity", - "int getChildCount()", - asMETHOD(EntityStruct, getChildCount), - asCALL_THISCALL - )); - - AS_CHECK(scriptEngine->RegisterObjectMethod( - "Entity", - "Entity getChild(int)", - asMETHOD(EntityStruct, getChild), - asCALL_THISCALL - )); - - AS_CHECK(scriptEngine->RegisterObjectMethod( - "Entity", - "string getName()", - asMETHOD(EntityStruct, getName), - asCALL_THISCALL - )); - - AS_CHECK(scriptEngine->RegisterObjectMethod( - "Entity", - "int getId()", - asMETHOD(EntityStruct, getId), - asCALL_THISCALL - )); - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterStructs.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterStructs.cpp deleted file mode 100644 index e809469..0000000 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterStructs.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "DeerStudio/EditorEngine.h" -#include "scripthandle.h" -#include "scriptany.h" -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Mesh.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" -#include "DeerStudio/EditorEngine/API/EditorEngine_Directory.h" -#include "angelscript.h" - -namespace Deer { - namespace EditorEngine { - void registerResourceTypeEnum() { - AS_RET_CHECK(scriptEngine->RegisterEnum("ResourceType")); - AS_CHECK(scriptEngine->RegisterEnumValue("ResourceType", "Mesh", (int)ResourceType::MESH)); - } - - void registerEntityStruct() { - AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityStruct), - asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); - - - AS_CHECK(scriptEngine->RegisterObjectBehaviour( - "Entity", - asBEHAVE_CONSTRUCT, - "void f(int)", - asFunctionPtr(constructEntityStruct), - asCALL_CDECL_OBJLAST - )); - } - - void registerEditorEngineStructs() { - RegisterScriptHandle(scriptEngine); - RegisterScriptAny(scriptEngine); - - registerResourceTypeEnum(); - registerEntityStruct(); - } - } -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.cpp b/DeerStudio/src/DeerStudio/EditorEngine/ErrorHandle.cpp similarity index 97% rename from DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/ErrorHandle.cpp index 7df0652..3371d9f 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/ErrorHandle.cpp @@ -1,4 +1,4 @@ -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" #include "angelscript.h" diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h b/DeerStudio/src/DeerStudio/EditorEngine/ErrorHandle.h similarity index 100% rename from DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h rename to DeerStudio/src/DeerStudio/EditorEngine/ErrorHandle.h diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_IconManagment.cpp b/DeerStudio/src/DeerStudio/EditorEngine/IconManagment.cpp similarity index 100% rename from DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_IconManagment.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/IconManagment.cpp diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadPanels.cpp b/DeerStudio/src/DeerStudio/EditorEngine/LoadPanels.cpp similarity index 94% rename from DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadPanels.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/LoadPanels.cpp index 82ec7cc..0bd2c37 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadPanels.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/LoadPanels.cpp @@ -1,7 +1,7 @@ #include "angelscript.h" #include "DeerStudio/EditorEngine.h" #include "DeerStudio/EditorEngine/DockPanelObject.h" -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" namespace Deer { void EditorEngine::registerDockPanel() { diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadScripts.cpp b/DeerStudio/src/DeerStudio/EditorEngine/LoadScripts.cpp similarity index 94% rename from DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadScripts.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/LoadScripts.cpp index c3bea56..7bf5d93 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadScripts.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/LoadScripts.cpp @@ -1,5 +1,5 @@ #include "DeerStudio/EditorEngine.h" -#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" #include "Deer/Path.h" #include "Deer/DataStore.h" diff --git a/DeerStudio/src/DeerStudio/EditorEngine/RegisterFunctions.cpp b/DeerStudio/src/DeerStudio/EditorEngine/RegisterFunctions.cpp new file mode 100644 index 0000000..0cf795e --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/RegisterFunctions.cpp @@ -0,0 +1,279 @@ +#include "DeerStudio/EditorEngine/API.h" +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" + +#include "angelscript.h" + +namespace Deer { + void EditorEngine::registerEditorEngineFunctions() { + registerEntityFunctions(); + registerMathFunctions(); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void textColor(float, float, float, const string& in)", + asFUNCTION(textColor), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void text(const string& in)", + asFUNCTION(text), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void textCenter(const string& in)", + asFUNCTION(textCenter), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void textEnd(const string& in)", + asFUNCTION(textEnd), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void drawIcon(const string& in, int)", + asFUNCTION(drawIcon), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool isItemClicked(int)", + asFUNCTION( + isItemClicked + ), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool isMouseDoubleClicked(int)", + asFUNCTION( + isMouseDoubleClicked + ), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void setupAutomaticColumns(int)", + asFUNCTION( + setupAutomaticColumns + ), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void setupColumns(int)", + asFUNCTION( + setupColumns + ), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void endColumns()", + asFUNCTION(endColumns), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void nextColumn()", + asFUNCTION(nextColumn), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void print(const string& in)", + asFUNCTION (print), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void drawIconCentered(const string& in, int)", + asFUNCTION(drawIconCentered), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "int getResourceCount(ResourceType, const string& in)", + asFUNCTION(getResourceCount), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getResourceNameById(ResourceType, const string& in, int)", + asFUNCTION(getResourceNameById), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getResourcePathById(ResourceType, const string& in, int)", + asFUNCTION(getResourcePathById), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "int getDirCount(ResourceType, const string& in)", + asFUNCTION(getDirCount), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getDirPathById(ResourceType, const string& in, int)", + asFUNCTION(getDirPathById), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getDirNameById(ResourceType, const string& in, int)", + asFUNCTION(getDirNameById), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void treeNodeLeaf(const string& in, bool)", + asFUNCTION(treeNode), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool treeNode(const string& in, bool, any@+, ReciverFunc@+)", + asFUNCTION(treeNodeRecursive), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool componentNode(const string& in, any@+, ReciverFunc@+)", + asFUNCTION(componentNode), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void space()", + asFUNCTION(space), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void contextItemPopup(const string& in, any@+, ReciverFunc@+)", + asFUNCTION(contextItemPopup), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void contextMenuPopup(const string& in, any@+, ReciverFunc@+)", + asFUNCTION(contextMenuPopup), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void modalPopup(const string& in, ReciverFunc@+)", + asFUNCTION(modalPopup), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void simplePopup(const string& in, ReciverFunc@+)", + asFUNCTION(simplePopup), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void openPopup(const string& in, any@)", + asFUNCTION(openPopup), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void closePopup()", + asFUNCTION(closePopup), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool menuItem(const string& in)", + asFUNCTION(menuItem), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void dragDropSource(const string& in, any@, const string& in)", + asFUNCTION(dragDropSource), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void dragDropTarget(const string& in, any@+, TransferFunc@+)", + asFUNCTION(dragDropTarget), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool button(const string& in)", + asFUNCTION(button), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool buttonCenter(const string&in)", + asFUNCTION(buttonCenter), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool buttonEnd(const string&in)", + asFUNCTION(buttonEnd), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool inputText(const string& in, const string& in, string& out)", + asFUNCTION(inputText), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "float magicSlider(const string& in, float, float)", + asFUNCTION(magicSlider), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "vec3 magicSlider3(const string& in, vec3, float)", + asFUNCTION(magicSlider3), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void sameLine()", + asFUNCTION(sameLine), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void separator()", + asFUNCTION(separator), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void title(const string&in)", + asFUNCTION(title), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void titleEnd(const string&in)", + asFUNCTION(titleEnd), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void titleCenter(const string&in)", + asFUNCTION(titleCenter), + asCALL_CDECL + )); + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/RegisterStructs.cpp b/DeerStudio/src/DeerStudio/EditorEngine/RegisterStructs.cpp new file mode 100644 index 0000000..f567e2c --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/RegisterStructs.cpp @@ -0,0 +1,28 @@ +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine/API.h" + +#include "scripthandle.h" +#include "scriptany.h" +#include "angelscript.h" + +namespace Deer { + namespace EditorEngine { + void registerResourceTypeEnum() { + AS_RET_CHECK(scriptEngine->RegisterEnum("ResourceType")); + AS_CHECK(scriptEngine->RegisterEnumValue("ResourceType", "Mesh", (int)ResourceType::MESH)); + } + + void registerEditorEngineStructs() { + RegisterScriptHandle(scriptEngine); + RegisterScriptAny(scriptEngine); + + AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunc(any@)")); + AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunc(any@, any@)")); + + registerResourceTypeEnum(); + registerEntityStructs(); + registerMathStructs(); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/Fonts.cpp b/DeerStudio/src/DeerStudio/Fonts.cpp similarity index 99% rename from DeerStudio/src/DeerStudio/Editor/Fonts.cpp rename to DeerStudio/src/DeerStudio/Fonts.cpp index a376c2e..476dbe5 100644 --- a/DeerStudio/src/DeerStudio/Editor/Fonts.cpp +++ b/DeerStudio/src/DeerStudio/Fonts.cpp @@ -1,5 +1,4 @@ #include "Fonts.h" - #include "Deer/DataStore.h" namespace Deer { diff --git a/DeerStudio/src/DeerStudio/Editor/Fonts.h b/DeerStudio/src/DeerStudio/Fonts.h similarity index 100% rename from DeerStudio/src/DeerStudio/Editor/Fonts.h rename to DeerStudio/src/DeerStudio/Fonts.h diff --git a/DeerStudio/src/DeerStudio/Project.cpp b/DeerStudio/src/DeerStudio/Project.cpp deleted file mode 100755 index 3513cee..0000000 --- a/DeerStudio/src/DeerStudio/Project.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "DeerStudio/Project.h" -#include "Deer/Scene.h" - -namespace Deer { - Scene Project::m_scene; -} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Project.h b/DeerStudio/src/DeerStudio/Project.h deleted file mode 100755 index 99cc128..0000000 --- a/DeerStudio/src/DeerStudio/Project.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -namespace Deer { - class Scene; - - class Project { - public: - static Scene m_scene; - }; -} - diff --git a/DeerStudio/src/DeerStudio/Style.cpp b/DeerStudio/src/DeerStudio/Style.cpp new file mode 100644 index 0000000..b098d4d --- /dev/null +++ b/DeerStudio/src/DeerStudio/Style.cpp @@ -0,0 +1,77 @@ +#include "imgui.h" + + +void SetupImGuiStyle() +{ + // Classic Steam style (modified to use blue tones) + ImGuiStyle& style = ImGui::GetStyle(); + + style.Alpha = 1.0f; + style.DisabledAlpha = 0.6000000238418579f; + style.WindowPadding = ImVec2(8.0f, 8.0f); + style.WindowRounding = 0.0f; + style.WindowBorderSize = 1.0f; + style.WindowMinSize = ImVec2(32.0f, 32.0f); + style.WindowTitleAlign = ImVec2(0.0f, 0.5f); + style.WindowMenuButtonPosition = ImGuiDir_Left; + style.ChildRounding = 2.0f; + style.ChildBorderSize = 1.0f; + style.PopupRounding = 2.0f; + style.PopupBorderSize = 1.0f; + style.FramePadding = ImVec2(4.0f, 3.0f); + style.FrameRounding = 2.0f; + style.FrameBorderSize = 1.0f; + style.ItemSpacing = ImVec2(8.0f, 4.0f); + style.ItemInnerSpacing = ImVec2(4.0f, 4.0f); + style.CellPadding = ImVec2(4.0f, 2.0f); + style.IndentSpacing = 21.0f; + style.ColumnsMinSpacing = 6.0f; + style.ScrollbarSize = 14.0f; + style.ScrollbarRounding = 2.0f; + style.GrabMinSize = 10.0f; + style.GrabRounding = 2.0f; + style.TabRounding = 2.0f; + style.TabBorderSize = 0.0f; + style.TabMinWidthForCloseButton = 0.0f; + style.ColorButtonPosition = ImGuiDir_Right; + style.ButtonTextAlign = ImVec2(0.5f, 0.5f); + style.SelectableTextAlign = ImVec2(0.0f, 0.0f); + + style.Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.5f, 0.5f, 0.5f, 1.0f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.2f, 0.27f, 0.38f, 1.0f); + style.Colors[ImGuiCol_ChildBg] = ImVec4(0.2f, 0.27f, 0.38f, 1.0f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(0.16f, 0.2f, 0.29f, 1.0f); + style.Colors[ImGuiCol_Border] = ImVec4(0.4f, 0.5f, 0.65f, 0.5f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.1f, 0.13f, 0.18f, 0.52f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.2f, 0.29f, 1.0f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.2f, 0.25f, 0.35f, 1.0f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.22f, 0.3f, 0.4f, 1.0f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.16f, 0.2f, 0.29f, 1.0f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.2f, 0.27f, 0.38f, 1.0f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.0f, 0.0f, 0.0f, 0.51f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.16f, 0.2f, 0.29f, 1.0f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.25f, 0.32f, 0.43f, 1.0f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.2f, 0.27f, 0.38f, 1.0f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.18f, 0.26f, 0.36f, 1.0f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.22f, 0.33f, 1.0f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.4f, 0.6f, 1.0f, 1.0f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.25f, 0.32f, 0.43f, 1.0f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.4f, 0.5f, 0.65f, 0.5f); + style.Colors[ImGuiCol_Button] = ImVec4(0.2f, 0.27f, 0.38f, 0.4f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.25f, 0.32f, 0.43f, 1.0f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.4f, 0.5f, 0.65f, 0.5f); + style.Colors[ImGuiCol_Header] = ImVec4(0.25f, 0.32f, 0.43f, 1.0f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.32f, 0.43f, 0.6f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.4f, 0.5f, 0.65f, 0.5f); + style.Colors[ImGuiCol_Separator] = ImVec4(0.1f, 0.13f, 0.18f, 1.0f); + style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.4f, 0.5f, 0.65f, 1.0f); + style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.4f, 0.6f, 1.0f, 1.0f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.13f, 0.18f, 0.26f, 0.0f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.4f, 0.5f, 0.65f, 1.0f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.4f, 0.6f, 1.0f, 1.0f); + style.Colors[ImGuiCol_Tab] = ImVec4(0.25f, 0.32f, 0.43f, 1.0f); + style.Colors[ImGuiCol_TabHovered] = ImVec4(0.4f, 0.5f, 0.65f, 0.78f); + style.Colors[ImGuiCol_TabActive] = ImVec4(0.4f, 0.6f, 1.0f, 1.0f); + // If you need more specific blue tweaks for other elements, let me know! +} diff --git a/DeerStudio/src/DeerStudio/Style.h b/DeerStudio/src/DeerStudio/Style.h index 2f98a4a..e83b469 100755 --- a/DeerStudio/src/DeerStudio/Style.h +++ b/DeerStudio/src/DeerStudio/Style.h @@ -1,150 +1,4 @@ #pragma once #include "imgui.h" -void SetupModernStyle(); -void geminiStyle(); - -void setNatureStyle() { - // geminiStyle(); - SetupModernStyle(); -} -void SetupModernStyle() { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4* colors = style.Colors; - - // Round everything slightly more for modern softness - style.WindowRounding = 6.0f; - style.FrameRounding = 4.0f; - style.ScrollbarRounding = 6.0f; - style.GrabRounding = 4.0f; - style.TabRounding = 4.0f; - - style.WindowBorderSize = 0.0f; - style.FrameBorderSize = 0.0f; - - // Core background colors - colors[ImGuiCol_WindowBg] = - ImVec4(0.11f, 0.11f, 0.13f, 1.00f); // Slightly lighter than pure black - colors[ImGuiCol_ChildBg] = ImVec4(0.13f, 0.13f, 0.15f, 1.00f); - colors[ImGuiCol_PopupBg] = ImVec4(0.15f, 0.15f, 0.18f, 1.00f); - - // Text - colors[ImGuiCol_Text] = ImVec4(0.95f, 0.96f, 0.98f, 1.00f); // Almost white - colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.55f, 0.60f, 1.00f); - - // Borders - colors[ImGuiCol_Border] = ImVec4(0.20f, 0.20f, 0.22f, 1.00f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - - // Frames - colors[ImGuiCol_FrameBg] = ImVec4(0.18f, 0.18f, 0.20f, 1.00f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.22f, 0.22f, 0.25f, 1.00f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.25f, 0.25f, 0.28f, 1.00f); - - // Title bar - colors[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.15f, 0.15f, 0.18f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f); - - // Scrollbars - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.30f, 0.30f, 0.35f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.35f, 0.35f, 0.40f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.40f, 0.40f, 0.45f, 1.00f); - - // Checkboxes, sliders, etc. - colors[ImGuiCol_CheckMark] = - ImVec4(0.22f, 0.65f, 0.90f, 1.00f); // Vivid blue - colors[ImGuiCol_SliderGrab] = ImVec4(0.22f, 0.65f, 0.90f, 1.00f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.30f, 0.70f, 0.95f, 1.00f); - - // Buttons - colors[ImGuiCol_Button] = ImVec4(0.18f, 0.18f, 0.22f, 1.00f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.22f, 0.22f, 0.27f, 1.00f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.25f, 0.25f, 0.30f, 1.00f); - - // Headers - colors[ImGuiCol_Header] = ImVec4(0.18f, 0.18f, 0.22f, 1.00f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.22f, 0.22f, 0.27f, 1.00f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.25f, 0.25f, 0.30f, 1.00f); - - // Tabs - colors[ImGuiCol_Tab] = ImVec4(0.12f, 0.12f, 0.15f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.22f, 0.65f, 0.90f, 1.00f); - colors[ImGuiCol_TabActive] = ImVec4(0.18f, 0.50f, 0.75f, 1.00f); - colors[ImGuiCol_TabUnfocused] = ImVec4(0.12f, 0.12f, 0.15f, 1.00f); - colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.18f, 0.20f, 0.25f, 1.00f); - - // Resize grip - colors[ImGuiCol_ResizeGrip] = ImVec4(0.22f, 0.65f, 0.90f, 0.25f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.22f, 0.65f, 0.90f, 0.67f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.22f, 0.65f, 0.90f, 0.95f); - - // Highlight - colors[ImGuiCol_TextSelectedBg] = ImVec4(0.22f, 0.65f, 0.90f, 0.35f); - colors[ImGuiCol_DragDropTarget] = ImVec4(0.22f, 0.65f, 0.90f, 0.90f); - colors[ImGuiCol_NavHighlight] = ImVec4(0.22f, 0.65f, 0.90f, 0.80f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.22f, 0.65f, 0.90f, 0.78f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.22f, 0.65f, 0.90f, 1.00f); -} - -void geminiStyle() { - ImGuiStyle& style = ImGui::GetStyle(); - style.WindowRounding = 8.0f; - style.FrameRounding = 6.0f; - style.GrabRounding = 6.0f; - style.ScrollbarRounding = 6.0f; - - ImVec4* colors = ImGui::GetStyle().Colors; - - colors[ImGuiCol_Text] = ImVec4( - 0.95f, 0.95f, 0.95f, 1.00f); // Lighter text for better readability - colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_WindowBg] = - ImVec4(0.10f, 0.10f, 0.10f, 1.00f); // Slightly darker background - colors[ImGuiCol_ChildBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_PopupBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_Border] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); - colors[ImGuiCol_TitleBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_CheckMark] = ImVec4(0.20f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.20f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.18f, 0.70f, 0.40f, 1.00f); - colors[ImGuiCol_Button] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); - colors[ImGuiCol_Header] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.32f, 0.32f, 0.32f, 1.00f); - colors[ImGuiCol_Separator] = ImVec4(0.23f, 0.23f, 0.23f, 1.00f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.32f, 0.32f, 0.32f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.36f, 0.36f, 0.36f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.20f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.18f, 0.70f, 0.40f, 1.00f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.14f, 0.56f, 0.36f, 1.00f); - colors[ImGuiCol_Tab] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.20f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_TabUnfocused] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); - colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.86f, 0.50f, 0.14f, 1.00f); - colors[ImGuiCol_PlotHistogram] = ImVec4(0.20f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.18f, 0.70f, 0.40f, 1.00f); - colors[ImGuiCol_TextSelectedBg] = ImVec4(0.20f, 0.80f, 0.40f, 0.35f); - colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); - colors[ImGuiCol_NavHighlight] = ImVec4(0.20f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); - colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); - colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); -} \ No newline at end of file +void SetupImGuiStyle(); \ No newline at end of file diff --git a/roe/editor/active_entity.as b/roe/editor/active_entity.as new file mode 100644 index 0000000..078f064 --- /dev/null +++ b/roe/editor/active_entity.as @@ -0,0 +1 @@ +Entity activeEntity(0); \ No newline at end of file diff --git a/roe/editor/mesh_explorer/mesh_explorer.as b/roe/editor/mesh_explorer.as similarity index 75% rename from roe/editor/mesh_explorer/mesh_explorer.as rename to roe/editor/mesh_explorer.as index 72cc309..5fcd8de 100644 --- a/roe/editor/mesh_explorer/mesh_explorer.as +++ b/roe/editor/mesh_explorer.as @@ -9,10 +9,10 @@ class MeshExplorer : DockPanel { const string cache_currentPath = currentPath; if (cache_currentPath != "") { drawIconCentered("folder", 64); - if (isMouseClicked(0) and isMouseDoubleClicked(0)) { + if (isItemClicked(0) and isMouseDoubleClicked(0)) { currentPath = ""; } - textCentered(cache_currentPath + "/.."); + textCenter(cache_currentPath + "/.."); nextColumn(); } @@ -21,12 +21,12 @@ class MeshExplorer : DockPanel { for (int i = 0; i < dirCount; i++) { drawIconCentered("folder", 64); - if (isMouseClicked(0) and isMouseDoubleClicked(0)) { + if (isItemClicked(0) and isMouseDoubleClicked(0)) { print(getDirPathById(ResourceType::Mesh, cache_currentPath, i)); currentPath = getDirPathById(ResourceType::Mesh, cache_currentPath, i); } - textCentered(getDirNameById(ResourceType::Mesh, cache_currentPath, i)); + textCenter(getDirNameById(ResourceType::Mesh, cache_currentPath, i)); nextColumn(); } @@ -34,7 +34,7 @@ class MeshExplorer : DockPanel { for (int i = 0; i < meshCount; i++) { drawIconCentered("file", 64); - textCentered(getResourceNameById(ResourceType::Mesh, cache_currentPath, i)); + textCenter(getResourceNameById(ResourceType::Mesh, cache_currentPath, i)); nextColumn(); } endColumns(); diff --git a/roe/editor/properties/components_render.as b/roe/editor/properties/components_render.as new file mode 100644 index 0000000..98c3e98 --- /dev/null +++ b/roe/editor/properties/components_render.as @@ -0,0 +1,13 @@ +void renderTransformComponent(any@ data) { + Entity entity; + data.retrieve(entity); + + TransformComponent transform = entity.transform; + vec3 position = transform.position; + vec3 scale = transform.scale; + vec3 rotation = transform.rotation; + + transform.position = magicSlider3("Posiiton", position, 0.1); + transform.scale = magicSlider3("Scale", scale, 0.1); + transform.rotation = magicSlider3("Rotation", rotation, 0.1); +} \ No newline at end of file diff --git a/roe/editor/properties/properties_pannel.as b/roe/editor/properties/properties_pannel.as new file mode 100644 index 0000000..30ed583 --- /dev/null +++ b/roe/editor/properties/properties_pannel.as @@ -0,0 +1,74 @@ + +class PropertiesPannel : DockPanel { + float slider = 0; + vec3 slid; + vec3 slid2; + + void onRender() { + Entity entity = activeEntity; + + // NAME + // ------- + // Id:0 [+ add component] + title(entity.name); + if (!entity.isRoot) + contextItemPopup("##MenuOptions", any(entity), ReciverFunc(this.renameEntityMenu)); + separator(); + textColor(0.5, 0.5, 0.5f, "Id : " + entity.id); + + // We don't want to change root options + if (entity.isRoot) + return; + + sameLine(); + if (buttonEnd("Add Component")) { + openPopup("ADD_COMPONENT", any(entity)); + } + + space(); + + componentNode("Transform Component", any(entity), renderTransformComponent); + componentNode("Transform Component 2", any(entity), renderTransformComponent); + + space(); + + separator(); + + if (buttonCenter("Add Component##2")) { + openPopup("ADD_COMPONENT", any(entity)); + } + + simplePopup("ADD_COMPONENT", ReciverFunc(this.addComponentPopup)); + modalPopup("Rename entity", renameEntity); + } + + void addComponentPopup(any@ data) { + titleCenter("Component"); + + separator(); + + if (menuItem("Mesh Render Component")) { + + } + + if (menuItem("Camera Component")) { + + } + + if (menuItem("Script Component")) { + + } + } + + void renameEntityMenu(any@ data) { + Entity entity; + data.retrieve(entity); + + if (!entity.isRoot) { + if (menuItem("Rename")) { + openPopup("Rename entity", data); + } + } + } + +} \ No newline at end of file diff --git a/roe/editor/rename_entity.as b/roe/editor/rename_entity.as new file mode 100644 index 0000000..3e872a3 --- /dev/null +++ b/roe/editor/rename_entity.as @@ -0,0 +1,13 @@ + +void renameEntity(any@ data) { + Entity entity; + data.retrieve(entity); + string name = entity.name; + if (inputText("##RENAME", name, name)) { + entity.name = name; + } + sameLine(); + if (button("Accept")) { + closePopup(); + } +} \ No newline at end of file diff --git a/roe/editor/tree_pannel.as b/roe/editor/tree_pannel.as new file mode 100644 index 0000000..15ced03 --- /dev/null +++ b/roe/editor/tree_pannel.as @@ -0,0 +1,98 @@ +class TreePannel : DockPanel { + void onRender() { + Entity root = getRoot(); + contextMenuPopup("Window popup", any(root), ReciverFunc(this.entityContextMenu)); + + bool opened = treeNode(root.name, false, any(root), ReciverFunc(this.renderNode)); + if (!opened) { + contextItemPopup("POP_ENTITY_" + root.id, any(root), ReciverFunc(this.entityContextMenu)); + } + + modalPopup("Rename entity", renameEntity); + } + + void entityInteraction(Entity entity) { + any data = any(entity); + + dragDropSource("ENTITY", data, entity.name); + dragDropTarget("ENTITY", data, TransferFunc(this.entityDrop)); + contextItemPopup("POP_ENTITY_" + entity.id, data, ReciverFunc(this.entityContextMenu)); + + // We can't select the entity + if (isItemClicked(0)) { + activeEntity = entity; + } + } + + void renderNode(any@ data) { + Entity entity; + data.retrieve(entity); + + entityInteraction(entity); + + // Maybe we deleted the entity in the context menu + if (!entity.exists) + return; + + for (int i = 0; i < entity.childs.count; i++) { + Entity child = entity.childs[i]; + bool isActive = child == activeEntity; + + string displayName = child.name; + if (displayName == "") { + displayName = "-"; + } + + displayName += "##" + child.id; + if (child.childs.count == 0) { + // END OF THE TREE + treeNodeLeaf(displayName, isActive); + entityInteraction(child); + } else { + // ADD ANOTHER NODE + bool opened = treeNode(displayName, isActive, any(child), ReciverFunc(this.renderNode)); + if (!opened) { + entityInteraction(child); + } + } + } + } + + void entityContextMenu(any@ data) { + Entity entity; + data.retrieve(entity); + + if (entity.isRoot) { + if (menuItem("New Entity")) { + entity.createChild("node"); + } + } else { + if (menuItem("Add child")) { + entity.createChild("node"); + } + + if (menuItem("Rename")) { + openPopup("Rename entity", data); + } + + if (menuItem("Destroy")) { + entity.destroy(); + } + } + } + + void entityDrop(any@ reciver, any@ emiter) { + Entity reciver_entity; + reciver.retrieve(reciver_entity); + + Entity emiter_entity; + emiter.retrieve(emiter_entity); + + // You cant be the father of your father + if (emiter_entity.isRoot || reciver_entity.isDescendantOf(emiter_entity)) { + return; + } + + emiter_entity.parent = reciver_entity; + } +} diff --git a/roe/editor/tree_pannel/tree_pannel.as b/roe/editor/tree_pannel/tree_pannel.as deleted file mode 100644 index 6394105..0000000 --- a/roe/editor/tree_pannel/tree_pannel.as +++ /dev/null @@ -1,30 +0,0 @@ -class TreePannel : DockPanel { - void onMenuBar() { - if (menuItem("Hey!")) { - print("clicked"); - } - } - - void onRender() { - Entity root = getRoot(); - - treeNode(root.getName(), root.getId(), any(root),CallbackFunc(this.render)); - } - - void render(any@ data) { - Entity entity; - data.retrieve(entity); - - int childCount = entity.getChildCount(); - for (int i = 0; i < childCount; i++) { - Entity child = entity.getChild(i); - - if (child.getChildCount() == 0) { - treeNode(child.getName(), child.getId()); - } else { - treeNode(child.getName(), child.getId(), any(child),CallbackFunc(this.render)); - } - - } - } -} diff --git a/roe/imgui.ini b/roe/imgui.ini index 0b63ae9..3ec1f57 100644 --- a/roe/imgui.ini +++ b/roe/imgui.ini @@ -9,34 +9,34 @@ Size=400,400 Collapsed=0 [Window][Properties] -Pos=961,24 -Size=319,392 +Pos=895,24 +Size=385,413 Collapsed=0 -DockId=0x00000004,0 +DockId=0x00000004,1 [Window][Game Window] -Pos=304,24 -Size=655,392 +Pos=258,24 +Size=653,413 Collapsed=0 -DockId=0x00000006,1 +DockId=0x00000006,0 [Window][Tree Panel] Pos=0,24 -Size=302,392 +Size=353,569 Collapsed=0 -DockId=0x00000005,0 +DockId=0x00000001,0 [Window][Terrain Editor] -Pos=961,24 -Size=319,392 +Pos=913,24 +Size=367,413 Collapsed=0 DockId=0x00000004,1 [Window][Viewport] -Pos=304,24 -Size=655,392 +Pos=258,24 +Size=653,413 Collapsed=0 -DockId=0x00000006,0 +DockId=0x00000006,1 [Window][Scene Explorer] Pos=0,389 @@ -57,25 +57,47 @@ Collapsed=0 DockId=0x00000008,1 [Window][MeshExplorer] -Pos=0,418 -Size=1280,302 +Pos=0,439 +Size=1280,281 Collapsed=0 DockId=0x00000008,0 [Window][TreePannel] Pos=0,24 -Size=302,392 +Size=256,413 Collapsed=0 -DockId=0x00000005,1 +DockId=0x00000005,0 + +[Window][RENAME_ENTITY] +Pos=472,218 +Size=208,95 +Collapsed=0 + +[Window][Rename entity] +Pos=379,301 +Size=351,75 +Collapsed=0 + +[Window][PropertiesPannel] +Pos=913,24 +Size=367,413 +Collapsed=0 +DockId=0x00000004,0 + +[Window][PropertiesP] +Pos=942,24 +Size=338,429 +Collapsed=0 +DockId=0x00000004,1 [Docking][Data] DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y - DockNode ID=0x00000007 Parent=0xA1672E74 SizeRef=1280,392 Split=Y + DockNode ID=0x00000007 Parent=0xA1672E74 SizeRef=1280,413 Split=Y DockNode ID=0x00000001 Parent=0x00000007 SizeRef=2560,363 Split=X Selected=0x13926F0B - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=959,779 Split=X Selected=0x13926F0B - DockNode ID=0x00000005 Parent=0x00000003 SizeRef=302,779 Selected=0xE45B9F93 - DockNode ID=0x00000006 Parent=0x00000003 SizeRef=655,779 CentralNode=1 Selected=0x13926F0B - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=319,779 Selected=0x199AB496 + DockNode ID=0x00000003 Parent=0x00000001 SizeRef=911,338 Split=X Selected=0x13926F0B + DockNode ID=0x00000005 Parent=0x00000003 SizeRef=256,446 Selected=0xE45B9F93 + DockNode ID=0x00000006 Parent=0x00000003 SizeRef=653,446 CentralNode=1 Selected=0x13926F0B + DockNode ID=0x00000004 Parent=0x00000001 SizeRef=367,338 Selected=0x2A2C795E DockNode ID=0x00000002 Parent=0x00000007 SizeRef=2560,331 Selected=0xCF339702 - DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,302 Selected=0xD962995A + DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,281 Selected=0xD962995A