From d307a8f01eab4d3cf396a26c67503cd17084224f Mon Sep 17 00:00:00 2001 From: turanszkij Date: Mon, 21 Sep 2015 23:31:59 +0200 Subject: [PATCH] updated lua bindings --- WickedEngine/wiLua_Globals.h | 14 ++++++++ WickedEngine/wiRenderer_BindLua.cpp | 54 ++++++++++++++++------------- WickedEngine/wiRenderer_BindLua.h | 2 ++ 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/WickedEngine/wiLua_Globals.h b/WickedEngine/wiLua_Globals.h index fc9683577..246a5f7d1 100644 --- a/WickedEngine/wiLua_Globals.h +++ b/WickedEngine/wiLua_Globals.h @@ -144,5 +144,19 @@ end function math.lerp(a,b,t) return (a + (b-a)*t); end +-- clamp number between min,max +function clamp(x,min,max) + if(x < min) then + return min + elseif(x > max) then + return max + else + return x + end +end +-- clamp number between 0,1 +function saturate(x) + return clamp(x,0,1) +end )"; diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index d80d45b68..b24bdd828 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -54,6 +54,8 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RunText("PICK_OPAQUE = 0"); wiLua::GetGlobal()->RunText("PICK_TRANSPARENT = 1"); wiLua::GetGlobal()->RunText("PICK_WATER = 2"); + + wiLua::GetGlobal()->RegisterFunc("ClearWorld", ClearWorld); } } @@ -404,38 +406,36 @@ namespace wiRenderer_BindLua } return 0; } - int DrawLine(lua_State* L) - { - int argc = wiLua::SGetArgCount(L); - if (argc > 1) { - Vector_BindLua* a = Luna::lightcheck(L, 1); - Vector_BindLua* b = Luna::lightcheck(L, 2); - if (a && b) + int argc = wiLua::SGetArgCount(L); + if (argc > 1) { - XMFLOAT3 xa, xb; - XMFLOAT4 xc = XMFLOAT4(1, 1, 1, 1); - XMStoreFloat3(&xa, a->vector); - XMStoreFloat3(&xb, b->vector); - if (argc > 2) + Vector_BindLua* a = Luna::lightcheck(L, 1); + Vector_BindLua* b = Luna::lightcheck(L, 2); + if (a && b) { - Vector_BindLua* c = Luna::lightcheck(L, 3); - if (c) - XMStoreFloat4(&xc, c->vector); - else - wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); + XMFLOAT3 xa, xb; + XMFLOAT4 xc = XMFLOAT4(1, 1, 1, 1); + XMStoreFloat3(&xa, a->vector); + XMStoreFloat3(&xb, b->vector); + if (argc > 2) + { + Vector_BindLua* c = Luna::lightcheck(L, 3); + if (c) + XMStoreFloat4(&xc, c->vector); + else + wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); + } + wiRenderer::linesTemp.push_back(new Lines(xa, xb, xc)); } - wiRenderer::linesTemp.push_back(new Lines(xa, xb, xc)); + else + wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); } else - wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); + wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) not enough arguments!"); + return 0; } - else - wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) not enough arguments!"); - return 0; - } - int PutWaterRipple(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -456,4 +456,10 @@ namespace wiRenderer_BindLua wiLua::SError(L, "PutWaterRipple(String imagename, Vector position) not enough arguments!"); return 0; } + + int ClearWorld(lua_State* L) + { + wiRenderer::CleanUpStaticTemp(); + return 0; + } }; diff --git a/WickedEngine/wiRenderer_BindLua.h b/WickedEngine/wiRenderer_BindLua.h index 9b26d171c..24ebd61e4 100644 --- a/WickedEngine/wiRenderer_BindLua.h +++ b/WickedEngine/wiRenderer_BindLua.h @@ -37,5 +37,7 @@ namespace wiRenderer_BindLua int Pick(lua_State* L); int DrawLine(lua_State* L); int PutWaterRipple(lua_State* L); + + int ClearWorld(lua_State* L); };