aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/support
diff options
context:
space:
mode:
authorPaul Gilbert2017-09-14 22:34:04 -0400
committerPaul Gilbert2017-09-14 22:34:04 -0400
commit3ed7ef57aec38a39d7887a520c8eaf510f19804e (patch)
tree9018ecf269c414c141c76ff3a5440c6c86c88a23 /engines/titanic/support
parent8607b702edd594264378f15dfe420fb0fc5881d0 (diff)
downloadscummvm-rg350-3ed7ef57aec38a39d7887a520c8eaf510f19804e.tar.gz
scummvm-rg350-3ed7ef57aec38a39d7887a520c8eaf510f19804e.tar.bz2
scummvm-rg350-3ed7ef57aec38a39d7887a520c8eaf510f19804e.zip
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
Diffstat (limited to 'engines/titanic/support')
-rw-r--r--engines/titanic/support/fixed_queue.h142
1 files changed, 142 insertions, 0 deletions
diff --git a/engines/titanic/support/fixed_queue.h b/engines/titanic/support/fixed_queue.h
new file mode 100644
index 0000000000..a7ba6eac2c
--- /dev/null
+++ b/engines/titanic/support/fixed_queue.h
@@ -0,0 +1,142 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_FIXED_QUEUE_H
+#define TITANIC_FIXED_QUEUE_H
+
+#include "common/scummsys.h"
+#include "common/array.h"
+
+namespace Titanic {
+
+/**
+ * Extremly simple fixed size queue class.
+ */
+template<class T, uint MAX_SIZE = 10>
+class FixedQueue {
+ typedef uint size_type;
+protected:
+ Common::Array<T> _data;
+ size_type _topIndex;
+public:
+ FixedQueue<T, MAX_SIZE>() : _topIndex(0) {
+ _data.reserve(MAX_SIZE);
+ }
+
+ /**
+ * Returns the size of the queue in use
+ */
+ size_type size() const { return _data.size() - _topIndex; }
+
+ /**
+ * Returns the amount of free remaining space in the queue
+ */
+ size_type freeSize() const { return MAX_SIZE - size(); }
+
+ /**
+ * Returns true if the queue is empty
+ */
+ bool empty() const {
+ return size() == 0;
+ }
+
+ /**
+ * Returns true if the queue is full
+ */
+ bool full() const {
+ return freeSize() == 0;
+ }
+
+ /**
+ * Clears the queue
+ */
+ void clear() {
+ _data.clear();
+ _topIndex = 0;
+ }
+
+ /**
+ * If the tail of the queue in use has reached the end of the internal
+ * array, pushes all pending data back to the start of the array
+ */
+ void compact() {
+ if (_data.size() == MAX_SIZE && _topIndex > 0) {
+ Common::copy(&_data[_topIndex], &_data[0] + MAX_SIZE, &_data[0]);
+ _data.resize(size());
+ _topIndex = 0;
+ }
+ }
+
+ /**
+ * Adds a value to the end of the queue
+ */
+ void push(const T &v) {
+ assert(size() < MAX_SIZE);
+ compact();
+ _data.push_back(v);
+ }
+
+ /**
+ * Returns the top value on the queue
+ */
+ const T &top() const {
+ assert(size() > 0);
+ return _data[_topIndex];
+ }
+
+ /**
+ * Returns the top value on the queue
+ */
+ T &top() {
+ assert(size() > 0);
+ return _data[_topIndex];
+ }
+
+ /**
+ * Pops the top value off the queue
+ */
+ T pop() {
+ T tmp = top();
+ ++_topIndex;
+ return tmp;
+ }
+
+ /**
+ * Returns values from within the queue without popping them
+ */
+ T &operator[](size_type i) {
+ assert(i < size());
+ return _data[_topIndex + i];
+ }
+
+ /**
+ * Returns values from within the queue without popping them
+ */
+ const T &operator[](size_type i) const {
+ assert(i < size());
+ return _data[_topIndex + i];
+ }
+};
+
+} // End of namespace Titanic
+
+#endif