Procházet zdrojové kódy

Add push/get_sound_instance_id()

Daniele Bartolini před 12 roky
rodič
revize
7cfd66ff94
2 změnil soubory, kde provedl 12 přidání a 29 odebrání
  1. 4 1
      engine/lua/LuaStack.h
  2. 8 28
      engine/lua/LuaWorld.cpp

+ 4 - 1
engine/lua/LuaStack.h

@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "lua.hpp"
 #include "Types.h"
+#include "IdTable.h"
 
 namespace crown
 {
@@ -41,6 +42,7 @@ class Camera;
 class World;
 class Mesh;
 class Sprite;
+typedef Id SoundInstanceId;
 
 void clear_lua_temporaries();
 
@@ -256,7 +258,8 @@ public:
 	{
 		uint32_t enc = (uint32_t) lua_touserdata(m_state, index);
 		SoundInstanceId id;
-		return id.decode(enc);
+		id.decode(enc);
+		return id;
 	}
 
 	bool is_vector2(int32_t index);

+ 8 - 28
engine/lua/LuaWorld.cpp

@@ -76,8 +76,7 @@ CE_EXPORT int world_play_sound(lua_State* L)
 
 	SoundInstanceId id = world->play_sound(name, loop, volume, pos, range);
 
-	stack.push_int32(id.encode());
-
+	stack.push_sound_instance_id(id);
 	return 1;
 }
 
@@ -87,12 +86,9 @@ CE_EXPORT int world_pause_sound(lua_State* L)
 	LuaStack stack(L);
 
 	World* world = stack.get_world(1);
-
-	SoundInstanceId id;
-	id.decode(stack.get_int(2));
+	const SoundInstanceId id = stack.get_sound_instance_id(2);
 
 	world->pause_sound(id);
-
 	return 0;
 }
 
@@ -102,15 +98,11 @@ CE_EXPORT int world_link_sound(lua_State* L)
 	LuaStack stack(L);
 
 	World* world = stack.get_world(1);
-
-	SoundInstanceId sound;
-	sound.decode(stack.get_int(2));
-
+	const SoundInstanceId id = stack.get_sound_instance_id(2);
 	Unit* unit = stack.get_unit(3);
-	int32_t node = stack.get_int(4);
-
-	world->link_sound(sound, unit, node);
+	const int32_t node = stack.get_int(4);
 
+	world->link_sound(id, unit, node);
 	return 0;
 }
 
@@ -127,7 +119,6 @@ CE_EXPORT int world_set_listener(lua_State* L)
 	const Vector3& or_at = stack.get_vector3(5);
 
 	world->set_listener(pos, vel, or_up, or_at);
-
 	return 0;
 }
 
@@ -137,14 +128,10 @@ CE_EXPORT int world_set_sound_position(lua_State* L)
 	LuaStack stack(L);
 
 	World* world = stack.get_world(1);
-
-	SoundInstanceId id;
-	id.decode(stack.get_int(2));
-
+	const SoundInstanceId id = stack.get_sound_instance_id(2);
 	const Vector3& pos = stack.get_vector3(3);
 
 	world->set_sound_position(id, pos);
-
 	return 0;
 }
 
@@ -154,14 +141,10 @@ CE_EXPORT int world_set_sound_range(lua_State* L)
 	LuaStack stack(L);
 
 	World* world = stack.get_world(1);
-
-	SoundInstanceId id;
-	id.decode(stack.get_int(2));
-
+	const SoundInstanceId id = stack.get_sound_instance_id(2);
 	float range = stack.get_float(3);
 
 	world->set_sound_range(id, range);
-
 	return 0;
 }
 
@@ -171,13 +154,10 @@ CE_EXPORT int world_set_sound_volume(lua_State* L)
 	LuaStack stack(L);
 
 	World* world = stack.get_world(1);
-
-	SoundInstanceId id;
-	id.decode(stack.get_int(2));
+	const SoundInstanceId id = stack.get_sound_instance_id(2);
 	float vol = stack.get_float(3);
 
 	world->set_sound_volume(id, vol);
-
 	return 0;
 }