2
0
Эх сурвалжийг харах

write some function definitions and notes for future rework

mikymod 12 жил өмнө
parent
commit
c39fbeded7

+ 35 - 9
engine/renderers/al/ALRenderer.cpp

@@ -121,7 +121,7 @@ SoundId ALRenderer::create_sound(const void* data, uint32_t size, uint32_t sampl
 			{
 				al_sound.format = AL_FORMAT_MONO8;
 			}
-			
+
 			break;
 		}
 
@@ -183,22 +183,48 @@ void ALRenderer::play_sound(SoundId id)
 	Sound& al_sound = m_sounds[id.index];
 
 	AL_CHECK(alSourcePlay(al_sound.sourceid));
+}
+
+//-----------------------------------------------------------------------------
+void ALRenderer::pause_sound(SoundId id)
+{
+	CE_ASSERT(m_sounds_id_table.has(id), "Sound does not exist");
+
+	Sound& al_sound = m_sounds[id.index];
+
+	if (is_sound_playing(id))
+	{
+		AL_CHECK(alSourcePause(al_sound.sourceid));
+	}
+}
 
-	// ALint source_state;
+//-----------------------------------------------------------------------------
+void ALRenderer::destroy_sound(SoundId id)
+{
+	CE_ASSERT(m_sounds_id_table.has(id), "Sound does not exist");
+
+	Sound& al_sound = m_sounds[id.index];
+
+	// alDeleteSources(1, al_sound.sourceid);
+	// alDeleteBuffers(1, al_sound.bufferid);
 
-	// alGetSourcei(al_sound.sourceid, AL_SOURCE_STATE, &source_state);
+	
 
-	// while (source_state == AL_PLAYING) 
-	// {
-	// 	Log::i("dio maiale");
- //        alGetSourcei(al_sound.sourceid, AL_SOURCE_STATE, &source_state);
-	// }
+	// Must be implemented
 }
 
 //-----------------------------------------------------------------------------
-void ALRenderer::destroy_sound(SoundId sound)
+bool ALRenderer::is_sound_playing(SoundId id)
 {
+	CE_ASSERT(m_sounds_id_table.has(id), "Sound does not exist");
+
+	Sound& al_sound = m_sounds[id.index];
+
+	ALint source_state;
+	alGetSourcei(al_sound.sourceid, AL_SOURCE_STATE, &source_state);
 
+	return source_state == AL_PLAYING;
 }
 
+
 } // namespace crown

+ 38 - 17
engine/renderers/al/ALRenderer.h

@@ -49,29 +49,29 @@ struct Listener
 	ALfloat orientation[6];
 };
 
-// //-----------------------------------------------------------------------------
-// struct Buffer
-// {
-
-// };
-
-
-// //-----------------------------------------------------------------------------
-// struct Source
-// {
-
-// };
-
 //-----------------------------------------------------------------------------
-struct Sound
+struct Buffer
 {
-	ALuint		sourceid;
 	ALuint 		bufferid;
 	ALenum 		format;
 	ALsizei		size;
 	ALsizei		freq;
 };
 
+
+//-----------------------------------------------------------------------------
+struct Source
+{
+	ALuint		id;
+};
+
+//-----------------------------------------------------------------------------
+struct Sound
+{
+	Source 		source;
+	Buffer 		buffer;		// Should be an array of buffer
+};
+
 //-----------------------------------------------------------------------------
 class ALRenderer
 {
@@ -82,13 +82,34 @@ public:
 	void			init();
 	void			shutdown();
 
+	// FIXME: public APIs, They should be placed in AudioSystem
 	SoundId			create_sound(const void* data, uint32_t size, uint32_t sample_rate, uint32_t channels, uint32_t bxs);
-	void 			play_sound(SoundId sound);
-	void 			destroy_sound(SoundId sound);
+	void 			play_sound(SoundId id);
+	void			pause_sound(SoundId id);
+	void 			destroy_sound(SoundId id);
+
+	bool			is_sound_playing(SoundId id);
 
 public:
 
 	static const uint32_t MAX_SOUNDS = 128;
+	// END
+
+private:
+
+	// FIXME: the following methods are the real wrapper of needed OpenAL functions
+	Buffer			create_buffer(const void* data, uint32_t size, uint32_t sample_rate, uint32_t channels, uint32_t bxs);
+	void			destroy_buffer(Buffer b);
+
+	Source			create_source();
+	void			play_source(Source s);
+	void			pause_source(Source s);
+	void			destroy_source(Source s);
+	bool			is_source_playing(Source s);
+
+	Listener		create_listener();
+	void			destroy_listener(Listener);
+	// END
 
 private: