Compare commits
2 Commits
905e66b241
...
3cc97f579f
Author | SHA1 | Date | |
---|---|---|---|
3cc97f579f | |||
e83c55f0e4 |
@ -16,3 +16,4 @@ BraceWrapping:
|
|||||||
AllowShortIfStatementsOnASingleLine: false
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
BreakBeforeBraces: Attach
|
BreakBeforeBraces: Attach
|
||||||
NamespaceIndentation: All
|
NamespaceIndentation: All
|
||||||
|
PointerAlignment: Left
|
||||||
|
@ -67,8 +67,8 @@ Size=104,68
|
|||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Test]
|
[Window][Test]
|
||||||
Pos=60,60
|
Pos=560,275
|
||||||
Size=55,82
|
Size=396,176
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
|
@ -1,10 +1,127 @@
|
|||||||
#include "ServiceScriptGenericFunction.h"
|
#include "ServiceScriptGenericFunction.h"
|
||||||
#include "Deer/Log.h"
|
#include "Deer/Log.h"
|
||||||
|
|
||||||
|
#include "DeerStudio/EditorEngine/ErrorHandle.h"
|
||||||
#include "angelscript.h"
|
#include "angelscript.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
|
bool copyParameter(asIScriptContext* ctx, int paramIndex, int typeId,
|
||||||
|
asDWORD flags, asIScriptGeneric* gen);
|
||||||
|
bool copyReturnValue(asIScriptGeneric* gen, asIScriptContext* ctx,
|
||||||
|
asIScriptFunction* func);
|
||||||
|
|
||||||
void EditorEngine::apiFunction(asIScriptGeneric* func) {
|
void EditorEngine::apiFunction(asIScriptGeneric* func) {
|
||||||
DEER_CORE_TRACE("Called function {0}",
|
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());
|
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
|
} // namespace Deer
|
@ -1,16 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
class asIScriptGeneric;
|
class asIScriptGeneric;
|
||||||
|
class asIScriptFunction;
|
||||||
|
class asIScriptContext;
|
||||||
|
class asIScriptObject;
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace EditorEngine {
|
namespace EditorEngine {
|
||||||
struct ServiceScriptObject;
|
struct ServiceScriptObject;
|
||||||
|
struct ServiceScriptFunction {
|
||||||
|
asIScriptFunction* apiFunction = nullptr;
|
||||||
|
asIScriptContext* scriptContext = nullptr;
|
||||||
|
asIScriptObject* scriptObject = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
void apiFunction(asIScriptGeneric* gen);
|
void apiFunction(asIScriptGeneric* gen);
|
||||||
|
|
||||||
struct ApiFunctionData {
|
|
||||||
uint16_t serviceContextId;
|
|
||||||
uint16_t serviceObjectId;
|
|
||||||
};
|
|
||||||
} // namespace EditorEngine
|
} // namespace EditorEngine
|
||||||
} // namespace Deer
|
} // namespace Deer
|
@ -171,9 +171,16 @@ namespace Deer {
|
|||||||
|
|
||||||
DEER_CORE_INFO(ext_dec.str().c_str());
|
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(
|
AS_CHECK(scriptEngine->RegisterGlobalFunction(
|
||||||
ext_dec.str().c_str(), asFUNCTION(apiFunction),
|
ext_dec.str().c_str(), asFUNCTION(apiFunction),
|
||||||
asCALL_GENERIC));
|
asCALL_GENERIC, serviceScriptFunction));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace EditorEngine
|
} // namespace EditorEngine
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "DeerStudio/DeerStudio.h"
|
#include "DeerStudio/DeerStudio.h"
|
||||||
#include "DeerStudio/EditorEngine.h"
|
#include "DeerStudio/EditorEngine.h"
|
||||||
#include "DeerStudio/EditorEngine/DockPanel/DockPanelObject.h"
|
|
||||||
#include "DeerStudio/EditorEngine/DockPanel/DockPanelContext.h"
|
#include "DeerStudio/EditorEngine/DockPanel/DockPanelContext.h"
|
||||||
|
#include "DeerStudio/EditorEngine/DockPanel/DockPanelObject.h"
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
@ -10,8 +10,8 @@ namespace Deer {
|
|||||||
void panelEnable(EditorEngine::DockPanelObject& dpo);
|
void panelEnable(EditorEngine::DockPanelObject& dpo);
|
||||||
|
|
||||||
void onPannelMenuBar() {
|
void onPannelMenuBar() {
|
||||||
if (ImGui::BeginMenu("Dock Panels Show/Hide")) {
|
for (EditorEngine::DockPanelContext& pc :
|
||||||
for (EditorEngine::DockPanelContext& pc : EditorEngine::dockPanelModules) {
|
EditorEngine::dockPanelModules) {
|
||||||
if (pc.dockPanels.size() == 0)
|
if (pc.dockPanels.size() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -28,8 +28,6 @@ namespace Deer {
|
|||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void panelEnable(EditorEngine::DockPanelObject& dpo) {
|
void panelEnable(EditorEngine::DockPanelObject& dpo) {
|
||||||
@ -40,5 +38,5 @@ namespace Deer {
|
|||||||
dpo.setFlag(DockPannelFlag_ShowPannel, !enabled);
|
dpo.setFlag(DockPannelFlag_ShowPannel, !enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace DeerStudio
|
||||||
}
|
} // namespace Deer
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
void addComponentPopup(any@ data) {
|
void addComponentPopup(any@ data) {
|
||||||
Entity entity;
|
Entity entity;
|
||||||
data.retrieve(entity);
|
data.retrieve(entity);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
void renderMeshComponent(any@ data) {
|
void renderMeshComponent(any@ data) {
|
||||||
Entity entity;
|
Entity entity;
|
||||||
data.retrieve(entity);
|
data.retrieve(entity);
|
||||||
@ -42,7 +41,6 @@ void renderMeshComponent(any@ data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setMeshComponentMesh(any@ meshComponent_data, any@ mesh_data) {
|
void setMeshComponentMesh(any@ meshComponent_data, any@ mesh_data) {
|
||||||
string mesh;
|
string mesh;
|
||||||
mesh_data.retrieve(mesh);
|
mesh_data.retrieve(mesh);
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
class PropertiesPannel : DockPanel {
|
class PropertiesPannel : DockPanel {
|
||||||
float slider = 0;
|
float slider = 0;
|
||||||
vec3 slid;
|
vec3 slid;
|
||||||
vec3 slid2;
|
vec3 slid2;
|
||||||
|
|
||||||
void onRender() {
|
void onRender() {
|
||||||
Entity entity = activeEntity;
|
Entity entity = Chewico::ActiveEntity::ActiveEntity::getActiveEntity();
|
||||||
|
|
||||||
// We don't want to change root options
|
// We don't want to change root options
|
||||||
if (entity.isRoot)
|
if (entity.isRoot)
|
||||||
@ -19,7 +18,6 @@ class PropertiesPannel : DockPanel {
|
|||||||
UI::separator();
|
UI::separator();
|
||||||
UI::textColor(0.5, 0.5, 0.5f, "Id : " + entity.id);
|
UI::textColor(0.5, 0.5, 0.5f, "Id : " + entity.id);
|
||||||
|
|
||||||
|
|
||||||
UI::sameline();
|
UI::sameline();
|
||||||
if (UI::buttonEnd("Add Component")) {
|
if (UI::buttonEnd("Add Component")) {
|
||||||
UI::openPopup("ADD_COMPONENT", any(entity));
|
UI::openPopup("ADD_COMPONENT", any(entity));
|
||||||
@ -41,7 +39,6 @@ class PropertiesPannel : DockPanel {
|
|||||||
UI::componentNode_contextMenu("Camera Component", any(entity), renderCameraComponent, removeCameraComponent);
|
UI::componentNode_contextMenu("Camera Component", any(entity), renderCameraComponent, removeCameraComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UI::space();
|
UI::space();
|
||||||
|
|
||||||
UI::separator();
|
UI::separator();
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
void setShaderComponent(any@ shaderComponent_data, any@ shader_data) {
|
void setShaderComponent(any@ shaderComponent_data, any@ shader_data) {
|
||||||
string shader;
|
string shader;
|
||||||
shader_data.retrieve(shader);
|
shader_data.retrieve(shader);
|
||||||
|
@ -21,7 +21,7 @@ class TreePannel : DockPanel {
|
|||||||
|
|
||||||
for (int i = 0; i < entity.childs.count; i++) {
|
for (int i = 0; i < entity.childs.count; i++) {
|
||||||
Entity child = entity.childs[i];
|
Entity child = entity.childs[i];
|
||||||
bool isActive = child == activeEntity;
|
bool isActive = child == Chewico::ActiveEntity::ActiveEntity::getActiveEntity();
|
||||||
|
|
||||||
string displayName = child.name;
|
string displayName = child.name;
|
||||||
if (displayName == "") {
|
if (displayName == "") {
|
||||||
@ -52,7 +52,7 @@ class TreePannel : DockPanel {
|
|||||||
|
|
||||||
// We can't select the entity
|
// We can't select the entity
|
||||||
if (UI::isItemClicked(0)) {
|
if (UI::isItemClicked(0)) {
|
||||||
activeEntity = entity;
|
Chewico::ActiveEntity::ActiveEntity::setActiveEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
|
|
||||||
Entity activeEntity = Engine::getRoot();
|
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
void renameEntity(any@ data) {
|
void renameEntity(any@ data) {
|
||||||
Entity entity;
|
Entity entity;
|
||||||
data.retrieve(entity);
|
data.retrieve(entity);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
class Test : DockPanel {
|
class Test : DockPanel {
|
||||||
void onRender() {
|
void onRender() {
|
||||||
|
Entity ent = Chewico::ActiveEntity::ActiveEntity::getActiveEntity();
|
||||||
|
|
||||||
UI::text("Hi");
|
UI::text("Hi");
|
||||||
Chewico::ActiveEntity::ActiveEntity::getActiveEntity();
|
UI::text(ent.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user