Procházet zdrojové kódy

world: use script_world::broadcast()

Daniele Bartolini před 4 měsíci
rodič
revize
90bc3eb8bc
3 změnil soubory, kde provedl 5 přidání a 25 odebrání
  1. 0 21
      src/world/script_world.cpp
  2. 0 3
      src/world/script_world.h
  3. 5 1
      src/world/world.cpp

+ 0 - 21
src/world/script_world.cpp

@@ -109,27 +109,6 @@ namespace script_world
 		return script_world_internal::make_instance(hash_map::get(sw._map, unit, UINT32_MAX));
 	}
 
-	void update(ScriptWorld &sw, f32 dt)
-	{
-		if (sw._disable_callbacks)
-			return;
-
-		LuaStack stack(sw._lua_environment->L);
-
-		for (u32 i = 0; i < array::size(sw._script); ++i) {
-			lua_rawgeti(stack.L, LUA_REGISTRYINDEX, sw._script[i].module_ref);
-			lua_getfield(stack.L, -1, "update");
-			stack.push_world(sw._world);
-			stack.push_float(dt);
-			int status = sw._lua_environment->call(2, 0);
-			if (status != LUA_OK) {
-				report(stack.L, status);
-				device()->pause();
-			}
-			stack.pop(1);
-		}
-	}
-
 	void collision(ScriptWorld &sw, const PhysicsCollisionEvent &ev)
 	{
 		if (sw._disable_callbacks)

+ 0 - 3
src/world/script_world.h

@@ -65,9 +65,6 @@ namespace script_world
 	/// Returns the component id for the @a unit.
 	ScriptInstance instance(ScriptWorld &sw, UnitId unit);
 
-	/// Calls the update function on all scripts.
-	void update(ScriptWorld &sw, f32 dt);
-
 	///
 	void collision(ScriptWorld &sw, const PhysicsCollisionEvent &ev);
 

+ 5 - 1
src/world/world.cpp

@@ -392,7 +392,11 @@ void World::update_scene(f32 dt)
 
 	array::clear(_events);
 
-	script_world::update(*_script_world, dt);
+	ArgType::Enum arg_types[2] = { ArgType::POINTER, ArgType::FLOAT };
+	Arg args[2];
+	args[0].pointer_value = this;
+	args[1].float_value = dt;
+	script_world::broadcast(*_script_world, "update", arg_types, args, countof(args));
 }
 
 void World::update(f32 dt)