[Scummvm-cvs-logs] scummvm master -> e37affcf4a571e68dd5930ee59e13def23e76760

Strangerke Strangerke at scummvm.org
Sun May 25 23:31:59 CEST 2014


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f01a402694 TOUCHE: Reduce the scope of a variable
e37affcf4a TOUCHE: Move some enums and struct definition to header file, get rid of some void* parameters


Commit: f01a402694dcd6934b4dee3b936f1b9dd1d2978b
    https://github.com/scummvm/scummvm/commit/f01a402694dcd6934b4dee3b936f1b9dd1d2978b
Author: Strangerke (strangerke at scummvm.org)
Date: 2014-05-25T23:29:03+02:00

Commit Message:
TOUCHE: Reduce the scope of a variable

Changed paths:
    engines/touche/touche.cpp



diff --git a/engines/touche/touche.cpp b/engines/touche/touche.cpp
index 7b70b4a..ff4f41f 100644
--- a/engines/touche/touche.cpp
+++ b/engines/touche/touche.cpp
@@ -3114,12 +3114,12 @@ void ToucheEngine::buildWalkPath(int dstPosX, int dstPosY, int keyChar) {
 	for (uint i = 0; i < _programWalkTable.size(); ++i) {
 		const ProgramWalkData *pwd = &_programWalkTable[i];
 		if ((pwd->point1 & 0x4000) == 0) {
-			int distance = 32000;
 			ProgramPointData *pts1 = &_programPointsTable[pwd->point1];
 			ProgramPointData *pts2 = &_programPointsTable[pwd->point2];
 			if (pts1->order != 0) {
 				int dx = pts2->x - pts1->x;
 				int dy = pts2->y - pts1->y;
+				int distance = 32000;
 				if (dx == 0) {
 					if (dstPosY > MIN(pts2->y, pts1->y) && dstPosY < MAX(pts2->y, pts1->y)) {
 						int d = ABS(dstPosX - pts1->x);


Commit: e37affcf4a571e68dd5930ee59e13def23e76760
    https://github.com/scummvm/scummvm/commit/e37affcf4a571e68dd5930ee59e13def23e76760
Author: Strangerke (strangerke at scummvm.org)
Date: 2014-05-25T23:30:22+02:00

Commit Message:
TOUCHE: Move some enums and struct definition to header file, get rid of some void* parameters

Changed paths:
    engines/touche/menu.cpp
    engines/touche/touche.h



diff --git a/engines/touche/menu.cpp b/engines/touche/menu.cpp
index 19c10af..b94776e 100644
--- a/engines/touche/menu.cpp
+++ b/engines/touche/menu.cpp
@@ -31,96 +31,6 @@
 
 namespace Touche {
 
-enum ActionId {
-	kActionNone,
-
-	// settings menu
-	kActionLoadMenu,
-	kActionSaveMenu,
-	kActionRestartGame,
-	kActionPlayGame,
-	kActionQuitGame,
-	kActionTextOnly,
-	kActionVoiceOnly,
-	kActionTextAndVoice,
-	kActionLowerVolume,
-	kActionUpperVolume,
-
-	// saveLoad menu
-	kActionGameState1,
-	kActionGameState2,
-	kActionGameState3,
-	kActionGameState4,
-	kActionGameState5,
-	kActionGameState6,
-	kActionGameState7,
-	kActionGameState8,
-	kActionGameState9,
-	kActionGameState10,
-	kActionScrollUpSaves,
-	kActionScrollDownSaves,
-	kActionPerformSaveLoad,
-	kActionCancelSaveLoad
-};
-
-enum MenuMode {
-	kMenuSettingsMode = 0,
-	kMenuLoadStateMode,
-	kMenuSaveStateMode
-};
-
-enum ButtonFlags {
-	kButtonBorder = 1 << 0,
-	kButtonText   = 1 << 1,
-	kButtonArrow  = 1 << 2
-};
-
-struct Button {
-	int x, y;
-	int w, h;
-	ActionId action;
-	int data;
-	uint8 flags;
-};
-
-struct MenuData {
-	MenuMode mode;
-	Button *buttonsTable;
-	uint buttonsCount;
-	bool quit;
-	bool exit;
-	char saveLoadDescriptionsTable[kMaxSaveStates][33];
-
-	void removeLastCharFromDescription(int slot) {
-		char *description = saveLoadDescriptionsTable[slot];
-		int descriptionLen = strlen(description);
-		if (descriptionLen > 0) {
-			--descriptionLen;
-			description[descriptionLen] = 0;
-		}
-	}
-
-	void addCharToDescription(int slot, char chr) {
-		char *description = saveLoadDescriptionsTable[slot];
-		int descriptionLen = strlen(description);
-		if (descriptionLen < 32 && Common::isPrint(chr)) {
-			description[descriptionLen] = chr;
-			description[descriptionLen + 1] = 0;
-		}
-	}
-
-	const Button *findButtonUnderCursor(int cursorX, int cursorY) const {
-		for (uint i = 0; i < buttonsCount; ++i) {
-			const Button *button = &buttonsTable[i];
-			if (cursorX >= button->x && cursorX < button->x + button->w &&
-				cursorY >= button->y && cursorY < button->y + button->h) {
-				return button;
-			}
-		}
-		return 0;
-	}
-};
-
 static void drawArrow(uint8 *dst, int dstPitch, int x, int y, int delta, uint8 color) {
 	static const int8 arrowCoordsTable[7][4] = {
 		{  5,  0,  9,  0 },
@@ -140,25 +50,24 @@ static void drawArrow(uint8 *dst, int dstPitch, int x, int y, int delta, uint8 c
 	}
 }
 
-void ToucheEngine::drawButton(void *button) {
-	Button *b = (Button *)button;
-	if (b->flags & kButtonBorder) {
-		Graphics::drawRect(_offscreenBuffer, kScreenWidth, b->x, b->y, b->w, b->h, 0xF7, 0xF9);
+void ToucheEngine::drawButton(Button *button) {
+	if (button->flags & kButtonBorder) {
+		Graphics::drawRect(_offscreenBuffer, kScreenWidth, button->x, button->y, button->w, button->h, 0xF7, 0xF9);
 	}
-	if (b->flags & kButtonText) {
-		if (b->data != 0) {
-			const char *str = getString(b->data);
-			const int w = getStringWidth(b->data);
+	if (button->flags & kButtonText) {
+		if (button->data != 0) {
+			const char *str = getString(button->data);
+			const int w = getStringWidth(button->data);
 			const int h = kTextHeight;
-			const int x = b->x + (b->w - w) / 2;
-			const int y = b->y + (b->h - h) / 2;
+			const int x = button->x + (button->w - w) / 2;
+			const int y = button->y + (button->h - h) / 2;
 			Graphics::drawString16(_offscreenBuffer, kScreenWidth, 0xFF, x, y, str);
 		}
 	}
-	if (b->flags & kButtonArrow) {
+	if (button->flags & kButtonArrow) {
 		int dx = 0;
 		int dy = 0;
-		switch (b->data) {
+		switch (button->data) {
 		case 2000: // up arrow
 			dx = 1;
 			dy = 2;
@@ -168,8 +77,8 @@ void ToucheEngine::drawButton(void *button) {
 			dy = -2;
 			break;
 		}
-		const int x = b->x + b->w / 2;
-		const int y = b->y + b->h / 2;
+		const int x = button->x + button->w / 2;
+		const int y = button->y + button->h / 2;
 		drawArrow(_offscreenBuffer, kScreenWidth, x, y + dy + 1, dx, 0xD2);
 		drawArrow(_offscreenBuffer, kScreenWidth, x, y + dy,     dx, 0xFF);
 	}
@@ -253,49 +162,47 @@ static void setupMenu(MenuMode mode, MenuData *menuData) {
 	}
 }
 
-void ToucheEngine::redrawMenu(void *menu) {
-	MenuData *menuData = (MenuData *)menu;
+void ToucheEngine::redrawMenu(MenuData *menu) {
 	Graphics::fillRect(_offscreenBuffer, kScreenWidth, 90, 102, 460, 196, 0xF8);
 	Graphics::drawRect(_offscreenBuffer, kScreenWidth, 90, 102, 460, 196, 0xF7, 0xF9);
 	Graphics::drawRect(_offscreenBuffer, kScreenWidth, 106, 118, 340, 164, 0xF9, 0xF7);
-	switch (menuData->mode) {
+	switch (menu->mode) {
 	case kMenuSettingsMode:
 		drawVolumeSlideBar(_offscreenBuffer, kScreenWidth, getMusicVolume());
-		menuData->buttonsTable[5].data = 0;
-		menuData->buttonsTable[6].data = 0;
-		menuData->buttonsTable[7].data = 0;
-		menuData->buttonsTable[5 + _talkTextMode].data = -86;
+		menu->buttonsTable[5].data = 0;
+		menu->buttonsTable[6].data = 0;
+		menu->buttonsTable[7].data = 0;
+		menu->buttonsTable[5 + _talkTextMode].data = -86;
 		break;
 	case kMenuLoadStateMode:
 	case kMenuSaveStateMode:
-		drawSaveGameStateDescriptions(_offscreenBuffer, kScreenWidth, menuData, _saveLoadCurrentPage, _saveLoadCurrentSlot);
+		drawSaveGameStateDescriptions(_offscreenBuffer, kScreenWidth, menu, _saveLoadCurrentPage, _saveLoadCurrentSlot);
 		break;
 	}
-	for (uint i = 0; i < menuData->buttonsCount; ++i) {
-		drawButton(&menuData->buttonsTable[i]);
+	for (uint i = 0; i < menu->buttonsCount; ++i) {
+		drawButton(&menu->buttonsTable[i]);
 	}
 }
 
-void ToucheEngine::handleMenuAction(void *menu, int actionId) {
-	MenuData *menuData = (MenuData *)menu;
+void ToucheEngine::handleMenuAction(MenuData *menu, int actionId) {
 	switch (actionId) {
 	case kActionLoadMenu:
-		menuData->mode = kMenuLoadStateMode;
+		menu->mode = kMenuLoadStateMode;
 		break;
 	case kActionSaveMenu:
 		_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
-		menuData->mode = kMenuSaveStateMode;
+		menu->mode = kMenuSaveStateMode;
 		break;
 	case kActionRestartGame:
 		restart();
-		menuData->quit = true;
+		menu->quit = true;
 		break;
 	case kActionPlayGame:
-		menuData->quit = true;
+		menu->quit = true;
 		break;
 	case kActionQuitGame:
 		quitGame();
-		menuData->quit = true;
+		menu->quit = true;
 		break;
 	case kActionTextOnly:
 		_talkTextMode = kTalkModeTextOnly;
@@ -327,23 +234,23 @@ void ToucheEngine::handleMenuAction(void *menu, int actionId) {
 		_saveLoadCurrentSlot = _saveLoadCurrentPage * 10 + (_saveLoadCurrentSlot % 10);
 		break;
 	case kActionPerformSaveLoad:
-		if (menuData->mode == kMenuLoadStateMode) {
+		if (menu->mode == kMenuLoadStateMode) {
 			if (loadGameState(_saveLoadCurrentSlot).getCode() == Common::kNoError) {
-				menuData->quit = true;
+				menu->quit = true;
 			}
-		} else if (menuData->mode == kMenuSaveStateMode) {
+		} else if (menu->mode == kMenuSaveStateMode) {
 			_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
-			const char *description = menuData->saveLoadDescriptionsTable[_saveLoadCurrentSlot];
+			const char *description = menu->saveLoadDescriptionsTable[_saveLoadCurrentSlot];
 			if (strlen(description) > 0) {
 				if (saveGameState(_saveLoadCurrentSlot, description).getCode() == Common::kNoError) {
-					menuData->quit = true;
+					menu->quit = true;
 				}
 			}
 		}
 		break;
 	case kActionCancelSaveLoad:
 		_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
-		menuData->mode = kMenuSettingsMode;
+		menu->mode = kMenuSettingsMode;
 		break;
 	default:
 		if (actionId >= kActionGameState1 && actionId <= kActionGameState10) {
diff --git a/engines/touche/touche.h b/engines/touche/touche.h
index ee6dffe..20bf723 100644
--- a/engines/touche/touche.h
+++ b/engines/touche/touche.h
@@ -346,10 +346,6 @@ enum StringType {
 	kStringTypeConversation
 };
 
-void readGameStateDescription(Common::ReadStream *f, char *description, int len);
-Common::String generateGameStateFileName(const char *target, int slot, bool prefixOnly = false);
-int getGameStateFileSlot(const char *filename);
-
 enum GameState {
 	kGameStateGameLoop,
 	kGameStateOptionsDialog,
@@ -357,6 +353,101 @@ enum GameState {
 	kGameStateNone
 };
 
+enum ActionId {
+	kActionNone,
+
+	// settings menu
+	kActionLoadMenu,
+	kActionSaveMenu,
+	kActionRestartGame,
+	kActionPlayGame,
+	kActionQuitGame,
+	kActionTextOnly,
+	kActionVoiceOnly,
+	kActionTextAndVoice,
+	kActionLowerVolume,
+	kActionUpperVolume,
+
+	// saveLoad menu
+	kActionGameState1,
+	kActionGameState2,
+	kActionGameState3,
+	kActionGameState4,
+	kActionGameState5,
+	kActionGameState6,
+	kActionGameState7,
+	kActionGameState8,
+	kActionGameState9,
+	kActionGameState10,
+	kActionScrollUpSaves,
+	kActionScrollDownSaves,
+	kActionPerformSaveLoad,
+	kActionCancelSaveLoad
+};
+
+enum MenuMode {
+	kMenuSettingsMode = 0,
+	kMenuLoadStateMode,
+	kMenuSaveStateMode
+};
+
+enum ButtonFlags {
+	kButtonBorder = 1 << 0,
+	kButtonText   = 1 << 1,
+	kButtonArrow  = 1 << 2
+};
+
+struct Button {
+	int x, y;
+	int w, h;
+	ActionId action;
+	int data;
+	uint8 flags;
+};
+
+struct MenuData {
+	MenuMode mode;
+	Button *buttonsTable;
+	uint buttonsCount;
+	bool quit;
+	bool exit;
+	char saveLoadDescriptionsTable[kMaxSaveStates][33];
+
+	void removeLastCharFromDescription(int slot) {
+		char *description = saveLoadDescriptionsTable[slot];
+		int descriptionLen = strlen(description);
+		if (descriptionLen > 0) {
+			--descriptionLen;
+			description[descriptionLen] = 0;
+		}
+	}
+
+	void addCharToDescription(int slot, char chr) {
+		char *description = saveLoadDescriptionsTable[slot];
+		int descriptionLen = strlen(description);
+		if (descriptionLen < 32 && Common::isPrint(chr)) {
+			description[descriptionLen] = chr;
+			description[descriptionLen + 1] = 0;
+		}
+	}
+
+	const Button *findButtonUnderCursor(int cursorX, int cursorY) const {
+		for (uint i = 0; i < buttonsCount; ++i) {
+			const Button *button = &buttonsTable[i];
+			if (cursorX >= button->x && cursorX < button->x + button->w &&
+				cursorY >= button->y && cursorY < button->y + button->h) {
+					return button;
+			}
+		}
+		return 0;
+	}
+};
+
+
+void readGameStateDescription(Common::ReadStream *f, char *description, int len);
+Common::String generateGameStateFileName(const char *target, int slot, bool prefixOnly = false);
+int getGameStateFileSlot(const char *filename);
+
 class MidiPlayer;
 
 class ToucheEngine: public Engine {
@@ -632,9 +723,9 @@ protected:
 	void res_loadSpeechSegment(int num);
 	void res_stopSpeech();
 
-	void drawButton(void *button);
-	void redrawMenu(void *menu);
-	void handleMenuAction(void *menu, int actionId);
+	void drawButton(Button *button);
+	void redrawMenu(MenuData *menu);
+	void handleMenuAction(MenuData *menu, int actionId);
 	void handleOptions(int forceDisplay);
 	void drawActionsPanel(int dstX, int dstY, int deltaX, int deltaY);
 	void drawConversationPanelBorder(int dstY, int srcX, int srcY);






More information about the Scummvm-git-logs mailing list