From 773c3f9c59c5dc23cb795a161cec9abdd256aa76 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Tue, 18 Aug 2015 22:48:47 +0200 Subject: [PATCH] updated lua bindings --- WickedEngine/wiLoader_BindLua.cpp | 156 +++++++++++++++++++++++++++- WickedEngine/wiLoader_BindLua.h | 44 +++++++- WickedEngine/wiRenderer.cpp | 9 ++ WickedEngine/wiRenderer.h | 1 + WickedEngine/wiRenderer_BindLua.cpp | 47 ++++++++- WickedEngine/wiRenderer_BindLua.h | 2 + 6 files changed, 254 insertions(+), 5 deletions(-) diff --git a/WickedEngine/wiLoader_BindLua.cpp b/WickedEngine/wiLoader_BindLua.cpp index 4698ac558..dc679ba74 100644 --- a/WickedEngine/wiLoader_BindLua.cpp +++ b/WickedEngine/wiLoader_BindLua.cpp @@ -4,14 +4,152 @@ namespace wiLoader_BindLua { void Bind() { + Node_BindLua::Bind(); + Transform_BindLua::Bind(); Object_BindLua::Bind(); Armature_BindLua::Bind(); } } + + + + +const char Node_BindLua::className[] = "Node"; + +Luna::FunctionType Node_BindLua::methods[] = { + lunamethod(Node_BindLua, GetName), + lunamethod(Node_BindLua, SetName), + { NULL, NULL } +}; +Luna::PropertyType Node_BindLua::properties[] = { + { NULL, NULL } +}; + +Node_BindLua::Node_BindLua(Node* node) +{ + node = node; + this->node = node; +} +Node_BindLua::Node_BindLua(lua_State *L) +{ + node = new Node(); +} +Node_BindLua::~Node_BindLua() +{ +} + +int Node_BindLua::GetName(lua_State* L) +{ + if (node == nullptr) + { + wiLua::SError(L, "GetName() node is null!"); + return 0; + } + wiLua::SSetString(L, node->name); + return 1; +} +int Node_BindLua::SetName(lua_State* L) +{ + if (node == nullptr) + { + wiLua::SError(L, "SetName(String name) node is null!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + node->name = wiLua::SGetString(L, 2); + } + else + { + wiLua::SError(L, "SetName(String name) not enough arguments!"); + } + return 0; +} + +void Node_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} + + + +const char Transform_BindLua::className[] = "Transform"; + +Luna::FunctionType Transform_BindLua::methods[] = { + lunamethod(Transform_BindLua, GetName), + lunamethod(Transform_BindLua, SetName), + + lunamethod(Transform_BindLua, DoTransform), + lunamethod(Transform_BindLua, AttachTo), + lunamethod(Transform_BindLua, Detach), + lunamethod(Transform_BindLua, ApplyTransform), + { NULL, NULL } +}; +Luna::PropertyType Transform_BindLua::properties[] = { + { NULL, NULL } +}; + +Transform_BindLua::Transform_BindLua(Transform* transform) +{ + node = transform; + this->transform = transform; +} +Transform_BindLua::Transform_BindLua(lua_State *L) +{ + transform = new Transform(); +} +Transform_BindLua::~Transform_BindLua() +{ +} + +int Transform_BindLua::DoTransform(lua_State* L) +{ + return 0; +} +int Transform_BindLua::AttachTo(lua_State* L) +{ + return 0; +} +int Transform_BindLua::Detach(lua_State* L) +{ + return 0; +} +int Transform_BindLua::ApplyTransform(lua_State* L) +{ + return 0; +} + +void Transform_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} + + + + const char Object_BindLua::className[] = "Object"; Luna::FunctionType Object_BindLua::methods[] = { + lunamethod(Object_BindLua, GetName), + lunamethod(Object_BindLua, SetName), + + lunamethod(Object_BindLua, DoTransform), + lunamethod(Object_BindLua, AttachTo), + lunamethod(Object_BindLua, Detach), + lunamethod(Object_BindLua, ApplyTransform), + lunamethod(Object_BindLua, SetTransparency), lunamethod(Object_BindLua, GetTransparency), lunamethod(Object_BindLua, SetColor), @@ -22,11 +160,14 @@ Luna::PropertyType Object_BindLua::properties[] = { { NULL, NULL } }; -Object_BindLua::Object_BindLua(Object* object) :object(object) +Object_BindLua::Object_BindLua(Object* object) { + node = object; + this->object = object; } Object_BindLua::Object_BindLua(lua_State *L) { + node = nullptr; object = nullptr; } Object_BindLua::~Object_BindLua() @@ -106,6 +247,14 @@ void Object_BindLua::Bind() const char Armature_BindLua::className[] = "Armature"; Luna::FunctionType Armature_BindLua::methods[] = { + lunamethod(Armature_BindLua, GetName), + lunamethod(Armature_BindLua, SetName), + + lunamethod(Armature_BindLua, DoTransform), + lunamethod(Armature_BindLua, AttachTo), + lunamethod(Armature_BindLua, Detach), + lunamethod(Armature_BindLua, ApplyTransform), + lunamethod(Armature_BindLua, GetActions), lunamethod(Armature_BindLua, GetBones), lunamethod(Armature_BindLua, ChangeAction), @@ -115,11 +264,14 @@ Luna::PropertyType Armature_BindLua::properties[] = { { NULL, NULL } }; -Armature_BindLua::Armature_BindLua(Armature* armature) :armature(armature) +Armature_BindLua::Armature_BindLua(Armature* armature) { + node = armature; + this->armature = armature; } Armature_BindLua::Armature_BindLua(lua_State *L) { + node = nullptr; armature = nullptr; } Armature_BindLua::~Armature_BindLua() diff --git a/WickedEngine/wiLoader_BindLua.h b/WickedEngine/wiLoader_BindLua.h index 4048be121..c86e4eea4 100644 --- a/WickedEngine/wiLoader_BindLua.h +++ b/WickedEngine/wiLoader_BindLua.h @@ -8,7 +8,47 @@ namespace wiLoader_BindLua void Bind(); } -class Object_BindLua +class Node_BindLua +{ +public: + Node* node; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + Node_BindLua(Node* node = nullptr); + Node_BindLua(lua_State *L); + ~Node_BindLua(); + + int GetName(lua_State* L); + int SetName(lua_State* L); + + static void Bind(); +}; + +class Transform_BindLua : public Node_BindLua +{ +public: + Transform* transform; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + Transform_BindLua(Transform* transform = nullptr); + Transform_BindLua(lua_State *L); + ~Transform_BindLua(); + + int DoTransform(lua_State* L); + int AttachTo(lua_State* L); + int Detach(lua_State* L); + int ApplyTransform(lua_State* L); + + static void Bind(); +}; + +class Object_BindLua : public Transform_BindLua { public: Object* object; @@ -29,7 +69,7 @@ public: static void Bind(); }; -class Armature_BindLua +class Armature_BindLua : public Transform_BindLua { public: Armature* armature; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index d5635b3f6..e0c2775bd 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -1568,6 +1568,15 @@ void wiRenderer::SetUpStates() } +Transform* wiRenderer::getTransformByName(const string& get) +{ + auto transf = transforms.find(get); + if (transf != transforms.end()) + { + return transf->second; + } + return nullptr; +} Armature* wiRenderer::getArmatureByName(const string& get) { for(Armature* armature : armatures) diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 052808fe7..4ab1496cb 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -393,6 +393,7 @@ public: static TextureView GetNoiseTexture(){ return noiseTex; } + static Transform* getTransformByName(const string& name); static Armature* getArmatureByName(const string& get); static int getActionByName(Armature* armature, const string& get); static int getBoneByName(Armature* armature, const string& get); diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 5c414c1a1..adff73485 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -13,6 +13,8 @@ namespace wiRenderer_BindLua if (!initialized) { initialized = true; + wiLua::GetGlobal()->RegisterFunc("GetTransforms", GetTransforms); + wiLua::GetGlobal()->RegisterFunc("GetTransform", GetTransform); wiLua::GetGlobal()->RegisterFunc("GetArmatures", GetArmatures); wiLua::GetGlobal()->RegisterFunc("GetArmature", GetArmature); wiLua::GetGlobal()->RegisterFunc("GetObjects", GetObjects); @@ -34,6 +36,49 @@ namespace wiRenderer_BindLua } } + int GetTransforms(lua_State* L) + { + stringstream ss(""); + for (auto& x : wiRenderer::transforms) + { + ss << x.first << endl; + } + wiLua::SSetString(L, ss.str()); + return 1; + } + int GetTransform(lua_State* L) + { + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + string name = wiLua::SGetString(L, 1); + Transform* transform = wiRenderer::getTransformByName(name); + if (transform != nullptr) + { + Object* object = dynamic_cast(transform); + if (object != nullptr) + { + Luna::push(L, new Object_BindLua(object)); + return 1; + } + Armature* armature = dynamic_cast(transform); + if (armature != nullptr) + { + Luna::push(L, new Armature_BindLua(armature)); + return 1; + } + + Luna::push(L, new Transform_BindLua(transform)); + return 1; + } + else + { + wiLua::SError(L, "GetTransform(String name) transform not found!"); + return 0; + } + } + return 0; + } int GetArmatures(lua_State* L) { stringstream ss(""); @@ -58,7 +103,7 @@ namespace wiRenderer_BindLua } else { - wiLua::SError(L, "GetArmature(String name) object not found!"); + wiLua::SError(L, "GetArmature(String name) armature not found!"); return 0; } } diff --git a/WickedEngine/wiRenderer_BindLua.h b/WickedEngine/wiRenderer_BindLua.h index 74fdbd074..c041a44af 100644 --- a/WickedEngine/wiRenderer_BindLua.h +++ b/WickedEngine/wiRenderer_BindLua.h @@ -6,6 +6,8 @@ namespace wiRenderer_BindLua void Bind(); + int GetTransforms(lua_State* L); + int GetTransform(lua_State* L); int GetArmatures(lua_State* L); int GetArmature(lua_State* L); int GetObjects(lua_State* L);