From 3ed7ef57aec38a39d7887a520c8eaf510f19804e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 14 Sep 2017 22:34:04 -0400 Subject: TITANIC: Moved queue logic within CAUdioBuffer to new FixedQueue class This is a cleaner implementation, since all the pointer logic and queue management is now better encapsulated in it's own class. I felt a new FixedQueue class was necessary because the standard Queue class uses a Common::List internally, which would be unsuitable for containing 100,000 elements, since each int value would need it's own list node. This way uses an array internally, like FixedStack --- engines/titanic/sound/audio_buffer.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'engines/titanic/sound/audio_buffer.h') diff --git a/engines/titanic/sound/audio_buffer.h b/engines/titanic/sound/audio_buffer.h index 8d27667e93..1f157b9346 100644 --- a/engines/titanic/sound/audio_buffer.h +++ b/engines/titanic/sound/audio_buffer.h @@ -23,7 +23,7 @@ #ifndef TITANIC_AUDIO_BUFFER_H #define TITANIC_AUDIO_BUFFER_H -#include "common/array.h" +#include "titanic/support/fixed_queue.h" #include "common/mutex.h" namespace Titanic { @@ -31,14 +31,7 @@ namespace Titanic { class CAudioBuffer { private: Common::Mutex _mutex; - Common::Array _data; - int16 *_frontP, *_backP; - - /** - * Reclaims any space at the start of the array resulting from - * having read values off the font - */ - void compact(); + FixedQueue _data; public: bool _finished; public: @@ -57,17 +50,17 @@ public: /** * Returns the number of 16-bit entries in the buffer */ - int size() const { return _backP - _frontP; } + int size() const { return _data.size(); } /** - * Returns true if the buffer is full + * Returns the number of entries free in the buffer */ - bool full() const { return (_backP - _frontP) == (int)_data.size(); } + int freeSize() const { return _data.freeSize(); } /** - * Returns the number of entries free in the buffer + * Returns true if the buffer is full */ - int freeSize(); + bool full() const { return _data.full(); } /** * Adds a value to the buffer @@ -77,7 +70,7 @@ public: /** * Adds a value to the buffer */ - void push(int16 *values, int count); + void push(const int16 *values, int count); /** * Removes a value from the buffer -- cgit v1.2.3