From d718d5ad5bd2fe8661b1bc64646ff2ff2a988442 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 27 Sep 2015 00:01:11 +0200 Subject: [PATCH] updated font and lua bindings --- WickedEngine/wiFont.cpp | 9 +- WickedEngine/wiFont.h | 2 + WickedEngine/wiFont_BindLua.cpp | 20 ++++- WickedEngine/wiFont_BindLua.h | 3 + WickedEngine/wiLoader_BindLua.cpp | 127 ++++++++++++++++++++++++++++ WickedEngine/wiLoader_BindLua.h | 23 +++++ WickedEngine/wiRenderer_BindLua.cpp | 10 +++ 7 files changed, 191 insertions(+), 3 deletions(-) diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index 3da3b3934..e4169234d 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -395,7 +395,14 @@ void wiFont::SetText(const wstring& text) { this->text = text; } - +wstring wiFont::GetText() +{ + return text; +} +string wiFont::GetTextA() +{ + return string(text.begin(),text.end()); +} wiFont::wiFontStyle::wiFontStyle(const string& newName){ diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index 7aa7d410c..24fc0e06d 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -111,6 +111,8 @@ public: void SetText(const string& text); void SetText(const wstring& text); + wstring GetText(); + string GetTextA(); void CleanUp(); }; diff --git a/WickedEngine/wiFont_BindLua.cpp b/WickedEngine/wiFont_BindLua.cpp index 33b9e57a0..818892adf 100644 --- a/WickedEngine/wiFont_BindLua.cpp +++ b/WickedEngine/wiFont_BindLua.cpp @@ -7,6 +7,8 @@ const char wiFont_BindLua::className[] = "Font"; Luna::FunctionType wiFont_BindLua::methods[] = { lunamethod(wiFont_BindLua, GetProperties), lunamethod(wiFont_BindLua, SetProperties), + lunamethod(wiFont_BindLua, GetText), + lunamethod(wiFont_BindLua, SetText), { NULL, NULL } }; Luna::PropertyType wiFont_BindLua::properties[] = { @@ -18,7 +20,7 @@ wiFont_BindLua::wiFont_BindLua(wiFont* font) if (font != nullptr) this->font = new wiFont(*font); else - this->font = nullptr; + this->font = new wiFont(); } wiFont_BindLua::wiFont_BindLua(lua_State* L) { @@ -29,7 +31,7 @@ wiFont_BindLua::wiFont_BindLua(lua_State* L) font = new wiFont(text); } else - font = nullptr; + font = new wiFont(); } wiFont_BindLua::~wiFont_BindLua() { @@ -39,12 +41,26 @@ wiFont_BindLua::~wiFont_BindLua() int wiFont_BindLua::GetProperties(lua_State* L) { + //TODO return 0; } int wiFont_BindLua::SetProperties(lua_State* L) { + //TODO return 0; } +int wiFont_BindLua::SetText(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + font->SetText(wiLua::SGetString(L, 1)); + return 0; +} +int wiFont_BindLua::GetText(lua_State* L) +{ + wiLua::SSetString(L, font->GetTextA()); + return 1; +} void wiFont_BindLua::Bind() { diff --git a/WickedEngine/wiFont_BindLua.h b/WickedEngine/wiFont_BindLua.h index 7ebd20148..80c6bd69b 100644 --- a/WickedEngine/wiFont_BindLua.h +++ b/WickedEngine/wiFont_BindLua.h @@ -19,6 +19,9 @@ public: int GetProperties(lua_State* L); int SetProperties(lua_State* L); + int SetText(lua_State* L); + int GetText(lua_State* L); + static void Bind(); }; diff --git a/WickedEngine/wiLoader_BindLua.cpp b/WickedEngine/wiLoader_BindLua.cpp index 8e749fadd..840370ae2 100644 --- a/WickedEngine/wiLoader_BindLua.cpp +++ b/WickedEngine/wiLoader_BindLua.cpp @@ -12,6 +12,7 @@ namespace wiLoader_BindLua Object_BindLua::Bind(); Armature_BindLua::Bind(); Ray_BindLua::Bind(); + AABB_BindLua::Bind(); } } @@ -367,6 +368,8 @@ const char Cullable_BindLua::className[] = "Cullable"; Luna::FunctionType Cullable_BindLua::methods[] = { lunamethod(Cullable_BindLua, Intersects), + lunamethod(Cullable_BindLua, GetAABB), + lunamethod(Cullable_BindLua, SetAABB), { NULL, NULL } }; Luna::PropertyType Cullable_BindLua::properties[] = { @@ -433,6 +436,28 @@ int Cullable_BindLua::Intersects(lua_State* L) } return 0; } +int Cullable_BindLua::GetAABB(lua_State* L) +{ + Luna::push(L, new AABB_BindLua(cullable->bounds)); + return 1; +} +int Cullable_BindLua::SetAABB(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc < 0) + { + AABB_BindLua* box = Luna::lightcheck(L, 1); + if (box) + { + + } + else + wiLua::SError(L, "SetAABB(AABB aabb) argument is not an AABB!"); + } + else + wiLua::SError(L, "SetAABB(AABB aabb) not enough arguments!"); + return 0; +} void Cullable_BindLua::Bind() { @@ -453,6 +478,8 @@ Luna::FunctionType Object_BindLua::methods[] = { lunamethod(Node_BindLua, SetName), lunamethod(Cullable_BindLua, Intersects), + lunamethod(Cullable_BindLua, GetAABB), + lunamethod(Cullable_BindLua, SetAABB), lunamethod(Transform_BindLua, AttachTo), lunamethod(Transform_BindLua, Detach), @@ -842,3 +869,103 @@ void Ray_BindLua::Bind() Luna::Register(wiLua::GetGlobal()->GetLuaState()); } } + + + + +const char AABB_BindLua::className[] = "AABB"; + +Luna::FunctionType AABB_BindLua::methods[] = { + lunamethod(AABB_BindLua, Intersects), + lunamethod(AABB_BindLua, Transform), + lunamethod(AABB_BindLua, GetMin), + lunamethod(AABB_BindLua, GetMax), + { NULL, NULL } +}; +Luna::PropertyType AABB_BindLua::properties[] = { + { NULL, NULL } +}; + +AABB_BindLua::AABB_BindLua(const AABB& aabb) :aabb(aabb) +{ +} +AABB_BindLua::AABB_BindLua(lua_State *L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* min = Luna::lightcheck(L, 1); + Vector_BindLua* max = Luna::lightcheck(L, 2); + if (min && max) + { + XMFLOAT3 fmin, fmax; + XMStoreFloat3(&fmin, min->vector); + XMStoreFloat3(&fmax, max->vector); + aabb = AABB(wiMath::Min(fmin, fmax), wiMath::Max(fmin, fmax)); + } + else + wiLua::SError(L, "AABB(Vector min,max) one of the arguments is not an AABB!"); + } + else + aabb = AABB(XMFLOAT3(0, 0, 0), XMFLOAT3(0, 0, 0)); +} +AABB_BindLua::~AABB_BindLua() +{ +} + +int AABB_BindLua::Intersects(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + AABB_BindLua* box = Luna::lightcheck(L, 1); + if (box) + { + wiLua::SSetBool(L, aabb.intersects(box->aabb) != AABB::INTERSECTION_TYPE::OUTSIDE); + return 1; + } + else + wiLua::SError(L, "Intersects(AABB aabb) argument is not an AABB!"); + } + else + wiLua::SError(L, "Intersects(AABB aabb) not enough arguments!"); + return 0; +} +int AABB_BindLua::Transform(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Matrix_BindLua* mat = Luna::lightcheck(L, 1); + if (mat) + { + Luna::push(L, new AABB_BindLua(aabb.get(mat->matrix))); + return 1; + } + else + wiLua::SError(L, "Transform(Matrix mat) argument is not a Matrix!"); + } + else + wiLua::SError(L, "Transform(Matrix mat) not enough arguments!"); + return 0; +} +int AABB_BindLua::GetMin(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&aabb.getMin()))); + return 1; +} +int AABB_BindLua::GetMax(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&aabb.getMax()))); + return 1; +} + +void AABB_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} \ No newline at end of file diff --git a/WickedEngine/wiLoader_BindLua.h b/WickedEngine/wiLoader_BindLua.h index fcab9835f..f167bc73a 100644 --- a/WickedEngine/wiLoader_BindLua.h +++ b/WickedEngine/wiLoader_BindLua.h @@ -72,6 +72,8 @@ public: ~Cullable_BindLua(); int Intersects(lua_State *L); + int GetAABB(lua_State* L); + int SetAABB(lua_State* L); static void Bind(); }; @@ -147,3 +149,24 @@ public: static void Bind(); }; +class AABB_BindLua +{ +public: + AABB aabb; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + AABB_BindLua(const AABB& ray); + AABB_BindLua(lua_State* L); + ~AABB_BindLua(); + + int Intersects(lua_State* L); + int Transform(lua_State* L); + int GetMin(lua_State* L); + int GetMax(lua_State* L); + + static void Bind(); +}; + diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 19e7f7627..3cc0963fd 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -337,6 +337,15 @@ namespace wiRenderer_BindLua wiLua::SError(L, "SetSpotLightShadowProps(int shadowMapCount, int resolution) not enough arguments!"); return 0; } + int SetDebugBoxesEnabled(lua_State* L) + { + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + wiRenderer::SetToDrawDebugBoxes(wiLua::SGetBool(L, 1)); + } + return 0; + } int Pick(lua_State* L) { @@ -451,6 +460,7 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RegisterFunc("SetDirectionalLightShadowProps", SetDirectionalLightShadowProps); wiLua::GetGlobal()->RegisterFunc("SetPointLightShadowProps", SetPointLightShadowProps); wiLua::GetGlobal()->RegisterFunc("SetSpotLightShadowProps", SetSpotLightShadowProps); + wiLua::GetGlobal()->RegisterFunc("SetDebugBoxesEnabled", SetDebugBoxesEnabled); wiLua::GetGlobal()->RegisterFunc("Pick", Pick); wiLua::GetGlobal()->RegisterFunc("DrawLine", DrawLine);