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.cpp | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'engines/titanic/sound/audio_buffer.cpp') diff --git a/engines/titanic/sound/audio_buffer.cpp b/engines/titanic/sound/audio_buffer.cpp index 636f4a5107..0b0b6a53ad 100644 --- a/engines/titanic/sound/audio_buffer.cpp +++ b/engines/titanic/sound/audio_buffer.cpp @@ -26,45 +26,24 @@ namespace Titanic { CAudioBuffer::CAudioBuffer(int maxSize) : _finished(false) { - _data.resize(maxSize); reset(); } void CAudioBuffer::reset() { - _frontP = _backP = &_data[0]; + _data.clear(); } void CAudioBuffer::push(int16 value) { - assert(!full()); - compact(); - - *_backP++ = value; + _data.push(value); } -void CAudioBuffer::push(int16 *values, int count) { - compact(); - assert(freeSize() >= count); - - Common::copy(values, values + count, _backP); - _backP += count; +void CAudioBuffer::push(const int16 *values, int count) { + for (; count > 0; --count, ++values) + _data.push(*values); } int16 CAudioBuffer::pop() { - assert(!empty()); - return *_frontP++; -} - -void CAudioBuffer::compact() { - if (_frontP != &_data[0]) { - Common::copy(_frontP, _backP, &_data[0]); - _backP -= _frontP - &_data[0]; - _frontP = &_data[0]; - } -} - -int CAudioBuffer::freeSize() { - compact(); - return &_data[0] + _data.size() - _backP; + return _data.pop(); } void CAudioBuffer::enterCriticalSection() { -- cgit v1.2.3