[Scummvm-cvs-logs] SF.net SVN: scummvm: [32952] scummvm/branches/gsoc2008-rtl

cpage88 at users.sourceforge.net cpage88 at users.sourceforge.net
Tue Jul 8 00:34:45 CEST 2008


Revision: 32952
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32952&view=rev
Author:   cpage88
Date:     2008-07-07 15:34:45 -0700 (Mon, 07 Jul 2008)

Log Message:
-----------
Implemented Common::EventManager::pushEvent() to insert fake events into the event queue.  Quit and RTL events have been added, and are now tracked by the DefaultEventManager using shouldQuit() and shouldRTL().  AGOS is working with this new implementation, other engines to follow.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.cpp
    scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.h
    scummvm/branches/gsoc2008-rtl/base/main.cpp
    scummvm/branches/gsoc2008-rtl/common/events.h
    scummvm/branches/gsoc2008-rtl/engines/agos/agos.cpp
    scummvm/branches/gsoc2008-rtl/engines/agos/animation.cpp
    scummvm/branches/gsoc2008-rtl/engines/agos/event.cpp
    scummvm/branches/gsoc2008-rtl/engines/agos/gfx.cpp
    scummvm/branches/gsoc2008-rtl/engines/agos/input.cpp
    scummvm/branches/gsoc2008-rtl/engines/agos/script.cpp
    scummvm/branches/gsoc2008-rtl/engines/agos/script_e1.cpp
    scummvm/branches/gsoc2008-rtl/engines/agos/script_s1.cpp
    scummvm/branches/gsoc2008-rtl/engines/dialogs.cpp

Modified: scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -201,6 +201,9 @@
 	_boss->unlockMutex(_timeMutex);
 	_boss->unlockMutex(_recorderMutex);
 
+	if (!artificialEventQueue.empty())
+		artificialEventQueue.clear();
+
 	if (_playbackFile != NULL) {
 		delete _playbackFile;
 	}
@@ -350,7 +353,11 @@
 	uint32 time = _boss->getMillis();
 	bool result;
 
-	result = _boss->pollEvent(event);
+	if (!artificialEventQueue.empty()) {
+		event.type = artificialEventQueue.pop();
+		result = true;
+	} else 	
+		result = _boss->pollEvent(event);
 
 	if (_recordMode != kPassthrough)  {
 
@@ -387,13 +394,9 @@
 			// Global Main Menu
 			if (event.kbd.keycode == Common::KEYCODE_F11)
 				if (g_engine && !g_engine->isPaused())
-					g_engine->mainMenuDialog();
+					pushEvent(Common::EVENT_MAINMENU);
+			break;
 
-			if (g_engine->_quit)
-				event.type = Common::EVENT_QUIT;
-			else
-				break;
-
 		case Common::EVENT_KEYUP:
 			_modifierState = event.kbd.flags;
 			if (event.kbd.keycode == _currentKeyDown.keycode) {
@@ -429,11 +432,12 @@
 		case Common::EVENT_MAINMENU:
 			if (g_engine && !g_engine->isPaused())
 				g_engine->mainMenuDialog();
+			break;
 
-			if (g_engine->_quit)
-				event.type = Common::EVENT_QUIT;
-			else 
-				break;
+		case Common::EVENT_RTL:
+			_shouldRTL = true;
+			_shouldQuit = true;
+			break;
 
 		case Common::EVENT_QUIT:
 			if (ConfMan.getBool("confirm_exit")) {
@@ -446,7 +450,6 @@
 			} else
 				_shouldQuit = true;
 
-			g_engine->_quit = true;
 			break;
 
 		default:
@@ -469,4 +472,8 @@
 	return result;
 }
 
+void DefaultEventManager::pushEvent(Common::EventType eventType) {
+	artificialEventQueue.push(eventType);
+}
+
 #endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)

Modified: scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.h
===================================================================
--- scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.h	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/backends/events/default/default-events.h	2008-07-07 22:34:45 UTC (rev 32952)
@@ -108,6 +108,7 @@
 	~DefaultEventManager();
 
 	virtual bool pollEvent(Common::Event &event);
+	virtual void pushEvent(Common::EventType eventType);
 	virtual void registerRandomSource(Common::RandomSource &rnd, const char *name);
 	virtual void processMillis(uint32 &millis);
 
@@ -116,8 +117,7 @@
 	virtual int getModifierState() const { return _modifierState; }
 	virtual int shouldQuit() const { return _shouldQuit; }
 	virtual int shouldRTL() const { return _shouldRTL; }
-	virtual void setQuit() { _shouldQuit = true; }
-	virtual void setRTL() { _shouldRTL = true; }
+	virtual void resetQuit() { _shouldQuit = false; }
 	virtual void resetRTL() { _shouldRTL = false; }
 };
 

Modified: scummvm/branches/gsoc2008-rtl/base/main.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/base/main.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/base/main.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -38,6 +38,7 @@
 #include "base/version.h"
 
 #include "common/config-manager.h"
+#include "common/events.h"
 #include "common/file.h"
 #include "common/fs.h"
 #include "common/system.h"
@@ -315,6 +316,11 @@
 			// TODO: We should keep running if starting the selected game failed
 			// (so instead of just quitting, show a nice error dialog to the
 			// user and let him pick another game).
+		 	
+			// Reset RTL and Quit flags in case we want to load another engine
+			g_system->getEventManager()->resetRTL();		
+			g_system->getEventManager()->resetQuit();
+
 			if (result == 0)
 				break;
 

Modified: scummvm/branches/gsoc2008-rtl/common/events.h
===================================================================
--- scummvm/branches/gsoc2008-rtl/common/events.h	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/common/events.h	2008-07-07 22:34:45 UTC (rev 32952)
@@ -27,6 +27,7 @@
 #define COMMON_EVENTS_H
 
 #include "common/keyboard.h"
+#include "common/queue.h"
 #include "common/rect.h"
 #include "common/system.h"
 #include "common/noncopyable.h"
@@ -59,6 +60,7 @@
 	EVENT_MBUTTONUP = 14,
 
 	EVENT_MAINMENU = 15,
+	EVENT_RTL = 16,
 
 	EVENT_QUIT = 10,
 	EVENT_SCREEN_CHANGED = 11,
@@ -144,6 +146,11 @@
 	 */
 	virtual bool pollEvent(Common::Event &event) = 0;
 
+	/**
+	 * Pushes a "fake" event of the specified type into the event queue
+	 */
+	virtual void pushEvent(Common::EventType eventType) = 0;
+
 	/** Register random source so it can be serialized in game test purposes **/
 	virtual void registerRandomSource(Common::RandomSource &rnd, const char *name) = 0;
 
@@ -173,18 +180,14 @@
 	 */
 	virtual int shouldRTL() const = 0;
 
-	/** 
-	 * Sets the quit variable to true
-	 */
-	virtual void setQuit() = 0;
-
 	/**
-	 * Set the RTL flag, we should return to the launcher
+	 * We have returned to the launcher, and _shouldQuit should be reset to false
 	 */
-	virtual void setRTL() = 0;
 
+	virtual void resetQuit() = 0;
+
 	/**
-	 * We have returned to the launcher, and the RTL should be reset to false
+	 * We have returned to the launcher, and the _shouldRTL should be reset to false
 	 */
 	virtual void resetRTL() = 0;
 
@@ -195,6 +198,9 @@
 
 	// TODO: Consider removing OSystem::getScreenChangeID and
 	// replacing it by a generic getScreenChangeID method here
+protected:
+
+	Common::Queue<Common::EventType> artificialEventQueue;
 };
 
 } // End of namespace Common

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/agos.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/agos.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/agos.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -947,7 +947,7 @@
 void AGOSEngine::pause() {
 	pauseEngine(true);
 
-	while (_pause && !_quit) {
+	while (_pause && !_eventMan->shouldQuit()) {
 		delay(1);
 		if (_keyPressed.keycode == Common::KEYCODE_p)
 			pauseEngine(false);
@@ -984,7 +984,7 @@
 		(getFeatures() & GF_DEMO)) {
 		int i;
 
-		while (!_quit) {
+		while (!_eventMan->shouldQuit()) {
 			for (i = 0; i < 4; i++) {
 				setWindowImage(3, 9902 + i);
 				debug(0, "Displaying image %d", 9902 + i);
@@ -1013,13 +1013,13 @@
 	runSubroutine101();
 	permitInput();
 
-	while (!_quit) {
+	while (!_eventMan->shouldQuit()) {
 		waitForInput();
 		handleVerbClicked(_verbHitArea);
 		delay(100);
 	}
 
-	return _rtl;
+	return _eventMan->shouldRTL();
 }
 
 

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/animation.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/animation.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/animation.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -279,9 +279,6 @@
 		case Common::EVENT_RBUTTONUP:
 			_rightButtonDown = false;
 			break;
-		case Common::EVENT_QUIT:
-			_vm->_quit = true;
-			break;
 		default:
 			break;
 		}

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/event.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/event.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/event.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -142,7 +142,7 @@
 
 	cur_time = getTime() - _gameStoppedClock;
 
-	while ((te = _firstTimeStruct) != NULL && te->time <= cur_time && !_quit) {
+	while ((te = _firstTimeStruct) != NULL && te->time <= cur_time && !_eventMan->shouldQuit()) {
 		result = true;
 		_pendingDeleteTimeEvent = te;
 		invokeTimeEvent(te);
@@ -521,7 +521,6 @@
 				_rightButtonDown++;
 				break;
 			case Common::EVENT_QUIT:
-				_quit = true;
 				return;
 			default:
 				break;
@@ -544,7 +543,7 @@
 		_system->delayMillis(this_delay);
 
 		cur = _system->getMillis();
-	} while (cur < start + amount && !_quit);
+	} while (cur < start + amount && !_eventMan->shouldQuit());
 }
 
 void AGOSEngine::timer_callback() {

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/gfx.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/gfx.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/gfx.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -26,6 +26,7 @@
 
 
 #include "common/system.h"
+#include "common/events.h"
 
 #include "graphics/surface.h"
 
@@ -1263,7 +1264,7 @@
 		if (getGameType() == GType_WW && (mode == 6 || mode == 8 || mode == 9)) {
 			setWindowImage(mode, vga_res);
 		} else {
-			while (_copyScnFlag && !_quit)
+			while (_copyScnFlag && !_eventMan->shouldQuit())
 				delay(1);
 
 			setWindowImage(mode, vga_res);

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/input.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/input.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/input.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -26,6 +26,7 @@
 
 
 #include "common/config-manager.h"
+#include "common/events.h"
 #include "common/file.h"
 
 #include "agos/intern.h"
@@ -189,12 +190,12 @@
 		resetVerbs();
 	}
 
-	while (!_quit) {
+	while (!_eventMan->shouldQuit()) {
 		_lastHitArea = NULL;
 		_lastHitArea3 = NULL;
 		_dragAccept = 1;
 
-		while (!_quit) {
+		while (!_eventMan->shouldQuit()) {
 			if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
 					_keyPressed.keycode == Common::KEYCODE_F10)
 				displayBoxStars();

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/script.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/script.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/script.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -28,6 +28,7 @@
 
 
 #include "common/system.h"
+#include "common/events.h"
 
 #include "agos/animation.h"
 #include "agos/agos.h"
@@ -410,7 +411,7 @@
 
 void AGOSEngine::o_end() {
 	// 68: exit interpreter
-	_quit = true;
+	_eventMan->pushEvent(Common::EVENT_QUIT);
 }
 
 void AGOSEngine::o_done() {
@@ -965,7 +966,7 @@
 int AGOSEngine::runScript() {
 	bool flag;
 
-	if (_quit)
+	if (_eventMan->shouldQuit())
 		return 1;
 
 	do {
@@ -1010,7 +1011,7 @@
 			error("Invalid opcode '%d' encountered", _opcode);
 
 		executeOpcode(_opcode);
-	} while  (getScriptCondition() != flag && !getScriptReturn() && !_quit);
+	} while  (getScriptCondition() != flag && !getScriptReturn() && !_eventMan->shouldQuit());
 
 	return getScriptReturn();
 }
@@ -1066,7 +1067,7 @@
 	_exitCutscene = false;
 	_rightButtonDown = false;
 
-	while (_vgaWaitFor != 0 && !_quit) {
+	while (_vgaWaitFor != 0 && !_eventMan->shouldQuit()) {
 		if (_rightButtonDown) {
 			if (_vgaWaitFor == 200 && (getGameType() == GType_FF || !getBitFlag(14))) {
 				skipSpeech();

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/script_e1.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/script_e1.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/script_e1.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -23,8 +23,8 @@
  *
  */
 
+#include "common/events.h"
 
-
 #include "agos/agos.h"
 #include "agos/vga.h"
 
@@ -565,7 +565,7 @@
 		lobjFunc(l, "You can see ");	/* Show objects */
 	}
 	if (r && (r->flags & 4) && levelOf(i) < 10000) {
-		_quit = true;
+		_eventMan->pushEvent(Common::EVENT_QUIT);
 	}
 }
 
@@ -944,7 +944,7 @@
 			windowPutChar(window, *message2);
 
 		if (confirmYesOrNo(120, 62) == 0x7FFF) {
-			_quit = true;
+			_eventMan->pushEvent(Common::EVENT_QUIT);
 		} else {
 			goto restart;
 		}

Modified: scummvm/branches/gsoc2008-rtl/engines/agos/script_s1.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/agos/script_s1.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/agos/script_s1.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -24,7 +24,7 @@
  */
 
 
-
+#include "common/events.h"
 #include "common/system.h"
 
 #include "agos/agos.h"
@@ -345,14 +345,14 @@
 		if (isSmartphone()) {
 			if (_keyPressed.keycode) {
 				if (_keyPressed.keycode == Common::KEYCODE_RETURN)
-					_quit = true;
+					_eventMan->pushEvent(Common::EVENT_QUIT);
 				else
 					break;
 			}
 		}
 #endif
 		if (_keyPressed.keycode == keyYes)
-			_quit = true;
+			_eventMan->pushEvent(Common::EVENT_QUIT);
 		else if (_keyPressed.keycode == keyNo)
 			break;
 	}

Modified: scummvm/branches/gsoc2008-rtl/engines/dialogs.cpp
===================================================================
--- scummvm/branches/gsoc2008-rtl/engines/dialogs.cpp	2008-07-07 22:02:01 UTC (rev 32951)
+++ scummvm/branches/gsoc2008-rtl/engines/dialogs.cpp	2008-07-07 22:34:45 UTC (rev 32952)
@@ -108,15 +108,11 @@
 		_aboutDialog->runModal();
 		break;
 	case kRTLCmd:
-		//g_system->getEventManager()->setQuit();
-		//g_system->getEventManager()->setRTL();
-		_engine->_quit = true;
-		_engine->_rtl = true;
+		g_system->getEventManager()->pushEvent(Common::EVENT_RTL);
 		close();
 		break;
 	case kQuitCmd:
-		//g_system->getEventManager()->setQuit();
-		_engine->_quit = true;
+		g_system->getEventManager()->pushEvent(Common::EVENT_QUIT);
 		close();
 		break;
 	default:


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