[Scummvm-cvs-logs] SF.net SVN: scummvm:[33441] residual/trunk/engine/backend

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Wed Jul 30 12:24:21 CEST 2008


Revision: 33441
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33441&view=rev
Author:   aquadran
Date:     2008-07-30 10:24:20 +0000 (Wed, 30 Jul 2008)

Log Message:
-----------
moved files a bit

Added Paths:
-----------
    residual/trunk/engine/backend/platform/dc/
    residual/trunk/engine/backend/platform/driver.h
    residual/trunk/engine/backend/platform/sdl/
    residual/trunk/engine/backend/timer/
    residual/trunk/engine/backend/timer/default/
    residual/trunk/engine/backend/timer/default/default-timer.cpp
    residual/trunk/engine/backend/timer/default/default-timer.h

Removed Paths:
-------------
    residual/trunk/engine/backend/dc/
    residual/trunk/engine/backend/default-timer.cpp
    residual/trunk/engine/backend/default-timer.h
    residual/trunk/engine/backend/driver.h
    residual/trunk/engine/backend/sdl/

Deleted: residual/trunk/engine/backend/default-timer.cpp
===================================================================
--- residual/trunk/engine/backend/default-timer.cpp	2008-07-30 10:17:17 UTC (rev 33440)
+++ residual/trunk/engine/backend/default-timer.cpp	2008-07-30 10:24:20 UTC (rev 33441)
@@ -1,147 +0,0 @@
-/* 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$
- *
- */
-
-#include "common/sys.h"
-
-#include "engine/backend/driver.h"
-#include "engine/backend/default-timer.h"
-
-struct TimerSlot {
-	Common::TimerManager::TimerProc callback;
-	void *refCon;
-	uint32 interval;	// in microseconds
-
-	uint32 nextFireTime;	// in milliseconds
-	uint32 nextFireTimeMicro;	// mircoseconds part of nextFire
-
-	TimerSlot *next;
-};
-
-void insertPrioQueue(TimerSlot *head, TimerSlot *newSlot) {
-	// The head points to a fake anchor TimerSlot; this common
-	// trick allows us to get rid of many special cases.
-
-	const uint32 nextFireTime = newSlot->nextFireTime;
-	TimerSlot *slot = head;
-	newSlot->next = 0;
-
-	// Insert the new slot into the sorted list of already scheduled
-	// timers in such a way that the list stays sorted...
-	while (true) {
-		assert(slot);
-		if (slot->next == 0 || nextFireTime < slot->next->nextFireTime) {
-			newSlot->next = slot->next;
-			slot->next = newSlot;
-			return;
-		}
-		slot = slot->next;
-	}
-}
-
-
-DefaultTimerManager::DefaultTimerManager() :
-	_timerHandler(0),
-	_head(0) {
-
-	_head = new TimerSlot();
-	memset(_head, 0, sizeof(TimerSlot));
-}
-
-DefaultTimerManager::~DefaultTimerManager() {
-	Common::StackLock lock(_mutex);
-
-	TimerSlot *slot = _head;
-	while (slot) {
-		TimerSlot *next = slot->next;
-		delete slot;
-		slot = next;
-	}
-	_head = 0;
-}
-
-void DefaultTimerManager::handler() {
-	Common::StackLock lock(_mutex);
-
-	const uint32 curTime = g_driver->getMillis();
-
-	// Repeat as long as there is a TimerSlot that is scheduled to fire.
-	TimerSlot *slot = _head->next;
-	while (slot && slot->nextFireTime < curTime) {
-		// Remove the slot from the priority queue
-		_head->next = slot->next;
-
-		// Update the fire time and reinsert the TimerSlot into the priority
-		// queue. Has to be done before the timer callback is invoked, in case
-		// the callback wants to remove itself.
-		assert(slot->interval > 0);
-		slot->nextFireTime += (slot->interval / 1000);
-		slot->nextFireTimeMicro += (slot->interval % 1000);
-		if (slot->nextFireTimeMicro > 1000) {
-			slot->nextFireTime += slot->nextFireTimeMicro / 1000;
-			slot->nextFireTimeMicro %= 1000;
-		}
-		insertPrioQueue(_head, slot);
-
-		// Invoke the timer callback
-		assert(slot->callback);
-		slot->callback(slot->refCon);
-
-		// Look at the next scheduled timer
-		slot = _head->next;
-	}
-}
-
-bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, void *refCon) {
-	assert(interval > 0);
-	Common::StackLock lock(_mutex);
-
-	TimerSlot *slot = new TimerSlot;
-	slot->callback = callback;
-	slot->refCon = refCon;
-	slot->interval = interval;
-	slot->nextFireTime = g_driver->getMillis() + interval / 1000;
-	slot->nextFireTimeMicro = interval % 1000;
-	slot->next = 0;
-
-	insertPrioQueue(_head, slot);
-
-	return true;
-}
-
-void DefaultTimerManager::removeTimerProc(TimerProc callback) {
-	Common::StackLock lock(_mutex);
-
-	TimerSlot *slot = _head;
-
-	while (slot->next) {
-		if (slot->next->callback == callback) {
-			TimerSlot *next = slot->next->next;
-			delete slot->next;
-			slot->next = next;
-		} else {
-			slot = slot->next;
-		}
-	}
-}

Deleted: residual/trunk/engine/backend/default-timer.h
===================================================================
--- residual/trunk/engine/backend/default-timer.h	2008-07-30 10:17:17 UTC (rev 33440)
+++ residual/trunk/engine/backend/default-timer.h	2008-07-30 10:24:20 UTC (rev 33441)
@@ -1,51 +0,0 @@
-/* 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 BACKENDS_TIMER_DEFAULT_H
-#define BACKENDS_TIMER_DEFAULT_H
-
-#include "common/timer.h"
-#include "common/mutex.h"
-
-struct TimerSlot;
-	
-class DefaultTimerManager : public Common::TimerManager {
-private:
-	Common::Mutex _mutex;
-	void *_timerHandler;
-	TimerSlot *_head;
-	
-
-public:
-	DefaultTimerManager();
-	~DefaultTimerManager();
-	bool installTimerProc(TimerProc proc, int32 interval, void *refCon);
-	void removeTimerProc(TimerProc proc);
-
-	// Timer callback, to be invoked at regular time intervals by the backend.
-	void handler();
-};
-
-#endif

Deleted: residual/trunk/engine/backend/driver.h
===================================================================
--- residual/trunk/engine/backend/driver.h	2008-07-30 10:17:17 UTC (rev 33440)
+++ residual/trunk/engine/backend/driver.h	2008-07-30 10:24:20 UTC (rev 33441)
@@ -1,325 +0,0 @@
-/* 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 library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
-
- * This library 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
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- *
- * $URL$
- * $Id$
- *
- */
-
-#ifndef BACKEND_DRIVER_H
-#define BACKEND_DRIVER_H
-
-#include "common/sys.h"
-#include "common/vector3d.h"
-#include "common/mutex.h"
-
-#include "engine/color.h"
-#include "engine/model.h"
-#include "engine/scene.h"
-#include "engine/colormap.h"
-#include "engine/font.h"
-#include "engine/primitives.h"
-#include "engine/actor.h"
-#include "engine/backend/default-timer.h"
-
-class Material;
-class Bitmap;
-class Timer;
-class FilesystemFactory;
-
-namespace Common {
-	class SaveFileManager;
-}
-
-namespace Audio {
-	class MixerImpl;
-	class Mixer;
-}
-
-class Driver {
-public:
-	Driver() { ; }
-	virtual ~Driver() { ; }
-
-	struct TextObjectHandle {
-		uint16 *bitmapData;
-		void *surface;
-		int numTex;
-		void *texIds;
-		int width;
-		int height;
-	};
-
-	virtual void init() = 0;
-
-	virtual void toggleFullscreenMode() = 0;
-
-	virtual bool isHardwareAccelerated() = 0;
-
-	virtual void setupIcon() = 0;
-
-	virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0;
-	virtual void positionCamera(Vector3d pos, Vector3d interest) = 0;
-
-	virtual void clearScreen() = 0;
-	virtual void flipBuffer() = 0;
-
-	virtual void startActorDraw(Vector3d pos, float yaw, float pitch, float roll) = 0;
-	virtual void finishActorDraw() = 0;
-	virtual void setShadow(Shadow *shadow) = 0;
-	virtual void drawShadowPlanes() = 0;
-	virtual void setShadowMode() = 0;
-	virtual void clearShadowMode() = 0;
-	virtual void setShadowColor(byte r, byte g, byte b) = 0;
-
-	virtual void set3DMode() = 0;
-
-	virtual void translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) = 0;
-	virtual void translateViewpoint() = 0;
-
-	virtual void drawHierachyNode(const Model::HierNode *node) = 0;
-	virtual void drawModelFace(const Model::Face *face, float *vertices, float *vertNormals, float *textureVerts) = 0;
-
-	virtual void disableLights() = 0;
-	virtual void setupLight(Scene::Light *light, int lightId) = 0;
-
-	virtual void createMaterial(Material *material, const char *data, const CMap *cmap) = 0;
-	virtual void selectMaterial(const Material *material) = 0;
-	virtual void destroyMaterial(Material *material) = 0;
-
-	virtual void createBitmap(Bitmap *bitmap) = 0;
-	virtual void drawBitmap(const Bitmap *bitmap) = 0;
-	virtual void destroyBitmap(Bitmap *bitmap) = 0;
-
-	virtual void drawDepthBitmap(int x, int y, int w, int h, char *data) = 0;
-
-	virtual Bitmap *getScreenshot(int w, int h) = 0;
-	virtual void storeDisplay() = 0;
-	virtual void copyStoredToDisplay() = 0;
-	virtual void dimScreen() = 0;
-	virtual void dimRegion(int x, int y, int w, int h, float level) = 0;
-
-	virtual void drawEmergString(int x, int y, const char *text, const Color &fgColor) = 0;
-	virtual void loadEmergFont() = 0;
-	virtual TextObjectHandle *createTextBitmap(uint8 *bitmap, int width, int height, const Color &fgColor) = 0;
-	virtual void drawTextBitmap(int x, int y, TextObjectHandle *handle) = 0;
-	virtual void destroyTextBitmap(TextObjectHandle *handle) = 0;
-
-	virtual void drawRectangle(PrimitiveObject *primitive) = 0;
-	virtual void drawLine(PrimitiveObject *primitive) = 0;
-	virtual void drawPolygon(PrimitiveObject *primitive) = 0;
-
-	virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
-	virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
-
-	virtual const char *getVideoDeviceName() = 0;
-
-	/** @name Events and Time */
-	//@{
-
-	typedef unsigned int (*TimerProc)(unsigned int interval, void *param);
-
-	virtual void getTimeAndDate(struct tm &t) const = 0;
-
-	/**
-	 * The types of events backends may generate.
-	 * @see Event
-	 */
-	enum EventType {
-		/** A key was pressed, details in Event::kbd. */
-		EVENT_KEYDOWN = 1,
-		/** A key was released, details in Event::kbd. */
-		EVENT_KEYUP = 2,
-
-		EVENT_QUIT = 10,
-		EVENT_REFRESH = 11
-	};
-
-	/**
-	 * Keyboard modifier flags, used for Event::kbd::flags.
-	 */
-	enum {
-		KBD_CTRL  = 1 << 0,
-		KBD_ALT   = 1 << 1,
-		KBD_SHIFT = 1 << 2
-	};
-
-	/**
-	 * Data structure for an event. A pointer to an instance of Event
-	 * can be passed to pollEvent.
-	 */
-	struct Event {
-		/** The type of the event. */
-		EventType type;
-		/**
-		  * Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and
-		  * EVENT_KEYUP). For all other event types, content is undefined.
-		  */
-		struct {
-			/**
-			 * Abstract control number (will be the same for any given key regardless
-			 * of modifiers being held at the same time.
-			 * For example, this is the same for both 'A' and Shift-'A'.
-			 */
-			int num;
-			/**
-			 * ASCII-value of the pressed key (if any).
-			 * This depends on modifiers, i.e. pressing the 'A' key results in
-			 * different values here depending on the status of shift, alt and
-			 * caps lock.
-			 */
-			uint16 ascii;
-			/**
-			 * Status of the modifier keys. Bits are set in this for each
-			 * pressed modifier
-			 * @see KBD_CTRL, KBD_ALT, KBD_SHIFT
-			 */
-			byte flags;
-		} kbd;
-	};
-
-	/**
-	 *
-	 */
-	struct ControlDescriptor {
-		const char *name;
-		int key;
-	};
-
-	/**
-	 * Get a list of all named controls supported by the driver
-	 */
-	virtual const ControlDescriptor *listControls() = 0;
-
-	/**
-	 * Get the largest control number used by the driver, plus 1
-	 */
-	virtual int getNumControls() = 0;
-
-	/**
-	 * Check whether a control is an axis control
-	 */
-	virtual bool controlIsAxis(int num) = 0;
-
-	/**
-	 * Read the current value of an axis control (-1.0 .. 1.0)
-	 */
-	virtual float getControlAxis(int num) = 0;
-
-	/**
-	 * Read the current state of a non-axis control
-	 */
-	virtual bool getControlState(int num) = 0;
-
-	/**
-	 * 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(Event &event) = 0;
-
-	/** Get the number of milliseconds since the program was started. */
-	virtual uint32 getMillis() = 0;
-
-	/** Delay/sleep for the specified amount of milliseconds. */
-	virtual void delayMillis(uint msecs) = 0;
-
-	virtual Common::TimerManager *getTimerManager() = 0;
-
-	//@}
-
-	/**
-	 * @name Mutex handling
-	 *
-	 * Hence backends which do not use threads to implement the timers simply
-	 * can use dummy implementations for these methods.
-	 */
-	//@{
-
-	typedef Common::MutexRef	MutexRef;
-
-	/**
-	 * Create a new mutex.
-	 * @return the newly created mutex, or 0 if an error occured.
-	 */
-	virtual MutexRef createMutex() = 0;
-
-	/**
-	 * Lock the given mutex.
-	 *
-	 * @note Code assumes that the mutex implementation supports
-	 * recursive locking. That is, a thread may lock a mutex twice w/o
-	 * deadlocking. In case of a multilock, the mutex has to be unlocked
-	 * as many times as it was locked befored it really becomes unlocked.
-	 *
-	 * @param mutex	the mutex to lock.
-	 */
-	virtual void lockMutex(MutexRef mutex) = 0;
-
-	/**
-	 * Unlock the given mutex.
-	 * @param mutex	the mutex to unlock.
-	 */
-	virtual void unlockMutex(MutexRef mutex) = 0;
-
-	/**
-	 * Delete the given mutex. Make sure the mutex is unlocked before you delete it.
-	 * If you delete a locked mutex, the behavior is undefined, in particular, your
-	 * program may crash.
-	 * @param mutex	the mutex to delete.
-	 */
-	virtual void deleteMutex(MutexRef mutex) = 0;
-
-	//@}
-
-	/** @name Sound */
-	//@{
-	virtual void setupMixer() = 0;
-
-	virtual Audio::Mixer *getMixer() = 0;
-
-	//@}
-
-	/** @name Miscellaneous */
-	//@{
-	/** Quit (exit) the application. */
-	virtual void quit() = 0;
-	/**
-	 * Returns the FilesystemFactory object, depending on the current architecture.
-	 *
-	 * @return FilesystemFactory* The specific factory for the current architecture.
-	 */
-	virtual FilesystemFactory *getFilesystemFactory() = 0;
-
-	virtual Common::SaveFileManager *getSavefileManager() = 0;
-	//@}
-
-protected:
-	int _screenWidth, _screenHeight, _screenBPP;
-	bool _isFullscreen;
-	Shadow *_currentShadowArray;
-	unsigned char _shadowColorR;
-	unsigned char _shadowColorG;
-	unsigned char _shadowColorB;
-};
-
-extern Driver *g_driver;
-
-#endif

Copied: residual/trunk/engine/backend/platform/driver.h (from rev 33439, residual/trunk/engine/backend/driver.h)
===================================================================
--- residual/trunk/engine/backend/platform/driver.h	                        (rev 0)
+++ residual/trunk/engine/backend/platform/driver.h	2008-07-30 10:24:20 UTC (rev 33441)
@@ -0,0 +1,325 @@
+/* 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 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef BACKEND_DRIVER_H
+#define BACKEND_DRIVER_H
+
+#include "common/sys.h"
+#include "common/vector3d.h"
+#include "common/mutex.h"
+
+#include "engine/color.h"
+#include "engine/model.h"
+#include "engine/scene.h"
+#include "engine/colormap.h"
+#include "engine/font.h"
+#include "engine/primitives.h"
+#include "engine/actor.h"
+#include "engine/backend/default-timer.h"
+
+class Material;
+class Bitmap;
+class Timer;
+class FilesystemFactory;
+
+namespace Common {
+	class SaveFileManager;
+}
+
+namespace Audio {
+	class MixerImpl;
+	class Mixer;
+}
+
+class Driver {
+public:
+	Driver() { ; }
+	virtual ~Driver() { ; }
+
+	struct TextObjectHandle {
+		uint16 *bitmapData;
+		void *surface;
+		int numTex;
+		void *texIds;
+		int width;
+		int height;
+	};
+
+	virtual void init() = 0;
+
+	virtual void toggleFullscreenMode() = 0;
+
+	virtual bool isHardwareAccelerated() = 0;
+
+	virtual void setupIcon() = 0;
+
+	virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0;
+	virtual void positionCamera(Vector3d pos, Vector3d interest) = 0;
+
+	virtual void clearScreen() = 0;
+	virtual void flipBuffer() = 0;
+
+	virtual void startActorDraw(Vector3d pos, float yaw, float pitch, float roll) = 0;
+	virtual void finishActorDraw() = 0;
+	virtual void setShadow(Shadow *shadow) = 0;
+	virtual void drawShadowPlanes() = 0;
+	virtual void setShadowMode() = 0;
+	virtual void clearShadowMode() = 0;
+	virtual void setShadowColor(byte r, byte g, byte b) = 0;
+
+	virtual void set3DMode() = 0;
+
+	virtual void translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) = 0;
+	virtual void translateViewpoint() = 0;
+
+	virtual void drawHierachyNode(const Model::HierNode *node) = 0;
+	virtual void drawModelFace(const Model::Face *face, float *vertices, float *vertNormals, float *textureVerts) = 0;
+
+	virtual void disableLights() = 0;
+	virtual void setupLight(Scene::Light *light, int lightId) = 0;
+
+	virtual void createMaterial(Material *material, const char *data, const CMap *cmap) = 0;
+	virtual void selectMaterial(const Material *material) = 0;
+	virtual void destroyMaterial(Material *material) = 0;
+
+	virtual void createBitmap(Bitmap *bitmap) = 0;
+	virtual void drawBitmap(const Bitmap *bitmap) = 0;
+	virtual void destroyBitmap(Bitmap *bitmap) = 0;
+
+	virtual void drawDepthBitmap(int x, int y, int w, int h, char *data) = 0;
+
+	virtual Bitmap *getScreenshot(int w, int h) = 0;
+	virtual void storeDisplay() = 0;
+	virtual void copyStoredToDisplay() = 0;
+	virtual void dimScreen() = 0;
+	virtual void dimRegion(int x, int y, int w, int h, float level) = 0;
+
+	virtual void drawEmergString(int x, int y, const char *text, const Color &fgColor) = 0;
+	virtual void loadEmergFont() = 0;
+	virtual TextObjectHandle *createTextBitmap(uint8 *bitmap, int width, int height, const Color &fgColor) = 0;
+	virtual void drawTextBitmap(int x, int y, TextObjectHandle *handle) = 0;
+	virtual void destroyTextBitmap(TextObjectHandle *handle) = 0;
+
+	virtual void drawRectangle(PrimitiveObject *primitive) = 0;
+	virtual void drawLine(PrimitiveObject *primitive) = 0;
+	virtual void drawPolygon(PrimitiveObject *primitive) = 0;
+
+	virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
+	virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
+
+	virtual const char *getVideoDeviceName() = 0;
+
+	/** @name Events and Time */
+	//@{
+
+	typedef unsigned int (*TimerProc)(unsigned int interval, void *param);
+
+	virtual void getTimeAndDate(struct tm &t) const = 0;
+
+	/**
+	 * The types of events backends may generate.
+	 * @see Event
+	 */
+	enum EventType {
+		/** A key was pressed, details in Event::kbd. */
+		EVENT_KEYDOWN = 1,
+		/** A key was released, details in Event::kbd. */
+		EVENT_KEYUP = 2,
+
+		EVENT_QUIT = 10,
+		EVENT_REFRESH = 11
+	};
+
+	/**
+	 * Keyboard modifier flags, used for Event::kbd::flags.
+	 */
+	enum {
+		KBD_CTRL  = 1 << 0,
+		KBD_ALT   = 1 << 1,
+		KBD_SHIFT = 1 << 2
+	};
+
+	/**
+	 * Data structure for an event. A pointer to an instance of Event
+	 * can be passed to pollEvent.
+	 */
+	struct Event {
+		/** The type of the event. */
+		EventType type;
+		/**
+		  * Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and
+		  * EVENT_KEYUP). For all other event types, content is undefined.
+		  */
+		struct {
+			/**
+			 * Abstract control number (will be the same for any given key regardless
+			 * of modifiers being held at the same time.
+			 * For example, this is the same for both 'A' and Shift-'A'.
+			 */
+			int num;
+			/**
+			 * ASCII-value of the pressed key (if any).
+			 * This depends on modifiers, i.e. pressing the 'A' key results in
+			 * different values here depending on the status of shift, alt and
+			 * caps lock.
+			 */
+			uint16 ascii;
+			/**
+			 * Status of the modifier keys. Bits are set in this for each
+			 * pressed modifier
+			 * @see KBD_CTRL, KBD_ALT, KBD_SHIFT
+			 */
+			byte flags;
+		} kbd;
+	};
+
+	/**
+	 *
+	 */
+	struct ControlDescriptor {
+		const char *name;
+		int key;
+	};
+
+	/**
+	 * Get a list of all named controls supported by the driver
+	 */
+	virtual const ControlDescriptor *listControls() = 0;
+
+	/**
+	 * Get the largest control number used by the driver, plus 1
+	 */
+	virtual int getNumControls() = 0;
+
+	/**
+	 * Check whether a control is an axis control
+	 */
+	virtual bool controlIsAxis(int num) = 0;
+
+	/**
+	 * Read the current value of an axis control (-1.0 .. 1.0)
+	 */
+	virtual float getControlAxis(int num) = 0;
+
+	/**
+	 * Read the current state of a non-axis control
+	 */
+	virtual bool getControlState(int num) = 0;
+
+	/**
+	 * 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(Event &event) = 0;
+
+	/** Get the number of milliseconds since the program was started. */
+	virtual uint32 getMillis() = 0;
+
+	/** Delay/sleep for the specified amount of milliseconds. */
+	virtual void delayMillis(uint msecs) = 0;
+
+	virtual Common::TimerManager *getTimerManager() = 0;
+
+	//@}
+
+	/**
+	 * @name Mutex handling
+	 *
+	 * Hence backends which do not use threads to implement the timers simply
+	 * can use dummy implementations for these methods.
+	 */
+	//@{
+
+	typedef Common::MutexRef	MutexRef;
+
+	/**
+	 * Create a new mutex.
+	 * @return the newly created mutex, or 0 if an error occured.
+	 */
+	virtual MutexRef createMutex() = 0;
+
+	/**
+	 * Lock the given mutex.
+	 *
+	 * @note Code assumes that the mutex implementation supports
+	 * recursive locking. That is, a thread may lock a mutex twice w/o
+	 * deadlocking. In case of a multilock, the mutex has to be unlocked
+	 * as many times as it was locked befored it really becomes unlocked.
+	 *
+	 * @param mutex	the mutex to lock.
+	 */
+	virtual void lockMutex(MutexRef mutex) = 0;
+
+	/**
+	 * Unlock the given mutex.
+	 * @param mutex	the mutex to unlock.
+	 */
+	virtual void unlockMutex(MutexRef mutex) = 0;
+
+	/**
+	 * Delete the given mutex. Make sure the mutex is unlocked before you delete it.
+	 * If you delete a locked mutex, the behavior is undefined, in particular, your
+	 * program may crash.
+	 * @param mutex	the mutex to delete.
+	 */
+	virtual void deleteMutex(MutexRef mutex) = 0;
+
+	//@}
+
+	/** @name Sound */
+	//@{
+	virtual void setupMixer() = 0;
+
+	virtual Audio::Mixer *getMixer() = 0;
+
+	//@}
+
+	/** @name Miscellaneous */
+	//@{
+	/** Quit (exit) the application. */
+	virtual void quit() = 0;
+	/**
+	 * Returns the FilesystemFactory object, depending on the current architecture.
+	 *
+	 * @return FilesystemFactory* The specific factory for the current architecture.
+	 */
+	virtual FilesystemFactory *getFilesystemFactory() = 0;
+
+	virtual Common::SaveFileManager *getSavefileManager() = 0;
+	//@}
+
+protected:
+	int _screenWidth, _screenHeight, _screenBPP;
+	bool _isFullscreen;
+	Shadow *_currentShadowArray;
+	unsigned char _shadowColorR;
+	unsigned char _shadowColorG;
+	unsigned char _shadowColorB;
+};
+
+extern Driver *g_driver;
+
+#endif

Copied: residual/trunk/engine/backend/timer/default/default-timer.cpp (from rev 33439, residual/trunk/engine/backend/default-timer.cpp)
===================================================================
--- residual/trunk/engine/backend/timer/default/default-timer.cpp	                        (rev 0)
+++ residual/trunk/engine/backend/timer/default/default-timer.cpp	2008-07-30 10:24:20 UTC (rev 33441)
@@ -0,0 +1,147 @@
+/* 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$
+ *
+ */
+
+#include "common/sys.h"
+
+#include "engine/backend/driver.h"
+#include "engine/backend/default-timer.h"
+
+struct TimerSlot {
+	Common::TimerManager::TimerProc callback;
+	void *refCon;
+	uint32 interval;	// in microseconds
+
+	uint32 nextFireTime;	// in milliseconds
+	uint32 nextFireTimeMicro;	// mircoseconds part of nextFire
+
+	TimerSlot *next;
+};
+
+void insertPrioQueue(TimerSlot *head, TimerSlot *newSlot) {
+	// The head points to a fake anchor TimerSlot; this common
+	// trick allows us to get rid of many special cases.
+
+	const uint32 nextFireTime = newSlot->nextFireTime;
+	TimerSlot *slot = head;
+	newSlot->next = 0;
+
+	// Insert the new slot into the sorted list of already scheduled
+	// timers in such a way that the list stays sorted...
+	while (true) {
+		assert(slot);
+		if (slot->next == 0 || nextFireTime < slot->next->nextFireTime) {
+			newSlot->next = slot->next;
+			slot->next = newSlot;
+			return;
+		}
+		slot = slot->next;
+	}
+}
+
+
+DefaultTimerManager::DefaultTimerManager() :
+	_timerHandler(0),
+	_head(0) {
+
+	_head = new TimerSlot();
+	memset(_head, 0, sizeof(TimerSlot));
+}
+
+DefaultTimerManager::~DefaultTimerManager() {
+	Common::StackLock lock(_mutex);
+
+	TimerSlot *slot = _head;
+	while (slot) {
+		TimerSlot *next = slot->next;
+		delete slot;
+		slot = next;
+	}
+	_head = 0;
+}
+
+void DefaultTimerManager::handler() {
+	Common::StackLock lock(_mutex);
+
+	const uint32 curTime = g_driver->getMillis();
+
+	// Repeat as long as there is a TimerSlot that is scheduled to fire.
+	TimerSlot *slot = _head->next;
+	while (slot && slot->nextFireTime < curTime) {
+		// Remove the slot from the priority queue
+		_head->next = slot->next;
+
+		// Update the fire time and reinsert the TimerSlot into the priority
+		// queue. Has to be done before the timer callback is invoked, in case
+		// the callback wants to remove itself.
+		assert(slot->interval > 0);
+		slot->nextFireTime += (slot->interval / 1000);
+		slot->nextFireTimeMicro += (slot->interval % 1000);
+		if (slot->nextFireTimeMicro > 1000) {
+			slot->nextFireTime += slot->nextFireTimeMicro / 1000;
+			slot->nextFireTimeMicro %= 1000;
+		}
+		insertPrioQueue(_head, slot);
+
+		// Invoke the timer callback
+		assert(slot->callback);
+		slot->callback(slot->refCon);
+
+		// Look at the next scheduled timer
+		slot = _head->next;
+	}
+}
+
+bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, void *refCon) {
+	assert(interval > 0);
+	Common::StackLock lock(_mutex);
+
+	TimerSlot *slot = new TimerSlot;
+	slot->callback = callback;
+	slot->refCon = refCon;
+	slot->interval = interval;
+	slot->nextFireTime = g_driver->getMillis() + interval / 1000;
+	slot->nextFireTimeMicro = interval % 1000;
+	slot->next = 0;
+
+	insertPrioQueue(_head, slot);
+
+	return true;
+}
+
+void DefaultTimerManager::removeTimerProc(TimerProc callback) {
+	Common::StackLock lock(_mutex);
+
+	TimerSlot *slot = _head;
+
+	while (slot->next) {
+		if (slot->next->callback == callback) {
+			TimerSlot *next = slot->next->next;
+			delete slot->next;
+			slot->next = next;
+		} else {
+			slot = slot->next;
+		}
+	}
+}

Copied: residual/trunk/engine/backend/timer/default/default-timer.h (from rev 33439, residual/trunk/engine/backend/default-timer.h)
===================================================================
--- residual/trunk/engine/backend/timer/default/default-timer.h	                        (rev 0)
+++ residual/trunk/engine/backend/timer/default/default-timer.h	2008-07-30 10:24:20 UTC (rev 33441)
@@ -0,0 +1,51 @@
+/* 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 BACKENDS_TIMER_DEFAULT_H
+#define BACKENDS_TIMER_DEFAULT_H
+
+#include "common/timer.h"
+#include "common/mutex.h"
+
+struct TimerSlot;
+	
+class DefaultTimerManager : public Common::TimerManager {
+private:
+	Common::Mutex _mutex;
+	void *_timerHandler;
+	TimerSlot *_head;
+	
+
+public:
+	DefaultTimerManager();
+	~DefaultTimerManager();
+	bool installTimerProc(TimerProc proc, int32 interval, void *refCon);
+	void removeTimerProc(TimerProc proc);
+
+	// Timer callback, to be invoked at regular time intervals by the backend.
+	void handler();
+};
+
+#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