From 9ca8377b7e0f15830b4395513a3ff784af2cbcda Mon Sep 17 00:00:00 2001 From: Chewico Date: Sun, 22 Jun 2025 00:21:29 +0200 Subject: [PATCH] Changes --- DeerStudio/imgui.ini | 55 +++++++++------- DeerStudio/src/DeerStudio/DeerStudio.cpp | 2 +- .../EditorEngine/DockPanel/DockPanelInfo.h | 4 ++ .../DockPanel/DockPanelInfoSerialization.cpp | 8 +++ .../EditorEngine/DockPanel/LoadDockPanels.cpp | 30 ++++++++- .../ServiceScript/ServiceScriptContext.cpp | 14 ++++ .../ServiceScript/ServiceScriptContext.h | 5 +- .../ServiceScript/ServiceScriptInfo.h | 5 ++ .../ServiceScript/ServiceScriptObject.cpp | 66 ++++++++++++++++++- .../ServiceScript/ServiceScriptObject.h | 6 ++ .../EntityManipulation/dockPanelModule.json | 8 ++- .../MeshExplorer/MeshExplorer.as | 4 +- .../MeshExplorer/dockPanelModule.json | 3 +- .../Viewport/dockPanelModule.json | 3 +- 14 files changed, 176 insertions(+), 37 deletions(-) diff --git a/DeerStudio/imgui.ini b/DeerStudio/imgui.ini index e519687..bff3745 100644 --- a/DeerStudio/imgui.ini +++ b/DeerStudio/imgui.ini @@ -1,6 +1,6 @@ [Window][DockSpace Demo] Pos=0,0 -Size=1280,720 +Size=2560,1371 Collapsed=0 [Window][Debug##Default] @@ -9,44 +9,44 @@ Size=400,400 Collapsed=0 [Window][Terrain Editor] -Pos=969,24 -Size=311,477 +Pos=2107,24 +Size=453,1012 Collapsed=0 DockId=0x00000006,0 [Window][Viewport] -Pos=299,24 -Size=668,477 +Pos=440,24 +Size=1665,1012 Collapsed=0 DockId=0x00000005,0 [Window][ViewportPannel] -Pos=265,24 -Size=702,477 +Pos=440,24 +Size=1665,1012 Collapsed=0 -DockId=0x00000005,0 +DockId=0x00000005,1 [Window][ShaderExplorer] -Pos=0,503 -Size=1280,217 +Pos=0,1038 +Size=2560,333 Collapsed=0 -DockId=0x00000004,0 +DockId=0x00000004,1 [Window][TreePannel] Pos=0,24 -Size=263,477 +Size=438,1012 Collapsed=0 DockId=0x00000001,0 [Window][MeshExplorer] -Pos=0,503 -Size=1280,217 +Pos=0,1038 +Size=2560,333 Collapsed=0 -DockId=0x00000004,1 +DockId=0x00000004,0 [Window][PropertiesPannel] -Pos=969,24 -Size=311,477 +Pos=2107,24 +Size=453,1012 Collapsed=0 DockId=0x00000006,1 @@ -61,12 +61,17 @@ Pos=60,60 Size=40,64 Collapsed=0 -[Docking][Data] -DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y Selected=0x34A4C10F - DockNode ID=0x00000003 Parent=0xA1672E74 SizeRef=1280,477 Split=X - DockNode ID=0x00000001 Parent=0x00000003 SizeRef=263,696 Selected=0xE45B9F93 - DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1015,696 Split=X Selected=0x34A4C10F - DockNode ID=0x00000005 Parent=0x00000002 SizeRef=702,454 CentralNode=1 Selected=0x34A4C10F - DockNode ID=0x00000006 Parent=0x00000002 SizeRef=311,454 Selected=0xA35A27E3 - DockNode ID=0x00000004 Parent=0xA1672E74 SizeRef=1280,217 Selected=0xD962995A +[Window][Rename entity] +Pos=1228,651 +Size=104,68 +Collapsed=0 + +[Docking][Data] +DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=2560,1347 Split=Y Selected=0x34A4C10F + DockNode ID=0x00000003 Parent=0xA1672E74 SizeRef=1280,1012 Split=X + DockNode ID=0x00000001 Parent=0x00000003 SizeRef=438,696 Selected=0xE45B9F93 + DockNode ID=0x00000002 Parent=0x00000003 SizeRef=2120,696 Split=X Selected=0x34A4C10F + DockNode ID=0x00000005 Parent=0x00000002 SizeRef=1665,454 CentralNode=1 Selected=0x34A4C10F + DockNode ID=0x00000006 Parent=0x00000002 SizeRef=453,454 Selected=0xA35A27E3 + DockNode ID=0x00000004 Parent=0xA1672E74 SizeRef=1280,333 Selected=0xD962995A diff --git a/DeerStudio/src/DeerStudio/DeerStudio.cpp b/DeerStudio/src/DeerStudio/DeerStudio.cpp index b604bc5..0eb0fa7 100644 --- a/DeerStudio/src/DeerStudio/DeerStudio.cpp +++ b/DeerStudio/src/DeerStudio/DeerStudio.cpp @@ -109,7 +109,7 @@ namespace Deer { ImGui::PopStyleVar(); TerrainEditor::onImGui(); - //viewport_onImGui(); + viewport_onImGui(); EditorEngine::render(); Scene::gizmoRenderer.refresh(); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfo.h b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfo.h index f48c796..583d091 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfo.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfo.h @@ -1,6 +1,9 @@ #pragma once +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h" + #include "Deer/Path.h" #include +#include namespace Deer { namespace EditorEngine { @@ -8,6 +11,7 @@ namespace Deer { std::string name = "null"; std::string author = ""; std::string version = "0.0.0"; + std::vector services; }; DockPanelInfo* loadDockPanelInfo(Path panelInfo); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfoSerialization.cpp b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfoSerialization.cpp index 403744a..a3bf2e6 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfoSerialization.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelInfoSerialization.cpp @@ -4,6 +4,7 @@ #include "cereal/cereal.hpp" #include "cereal/archives/json.hpp" #include "cereal/types/string.hpp" +#include "cereal/types/vector.hpp" #include #include @@ -16,6 +17,13 @@ namespace Deer { ar(cereal::make_nvp("name", data.name)); ar(cereal::make_nvp("author", data.author)); ar(cereal::make_nvp("version", data.version)); + ar(cereal::make_nvp("services", data.services)); + } + + template + void serialize(Archive& ar, ServiceScriptRef& data) { + ar(cereal::make_nvp("name", data.name)); + ar(cereal::make_nvp("version", data.version)); } DockPanelInfo* loadDockPanelInfo(Path dockPanelInfoPath) { diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp index be6e3fa..0fa2c4a 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp @@ -1,6 +1,7 @@ #include "DeerStudio/EditorEngine.h" #include "DeerStudio/EditorEngine/DockPanel/DockPanelInfo.h" #include "DeerStudio/EditorEngine/DockPanel/DockPanelContext.h" +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h" #include "DeerStudio/EditorEngine/ErrorHandle.h" #include "Deer/Log.h" @@ -20,7 +21,20 @@ namespace fs = std::filesystem; namespace Deer { namespace EditorEngine { CScriptBuilder scriptBuilder; + + ServiceScriptContext* getServiceScriptContext(const ServiceScriptRef& ref) { + for (ServiceScriptContext& ctx : serviceScriptModules) { + const ServiceScriptInfo& info = ctx.getInfo(); + + if (info.name == ref.name && info.version == ref.version) { + return &ctx; + } + } + + return nullptr; + } } + void EditorEngine::loadDockPanels() { Path path = DataStore::rootPath / DEER_EDITOR_PANEL_PATH; @@ -54,6 +68,20 @@ namespace Deer { continue; } + asIScriptModule* module = scriptBuilder.GetModule(); + + // Extract apis + for (const ServiceScriptRef& serviceRef : dockPanelInfo->services) { + ServiceScriptContext* ctx = getServiceScriptContext(serviceRef); + + if (ctx == nullptr) { + DEER_EDITOR_ENGINE_ERROR("Editor engine could not find the Service with name {0} and version {1}", serviceRef.name.c_str(), serviceRef.version.c_str()); + continue; + } + + ctx->bindFunctions(); + } + for (const auto& entry : fs::recursive_directory_iterator(_dir)) { if (entry.is_regular_file() && entry.path().extension() == ".as") { r = scriptBuilder.AddSectionFromFile(entry.path().string().c_str()); @@ -70,7 +98,7 @@ namespace Deer { continue; } - dockPanelModules.push_back(DockPanelContext(scriptEngine->GetModule(dockPanelInfo->name.c_str()), dockPanelInfo)); + dockPanelModules.push_back({module, dockPanelInfo}); } } } \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp index 6f37441..4dd8fc4 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp @@ -75,5 +75,19 @@ namespace Deer { scriptService.init(); } } + + void ServiceScriptContext::bindFunctions() { + std::string ns; + ns = info->author + "::" + info->name +"::" + info->name; + + DEER_CORE_INFO(ns.c_str()); + + scriptEngine->SetDefaultNamespace(ns.c_str()); + for (ServiceScriptObject& object : scriptServices) { + object.bindFunctions(); + } + scriptEngine->SetDefaultNamespace(""); + } + } } \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h index cec96af..f91703b 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h @@ -22,8 +22,11 @@ namespace Deer { void update(); void init(); + void bindFunctions(); + inline const char* getName() const { return info->name.c_str(); } - + inline const ServiceScriptInfo& getInfo() const { return *info; } + std::vector scriptServices; private: asIScriptContext* context; diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h index 39ddcc5..0c88155 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h @@ -10,6 +10,11 @@ namespace Deer { std::string version = "0.0.0"; }; + struct ServiceScriptRef { + std::string name = ""; + std::string version = "0.0.0"; + }; + ServiceScriptInfo* loadServiceScriptInfo(Path panelInfo); } } \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp index 039eb77..dc9238d 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp @@ -1,9 +1,12 @@ #include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h" #include "DeerStudio/EditorEngine/ErrorHandle.h" #include "DeerStudio/EditorEngine.h" + #include "angelscript.h" +#include "scriptbuilder.h" #include +#include namespace Deer { namespace EditorEngine { @@ -70,9 +73,6 @@ namespace Deer { AS_CHECK(scriptContext->Unprepare()); } - const char* ServiceScriptObject::getName() { - return type->GetName(); - } ServiceScriptObject::ServiceScriptObject(ServiceScriptObject&& other) noexcept { type = other.type; @@ -104,5 +104,65 @@ namespace Deer { } return *this; } + + void ServiceScriptObject::bindFunctions() { + for (int i = 0; i < type->GetMethodCount(); i++) { + asIScriptFunction* func = type->GetMethodByIndex(i); + std::vector metadata = scriptBuilder.GetMetadataForTypeMethod(type->GetTypeId(), func); + + bool containsServiceAPI = false; + for (std::string& str : metadata) { + if (str != "ServiceAPI") + continue; + containsServiceAPI = true; + break; + } + + if (!containsServiceAPI) + continue; + + DEER_CORE_INFO("Registering function from object {0}.{1}", type->GetName(), func->GetName()); + + asITypeInfo* retType = EditorEngine::scriptEngine->GetTypeInfoById(func->GetReturnTypeId()); + + std::stringstream ext_dec; + + // This means its void + if (retType == nullptr) + ext_dec << "void "; + else + ext_dec << retType->GetName() << " "; + + ext_dec << func->GetName(); + ext_dec << "("; + + for (int i = 0; i < func->GetParamCount(); i++) { + if (i != 0) + ext_dec << ", "; + + int typeId; + const char* name; + + func->GetParam(i, &typeId, nullptr, &name); + asITypeInfo* paramType = scriptEngine->GetTypeInfoById(typeId); + + ext_dec << paramType->GetName(); + if (name != nullptr) + ext_dec << " " << name; + } + + ext_dec << ")"; + + DEER_CORE_INFO(ext_dec.str().c_str()); + //scriptEngine->RegisterGlobalFunction(ext_dec.str().c_str(), asFUNCTION(apiFunction), asEP_GENERIC_CALL_MODE); + + } + + + } + + void ServiceScriptObject::apiFunction(asIScriptGeneric* gen) { + gen->GetAuxiliary(); + } } } \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h index 5d11509..bed7cc2 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h @@ -5,6 +5,8 @@ class asITypeInfo; class asIScriptObject; class asIScriptFunction; class asIScriptContext; +class asIScriptGeneric; +class asIScriptModule; namespace Deer { namespace EditorEngine { @@ -22,6 +24,8 @@ namespace Deer { void init(); void update(); + void bindFunctions(); + const char* getName(); private: asITypeInfo* type = nullptr; @@ -29,6 +33,8 @@ namespace Deer { asIScriptFunction* updateFunction = nullptr; asIScriptFunction* initFunction = nullptr; asIScriptContext* scriptContext = nullptr; + + void apiFunction(asIScriptGeneric*); }; } } \ No newline at end of file diff --git a/roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json b/roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json index 5cae516..ab42d70 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json +++ b/roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json @@ -2,6 +2,12 @@ "dockPanelModule" : { "name" : "Entity Manipulation", "author" : "Chewico", - "version" : "1.0.0" + "version" : "1.0.0", + "services" : [ + { + "name" : "ActiveEntity", + "version" : "1.0.0" + } + ] } } \ No newline at end of file diff --git a/roe/Editor/DockPanelModules/MeshExplorer/MeshExplorer.as b/roe/Editor/DockPanelModules/MeshExplorer/MeshExplorer.as index 63a4002..34d5751 100644 --- a/roe/Editor/DockPanelModules/MeshExplorer/MeshExplorer.as +++ b/roe/Editor/DockPanelModules/MeshExplorer/MeshExplorer.as @@ -3,8 +3,6 @@ class MeshExplorer : DockPanel { void onRender() { - if (true) - return; UI::setupAutomaticColumns(128); // To avoid problems we will cache the current path @@ -43,6 +41,6 @@ class MeshExplorer : DockPanel { UI::nextColumn(); } UI::endColumns(); + } } - diff --git a/roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json b/roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json index f15c363..d7d5162 100644 --- a/roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json +++ b/roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json @@ -2,6 +2,7 @@ "dockPanelModule" : { "name" : "Explorers", "author" : "Chewico", - "version" : "1.0.0" + "version" : "1.0.0", + "services" : [] } } \ No newline at end of file diff --git a/roe/Editor/DockPanelModules/Viewport/dockPanelModule.json b/roe/Editor/DockPanelModules/Viewport/dockPanelModule.json index c56cb8a..493987a 100644 --- a/roe/Editor/DockPanelModules/Viewport/dockPanelModule.json +++ b/roe/Editor/DockPanelModules/Viewport/dockPanelModule.json @@ -2,6 +2,7 @@ "dockPanelModule" : { "name" : "Viewport", "author" : "Chewico", - "version" : "1.0.0" + "version" : "1.0.0", + "services" : [] } } \ No newline at end of file