diff --git a/DeerStudio/imgui.ini b/DeerStudio/imgui.ini index 2aea1fe..56eb4be 100644 --- a/DeerStudio/imgui.ini +++ b/DeerStudio/imgui.ini @@ -67,8 +67,8 @@ Size=104,68 Collapsed=0 [Window][Test] -Pos=60,60 -Size=55,82 +Pos=560,275 +Size=396,176 Collapsed=0 [Docking][Data] diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.cpp b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.cpp index 492058b..a277343 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.cpp @@ -1,14 +1,127 @@ #include "ServiceScriptGenericFunction.h" #include "Deer/Log.h" +#include "DeerStudio/EditorEngine/ErrorHandle.h" #include "angelscript.h" namespace Deer { - void EditorEngine::apiFunction(asIScriptGeneric* func) { - DEER_CORE_TRACE("Called function {0}", - func->GetFunction()->GetDeclaration()); + bool copyParameter(asIScriptContext* ctx, int paramIndex, int typeId, + asDWORD flags, asIScriptGeneric* gen); + bool copyReturnValue(asIScriptGeneric* gen, asIScriptContext* ctx, + asIScriptFunction* func); - asIScriptFunction* aux_funx = (asIScriptFunction*)func->GetAuxiliary(); - DEER_CORE_TRACE("Real function {0}", aux_funx->GetDeclaration()); + void EditorEngine::apiFunction(asIScriptGeneric* func) { + ServiceScriptFunction* serviceScriptFunction = + (ServiceScriptFunction*)func->GetAuxiliary(); + + asIScriptContext* context = serviceScriptFunction->scriptContext; + asIScriptFunction* apiFunction = serviceScriptFunction->apiFunction; + DEER_CORE_ASSERT(context, "Nullptr service script context calling {0}", + func->GetFunction()->GetDeclaration()); + + AS_CHECK(context->Prepare(apiFunction)); + AS_CHECK(context->SetObject(serviceScriptFunction->scriptObject)); + + // Extract atributes + asUINT paramCount = apiFunction->GetParamCount(); + for (asUINT i = 0; i < paramCount; i++) { + int type; + asDWORD flags; + + apiFunction->GetParam(i, &type, &flags, nullptr); + copyParameter(context, i, type, flags, func); + } + + AS_CHECK(context->Execute()); + + copyReturnValue(func, context, apiFunction); + + AS_CHECK(context->Unprepare()); } + + bool copyParameter(asIScriptContext* ctx, int paramIndex, int typeId, + asDWORD flags, asIScriptGeneric* gen) { + if (flags & asTM_OUTREF) { + // Skip out refs for now + // Unsupported type + DEER_EDITOR_ENGINE_WARN( + "Skipping our ref type {0} when calling {1}", + ctx->GetEngine()->GetTypeDeclaration(typeId, true), + gen->GetFunction()->GetDeclaration()); + return false; + } + + if (typeId == asTYPEID_INT32) { + ctx->SetArgDWord(paramIndex, gen->GetArgDWord(paramIndex)); + } else if (typeId == asTYPEID_FLOAT) { + ctx->SetArgFloat(paramIndex, gen->GetArgFloat(paramIndex)); + } else if (typeId == asTYPEID_DOUBLE) { + ctx->SetArgDouble(paramIndex, gen->GetArgDouble(paramIndex)); + } else if (typeId == asTYPEID_INT64) { + ctx->SetArgQWord(paramIndex, gen->GetArgQWord(paramIndex)); + } else if (typeId & asTYPEID_OBJHANDLE) { + void* obj = + gen->GetArgAddress(paramIndex); // Use GetArgAddress instead of + // GetArgObject for handles + ctx->SetArgObject(paramIndex, obj); + } else if (typeId & asTYPEID_MASK_OBJECT) { + void* obj = gen->GetArgObject(paramIndex); + ctx->SetArgObject(paramIndex, obj); + } else { + // Unsupported type + DEER_EDITOR_ENGINE_WARN( + "Unsuported type {0} when calling {1}", + ctx->GetEngine()->GetTypeDeclaration(typeId, true), + gen->GetFunction()->GetDeclaration()); + return false; + } + + return true; + } + + bool copyReturnValue(asIScriptGeneric* gen, asIScriptContext* ctx, + asIScriptFunction* func) { + int returnTypeId = func->GetReturnTypeId(); + asITypeInfo* typeInfo = ctx->GetEngine()->GetTypeInfoById(returnTypeId); + + if (returnTypeId == asTYPEID_VOID) { + // Nothing to return + return true; + } + + if (returnTypeId == asTYPEID_INT32) { + gen->SetReturnDWord(ctx->GetReturnDWord()); + } else if (returnTypeId == asTYPEID_FLOAT) { + gen->SetReturnFloat(ctx->GetReturnFloat()); + } else if (returnTypeId == asTYPEID_DOUBLE) { + gen->SetReturnDouble(ctx->GetReturnDouble()); + } else if (returnTypeId == asTYPEID_INT64) { + gen->SetReturnQWord(ctx->GetReturnQWord()); + } else if (returnTypeId & asTYPEID_OBJHANDLE) { + void* obj = ctx->GetReturnAddress(); // For handles, this returns + // the pointer + gen->SetReturnAddress(obj); + } else if (returnTypeId & asTYPEID_MASK_OBJECT) { + bool isRef = (typeInfo->GetFlags() & asOBJ_REF) != 0; + + if (isRef) { + void* obj = ctx->GetReturnObject(); + gen->SetReturnObject(obj); + } else { + void* src = ctx->GetReturnObject(); + void* dst = gen->GetAddressOfReturnLocation(); + + memcpy(dst, src, typeInfo->GetSize()); + } + } else { + DEER_EDITOR_ENGINE_WARN( + "Unsupported return type {0} in call to {1}", + ctx->GetEngine()->GetTypeDeclaration(returnTypeId, true), + func->GetDeclaration()); + return false; + } + + return true; + } + } // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.h b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.h index b2ba2df..3f44e24 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptGenericFunction.h @@ -1,11 +1,20 @@ #pragma once +#include "angelscript.h" class asIScriptGeneric; +class asIScriptFunction; +class asIScriptContext; +class asIScriptObject; namespace Deer { namespace EditorEngine { struct ServiceScriptObject; + struct ServiceScriptFunction { + asIScriptFunction* apiFunction = nullptr; + asIScriptContext* scriptContext = nullptr; + asIScriptObject* scriptObject = nullptr; + }; - void apiFunction(asIScriptGeneric *gen); + void apiFunction(asIScriptGeneric* gen); } // namespace EditorEngine } // namespace Deer \ 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 cb8c09c..6bf1402 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/ServiceScript/ServiceScriptObject.cpp @@ -15,7 +15,7 @@ namespace Deer { namespace EditorEngine { ServiceScriptObject::ServiceScriptObject( - asITypeInfo *_type, asIScriptContext *_scriptContext) + asITypeInfo* _type, asIScriptContext* _scriptContext) : type(_type), scriptContext(_scriptContext) { // Constructor // "type@ type()" @@ -34,7 +34,7 @@ namespace Deer { callString += type->GetName(); callString += "()"; - asIScriptFunction *factory = + asIScriptFunction* factory = type->GetFactoryByDecl(callString.c_str()); AS_CHECK(scriptContext->Prepare(factory)); @@ -43,7 +43,7 @@ namespace Deer { // Return value contains the ref to a asIScriptObject in the // location provided object = - *(asIScriptObject **)scriptContext->GetAddressOfReturnValue(); + *(asIScriptObject**)scriptContext->GetAddressOfReturnValue(); if (!object) { DEER_EDITOR_ENGINE_ERROR("Could not create object", type->GetName()); @@ -83,7 +83,7 @@ namespace Deer { } ServiceScriptObject::ServiceScriptObject( - ServiceScriptObject &&other) noexcept { + ServiceScriptObject&& other) noexcept { type = other.type; object = other.object; updateFunction = other.updateFunction; @@ -97,8 +97,8 @@ namespace Deer { other.scriptContext = nullptr; } - ServiceScriptObject & - ServiceScriptObject::operator=(ServiceScriptObject &&other) noexcept { + ServiceScriptObject& + ServiceScriptObject::operator=(ServiceScriptObject&& other) noexcept { if (&other != this) { type = other.type; object = other.object; @@ -117,13 +117,13 @@ namespace Deer { void ServiceScriptObject::bindFunctions() { for (int i = 0; i < type->GetMethodCount(); i++) { - asIScriptFunction *func = type->GetMethodByIndex(i); + asIScriptFunction* func = type->GetMethodByIndex(i); std::vector metadata = scriptBuilder.GetMetadataForTypeMethod(type->GetTypeId(), func); bool containsServiceAPI = false; - for (std::string &str : metadata) { + for (std::string& str : metadata) { if (str != "ServiceAPI") continue; containsServiceAPI = true; @@ -136,7 +136,7 @@ namespace Deer { DEER_CORE_INFO("Registering function from object {0}.{1}", type->GetName(), func->GetName()); - asITypeInfo *retType = + asITypeInfo* retType = EditorEngine::scriptEngine->GetTypeInfoById( func->GetReturnTypeId()); @@ -156,10 +156,10 @@ namespace Deer { ext_dec << ", "; int typeId; - const char *name; + const char* name; func->GetParam(i, &typeId, nullptr, &name); - asITypeInfo *paramType = + asITypeInfo* paramType = scriptEngine->GetTypeInfoById(typeId); ext_dec << paramType->GetName(); @@ -171,9 +171,16 @@ namespace Deer { DEER_CORE_INFO(ext_dec.str().c_str()); + ServiceScriptFunction* serviceScriptFunction = + new ServiceScriptFunction(); + + serviceScriptFunction->apiFunction = func; + serviceScriptFunction->scriptContext = scriptContext; + serviceScriptFunction->scriptObject = object; + AS_CHECK(scriptEngine->RegisterGlobalFunction( ext_dec.str().c_str(), asFUNCTION(apiFunction), - asCALL_GENERIC, func)); + asCALL_GENERIC, serviceScriptFunction)); } } } // namespace EditorEngine diff --git a/DeerStudio/src/DeerStudio/PannelMenuBarManagment.cpp b/DeerStudio/src/DeerStudio/PannelMenuBarManagment.cpp index b97c6f0..6f7ff24 100644 --- a/DeerStudio/src/DeerStudio/PannelMenuBarManagment.cpp +++ b/DeerStudio/src/DeerStudio/PannelMenuBarManagment.cpp @@ -1,44 +1,42 @@ #include "DeerStudio/DeerStudio.h" #include "DeerStudio/EditorEngine.h" -#include "DeerStudio/EditorEngine/DockPanel/DockPanelObject.h" #include "DeerStudio/EditorEngine/DockPanel/DockPanelContext.h" +#include "DeerStudio/EditorEngine/DockPanel/DockPanelObject.h" #include "imgui.h" namespace Deer { - namespace DeerStudio { - void panelEnable(EditorEngine::DockPanelObject& dpo); - - void onPannelMenuBar() { - if (ImGui::BeginMenu("Dock Panels Show/Hide")) { - for (EditorEngine::DockPanelContext& pc : EditorEngine::dockPanelModules) { - if (pc.dockPanels.size() == 0) - continue; - - if (pc.dockPanels.size() == 1){ - panelEnable(pc.dockPanels[0]); - continue; - } - - const char* name = pc.getName(); - if (ImGui::BeginMenu(name)) { - for (EditorEngine::DockPanelObject& panel : pc.dockPanels) { - panelEnable(panel); - } - ImGui::EndMenu(); - } - } - ImGui::EndMenu(); - } - } + namespace DeerStudio { + void panelEnable(EditorEngine::DockPanelObject& dpo); - void panelEnable(EditorEngine::DockPanelObject& dpo) { - const char* name = dpo.getName(); - - bool enabled = dpo.getFlag(DockPannelFlag_ShowPannel); - if (ImGui::MenuItem(name, nullptr, enabled)) { - dpo.setFlag(DockPannelFlag_ShowPannel, !enabled); - } - } - } -} \ No newline at end of file + void onPannelMenuBar() { + for (EditorEngine::DockPanelContext& pc : + EditorEngine::dockPanelModules) { + if (pc.dockPanels.size() == 0) + continue; + + if (pc.dockPanels.size() == 1) { + panelEnable(pc.dockPanels[0]); + continue; + } + + const char* name = pc.getName(); + if (ImGui::BeginMenu(name)) { + for (EditorEngine::DockPanelObject& panel : pc.dockPanels) { + panelEnable(panel); + } + ImGui::EndMenu(); + } + } + } + + void panelEnable(EditorEngine::DockPanelObject& dpo) { + const char* name = dpo.getName(); + + bool enabled = dpo.getFlag(DockPannelFlag_ShowPannel); + if (ImGui::MenuItem(name, nullptr, enabled)) { + dpo.setFlag(DockPannelFlag_ShowPannel, !enabled); + } + } + } // namespace DeerStudio +} // namespace Deer \ No newline at end of file diff --git a/roe/Editor/DockPanelModules/EntityManipulation/AddComponent.as b/roe/Editor/DockPanelModules/EntityManipulation/AddComponent.as index f4a59d1..5d3452e 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/AddComponent.as +++ b/roe/Editor/DockPanelModules/EntityManipulation/AddComponent.as @@ -1,11 +1,10 @@ - void addComponentPopup(any@ data) { Entity entity; data.retrieve(entity); UI::titleCenter("Component"); UI::separator(); - UI::menuSpace("Rendering", any(entity), addComponentRendering ); + UI::menuSpace("Rendering", any(entity), addComponentRendering); if (UI::menuItem("Script Component")) { } } @@ -37,4 +36,4 @@ void addComponentRendering(any@ data) { entity.createCameraComponent(); } } -} \ No newline at end of file +} diff --git a/roe/Editor/DockPanelModules/EntityManipulation/CameraProperties.as b/roe/Editor/DockPanelModules/EntityManipulation/CameraProperties.as index f11dc9d..a96895a 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/CameraProperties.as +++ b/roe/Editor/DockPanelModules/EntityManipulation/CameraProperties.as @@ -7,10 +7,10 @@ void renderCameraComponent(any@ data) { CameraComponent cameraComponent = entity.getCameraComponent(); - float fov = cameraComponent.fov; - float aspect = cameraComponent.aspectRatio; - float nearZ = cameraComponent.nearZ; - float farZ = cameraComponent.farZ; + float fov = cameraComponent.fov; + float aspect = cameraComponent.aspectRatio; + float nearZ = cameraComponent.nearZ; + float farZ = cameraComponent.farZ; fov = UI::magicSlider("Fov", fov, 0.1); if (fov > 180) @@ -31,10 +31,10 @@ void renderCameraComponent(any@ data) { if (nearZ > farZ) farZ = nearZ; - cameraComponent.fov = fov; - cameraComponent.aspectRatio = aspect; + cameraComponent.fov = fov; + cameraComponent.aspectRatio = aspect; cameraComponent.nearZ = nearZ; - cameraComponent.farZ = farZ; + cameraComponent.farZ = farZ; } void removeCameraComponent(any@ entity) { @@ -44,4 +44,4 @@ void removeCameraComponent(any@ entity) { if (UI::menuItem("Remove")) { ent.removeCameraComponent(); } -} \ No newline at end of file +} diff --git a/roe/Editor/DockPanelModules/EntityManipulation/MeshProperties.as b/roe/Editor/DockPanelModules/EntityManipulation/MeshProperties.as index 3532d6f..996bebf 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/MeshProperties.as +++ b/roe/Editor/DockPanelModules/EntityManipulation/MeshProperties.as @@ -1,4 +1,3 @@ - void renderMeshComponent(any@ data) { Entity entity; data.retrieve(entity); @@ -42,8 +41,7 @@ void renderMeshComponent(any@ data) { } } - -void setMeshComponentMesh(any@ meshComponent_data, any@ mesh_data){ +void setMeshComponentMesh(any@ meshComponent_data, any@ mesh_data) { string mesh; mesh_data.retrieve(mesh); @@ -60,4 +58,4 @@ void removeMeshComponent(any@ entity) { if (UI::menuItem("Remove")) { ent.removeMeshComponent(); } -} \ No newline at end of file +} diff --git a/roe/Editor/DockPanelModules/EntityManipulation/PropertiesPannel.as b/roe/Editor/DockPanelModules/EntityManipulation/PropertiesPannel.as index 7172c8f..e286e86 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/PropertiesPannel.as +++ b/roe/Editor/DockPanelModules/EntityManipulation/PropertiesPannel.as @@ -1,11 +1,10 @@ - class PropertiesPannel : DockPanel { float slider = 0; vec3 slid; vec3 slid2; void onRender() { - Entity entity = activeEntity; + Entity entity = Chewico::ActiveEntity::ActiveEntity::getActiveEntity(); // We don't want to change root options if (entity.isRoot) @@ -19,7 +18,6 @@ class PropertiesPannel : DockPanel { UI::separator(); UI::textColor(0.5, 0.5, 0.5f, "Id : " + entity.id); - UI::sameline(); if (UI::buttonEnd("Add Component")) { UI::openPopup("ADD_COMPONENT", any(entity)); @@ -40,8 +38,7 @@ class PropertiesPannel : DockPanel { if (entity.hasCameraComponent()) { UI::componentNode_contextMenu("Camera Component", any(entity), renderCameraComponent, removeCameraComponent); } - - + UI::space(); UI::separator(); @@ -65,4 +62,4 @@ class PropertiesPannel : DockPanel { } } -} \ No newline at end of file +} diff --git a/roe/Editor/DockPanelModules/EntityManipulation/ShaderProperties.as b/roe/Editor/DockPanelModules/EntityManipulation/ShaderProperties.as index 8716dc3..62f4882 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/ShaderProperties.as +++ b/roe/Editor/DockPanelModules/EntityManipulation/ShaderProperties.as @@ -1,4 +1,3 @@ - void setShaderComponent(any@ shaderComponent_data, any@ shader_data) { string shader; shader_data.retrieve(shader); diff --git a/roe/Editor/DockPanelModules/EntityManipulation/Tree.as b/roe/Editor/DockPanelModules/EntityManipulation/Tree.as index 5e89b53..4138f90 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/Tree.as +++ b/roe/Editor/DockPanelModules/EntityManipulation/Tree.as @@ -21,7 +21,7 @@ class TreePannel : DockPanel { for (int i = 0; i < entity.childs.count; i++) { Entity child = entity.childs[i]; - bool isActive = child == activeEntity; + bool isActive = child == Chewico::ActiveEntity::ActiveEntity::getActiveEntity(); string displayName = child.name; if (displayName == "") { @@ -52,7 +52,7 @@ class TreePannel : DockPanel { // We can't select the entity if (UI::isItemClicked(0)) { - activeEntity = entity; + Chewico::ActiveEntity::ActiveEntity::setActiveEntity(entity); } } diff --git a/roe/Editor/DockPanelModules/EntityManipulation/active_entity.as b/roe/Editor/DockPanelModules/EntityManipulation/active_entity.as deleted file mode 100644 index 0261cfc..0000000 --- a/roe/Editor/DockPanelModules/EntityManipulation/active_entity.as +++ /dev/null @@ -1,2 +0,0 @@ - -Entity activeEntity = Engine::getRoot(); diff --git a/roe/Editor/DockPanelModules/EntityManipulation/rename_entity.as b/roe/Editor/DockPanelModules/EntityManipulation/rename_entity.as index b85bbdd..376da57 100644 --- a/roe/Editor/DockPanelModules/EntityManipulation/rename_entity.as +++ b/roe/Editor/DockPanelModules/EntityManipulation/rename_entity.as @@ -1,4 +1,3 @@ - void renameEntity(any@ data) { Entity entity; data.retrieve(entity); @@ -11,4 +10,4 @@ void renameEntity(any@ data) { if (UI::button("Accept")) { UI::closePopup(); } -} \ No newline at end of file +} diff --git a/roe/Editor/DockPanelModules/TestModule/Test.as b/roe/Editor/DockPanelModules/TestModule/Test.as index fbbff70..26ae56e 100644 --- a/roe/Editor/DockPanelModules/TestModule/Test.as +++ b/roe/Editor/DockPanelModules/TestModule/Test.as @@ -1,6 +1,8 @@ class Test : DockPanel { void onRender() { + Entity ent = Chewico::ActiveEntity::ActiveEntity::getActiveEntity(); + UI::text("Hi"); - Chewico::ActiveEntity::ActiveEntity::getActiveEntity(); + UI::text(ent.name); } } diff --git a/roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as b/roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as index de866e1..708201c 100644 --- a/roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as +++ b/roe/Editor/ScriptServiceModules/ActiveEntity/ActiveEntity.as @@ -14,4 +14,4 @@ class ActiveEntity : ServiceScript { void setActiveEntity(Entity ent) { entity = ent; } -} \ No newline at end of file +}