[Scummvm-cvs-logs] SF.net SVN: scummvm: [31614] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Apr 20 17:47:11 CEST 2008


Revision: 31614
          http://scummvm.svn.sourceforge.net/scummvm/?rev=31614&view=rev
Author:   lordhoto
Date:     2008-04-20 08:47:11 -0700 (Sun, 20 Apr 2008)

Log Message:
-----------
- moved kyra functor code to common/func.h
- adapted debugger code to use functor code from common/func.h
- adapted kyra engine to use functor code from common/func.h

Modified Paths:
--------------
    scummvm/trunk/common/func.h
    scummvm/trunk/engines/kyra/gui.h
    scummvm/trunk/engines/kyra/kyra.h
    scummvm/trunk/engines/kyra/kyra_v2.h
    scummvm/trunk/engines/kyra/screen.h
    scummvm/trunk/engines/kyra/script.h
    scummvm/trunk/engines/kyra/script_tim.h
    scummvm/trunk/engines/kyra/script_v1.cpp
    scummvm/trunk/engines/kyra/script_v2.cpp
    scummvm/trunk/engines/kyra/script_v3.cpp
    scummvm/trunk/engines/kyra/timer.h
    scummvm/trunk/engines/kyra/timer_v1.cpp
    scummvm/trunk/engines/kyra/timer_v2.cpp
    scummvm/trunk/engines/kyra/timer_v3.cpp
    scummvm/trunk/gui/debugger.cpp
    scummvm/trunk/gui/debugger.h

Removed Paths:
-------------
    scummvm/trunk/engines/kyra/util.h

Modified: scummvm/trunk/common/func.h
===================================================================
--- scummvm/trunk/common/func.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/common/func.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -247,6 +247,80 @@
 	return FrontInsertIterator<Cont>(c);
 }
 
+// functor code
+
+template<class Res>
+struct Functor0 {
+	virtual ~Functor0() {}
+
+	virtual bool isValid() const = 0;
+	virtual Res operator()() const = 0;
+};
+
+template<class Res, class T>
+class Functor0Mem : public Functor0<Res> {
+public:
+	typedef Res (T::*FuncType)();
+
+	Functor0Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
+
+	bool isValid() const { return _func != 0; }
+	Res operator()() const {
+		return (_t->*_func)();
+	}
+private:
+	mutable T *_t;
+	const FuncType _func;
+};
+
+template<class Arg, class Res>
+struct Functor1 : public Common::UnaryFunction<Arg, Res> {
+	virtual ~Functor1() {}
+
+	virtual bool isValid() const = 0;
+	virtual Res operator()(Arg) const = 0;
+};
+
+template<class Arg, class Res, class T>
+class Functor1Mem : public Functor1<Arg, Res> {
+public:
+	typedef Res (T::*FuncType)(Arg);
+
+	Functor1Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
+
+	bool isValid() const { return _func != 0; }
+	Res operator()(Arg v1) const {
+		return (_t->*_func)(v1);
+	}
+private:
+	mutable T *_t;
+	const FuncType _func;
+};
+
+template<class Arg1, class Arg2, class Res>
+struct Functor2 : public Common::BinaryFunction<Arg1, Arg2, Res> {
+	virtual ~Functor2() {}
+
+	virtual bool isValid() const = 0;
+	virtual Res operator()(Arg1, Arg2) const = 0;
+};
+
+template<class Arg1, class Arg2, class Res, class T>
+class Functor2Mem : public Functor2<Arg1, Arg2, Res> {
+public:
+	typedef Res (T::*FuncType)(Arg1, Arg2);
+
+	Functor2Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
+
+	bool isValid() const { return _func != 0; }
+	Res operator()(Arg1 v1, Arg2 v2) const {
+		return (_t->*_func)(v1, v2);
+	}
+private:
+	mutable T *_t;
+	const FuncType _func;
+};
+
 /**
  * Base template for hash functor objects, used by HashMap.
  * This needs to be specialized for every type that you need to hash.

Modified: scummvm/trunk/engines/kyra/gui.h
===================================================================
--- scummvm/trunk/engines/kyra/gui.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/gui.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -26,18 +26,18 @@
 #ifndef KYRA_GUI_H
 #define KYRA_GUI_H
 
-#include "kyra/util.h"
 #include "kyra/kyra.h"
 
 #include "common/ptr.h"
 #include "common/array.h"
+#include "common/func.h"
 
 namespace Kyra {
 
-#define BUTTON_FUNCTOR(type, x, y) Button::Callback(new Functor1Mem<Button*, int, type>(x, y))
+#define BUTTON_FUNCTOR(type, x, y) Button::Callback(new Common::Functor1Mem<Button*, int, type>(x, y))
 
 struct Button {
-	typedef Functor1<Button*, int> CallbackFunctor;
+	typedef Common::Functor1<Button*, int> CallbackFunctor;
 	typedef Common::SharedPtr<CallbackFunctor> Callback;
 
 	Button *nextButton;

Modified: scummvm/trunk/engines/kyra/kyra.h
===================================================================
--- scummvm/trunk/engines/kyra/kyra.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/kyra.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -27,11 +27,13 @@
 #define KYRA_KYRA_H
 
 #include "engines/engine.h"
+
 #include "common/rect.h"
 #include "common/array.h"
 #include "common/events.h"
+#include "common/func.h"
 
-#include "kyra/util.h"
+#include "kyra/script.h"
 
 namespace Common {
 class InSaveFile;
@@ -99,7 +101,6 @@
 class TextDisplayer;
 class StaticResource;
 class TimerManager;
-class ScriptHelper;
 
 class KyraEngine : public Engine {
 friend class Debugger;

Modified: scummvm/trunk/engines/kyra/kyra_v2.h
===================================================================
--- scummvm/trunk/engines/kyra/kyra_v2.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/kyra_v2.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -28,12 +28,13 @@
 
 #include "kyra/kyra.h"
 #include "kyra/script.h"
+#include "kyra/script_tim.h"
 #include "kyra/screen_v2.h"
 #include "kyra/text_v2.h"
 #include "kyra/gui_v2.h"
-#include "kyra/util.h"
 
 #include "common/list.h"
+#include "common/func.h"
 
 namespace Kyra {
 
@@ -99,7 +100,6 @@
 class WSAMovieV2;
 class KyraEngine_v2;
 class TextDisplayer_v2;
-class TIMInterpreter;
 class Debugger_v2;
 
 struct TIM;
@@ -329,7 +329,7 @@
 	void update();
 	void updateWithText();
 
-	Functor0Mem<void, KyraEngine_v2> _updateFunctor;
+	Common::Functor0Mem<void, KyraEngine_v2> _updateFunctor;
 
 	void updateMouse();
 

Modified: scummvm/trunk/engines/kyra/screen.h
===================================================================
--- scummvm/trunk/engines/kyra/screen.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/screen.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -27,14 +27,13 @@
 #define KYRA_SCREEN_H
 
 #include "common/util.h"
+#include "common/func.h"
 
-#include "kyra/util.h"
-
 class OSystem;
 
 namespace Kyra {
 
-typedef Functor0<void> UpdateFunctor;
+typedef Common::Functor0<void> UpdateFunctor;
 
 class KyraEngine;
 struct Rect;

Modified: scummvm/trunk/engines/kyra/script.h
===================================================================
--- scummvm/trunk/engines/kyra/script.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/script.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -26,13 +26,14 @@
 #ifndef KYRA_SCRIPT_H
 #define KYRA_SCRIPT_H
 
-#include "kyra/kyra.h"
-#include "kyra/util.h"
-
 #include "common/stream.h"
+#include "common/func.h"
 
 namespace Kyra {
 
+struct ScriptState;
+typedef Common::Functor1<ScriptState*, int> Opcode;
+
 struct ScriptData {
 	byte *text;
 	uint16 *data;
@@ -61,6 +62,9 @@
 #define ORDR_CHUNK 0x5244524F
 #define AVTL_CHUNK 0x4C545641
 
+class Resource;
+class KyraEngine;
+
 class ScriptFileParser {
 public:
 	ScriptFileParser() : _stream(0), _startOffset(0), _endOffset(0) {}

Modified: scummvm/trunk/engines/kyra/script_tim.h
===================================================================
--- scummvm/trunk/engines/kyra/script_tim.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/script_tim.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -27,12 +27,15 @@
 #define KYRA_SCRIPT_TIM_H
 
 #include "kyra/kyra.h"
-#include "kyra/util.h"
 
 #include "common/array.h"
+#include "common/func.h"
 
 namespace Kyra {
 
+struct TIM;
+typedef Common::Functor2<const TIM*, const uint16*, int> TIMOpcode;
+
 struct TIM {
 	int16 procFunc;
 	uint16 procParam;

Modified: scummvm/trunk/engines/kyra/script_v1.cpp
===================================================================
--- scummvm/trunk/engines/kyra/script_v1.cpp	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/script_v1.cpp	2008-04-20 15:47:11 UTC (rev 31614)
@@ -1820,7 +1820,7 @@
 
 #pragma mark -
 
-typedef Functor1Mem<ScriptState*, int, KyraEngine_v1> OpcodeV1;
+typedef Common::Functor1Mem<ScriptState*, int, KyraEngine_v1> OpcodeV1;
 #define SetOpcodeTable(x) table = &x;
 #define Opcode(x) table->push_back(new OpcodeV1(this, &KyraEngine_v1::x))
 void KyraEngine_v1::setupOpcodeTable() {

Modified: scummvm/trunk/engines/kyra/script_v2.cpp
===================================================================
--- scummvm/trunk/engines/kyra/script_v2.cpp	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/script_v2.cpp	2008-04-20 15:47:11 UTC (rev 31614)
@@ -1872,12 +1872,12 @@
 
 #pragma mark -
 
-typedef Functor1Mem<ScriptState*, int, KyraEngine_v2> OpcodeV2;
+typedef Common::Functor1Mem<ScriptState*, int, KyraEngine_v2> OpcodeV2;
 #define SetOpcodeTable(x) table = &x;
 #define Opcode(x) table->push_back(new OpcodeV2(this, &KyraEngine_v2::x))
 #define OpcodeUnImpl() table->push_back(new OpcodeV2(this, 0))
 
-typedef Functor2Mem<const TIM*, const uint16*, int, KyraEngine_v2> TIMOpcodeV2;
+typedef Common::Functor2Mem<const TIM*, const uint16*, int, KyraEngine_v2> TIMOpcodeV2;
 #define OpcodeTim(x) _timOpcodes.push_back(new TIMOpcodeV2(this, &KyraEngine_v2::x))
 #define OpcodeTimUnImpl() _timOpcodes.push_back(TIMOpcodeV2(this, 0))
 

Modified: scummvm/trunk/engines/kyra/script_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/script_v3.cpp	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/script_v3.cpp	2008-04-20 15:47:11 UTC (rev 31614)
@@ -580,7 +580,7 @@
 	return _malcolmShapes;
 }
 
-typedef Functor1Mem<ScriptState*, int, KyraEngine_v3> OpcodeV3;
+typedef Common::Functor1Mem<ScriptState*, int, KyraEngine_v3> OpcodeV3;
 #define SetOpcodeTable(x) table = &x;
 #define Opcode(x) table->push_back(new OpcodeV3(this, &KyraEngine_v3::x))
 #define OpcodeUnImpl() table->push_back(new OpcodeV3(this, 0))

Modified: scummvm/trunk/engines/kyra/timer.h
===================================================================
--- scummvm/trunk/engines/kyra/timer.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/timer.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -27,14 +27,14 @@
 #define KYRA_TIMER_H
 
 #include "kyra/kyra.h"
-#include "kyra/util.h"
 
 #include "common/list.h"
 #include "common/stream.h"
+#include "common/func.h"
 
 namespace Kyra {
 
-typedef Functor1<int, void> TimerFunc;
+typedef Common::Functor1<int, void> TimerFunc;
 
 struct TimerEntry {
 	uint8 id;
@@ -89,3 +89,4 @@
 } // end of namespace Kyra
 
 #endif
+

Modified: scummvm/trunk/engines/kyra/timer_v1.cpp
===================================================================
--- scummvm/trunk/engines/kyra/timer_v1.cpp	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/timer_v1.cpp	2008-04-20 15:47:11 UTC (rev 31614)
@@ -33,7 +33,7 @@
 
 namespace Kyra {
 
-#define TimerV1(x) new Functor1Mem<int, void, KyraEngine_v1>(this, &KyraEngine_v1::x)
+#define TimerV1(x) new Common::Functor1Mem<int, void, KyraEngine_v1>(this, &KyraEngine_v1::x)
 
 void KyraEngine_v1::setupTimers() {
 	debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v1::setupTimers()");

Modified: scummvm/trunk/engines/kyra/timer_v2.cpp
===================================================================
--- scummvm/trunk/engines/kyra/timer_v2.cpp	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/timer_v2.cpp	2008-04-20 15:47:11 UTC (rev 31614)
@@ -28,7 +28,7 @@
 
 namespace Kyra {
 
-#define TimerV2(x) new Functor1Mem<int, void, KyraEngine_v2>(this, &KyraEngine_v2::x)
+#define TimerV2(x) new Common::Functor1Mem<int, void, KyraEngine_v2>(this, &KyraEngine_v2::x)
 
 void KyraEngine_v2::setupTimers() {
 	debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v2::setupTimers()");

Modified: scummvm/trunk/engines/kyra/timer_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/timer_v3.cpp	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/timer_v3.cpp	2008-04-20 15:47:11 UTC (rev 31614)
@@ -28,7 +28,7 @@
 
 namespace Kyra {
 
-#define TimerV3(x) new Functor1Mem<int, void, KyraEngine_v3>(this, &KyraEngine_v3::x)
+#define TimerV3(x) new Common::Functor1Mem<int, void, KyraEngine_v3>(this, &KyraEngine_v3::x)
 
 void KyraEngine_v3::setupTimers() {
 	debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v3::setupTimers()");

Deleted: scummvm/trunk/engines/kyra/util.h
===================================================================
--- scummvm/trunk/engines/kyra/util.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/engines/kyra/util.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -1,114 +0,0 @@
-/* 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.
- *
- * $URL$
- * $Id$
- *
- */
-
-#ifndef KYRA_UTIL_H
-#define KYRA_UTIL_H
-
-#include "common/func.h"
-
-namespace Kyra {
-
-template<class Res>
-struct Functor0 {
-	virtual ~Functor0() {}
-
-	virtual bool isValid() const = 0;
-	virtual Res operator()() const = 0;
-};
-
-template<class Res, class T>
-class Functor0Mem : public Functor0<Res> {
-public:
-	typedef Res (T::*FuncType)();
-
-	Functor0Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
-
-	bool isValid() const { return _func != 0; }
-	Res operator()() const {
-		return (_t->*_func)();
-	}
-private:
-	mutable T *_t;
-	Res (T::*_func)();
-};
-
-template<class Arg, class Res>
-struct Functor1 : public Common::UnaryFunction<Arg, Res> {
-	virtual ~Functor1() {}
-
-	virtual bool isValid() const = 0;
-	virtual Res operator()(Arg) const = 0;
-};
-
-template<class Arg, class Res, class T>
-class Functor1Mem : public Functor1<Arg, Res> {
-public:
-	typedef Res (T::*FuncType)(Arg);
-
-	Functor1Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
-
-	bool isValid() const { return _func != 0; }
-	Res operator()(Arg v1) const {
-		return (_t->*_func)(v1);
-	}
-private:
-	mutable T *_t;
-	Res (T::*_func)(Arg);
-};
-
-template<class Arg1, class Arg2, class Res>
-struct Functor2 : public Common::BinaryFunction<Arg1, Arg2, Res> {
-	virtual ~Functor2() {}
-
-	virtual bool isValid() const = 0;
-	virtual Res operator()(Arg1, Arg2) const = 0;
-};
-
-template<class Arg1, class Arg2, class Res, class T>
-class Functor2Mem : public Functor2<Arg1, Arg2, Res> {
-public:
-	typedef Res (T::*FuncType)(Arg1, Arg2);
-
-	Functor2Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
-
-	bool isValid() const { return _func != 0; }
-	Res operator()(Arg1 v1, Arg2 v2) const {
-		return (_t->*_func)(v1, v2);
-	}
-private:
-	mutable T *_t;
-	Res (T::*_func)(Arg1, Arg2);
-};
-
-struct ScriptState;
-typedef Functor1<ScriptState*, int> Opcode;
-
-struct TIM;
-typedef Functor2<const TIM*, const uint16*, int> TIMOpcode;
-
-} // end of namespace Kyra
-
-#endif
-

Modified: scummvm/trunk/gui/debugger.cpp
===================================================================
--- scummvm/trunk/gui/debugger.cpp	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/gui/debugger.cpp	2008-04-20 15:47:11 UTC (rev 31614)
@@ -347,6 +347,7 @@
 
 // Command registration function
 void Debugger::DCmd_Register(const char *cmdname, Debuglet *debuglet) {
+	assert(debuglet->isValid());
 	assert(_dcmd_count < ARRAYSIZE(_dcmds));
 	strcpy(_dcmds[_dcmd_count].name, cmdname);
 	_dcmds[_dcmd_count].debuglet = debuglet;

Modified: scummvm/trunk/gui/debugger.h
===================================================================
--- scummvm/trunk/gui/debugger.h	2008-04-20 15:40:17 UTC (rev 31613)
+++ scummvm/trunk/gui/debugger.h	2008-04-20 15:47:11 UTC (rev 31614)
@@ -25,6 +25,8 @@
 #ifndef GUI_DEBUGGER_H
 #define GUI_DEBUGGER_H
 
+#include "common/func.h"
+
 namespace GUI {
 
 // Choose between text console or ScummConsole
@@ -47,32 +49,12 @@
 	bool isAttached() const { return _isAttached; }
 
 protected:
-	class Debuglet {
-	public:
-		virtual ~Debuglet() {}
-		virtual bool operator()(int argc, const char **argv) = 0;
-	};
+	typedef Common::Functor2<int, const char **, bool> Debuglet;
 
-	template <class T>
-	class DelegateDebuglet : public Debuglet {
-		typedef bool (T::*Method)(int argc, const char **argv);
-
-		T *_delegate;
-		const Method _method;
-	public:
-		DelegateDebuglet(T *delegate, Method method)
-			: _delegate(delegate), _method(method) {
-			assert(delegate != 0);
-		}
-		virtual bool operator()(int argc, const char **argv) {
-			return (_delegate->*_method)(argc, argv);
-		};
-	};
-
 	// Convenicence macro for registering a method of a debugger class
 	// as the current command.
 	#define WRAP_METHOD(cls, method) \
-		new DelegateDebuglet<cls>(this, &cls::method)
+		new Common::Functor2Mem<int, const char **, bool, cls>(this, &cls::method)
 
 	enum {
 		DVAR_BYTE,


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