Revamped collision system
This commit is contained in:
42
src/lua.cpp
42
src/lua.cpp
@@ -349,10 +349,9 @@ void psxsplash::Lua::RegisterGameObject(GameObject* go) {
|
||||
// Resolve each event and build the bitmask
|
||||
// Only events that exist in the script get their bit set
|
||||
if (onCreateMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_CREATE;
|
||||
if (onCollisionMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_COLLISION;
|
||||
if (onCollideWithPlayerMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_COLLISION;
|
||||
if (onInteractMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_INTERACT;
|
||||
if (onTriggerEnterMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_TRIGGER_ENTER;
|
||||
if (onTriggerStayMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_TRIGGER_STAY;
|
||||
if (onTriggerExitMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_TRIGGER_EXIT;
|
||||
if (onUpdateMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_UPDATE;
|
||||
if (onDestroyMethodWrapper.resolveGlobal(L)) eventMask |= EVENT_ON_DESTROY;
|
||||
@@ -379,9 +378,9 @@ void psxsplash::Lua::RegisterGameObject(GameObject* go) {
|
||||
}
|
||||
}
|
||||
|
||||
void psxsplash::Lua::OnCollision(GameObject* self, GameObject* other) {
|
||||
void psxsplash::Lua::OnCollideWithPlayer(GameObject* self) {
|
||||
if (!hasEvent(self, EVENT_ON_COLLISION)) return;
|
||||
onCollisionMethodWrapper.callMethod(*this, self, other);
|
||||
onCollideWithPlayerMethodWrapper.callMethod(*this, self);
|
||||
}
|
||||
|
||||
void psxsplash::Lua::OnInteract(GameObject* self) {
|
||||
@@ -394,16 +393,41 @@ void psxsplash::Lua::OnTriggerEnter(GameObject* trigger, GameObject* other) {
|
||||
onTriggerEnterMethodWrapper.callMethod(*this, trigger, other);
|
||||
}
|
||||
|
||||
void psxsplash::Lua::OnTriggerStay(GameObject* trigger, GameObject* other) {
|
||||
if (!hasEvent(trigger, EVENT_ON_TRIGGER_STAY)) return;
|
||||
onTriggerStayMethodWrapper.callMethod(*this, trigger, other);
|
||||
}
|
||||
|
||||
void psxsplash::Lua::OnTriggerExit(GameObject* trigger, GameObject* other) {
|
||||
if (!hasEvent(trigger, EVENT_ON_TRIGGER_EXIT)) return;
|
||||
onTriggerExitMethodWrapper.callMethod(*this, trigger, other);
|
||||
}
|
||||
|
||||
void psxsplash::Lua::OnTriggerEnterScript(int luaFileIndex, int triggerIndex) {
|
||||
auto L = m_state;
|
||||
L.rawGetI(LUA_REGISTRYINDEX, m_luascriptsReference);
|
||||
L.rawGetI(-1, luaFileIndex);
|
||||
if (!L.isTable(-1)) { L.clearStack(); return; }
|
||||
L.push("onTriggerEnter", 14);
|
||||
L.getTable(-2);
|
||||
if (!L.isFunction(-1)) { L.clearStack(); return; }
|
||||
L.pushNumber(triggerIndex);
|
||||
if (L.pcall(1, 0) != LUA_OK) {
|
||||
printf("Lua error: %s\n", L.toString(-1));
|
||||
}
|
||||
L.clearStack();
|
||||
}
|
||||
|
||||
void psxsplash::Lua::OnTriggerExitScript(int luaFileIndex, int triggerIndex) {
|
||||
auto L = m_state;
|
||||
L.rawGetI(LUA_REGISTRYINDEX, m_luascriptsReference);
|
||||
L.rawGetI(-1, luaFileIndex);
|
||||
if (!L.isTable(-1)) { L.clearStack(); return; }
|
||||
L.push("onTriggerExit", 13);
|
||||
L.getTable(-2);
|
||||
if (!L.isFunction(-1)) { L.clearStack(); return; }
|
||||
L.pushNumber(triggerIndex);
|
||||
if (L.pcall(1, 0) != LUA_OK) {
|
||||
printf("Lua error: %s\n", L.toString(-1));
|
||||
}
|
||||
L.clearStack();
|
||||
}
|
||||
|
||||
void psxsplash::Lua::OnDestroy(GameObject* go) {
|
||||
if (!hasEvent(go, EVENT_ON_DESTROY)) return;
|
||||
onDestroyMethodWrapper.callMethod(*this, go);
|
||||
|
||||
Reference in New Issue
Block a user