[Scummvm-cvs-logs] SF.net SVN: scummvm: [29709] scummvm/trunk/engines/lure

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Mon Dec 3 13:26:45 CET 2007


Revision: 29709
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29709&view=rev
Author:   dreammaster
Date:     2007-12-03 04:26:45 -0800 (Mon, 03 Dec 2007)

Log Message:
-----------
Reworked the fight loop and event handling so fights run at the same speed as in the original game

Modified Paths:
--------------
    scummvm/trunk/engines/lure/fights.cpp
    scummvm/trunk/engines/lure/fights.h

Modified: scummvm/trunk/engines/lure/fights.cpp
===================================================================
--- scummvm/trunk/engines/lure/fights.cpp	2007-12-02 23:08:29 UTC (rev 29708)
+++ scummvm/trunk/engines/lure/fights.cpp	2007-12-03 12:26:45 UTC (rev 29709)
@@ -44,6 +44,7 @@
 	int_fights = this;
 	_fightData = NULL;
 	_mouseFlags = 0;
+	_keyDown = KS_UP;
 	reset();
 }
 
@@ -110,22 +111,28 @@
 void FightsManager::fightLoop() {
 	Resources &res = Resources::getReference();
 	Game &game = Game::getReference();
+	Room &room = Room::getReference();
 	Events &events = Events::getReference();
 	FighterRecord &playerFight = getDetails(PLAYER_ID);
+	uint32 timerVal = g_system->getMillis();
 
 	// Loop for the duration of the battle
 	while (!events.quitFlag && (playerFight.fwhits != GENERAL_MAGIC_ID)) {
 		checkEvents();
-		
-		Game::getReference().tick();
-		Room::getReference().update();
-		res.delayList().tick();
+
+		if (g_system->getMillis() > timerVal + GAME_FRAME_DELAY) {
+			timerVal = g_system->getMillis();
+
+			game.tick();
+			room.update();
+			res.delayList().tick();
+		}
+
 		Screen::getReference().update();
-
 		if (game.debugger().isAttached())
 			game.debugger().onFrame();
 
-		g_system->delayMillis(20);		
+		g_system->delayMillis(10);		
 	}
 }
 
@@ -180,59 +187,67 @@
 void FightsManager::checkEvents() {
 	Game &game = Game::getReference();
 	Events &events = Events::getReference();
-	if (!events.pollEvent()) return;
+	Mouse &mouse = Mouse::getReference();
 	FighterRecord &rec = getDetails(PLAYER_ID);
 	Hotspot *player = Resources::getReference().getActiveHotspot(PLAYER_ID);
-	Mouse &mouse = Mouse::getReference();
-
 	int moveNumber = 0;
 
-	if (events.type() == Common::EVENT_KEYDOWN) {
-		switch (events.event().kbd.keycode) {
-		case Common::KEYCODE_ESCAPE:
-			events.quitFlag = true;
-			break;
+	while ((moveNumber == 0) && events.pollEvent()) {
 
-		case Common::KEYCODE_d:
-			if (events.event().kbd.flags == Common::KBD_CTRL)
-				// Activate the debugger
-				game.debugger().attach();
-			break;
+		if (events.type() == Common::EVENT_KEYDOWN) {
+			switch (events.event().kbd.keycode) {
+			case Common::KEYCODE_ESCAPE:
+				events.quitFlag = true;
+				return;
 
-		default:
-			// Scan through the mapping list for a move for the keypress
-			const KeyMapping *keyPtr = &keyList[0];
-			while ((keyPtr->keycode != Common::KEYCODE_INVALID) &&
-				(keyPtr->keycode != events.event().kbd.keycode))
-				++keyPtr;
-			if (keyPtr->keycode != Common::KEYCODE_INVALID)
-				moveNumber = keyPtr->moveNumber;
+			case Common::KEYCODE_d:
+				if (events.event().kbd.flags == Common::KBD_CTRL) {
+					// Activate the debugger
+					game.debugger().attach();
+					return;
+				}
+				break;
+
+			default:
+				// Scan through the mapping list for a move for the keypress
+				const KeyMapping *keyPtr = &keyList[0];
+				while ((keyPtr->keycode != Common::KEYCODE_INVALID) &&
+					(keyPtr->keycode != events.event().kbd.keycode))
+					++keyPtr;
+				if (keyPtr->keycode != Common::KEYCODE_INVALID) {
+					moveNumber = keyPtr->moveNumber;
+					_keyDown = KS_KEYDOWN_1;
+				}
+			}
+
+		} else if (events.type() == Common::EVENT_KEYUP) {
+			_keyDown = KS_UP;
+
+		} else if (events.type() == Common::EVENT_MOUSEMOVE) {
+			Point mPos = events.event().mouse;
+			if (mPos.x < rec.fwtrue_x - 12) 
+				mouse.setCursorNum(CURSOR_LEFT_ARROW);
+			else if (mPos.x > rec.fwtrue_x + player->width())
+				mouse.setCursorNum(CURSOR_RIGHT_ARROW);
+			else if (mPos.y < player->y() + 4)
+				mouse.setCursorNum(CURSOR_FIGHT_UPPER);
+			else if (mPos.y < player->y() + 38)
+				mouse.setCursorNum(CURSOR_FIGHT_MIDDLE);
+			else 
+				mouse.setCursorNum(CURSOR_FIGHT_LOWER);
+		
+		} else if ((events.type() == Common::EVENT_LBUTTONDOWN) ||
+				(events.type() == Common::EVENT_RBUTTONDOWN) ||
+				(events.type() == Common::EVENT_LBUTTONUP) ||
+				(events.type() == Common::EVENT_RBUTTONUP)) {
+			_mouseFlags = 0;
+			if (events.type() == Common::EVENT_LBUTTONDOWN) ++_mouseFlags;
+			if (events.type() == Common::EVENT_RBUTTONDOWN) _mouseFlags += 2;
 		}
 	}
 
-	if (events.type() == Common::EVENT_MOUSEMOVE) {
-		Point mPos = events.event().mouse;
-		if (mPos.x < rec.fwtrue_x - 12) 
-			mouse.setCursorNum(CURSOR_LEFT_ARROW);
-		else if (mPos.x > rec.fwtrue_x + player->width())
-			mouse.setCursorNum(CURSOR_RIGHT_ARROW);
-		else if (mPos.y < player->y() + 4)
-			mouse.setCursorNum(CURSOR_FIGHT_UPPER);
-		else if (mPos.y < player->y() + 38)
-			mouse.setCursorNum(CURSOR_FIGHT_MIDDLE);
-		else 
-			mouse.setCursorNum(CURSOR_FIGHT_LOWER);
-	}
+	if (_keyDown == KS_KEYDOWN_2) return;
 
-	if ((events.type() == Common::EVENT_LBUTTONDOWN) ||
-		(events.type() == Common::EVENT_RBUTTONDOWN) ||
-		(events.type() == Common::EVENT_LBUTTONUP) ||
-		(events.type() == Common::EVENT_RBUTTONUP)) {
-		_mouseFlags = 0;
-		if (events.type() == Common::EVENT_LBUTTONDOWN) ++_mouseFlags;
-		if (events.type() == Common::EVENT_RBUTTONDOWN) _mouseFlags += 2;
-	}
-
 	// Get the correct base index for the move
 	while ((moveNumber < 5) && (moveList[moveNumber] != mouse.getCursorNum()))
 		++moveNumber;
@@ -247,6 +262,9 @@
 
 	rec.fwmove_number = moveNumber;
 
+	if (_keyDown == KS_KEYDOWN_1) 
+		_keyDown = KS_KEYDOWN_2;
+
 	if (rec.fwmove_number >= 5)
 		debugC(ERROR_INTERMEDIATE, kLureDebugFights, 
 			"Player fight move number=%d", rec.fwmove_number);

Modified: scummvm/trunk/engines/lure/fights.h
===================================================================
--- scummvm/trunk/engines/lure/fights.h	2007-12-02 23:08:29 UTC (rev 29708)
+++ scummvm/trunk/engines/lure/fights.h	2007-12-03 12:26:45 UTC (rev 29709)
@@ -62,11 +62,14 @@
 
 #define FIGHT_DISTANCE 32
 
+enum KeyStatus {KS_UP, KS_KEYDOWN_1, KS_KEYDOWN_2};
+
 class FightsManager {
 private:
 	MemoryBlock *_fightData;
 	Common::RandomSource _rnd;
 	uint8 _mouseFlags;
+	KeyStatus _keyDown;
 	FighterRecord _fighterList[3];
 
 	FighterRecord &getDetails(uint16 hotspotId);


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