Explorar el Código

Be consistent

Daniele Bartolini hace 9 años
padre
commit
6b9bb306fa
Se han modificado 5 ficheros con 39 adiciones y 33 borrados
  1. 31 25
      src/lua/lua_api.cpp
  2. 4 4
      src/world/render_world.cpp
  3. 2 2
      src/world/render_world.h
  4. 1 1
      src/world/world.cpp
  5. 1 1
      src/world/world.h

+ 31 - 25
src/lua/lua_api.cpp

@@ -1361,7 +1361,12 @@ static int camera_create(lua_State* L)
 static int world_camera_instances(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_camera(stack.get_world(1)->camera(stack.get_unit(2)));
+	CameraInstance inst = stack.get_world(1)->camera_instances(stack.get_unit(2));
+
+	if (inst.i == UINT32_MAX)
+		return 0;
+
+	stack.push_camera(inst);
 	return 1;
 }
 
@@ -1631,12 +1636,12 @@ static int scene_graph_destroy(lua_State* L)
 static int scene_graph_instances(lua_State* L)
 {
 	LuaStack stack(L);
-	SceneGraph* sg = stack.get_scene_graph(1);
-	TransformInstance ti = sg->instances(stack.get_unit(2));
-	if (sg->is_valid(ti))
-		stack.push_transform(ti);
-	else
-		stack.push_nil();
+	TransformInstance inst = stack.get_scene_graph(1)->instances(stack.get_unit(2));
+
+	if (inst.i == UINT32_MAX)
+		return 0;
+
+	stack.push_transform(inst);
 	return 1;
 }
 
@@ -1785,15 +1790,11 @@ static int render_world_mesh_instances(lua_State* L)
 	Array<MeshInstance> inst(ta);
 	rw->mesh_instances(unit, inst);
 
-	stack.push_table(array::size(inst));
-	for (u32 i = 0; i < array::size(inst); ++i)
-	{
-		stack.push_key_begin(i+1);
+	const u32 n = array::size(inst);
+	for (u32 i = 0; i < n; ++i)
 		stack.push_mesh_instance(inst[i]);
-		stack.push_key_end();
-	}
 
-	return 1;
+	return n;
 }
 
 static int render_world_mesh_obb(lua_State* L)
@@ -1851,10 +1852,12 @@ static int render_world_sprite_destroy(lua_State* L)
 static int render_world_sprite_instances(lua_State* L)
 {
 	LuaStack stack(L);
-	RenderWorld* rw = stack.get_render_world(1);
-	UnitId unit = stack.get_unit(2);
+	SpriteInstance inst = stack.get_render_world(1)->sprite_instances(stack.get_unit(2));
 
-	stack.push_sprite_instance(rw->sprite(unit));
+	if (inst.i == UINT32_MAX)
+		return 0;
+
+	stack.push_sprite_instance(inst);
 	return 1;
 }
 
@@ -1903,13 +1906,12 @@ static int render_world_light_destroy(lua_State* L)
 static int render_world_light_instances(lua_State* L)
 {
 	LuaStack stack(L);
-	LightInstance inst = stack.get_render_world(1)->light(stack.get_unit(2));
+	LightInstance inst = stack.get_render_world(1)->light_instances(stack.get_unit(2));
 
 	if (inst.i == UINT32_MAX)
-		stack.push_nil();
-	else
-		stack.push_light_instance(inst);
+		return 0;
 
+	stack.push_light_instance(inst);
 	return 1;
 }
 
@@ -2009,10 +2011,9 @@ static int physics_world_actor_instances(lua_State* L)
 	ActorInstance inst = stack.get_physics_world(1)->actor(stack.get_unit(2));
 
 	if (inst.i == UINT32_MAX)
-		stack.push_nil();
-	else
-		stack.push_actor(inst);
+		return 0;
 
+	stack.push_actor(inst);
 	return 1;
 }
 
@@ -2251,7 +2252,12 @@ static int physics_world_actor_wake_up(lua_State* L)
 static int physics_world_controller_instances(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_controller(stack.get_physics_world(1)->controller(stack.get_unit(2)));
+	ControllerInstance inst = stack.get_physics_world(1)->controller(stack.get_unit(2));
+
+	if (inst.i == UINT32_MAX)
+		return 0;
+
+	stack.push_controller(inst);
 	return 1;
 }
 

+ 4 - 4
src/world/render_world.cpp

@@ -136,7 +136,7 @@ void RenderWorld::sprite_destroy(SpriteInstance i)
 	_sprite_manager.destroy(i);
 }
 
-SpriteInstance RenderWorld::sprite(UnitId id)
+SpriteInstance RenderWorld::sprite_instances(UnitId id)
 {
 	return _sprite_manager.sprite(id);
 }
@@ -169,7 +169,7 @@ void RenderWorld::light_destroy(LightInstance i)
 	_light_manager.destroy(i);
 }
 
-LightInstance RenderWorld::light(UnitId id)
+LightInstance RenderWorld::light_instances(UnitId id)
 {
 	return _light_manager.light(id);
 }
@@ -377,14 +377,14 @@ void RenderWorld::unit_destroyed_callback(UnitId id)
 	}
 
 	{
-		SpriteInstance first = sprite(id);
+		SpriteInstance first = sprite_instances(id);
 
 		if (_sprite_manager.is_valid(first))
 			sprite_destroy(first);
 	}
 
 	{
-		LightInstance first = light(id);
+		LightInstance first = light_instances(id);
 
 		if (_light_manager.is_valid(first))
 			light_destroy(first);

+ 2 - 2
src/world/render_world.h

@@ -54,7 +54,7 @@ public:
 	void sprite_destroy(SpriteInstance i);
 
 	/// Returns the sprite instances of the unit @a id.
-	SpriteInstance sprite(UnitId id);
+	SpriteInstance sprite_instances(UnitId id);
 
 	/// Sets the material @a id of the sprite @a i.
 	void sprite_set_material(SpriteInstance i, StringId64 id);
@@ -72,7 +72,7 @@ public:
 	void light_destroy(LightInstance i);
 
 	/// Returns the light of the unit @a id.
-	LightInstance light(UnitId id);
+	LightInstance light_instances(UnitId id);
 
 	/// Returns the type of the light @a i.
 	LightType::Enum light_type(LightInstance i);

+ 1 - 1
src/world/world.cpp

@@ -226,7 +226,7 @@ void World::camera_destroy(CameraInstance i)
 	hash_map::remove(_camera_map, u);
 }
 
-CameraInstance World::camera(UnitId id)
+CameraInstance World::camera_instances(UnitId id)
 {
 	return make_camera_instance(hash_map::get(_camera_map, id, UINT32_MAX));
 }

+ 1 - 1
src/world/world.h

@@ -98,7 +98,7 @@ public:
 	void camera_destroy(CameraInstance i);
 
 	/// Returns the camera owned by unit @a id.
-	CameraInstance camera(UnitId id);
+	CameraInstance camera_instances(UnitId id);
 
 	/// Sets the projection type of the camera.
 	void camera_set_projection_type(CameraInstance i, ProjectionType::Enum type);