Fixed lua function resolution, reverted fixed point handling
This commit is contained in:
26
src/lua.cpp
26
src/lua.cpp
@@ -34,29 +34,43 @@ end
|
||||
// Lua helpers
|
||||
|
||||
static int gameobjectSetPosition(psyqo::Lua L) {
|
||||
|
||||
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
||||
|
||||
L.getField(2, "x");
|
||||
go->position.x = L.toFixedPoint(3);
|
||||
psyqo::FixedPoint<> x(L.toNumber(3), psyqo::FixedPoint<>::RAW);
|
||||
go->position.x = x;
|
||||
L.pop();
|
||||
|
||||
L.getField(2, "y");
|
||||
go->position.y = L.toFixedPoint(3);
|
||||
psyqo::FixedPoint<> y(L.toNumber(3), psyqo::FixedPoint<>::RAW);
|
||||
go->position.y = y;
|
||||
L.pop();
|
||||
L.getField(2, "z");
|
||||
go->position.z = L.toFixedPoint(3);
|
||||
|
||||
psyqo::FixedPoint<> z(L.toNumber(3), psyqo::FixedPoint<>::RAW);
|
||||
go->position.z = z;
|
||||
L.pop();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int gameobjectGetPosition(psyqo::Lua L) {
|
||||
|
||||
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
||||
|
||||
L.newTable();
|
||||
L.push(go->position.x);
|
||||
L.pushNumber(go->position.x.raw());
|
||||
L.setField(2, "x");
|
||||
L.push(go->position.y);
|
||||
L.pushNumber(go->position.y.raw());
|
||||
L.setField(2, "y");
|
||||
L.push(go->position.z);
|
||||
L.pushNumber(go->position.z.raw());
|
||||
L.setField(2, "z");
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
void psxsplash::Lua::Init() {
|
||||
|
||||
14
src/lua.h
14
src/lua.h
@@ -42,13 +42,17 @@ class Lua {
|
||||
typedef irqus::typestring<C...> methodName;
|
||||
// Needs the methods table at index 1, and the script environment table at index 3
|
||||
static void resolveGlobal(psyqo::Lua L) {
|
||||
L.pushNumber(methodId);
|
||||
L.getTable(3);
|
||||
// Push the method name string to access the environment table
|
||||
L.push(methodName::data(), methodName::size());
|
||||
L.getTable(3);
|
||||
|
||||
if (L.isFunction(-1)) {
|
||||
L.push(methodName::data(), methodName::size());
|
||||
L.setTable(1);
|
||||
// Store the function in methods table using numeric ID as key
|
||||
L.pushNumber(methodId); // Push numeric key for methods table
|
||||
L.copy(-2); // Push the function (copy from top -2)
|
||||
L.setTable(1); // methodsTable[methodId] = function
|
||||
} else {
|
||||
L.pop();
|
||||
L.pop(); // Pop the non-function value
|
||||
}
|
||||
}
|
||||
template <typename... Args>
|
||||
|
||||
@@ -67,5 +67,5 @@ void psxsplash::SceneManager::GameTick() {
|
||||
static_cast<psyqo::FixedPoint<12>>(m_playerPosition.z));
|
||||
m_currentCamera.SetRotation(playerRotationX, playerRotationY, playerRotationZ);
|
||||
|
||||
L.OnCollision(m_gameObjects[0], m_gameObjects[1]); // Example call, replace with actual logic
|
||||
L.OnCollision(m_gameObjects[1], m_gameObjects[0]); // Example call, replace with actual logic
|
||||
}
|
||||
Reference in New Issue
Block a user