diff options
author | D G Turner | 2014-05-17 15:07:51 +0100 |
---|---|---|
committer | D G Turner | 2014-05-17 15:09:46 +0100 |
commit | 2126bef17a174a1544225be89c9d56053622a107 (patch) | |
tree | f71b8fc76360525c9b2a862df6e21e8ce4bd2207 /engines/hopkins | |
parent | 16152cf1ea7807546cc40c8ba094ce874e2f877a (diff) | |
download | scummvm-rg350-2126bef17a174a1544225be89c9d56053622a107.tar.gz scummvm-rg350-2126bef17a174a1544225be89c9d56053622a107.tar.bz2 scummvm-rg350-2126bef17a174a1544225be89c9d56053622a107.zip |
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.
Diffstat (limited to 'engines/hopkins')
-rw-r--r-- | engines/hopkins/computer.cpp | 38 | ||||
-rw-r--r-- | engines/hopkins/computer.h | 26 |
2 files changed, 32 insertions, 32 deletions
diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp index 4f8e373899..dafff15d74 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 e8857a234b..ba50dca4cf 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(); |