Просмотр исходного кода

Use reference instead of pointer

Daniele Bartolini 10 лет назад
Родитель
Сommit
63e99c4c02
2 измененных файлов с 12 добавлено и 12 удалено
  1. 2 2
      src/audio/sound_world.h
  2. 10 10
      src/audio/sound_world_al.cpp

+ 2 - 2
src/audio/sound_world.h

@@ -26,7 +26,7 @@ public:
 
 	/// Plays the sound @a sr at the given @a volume [0 .. 1].
 	/// If loop is true the sound will be played looping.
-	virtual SoundInstanceId play(const SoundResource* sr, bool loop, float volume, const Vector3& pos) = 0;
+	virtual SoundInstanceId play(const SoundResource& sr, bool loop, float volume, const Vector3& pos) = 0;
 
 	/// Stops the sound with the given @a id.
 	/// After this call, the instance will be destroyed.
@@ -53,7 +53,7 @@ public:
 	/// Sets the @a volumes of @a num sound instances @a ids.
 	virtual void set_sound_volumes(uint32_t num, const SoundInstanceId* ids, const float* volumes) = 0;
 
-	virtual void reload_sounds(const SoundResource* old_sr, const SoundResource* new_sr) = 0;
+	virtual void reload_sounds(const SoundResource& old_sr, const SoundResource& new_sr) = 0;
 
 	/// Sets the @a pose of the listener in world space.
 	virtual void set_listener_pose(const Matrix4x4& pose) = 0;

+ 10 - 10
src/audio/sound_world_al.cpp

@@ -77,7 +77,7 @@ namespace audio_globals
 
 struct SoundInstance
 {
-	void create(const SoundResource* sr, const Vector3& pos)
+	void create(const SoundResource& sr, const Vector3& pos)
 	{
 		using namespace sound_resource;
 
@@ -93,15 +93,15 @@ struct SoundInstance
 		CE_ASSERT(alIsBuffer(_buffer), "Bad OpenAL buffer");
 
 		ALenum format;
-		switch (bits_ps(sr))
+		switch (bits_ps(&sr))
 		{
-			case 8: format = channels(sr) > 1 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8; break;
-			case 16: format = channels(sr) > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; break;
+			case 8: format = channels(&sr) > 1 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8; break;
+			case 16: format = channels(&sr) > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; break;
 			default: CE_FATAL("Number of bits per sample not supported."); break;
 		}
-		AL_CHECK(alBufferData(_buffer, format, data(sr), size(sr), sample_rate(sr)));
+		AL_CHECK(alBufferData(_buffer, format, data(&sr), size(&sr), sample_rate(&sr)));
 
-		_resource = sr;
+		_resource = &sr;
 		set_position(pos);
 	}
 
@@ -113,7 +113,7 @@ struct SoundInstance
 		AL_CHECK(alDeleteSources(1, &_source));
 	}
 
-	void reload(const SoundResource* new_sr)
+	void reload(const SoundResource& new_sr)
 	{
 		destroy();
 		create(new_sr, position());
@@ -213,7 +213,7 @@ public:
 	{
 	}
 
-	virtual SoundInstanceId play(const SoundResource* sr, bool loop, float volume, const Vector3& pos)
+	virtual SoundInstanceId play(const SoundResource& sr, bool loop, float volume, const Vector3& pos)
 	{
 		SoundInstance instance;
 		instance.create(sr, pos);
@@ -283,11 +283,11 @@ public:
 		}
 	}
 
-	virtual void reload_sounds(const SoundResource* old_sr, const SoundResource* new_sr)
+	virtual void reload_sounds(const SoundResource& old_sr, const SoundResource& new_sr)
 	{
 		for (uint32_t i = 0; i < id_array::size(_playing_sounds); i++)
 		{
-			if (_playing_sounds[i].resource() == old_sr)
+			if (_playing_sounds[i].resource() == &old_sr)
 			{
 				_playing_sounds[i].reload(new_sr);
 			}