[Scummvm-cvs-logs] SF.net SVN: scummvm:[39850] residual/trunk/common
aquadran at users.sourceforge.net
aquadran at users.sourceforge.net
Sat Apr 4 19:14:52 CEST 2009
Revision: 39850
http://scummvm.svn.sourceforge.net/scummvm/?rev=39850&view=rev
Author: aquadran
Date: 2009-04-04 17:14:52 +0000 (Sat, 04 Apr 2009)
Log Message:
-----------
synced some parts of common directory code from scummvm
Modified Paths:
--------------
residual/trunk/common/debug.cpp
residual/trunk/common/debug.h
residual/trunk/common/events.h
residual/trunk/common/hashmap.h
residual/trunk/common/list.h
residual/trunk/common/noncopyable.h
residual/trunk/common/ptr.h
residual/trunk/common/rect.h
residual/trunk/common/str.cpp
residual/trunk/common/str.h
residual/trunk/common/sys.h
residual/trunk/common/timer.h
residual/trunk/common/util.cpp
residual/trunk/common/util.h
Added Paths:
-----------
residual/trunk/common/list_intern.h
residual/trunk/common/queue.h
Modified: residual/trunk/common/debug.cpp
===================================================================
--- residual/trunk/common/debug.cpp 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/debug.cpp 2009-04-04 17:14:52 UTC (rev 39850)
@@ -36,41 +36,39 @@
#include "engine/backend/platform/ps2/fileio.h"
#define fprintf ps2_fprintf
+ #define fputs(str, file) ps2_fputs(str, file)
#define fflush(a) ps2_fflush(a)
#endif
#ifdef __DS__
#include "engine/backend/fs/ds/ds-fs.h"
- #undef stderr
- #undef stdout
- #undef stdin
-
- #define stdout ((DS::fileHandle*) -1)
- #define stderr ((DS::fileHandle*) -2)
- #define stdin ((DS::fileHandle*) -3)
-
void std_fprintf(FILE* handle, const char* fmt, ...);
void std_fflush(FILE* handle);
- #define fprintf(file, fmt, ...) { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); }
+ #define fprintf(file, fmt, ...) do { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); } while(0)
+ #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file)
#define fflush(file) DS::std_fflush(file)
#endif
-static void debugHelper(const char *in_buf, bool caret = true) {
+#ifndef DISABLE_TEXT_CONSOLE
+
+static void debugHelper(const char *s, va_list va, bool caret = true) {
+ char in_buf[STRINGBUFLEN];
char buf[STRINGBUFLEN];
+ vsnprintf(in_buf, STRINGBUFLEN, s, va);
strcpy(buf, in_buf);
- if (caret)
- printf("%s\n", buf);
- else
- printf("%s", buf);
+ if (caret) {
+ buf[STRINGBUFLEN-2] = '\0';
+ strcat(buf, "\n");
+ }
-#if defined(USE_WINDBG)
- if (caret)
- strcat(buf, "\n");
-#if defined(_WIN32_WCE)
+ fputs(buf, stdout);
+
+#if defined( USE_WINDBG )
+#if defined( _WIN32_WCE )
TCHAR buf_unicode[1024];
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
OutputDebugString(buf_unicode);
@@ -83,30 +81,26 @@
}
void debug(const char *s, ...) {
- char buf[STRINGBUFLEN];
va_list va;
va_start(va, s);
- vsnprintf(buf, STRINGBUFLEN, s, va);
+ debugHelper(s, va);
va_end(va);
-
- debugHelper(buf);
}
void debug(int level, const char *s, ...) {
- char buf[STRINGBUFLEN];
va_list va;
if (level > debugLevel)
return;
va_start(va, s);
- vsnprintf(buf, STRINGBUFLEN, s, va);
+ debugHelper(s, va);
va_end(va);
-
- debugHelper(buf);
}
+#endif
+
void NORETURN error(const char *s, ...) {
char buf_input[STRINGBUFLEN];
char buf_output[STRINGBUFLEN];
@@ -122,8 +116,17 @@
// Print the error message to stderr
fprintf(stderr, "%s!\n", buf_output);
-#if defined(USE_WINDBG)
-#if defined(_WIN32_WCE)
+ buf_output[STRINGBUFLEN-3] = '\0';
+ buf_output[STRINGBUFLEN-2] = '\0';
+ buf_output[STRINGBUFLEN-1] = '\0';
+ strcat(buf_output, "!\n");
+
+
+ // Print the error message to stderr
+ fputs(buf_output, stderr);
+
+#if defined( USE_WINDBG )
+#if defined( _WIN32_WCE )
TCHAR buf_output_unicode[1024];
MultiByteToWideChar(CP_ACP, 0, buf_output, strlen(buf_output) + 1, buf_output_unicode, sizeof(buf_output_unicode));
OutputDebugString(buf_output_unicode);
@@ -146,28 +149,30 @@
#ifdef __SYMBIAN32__
Symbian::FatalError(buf_output);
#endif
-
+ // Finally exit. quit() will terminate the program if g_driver is present
if (g_driver)
g_driver->quit();
exit(1);
}
-void warning(const char *fmt, ...) {
+#ifndef DISABLE_TEXT_CONSOLE
+
+void warning(const char *s, ...) {
char buf[STRINGBUFLEN];
va_list va;
- va_start(va, fmt);
- vsnprintf(buf, STRINGBUFLEN, fmt, va);
+ va_start(va, s);
+ vsnprintf(buf, STRINGBUFLEN, s, va);
va_end(va);
#if !defined (__SYMBIAN32__)
fprintf(stderr, "WARNING: %s!\n", buf);
#endif
-#if defined(USE_WINDBG)
+#if defined( USE_WINDBG )
strcat(buf, "\n");
-#if defined(_WIN32_WCE)
+#if defined( _WIN32_WCE )
TCHAR buf_unicode[1024];
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
OutputDebugString(buf_unicode);
@@ -177,6 +182,9 @@
#endif
}
+#endif
+
+
const char *debug_levels[] = {
"NONE",
"NORMAL",
Modified: residual/trunk/common/debug.h
===================================================================
--- residual/trunk/common/debug.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/debug.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -53,9 +53,20 @@
// Hacky toggles for experimental / debug code (defined/set in main.cpp)
extern bool ZBUFFER_GLOBAL, SHOWFPS_GLOBAL;
+void error(const char *fmt, ...);
+
+#ifdef DISABLE_TEXT_CONSOLE
+
+inline int printf(const char *s, ...) { return 0; }
+
+inline void warning(const char *s, ...) {}
+
+#else
+
void warning(const char *fmt, ...);
-void error(const char *fmt, ...);
void debug(int level, const char *s, ...);
void debug(const char *s, ...);
#endif
+
+#endif
Modified: residual/trunk/common/events.h
===================================================================
--- residual/trunk/common/events.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/events.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -27,6 +27,7 @@
#define COMMON_EVENTS_H
#include "common/keyboard.h"
+#include "common/queue.h"
#include "common/rect.h"
#include "common/noncopyable.h"
@@ -42,6 +43,7 @@
* indicates which button was pressed.
*/
enum EventType {
+ EVENT_INVALID = 0,
/** A key was pressed, details in Event::kbd. */
EVENT_KEYDOWN = 1,
/** A key was released, details in Event::kbd. */
@@ -57,6 +59,8 @@
EVENT_MBUTTONDOWN = 13,
EVENT_MBUTTONUP = 14,
+ EVENT_MAINMENU = 15,
+
EVENT_QUIT = 10,
EVENT_SCREEN_CHANGED = 11,
/**
@@ -116,8 +120,11 @@
* screen area as defined by the most recent call to initSize().
*/
Common::Point mouse;
+
+ Event() : type(EVENT_INVALID), synthetic(false) {}
};
+class Keymapper;
/**
* The EventManager provides user input events to the client code.
@@ -134,13 +141,25 @@
RBUTTON = 1 << 1
};
+
/**
+ * Initialise the event manager.
+ * @note called after graphics system has been set up
+ */
+ virtual void init() {}
+
+ /**
* Get the next event in the event queue.
* @param event point to an Event struct, which will be filled with the event data.
* @return true if an event was retrieved.
*/
virtual bool pollEvent(Common::Event &event) = 0;
+ /**
+ * Pushes a "fake" event into the event queue
+ */
+ virtual void pushEvent(const Common::Event &event) = 0;
+
/** Register random source so it can be serialized in game test purposes **/
virtual void registerRandomSource(Common::RandomSource &rnd, const char *name) = 0;
@@ -172,6 +191,10 @@
// TODO: Consider removing OSystem::getScreenChangeID and
// replacing it by a generic getScreenChangeID method here
+
+protected:
+
+ Common::Queue<Common::Event> artificialEventQueue;
};
} // End of namespace Common
Modified: residual/trunk/common/hashmap.h
===================================================================
--- residual/trunk/common/hashmap.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/hashmap.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -24,34 +24,6 @@
*/
// The hash map (associative array) implementation in this file is
-// based on code by Andrew Y. Ng, 1996:
-
-/*
- * Copyright (c) 1998-2003 Massachusetts Institute of Technology.
- * This code was developed as part of the Haystack research project
- * (http://haystack.lcs.mit.edu/). Permission is hereby granted,
- * free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit
- * persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-// The hash map (associative array) implementation in this file is
// based on the PyDict implementation of CPython. The erase() method
// is based on example code in the Wikipedia article on Hash tables.
@@ -290,8 +262,15 @@
* Base constructor, creates an empty hashmap.
*/
template<class Key, class Val, class HashFunc, class EqualFunc>
-HashMap<Key, Val, HashFunc, EqualFunc>::HashMap() :
- _defaultVal() {
+HashMap<Key, Val, HashFunc, EqualFunc>::HashMap()
+//
+// We have to skip _defaultVal() on PS2 to avoid gcc 3.2.2 ICE
+//
+#ifdef __PLAYSTATION2__
+ {
+#else
+ : _defaultVal() {
+#endif
_mask = HASHMAP_MIN_CAPACITY - 1;
_storage = new Node *[HASHMAP_MIN_CAPACITY];
assert(_storage != NULL);
@@ -459,6 +438,7 @@
if (_storage[ctr] == NULL) {
_storage[ctr] = allocNode(key);
+ assert(_storage[ctr] != NULL);
_size++;
// Keep the load factor below a certain threshold.
@@ -467,6 +447,7 @@
capacity = capacity < 500 ? (capacity * 4) : (capacity * 2);
expandStorage(capacity);
ctr = lookup(key);
+ assert(_storage[ctr] != NULL);
}
}
Modified: residual/trunk/common/list.h
===================================================================
--- residual/trunk/common/list.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/list.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -26,7 +26,7 @@
#ifndef COMMON_LIST_H
#define COMMON_LIST_H
-#include "common/sys.h"
+#include "common/list_intern.h"
namespace Common {
@@ -34,100 +34,17 @@
* Simple double linked list, modeled after the list template of the standard
* C++ library.
*/
-template<class t_T>
+template<typename t_T>
class List {
protected:
-#if defined (_WIN32_WCE) || defined (_MSC_VER)
-//FIXME evc4 and msvc7 doesn't like it as protected member
-public:
-#endif
- struct NodeBase {
- NodeBase *_prev;
- NodeBase *_next;
- };
+ typedef ListInternal::NodeBase NodeBase;
+ typedef ListInternal::Node<t_T> Node;
- template <class t_T2>
- struct Node : public NodeBase {
- t_T2 _data;
-
- Node(const t_T2 &x) : _data(x) {}
- };
-
- template<class t_T2>
- class Iterator {
- template<class T> friend class Iterator;
- friend class List<t_T>;
- NodeBase *_node;
-
-#if !defined (__WINSCW__)
- explicit Iterator(NodeBase *node) : _node(node) {}
-#else
- Iterator(NodeBase *node) : _node(node) {}
-#endif
-
- public:
- Iterator() : _node(0) {}
- template<class T>
- Iterator(const Iterator<T> &c) : _node(c._node) {}
-
- template<class T>
- Iterator<t_T2> &operator=(const Iterator<T> &c) {
- _node = c._node;
- return *this;
- }
-
- // Prefix inc
- Iterator<t_T2> &operator++() {
- if (_node)
- _node = _node->_next;
- return *this;
- }
- // Postfix inc
- Iterator<t_T2> operator++(int) {
- Iterator tmp(_node);
- ++(*this);
- return tmp;
- }
- // Prefix dec
- Iterator<t_T2> &operator--() {
- if (_node)
- _node = _node->_prev;
- return *this;
- }
- // Postfix dec
- Iterator<t_T2> operator--(int) {
- Iterator tmp(_node);
- --(*this);
- return tmp;
- }
- t_T2 &operator*() const {
- assert(_node);
-#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)
- return static_cast<List<t_T>::Node<t_T2> *>(_node)->_data;
-#else
- return static_cast<Node<t_T2> *>(_node)->_data;
-#endif
- }
- t_T2 *operator->() const {
- return &(operator*());
- }
-
- template<class T>
- bool operator==(const Iterator<T> &x) const {
- return _node == x._node;
- }
-
- template<class T>
- bool operator!=(const Iterator<T> &x) const {
- return _node != x._node;
- }
- };
-
NodeBase _anchor;
public:
- typedef Iterator<t_T> iterator;
- typedef Iterator<const t_T> const_iterator;
+ typedef ListInternal::Iterator<t_T> iterator;
+ typedef ListInternal::ConstIterator<t_T> const_iterator;
typedef t_T value_type;
@@ -156,7 +73,7 @@
}
void insert(iterator pos, const t_T &element) {
- NodeBase *newNode = new Node<t_T>(element);
+ ListInternal::NodeBase *newNode = new Node(element);
newNode->_next = pos._node;
newNode->_prev = pos._node->_prev;
@@ -175,7 +92,7 @@
NodeBase *next = pos._node->_next;
NodeBase *prev = pos._node->_prev;
- Node<t_T> *node = static_cast<Node<t_T> *>(pos._node);
+ Node *node = static_cast<Node *>(pos._node);
prev->_next = next;
next->_prev = prev;
delete node;
@@ -187,7 +104,7 @@
NodeBase *next = pos._node->_next;
NodeBase *prev = pos._node->_prev;
- Node<t_T> *node = static_cast<Node<t_T> *>(pos._node);
+ Node *node = static_cast<Node *>(pos._node);
prev->_next = next;
next->_prev = prev;
delete node;
@@ -222,7 +139,7 @@
const_iterator j;
for (i = begin(), j = list.begin(); (i != end()) && (j != list.end()) ; ++i, ++j) {
- static_cast<Node<t_T> *>(i._node)->_data = static_cast<Node<t_T> *>(j._node)->_data;
+ static_cast<Node *>(i._node)->_data = static_cast<const Node *>(j._node)->_data;
}
if (i == end())
Added: residual/trunk/common/list_intern.h
===================================================================
--- residual/trunk/common/list_intern.h (rev 0)
+++ residual/trunk/common/list_intern.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -0,0 +1,172 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef COMMON_LIST_INTERN_H
+#define COMMON_LIST_INTERN_H
+
+#include "common/sys.h"
+
+namespace Common {
+
+template<typename T> class List;
+
+
+namespace ListInternal {
+ struct NodeBase {
+ NodeBase *_prev;
+ NodeBase *_next;
+ };
+
+ template <typename T>
+ struct Node : public NodeBase {
+ T _data;
+
+ Node(const T &x) : _data(x) {}
+ };
+
+ template<typename T> struct ConstIterator;
+
+ template<typename T>
+ struct Iterator {
+ typedef Iterator<T> Self;
+ typedef Node<T> * NodePtr;
+ typedef T & ValueRef;
+ typedef T * ValuePtr;
+
+ NodeBase *_node;
+
+ Iterator() : _node(0) {}
+ Iterator(NodeBase *node) : _node(node) {}
+
+ // Prefix inc
+ Self &operator++() {
+ if (_node)
+ _node = _node->_next;
+ return *this;
+ }
+ // Postfix inc
+ Self operator++(int) {
+ Self tmp(_node);
+ ++(*this);
+ return tmp;
+ }
+ // Prefix dec
+ Self &operator--() {
+ if (_node)
+ _node = _node->_prev;
+ return *this;
+ }
+ // Postfix dec
+ Self operator--(int) {
+ Self tmp(_node);
+ --(*this);
+ return tmp;
+ }
+ ValueRef operator*() const {
+ assert(_node);
+ return static_cast<NodePtr>(_node)->_data;
+ }
+ ValuePtr operator->() const {
+ return &(operator*());
+ }
+
+ bool operator==(const Self &x) const {
+ return _node == x._node;
+ }
+
+ bool operator!=(const Self &x) const {
+ return _node != x._node;
+ }
+ };
+
+ template<typename T>
+ struct ConstIterator {
+ typedef ConstIterator<T> Self;
+ typedef const Node<T> * NodePtr;
+ typedef const T & ValueRef;
+ typedef const T * ValuePtr;
+
+ const NodeBase *_node;
+
+ ConstIterator() : _node(0) {}
+ ConstIterator(const NodeBase *node) : _node(node) {}
+ ConstIterator(const Iterator<T> &x) : _node(x._node) {}
+
+ // Prefix inc
+ Self &operator++() {
+ if (_node)
+ _node = _node->_next;
+ return *this;
+ }
+ // Postfix inc
+ Self operator++(int) {
+ Self tmp(_node);
+ ++(*this);
+ return tmp;
+ }
+ // Prefix dec
+ Self &operator--() {
+ if (_node)
+ _node = _node->_prev;
+ return *this;
+ }
+ // Postfix dec
+ Self operator--(int) {
+ Self tmp(_node);
+ --(*this);
+ return tmp;
+ }
+ ValueRef operator*() const {
+ assert(_node);
+ return static_cast<NodePtr>(_node)->_data;
+ }
+ ValuePtr operator->() const {
+ return &(operator*());
+ }
+
+ bool operator==(const Self &x) const {
+ return _node == x._node;
+ }
+
+ bool operator!=(const Self &x) const {
+ return _node != x._node;
+ }
+ };
+
+
+ template<typename T>
+ bool operator==(const Iterator<T>& a, const ConstIterator<T>& b) {
+ return a._node == b._node;
+ }
+
+ template<typename T>
+ bool operator!=(const Iterator<T>& a, const ConstIterator<T>& b) {
+ return a._node != b._node;
+ }
+}
+
+
+} // End of namespace Common
+
+#endif
Property changes on: residual/trunk/common/list_intern.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Author URL Id
Added: svn:eol-style
+ native
Modified: residual/trunk/common/noncopyable.h
===================================================================
--- residual/trunk/common/noncopyable.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/noncopyable.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -38,7 +38,7 @@
private:
// Prevent copying instances by accident
NonCopyable(const NonCopyable&);
- NonCopyable& operator= (const NonCopyable&);
+ NonCopyable& operator=(const NonCopyable&);
};
} // End of namespace Common
Modified: residual/trunk/common/ptr.h
===================================================================
--- residual/trunk/common/ptr.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/ptr.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -180,6 +180,16 @@
_pointer = 0;
}
+ template<class T2>
+ bool operator==(const Common::SharedPtr<T2> &r) const {
+ return _pointer == r.get();
+ }
+
+ template<class T2>
+ bool operator!=(const Common::SharedPtr<T2> &r) const {
+ return _pointer != r.get();
+ }
+
/**
* Returns the number of references to the assigned pointer.
* This should just be used for debugging purposes.
@@ -208,14 +218,4 @@
} // end of namespace Common
-template<class T1, class T2>
-bool operator==(const Common::SharedPtr<T1> &l, const Common::SharedPtr<T2> &r) {
- return l.get() == r.get();
-}
-
-template<class T1, class T2>
-bool operator!=(const Common::SharedPtr<T1> &l, const Common::SharedPtr<T2> &r) {
- return l.get() != r.get();
-}
-
#endif
Added: residual/trunk/common/queue.h
===================================================================
--- residual/trunk/common/queue.h (rev 0)
+++ residual/trunk/common/queue.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -0,0 +1,94 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef COMMON_QUEUE_H
+#define COMMON_QUEUE_H
+
+#include "common/sys.h"
+#include "common/list.h"
+
+namespace Common {
+
+/**
+ * Variable size Queue class, implemented using our List class.
+ */
+template<class T>
+class Queue {
+public:
+ typedef T value_type;
+
+public:
+ Queue<T>() : _impl() {}
+ Queue<T>(const Queue<T> &queue) : _impl(queue._impl) {}
+
+ Queue<T> &operator=(const Queue<T> &queue) {
+ _impl = queue._impl;
+ return *this;
+ }
+
+ bool empty() const {
+ return _impl.empty();
+ }
+
+ void clear() {
+ _impl.clear();
+ }
+
+ void push(const T &x) {
+ _impl.push_back(x);
+ }
+
+ T &front() {
+ return *_impl.begin();
+ }
+
+ const T &front() const {
+ return *_impl.begin();
+ }
+
+ T &back() {
+ return *_impl.reverse_begin();
+ }
+
+ const T &back() const {
+ return *_impl.reverse_begin();
+ }
+
+ T pop() {
+ T tmp = front();
+ _impl.pop_front();
+ return tmp;
+ }
+
+ int size() const {
+ return _impl.size();
+ }
+
+private:
+ List<T> _impl;
+};
+
+} // End of namespace Common
+
+#endif
Property changes on: residual/trunk/common/queue.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Author URL Id
Added: svn:eol-style
+ native
Modified: residual/trunk/common/rect.h
===================================================================
--- residual/trunk/common/rect.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/rect.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -137,6 +137,17 @@
}
/**
+ * Check if the given rect is equal to this one.
+ *
+ * @param r The rectangle to check
+ *
+ * @return true if the given rect is equal, false otherwise
+ */
+ bool equals(const Rect &r) const {
+ return (left == r.left) && (right == r.right) && (top == r.top) && (bottom == r.bottom);
+ }
+
+ /**
* Check if given rectangle intersects with this rectangle
*
* @param r the rectangle to check
Modified: residual/trunk/common/str.cpp
===================================================================
--- residual/trunk/common/str.cpp 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/str.cpp 2009-04-04 17:14:52 UTC (rev 39850)
@@ -26,6 +26,13 @@
#include "common/hash-str.h"
#include "common/util.h"
+#include "common/memorypool.h"
+
+#if !defined(__SYMBIAN32__)
+#include <new>
+#endif
+
+
namespace Common {
#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
@@ -323,12 +330,12 @@
return strchr(c_str(), x) != NULL;
}
-bool String::matchString(const char *pat) const {
- return Common::matchString(c_str(), pat);
+bool String::matchString(const char *pat, bool pathMode) const {
+ return Common::matchString(c_str(), pat, pathMode);
}
-bool String::matchString(const String &pat) const {
- return Common::matchString(c_str(), pat.c_str());
+bool String::matchString(const String &pat, bool pathMode) const {
+ return Common::matchString(c_str(), pat.c_str(), pathMode);
}
void String::deleteLastChar() {
@@ -608,7 +615,7 @@
return result;
}
-bool matchString(const char *str, const char *pat) {
+bool matchString(const char *str, const char *pat, bool pathMode) {
assert(str);
assert(pat);
@@ -616,6 +623,13 @@
const char *q = 0;
for (;;) {
+ if (pathMode && *str == '/') {
+ p = 0;
+ q = 0;
+ if (*pat == '?')
+ return false;
+ }
+
switch (*pat) {
case '*':
// Record pattern / string possition for backtracking
Modified: residual/trunk/common/str.h
===================================================================
--- residual/trunk/common/str.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/str.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -166,11 +166,12 @@
*
* @param str Text to be matched against the given pattern.
* @param pat Glob pattern.
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
*
* @return true if str matches the pattern, false otherwise.
*/
- bool matchString(const char *pat) const;
- bool matchString(const String &pat) const;
+ bool matchString(const char *pat, bool pathMode = false) const;
+ bool matchString(const String &pat, bool pathMode = false) const;
inline const char *c_str() const { return _str; }
@@ -179,7 +180,7 @@
inline bool empty() const { return (_size == 0); }
char lastChar() const { return (_size > 0) ? _str[_size-1] : 0; }
- char operator [](int idx) const {
+ char operator[](int idx) const {
assert(_str && idx >= 0 && idx < (int)_size);
return _str[idx];
}
@@ -306,10 +307,11 @@
*
* @param str Text to be matched against the given pattern.
* @param pat Glob pattern.
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
*
* @return true if str matches the pattern, false otherwise.
*/
-bool matchString(const char *str, const char *pat);
+bool matchString(const char *str, const char *pat, bool pathMode = false);
class StringList : public Array<String> {
Modified: residual/trunk/common/sys.h
===================================================================
--- residual/trunk/common/sys.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/sys.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -93,8 +93,6 @@
#if defined(__SYMBIAN32__)
- #define strcasecmp stricmp
-
#define SYSTEM_LITTLE_ENDIAN
#define SYSTEM_NEED_ALIGNMENT
@@ -125,7 +123,9 @@
#define SYSTEM_LITTLE_ENDIAN
#define SYSTEM_NEED_ALIGNMENT
+ #if _WIN32_WCE < 300
#define SMALL_SCREEN_DEVICE
+ #endif
typedef signed char int8_t;
typedef signed short int16_t;
@@ -144,6 +144,11 @@
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
+// #if !defined(SDL_COMPILEDVERSION) || (SDL_COMPILEDVERSION < 1210)
+// typedef signed long int32_t;
+// typedef unsigned long uint32_t;
+// #endif
+
#elif defined(__MINGW32__)
#define strcasecmp stricmp
@@ -185,11 +190,39 @@
#define SYSTEM_NEED_ALIGNMENT
#define STRINGBUFLEN 256
+ extern const char *RESIDUAL_SAVEPATH;
+
+ #if !defined(COMPILE_ZODIAC) && !defined(COMPILE_OS5)
+ # define NEWGUI_256
+ #else
+ # undef UNUSED
+ #endif
+
#elif defined(__DC__)
#define SYSTEM_LITTLE_ENDIAN
#define SYSTEM_NEED_ALIGNMENT
+#elif defined(__GP32__)
+
+ #define strcasecmp stricmp
+
+ #define SYSTEM_LITTLE_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+ // Override typenames. uint is already defined by system header files.
+ #define SYSTEM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short int uint16;
+ typedef signed short int int16;
+
+ typedef unsigned long int uint32;
+ typedef signed long int int32;
+
#elif defined(__PLAYSTATION2__)
#define SYSTEM_LITTLE_ENDIAN
@@ -205,7 +238,7 @@
#define SYSTEM_BIG_ENDIAN
#define SYSTEM_NEED_ALIGNMENT
-#elif defined (__DS__) //NeilM
+#elif defined (__DS__)
#define strcasecmp stricmp
@@ -230,39 +263,15 @@
#endif
//
-// Typedef our system types unless SYSTEM_DONT_DEFINE_TYPES is set.
-//
-#ifndef SYSTEM_DONT_DEFINE_TYPES
-
- typedef unsigned char byte;
-
- typedef unsigned char uint8;
- typedef signed char int8;
-
- typedef unsigned short uint16;
- typedef signed short int16;
-
- #ifdef SYSTEM_USE_LONG_INT
- typedef unsigned long uint32;
- typedef signed long int32;
- typedef unsigned long uint;
- #else
- typedef unsigned int uint32;
- typedef signed int int32;
- typedef unsigned int uint;
- #endif
-#endif
-
-//
// GCC specific stuff
//
#if defined(__GNUC__)
#define NORETURN __attribute__((__noreturn__))
#define PACKED_STRUCT __attribute__((packed))
- #define GCC_PRINTF(x, y) __attribute__((format(printf, x, y)))
+ #define GCC_PRINTF(x,y) __attribute__((format(printf, x, y)))
#else
#define PACKED_STRUCT
- #define GCC_PRINTF(x, y)
+ #define GCC_PRINTF(x,y)
#endif
//
@@ -285,7 +294,31 @@
#endif
#ifndef NORETURN
-#define NORETURN
+#define NORETURN
#endif
+//
+// Typedef our system types unless SYSTEM_DONT_DEFINE_TYPES is set.
+//
+#ifndef SYSTEM_DONT_DEFINE_TYPES
+
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short uint16;
+ typedef signed short int16;
+
+ #ifdef SYSTEM_USE_LONG_INT
+ typedef unsigned long uint32;
+ typedef signed long int32;
+ typedef unsigned long uint;
+ #else
+ typedef unsigned int uint32;
+ typedef signed int int32;
+ typedef unsigned int uint;
+ #endif
+#endif
+
#endif // COMMON_SYS_H
Modified: residual/trunk/common/timer.h
===================================================================
--- residual/trunk/common/timer.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/timer.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -52,7 +52,8 @@
virtual bool installTimerProc(TimerProc proc, int32 interval, void *refCon) = 0;
/**
- * Remove the given timer callback. It will not be invoked anymore.
+ * Remove the given timer callback. It will not be invoked anymore,
+ * and no instance of this callback will be running anymore.
*/
virtual void removeTimerProc(TimerProc proc) = 0;
};
Modified: residual/trunk/common/util.cpp
===================================================================
--- residual/trunk/common/util.cpp 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/util.cpp 2009-04-04 17:14:52 UTC (rev 39850)
@@ -30,7 +30,7 @@
//
// Print hexdump of the data passed in
//
-void hexdump(const byte *data, int len, int bytesPerLine) {
+void hexdump(const byte * data, int len, int bytesPerLine) {
assert(1 <= bytesPerLine && bytesPerLine <= 32);
int i;
byte c;
@@ -79,6 +79,22 @@
printf("|\n");
}
+String tag2string(uint32 tag) {
+ char str[5];
+ str[0] = (char)(tag >> 24);
+ str[1] = (char)(tag >> 16);
+ str[2] = (char)(tag >> 8);
+ str[3] = (char)tag;
+ str[4] = '\0';
+ // Replace non-printable chars by dot
+ for (int i = 0; i < 4; ++i) {
+ if (!isprint(str[i]))
+ str[i] = '.';
+ }
+ return Common::String(str);
+}
+
+
#pragma mark -
@@ -110,15 +126,6 @@
return getRandomNumber(max - min) + min;
}
-Common::String tag2string(uint32 tag) {
- char str[5];
- str[0] = (char)(tag >> 24);
- str[1] = (char)(tag >> 16);
- str[2] = (char)(tag >> 8);
- str[3] = (char)tag;
- str[4] = '\0';
- return Common::String(str);
-}
} // End of namespace Common
Modified: residual/trunk/common/util.h
===================================================================
--- residual/trunk/common/util.h 2009-04-04 16:41:21 UTC (rev 39849)
+++ residual/trunk/common/util.h 2009-04-04 17:14:52 UTC (rev 39850)
@@ -32,6 +32,13 @@
#include <windows.h>
#endif
+/**
+ * Check whether a given pointer is aligned correctly.
+ * Note that 'alignment' must be a power of two!
+ */
+#define IS_ALIGNED(value, alignment) \
+ ((((size_t)value) & ((alignment) - 1)) == 0)
+
#ifdef MIN
#undef MIN
#endif
@@ -40,9 +47,9 @@
#undef MAX
#endif
-template<typename T> inline T ABS (T x) { return (x >= 0) ? x : -x; }
-template<typename T> inline T MIN (T a, T b) { return (a < b) ? a : b; }
-template<typename T> inline T MAX (T a, T b) { return (a > b) ? a : b; }
+template<typename T> inline T ABS (T x) { return (x>=0) ? x : -x; }
+template<typename T> inline T MIN (T a, T b) { return (a<b) ? a : b; }
+template<typename T> inline T MAX (T a, T b) { return (a>b) ? a : b; }
template<typename T> inline T CLIP (T v, T amin, T amax)
{ if (v < amin) return amin; else if (v > amax) return amax; else return v; }
@@ -55,6 +62,9 @@
// VS2005beta2 introduces new stuff in winnt.h
#undef ARRAYSIZE
#endif
+/**
+ * Macro which determines the number of entries in a fixed size array.
+ */
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
#ifndef round
@@ -70,9 +80,21 @@
* @param len the lenght of that data
* @param bytesPerLine number of bytes to print per line (default: 16)
*/
-extern void hexdump(const byte *data, int len, int bytesPerLine = 16);
+extern void hexdump(const byte * data, int len, int bytesPerLine = 16);
+
/**
+ * Take a 32 bit value and turn it into a four character string, where each of
+ * the four bytes is turned into one character. Most significant byte is printed
+ * first.
+ */
+String tag2string(uint32 tag);
+#define tag2str(x) Common::tag2string(x).c_str()
+
+
+
+
+/**
* Simple random number generator. Although it is definitely not suitable for
* cryptographic purposes, it serves our purposes just fine.
*/
@@ -109,8 +131,6 @@
uint getRandomNumberRng(uint min, uint max);
};
-Common::String tag2string(uint32 tag);
-
} // End of namespace Common
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list