浏览代码

Add g_trigger_callback

Daniele Bartolini 11 年之前
父节点
当前提交
39d57950f8
共有 3 个文件被更改,包括 25 次插入2 次删除
  1. 18 1
      engine/lua/LuaEnvironment.cpp
  2. 1 0
      engine/lua/LuaEnvironment.h
  3. 6 1
      engine/world/World.cpp

+ 18 - 1
engine/lua/LuaEnvironment.cpp

@@ -165,6 +165,7 @@ void LuaEnvironment::call_global(const char* func, uint8_t argc, ...)
 	lua_pcall(m_L, argc, 0, -argc - 2);
 }
 
+//-----------------------------------------------------------------------------
 void LuaEnvironment::call_physics_callback(Actor* actor_0, Actor* actor_1, Unit* unit_0, Unit* unit_1, const Vector3& where, const Vector3& normal, const char* type)
 {
 	LuaStack stack(m_L);
@@ -184,4 +185,20 @@ void LuaEnvironment::call_physics_callback(Actor* actor_0, Actor* actor_1, Unit*
 	lua_pcall(m_L, 1, 0, -3);
 }
 
-} // namespace crown
+//-----------------------------------------------------------------------------
+void LuaEnvironment::call_trigger_callback(Actor* trigger, Actor* other, const char* type)
+{
+	LuaStack stack(m_L);
+
+	lua_pushcfunction(m_L, lua_system::error_handler);
+	lua_getglobal(m_L, "g_trigger_callback");
+
+	stack.push_table();
+	stack.push_key_begin("trigger"); (trigger ? stack.push_actor(trigger) : stack.push_nil()); stack.push_key_end();
+	stack.push_key_begin("other"); (other ? stack.push_actor(other) : stack.push_nil()); stack.push_key_end();
+	stack.push_key_begin("type"); stack.push_string(type); stack.push_key_end();
+
+	lua_pcall(m_L, 1, 0, -3);
+}
+
+} // namespace crown

+ 1 - 0
engine/lua/LuaEnvironment.h

@@ -78,6 +78,7 @@ public:
 
 	// HACK
 	void call_physics_callback(Actor* actor_0, Actor* actor_1, Unit* unit_0, Unit* unit_1, const Vector3& where, const Vector3& normal, const char* type);
+	void call_trigger_callback(Actor* trigger, Actor* other, const char* type);
 
 private:
 

+ 6 - 1
engine/world/World.cpp

@@ -368,11 +368,16 @@ void World::process_physics_events()
 			}
 			case physics_world::EventType::TRIGGER:
 			{
-				// physics_world::TriggerEvent trigg_ev = *(physics_world::TriggerEvent*) event;
+				physics_world::TriggerEvent trigg_ev = *(physics_world::TriggerEvent*) event;
 
 				// CE_LOGD("type    = %s", trigg_ev.type == physics_world::TriggerEvent::BEGIN_TOUCH ? "begin" : "end");
 				// CE_LOGD("trigger = (%p)", trigg_ev.trigger);
 				// CE_LOGD("other   = (%p)", trigg_ev.other);
+
+				device()->lua_environment()->call_trigger_callback(
+					trigg_ev.trigger,
+					trigg_ev.other,
+					(trigg_ev.type == physics_world::TriggerEvent::BEGIN_TOUCH ? "begin" : "end"));
 				break;
 			}
 			default: