[Scummvm-cvs-logs] scummvm master -> 2126bef17a174a1544225be89c9d56053622a107
digitall
dgturner at iee.org
Sat May 17 16:06:58 CEST 2014
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
2126bef17a HOPKINS: Further cleanup in ComputerManager class.
Commit: 2126bef17a174a1544225be89c9d56053622a107
https://github.com/scummvm/scummvm/commit/2126bef17a174a1544225be89c9d56053622a107
Author: D G Turner (digitall at scummvm.org)
Date: 2014-05-17T15:09:46+01:00
Commit Message:
HOPKINS: Further cleanup in ComputerManager class.
Have simplified the parsing of the COMPUTAN.TXT file prior to looking at
supporting the Polish file format variant.
These change should have no functional difference, but improve the code
by removing a set-but-unused bool in the MenuItem structure, fixing a
number of repeated "magic" values to be explicit as various buffer sizes
and replacing usage of strcpy with the safer version from our Common
code etc.
Changed paths:
engines/hopkins/computer.cpp
engines/hopkins/computer.h
diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp
index 4f8e373..dafff15 100644
--- a/engines/hopkins/computer.cpp
+++ b/engines/hopkins/computer.cpp
@@ -38,10 +38,9 @@ namespace Hopkins {
ComputerManager::ComputerManager(HopkinsEngine *vm) {
_vm = vm;
- for (int i = 0; i < 50; i++) {
- _menuText[i]._actvFl = false;
+ for (int i = 0; i < ARRAYSIZE(_menuText); i++) {
_menuText[i]._lineSize = 0;
- memset(_menuText[i]._line, 0, 90);
+ memset(_menuText[i]._line, 0, ARRAYSIZE(_menuText[0]._line));
}
Common::fill(&_inputBuf[0], &_inputBuf[200], '\0');
_breakoutSpr = NULL;
@@ -353,46 +352,47 @@ void ComputerManager::loadMenu() {
switch (_vm->_globals->_language) {
case LANG_FR:
ptr = (char *)_vm->_globals->allocMemory(sizeof(_frenchText));
- strcpy(ptr, _frenchText);
+ Common::strlcpy(ptr, _frenchText, sizeof(_frenchText));
break;
case LANG_SP:
ptr = (char *)_vm->_globals->allocMemory(sizeof(_spanishText));
- strcpy(ptr, _spanishText);
+ Common::strlcpy(ptr, _spanishText, sizeof(_spanishText));
break;
default:
ptr = (char *)_vm->_globals->allocMemory(sizeof(_englishText));
- strcpy(ptr, _englishText);
+ Common::strlcpy(ptr, _englishText, sizeof(_englishText));
break;
}
}
char *tmpPtr = ptr;
int lineNum = 0;
- int strPos;
- bool loopCond = false;
- do {
+ while (tmpPtr[0] != '\0' && lineNum < ARRAYSIZE(_menuText)) {
+ if (tmpPtr[0] == '%' && tmpPtr[1] == '%') {
+ // End of file marker found - Break out of parse loop
+ break;
+ }
+
if (tmpPtr[0] == '%') {
- if (tmpPtr[1] == '%') {
- loopCond = true;
- break;
- }
- _menuText[lineNum]._actvFl = 1;
- strPos = 0;
- while (strPos <= 89) {
+ int strPos = 0;
+ while (strPos < ARRAYSIZE(_menuText[0]._line)) {
char curChar = tmpPtr[strPos + 2];
- if (curChar == '%' || curChar == 10)
+ if (curChar == '\0' || curChar == '%' || curChar == 0x0a) // Line Feed
break;
_menuText[lineNum]._line[strPos++] = curChar;
}
- if (strPos <= 89) {
+
+ if (strPos < ARRAYSIZE(_menuText[0]._line)) {
_menuText[lineNum]._line[strPos] = 0;
_menuText[lineNum]._lineSize = strPos - 1;
}
+
++lineNum;
}
++tmpPtr;
- } while (!loopCond && tmpPtr[0] != '\0' && lineNum < 50);
+ }
+
_vm->_globals->freeMemory((byte *)ptr);
}
diff --git a/engines/hopkins/computer.h b/engines/hopkins/computer.h
index e8857a2..ba50dca 100644
--- a/engines/hopkins/computer.h
+++ b/engines/hopkins/computer.h
@@ -31,22 +31,22 @@ namespace Hopkins {
class HopkinsEngine;
-struct MenuItem {
- bool _actvFl;
- int _lineSize;
- char _line[90];
-};
-
-struct ScoreItem {
- Common::String _name;
- Common::String _score;
-};
-
enum ComputerEnum { COMPUTER_HOPKINS = 1, COMPUTER_SAMANTHA = 2, COMPUTER_PUBLIC = 3 };
class ComputerManager {
private:
HopkinsEngine *_vm;
+
+ struct MenuItem {
+ int _lineSize;
+ char _line[90];
+ };
+
+ struct ScoreItem {
+ Common::String _name;
+ Common::String _score;
+ };
+
MenuItem _menuText[50];
char _inputBuf[200];
ScoreItem _score[6];
@@ -84,14 +84,14 @@ private:
void displayLives();
void displayBricks();
void displayGamesSubMenu();
- int displayHiscores();
+ int displayHiscores();
void displayHiscoreLine(const byte *objectData, int x, int y, int curChar);
void displayMessage(int xp, int yp, int textIdx);
void displayScore();
void displayScoreChar(int charPos, int charDisp);
void getScoreName();
void playBreakout();
- int moveBall();
+ int moveBall();
void saveScore();
void checkBallCollisions();
More information about the Scummvm-git-logs
mailing list