aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/array.h59
-rw-r--r--common/events.h5
-rw-r--r--common/memory.h4
-rw-r--r--common/ptr.h13
-rw-r--r--common/system.h13
-rw-r--r--common/util.h3
6 files changed, 67 insertions, 30 deletions
diff --git a/common/array.h b/common/array.h
index 04ec9f9ccb..d4dac35866 100644
--- a/common/array.h
+++ b/common/array.h
@@ -59,6 +59,24 @@ protected:
public:
Array() : _capacity(0), _size(0), _storage(0) {}
+ /**
+ * Constructs an array with `count` default-inserted instances of T. No
+ * copies are made.
+ */
+ explicit Array(size_type count) : _size(count) {
+ allocCapacity(count);
+ for (size_type i = 0; i < count; ++i)
+ new ((void *)&_storage[i]) T();
+ }
+
+ /**
+ * Constructs an array with `count` copies of elements with value `value`.
+ */
+ Array(size_type count, const T &value) : _size(count) {
+ allocCapacity(count);
+ uninitialized_fill_n(_storage, count, value);
+ }
+
Array(const Array<T> &array) : _capacity(array._size), _size(array._size), _storage(0) {
if (array._storage) {
allocCapacity(_size);
@@ -70,10 +88,10 @@ public:
* Construct an array by copying data from a regular array.
*/
template<class T2>
- Array(const T2 *data, size_type n) {
+ Array(const T2 *array, size_type n) {
_size = n;
allocCapacity(n);
- uninitialized_copy(data, data + _size, _storage);
+ uninitialized_copy(array, array + _size, _storage);
}
~Array() {
@@ -106,6 +124,16 @@ public:
_storage[_size].~T();
}
+ /** Returns a pointer to the underlying memory serving as element storage. */
+ const T *data() const {
+ return _storage;
+ }
+
+ /** Returns a pointer to the underlying memory serving as element storage. */
+ T *data() {
+ return _storage;
+ }
+
/** Returns a reference to the first element of the array. */
T &front() {
assert(_size > 0);
@@ -391,31 +419,19 @@ public:
Array<T>::insert(where, element);
}
- T &operator[](size_type idx) {
- error("Operation []= not allowed with SortedArray");
- }
+private:
+ T &operator[](size_type idx);
- void insert_at(size_type idx, const T &element) {
- error("Operation insert_at(idx, element) not allowed with SortedArray");
- }
+ void insert_at(size_type idx, const T &element);
- void insert_at(size_type idx, const Array<T> &array) {
- error("Operation insert_at(idx, array) not allowed with SortedArray");
- }
+ void insert_at(size_type idx, const Array<T> &array);
- void insert(iterator pos, const T &element) {
- error("Operation insert(pos, elemnet) not allowed with SortedArray");
- }
+ void insert(iterator pos, const T &element);
- void push_back(const T &element) {
- error("Operation push_back(element) not allowed with SortedArray");
- }
+ void push_back(const T &element);
- void push_back(const Array<T> &array) {
- error("Operation push_back(array) not allowed with SortedArray");
- }
+ void push_back(const Array<T> &array);
-private:
// Based on code Copyright (C) 2008-2009 Ksplice, Inc.
// Author: Tim Abbott <tabbott@ksplice.com>
// Licensed under GPLv2+
@@ -438,7 +454,6 @@ private:
return &this->_storage[start_];
}
-private:
int (*_comparator)(const void *, const void *);
};
diff --git a/common/events.h b/common/events.h
index 21a65a642b..e5bb8cab50 100644
--- a/common/events.h
+++ b/common/events.h
@@ -395,6 +395,11 @@ public:
*/
virtual void pushEvent(const Event &event) = 0;
+ /**
+ * Purges all unprocessed mouse events already in the event queue.
+ */
+ virtual void purgeMouseEvents() = 0;
+
/** Return the current mouse position */
virtual Point getMousePos() const = 0;
diff --git a/common/memory.h b/common/memory.h
index c32af42ba5..91a320080b 100644
--- a/common/memory.h
+++ b/common/memory.h
@@ -55,11 +55,11 @@ void uninitialized_fill(Type *first, Type *last, const Value &x) {
* It requires the range [dst, dst + n) to be valid and
* uninitialized.
*/
-/*template<class Type, class Value>
+template<class Type, class Value>
void uninitialized_fill_n(Type *dst, size_t n, const Value &x) {
while (n--)
new ((void *)dst++) Type(x);
-}*/
+}
} // End of namespace Common
diff --git a/common/ptr.h b/common/ptr.h
index ebdd77cf3c..510fec14df 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "common/noncopyable.h"
+#include "common/safe-bool.h"
#include "common/types.h"
namespace Common {
@@ -103,7 +104,7 @@ private:
* a plain pointer is only possible via SharedPtr::get.
*/
template<class T>
-class SharedPtr {
+class SharedPtr : public SafeBool<SharedPtr<T> > {
#if !defined(__GNUC__) || GCC_ATLEAST(3, 0)
template<class T2> friend class SharedPtr;
#endif
@@ -167,7 +168,7 @@ public:
* Implicit conversion operator to bool for convenience, to make
* checks like "if (sharedPtr) ..." possible.
*/
- operator bool() const { return _pointer != 0; }
+ bool operator_bool() const { return _pointer != nullptr; }
/**
* Checks if the SharedPtr object is the only object refering
@@ -223,7 +224,7 @@ private:
};
template<typename T>
-class ScopedPtr : NonCopyable {
+class ScopedPtr : private NonCopyable, public SafeBool<ScopedPtr<T> > {
public:
typedef T ValueType;
typedef T *PointerType;
@@ -238,7 +239,7 @@ public:
* Implicit conversion operator to bool for convenience, to make
* checks like "if (scopedPtr) ..." possible.
*/
- operator bool() const { return _pointer != 0; }
+ bool operator_bool() const { return _pointer != nullptr; }
~ScopedPtr() {
delete _pointer;
@@ -277,7 +278,7 @@ private:
template<typename T>
-class DisposablePtr : NonCopyable {
+class DisposablePtr : private NonCopyable, public SafeBool<DisposablePtr<T> > {
public:
typedef T ValueType;
typedef T *PointerType;
@@ -296,7 +297,7 @@ public:
* Implicit conversion operator to bool for convenience, to make
* checks like "if (scopedPtr) ..." possible.
*/
- operator bool() const { return _pointer; }
+ bool operator_bool() const { return _pointer != nullptr; }
/**
* Returns the plain pointer value.
diff --git a/common/system.h b/common/system.h
index 32f20daf8f..206c3134c4 100644
--- a/common/system.h
+++ b/common/system.h
@@ -27,6 +27,7 @@
#include "common/noncopyable.h"
#include "common/list.h" // For OSystem::getSupportedFormats()
#include "graphics/pixelformat.h"
+#include "graphics/mode.h"
namespace Audio {
class Mixer;
@@ -634,6 +635,18 @@ public:
virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) = 0;
/**
+ * Send a list of graphics modes to the backend so it can make a decision
+ * about the best way to set up the display hardware.
+ *
+ * Engines that switch between different virtual screen sizes during a game
+ * should call this function prior to any call to initSize. Engines that use
+ * only a single screen size do not need to call this function.
+ *
+ * @param modes the list of graphics modes the engine will probably use.
+ */
+ virtual void initSizeHint(const Graphics::ModeList &modes) {}
+
+ /**
* Return an int value which is changed whenever any screen
* parameters (like the resolution) change. That is, whenever a
* EVENT_SCREEN_CHANGED would be sent. You can track this value
diff --git a/common/util.h b/common/util.h
index 13c364e97d..a098a6a437 100644
--- a/common/util.h
+++ b/common/util.h
@@ -33,6 +33,9 @@
#define IS_ALIGNED(value, alignment) \
((((size_t)value) & ((alignment) - 1)) == 0)
+#ifdef ABS
+#undef ABS
+#endif
#ifdef MIN
#undef MIN