First pass on EzMesh integration (doesn't work yet)undefined
| @@ -19,12 +19,13 @@ | |||||
| using namespace lol; | using namespace lol; | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| class DemoObject : public Lolua::ObjectDef | |||||
| class DemoObject : public LuaObjectDef | |||||
| { | { | ||||
| typedef Lolua::VarPtr<DemoObject> LuaDemoObjectPtr; | |||||
| public: | public: | ||||
| DemoObject() : Lolua::ObjectDef() {} | |||||
| DemoObject() : LuaObjectDef() {} | |||||
| virtual ~DemoObject() {} | virtual ~DemoObject() {} | ||||
| static DemoObject* New(Lolua::State* l, int arg_nb) | |||||
| static DemoObject* New(LuaState* l, int arg_nb) | |||||
| { | { | ||||
| UNUSED(l); | UNUSED(l); | ||||
| UNUSED(arg_nb); | UNUSED(arg_nb); | ||||
| @@ -32,17 +33,19 @@ public: | |||||
| } | } | ||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| static int AddFive(Lolua::State* l) | |||||
| static int AddFive(LuaState* l) | |||||
| { | { | ||||
| Lolua::Var<int> i(l, 1); | |||||
| LuaInt32 i; i.Get(l, 1); | |||||
| i += 5; | i += 5; | ||||
| return i.Return(l); | return i.Return(l); | ||||
| } | } | ||||
| static int AddTenInstance(Lolua::State* l) | |||||
| static int AddTenInstance(LuaState* l) | |||||
| { | { | ||||
| Lolua::VarPtr<DemoObject> obj(l, 1); | |||||
| Lolua::Var<float> f(l, 2); | |||||
| f = obj.V()->AddTenMethod(f.V()); | |||||
| LuaStack stack(l); | |||||
| LuaDemoObjectPtr obj; | |||||
| LuaFloat f; | |||||
| stack >> obj >> f; | |||||
| f = obj->AddTenMethod(f); | |||||
| return f.Return(l); | return f.Return(l); | ||||
| } | } | ||||
| float AddTenMethod(float f) | float AddTenMethod(float f) | ||||
| @@ -50,25 +53,29 @@ public: | |||||
| return (f + 10); | return (f + 10); | ||||
| } | } | ||||
| static int GetX(Lolua::State* l) | |||||
| static int GetX(LuaState* l) | |||||
| { | { | ||||
| Lolua::VarPtr<DemoObject> obj(l, 1); | |||||
| Lolua::Var<int32_t> i; | |||||
| i = obj.V()->m_x; | |||||
| return i.Return(l); | |||||
| LuaStack stack(l); | |||||
| LuaDemoObjectPtr obj; | |||||
| LuaInt32 i; | |||||
| stack >> obj; | |||||
| i = obj->m_x; | |||||
| return stack << i; | |||||
| } | } | ||||
| static int SetX(Lolua::State* l) | |||||
| static int SetX(LuaState* l) | |||||
| { | { | ||||
| Lolua::VarPtr<DemoObject> obj(l, 1); | |||||
| Lolua::Var<int32_t> i(l, 2); | |||||
| obj.V()->m_x = i.V(); | |||||
| LuaStack stack(l); | |||||
| LuaDemoObjectPtr obj; | |||||
| LuaInt32 i; | |||||
| stack >> obj >> i; | |||||
| obj->m_x = i; | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| static const Lolua::ObjectLib* GetLib() | |||||
| static const LuaObjectLib* GetLib() | |||||
| { | { | ||||
| static const Lolua::ObjectLib lib = Lolua::ObjectLib( | |||||
| static const LuaObjectLib lib = LuaObjectLib( | |||||
| "LoluaDemo", | "LoluaDemo", | ||||
| { { "AddFive", &DemoObject::AddFive } }, | { { "AddFive", &DemoObject::AddFive } }, | ||||
| { { "AddTenInstance", &DemoObject::AddTenInstance } }, | { { "AddTenInstance", &DemoObject::AddTenInstance } }, | ||||
| @@ -80,26 +87,26 @@ public: | |||||
| }; | }; | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| static int GlobalAddString(Lolua::State* l) | |||||
| static int GlobalAddString(LuaState* l) | |||||
| { | { | ||||
| Lolua::Var<String> s(l, 1); | |||||
| s += "_added"; | |||||
| LuaString s; s.Get(l, 1); | |||||
| s() += "_added"; | |||||
| return s.Return(l); | return s.Return(l); | ||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| class LoluaDemoLoader : public Lolua::Loader | |||||
| class LoluaDemoLoader : public LuaLoader | |||||
| { | { | ||||
| public: | public: | ||||
| LoluaDemoLoader() : Lolua::Loader() | |||||
| LoluaDemoLoader() : LuaLoader() | |||||
| { | { | ||||
| Lolua::State* l = GetLuaState(); | |||||
| LuaState* l = GetLuaState(); | |||||
| //Registering demo object | //Registering demo object | ||||
| Lolua::Object::Register<DemoObject>(l); | |||||
| LuaObject::Register<DemoObject>(l); | |||||
| //Registering function | //Registering function | ||||
| Lolua::Function add_string(l, "GlobalAddString", &GlobalAddString); | |||||
| LuaFunction add_string(l, "GlobalAddString", &GlobalAddString); | |||||
| } | } | ||||
| virtual ~LoluaDemoLoader() | virtual ~LoluaDemoLoader() | ||||
| { | { | ||||
| @@ -107,7 +114,7 @@ public: | |||||
| } | } | ||||
| void TestStuff() | void TestStuff() | ||||
| { | { | ||||
| Lolua::State* l = GetLuaState(); | |||||
| LuaState* l = GetLuaState(); | |||||
| /* | /* | ||||
| //create property | //create property | ||||
| @@ -16,7 +16,6 @@ | |||||
| #include "commandstack.h" | #include "commandstack.h" | ||||
| #include "easymeshrender.h" | #include "easymeshrender.h" | ||||
| #include "easymeshbuild.h" | #include "easymeshbuild.h" | ||||
| #include "easymeshlua.h" | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -181,6 +180,12 @@ public: | |||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| //Mesh transform operations | //Mesh transform operations | ||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| /* See Translate */ | |||||
| void TranslateX(float t); | |||||
| /* See Translate */ | |||||
| void TranslateY(float t); | |||||
| /* See Translate */ | |||||
| void TranslateZ(float t); | |||||
| /* [cmd:t/tx/ty/tz] Translate vertices | /* [cmd:t/tx/ty/tz] Translate vertices | ||||
| - v : Translation quantity. | - v : Translation quantity. | ||||
| */ | */ | ||||
| @@ -263,6 +268,9 @@ public: | |||||
| - s : scale quantity. | - s : scale quantity. | ||||
| */ | */ | ||||
| void Scale(float s); | void Scale(float s); | ||||
| void ScaleX(float s); | |||||
| void ScaleY(float s); | |||||
| void ScaleZ(float s); | |||||
| void Scale(vec3 const &s); | void Scale(vec3 const &s); | ||||
| /* [cmd:m*] Mirror vertices through *-plane | /* [cmd:m*] Mirror vertices through *-plane | ||||
| Acts as an OpenBrace | Acts as an OpenBrace | ||||
| @@ -22,12 +22,12 @@ | |||||
| using namespace lol; | using namespace lol; | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| EasyMeshLuaLoader::EasyMeshLuaLoader() : Lolua::Loader() | |||||
| EasyMeshLuaLoader::EasyMeshLuaLoader() : LuaLoader() | |||||
| { | { | ||||
| Lolua::State* l = GetLuaState(); | |||||
| LuaState* l = GetLuaState(); | |||||
| //Registering demo object | //Registering demo object | ||||
| Lolua::Object::Register<EasyMeshLuaObject>(l); | |||||
| LuaObject::Register<EasyMeshLuaObject>(l); | |||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| @@ -37,7 +37,7 @@ EasyMeshLuaLoader::~EasyMeshLuaLoader() | |||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| EasyMeshLuaObject::EasyMeshLuaObject() : Lolua::ObjectDef() | |||||
| EasyMeshLuaObject::EasyMeshLuaObject() : LuaObjectDef() | |||||
| { | { | ||||
| } | } | ||||
| @@ -47,20 +47,104 @@ EasyMeshLuaObject::~EasyMeshLuaObject() | |||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| EasyMeshLuaObject* EasyMeshLuaObject::New(Lolua::State* l, int arg_nb) | |||||
| EasyMeshLuaObject* EasyMeshLuaObject::New(LuaState* l, int arg_nb) | |||||
| { | { | ||||
| UNUSED(l); | UNUSED(l); | ||||
| UNUSED(arg_nb); | UNUSED(arg_nb); | ||||
| return new EasyMeshLuaObject(); | return new EasyMeshLuaObject(); | ||||
| } | } | ||||
| //------------------------------------------------------------------------- | |||||
| const Lolua::ObjectLib* EasyMeshLuaObject::GetLib() | |||||
| //----------------------------------------------------------------------------- | |||||
| const LuaObjectLib* EasyMeshLuaObject::GetLib() | |||||
| { | { | ||||
| static const Lolua::ObjectLib lib = Lolua::ObjectLib( | |||||
| static const LuaObjectLib lib = LuaObjectLib( | |||||
| "EasyMesh", | "EasyMesh", | ||||
| { { nullptr, nullptr } }, | |||||
| { { nullptr, nullptr } }, | |||||
| //Statics | |||||
| { /*{ nullptr, nullptr }*/ }, | |||||
| //Methods | |||||
| { | |||||
| //----------------------------------------------------------------- | |||||
| { "AddCylinder", &AppendCylinder }, { "ac", &AppendCylinder }, | |||||
| { "AddSphere", &AppendSphere }, { "asph", &AppendSphere }, | |||||
| { "AddCapsule", &AppendCapsule }, { "acap", &AppendCapsule }, | |||||
| { "AddTorus", &AppendTorus }, { "ato", &AppendTorus }, | |||||
| { "AddBox", &AppendBox }, { "ab", &AppendBox }, | |||||
| { "AddStar", &AppendStar }, { "as", &AppendStar }, | |||||
| { "AddExpandedStar", &AppendExpandedStar }, { "aes", &AppendExpandedStar }, | |||||
| { "AddDisc", &AppendDisc }, { "ad", &AppendDisc }, | |||||
| { "AddTriangle", &AppendSimpleTriangle }, { "at", &AppendSimpleTriangle }, | |||||
| { "AddQuad", &AppendSimpleQuad }, { "aq", &AppendSimpleQuad }, | |||||
| { "AddCog", &AppendCog }, { "acog", &AppendCog }, | |||||
| //----------------------------------------------------------------- | |||||
| { "setcolor", &SetCurColor }, { "sc", &SetCurColor }, | |||||
| { "setcolora", &SetCurColorA }, { "sca", &SetCurColorA }, | |||||
| { "setcolorb", &SetCurColorB }, { "scb", &SetCurColorB }, | |||||
| { "setcolorv", &SetVertColor }, { "scv", &SetVertColor }, | |||||
| //----------------------------------------------------------------- | |||||
| { "TranslateX", &TranslateX }, { "tx", &TranslateX }, | |||||
| { "TranslateY", &TranslateY }, { "ty", &TranslateY }, | |||||
| { "TranslateZ", &TranslateZ }, { "tz", &TranslateZ }, | |||||
| { "Translate", &Translate }, { "t", &Translate }, | |||||
| //----------------------------------------------------------------- | |||||
| { "RotateX", &RotateX }, { "rx", &RotateX }, | |||||
| { "RotateY", &RotateY }, { "ry", &RotateY }, | |||||
| { "RotateZ", &RotateZ }, { "rz", &RotateZ }, | |||||
| { "Rotate", &Rotate }, { "r", &Rotate }, | |||||
| //----------------------------------------------------------------- | |||||
| { "ScaleX", &ScaleX }, { "sx", &ScaleX }, | |||||
| { "ScaleY", &ScaleY }, { "sy", &ScaleY }, | |||||
| { "ScaleZ", &ScaleZ }, { "sz", &ScaleZ }, | |||||
| { "Scale", &Scale }, { "s", &Scale }, | |||||
| //----------------------------------------------------------------- | |||||
| { "RadialJitter", &RadialJitter }, { "rj", &RadialJitter }, | |||||
| //----------------------------------------------------------------- | |||||
| { "TaperX", &TaperX }, { "tax", &TaperX }, | |||||
| { "TaperY", &TaperY }, { "tay", &TaperY }, | |||||
| { "TaperZ", &TaperZ }, { "taz", &TaperZ }, | |||||
| //----------------------------------------------------------------- | |||||
| { "TwistX", &TwistX }, { "twx", &TwistX }, | |||||
| { "TwistY", &TwistY }, { "twy", &TwistY }, | |||||
| { "TwistZ", &TwistZ }, { "twz", &TwistZ }, | |||||
| //----------------------------------------------------------------- | |||||
| { "ShearX", &ShearX }, { "shx", &ShearX }, | |||||
| { "ShearY", &ShearY }, { "shy", &ShearY }, | |||||
| { "ShearZ", &ShearZ }, { "shz", &ShearZ }, | |||||
| //----------------------------------------------------------------- | |||||
| { "StretchX", &StretchX }, { "stx", &StretchX }, | |||||
| { "StretchY", &StretchY }, { "sty", &StretchY }, | |||||
| { "StretchZ", &StretchZ }, { "stz", &StretchZ }, | |||||
| //----------------------------------------------------------------- | |||||
| { "BendXY", &BendXY }, { "bdxy", &BendXY }, | |||||
| { "BendXZ", &BendXZ }, { "bdxz", &BendXZ }, | |||||
| { "BendYX", &BendYX }, { "bdyx", &BendYX }, | |||||
| { "BendYZ", &BendYZ }, { "bdyz", &BendYZ }, | |||||
| { "BendZX", &BendZX }, { "bdzx", &BendZX }, | |||||
| { "BendZY", &BendZY }, { "bdzy", &BendZY }, | |||||
| //----------------------------------------------------------------- | |||||
| { "MirrorX", &MirrorX }, { "mx", &MirrorX }, | |||||
| { "MirrorY", &MirrorY }, { "my", &MirrorY }, | |||||
| { "MirrorZ", &MirrorZ }, { "mz", &MirrorZ }, | |||||
| //----------------------------------------------------------------- | |||||
| { "Loop", &LoopStart }, { "lp", &LoopStart }, | |||||
| { "LoopDo", &LoopEnd }, { "ld", &LoopEnd }, | |||||
| { "BraceOpen", &OpenBrace }, { "bop", &OpenBrace }, | |||||
| { "BraceClose", &CloseBrace }, { "bcl", &CloseBrace }, | |||||
| //----------------------------------------------------------------- | |||||
| { "VerticeMerge", &VerticesMerge }, { "vm", &VerticesMerge }, | |||||
| { "VerticeSeparate", &VerticesSeparate }, { "vs", &VerticesSeparate }, | |||||
| //----------------------------------------------------------------- | |||||
| { "Duplicate", &Duplicate }, { "dup", &Duplicate }, | |||||
| { "Smooth", &Smooth }, { "smth", &Smooth }, | |||||
| { "SplitTriangles", &SplitTriangles }, { "splt", &SplitTriangles }, | |||||
| { "Chamfer", &Chamfer }, { "cf", &Chamfer }, | |||||
| //----------------------------------------------------------------- | |||||
| { "ToggleScaleWinding", &ToggleScaleWinding }, { "tsw", &ToggleScaleWinding }, | |||||
| { "ToggleQuadWeighting", &ToggleQuadWeighting }, { "tqw", &ToggleQuadWeighting }, | |||||
| { "TogglePostBuildNormal", &TogglePostBuildNormal }, { "tpbn", &TogglePostBuildNormal }, | |||||
| { "ToggleVerticeNoCleanup", &ToggleVerticeNoCleanup }, { "tvnc", &ToggleVerticeNoCleanup }, | |||||
| //----------------------------------------------------------------- | |||||
| }, | |||||
| //Variables | |||||
| { { nullptr, nullptr, nullptr } }); | { { nullptr, nullptr, nullptr } }); | ||||
| return &lib; | return &lib; | ||||
| } | } | ||||
| @@ -16,7 +16,7 @@ namespace lol | |||||
| { | { | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| class EasyMeshLuaLoader : public Lolua::Loader | |||||
| class EasyMeshLuaLoader : public LuaLoader | |||||
| { | { | ||||
| public: | public: | ||||
| EasyMeshLuaLoader(); | EasyMeshLuaLoader(); | ||||
| @@ -24,120 +24,645 @@ public: | |||||
| }; | }; | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| class EasyMeshLuaObject : public Lolua::ObjectDef | |||||
| class EasyMeshLuaObject : public LuaObjectDef | |||||
| { | { | ||||
| typedef Lolua::VarPtr<EasyMeshLuaObject> EzMeshPtr; | |||||
| EasyMesh m_instance; | |||||
| public: | public: | ||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| EasyMeshLuaObject(); | EasyMeshLuaObject(); | ||||
| virtual ~EasyMeshLuaObject(); | virtual ~EasyMeshLuaObject(); | ||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| static EasyMeshLuaObject* New(Lolua::State* l, int arg_nb); | |||||
| static const Lolua::ObjectLib* GetLib(); | |||||
| static EasyMeshLuaObject* New(LuaState* l, int arg_nb); | |||||
| static const LuaObjectLib* GetLib(); | |||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| static int AppendCylinder(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 nsides; | |||||
| LuaFloat h, d1, d2; | |||||
| LuaBool dualside(false, true), smooth(false, true), close(false, true); | |||||
| s >> m >> nsides >> h >> d1 >> d2 >> dualside >> smooth >> close; | |||||
| m->m_instance.AppendCylinder(nsides, h, d1, d2, dualside, smooth, close); | |||||
| return 0; | |||||
| } | |||||
| static int AppendSphere(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 ndivisions; | |||||
| LuaFloat d; | |||||
| s >> m >> ndivisions >> d; | |||||
| m->m_instance.AppendSphere(ndivisions, d); | |||||
| return 0; | |||||
| } | |||||
| static int AppendCapsule(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 ndivisions; | |||||
| LuaFloat h, d; | |||||
| s >> m >> ndivisions >> h >> d; | |||||
| m->m_instance.AppendCapsule(ndivisions, h, d); | |||||
| return 0; | |||||
| } | |||||
| static int AppendTorus(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 ndivisions; | |||||
| LuaFloat d1, d2; | |||||
| s >> m >> ndivisions >> d1 >> d2; | |||||
| m->m_instance.AppendTorus(ndivisions, d1, d2); | |||||
| return 0; | |||||
| } | |||||
| static int AppendBox(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaVec3 size; | |||||
| LuaFloat chamf(0.f, true); | |||||
| LuaBool smooth(false, true); | |||||
| s >> m >> size >> chamf >> smooth; | |||||
| m->m_instance.AppendBox(size, chamf, smooth); | |||||
| return 0; | |||||
| } | |||||
| static int AppendStar(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 nbranches; | |||||
| LuaFloat d1, d2; | |||||
| LuaBool fade(false, true), fade2(false, true); | |||||
| s >> m >> nbranches >> d1 >> d2 >> fade >> fade2; | |||||
| m->m_instance.AppendStar(nbranches, d1, d2, fade, fade2); | |||||
| return 0; | |||||
| } | |||||
| static int AppendExpandedStar(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 nbranches; | |||||
| LuaFloat d1, d2, extrad(0.f, true); | |||||
| s >> m >> nbranches >> d1 >> d2 >> extrad; | |||||
| m->m_instance.AppendExpandedStar(nbranches, d1, d2, extrad); | |||||
| return 0; | |||||
| } | |||||
| static int AppendDisc(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 nsides; | |||||
| LuaFloat d; | |||||
| LuaBool fade(false, true); | |||||
| s >> m >> nsides >> d >> fade; | |||||
| m->m_instance.AppendDisc(nsides, d, fade); | |||||
| return 0; | |||||
| } | |||||
| static int AppendSimpleTriangle(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat d; | |||||
| LuaBool fade(false, true); | |||||
| s >> m >> d >> fade; | |||||
| m->m_instance.AppendSimpleTriangle(d, fade); | |||||
| return 0; | |||||
| } | |||||
| static int AppendSimpleQuad(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat size; | |||||
| LuaBool fade(false, true); | |||||
| s >> m >> size >> fade; | |||||
| m->m_instance.AppendSimpleQuad(size, fade); | |||||
| return 0; | |||||
| } | |||||
| static int AppendCog(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 nbsides; | |||||
| LuaFloat h, sidemul(0.f, true); | |||||
| LuaVec2 d0, d1, d2; | |||||
| LuaBool offset(false, true); | |||||
| s >> m >> nbsides >> h >> d0 >> d1 >> d2 >> sidemul >> offset; | |||||
| m->m_instance.AppendCog(nbsides, h, d0().x, d0().y, d1().x, d1().y, d2().x, d2().y, sidemul, offset); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int TranslateX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat f; | |||||
| s >> m >> f; | |||||
| m->m_instance.TranslateX(f); | |||||
| return 0; | |||||
| } | |||||
| static int TranslateY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat f; | |||||
| s >> m >> f; | |||||
| m->m_instance.TranslateY(f); | |||||
| return 0; | |||||
| } | |||||
| static int TranslateZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat f; | |||||
| s >> m >> f; | |||||
| m->m_instance.TranslateZ(f); | |||||
| return 0; | |||||
| } | |||||
| static int Translate(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaVec3 v; | |||||
| s >> m >> v; | |||||
| m->m_instance.Translate(v); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int RotateX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat a; | |||||
| s >> m >> a; | |||||
| m->m_instance.RotateX(a); | |||||
| return 0; | |||||
| } | |||||
| static int RotateY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat a; | |||||
| s >> m >> a; | |||||
| m->m_instance.RotateY(a); | |||||
| return 0; | |||||
| } | |||||
| static int RotateZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat a; | |||||
| s >> m >> a; | |||||
| m->m_instance.RotateZ(a); | |||||
| return 0; | |||||
| } | |||||
| static int Rotate(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat a; | |||||
| LuaVec3 v; | |||||
| s >> m >> a >> v; | |||||
| m->m_instance.Rotate(a, v); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int ScaleX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat x; | |||||
| s >> m >> x; | |||||
| m->m_instance.ScaleX(x); | |||||
| return 0; | |||||
| } | |||||
| static int ScaleY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat y; | |||||
| s >> m >> y; | |||||
| m->m_instance.ScaleY(y); | |||||
| return 0; | |||||
| } | |||||
| static int ScaleZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat z; | |||||
| s >> m >> z; | |||||
| m->m_instance.ScaleZ(z); | |||||
| return 0; | |||||
| } | |||||
| static int Scale(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaVec3 v; | |||||
| s >> m >> v; | |||||
| m->m_instance.Scale(v); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int RadialJitter(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat f; | |||||
| s >> m >> f; | |||||
| m->m_instance.RadialJitter(f); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int TaperX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat y, z, xoff(0.f, true); | |||||
| LuaBool abs(true, true); | |||||
| s >> m >> y >> z >> xoff >> abs; | |||||
| m->m_instance.TaperX(y, z, xoff, abs); | |||||
| return 0; | |||||
| } | |||||
| static int TaperY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat x, z, yoff(0.f, true); | |||||
| LuaBool abs(true, true); | |||||
| s >> m >> x >> z >> yoff >> abs; | |||||
| m->m_instance.TaperY(x, z, yoff, abs); | |||||
| return 0; | |||||
| } | |||||
| static int TaperZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat x, y, zoff(0.f, true); | |||||
| LuaBool abs(true, true); | |||||
| s >> m >> x >> y >> zoff >> abs; | |||||
| m->m_instance.TaperZ(x, y, zoff, abs); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int TwistX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.TwistX(t, toff); | |||||
| return 0; | |||||
| } | |||||
| static int TwistY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.TwistY(t, toff); | |||||
| return 0; | |||||
| } | |||||
| static int TwistZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.TwistZ(t, toff); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int ShearX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat y, z, xoff(0.f, true); | |||||
| LuaBool abs(true, true); | |||||
| s >> m >> y >> z >> xoff >> abs; | |||||
| m->m_instance.ShearX(y, z, xoff, abs); | |||||
| return 0; | |||||
| } | |||||
| static int ShearY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat x, z, yoff(0.f, true); | |||||
| LuaBool abs(true, true); | |||||
| s >> m >> x >> z >> yoff >> abs; | |||||
| m->m_instance.ShearY(x, z, yoff, abs); | |||||
| return 0; | |||||
| } | |||||
| static int ShearZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat x, y, zoff(0.f, true); | |||||
| LuaBool abs(true, true); | |||||
| s >> m >> x >> y >> zoff >> abs; | |||||
| m->m_instance.ShearZ(x, y, zoff, abs); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int StretchX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat y, z, xoff(0.f, true); | |||||
| s >> m >> y >> z >> xoff; | |||||
| m->m_instance.StretchX(y, z, xoff); | |||||
| return 0; | |||||
| } | |||||
| static int StretchY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat x, z, yoff(0.f, true); | |||||
| s >> m >> x >> z >> yoff; | |||||
| m->m_instance.StretchY(x, z, yoff); | |||||
| return 0; | |||||
| } | |||||
| static int StretchZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat x, y, zoff(0.f, true); | |||||
| s >> m >> x >> y >> zoff; | |||||
| m->m_instance.StretchZ(x, y, zoff); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int BendXY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.BendXY(t, toff); | |||||
| return 0; | |||||
| } | |||||
| static int BendXZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.BendXZ(t, toff); | |||||
| return 0; | |||||
| } | |||||
| static int BendYX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.BendYX(t, toff); | |||||
| return 0; | |||||
| } | |||||
| static int BendYZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.BendYZ(t, toff); | |||||
| return 0; | |||||
| } | |||||
| static int BendZX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.BendZX(t, toff); | |||||
| return 0; | |||||
| } | |||||
| static int BendZY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat t, toff(0.f, true); | |||||
| s >> m >> t >> toff; | |||||
| m->m_instance.BendZY(t, toff); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int MirrorX(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.MirrorX(); | |||||
| return 0; | |||||
| } | |||||
| static int MirrorY(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.MirrorY(); | |||||
| return 0; | |||||
| } | |||||
| static int MirrorZ(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.MirrorZ(); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int LoopStart(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 loopnb; | |||||
| s >> m >> loopnb; | |||||
| m->m_instance.LoopStart(loopnb); | |||||
| return 0; | |||||
| } | |||||
| static int LoopEnd(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.LoopEnd(); | |||||
| return 0; | |||||
| } | |||||
| static int OpenBrace(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.OpenBrace(); | |||||
| return 0; | |||||
| } | |||||
| static int CloseBrace(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.CloseBrace(); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int ToggleScaleWinding(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.ToggleScaleWinding(); | |||||
| return 0; | |||||
| } | |||||
| static int ToggleQuadWeighting(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.ToggleQuadWeighting(); | |||||
| return 0; | |||||
| } | |||||
| static int TogglePostBuildNormal(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.TogglePostBuildNormal(); | |||||
| return 0; | |||||
| } | |||||
| static int ToggleVerticeNoCleanup(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.ToggleVerticeNoCleanup(); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int VerticesMerge(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.VerticesMerge(); | |||||
| return 0; | |||||
| } | |||||
| static int VerticesSeparate(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| m->m_instance.VerticesSeparate(); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int Duplicate(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaVec3 ds(vec3(1.f)); | |||||
| s >> m >> ds; | |||||
| m->m_instance.DupAndScale(ds, true); | |||||
| return 0; | |||||
| } | |||||
| static int Smooth(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 pass, split_per_pass, smooth_per_pass; | |||||
| s >> m >> pass >> split_per_pass >> smooth_per_pass; | |||||
| m->m_instance.SmoothMesh(pass, split_per_pass, smooth_per_pass); | |||||
| return 0; | |||||
| } | |||||
| static int SplitTriangles(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaInt32 pass; | |||||
| s >> m >> pass; | |||||
| m->m_instance.SplitTriangles(pass); | |||||
| return 0; | |||||
| } | |||||
| static int Chamfer(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| LuaFloat f; | |||||
| s >> m >> f; | |||||
| m->m_instance.Chamfer(f); | |||||
| return 0; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| static int SetCurColor(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| LuaVec4 c; | |||||
| if (s.GetArgs() == 1 && !c.IsValid(l, 2)) | |||||
| { | |||||
| LuaString str; | |||||
| s >> str; | |||||
| c = Color::C8BppHexString(str); | |||||
| } | |||||
| m->m_instance.SetCurColor(c); | |||||
| return 0; | |||||
| } | |||||
| static int SetCurColorA(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| LuaVec4 c; | |||||
| if (s.GetArgs() == 1 && !c.IsValid(l, 2)) | |||||
| { | |||||
| LuaString str; | |||||
| s >> str; | |||||
| c = Color::C8BppHexString(str); | |||||
| } | |||||
| m->m_instance.SetCurColorA(c); | |||||
| return 0; | |||||
| } | |||||
| static int SetCurColorB(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| LuaVec4 c; | |||||
| if (s.GetArgs() == 1 && !c.IsValid(l, 2)) | |||||
| { | |||||
| LuaString str; | |||||
| s >> str; | |||||
| c = Color::C8BppHexString(str); | |||||
| } | |||||
| m->m_instance.SetCurColorB(c); | |||||
| return 0; | |||||
| } | |||||
| static int SetVertColor(LuaState* l) | |||||
| { | |||||
| LuaStack s(l); | |||||
| EzMeshPtr m; | |||||
| s >> m; | |||||
| LuaVec4 c; | |||||
| if (s.GetArgs() == 1 && !c.IsValid(l, 2)) | |||||
| { | |||||
| LuaString str; | |||||
| s >> str; | |||||
| c = Color::C8BppHexString(str); | |||||
| } | |||||
| m->m_instance.SetVertColor(c); | |||||
| return 0; | |||||
| } | |||||
| /* | /* | ||||
| (csgu|csgunion) { return token::T_CSGUNION; } | (csgu|csgunion) { return token::T_CSGUNION; } | ||||
| (csgs|CsgSub) { return token::T_CSGSUBSTRACT; } | (csgs|CsgSub) { return token::T_CSGSUBSTRACT; } | ||||
| (csgsl|CsgSubL) { return token::T_CSGSUBSTRACTLOSS; } | (csgsl|CsgSubL) { return token::T_CSGSUBSTRACTLOSS; } | ||||
| (csga|csgand) { return token::T_CSGAND; } | (csga|csgand) { return token::T_CSGAND; } | ||||
| (csgx|csgxor) { return token::T_CSGXOR; } | (csgx|csgxor) { return token::T_CSGXOR; } | ||||
| (lp|loop) { return token::T_LOOP; } | |||||
| (sc|setcolor) { return token::T_COLOR; } | |||||
| (sca|setcolora) { return token::T_ACOLOR; } | |||||
| (scb|setcolorb) { return token::T_BCOLOR; } | |||||
| (scv|setcolorv) { return token::T_VCOLOR; } | |||||
| (tsw|tglscalewind) { return token::T_TOGGLESCALEWINDING; } | |||||
| (tqw|tglquadweight) { return token::T_TOGGLEQUADWEIGHTING; } | |||||
| (tpbn|tglpstbuildnormal) { return token::T_TOGGLEPOSTBUILDNORMAL; } | |||||
| (tvnc|tglvertnocleanup) { return token::T_TOGGLEVERTNOCLEANUP; } | |||||
| (vm|vertmerge) { return token::T_VERTMERGE; } | |||||
| (vs|vertseparate) { return token::T_VERTSEPARATE; } | |||||
| (tx|translatex) { return token::T_TRANSLATEX; } | |||||
| (ty|translatey) { return token::T_TRANSLATEY; } | |||||
| (tz|translatez) { return token::T_TRANSLATEZ; } | |||||
| (t|translate) { return token::T_TRANSLATE; } | |||||
| (rx|rotatex) { return token::T_ROTATEX; } | |||||
| (ry|rotatey) { return token::T_ROTATEY; } | |||||
| (rz|rotatez) { return token::T_ROTATEZ; } | |||||
| (r|rotate) { return token::T_ROTATE; } | |||||
| (rj|radialjitter) { return token::T_RADIALJITTER; } | |||||
| (tax|taperx) { return token::T_TAPERX; } | |||||
| (tay|tapery) { return token::T_TAPERY; } | |||||
| (taz|taperz) { return token::T_TAPERZ; } | |||||
| (twx|twistx) { return token::T_TWISTX; } | |||||
| (twy|twisty) { return token::T_TWISTY; } | |||||
| (twz|twistz) { return token::T_TWISTZ; } | |||||
| (shx|shearx) { return token::T_SHEARX; } | |||||
| (shy|sheary) { return token::T_SHEARY; } | |||||
| (shz|shearz) { return token::T_SHEARZ; } | |||||
| (stx|stretchx) { return token::T_STRETCHX; } | |||||
| (sty|stretchy) { return token::T_STRETCHY; } | |||||
| (stz|stretchz) { return token::T_STRETCHZ; } | |||||
| (bdxy|bendxy) { return token::T_BENDXY; } | |||||
| (bdxz|bendxz) { return token::T_BENDXZ; } | |||||
| (bdyx|bendyx) { return token::T_BENDYX; } | |||||
| (bdyz|bendyz) { return token::T_BENDYZ; } | |||||
| (bdzx|bendzx) { return token::T_BENDZX; } | |||||
| (bdzy|bendzy) { return token::T_BENDZY; } | |||||
| (sx|scalex) { return token::T_SCALEX; } | |||||
| (sy|scaley) { return token::T_SCALEY; } | |||||
| (sz|scalez) { return token::T_SCALEZ; } | |||||
| (s|scale) { return token::T_SCALE; } | |||||
| (mx|mirrorx) { return token::T_MIRRORX; } | |||||
| (my|mirrory) { return token::T_MIRRORY; } | |||||
| (mz|mirrorz) { return token::T_MIRRORZ; } | |||||
| (ch|chamfer) { return token::T_CHAMFER; } | |||||
| (splt|splittriangle) { return token::T_SPLITTRIANGLE; } | |||||
| (smth|smooth) { return token::T_SMOOTHMESH; } | |||||
| (dup|duplicate) { return token::T_DUPLICATE; } | |||||
| (ac|addcylinder) { return token::T_CYLINDER; } | |||||
| (asph|addsphere) { return token::T_SPHERE; } | |||||
| (acap|addcapsule) { return token::T_CAPSULE; } | |||||
| (ato|addtorus) { return token::T_TORUS; } | |||||
| (ab|addbox) { return token::T_BOX; } | |||||
| (ascb|addsmoothchamfbox) { return token::T_SMOOTHCHAMFBOX; } | |||||
| (afcb|addflatchamfbox) { return token::T_FLATCHAMFBOX; } | |||||
| (as|addstar) { return token::T_STAR; } | |||||
| (aes|addexpandedstar) { return token::T_EXPANDEDSTAR; } | |||||
| (ad|adddisc) { return token::T_DISC; } | |||||
| (at|addtriangle) { return token::T_TRIANGLE; } | |||||
| (aq|addquad) { return token::T_QUAD; } | |||||
| (acg|addcog) { return token::T_COG; } | |||||
| */ | */ | ||||
| /* | |||||
| %{ *//* ======= BASE COLOR TYPES ========================================= *//* % | |||||
| } | |||||
| %{ *//* COLOR *//* %} | |||||
| #[0-9a-fA-F]{3} { | |||||
| uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); | |||||
| yylval->u32val = 0x11000000u * (tmp >> 8) | |||||
| | 0x00110000u * ((tmp >> 4) & 0xf) | |||||
| | 0x00001100u * (tmp & 0xf) | |||||
| | 0x000000ffu; | |||||
| return token::COLOR; } | |||||
| #[0-9a-fA-F]{4} { | |||||
| uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); | |||||
| yylval->u32val = 0x11000000u * (tmp >> 12) | |||||
| | 0x00110000u * ((tmp >> 8) & 0xf) | |||||
| | 0x00001100u * ((tmp >> 4) & 0xf) | |||||
| | 0x00000011u * (tmp & 0xf); | |||||
| return token::COLOR; } | |||||
| #[0-9a-fA-F]{6} { | |||||
| yylval->u32val = 0xffu | |||||
| | 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16); | |||||
| return token::COLOR; } | |||||
| #[0-9a-fA-F]{8} { | |||||
| yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16); | |||||
| return token::COLOR; } | |||||
| */ | |||||
| }; | }; | ||||
| @@ -15,6 +15,11 @@ | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| //----------------------------------------------------------------------------- | |||||
| void EasyMesh::TranslateX(float t) { Translate(vec3(t, 0.f, 0.f)); } | |||||
| void EasyMesh::TranslateY(float t) { Translate(vec3(0.f, t, 0.f)); } | |||||
| void EasyMesh::TranslateZ(float t) { Translate(vec3(0.f, 0.f, t)); } | |||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| void EasyMesh::Translate(vec3 const &v) | void EasyMesh::Translate(vec3 const &v) | ||||
| { | { | ||||
| @@ -188,6 +193,9 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n | |||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| void EasyMesh::Scale(float s) { Scale(vec3(s)); } | void EasyMesh::Scale(float s) { Scale(vec3(s)); } | ||||
| void EasyMesh::ScaleX(float s) { Scale(vec3(s, 0.f, 0.f)); } | |||||
| void EasyMesh::ScaleY(float s) { Scale(vec3(0.f, s, 0.f)); } | |||||
| void EasyMesh::ScaleZ(float s) { Scale(vec3(0.f, 0.f, s)); } | |||||
| void EasyMesh::Scale(vec3 const &s) | void EasyMesh::Scale(vec3 const &s) | ||||
| { | { | ||||
| if (BD()->IsEnabled(MeshBuildOperation::CommandRecording)) | if (BD()->IsEnabled(MeshBuildOperation::CommandRecording)) | ||||
| @@ -55,5 +55,35 @@ String Color::HexString8Bpp(vec4 c) | |||||
| return String::Printf("%02x%2x%02x%02x", c2.r, c2.g, c2.b, c2.a); | return String::Printf("%02x%2x%02x%02x", c2.r, c2.g, c2.b, c2.a); | ||||
| } | } | ||||
| /* | |||||
| * Conversion from colours to hexadecimal | |||||
| */ | |||||
| vec4 Color::C8BppHexString(String s) | |||||
| { | |||||
| String c = s[0] == '#' ? &s[1] : s; | |||||
| uint32_t tmp = std::strtol(c.C(), nullptr, 16); | |||||
| if (c.Count() == 3) | |||||
| { | |||||
| tmp = 0x11000000u * (tmp >> 8) | |||||
| | 0x00110000u * ((tmp >> 4) & 0xf) | |||||
| | 0x00001100u * (tmp & 0xf) | |||||
| | 0x000000ffu; | |||||
| } | |||||
| else if (c.Count() == 4) | |||||
| { | |||||
| tmp = 0x11000000u * (tmp >> 12) | |||||
| | 0x00110000u * ((tmp >> 8) & 0xf) | |||||
| | 0x00001100u * ((tmp >> 4) & 0xf) | |||||
| | 0x00000011u * (tmp & 0xf); | |||||
| } | |||||
| else if (c.Count() == 6) | |||||
| { | |||||
| tmp = 0xffu | 0x100u * tmp; | |||||
| } | |||||
| vec4 color(0.f); | |||||
| ivec4 v(tmp >> 24, (tmp >> 16) & 0xff, (tmp >> 8) & 0xff, tmp & 0xff); | |||||
| return vec4(v) * (1.f / 255.f); | |||||
| } | |||||
| } /* namespace lol */ | } /* namespace lol */ | ||||
| @@ -53,6 +53,7 @@ | |||||
| #include <lol/../application/application.h> | #include <lol/../application/application.h> | ||||
| #include <lol/../easymesh/csgbsp.h> | #include <lol/../easymesh/csgbsp.h> | ||||
| #include <lol/../easymesh/easymesh.h> | #include <lol/../easymesh/easymesh.h> | ||||
| #include <lol/../easymesh/easymeshlua.h> | |||||
| // Managers | // Managers | ||||
| #include <lol/../ticker.h> | #include <lol/../ticker.h> | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| class Color | |||||
| class Color : public vec4 | |||||
| { | { | ||||
| public: | public: | ||||
| /* | /* | ||||
| @@ -317,15 +317,20 @@ public: | |||||
| static vec3 WavelengthToCIExyY(float nm); | static vec3 WavelengthToCIExyY(float nm); | ||||
| /* | /* | ||||
| * Convert colors to hex strings. | |||||
| */ | |||||
| * Convert colors to hex strings. | |||||
| */ | |||||
| static String HexString4Bpp(vec3 c); | static String HexString4Bpp(vec3 c); | ||||
| static String HexString4Bpp(vec4 c); | static String HexString4Bpp(vec4 c); | ||||
| static String HexString8Bpp(vec3 c); | static String HexString8Bpp(vec3 c); | ||||
| static String HexString8Bpp(vec4 c); | static String HexString8Bpp(vec4 c); | ||||
| /* | /* | ||||
| * Some predefined colours | |||||
| * Convert hex strings to colors. | |||||
| */ | |||||
| static vec4 C8BppHexString(String c); | |||||
| /* | |||||
| * Some predefined colours | |||||
| */ | */ | ||||
| static const vec4 black, red, green, yellow, blue, magenta, cyan, white, gray_dark, gray, gray_light; | static const vec4 black, red, green, yellow, blue, magenta, cyan, white, gray_dark, gray, gray_light; | ||||
| }; | }; | ||||
| @@ -25,7 +25,7 @@ class LuaBaseData | |||||
| { | { | ||||
| friend class Lolua::Loader; | friend class Lolua::Loader; | ||||
| static int LuaPanic(Lolua::State* L) | |||||
| static int LuaPanic(LuaState* L) | |||||
| { | { | ||||
| char const *message = lua_tostring(L, -1); | char const *message = lua_tostring(L, -1); | ||||
| Log::Error("%s\n", message); | Log::Error("%s\n", message); | ||||
| @@ -33,13 +33,13 @@ class LuaBaseData | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| static int LuaDoFile(Lolua::State *L) | |||||
| static int LuaDoFile(LuaState *L) | |||||
| { | { | ||||
| if (lua_isnoneornil(L, 1)) | if (lua_isnoneornil(L, 1)) | ||||
| return LUA_ERRFILE; | return LUA_ERRFILE; | ||||
| Lolua::Var<char const*> var(L, 1); | |||||
| char const *filename = var.V();// lua_tostring(L, 1); | |||||
| LuaCharPtr var; var.Get(L, 1); | |||||
| char const *filename = var;// lua_tostring(L, 1); | |||||
| int status = LUA_ERRFILE; | int status = LUA_ERRFILE; | ||||
| array<String> pathlist = System::GetPathList(filename); | array<String> pathlist = System::GetPathList(filename); | ||||
| @@ -78,7 +78,7 @@ Loader::Loader() | |||||
| luaL_openlibs(m_lua_state); | luaL_openlibs(m_lua_state); | ||||
| /* Override dofile() */ | /* Override dofile() */ | ||||
| Lolua::Function do_file(m_lua_state, "dofile", LuaBaseData::LuaDoFile); | |||||
| LuaFunction do_file(m_lua_state, "dofile", LuaBaseData::LuaDoFile); | |||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| @@ -96,7 +96,7 @@ bool Loader::ExecLua(String const &lua) | |||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| Lolua::State* Loader::GetLuaState() | |||||
| LuaState* Loader::GetLuaState() | |||||
| { | { | ||||
| return m_lua_state; | return m_lua_state; | ||||
| } | } | ||||
| @@ -19,6 +19,8 @@ | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| typedef lua_State LuaState; | |||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| namespace Lolua | namespace Lolua | ||||
| { | { | ||||
| @@ -31,7 +33,6 @@ typedef struct ClassVar | |||||
| lua_CFunction get; | lua_CFunction get; | ||||
| lua_CFunction set; | lua_CFunction set; | ||||
| } ClassVar; | } ClassVar; | ||||
| typedef lua_State State; | |||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| struct ObjectLib | struct ObjectLib | ||||
| @@ -100,7 +101,7 @@ class ObjectDef | |||||
| public: | public: | ||||
| ObjectDef() { } | ObjectDef() { } | ||||
| virtual ~ObjectDef() { } | virtual ~ObjectDef() { } | ||||
| static ObjectDef* New(State* l, int arg_nb) | |||||
| static ObjectDef* New(LuaState* l, int arg_nb) | |||||
| { | { | ||||
| UNUSED(l); | UNUSED(l); | ||||
| UNUSED(arg_nb); | UNUSED(arg_nb); | ||||
| @@ -122,7 +123,7 @@ public: | |||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| template <typename TLuaClass> | template <typename TLuaClass> | ||||
| static void Register(State *l) | |||||
| static void Register(LuaState *l) | |||||
| { | { | ||||
| //Default statics | //Default statics | ||||
| static const luaL_Reg default_statics[] | static const luaL_Reg default_statics[] | ||||
| @@ -208,7 +209,7 @@ public: | |||||
| protected: | protected: | ||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| template <typename TLuaClass> | template <typename TLuaClass> | ||||
| static int New(State* l) | |||||
| static int New(LuaState* l) | |||||
| { | { | ||||
| //Number of arguments | //Number of arguments | ||||
| int n_args = lua_gettop(l); | int n_args = lua_gettop(l); | ||||
| @@ -227,11 +228,11 @@ protected: | |||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| template <typename TLuaClass> | template <typename TLuaClass> | ||||
| static int Del(State * l) | |||||
| static int Del(LuaState * l) | |||||
| { | { | ||||
| VarPtr<TLuaClass> obj(l, 1); | |||||
| ASSERT(obj.V()); | |||||
| delete obj.V(); | |||||
| VarPtr<TLuaClass> obj; obj.Get(l, 1); | |||||
| ASSERT(obj()); | |||||
| delete obj(); | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| }; | }; | ||||
| @@ -240,7 +241,7 @@ protected: | |||||
| class Function | class Function | ||||
| { | { | ||||
| public: | public: | ||||
| Function(State* l, const char* name, int(*function)(State*)) | |||||
| Function(LuaState* l, const char* name, int(*function)(LuaState*)) | |||||
| { | { | ||||
| lua_pushcfunction(l, function); | lua_pushcfunction(l, function); | ||||
| lua_setglobal(l, name); | lua_setglobal(l, name); | ||||
| @@ -253,22 +254,60 @@ class VarPtr | |||||
| { | { | ||||
| protected: | protected: | ||||
| T* m_value = nullptr; | T* m_value = nullptr; | ||||
| bool m_optional = false; | |||||
| public: | public: | ||||
| VarPtr() { } | |||||
| VarPtr(T* value) { m_value = value; } | |||||
| VarPtr(State* l, int index) { InnerGet(l, index); } | |||||
| inline T* V() { return m_value; } | |||||
| inline T* operator=(T* value) { m_value = value; } | |||||
| inline int Return(State* l) { InnerPush(l); return 1; } | |||||
| VarPtr() { } | |||||
| VarPtr(T* value, bool optional = false) | |||||
| { | |||||
| m_value = value; | |||||
| m_optional = optional; | |||||
| } | |||||
| VarPtr(LuaState* l, int& index, bool optional = false) | |||||
| { | |||||
| m_optional = optional; | |||||
| GetInc(l, index); | |||||
| } | |||||
| inline T* operator ()() { return m_value; } | |||||
| inline T* operator ->() { return m_value; } | |||||
| inline T* operator=(T* value) { m_value = value; } | |||||
| inline bool IsValid(LuaState* l, int index) | |||||
| { | |||||
| return InnerValid(l, index); | |||||
| } | |||||
| private: | |||||
| inline void GetInc(LuaState* l, int& index) | |||||
| { | |||||
| bool is_nil = lua_isnil(l, index); | |||||
| if (!m_optional || (!is_nil && InnerIsValid(l, index))) | |||||
| { | |||||
| ASSERT(!is_nil); | |||||
| InnerGet(l, index); | |||||
| } | |||||
| } | |||||
| public: | |||||
| inline void Get(LuaState* l, int index) | |||||
| { | |||||
| int idx = index; | |||||
| GetInc(l, idx); | |||||
| } | |||||
| inline int Return(LuaState* l) | |||||
| { | |||||
| InnerPush(l); | |||||
| return 1; | |||||
| } | |||||
| protected: | protected: | ||||
| virtual void InnerGet(State* l, int index) | |||||
| virtual bool InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| return !!lua_isuserdata(l, index); | |||||
| } | |||||
| virtual void InnerGet(LuaState* l, int& index) | |||||
| { | { | ||||
| T** obj = static_cast<T**>(luaL_checkudata(l, index, Object::GetMethodName<T>())); | |||||
| T** obj = static_cast<T**>(luaL_checkudata(l, index++, Object::GetMethodName<T>())); | |||||
| m_value = obj ? *obj : nullptr; | m_value = obj ? *obj : nullptr; | ||||
| } | } | ||||
| void InnerPush(State* l) | |||||
| void InnerPush(LuaState* l) | |||||
| { | { | ||||
| T** data = (T**)lua_newuserdata(l, sizeof(T*)); | T** data = (T**)lua_newuserdata(l, sizeof(T*)); | ||||
| *data = m_value; | *data = m_value; | ||||
| @@ -280,12 +319,12 @@ class VarPtrLight | |||||
| { | { | ||||
| public: | public: | ||||
| VarPtrLight() : VarPtr() { } | VarPtrLight() : VarPtr() { } | ||||
| VarPtrLight(T* value) : VarPtr(T* value) { } | |||||
| VarPtrLight(State* l, int index) : VarPtr(State* l, int index) { } | |||||
| VarPtrLight(T* value, bool optional = false) : VarPtr(value, optional) { } | |||||
| VarPtrLight(LuaState* l, int& index, bool optional = false) : VarPtr(l, index, optional) { } | |||||
| protected: | protected: | ||||
| virtual void InnerGet(State* l, int index) | |||||
| virtual void InnerGet(LuaState* l, int& index) | |||||
| { | { | ||||
| T** obj = static_cast<T**>(luaL_testudata(l, index, Object::GetMethodName<T>())); | |||||
| T** obj = static_cast<T**>(luaL_testudata(l, index++, Object::GetMethodName<T>())); | |||||
| m_value = obj ? *obj : nullptr; | m_value = obj ? *obj : nullptr; | ||||
| } | } | ||||
| }; | }; | ||||
| @@ -295,14 +334,51 @@ template<typename T> | |||||
| class Var | class Var | ||||
| { | { | ||||
| private: | private: | ||||
| bool m_optional = false; | |||||
| T m_value; | T m_value; | ||||
| public: | public: | ||||
| Var() { InnerInit(); } | |||||
| Var(T value) { m_value = value; } | |||||
| Var(State* l, int index) { InnerGet(l, index); } | |||||
| inline T& V() { return m_value; } | |||||
| inline int Return(State* l) { InnerPush(l); return 1; } | |||||
| Var(bool optional = false) | |||||
| { | |||||
| m_optional = optional; | |||||
| InnerInit(); | |||||
| } | |||||
| Var(T value, bool optional = false) | |||||
| { | |||||
| m_optional = optional; | |||||
| m_value = value; | |||||
| } | |||||
| Var(LuaState* l, int& index, bool optional = false) | |||||
| { | |||||
| m_optional = optional; | |||||
| GetInc(l, index); | |||||
| } | |||||
| inline operator T() { return m_value; } | |||||
| inline T& operator ()() { return m_value; } | |||||
| inline bool IsValid(LuaState* l, int index) | |||||
| { | |||||
| return InnerIsValid(l, index); | |||||
| } | |||||
| private: | |||||
| void GetInc(LuaState* l, int& index) | |||||
| { | |||||
| bool is_nil = lua_isnil(l, index); | |||||
| if (!m_optional || (!is_nil && InnerIsValid(l, index))) | |||||
| { | |||||
| ASSERT(!is_nil); | |||||
| InnerGet(l, index); | |||||
| } | |||||
| } | |||||
| public: | |||||
| inline void Get(LuaState* l, int index) | |||||
| { | |||||
| int idx = index; | |||||
| GetInc(l, idx); | |||||
| } | |||||
| inline int Return(LuaState* l) | |||||
| { | |||||
| return InnerPush(l); | |||||
| } | |||||
| inline Var<T>& operator-(const T& value) { m_value - value; return *this; } | inline Var<T>& operator-(const T& value) { m_value - value; return *this; } | ||||
| inline Var<T>& operator+(const T& value) { m_value + value; return *this; } | inline Var<T>& operator+(const T& value) { m_value + value; return *this; } | ||||
| inline Var<T>& operator*(const T& value) { m_value * value; return *this; } | inline Var<T>& operator*(const T& value) { m_value * value; return *this; } | ||||
| @@ -323,32 +399,277 @@ public: | |||||
| inline Var<T>& operator/=(const Var<T>& o) { m_value /= o.m_value; return *this; } | inline Var<T>& operator/=(const Var<T>& o) { m_value /= o.m_value; return *this; } | ||||
| inline bool operator==(const T& value) { return m_value == value; } | inline bool operator==(const T& value) { return m_value == value; } | ||||
| inline bool operator!=(const T& value) { return m_value != value; } | inline bool operator!=(const T& value) { return m_value != value; } | ||||
| inline bool operator==(const Var<T>& o) { return m_value == o.m_value; } | |||||
| inline bool operator!=(const Var<T>& o) { return m_value != o.m_value; } | |||||
| inline bool operator==(const Var<T>& o) { return m_value == o.m_value; } | |||||
| inline bool operator!=(const Var<T>& o) { return m_value != o.m_value; } | |||||
| private: | private: | ||||
| void InnerInit() { m_value = T(0); } | |||||
| void InnerGet(State* l, int index) { ASSERT(false); } | |||||
| void InnerPush(State* l) { ASSERT(false); } | |||||
| void InnerInit() { m_value = T(0); } | |||||
| bool InnerIsValid(LuaState* l, int index) { UNUSED(l); UNUSED(index); ASSERT(false); return false; } | |||||
| void InnerGet(LuaState* l, int& index) { UNUSED(l); UNUSED(index); ASSERT(false); } | |||||
| int InnerPush(LuaState* l) { UNUSED(l); ASSERT(false); return 0; } | |||||
| }; | }; | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| template<> inline void Var<String> ::InnerInit() { m_value = String(); } | |||||
| template<> inline void Var<String> ::InnerGet(State* l, int index) { m_value = lua_tostring(l, index); } | |||||
| template<> inline void Var<char const*>::InnerGet(State* l, int index) { m_value = lua_tostring(l, index); } | |||||
| template<> inline void Var<double> ::InnerGet(State* l, int index) { m_value = lua_tonumber(l, index); } | |||||
| template<> inline void Var<float> ::InnerGet(State* l, int index) { m_value = (float)lua_tonumber(l, index); } | |||||
| template<> inline void Var<int32_t> ::InnerGet(State* l, int index) { m_value = (int32_t)lua_tointeger(l, index); } | |||||
| template<> inline void Var<int64_t> ::InnerGet(State* l, int index) { m_value = lua_tointeger(l, index); } | |||||
| template<> inline void Var<uint32_t> ::InnerGet(State* l, int index) { m_value = lua_tounsigned(l, index); } | |||||
| template<> inline void Var<String> ::InnerPush(State* l) { lua_pushstring(l, m_value.C()); } | |||||
| template<> inline void Var<char const*>::InnerPush(State* l) { lua_pushstring(l, m_value); } | |||||
| template<> inline void Var<double> ::InnerPush(State* l) { lua_pushnumber(l, m_value); } | |||||
| template<> inline void Var<float> ::InnerPush(State* l) { lua_pushnumber(l, m_value); } | |||||
| template<> inline void Var<int32_t> ::InnerPush(State* l) { lua_pushinteger(l, m_value); } | |||||
| template<> inline void Var<int64_t> ::InnerPush(State* l) { lua_pushinteger(l, m_value); } | |||||
| template<> inline void Var<uint32_t> ::InnerPush(State* l) { lua_pushunsigned(l, m_value); } | |||||
| template<> inline bool Var<bool>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| return lua_isboolean(l, index); | |||||
| } | |||||
| template<> inline void Var<bool>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| m_value = !!lua_toboolean(l, index++); | |||||
| } | |||||
| template<> inline int Var<bool>::InnerPush(LuaState* l) | |||||
| { | |||||
| lua_pushboolean(l, m_value); | |||||
| return 1; | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<char const*>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| return !!lua_isstring(l, index); | |||||
| } | |||||
| template<> inline void Var<char const*>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| m_value = lua_tostring(l, index++); | |||||
| } | |||||
| template<> inline int Var<char const*>::InnerPush(LuaState* l) | |||||
| { | |||||
| lua_pushstring(l, m_value); | |||||
| return 1; | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline void Var<String>::InnerInit() | |||||
| { | |||||
| m_value = String(); | |||||
| } | |||||
| template<> inline bool Var<String>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| Var<char const*> v; | |||||
| return v.IsValid(l, index); | |||||
| } | |||||
| template<> inline void Var<String>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| Var<char const*> v(l, index); | |||||
| m_value = v(); | |||||
| } | |||||
| template<> inline int Var<String>::InnerPush(LuaState* l) | |||||
| { | |||||
| Var<char const*> v; | |||||
| v = m_value.C(); | |||||
| return v.Return(l); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<double>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| return !!lua_isnumber(l, index); | |||||
| } | |||||
| template<> inline void Var<double>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| m_value = lua_tonumber(l, index++); | |||||
| } | |||||
| template<> inline int Var<double>::InnerPush(LuaState* l) | |||||
| { | |||||
| lua_pushnumber(l, m_value); | |||||
| return 1; | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<float>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| Var<double> v; | |||||
| return v.IsValid(l, index); | |||||
| } | |||||
| template<> inline void Var<float>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| Var<double> v(l, index); | |||||
| m_value = (float)v(); | |||||
| } | |||||
| template<> inline int Var<float>::InnerPush(LuaState* l) | |||||
| { | |||||
| Var<double> v = (double)m_value; | |||||
| return v.Return(l); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<int64_t>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| return !!lua_isnumber(l, index); | |||||
| } | |||||
| template<> inline void Var<int64_t>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| m_value = lua_tointeger(l, index++); | |||||
| } | |||||
| template<> inline int Var<int64_t>::InnerPush(LuaState* l) | |||||
| { | |||||
| lua_pushinteger(l, m_value); | |||||
| return 1; | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<int32_t>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| Var<int64_t> v; | |||||
| return v.IsValid(l, index); | |||||
| } | |||||
| template<> inline void Var<int32_t>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| Var<int64_t> v(l, index); | |||||
| m_value = (int32_t)v(); | |||||
| } | |||||
| template<> inline int Var<int32_t>::InnerPush(LuaState* l) | |||||
| { | |||||
| Var<int64_t> v = (int64_t)m_value; | |||||
| return v.Return(l); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<uint32_t>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| return !!lua_isnumber(l, index); | |||||
| } | |||||
| template<> inline void Var<uint32_t>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| m_value = lua_tounsigned(l, index++); | |||||
| } | |||||
| template<> inline int Var<uint32_t>::InnerPush(LuaState* l) | |||||
| { | |||||
| lua_pushunsigned(l, m_value); | |||||
| return 1; | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<uint64_t>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| Var<uint32_t> v; | |||||
| return v.IsValid(l, index); | |||||
| } | |||||
| template<> inline void Var<uint64_t>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| Var<uint32_t> v(l, index); | |||||
| m_value = (uint64_t)v(); | |||||
| } | |||||
| template<> inline int Var<uint64_t>::InnerPush(LuaState* l) | |||||
| { | |||||
| Var<uint32_t> v = (uint32_t)m_value; | |||||
| return v.Return(l); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<vec2>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| Var<float> x; | |||||
| return x.IsValid(l, index); | |||||
| } | |||||
| template<> inline void Var<vec2>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| Var<float> x(l, index); | |||||
| Var<float> y(x(), true); y.Get(l, index); | |||||
| m_value = vec2(x, y); | |||||
| } | |||||
| template<> inline int Var<vec2>::InnerPush(LuaState* l) | |||||
| { | |||||
| Var<float> x = m_value.x; | |||||
| Var<float> y = m_value.y; | |||||
| return (x.Return(l) + y.Return(l)); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<vec3>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| Var<float> x; | |||||
| return x.IsValid(l, index); | |||||
| } | |||||
| template<> inline void Var<vec3>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| Var<float> x(l, index); | |||||
| Var<float> y(x(), true); y.Get(l, index); | |||||
| Var<float> z(x(), true); z.Get(l, index); | |||||
| m_value = vec3(x, y, z); | |||||
| } | |||||
| template<> inline int Var<vec3>::InnerPush(LuaState* l) | |||||
| { | |||||
| Var<float> x = m_value.x; | |||||
| Var<float> y = m_value.y; | |||||
| Var<float> z = m_value.z; | |||||
| return (x.Return(l) + y.Return(l) + z.Return(l)); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| template<> inline bool Var<vec4>::InnerIsValid(LuaState* l, int index) | |||||
| { | |||||
| Var<float> x; | |||||
| return x.IsValid(l, index); | |||||
| } | |||||
| template<> inline void Var<vec4>::InnerGet(LuaState* l, int& index) | |||||
| { | |||||
| Var<float> x(l, index); | |||||
| Var<float> y(x(), true); y.Get(l, index); | |||||
| Var<float> z(x(), true); z.Get(l, index); | |||||
| Var<float> w(x(), true); w.Get(l, index); | |||||
| m_value = vec4(x, y, z, w); | |||||
| } | |||||
| template<> inline int Var<vec4>::InnerPush(LuaState* l) | |||||
| { | |||||
| Var<float> x = m_value.x; | |||||
| Var<float> y = m_value.y; | |||||
| Var<float> z = m_value.z; | |||||
| Var<float> w = m_value.w; | |||||
| return (x.Return(l) + y.Return(l) + z.Return(l) + w.Return(l)); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| class Stack | |||||
| { | |||||
| public: | |||||
| Stack(LuaState* l, int32_t start_index = 1) | |||||
| { | |||||
| m_state = l; | |||||
| m_index = start_index; | |||||
| } | |||||
| virtual ~Stack() { } | |||||
| inline operator int32_t() { return m_result; } | |||||
| int32_t GetArgs() | |||||
| { | |||||
| return lua_gettop(m_state); | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| template<typename T> | |||||
| Stack& operator>>(Var<T>& var) | |||||
| { | |||||
| var = Var<T>(m_state, m_index); | |||||
| return *this; | |||||
| } | |||||
| template<typename T> | |||||
| Stack& operator>>(VarPtr<T>& var) | |||||
| { | |||||
| var = VarPtr<T>(m_state, m_index); | |||||
| return *this; | |||||
| } | |||||
| template<typename T> | |||||
| Stack& operator>>(VarPtrLight<T>& var) | |||||
| { | |||||
| var = VarPtrLight<T>(m_state, m_index); | |||||
| return *this; | |||||
| } | |||||
| //------------------------------------------------------------------------- | |||||
| template<typename T> | |||||
| Stack& operator<<(Var<T>& var) | |||||
| { | |||||
| m_result += var.Return(m_state); | |||||
| return *this; | |||||
| } | |||||
| template<typename T> | |||||
| Stack& operator<<(VarPtr<T>& var) | |||||
| { | |||||
| m_result += var.Return(m_state); | |||||
| return *this; | |||||
| } | |||||
| template<typename T> | |||||
| Stack& operator<<(VarPtrLight<T>& var) | |||||
| { | |||||
| m_result += var.Return(m_state); | |||||
| return *this; | |||||
| } | |||||
| private: | |||||
| LuaState* m_state = nullptr; | |||||
| int32_t m_index = 1; | |||||
| int32_t m_result = 0; | |||||
| }; | |||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| class Loader | class Loader | ||||
| @@ -363,26 +684,45 @@ public: | |||||
| T GetVar(String const &name) | T GetVar(String const &name) | ||||
| { | { | ||||
| lua_getglobal(m_lua_state, name.C()); | lua_getglobal(m_lua_state, name.C()); | ||||
| Var<T> var(m_lua_state, -1); | |||||
| Var<T> var; var.Get(m_lua_state, -1); | |||||
| lua_pop(m_lua_state, 1); | lua_pop(m_lua_state, 1); | ||||
| return var.V(); | |||||
| return var; | |||||
| } | } | ||||
| template<typename T> | template<typename T> | ||||
| T* GetPtr(String const &name) | T* GetPtr(String const &name) | ||||
| { | { | ||||
| lua_getglobal(m_lua_state, name.C()); | lua_getglobal(m_lua_state, name.C()); | ||||
| VarPtr<T> var(m_lua_state, -1); | |||||
| VarPtr<T> var; var.Get(m_lua_state, -1); | |||||
| lua_pop(m_lua_state, 1); | lua_pop(m_lua_state, 1); | ||||
| return var.V(); | |||||
| return var(); | |||||
| } | } | ||||
| protected: | protected: | ||||
| Lolua::State* GetLuaState(); | |||||
| LuaState* GetLuaState(); | |||||
| private: | private: | ||||
| Lolua::State* m_lua_state; | |||||
| LuaState* m_lua_state; | |||||
| }; | }; | ||||
| } /* namespace Lolua */ | } /* namespace Lolua */ | ||||
| typedef Lolua::Function LuaFunction; | |||||
| typedef Lolua::Object LuaObject; | |||||
| typedef Lolua::ObjectDef LuaObjectDef; | |||||
| typedef Lolua::ObjectLib LuaObjectLib; | |||||
| typedef Lolua::Loader LuaLoader; | |||||
| typedef Lolua::Var<bool> LuaBool; | |||||
| typedef Lolua::Var<char const*> LuaCharPtr; | |||||
| typedef Lolua::Var<String> LuaString; | |||||
| typedef Lolua::Var<double> LuaDouble; | |||||
| typedef Lolua::Var<float> LuaFloat; | |||||
| typedef Lolua::Var<int64_t> LuaInt64; | |||||
| typedef Lolua::Var<int32_t> LuaInt32; | |||||
| typedef Lolua::Var<uint32_t> LuaUInt32; | |||||
| typedef Lolua::Var<uint64_t> LuaUInt64; | |||||
| typedef Lolua::Var<vec2> LuaVec2; | |||||
| typedef Lolua::Var<vec3> LuaVec3; | |||||
| typedef Lolua::Var<vec4> LuaVec4; | |||||
| typedef Lolua::Stack LuaStack; | |||||
| } /* namespace lol */ | } /* namespace lol */ | ||||
| @@ -35,7 +35,7 @@ World g_world; | |||||
| */ | */ | ||||
| World::World() | World::World() | ||||
| : Lolua::Loader() | |||||
| : LuaLoader() | |||||
| { | { | ||||
| g_world_data.m_lua_state = GetLuaState(); | g_world_data.m_lua_state = GetLuaState(); | ||||
| } | } | ||||
| @@ -18,7 +18,7 @@ | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| class World : public Lolua::Loader | |||||
| class World : public LuaLoader | |||||
| { | { | ||||
| public: | public: | ||||
| World(); | World(); | ||||