From 7adbc97ff2e4ec7f932ea2d8609dc35a58389edf Mon Sep 17 00:00:00 2001 From: Chewico Date: Fri, 30 May 2025 23:28:01 +0200 Subject: [PATCH] Added Service Scripp Module --- Deer/Include/Deer/DataStore.h | 2 + Deer/Include/Deer/Log.h | 8 +- DeerStudio/src/DeerStudio/EditorEngine.h | 7 +- .../API_Registration/RegisterStructs.cpp | 12 +- .../DockPanel/DockPanelObject.cpp | 3 - .../EditorEngine/DockPanel/LoadDockPanels.cpp | 8 +- .../DeerStudio/EditorEngine/EditorEngine.cpp | 8 ++ .../ServiceScript/LoadServiceScripts.cpp | 71 ++++++++++++ .../SeriveScriptInfoSerialization.cpp | 41 +++++++ .../ServiceScript/ServiceScriptContext.cpp | 79 +++++++++++++ .../ServiceScript/ServiceScriptContext.h | 34 ++++++ .../ServiceScript/ServiceScriptInfo.h | 15 +++ .../ServiceScript/ServiceScriptObject.cpp | 108 ++++++++++++++++++ .../ServiceScript/ServiceScriptObject.h | 34 ++++++ .../CameraViewport/CameraPannel.as | 0 .../EntityManipulation}/AddComponent.as | 0 .../EntityManipulation}/CameraProperties.as | 0 .../EntityManipulation}/MeshProperties.as | 0 .../EntityManipulation}/PropertiesPannel.as | 0 .../EntityManipulation}/ShaderProperties.as | 0 .../TransformProperties.as | 0 .../EntityManipulation/Tree.as} | 0 .../EntityManipulation}/active_entity.as | 0 .../EntityManipulation/dockPanelModule.json | 7 ++ .../EntityManipulation}/rename_entity.as | 0 .../MeshExplorer/MeshExplorer.as | 3 + .../MeshExplorer/MeshPreviewRender.as | 9 +- .../MeshExplorer/ShaderExplorer.as} | 1 + .../MeshExplorer/dockPanelModule.json | 7 ++ .../Viewport}/Viewport.as | 3 +- .../Viewport/dockPanelModule.json | 7 ++ .../ActiveEntity/ActiveEntity.as | 17 +++ .../ActiveEntity/ServiceScript.json | 7 ++ roe/Editor/as.predefined | 8 +- 34 files changed, 472 insertions(+), 27 deletions(-) create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/LoadServiceScripts.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/SeriveScriptInfoSerialization.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h rename roe/Editor/{ => DockPanelModules}/CameraViewport/CameraPannel.as (100%) rename roe/Editor/{Properties => DockPanelModules/EntityManipulation}/AddComponent.as (100%) rename roe/Editor/{Properties => DockPanelModules/EntityManipulation}/CameraProperties.as (100%) rename roe/Editor/{Properties => DockPanelModules/EntityManipulation}/MeshProperties.as (100%) rename roe/Editor/{Properties => DockPanelModules/EntityManipulation}/PropertiesPannel.as (100%) rename roe/Editor/{Properties => DockPanelModules/EntityManipulation}/ShaderProperties.as (100%) rename roe/Editor/{Properties => DockPanelModules/EntityManipulation}/TransformProperties.as (100%) rename roe/Editor/{tree_pannel.as => DockPanelModules/EntityManipulation/Tree.as} (100%) rename roe/Editor/{ => DockPanelModules/EntityManipulation}/active_entity.as (100%) create mode 100644 roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json rename roe/Editor/{ => DockPanelModules/EntityManipulation}/rename_entity.as (100%) rename roe/Editor/{ => DockPanelModules}/MeshExplorer/MeshExplorer.as (97%) rename roe/Editor/{ => DockPanelModules}/MeshExplorer/MeshPreviewRender.as (57%) rename roe/Editor/{shader_explorer.as => DockPanelModules/MeshExplorer/ShaderExplorer.as} (99%) create mode 100644 roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json rename roe/Editor/{ => DockPanelModules/Viewport}/Viewport.as (98%) create mode 100644 roe/Editor/DockPanelModules/Viewport/dockPanelModule.json create mode 100644 roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as create mode 100644 roe/Editor/ScriptServiceModules/ActiveEntity/ServiceScript.json diff --git a/Deer/Include/Deer/DataStore.h b/Deer/Include/Deer/DataStore.h index 08ef956..201ccd0 100755 --- a/Deer/Include/Deer/DataStore.h +++ b/Deer/Include/Deer/DataStore.h @@ -14,6 +14,8 @@ #define DEER_VOXEL_TEXTURE_PATH "voxels/textures" #define DEER_VOXEL_SHADER_PATH "voxels/shaders" #define DEER_EDITOR_PATH "Editor" +#define DEER_EDITOR_PANEL_PATH "Editor/DockPanelModules" +#define DEER_EDITOR_SERVICE_PATH "Editor/ScriptServiceModules" #define DEER_MESH_PATH "meshes" #define DEER_MESH_EXTENSION ".dmesh" diff --git a/Deer/Include/Deer/Log.h b/Deer/Include/Deer/Log.h index 11d49b7..540f05b 100755 --- a/Deer/Include/Deer/Log.h +++ b/Deer/Include/Deer/Log.h @@ -49,10 +49,10 @@ namespace Deer { #define DEER_SCRIPT_ERROR(...) Deer::Log::getScriptLogger()->error(__VA_ARGS__) -#define DEER_UI_ENGINE_TRACE(...) Deer::Log::getEditorEngineLogger()->trace(__VA_ARGS__) -#define DEER_UI_ENGINE_INFO(...) Deer::Log::getEditorEngineLogger()->info(__VA_ARGS__) -#define DEER_UI_ENGINE_WARN(...) Deer::Log::getEditorEngineLogger()->warn(__VA_ARGS__) -#define DEER_UI_ENGINE_ERROR(...) Deer::Log::getEditorEngineLogger()->error(__VA_ARGS__) +#define DEER_EDITOR_ENGINE_TRACE(...) Deer::Log::getEditorEngineLogger()->trace(__VA_ARGS__) +#define DEER_EDITOR_ENGINE_INFO(...) Deer::Log::getEditorEngineLogger()->info(__VA_ARGS__) +#define DEER_EDITOR_ENGINE_WARN(...) Deer::Log::getEditorEngineLogger()->warn(__VA_ARGS__) +#define DEER_EDITOR_ENGINE_ERROR(...) Deer::Log::getEditorEngineLogger()->error(__VA_ARGS__) #ifdef LINUX #define DEER_CORE_ASSERT(condition, ...) \ diff --git a/DeerStudio/src/DeerStudio/EditorEngine.h b/DeerStudio/src/DeerStudio/EditorEngine.h index f1bf5a2..12d9034 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine.h +++ b/DeerStudio/src/DeerStudio/EditorEngine.h @@ -12,6 +12,7 @@ namespace Deer { namespace EditorEngine { class DockPanelContext; class DockPanelObject; + class ServiceScriptContext; void initialize(); void deinitialize(); @@ -22,15 +23,17 @@ namespace Deer { // Panels extern asIScriptEngine* scriptEngine; extern asIScriptContext* executingScriptContext; - extern CScriptBuilder dockPanelScriptBuilder; + extern CScriptBuilder scriptBuilder; extern std::vector dockPanelModules; + extern std::vector serviceScriptModules; extern DockPanelObject* currentDockPanelExecution; void loadDockPanels(); + void loadServiceScripts(); + void registerEditorEngineFunctions(); void registerEditorEngineStructs(); - void registerDockPanel(); } namespace DataStore { diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterStructs.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterStructs.cpp index 230f3bd..9440818 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterStructs.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/RegisterStructs.cpp @@ -18,6 +18,11 @@ namespace Deer { RegisterScriptHandle(scriptEngine); RegisterScriptAny(scriptEngine); + AS_RET_CHECK(scriptEngine->RegisterInterface("DockPanel")); + AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("DockPanel", "void onRender()")); + + AS_RET_CHECK(scriptEngine->RegisterInterface("ServiceScript")); + AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunc(any@)")); AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunc(any@, any@)")); @@ -27,13 +32,6 @@ namespace Deer { registerMathStructs(); registerFrameBufferStructs(); registerEnvironmentStructs(); - registerDockPanel(); - } - - void registerDockPanel() { - AS_RET_CHECK(scriptEngine->RegisterInterface("DockPanel")); - - AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("DockPanel", "void onRender()")); } } diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelObject.cpp b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelObject.cpp index c830c29..da87681 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelObject.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/DockPanelObject.cpp @@ -56,9 +56,6 @@ namespace Deer { isValid = true; - int refCount = object->AddRef(); // increments refcount by 1 - refCount = object->Release(); - scriptContext->Unprepare(); } diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp index 28979e7..be6e3fa 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanel/LoadDockPanels.cpp @@ -19,7 +19,7 @@ namespace fs = std::filesystem; namespace Deer { namespace EditorEngine { - CScriptBuilder dockPanelScriptBuilder; + CScriptBuilder scriptBuilder; } void EditorEngine::loadDockPanels() { @@ -47,7 +47,7 @@ namespace Deer { continue; } - int r; r = dockPanelScriptBuilder.StartNewModule(scriptEngine, dockPanelInfo->name.c_str()); + int r; r = scriptBuilder.StartNewModule(scriptEngine, dockPanelInfo->name.c_str()); if (r < 0) { DEER_EDITOR_ENGINE_ERROR("Failed to create module for dock panel module {0}", path.string().c_str()); delete dockPanelInfo; @@ -56,14 +56,14 @@ namespace Deer { for (const auto& entry : fs::recursive_directory_iterator(_dir)) { if (entry.is_regular_file() && entry.path().extension() == ".as") { - r = dockPanelScriptBuilder.AddSectionFromFile(entry.path().string().c_str()); + r = scriptBuilder.AddSectionFromFile(entry.path().string().c_str()); if (r < 0) { DEER_EDITOR_ENGINE_ERROR("Failed loading script for module {0}\nscript: {1}", path.string().c_str(), entry.path().string().c_str()); } } } - r = dockPanelScriptBuilder.BuildModule(); + r = scriptBuilder.BuildModule(); if (r < 0) { DEER_EDITOR_ENGINE_ERROR("Failed compiling module {0}", path.string().c_str()); delete dockPanelInfo; diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp index 7fc71fd..a6b2b25 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp @@ -4,6 +4,7 @@ #include "DeerStudio/EditorEngine/DockPanel/DockPanelObject.h" #include "DeerStudio/EditorEngine/DockPanel/DockPanelContext.h" +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h" #include "DeerStudio/EditorEngine.h" #include "Deer/Log.h" @@ -22,6 +23,7 @@ namespace Deer { asIScriptEngine* scriptEngine = nullptr; std::vector dockPanelModules; + std::vector serviceScriptModules; DockPanelObject* currentDockPanelExecution = nullptr; asIScriptContext* executingScriptContext; @@ -49,9 +51,14 @@ namespace Deer { // This is simply to generate the as.predefined for better experience extract_angelScript(); + loadServiceScripts(); loadDockPanels(); active = true; + for (ServiceScriptContext& service : serviceScriptModules) { + service.init(); + } + for (DockPanelContext& pannel : dockPanelModules) pannel.init(); @@ -59,6 +66,7 @@ namespace Deer { void EditorEngine::deinitialize() { dockPanelModules.clear(); + serviceScriptModules.clear(); if (scriptEngine) scriptEngine->ShutDownAndRelease(); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/LoadServiceScripts.cpp b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/LoadServiceScripts.cpp new file mode 100644 index 0000000..28c3baa --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/LoadServiceScripts.cpp @@ -0,0 +1,71 @@ +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h" +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "Deer/Log.h" + +#include "Deer/Path.h" +#include "Deer/DataStore.h" + +#include "angelscript.h" +#include "scriptbuilder.h" + +#include +#include +#include +#include + +namespace fs = std::filesystem; + +namespace Deer { + void EditorEngine::loadServiceScripts() { + Path path = DataStore::rootPath / DEER_EDITOR_SERVICE_PATH; + + if (!fs::exists(path) || !fs::is_directory(path)) { + DEER_EDITOR_ENGINE_ERROR("Could not find folder " DEER_EDITOR_SERVICE_PATH); + return; + } + + for (const auto& _dir : fs::directory_iterator(path)) { + Path panelInfo_path = _dir.path() / "ServiceScript.json"; + + // A panel info is neded to load a panel + if (!fs::exists(panelInfo_path) || !fs::is_regular_file(panelInfo_path)) { + DEER_EDITOR_ENGINE_WARN("Editor engine did not find ServiceScript.json in folder {0}", panelInfo_path.c_str()); + continue; + } + + ServiceScriptInfo* serviceScriptInfo = loadServiceScriptInfo(panelInfo_path); + if (serviceScriptInfo->name == "null") { + DEER_EDITOR_ENGINE_ERROR("Failed to load service script module from {0},\n incorrect ServiceScript.json file", path.string().c_str()); + delete serviceScriptInfo; + continue; + } + + int r; r = scriptBuilder.StartNewModule(scriptEngine, serviceScriptInfo->name.c_str()); + if (r < 0) { + DEER_EDITOR_ENGINE_ERROR("Failed to create module for service script module {0}", path.string().c_str()); + delete serviceScriptInfo; + continue; + } + + 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()); + if (r < 0) { + DEER_EDITOR_ENGINE_ERROR("Failed loading script for module {0}\nscript: {1}", path.string().c_str(), entry.path().string().c_str()); + } + } + } + + r = scriptBuilder.BuildModule(); + if (r < 0) { + DEER_EDITOR_ENGINE_ERROR("Failed compiling module {0}", path.string().c_str()); + delete serviceScriptInfo; + continue; + } + + serviceScriptModules.push_back(ServiceScriptContext(scriptEngine->GetModule(serviceScriptInfo->name.c_str()), serviceScriptInfo)); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/SeriveScriptInfoSerialization.cpp b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/SeriveScriptInfoSerialization.cpp new file mode 100644 index 0000000..5245621 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/SeriveScriptInfoSerialization.cpp @@ -0,0 +1,41 @@ +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h" +#include "Deer/Log.h" + +#include "cereal/cereal.hpp" +#include "cereal/archives/json.hpp" +#include "cereal/types/string.hpp" + +#include +#include +#include + +namespace Deer { + namespace EditorEngine { + template + void serialize(Archive& ar, ServiceScriptInfo& data) { + ar(cereal::make_nvp("name", data.name)); + ar(cereal::make_nvp("author", data.author)); + ar(cereal::make_nvp("version", data.version)); + } + + ServiceScriptInfo* loadServiceScriptInfo(Path seriveScriptInfoPath) { + try { + std::ifstream is(seriveScriptInfoPath); + + if (!is) + return new ServiceScriptInfo(); + + ServiceScriptInfo* info = new ServiceScriptInfo(); + { + cereal::JSONInputArchive archive(is); + archive(cereal::make_nvp("serviceScriptModule", *info)); + } + + return info; + } catch (const std::exception& e) { + DEER_EDITOR_ENGINE_TRACE(e.what()); + return new ServiceScriptInfo(); + } + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp new file mode 100644 index 0000000..6f37441 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.cpp @@ -0,0 +1,79 @@ +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine.h" + +#include "angelscript.h" + +namespace Deer { + namespace EditorEngine { + ServiceScriptContext::ServiceScriptContext(asIScriptModule* _module, ServiceScriptInfo* _info) + : info(_info), module(_module) { + + size_t nScripts = module->GetObjectTypeCount(); + asITypeInfo* serviceScriptType = scriptEngine->GetTypeInfoByName("ServiceScript"); + + if (!serviceScriptType) { + DEER_EDITOR_ENGINE_ERROR("Could not load ServiceScript interface type"); + return; + } + + context = scriptEngine->CreateContext(); + context->AddRef(); + for (size_t i = 0; i < nScripts; i++) { + asITypeInfo* info = module->GetObjectTypeByIndex(i); + + // If it does not implement service script we are not interested int it + if (!info->Implements(serviceScriptType)) + continue; + + scriptServices.push_back({info, context}); + } + } + + ServiceScriptContext::~ServiceScriptContext() { + scriptServices.clear(); + + if (context) + context->Release(); + + delete info; + } + + ServiceScriptContext::ServiceScriptContext(ServiceScriptContext&& o) + : scriptServices(std::move(o.scriptServices)) { + context = o.context; + module = o.module; + info = o.info; + + o.context = nullptr; + o.module = nullptr; + o.info = nullptr; + } + + ServiceScriptContext& ServiceScriptContext::operator=(ServiceScriptContext&& o) { + if (&o != this) { + scriptServices = std::move(o.scriptServices); + context = o.context; + module = o.module; + info = o.info; + + o.context = nullptr; + o.module = nullptr; + o.info = nullptr; + } + return *this; + } + + void ServiceScriptContext::update() { + for (auto& scriptService : scriptServices) { + scriptService.update(); + } + } + + void ServiceScriptContext::init() { + for (auto& scriptService : scriptServices) { + scriptService.init(); + } + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h new file mode 100644 index 0000000..cec96af --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptContext.h @@ -0,0 +1,34 @@ +#pragma once +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h" +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h" +#include + +class asIScriptModule; +class asIScriptContext; + +namespace Deer { + namespace EditorEngine { + class ServiceScriptContext { + public: + ServiceScriptContext(asIScriptModule*, ServiceScriptInfo*); + ~ServiceScriptContext(); + + ServiceScriptContext(ServiceScriptContext&) = delete; + ServiceScriptContext& operator=(ServiceScriptContext&) = delete; + + ServiceScriptContext(ServiceScriptContext&&); + ServiceScriptContext& operator=(ServiceScriptContext&&); + + void update(); + void init(); + + inline const char* getName() const { return info->name.c_str(); } + + std::vector scriptServices; + private: + asIScriptContext* context; + asIScriptModule* module; + ServiceScriptInfo* info; + }; + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h new file mode 100644 index 0000000..39ddcc5 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptInfo.h @@ -0,0 +1,15 @@ +#pragma once +#include "Deer/Path.h" +#include + +namespace Deer { + namespace EditorEngine { + struct ServiceScriptInfo { + std::string name = "null"; + std::string author = ""; + 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 new file mode 100644 index 0000000..039eb77 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp @@ -0,0 +1,108 @@ +#include "DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" +#include "DeerStudio/EditorEngine.h" +#include "angelscript.h" + +#include + +namespace Deer { + namespace EditorEngine { + ServiceScriptObject::ServiceScriptObject(asITypeInfo* _type, asIScriptContext* _scriptContext) + : type(_type), scriptContext(_scriptContext) { + // Constructor + // "type@ type()" + std::string callString; + const std::string ns(type->GetNamespace()); + if (ns != "") { + callString += ns; + callString += "::"; + } + callString += type->GetName(); + callString += "@ "; + if (ns != "") { + callString += ns; + callString += "::"; + } + callString += type->GetName(); + callString += "()"; + + asIScriptFunction* factory = type->GetFactoryByDecl(callString.c_str()); + + AS_CHECK(scriptContext->Prepare(factory)); + AS_CHECK(scriptContext->Execute()); + + // Return value contains the ref to a asIScriptObject in the location provided + object = *(asIScriptObject**)scriptContext->GetAddressOfReturnValue(); + if (!object){ + DEER_EDITOR_ENGINE_ERROR("Could not create object", type->GetName()); + return; + } + object->AddRef(); + + updateFunction = type->GetMethodByDecl("void onUpdate()"); + initFunction = type->GetMethodByDecl("void onInit()"); + + scriptContext->Unprepare(); + } + + ServiceScriptObject::~ServiceScriptObject() { + if (object) + object->Release(); + } + + void ServiceScriptObject::init() { + if (!initFunction) + return; + + AS_CHECK(scriptContext->Prepare(initFunction)); + AS_CHECK(scriptContext->SetObject(object)); + AS_CHECK(scriptContext->Execute()); + AS_CHECK(scriptContext->Unprepare()); + } + + void ServiceScriptObject::update() { + if (!updateFunction) + return; + + AS_CHECK(scriptContext->Prepare(updateFunction)); + AS_CHECK(scriptContext->SetObject(object)); + AS_CHECK(scriptContext->Execute()); + AS_CHECK(scriptContext->Unprepare()); + } + + const char* ServiceScriptObject::getName() { + return type->GetName(); + } + + ServiceScriptObject::ServiceScriptObject(ServiceScriptObject&& other) noexcept { + type = other.type; + object = other.object; + updateFunction = other.updateFunction; + initFunction = other.initFunction; + scriptContext = other.scriptContext; + + other.type = nullptr; + other.object = nullptr; + other.updateFunction = nullptr; + other.initFunction = nullptr; + other.scriptContext = nullptr; + } + + ServiceScriptObject& ServiceScriptObject::operator=(ServiceScriptObject&& other) noexcept { + if (&other != this) { + type = other.type; + object = other.object; + updateFunction = other.updateFunction; + initFunction = other.initFunction; + scriptContext = other.scriptContext; + + other.type = nullptr; + other.object = nullptr; + other.updateFunction = nullptr; + other.initFunction = nullptr; + other.scriptContext = nullptr; + } + return *this; + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h new file mode 100644 index 0000000..5d11509 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.h @@ -0,0 +1,34 @@ +#pragma once +#include + +class asITypeInfo; +class asIScriptObject; +class asIScriptFunction; +class asIScriptContext; + +namespace Deer { + namespace EditorEngine { + struct ServiceScriptObject { + public: + ServiceScriptObject(asITypeInfo*, asIScriptContext*); + ~ServiceScriptObject(); + // Delete copy constructor + ServiceScriptObject(const ServiceScriptObject&) = delete; + ServiceScriptObject& operator=(const ServiceScriptObject&) = delete; + + ServiceScriptObject(ServiceScriptObject&& other) noexcept; + ServiceScriptObject& operator=(ServiceScriptObject&& other) noexcept; + + void init(); + void update(); + + const char* getName(); + private: + asITypeInfo* type = nullptr; + asIScriptObject* object = nullptr; + asIScriptFunction* updateFunction = nullptr; + asIScriptFunction* initFunction = nullptr; + asIScriptContext* scriptContext = nullptr; + }; + } +} \ No newline at end of file diff --git a/roe/Editor/CameraViewport/CameraPannel.as b/roe/Editor/DockPanelModules/CameraViewport/CameraPannel.as similarity index 100% rename from roe/Editor/CameraViewport/CameraPannel.as rename to roe/Editor/DockPanelModules/CameraViewport/CameraPannel.as diff --git a/roe/Editor/Properties/AddComponent.as b/roe/Editor/DockPanelModules/EntityManipulation/AddComponent.as similarity index 100% rename from roe/Editor/Properties/AddComponent.as rename to roe/Editor/DockPanelModules/EntityManipulation/AddComponent.as diff --git a/roe/Editor/Properties/CameraProperties.as b/roe/Editor/DockPanelModules/EntityManipulation/CameraProperties.as similarity index 100% rename from roe/Editor/Properties/CameraProperties.as rename to roe/Editor/DockPanelModules/EntityManipulation/CameraProperties.as diff --git a/roe/Editor/Properties/MeshProperties.as b/roe/Editor/DockPanelModules/EntityManipulation/MeshProperties.as similarity index 100% rename from roe/Editor/Properties/MeshProperties.as rename to roe/Editor/DockPanelModules/EntityManipulation/MeshProperties.as diff --git a/roe/Editor/Properties/PropertiesPannel.as b/roe/Editor/DockPanelModules/EntityManipulation/PropertiesPannel.as similarity index 100% rename from roe/Editor/Properties/PropertiesPannel.as rename to roe/Editor/DockPanelModules/EntityManipulation/PropertiesPannel.as diff --git a/roe/Editor/Properties/ShaderProperties.as b/roe/Editor/DockPanelModules/EntityManipulation/ShaderProperties.as similarity index 100% rename from roe/Editor/Properties/ShaderProperties.as rename to roe/Editor/DockPanelModules/EntityManipulation/ShaderProperties.as diff --git a/roe/Editor/Properties/TransformProperties.as b/roe/Editor/DockPanelModules/EntityManipulation/TransformProperties.as similarity index 100% rename from roe/Editor/Properties/TransformProperties.as rename to roe/Editor/DockPanelModules/EntityManipulation/TransformProperties.as diff --git a/roe/Editor/tree_pannel.as b/roe/Editor/DockPanelModules/EntityManipulation/Tree.as similarity index 100% rename from roe/Editor/tree_pannel.as rename to roe/Editor/DockPanelModules/EntityManipulation/Tree.as diff --git a/roe/Editor/active_entity.as b/roe/Editor/DockPanelModules/EntityManipulation/active_entity.as similarity index 100% rename from roe/Editor/active_entity.as rename to roe/Editor/DockPanelModules/EntityManipulation/active_entity.as diff --git a/roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json b/roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json new file mode 100644 index 0000000..5cae516 --- /dev/null +++ b/roe/Editor/DockPanelModules/EntityManipulation/dockPanelModule.json @@ -0,0 +1,7 @@ +{ + "dockPanelModule" : { + "name" : "Entity Manipulation", + "author" : "Chewico", + "version" : "1.0.0" + } +} \ No newline at end of file diff --git a/roe/Editor/rename_entity.as b/roe/Editor/DockPanelModules/EntityManipulation/rename_entity.as similarity index 100% rename from roe/Editor/rename_entity.as rename to roe/Editor/DockPanelModules/EntityManipulation/rename_entity.as diff --git a/roe/Editor/MeshExplorer/MeshExplorer.as b/roe/Editor/DockPanelModules/MeshExplorer/MeshExplorer.as similarity index 97% rename from roe/Editor/MeshExplorer/MeshExplorer.as rename to roe/Editor/DockPanelModules/MeshExplorer/MeshExplorer.as index 9843973..63a4002 100644 --- a/roe/Editor/MeshExplorer/MeshExplorer.as +++ b/roe/Editor/DockPanelModules/MeshExplorer/MeshExplorer.as @@ -2,6 +2,9 @@ class MeshExplorer : DockPanel { string currentPath = ""; void onRender() { + + if (true) + return; UI::setupAutomaticColumns(128); // To avoid problems we will cache the current path diff --git a/roe/Editor/MeshExplorer/MeshPreviewRender.as b/roe/Editor/DockPanelModules/MeshExplorer/MeshPreviewRender.as similarity index 57% rename from roe/Editor/MeshExplorer/MeshPreviewRender.as rename to roe/Editor/DockPanelModules/MeshExplorer/MeshPreviewRender.as index 719196c..a097f8b 100644 --- a/roe/Editor/MeshExplorer/MeshPreviewRender.as +++ b/roe/Editor/DockPanelModules/MeshExplorer/MeshPreviewRender.as @@ -2,12 +2,17 @@ dictionary meshFrameBuffer; Environment renderEnvironment; FrameBuffer getMeshFrameBuffer(string mesh) { - + if (meshFrameBuffer.exists(mesh)) { + FrameBuffer fb; + any fbAny = cast(meshFrameBuffer[mesh]); + fbAny.retrieve(fb); + return fb; + } return generateMeshFrameBuffer(mesh); } FrameBuffer generateMeshFrameBuffer(string mesh) { FrameBuffer fb = Engine::createRGBA8FrameBuffer(mesh, 64, 64); - + meshFrameBuffer[mesh] = any(fb); return fb; } \ No newline at end of file diff --git a/roe/Editor/shader_explorer.as b/roe/Editor/DockPanelModules/MeshExplorer/ShaderExplorer.as similarity index 99% rename from roe/Editor/shader_explorer.as rename to roe/Editor/DockPanelModules/MeshExplorer/ShaderExplorer.as index 07b389b..4ebfa61 100644 --- a/roe/Editor/shader_explorer.as +++ b/roe/Editor/DockPanelModules/MeshExplorer/ShaderExplorer.as @@ -1,3 +1,4 @@ + class ShaderExplorer : DockPanel { string currentPath = ""; diff --git a/roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json b/roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json new file mode 100644 index 0000000..f15c363 --- /dev/null +++ b/roe/Editor/DockPanelModules/MeshExplorer/dockPanelModule.json @@ -0,0 +1,7 @@ +{ + "dockPanelModule" : { + "name" : "Explorers", + "author" : "Chewico", + "version" : "1.0.0" + } +} \ No newline at end of file diff --git a/roe/Editor/Viewport.as b/roe/Editor/DockPanelModules/Viewport/Viewport.as similarity index 98% rename from roe/Editor/Viewport.as rename to roe/Editor/DockPanelModules/Viewport/Viewport.as index 923f120..e6a4b72 100644 --- a/roe/Editor/Viewport.as +++ b/roe/Editor/DockPanelModules/Viewport/Viewport.as @@ -92,5 +92,4 @@ class ViewportPannel : DockPanel { void viewportCameraProps(any@ data) { sceneCamera.camera.fov = UI::slider("Fov", sceneCamera.camera.fov / 3.14f * 180, 10, 160) / 180 * 3.14f; } -} - \ No newline at end of file +} \ No newline at end of file diff --git a/roe/Editor/DockPanelModules/Viewport/dockPanelModule.json b/roe/Editor/DockPanelModules/Viewport/dockPanelModule.json new file mode 100644 index 0000000..c56cb8a --- /dev/null +++ b/roe/Editor/DockPanelModules/Viewport/dockPanelModule.json @@ -0,0 +1,7 @@ +{ + "dockPanelModule" : { + "name" : "Viewport", + "author" : "Chewico", + "version" : "1.0.0" + } +} \ No newline at end of file diff --git a/roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as b/roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as new file mode 100644 index 0000000..de866e1 --- /dev/null +++ b/roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as @@ -0,0 +1,17 @@ +class ActiveEntity : ServiceScript { + Entity entity; + + void onInit() { + entity = Engine::getMainEnvironment().getRootEntity(); + } + + [ServiceAPI] + Entity getActiveEntity() { + return entity; + } + + [ServiceAPI] + void setActiveEntity(Entity ent) { + entity = ent; + } +} \ No newline at end of file diff --git a/roe/Editor/ScriptServiceModules/ActiveEntity/ServiceScript.json b/roe/Editor/ScriptServiceModules/ActiveEntity/ServiceScript.json new file mode 100644 index 0000000..f53143a --- /dev/null +++ b/roe/Editor/ScriptServiceModules/ActiveEntity/ServiceScript.json @@ -0,0 +1,7 @@ +{ + "serviceScriptModule" : { + "name" : "ActiveEntity", + "author" : "Chewico", + "version" : "1.0.0" + } +} \ No newline at end of file diff --git a/roe/Editor/as.predefined b/roe/Editor/as.predefined index ab7b2b4..86fa8bc 100644 --- a/roe/Editor/as.predefined +++ b/roe/Editor/as.predefined @@ -200,6 +200,11 @@ class any { bool retrieve(int64&out); bool retrieve(double&out); } +class DockPanel { + void onRender(); +} +class ServiceScript { +} class Entity { string get_name() const property; void set_name(string&in) property; @@ -319,9 +324,6 @@ class Environment { Entity getRootEntity(); Entity getEntity(int); } -class DockPanel { - void onRender(); -} string formatInt(int64 val, const string&in options = "", uint width = 0); string formatUInt(uint64 val, const string&in options = "", uint width = 0); string formatFloat(double val, const string&in options = "", uint width = 0, uint precision = 0);