summaryrefslogtreecommitdiff
path: root/Runtime/Scripting
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-25 23:29:21 +0800
committerchai <chaifix@163.com>2021-10-25 23:29:21 +0800
commit7ecf913256fb396e3027aac3318d996a716a52ef (patch)
tree4540835c881a63b665e2a692bf30115fd29e8bb0 /Runtime/Scripting
parent0816cd70ca1a213b6ed872bcf3c0bf0912473722 (diff)
+ job system
Diffstat (limited to 'Runtime/Scripting')
-rw-r--r--Runtime/Scripting/FileSystem/FileSystem.bind.cpp10
-rw-r--r--Runtime/Scripting/GL/GL.bind.cpp184
-rw-r--r--Runtime/Scripting/IO/IO.bind.cpp51
3 files changed, 234 insertions, 11 deletions
diff --git a/Runtime/Scripting/FileSystem/FileSystem.bind.cpp b/Runtime/Scripting/FileSystem/FileSystem.bind.cpp
deleted file mode 100644
index fea8b57..0000000
--- a/Runtime/Scripting/FileSystem/FileSystem.bind.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <iostream>
-
-#include "Runtime/Lua/LuaBind/LuaBind.h"
-
-int luaopen_GameLab_FileSystem(lua_State* L)
-{
-
- return 1;
-}
-
diff --git a/Runtime/Scripting/GL/GL.bind.cpp b/Runtime/Scripting/GL/GL.bind.cpp
index f167237..f4c9f50 100644
--- a/Runtime/Scripting/GL/GL.bind.cpp
+++ b/Runtime/Scripting/GL/GL.bind.cpp
@@ -212,11 +212,187 @@ int MatrixMode(lua_State* L)
return 0;
}
-// GL.LoadMatrix([Matrix4x4, mat44ColumnMajorTable])
+// GL.LoadMatrix([Matrix44, mat44ColumnMajorTable])
int LoadMatrix(lua_State* L)
{
LUA_BIND_STATE(L);
+ if (LuaHelper::IsType(state, "GameLab.Engine.Math.Matrix44", 1))
+ {
+ float m[16];
+ m[0] = state.GetField(1, "m00", 0.f);
+ m[1] = state.GetField(1, "m10", 0.f);
+ m[2] = state.GetField(1, "m20", 0.f);
+ m[3] = state.GetField(1, "m30", 0.f);
+
+ m[4] = state.GetField(1, "m01", 0.f);
+ m[5] = state.GetField(1, "m11", 0.f);
+ m[6] = state.GetField(1, "m21", 0.f);
+ m[7] = state.GetField(1, "m31", 0.f);
+
+ m[8] = state.GetField(1, "m02", 0.f);
+ m[9] = state.GetField(1, "m12", 0.f);
+ m[10] = state.GetField(1, "m22", 0.f);
+ m[11] = state.GetField(1, "m32", 0.f);
+
+ m[12] = state.GetField(1, "m03", 0.f);
+ m[13] = state.GetField(1, "m13", 0.f);
+ m[14] = state.GetField(1, "m23", 0.f);
+ m[15] = state.GetField(1, "m33", 0.f);
+
+ glLoadMatrixf(m);
+ }
+ else if (LuaHelper::IsType(state, "table", 1))
+ {
+ float m[16];
+ m[0] = state.GetField(1, 1, 0.f);
+ m[1] = state.GetField(1, 2, 0.f);
+ m[2] = state.GetField(1, 3, 0.f);
+ m[3] = state.GetField(1, 4, 0.f);
+
+ m[4] = state.GetField(1, 5, 0.f);
+ m[5] = state.GetField(1, 6, 0.f);
+ m[6] = state.GetField(1, 7, 0.f);
+ m[7] = state.GetField(1, 8, 0.f);
+
+ m[8] = state.GetField(1, 9, 0.f);
+ m[9] = state.GetField(1, 10, 0.f);
+ m[10] = state.GetField(1, 11, 0.f);
+ m[11] = state.GetField(1, 12, 0.f);
+
+ m[12] = state.GetField(1, 13, 0.f);
+ m[13] = state.GetField(1, 14, 0.f);
+ m[14] = state.GetField(1, 15, 0.f);
+ m[15] = state.GetField(1, 16, 0.f);
+
+ glLoadMatrixf(m);
+ }
+ else
+ {
+ state.ErrorType(1, "Matrix44 or mat44ColumnMajorTable");
+ }
+
+ return 0;
+}
+
+// GL.Ortho(l,r,b,t,n,f)
+int OrthoMatrix(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+ double l = state.GetValue<double>(1, 0);
+ double r = state.GetValue<double>(2, 0);
+ double b = state.GetValue<double>(3, 0);
+ double t = state.GetValue<double>(4, 0);
+ double n = state.GetValue<double>(5, 0);
+ double f = state.GetValue<double>(6, 0);
+ glOrtho(l, r, b, t, n, f);
+ return 0;
+}
+
+// GL.Ortho(l,r,b,t,n,f)
+int FrustumMatrix(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+ double l = state.GetValue<double>(1, 0);
+ double r = state.GetValue<double>(2, 0);
+ double b = state.GetValue<double>(3, 0);
+ double t = state.GetValue<double>(4, 0);
+ double n = state.GetValue<double>(5, 0);
+ double f = state.GetValue<double>(6, 0);
+ glFrustum(l, r, b, t, n, f);
+ return 0;
+}
+
+int MultMatrix(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+
+ if (LuaHelper::IsType(state, "GameLab.Engine.Math.Matrix44", 1))
+ {
+ float m[16];
+ m[0] = state.GetField(1, "m00", 0);
+ m[1] = state.GetField(1, "m10", 0);
+ m[2] = state.GetField(1, "m20", 0);
+ m[3] = state.GetField(1, "m30", 0);
+
+ m[4] = state.GetField(1, "m01", 0);
+ m[5] = state.GetField(1, "m11", 0);
+ m[6] = state.GetField(1, "m21", 0);
+ m[7] = state.GetField(1, "m31", 0);
+
+ m[8] = state.GetField(1, "m02", 0);
+ m[9] = state.GetField(1, "m12", 0);
+ m[10] = state.GetField(1, "m22", 0);
+ m[11] = state.GetField(1, "m32", 0);
+
+ m[12] = state.GetField(1, "m03", 0);
+ m[13] = state.GetField(1, "m13", 0);
+ m[14] = state.GetField(1, "m23", 0);
+ m[15] = state.GetField(1, "m33", 0);
+
+ glMultMatrixf(m);
+ }
+ else if (LuaHelper::IsType(state, "table", 1))
+ {
+ float m[16];
+ m[0] = state.GetField(1, 1, 0);
+ m[1] = state.GetField(1, 2, 0);
+ m[2] = state.GetField(1, 3, 0);
+ m[3] = state.GetField(1, 4, 0);
+
+ m[4] = state.GetField(1, 5, 0);
+ m[5] = state.GetField(1, 6, 0);
+ m[6] = state.GetField(1, 7, 0);
+ m[7] = state.GetField(1, 8, 0);
+
+ m[8] = state.GetField(1, 9, 0);
+ m[9] = state.GetField(1, 10, 0);
+ m[10] = state.GetField(1, 11, 0);
+ m[11] = state.GetField(1, 12, 0);
+
+ m[12] = state.GetField(1, 13, 0);
+ m[13] = state.GetField(1, 14, 0);
+ m[14] = state.GetField(1, 15, 0);
+ m[15] = state.GetField(1, 16, 0);
+
+ glMultMatrixf(m);
+ }
+ else
+ {
+ state.ErrorType(1, "Matrix44 or mat44ColumnMajorTable");
+ }
+
+ return 0;
+}
+
+int Scale(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+ float x = state.GetValue(1, 1);
+ float y = state.GetValue(2, 1);
+ float z = state.GetValue(3, 1);
+ glScalef(x, y, z);
+ return 0;
+}
+
+int Rotate(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+ float angle = state.GetValue(1, 0);
+ float x = state.GetValue(2, 0);
+ float y = state.GetValue(3, 0);
+ float z = state.GetValue(4, 1);
+ glRotatef(angle, x, y, z);
+ return 0;
+}
+
+int Translate(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+ float x = state.GetValue(1, 0);
+ float y = state.GetValue(2, 0);
+ float z = state.GetValue(3, 0);
+ glTranslatef(x, y, z);
return 0;
}
@@ -233,6 +409,12 @@ static luaL_Reg glFuncs[] = {
{"PopMatrix", PopMatrix},
{"MatrixMode", MatrixMode},
{"LoadMatrix", LoadMatrix},
+ {"LoadOrthoMatrix", OrthoMatrix},
+ {"LoadFrustumMatrix", FrustumMatrix},
+ {"MultMatrix", MultMatrix},
+ {"Scale", Scale},
+ {"Rotate", Rotate},
+ {"Translate", Translate},
{0, 0}
};
diff --git a/Runtime/Scripting/IO/IO.bind.cpp b/Runtime/Scripting/IO/IO.bind.cpp
new file mode 100644
index 0000000..d58d86f
--- /dev/null
+++ b/Runtime/Scripting/IO/IO.bind.cpp
@@ -0,0 +1,51 @@
+#include "Runtime/Lua/LuaHelper.h"
+#include "Runtime/Debug/Log.h"
+#include "Runtime/FileSystem/FileJobs.h"
+
+// IO.ReadFiles({}, callback)
+int ReadFiles(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+ LUA_BIND_CHECK(L, "TF");
+
+ std::vector<std::string> files;
+ for (int i = 1; true; ++i)
+ {
+ state.GetField(1, i);
+ if (lua_type(L, -1) != LUA_TSTRING)
+ {
+ lua_pop(L, 1);
+ break;
+ }
+ const char* f = lua_tostring(L, -1);
+ state.Pop(1);
+ files.push_back(f);
+ }
+
+ ReadFilesJob* job = new ReadFilesJob(state.GetVM());
+ job->files = files;
+ job->callback.SetRef(state, 2);
+
+ JobSystem::Instance()->AddJobAtEnd(job);
+ return 0;
+}
+
+static luaL_Reg ioFuncs[] = {
+ {"ReadFiles", ReadFiles},
+ {0, 0}
+};
+
+int luaopen_GameLab_IO(lua_State* L)
+{
+ log_info("Scripting", "luaopen_GameLab_IO()");
+
+ LUA_BIND_STATE(L);
+
+ state.PushGlobalNamespace();
+ state.PushNamespace("GameLab");
+ state.PushNamespace("IO");
+
+ state.RegisterMethods(ioFuncs);
+
+ return 1;
+} \ No newline at end of file