[Scummvm-cvs-logs] CVS: residual driver_sdl.cpp,NONE,1.1 driver_sdl.h,NONE,1.1 Makefile.common,1.21,1.22 driver.h,1.17,1.18 driver_gl.h,1.31,1.32 driver_tinygl.h,1.18,1.19 engine.cpp,1.101,1.102 timer.cpp,1.13,1.14
Marcus Comstedt
marcus_c at users.sourceforge.net
Sun Feb 5 09:20:09 CET 2006
Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28431
Modified Files:
Makefile.common driver.h driver_gl.h driver_tinygl.h
engine.cpp timer.cpp
Added Files:
driver_sdl.cpp driver_sdl.h
Log Message:
Added time functionality to the Driver interface, following the model
from ScummVM.
SDL-specific time code has been moved into the new class DriverSDL,
which now serves as a base class for DriverGL and DriverTinyGL.
--- NEW FILE: driver_sdl.cpp ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "debug.h"
#include "driver_sdl.h"
// NOTE: This is not a complete driver, it needs to be subclassed
// to provide rendering functionality.
uint32 DriverSDL::getMillis() {
return SDL_GetTicks();
}
void DriverSDL::delayMillis(uint msecs) {
SDL_Delay(msecs);
}
void DriverSDL::setTimerCallback(TimerProc callback, int timer) {
SDL_SetTimer(timer, (SDL_TimerCallback) callback);
}
--- NEW FILE: driver_sdl.h ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org)
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef DRIVER_SDL_H
#define DRIVER_SDL_H
#include "bits.h"
#include "vector3d.h"
#include "color.h"
#include "model.h"
#include "colormap.h"
#include "bitmap.h"
#include "driver.h"
#include <SDL.h>
// NOTE: This is not a complete driver, it needs to be subclassed
// to provide rendering functionality.
class DriverSDL : public Driver {
public:
DriverSDL() { ; }
virtual ~DriverSDL() { ; }
uint32 getMillis();
void delayMillis(uint msecs);
void setTimerCallback(TimerProc callback, int interval);
};
#endif
Index: Makefile.common
===================================================================
RCS file: /cvsroot/scummvm/residual/Makefile.common,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- Makefile.common 26 Dec 2005 02:36:00 -0000 1.21
+++ Makefile.common 5 Feb 2006 17:19:44 -0000 1.22
@@ -61,6 +61,7 @@
blocky16.o \
costume.o \
debug.o \
+ driver_sdl.o \
driver_gl.o \
driver_tinygl.o \
engine.o \
Index: driver.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- driver.h 5 Jan 2006 02:40:26 -0000 1.17
+++ driver.h 5 Feb 2006 17:19:44 -0000 1.18
@@ -102,6 +102,40 @@
virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
+
+ /** @name Events and Time */
+ //@{
+
+ typedef int (*TimerProc)(int interval);
+
+ /** 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;
+
+ /**
+ * Set the timer callback, a function which is periodically invoked by the
+ * driver. This can for example be done via a background thread.
+ * There is at most one active timer; if this method is called while there
+ * is already an active timer, then the new timer callback should replace
+ * the previous one. In particular, passing a callback pointer value of 0
+ * is legal and can be used to clear the current timer callback.
+ * @see Timer
+ * @note The implementation of this method must be 'atomic' in the sense
+ * that when the method returns, the previously set callback must
+ * not be in use anymore (in particular, if timers are implemented
+ * via threads, then it must be ensured that the timer thread is
+ * not using the old callback function anymore).
+ *
+ * @param callback pointer to the callback. May be 0 to reset the timer
+ * @param interval the interval (in milliseconds) between invocations
+ * of the callback
+ */
+ virtual void setTimerCallback(TimerProc callback, int interval) = 0;
+
+ //@}
+
protected:
int _screenWidth, _screenHeight, _screenBPP;
bool _isFullscreen;
Index: driver_gl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- driver_gl.h 5 Jan 2006 02:40:26 -0000 1.31
+++ driver_gl.h 5 Feb 2006 17:19:44 -0000 1.32
@@ -25,11 +25,12 @@
#include "colormap.h"
#include "bitmap.h"
#include "driver.h"
+#include "driver_sdl.h"
#include <SDL.h>
#include <SDL_opengl.h>
-class DriverGL : public Driver {
+class DriverGL : public DriverSDL {
public:
DriverGL(int screenW, int screenH, int screenBPP, bool fullscreen = false);
virtual ~DriverGL();
Index: driver_tinygl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_tinygl.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- driver_tinygl.h 5 Jan 2006 02:40:26 -0000 1.18
+++ driver_tinygl.h 5 Feb 2006 17:19:44 -0000 1.19
@@ -25,13 +25,14 @@
#include "colormap.h"
#include "bitmap.h"
#include "driver.h"
+#include "driver_sdl.h"
#include "tinygl/gl.h"
#include "tinygl/zgl.h"
#include <SDL.h>
-class DriverTinyGL : public Driver {
+class DriverTinyGL : public DriverSDL {
public:
DriverTinyGL(int screenW, int screenH, int screenBPP, bool fullscreen = false);
virtual ~DriverTinyGL();
Index: engine.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/engine.cpp,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- engine.cpp 21 Jan 2006 17:32:18 -0000 1.101
+++ engine.cpp 5 Feb 2006 17:19:44 -0000 1.102
@@ -29,7 +29,6 @@
#include "imuse/imuse.h"
#include <SDL.h>
-#include <SDL_timer.h>
#include <assert.h>
// CHAR_KEY tests to see whether a keycode is for
@@ -217,7 +216,7 @@
void Engine::luaUpdate() {
// Update timing information
- unsigned newStart = SDL_GetTicks();
+ unsigned newStart = g_driver->getMillis();
if (newStart < _frameStart) {
_frameStart = newStart;
return;
@@ -246,7 +245,7 @@
}
void Engine::updateDisplayScene() {
- uint32 newTime = SDL_GetTicks();
+ uint32 newTime = g_driver->getMillis();
if (newTime < _lastUpdateTime) {
_lastUpdateTime = newTime;
_doFlip = false;
@@ -374,7 +373,7 @@
g_driver->flipBuffer();
// don't kill CPU
- SDL_Delay(10);
+ g_driver->delayMillis(10);
if (SHOWFPS_GLOBAL && _doFlip) {
_frameCounter++;
@@ -390,7 +389,7 @@
void Engine::mainLoop() {
_movieTime = 0;
_frameTime = 0;
- _frameStart = SDL_GetTicks();
+ _frameStart = g_driver->getMillis();
_frameCounter = 0;
_timeAccum = 0;
_frameTimeCollection = 0;
Index: timer.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/timer.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- timer.cpp 10 Jul 2005 18:57:27 -0000 1.13
+++ timer.cpp 5 Feb 2006 17:19:44 -0000 1.14
@@ -19,8 +19,7 @@
#include "bits.h"
#include "debug.h"
#include "timer.h"
-
-#include <SDL.h>
+#include "driver.h"
Timer *g_timer = NULL;
@@ -39,14 +38,14 @@
_timerSlots[i].counter = 0;
}
- _thisTime = SDL_GetTicks();
+ _thisTime = g_driver->getMillis();
// Set the timer last, after everything has been initialised
- SDL_SetTimer(10, (SDL_TimerCallback) timer_handler);
+ g_driver->setTimerCallback(timer_handler, 10);
}
Timer::~Timer() {
- SDL_SetTimer(0, NULL);
+ g_driver->setTimerCallback(NULL, 0);
{
StackLock lock(_mutex);
@@ -71,7 +70,7 @@
uint32 interval, l;
_lastTime = _thisTime;
- _thisTime = SDL_GetTicks();
+ _thisTime = g_driver->getMillis();
interval = 1000 * (_thisTime - _lastTime);
for (l = 0; l < MAX_TIMERS; l++) {
More information about the Scummvm-git-logs
mailing list