Kaynağa Gözat

Check whether the units involved in a collision exist

Daniele Bartolini 11 yıl önce
ebeveyn
işleme
5d8863286f
2 değiştirilmiş dosya ile 6 ekleme ve 6 silme
  1. 4 4
      engine/lua/LuaEnvironment.cpp
  2. 2 2
      engine/world/World.cpp

+ 4 - 4
engine/lua/LuaEnvironment.cpp

@@ -173,10 +173,10 @@ void LuaEnvironment::call_physics_callback(Actor* actor_0, Actor* actor_1, Unit*
 	lua_getglobal(m_L, "g_physics_callback");
 
 	stack.push_table();
-	stack.push_key_begin("actor_0"); stack.push_actor(actor_0); stack.push_key_end();
-	stack.push_key_begin("actor_1"); stack.push_actor(actor_1); stack.push_key_end();
-	stack.push_key_begin("unit_0"); stack.push_unit(unit_0); stack.push_key_end();
-	stack.push_key_begin("unit_1"); stack.push_unit(unit_1); stack.push_key_end();
+	stack.push_key_begin("actor_0"); (actor_0 ? stack.push_actor(actor_0) : stack.push_nil()); stack.push_key_end();
+	stack.push_key_begin("actor_1"); (actor_1 ? stack.push_actor(actor_1) : stack.push_nil()); stack.push_key_end();
+	stack.push_key_begin("unit_0"); (unit_0 ? stack.push_unit(unit_0) : stack.push_nil()); stack.push_key_end();
+	stack.push_key_begin("unit_1"); (unit_1 ? stack.push_unit(unit_1) : stack.push_nil()); stack.push_key_end();
 	stack.push_key_begin("where"); stack.push_vector3(where); stack.push_key_end();
 	stack.push_key_begin("normal"); stack.push_vector3(normal); stack.push_key_end();
 	stack.push_key_begin("type"); stack.push_string(type); stack.push_key_end();

+ 2 - 2
engine/world/World.cpp

@@ -359,8 +359,8 @@ void World::process_physics_events()
 				device()->lua_environment()->call_physics_callback(
 					coll_ev.actors[0],
 					coll_ev.actors[1],
-					coll_ev.actors[0]->unit(),
-					coll_ev.actors[1]->unit(),
+					(id_array::has(m_units, coll_ev.actors[0]->unit_id())) ? coll_ev.actors[0]->unit() : NULL,
+					(id_array::has(m_units, coll_ev.actors[1]->unit_id())) ? coll_ev.actors[1]->unit() : NULL,
 					coll_ev.where,
 					coll_ev.normal,
 					(coll_ev.type == physics_world::CollisionEvent::BEGIN_TOUCH) ? "begin" : "end");