aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Boutonné2011-02-03 18:25:38 +0000
committerArnaud Boutonné2011-02-03 18:25:38 +0000
commit935b3187982afb8a8c1aebded8b5ddc607e27f0f (patch)
tree96e092ef06cb439f25db0b91ab43be653c8756a6
parent38444a3712543f60f5daf8106ef3b2d66c6f9ab9 (diff)
downloadscummvm-rg350-935b3187982afb8a8c1aebded8b5ddc607e27f0f.tar.gz
scummvm-rg350-935b3187982afb8a8c1aebded8b5ddc607e27f0f.tar.bz2
scummvm-rg350-935b3187982afb8a8c1aebded8b5ddc607e27f0f.zip
HUGO: Suppress static variables (except one)
This also fixes the multiple-RTL related music bug reported by D. Gray svn-id: r55758
-rw-r--r--engines/hugo/display.cpp52
-rw-r--r--engines/hugo/display.h25
-rw-r--r--engines/hugo/file.cpp24
-rw-r--r--engines/hugo/file.h35
-rw-r--r--engines/hugo/file_v2d.cpp11
-rw-r--r--engines/hugo/hugo.cpp14
-rw-r--r--engines/hugo/hugo.h13
-rw-r--r--engines/hugo/intro.cpp4
-rw-r--r--engines/hugo/intro.h2
-rw-r--r--engines/hugo/inventory.cpp15
-rw-r--r--engines/hugo/inventory.h2
-rw-r--r--engines/hugo/object_v1d.cpp16
-rw-r--r--engines/hugo/parser.cpp36
-rw-r--r--engines/hugo/parser.h5
-rw-r--r--engines/hugo/route.cpp10
-rw-r--r--engines/hugo/route.h2
-rw-r--r--engines/hugo/schedule.cpp28
-rw-r--r--engines/hugo/schedule.h20
-rw-r--r--engines/hugo/sound.cpp20
-rw-r--r--engines/hugo/sound.h7
20 files changed, 194 insertions, 147 deletions
diff --git a/engines/hugo/display.cpp b/engines/hugo/display.cpp
index 1d960c6945..3ae0e8373f 100644
--- a/engines/hugo/display.cpp
+++ b/engines/hugo/display.cpp
@@ -42,11 +42,31 @@
#include "hugo/object.h"
namespace Hugo {
-Screen::Screen(HugoEngine *vm) : _vm(vm), _mainPalette(0), _curPalette(0) {
+Screen::Screen(HugoEngine *vm) : _vm(vm) {
+ _mainPalette = 0;
+ _curPalette = 0;
for (int i = 0; i < kNumFonts; i++) {
_arrayFont[i] = 0;
fontLoadedFl[i] = false;
}
+ for (int i = 0; i < kBlitListSize; i++) {
+ _dlBlistList[i].x = 0;
+ _dlBlistList[i].y = 0;
+ _dlBlistList[i].dx = 0;
+ _dlBlistList[i].dy = 0;
+ }
+ for (int i = 0; i < kRectListSize; i++) {
+ _dlRestoreList[i].x = 0;
+ _dlRestoreList[i].y = 0;
+ _dlRestoreList[i].dx = 0;
+ _dlRestoreList[i].dy = 0;
+ }
+ for (int i = 0; i < kRectListSize; i++) {
+ _dlAddList[i].x = 0;
+ _dlAddList[i].y = 0;
+ _dlAddList[i].dx = 0;
+ _dlAddList[i].dy = 0;
+ }
}
Screen::~Screen() {
@@ -58,7 +78,7 @@ Screen::~Screen() {
void Screen::createPal() {
debugC(1, kDebugDisplay, "createPal");
- g_system->setPalette(_mainPalette, 0, kNumColors);
+ g_system->setPalette(_mainPalette, 0, _paletteSize / 4);
}
void Screen::setCursorPal() {
@@ -290,32 +310,28 @@ int16 Screen::mergeLists(rect_t *list, rect_t *blist, const int16 len, int16 ble
void Screen::displayList(dupdate_t update, ...) {
debugC(6, kDebugDisplay, "displayList()");
- static int16 addIndex, restoreIndex; // Index into add/restore lists
- static rect_t restoreList[kRectListSize]; // The restore list
- static rect_t addList[kRectListSize]; // The add list
- static rect_t blistList[kBlitListSize]; // The blit list
int16 blitLength = 0; // Length of blit list
va_list marker; // Args used for D_ADD operation
rect_t *p; // Ptr to dlist entry
switch (update) {
case kDisplayInit: // Init lists, restore whole screen
- addIndex = restoreIndex = 0;
+ _dlAddIndex = _dlRestoreIndex = 0;
memcpy(_frontBuffer, _backBuffer, sizeof(_frontBuffer));
break;
case kDisplayAdd: // Add a rectangle to list
- if (addIndex >= kRectListSize) {
+ if (_dlAddIndex >= kRectListSize) {
warning("Display list exceeded");
return;
}
va_start(marker, update); // Initialize variable arguments
- p = &addList[addIndex];
+ p = &_dlAddList[_dlAddIndex];
p->x = va_arg(marker, int); // x
p->y = va_arg(marker, int); // y
p->dx = va_arg(marker, int); // dx
p->dy = va_arg(marker, int); // dy
va_end(marker); // Reset variable arguments
- addIndex++;
+ _dlAddIndex++;
break;
case kDisplayDisplay: // Display whole list
// Don't blit if newscreen just loaded because _frontBuffer will
@@ -327,22 +343,22 @@ void Screen::displayList(dupdate_t update, ...) {
}
// Coalesce restore-list, add-list into combined blit-list
- blitLength = mergeLists(restoreList, blistList, restoreIndex, blitLength);
- blitLength = mergeLists(addList, blistList, addIndex, blitLength);
+ blitLength = mergeLists(_dlRestoreList, _dlBlistList, _dlRestoreIndex, blitLength);
+ blitLength = mergeLists(_dlAddList, _dlBlistList, _dlAddIndex, blitLength);
// Blit the combined blit-list
- for (restoreIndex = 0, p = blistList; restoreIndex < blitLength; restoreIndex++, p++) {
+ for (_dlRestoreIndex = 0, p = _dlBlistList; _dlRestoreIndex < blitLength; _dlRestoreIndex++, p++) {
if (p->dx) // Marks a used entry
displayRect(p->x, p->y, p->dx, p->dy);
}
break;
case kDisplayRestore: // Restore each rectangle
- for (restoreIndex = 0, p = addList; restoreIndex < addIndex; restoreIndex++, p++) {
+ for (_dlRestoreIndex = 0, p = _dlAddList; _dlRestoreIndex < _dlAddIndex; _dlRestoreIndex++, p++) {
// Restoring from _backBuffer to _frontBuffer
- restoreList[restoreIndex] = *p; // Copy add-list to restore-list
+ _dlRestoreList[_dlRestoreIndex] = *p; // Copy add-list to restore-list
moveImage(_backBuffer, p->x, p->y, p->dx, p->dy, kXPix, _frontBuffer, p->x, p->y, kXPix);
}
- addIndex = 0; // Reset add-list
+ _dlAddIndex = 0; // Reset add-list
break;
}
}
@@ -376,10 +392,10 @@ void Screen::writeChr(const int sx, const int sy, const byte color, const char *
/**
* Returns height of characters in current font
*/
-int16 Screen::fontHeight() {
+int16 Screen::fontHeight() const {
debugC(2, kDebugDisplay, "fontHeight()");
- static int16 height[kNumFonts] = {5, 7, 8};
+ static const int16 height[kNumFonts] = {5, 7, 8};
return height[_fnt - kFirstFont];
}
diff --git a/engines/hugo/display.h b/engines/hugo/display.h
index f3fe08f02b..019496b6e0 100644
--- a/engines/hugo/display.h
+++ b/engines/hugo/display.h
@@ -90,16 +90,16 @@ public:
virtual void loadFont(int16 fontId) = 0;
virtual void loadFontArr(Common::File &in) = 0;
- int16 fontHeight();
+ int16 fontHeight() const;
int16 stringLength(const char *s) const;
void displayBackground();
- void displayFrame(int sx, int sy, seq_t *seq, bool foreFl);
+ void displayFrame(const int sx, const int sy, seq_t *seq, const bool foreFl);
void displayList(dupdate_t update, ...);
- void displayRect(int16 x, int16 y, int16 dx, int16 dy);
+ void displayRect(const int16 x, const int16 y, const int16 dx, const int16 dy);
void drawHotspots();
- void drawRectangle(bool filledFl, int16 x1, int16 y1, int16 x2, int16 y2, int color);
- void drawShape(int x, int y, int color1, int color2);
+ void drawRectangle(const bool filledFl, const int16 x1, const int16 y1, const int16 x2, const int16 y2, const int color);
+ void drawShape(const int x, const int y, const int color1, const int color2);
void drawStatusText();
void freeFonts();
void freePalette();
@@ -107,14 +107,14 @@ public:
void initDisplay();
void initNewScreenDisplay();
void loadPalette(Common::File &in);
- void moveImage(image_pt srcImage, int16 x1, int16 y1, int16 dx, int16 dy, int16 width1, image_pt dstImage, int16 x2, int16 y2, int16 width2);
+ void moveImage(image_pt srcImage, const int16 x1, const int16 y1, const int16 dx, int16 dy, const int16 width1, image_pt dstImage, const int16 x2, const int16 y2, const int16 width2);
void remapPal(uint16 oldIndex, uint16 newIndex);
void resetInventoryObjId();
void restorePal(Common::SeekableReadStream *f);
void savePal(Common::WriteStream *f) const;
void setBackgroundColor(const uint16 color);
void setCursorPal();
- void selectInventoryObjId(int16 objId);
+ void selectInventoryObjId(const int16 objId);
void shadowStr(int16 sx, const int16 sy, const char *s, const byte color);
void showCursor();
void userHelp() const;
@@ -174,8 +174,15 @@ private:
viewdib_t _frontBuffer;
viewdib_t _backBuffer;
- viewdib_t _GUIBuffer; // User interface images
- viewdib_t _backBufferBackup; // Backup _backBuffer during inventory
+ viewdib_t _GUIBuffer; // User interface images
+ viewdib_t _backBufferBackup; // Backup _backBuffer during inventory
+
+ // Formerly static variables used by displayList()
+ int16 _dlAddIndex, _dlRestoreIndex; // Index into add/restore lists
+ rect_t _dlRestoreList[kRectListSize]; // The restore list
+ rect_t _dlAddList[kRectListSize]; // The add list
+ rect_t _dlBlistList[kBlitListSize]; // The blit list
+ //
void createPal();
void merge(const rect_t *rectA, rect_t *rectB);
diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp
index a6a3690464..b17d3c9c6a 100644
--- a/engines/hugo/file.cpp
+++ b/engines/hugo/file.cpp
@@ -46,6 +46,8 @@
namespace Hugo {
FileManager::FileManager(HugoEngine *vm) : _vm(vm) {
+ has_read_header = false;
+ firstUIFFl = true;
}
FileManager::~FileManager() {
@@ -55,7 +57,7 @@ FileManager::~FileManager() {
* Convert 4 planes (RGBI) data to 8-bit DIB format
* Return original plane data ptr
*/
-byte *FileManager::convertPCC(byte *p, const uint16 y, const uint16 bpl, image_pt dataPtr) const{
+byte *FileManager::convertPCC(byte *p, const uint16 y, const uint16 bpl, image_pt dataPtr) const {
debugC(2, kDebugFile, "convertPCC(byte *p, %d, %d, image_pt data_p)", y, bpl);
dataPtr += y * bpl * 8; // Point to correct DIB line
@@ -79,7 +81,6 @@ seq_t *FileManager::readPCX(Common::File &f, seq_t *seqPtr, byte *imagePtr, cons
debugC(1, kDebugFile, "readPCX(..., %s)", name);
// Read in the PCC header and check consistency
- static PCC_header_t PCC_header;
PCC_header.mfctr = f.readByte();
PCC_header.vers = f.readByte();
PCC_header.enc = f.readByte();
@@ -179,7 +180,7 @@ void FileManager::readImage(const int objNum, object_t *objPtr) {
}
}
- bool firstFl = true; // Initializes pcx read function
+ bool firstImgFl = true; // Initializes pcx read function
seq_t *seqPtr = 0; // Ptr to sequence structure
// Now read the images into an images list
@@ -187,12 +188,12 @@ void FileManager::readImage(const int objNum, object_t *objPtr) {
for (int k = 0; k < objPtr->seqList[j].imageNbr; k++) { // each image
if (k == 0) { // First image
// Read this image - allocate both seq and image memory
- seqPtr = readPCX(_objectsArchive, 0, 0, firstFl, _vm->_text->getNoun(objPtr->nounIndex, 0));
+ seqPtr = readPCX(_objectsArchive, 0, 0, firstImgFl, _vm->_text->getNoun(objPtr->nounIndex, 0));
objPtr->seqList[j].seqPtr = seqPtr;
- firstFl = false;
+ firstImgFl = false;
} else { // Subsequent image
// Read this image - allocate both seq and image memory
- seqPtr->nextSeqPtr = readPCX(_objectsArchive, 0, 0, firstFl, _vm->_text->getNoun(objPtr->nounIndex, 0));
+ seqPtr->nextSeqPtr = readPCX(_objectsArchive, 0, 0, firstImgFl, _vm->_text->getNoun(objPtr->nounIndex, 0));
seqPtr = seqPtr->nextSeqPtr;
}
@@ -261,10 +262,6 @@ sound_pt FileManager::getSound(const int16 sound, uint16 *size) {
return 0;
}
- // If this is the first call, read the lookup table
- static bool has_read_header = false;
- static sound_hdr_t s_hdr[kMaxSounds]; // Sound lookup table
-
if (!has_read_header) {
if (fp.read(s_hdr, sizeof(s_hdr)) != sizeof(s_hdr))
error("Wrong sound file format");
@@ -605,12 +602,9 @@ void FileManager::readBootFile() {
uif_hdr_t *FileManager::getUIFHeader(const uif_t id) {
debugC(1, kDebugFile, "getUIFHeader(%d)", id);
- static bool firstFl = true;
- static uif_hdr_t UIFHeader[kMaxUifs]; // Lookup for uif fonts/images
-
// Initialize offset lookup if not read yet
- if (firstFl) {
- firstFl = false;
+ if (firstUIFFl) {
+ firstUIFFl = false;
// Open unbuffered to do far read
Common::File ip; // Image data file
if (!ip.open(getUifFilename()))
diff --git a/engines/hugo/file.h b/engines/hugo/file.h
index a5c2254f3e..766c8d24a0 100644
--- a/engines/hugo/file.h
+++ b/engines/hugo/file.h
@@ -55,12 +55,12 @@ public:
bool saveGame(const int16 slot, const Common::String descrip);
// Name scenery and objects picture databases
- const char *getBootFilename() { return "HUGO.BSF"; }
- const char *getObjectFilename() { return "objects.dat"; }
- const char *getSceneryFilename() { return "scenery.dat"; }
- const char *getSoundFilename() { return "sounds.dat"; }
- const char *getStringFilename() { return "strings.dat"; }
- const char *getUifFilename() { return "uif.dat"; }
+ const char *getBootFilename() const { return "HUGO.BSF"; }
+ const char *getObjectFilename() const { return "objects.dat"; }
+ const char *getSceneryFilename() const { return "scenery.dat"; }
+ const char *getSoundFilename() const { return "sounds.dat"; }
+ const char *getStringFilename() const { return "strings.dat"; }
+ const char *getUifFilename() const { return "uif.dat"; }
virtual void openDatabaseFiles() = 0;
virtual void closeDatabaseFiles() = 0;
@@ -92,13 +92,34 @@ protected:
uint32 ob_len;
};
+ static const int kNumColors = 16; // Num colors to save in palette
+
+ struct PCC_header_t { // Structure of PCX file header
+ byte mfctr, vers, enc, bpx;
+ uint16 x1, y1, x2, y2; // bounding box
+ uint16 xres, yres;
+ byte palette[3 * kNumColors]; // EGA color palette
+ byte vmode, planes;
+ uint16 bytesPerLine; // Bytes per line
+ byte fill2[60];
+ }; // Header of a PCC file
+
+ bool firstUIFFl;
+ uif_hdr_t UIFHeader[kMaxUifs]; // Lookup for uif fonts/images
+
Common::File _stringArchive; // Handle for string file
Common::File _sceneryArchive1; // Handle for scenery file
Common::File _objectsArchive; // Handle for objects file
+ PCC_header_t PCC_header;
+
seq_t *readPCX(Common::File &f, seq_t *seqPtr, byte *imagePtr, const bool firstFl, const char *name);
const char *getBootCypher() const;
+ // If this is the first call, read the lookup table
+ bool has_read_header;
+ sound_hdr_t s_hdr[kMaxSounds]; // Sound lookup table
+
private:
byte *convertPCC(byte *p, const uint16 y, const uint16 bpl, image_pt dataPtr) const;
uif_hdr_t *getUIFHeader(const uif_t id);
@@ -130,6 +151,8 @@ public:
virtual void readBackground(const int screenIndex);
virtual void readOverlay(const int screenNum, image_pt image, ovl_t overlayType);
char *fetchString(const int index);
+private:
+ char *_fetchStringBuf;
};
class FileManager_v3d : public FileManager_v2d {
diff --git a/engines/hugo/file_v2d.cpp b/engines/hugo/file_v2d.cpp
index 06e4c71c28..2e3b0e2b08 100644
--- a/engines/hugo/file_v2d.cpp
+++ b/engines/hugo/file_v2d.cpp
@@ -41,9 +41,11 @@
namespace Hugo {
FileManager_v2d::FileManager_v2d(HugoEngine *vm) : FileManager_v1d(vm) {
+ _fetchStringBuf = (char *)malloc(kMaxBoxChar);
}
FileManager_v2d::~FileManager_v2d() {
+ free(_fetchStringBuf);
}
/**
@@ -163,7 +165,6 @@ void FileManager_v2d::readOverlay(const int screenNum, image_pt image, ovl_t ove
*/
char *FileManager_v2d::fetchString(const int index) {
debugC(1, kDebugFile, "fetchString(%d)", index);
- static char buffer[kMaxBoxChar];
// Get offset to string[index] (and next for length calculation)
_stringArchive.seek((uint32)index * sizeof(uint32), SEEK_SET);
@@ -179,13 +180,13 @@ char *FileManager_v2d::fetchString(const int index) {
// Position to string and read it into gen purpose _textBoxBuffer
_stringArchive.seek(off1, SEEK_SET);
- if (_stringArchive.read(buffer, (uint16)(off2 - off1)) == 0)
+ if (_stringArchive.read(_fetchStringBuf, (uint16)(off2 - off1)) == 0)
error("An error has occurred: fetchString");
// Null terminate, decode and return it
- buffer[off2-off1] = '\0';
- _vm->_scheduler->decodeString(buffer);
- return buffer;
+ _fetchStringBuf[off2-off1] = '\0';
+ _vm->_scheduler->decodeString(_fetchStringBuf);
+ return _fetchStringBuf;
}
} // End of namespace Hugo
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp
index 78d7b9a581..7014b66f87 100644
--- a/engines/hugo/hugo.cpp
+++ b/engines/hugo/hugo.cpp
@@ -62,8 +62,7 @@ HugoEngine::HugoEngine(OSystem *syst, const HugoGameDescription *gd) : Engine(sy
_arrayReqs(0), _hotspots(0), _invent(0), _uses(0), _catchallList(0), _backgroundObjects(0), _points(0), _cmdList(0),
_screenActs(0), _hero(0), _heroImage(0), _defltTunes(0), _introX(0), _introY(0), _maxInvent(0), _numBonuses(0),
_numScreens(0), _tunesNbr(0), _soundSilence(0), _soundTest(0), _screenStates(0), _score(0), _maxscore(0),
- _backgroundObjectsSize(0), _screenActsSize(0), _usesSize(0)
-
+ _backgroundObjectsSize(0), _screenActsSize(0), _usesSize(0), _lastTime(0), _curTime(0)
{
_system = syst;
DebugMan.addDebugChannel(kDebugSchedule, "Schedule", "Script Schedule debug level");
@@ -305,9 +304,6 @@ void HugoEngine::initMachine() {
* Hugo game state machine - called during onIdle
*/
void HugoEngine::runMachine() {
- static uint32 lastTime;
- uint32 curTime;
-
status_t &gameStatus = getGameStatus();
// Don't process if we're in a textbox
if (gameStatus.textBoxFl)
@@ -317,13 +313,13 @@ void HugoEngine::runMachine() {
if (gameStatus.gameOverFl)
return;
- curTime = g_system->getMillis();
+ _curTime = g_system->getMillis();
// Process machine once every tick
- while (curTime - lastTime < (uint32)(1000 / getTPS())) {
+ while (_curTime - _lastTime < (uint32)(1000 / getTPS())) {
g_system->delayMillis(5);
- curTime = g_system->getMillis();
+ _curTime = g_system->getMillis();
}
- lastTime = curTime;
+ _lastTime = _curTime;
switch (gameStatus.viewState) {
case kViewIdle: // Not processing state machine
diff --git a/engines/hugo/hugo.h b/engines/hugo/hugo.h
index 55be443199..07affc2753 100644
--- a/engines/hugo/hugo.h
+++ b/engines/hugo/hugo.h
@@ -82,21 +82,10 @@ static const int kRightArrow = -3; // Cursor over Right arrow i
static const int kMaxPath = 256; // Max length of a full path name
static const int kHeroMaxWidth = 24; // Maximum width of hero
static const int kHeroMinWidth = 16; // Minimum width of hero
-static const int kNumColors = 16; // Num colors to save in palette
typedef char fpath_t[kMaxPath]; // File path
typedef char command_t[kMaxLineSize + 8]; // Command line (+spare for prompt,cursor)
-struct PCC_header_t { // Structure of PCX file header
- byte mfctr, vers, enc, bpx;
- uint16 x1, y1, x2, y2; // bounding box
- uint16 xres, yres;
- byte palette[3 * kNumColors]; // EGA color palette
- byte vmode, planes;
- uint16 bytesPerLine; // Bytes per line
- byte fill2[60];
-}; // Header of a PCC file
-
struct config_t { // User's config (saved)
bool musicFl; // State of Music button/menu item
bool soundFl; // State of Sound button/menu item
@@ -424,6 +413,8 @@ private:
int _mouseY;
byte _introXSize;
status_t _status; // Game status structure
+ uint32 _lastTime;
+ uint32 _curTime;
static HugoEngine *s_Engine;
diff --git a/engines/hugo/intro.cpp b/engines/hugo/intro.cpp
index bc9f2d1394..3a958a2988 100644
--- a/engines/hugo/intro.cpp
+++ b/engines/hugo/intro.cpp
@@ -57,6 +57,7 @@ void intro_v1d::preNewGame() {
}
void intro_v1d::introInit() {
+ _introState = 0;
introTicks = 0;
surf.w = 320;
surf.h = 200;
@@ -66,14 +67,13 @@ void intro_v1d::introInit() {
}
bool intro_v1d::introPlay() {
- static int state = 0;
byte introSize = _vm->getIntroSize();
if (_vm->getGameStatus().skipIntroFl)
return true;
if (introTicks < introSize) {
- switch (state++) {
+ switch (_introState++) {
case 0:
_vm->_screen->drawRectangle(true, 0, 0, 319, 199, _TMAGENTA);
_vm->_screen->drawRectangle(true, 10, 10, 309, 189, _TBLACK);
diff --git a/engines/hugo/intro.h b/engines/hugo/intro.h
index 132fd12846..37c846fc10 100644
--- a/engines/hugo/intro.h
+++ b/engines/hugo/intro.h
@@ -77,6 +77,8 @@ public:
void preNewGame();
void introInit();
bool introPlay();
+private:
+ int _introState;
};
class intro_v2w : public IntroHandler {
diff --git a/engines/hugo/inventory.cpp b/engines/hugo/inventory.cpp
index 4d9da085ac..dfbf6fda6e 100644
--- a/engines/hugo/inventory.cpp
+++ b/engines/hugo/inventory.cpp
@@ -47,6 +47,7 @@ namespace Hugo {
static const int kMaxDisp = (kXPix / kInvDx); // Max icons displayable
InventoryHandler::InventoryHandler(HugoEngine *vm) : _vm(vm) {
+ _firstIconId = 0;
}
/**
@@ -100,8 +101,6 @@ void InventoryHandler::constructInventory(const int16 imageTotNumb, int displayN
int16 InventoryHandler::processInventory(const invact_t action, ...) {
debugC(1, kDebugInventory, "processInventory(invact_t action, ...)");
- static int16 firstIconId = 0; // Index of first icon to display
-
int16 imageNumb; // Total number of inventory items
int displayNumb; // Total number displayed/carried
// Compute total number and number displayed, i.e. number carried
@@ -118,15 +117,15 @@ int16 InventoryHandler::processInventory(const invact_t action, ...) {
switch (action) {
case kInventoryActionInit: // Initialize inventory display
- constructInventory(imageNumb, displayNumb, scrollFl, firstIconId);
+ constructInventory(imageNumb, displayNumb, scrollFl, _firstIconId);
break;
case kInventoryActionLeft: // Scroll left by one icon
- firstIconId = MAX(0, firstIconId - 1);
- constructInventory(imageNumb, displayNumb, scrollFl, firstIconId);
+ _firstIconId = MAX(0, _firstIconId - 1);
+ constructInventory(imageNumb, displayNumb, scrollFl, _firstIconId);
break;
case kInventoryActionRight: // Scroll right by one icon
- firstIconId = MIN(displayNumb, firstIconId + 1);
- constructInventory(imageNumb, displayNumb, scrollFl, firstIconId);
+ _firstIconId = MIN(displayNumb, _firstIconId + 1);
+ constructInventory(imageNumb, displayNumb, scrollFl, _firstIconId);
break;
case kInventoryActionGet: // Return object id under cursor
// Get cursor position from variable argument list
@@ -145,7 +144,7 @@ int16 InventoryHandler::processInventory(const invact_t action, ...) {
if (i == kMaxDisp - 1) // Right scroll button
objId = kRightArrow;
else // Adjust for scroll
- i += firstIconId - 1; // i is icon index
+ i += _firstIconId - 1; // i is icon index
}
}
diff --git a/engines/hugo/inventory.h b/engines/hugo/inventory.h
index 04dbe4b1ea..04273fb00e 100644
--- a/engines/hugo/inventory.h
+++ b/engines/hugo/inventory.h
@@ -50,6 +50,8 @@ private:
HugoEngine *_vm;
static const int kStepDy = 8; // Pixels per step movement
+
+ int16 _firstIconId; // Index of first icon to display
void constructInventory(const int16 imageTotNumb, int displayNumb, const bool scrollFl, int16 firstObjId);
};
diff --git a/engines/hugo/object_v1d.cpp b/engines/hugo/object_v1d.cpp
index 17468565a4..3bd5c64aea 100644
--- a/engines/hugo/object_v1d.cpp
+++ b/engines/hugo/object_v1d.cpp
@@ -177,8 +177,6 @@ void ObjectHandler_v1d::updateImages() {
void ObjectHandler_v1d::moveObjects() {
debugC(4, kDebugObject, "moveObjects");
- static int dxOld; // previous direction for CHASEing
-
// Added to DOS version in order to handle mouse properly
// If route mode enabled, do special route processing
if (_vm->getGameStatus().routeIndex >= 0)
@@ -208,13 +206,13 @@ void ObjectHandler_v1d::moveObjects() {
// Set first image in sequence (if multi-seq object)
if (obj->seqNumb == 4) {
if (!obj->vx) { // Got 4 directions
- if (obj->vx != dxOld) { // vx just stopped
+ if (obj->vx != obj->oldvx) {// vx just stopped
if (dy > 0)
obj->currImagePtr = obj->seqList[DOWN].seqPtr;
else
obj->currImagePtr = obj->seqList[_UP].seqPtr;
}
- } else if (obj->vx != dxOld) {
+ } else if (obj->vx != obj->oldvx) {
if (dx > 0)
obj->currImagePtr = obj->seqList[RIGHT].seqPtr;
else
@@ -229,7 +227,8 @@ void ObjectHandler_v1d::moveObjects() {
obj->cycling = kCycleNotCycling;
_vm->boundaryCollision(obj); // Must have got hero!
}
- dxOld = obj->vx;
+ obj->oldvx = obj->vx;
+ obj->oldvy = obj->vy;
currImage = obj->currImagePtr; // Get (new) ptr to current image
break;
}
@@ -241,13 +240,13 @@ void ObjectHandler_v1d::moveObjects() {
// Set first image in sequence (if multi-seq object)
if (obj->seqNumb > 1) {
if (!obj->vx && (obj->seqNumb > 2)) {
- if (obj->vx != dxOld) { // vx just stopped
+ if (obj->vx != obj->oldvx) { // vx just stopped
if (obj->vy > 0)
obj->currImagePtr = obj->seqList[DOWN].seqPtr;
else
obj->currImagePtr = obj->seqList[_UP].seqPtr;
}
- } else if (obj->vx != dxOld) {
+ } else if (obj->vx != obj->oldvx) {
if (obj->vx > 0)
obj->currImagePtr = obj->seqList[RIGHT].seqPtr;
else
@@ -259,7 +258,8 @@ void ObjectHandler_v1d::moveObjects() {
else
obj->cycling = kCycleNotCycling;
}
- dxOld = obj->vx;
+ obj->oldvx = obj->vx;
+ obj->oldvy = obj->vy;
currImage = obj->currImagePtr; // Get (new) ptr to current image
}
break;
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index 6988434285..c354329d93 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -52,6 +52,10 @@ namespace Hugo {
Parser::Parser(HugoEngine *vm) :
_vm(vm), _putIndex(0), _getIndex(0), _checkDoubleF1Fl(false) {
+ _cmdLineIndex = 0;
+ _cmdLineTick = 0;
+ _cmdLineCursor = '_';
+ _cmdLine[0] = '\0';
}
Parser::~Parser() {
@@ -68,11 +72,7 @@ void Parser::switchTurbo() {
void Parser::charHandler() {
debugC(4, kDebugParser, "charHandler");
- static int16 lineIndex = 0; // Index into line
- static uint32 tick = 0; // For flashing cursor
- static char cursor = '_';
- static command_t cmdLine; // Build command line
- status_t &gameStatus = _vm->getGameStatus();
+ status_t &gameStatus = _vm->getGameStatus();
// Check for one or more characters in ring buffer
while (_getIndex != _putIndex) {
@@ -82,44 +82,44 @@ void Parser::charHandler() {
switch (c) {
case Common::KEYCODE_BACKSPACE: // Rubout key
- if (lineIndex)
- cmdLine[--lineIndex] = '\0';
+ if (_cmdLineIndex)
+ _cmdLine[--_cmdLineIndex] = '\0';
break;
case Common::KEYCODE_RETURN: // EOL, pass line to line handler
- if (lineIndex && (_vm->_hero->pathType != kPathQuiet)) {
+ if (_cmdLineIndex && (_vm->_hero->pathType != kPathQuiet)) {
// Remove inventory bar if active
if (gameStatus.inventoryState == kInventoryActive)
gameStatus.inventoryState = kInventoryUp;
// Call Line handler and reset line
- command(cmdLine);
- cmdLine[lineIndex = 0] = '\0';
+ command(_cmdLine);
+ _cmdLine[_cmdLineIndex = 0] = '\0';
}
break;
default: // Normal text key, add to line
- if (lineIndex >= kMaxLineSize) {
+ if (_cmdLineIndex >= kMaxLineSize) {
//MessageBeep(MB_ICONASTERISK);
warning("STUB: MessageBeep() - Command line too long");
} else if (isprint(c)) {
- cmdLine[lineIndex++] = c;
- cmdLine[lineIndex] = '\0';
+ _cmdLine[_cmdLineIndex++] = c;
+ _cmdLine[_cmdLineIndex] = '\0';
}
break;
}
}
// See if time to blink cursor, set cursor character
- if ((tick++ % (_vm->getTPS() / kBlinksPerSec)) == 0)
- cursor = (cursor == '_') ? ' ' : '_';
+ if ((_cmdLineTick++ % (_vm->getTPS() / kBlinksPerSec)) == 0)
+ _cmdLineCursor = (_cmdLineCursor == '_') ? ' ' : '_';
// See if recall button pressed
if (gameStatus.recallFl) {
// Copy previous line to current cmdline
gameStatus.recallFl = false;
- strcpy(cmdLine, _vm->_line);
- lineIndex = strlen(cmdLine);
+ strcpy(_cmdLine, _vm->_line);
+ _cmdLineIndex = strlen(_cmdLine);
}
- sprintf(_vm->_statusLine, ">%s%c", cmdLine, cursor);
+ sprintf(_vm->_statusLine, ">%s%c", _cmdLine, _cmdLineCursor);
sprintf(_vm->_scoreLine, "F1-Help %s Score: %d of %d Sound %s", (_vm->_config.turboFl) ? "T" : " ", _vm->getScore(), _vm->getMaxScore(), (_vm->_config.soundFl) ? "On" : "Off");
// See if "look" button pressed
diff --git a/engines/hugo/parser.h b/engines/hugo/parser.h
index 3e4eedbdf3..2749343df9 100644
--- a/engines/hugo/parser.h
+++ b/engines/hugo/parser.h
@@ -60,6 +60,11 @@ public:
protected:
HugoEngine *_vm;
+ int16 _cmdLineIndex; // Index into line
+ uint32 _cmdLineTick; // For flashing cursor
+ char _cmdLineCursor;
+ command_t _cmdLine; // Build command line
+
char *findNoun() const;
char *findVerb() const;
void showDosInventory() const;
diff --git a/engines/hugo/route.cpp b/engines/hugo/route.cpp
index 2d4da033d2..e2677aea20 100644
--- a/engines/hugo/route.cpp
+++ b/engines/hugo/route.cpp
@@ -41,6 +41,7 @@
namespace Hugo {
Route::Route(HugoEngine *vm) : _vm(vm) {
+ _oldWalkDirection = 0;
}
/**
@@ -95,16 +96,15 @@ void Route::setDirection(const uint16 keyCode) {
void Route::setWalk(const uint16 direction) {
debugC(1, kDebugRoute, "setWalk(%d)", direction);
- static uint16 oldDirection = 0; // Last direction char
object_t *obj = _vm->_hero; // Pointer to hero object
if (_vm->getGameStatus().storyModeFl || obj->pathType != kPathUser) // Make sure user has control
return;
if (!obj->vx && !obj->vy)
- oldDirection = 0; // Fix for consistant restarts
+ _oldWalkDirection = 0; // Fix for consistant restarts
- if (direction != oldDirection) {
+ if (direction != _oldWalkDirection) {
// Direction has changed
setDirection(direction); // Face new direction
obj->vx = obj->vy = 0;
@@ -150,13 +150,13 @@ void Route::setWalk(const uint16 direction) {
obj->vy = kStepDy / 2;
break;
}
- oldDirection = direction;
+ _oldWalkDirection = direction;
obj->cycling = kCycleForward;
} else {
// Same key twice - halt hero
obj->vy = 0;
obj->vx = 0;
- oldDirection = 0;
+ _oldWalkDirection = 0;
obj->cycling = kCycleNotCycling;
}
}
diff --git a/engines/hugo/route.h b/engines/hugo/route.h
index e5ee72bc5d..c1b860fd57 100644
--- a/engines/hugo/route.h
+++ b/engines/hugo/route.h
@@ -62,6 +62,8 @@ private:
static const int kMaxSeg = 256; // Maximum number of segments
static const int kMaxNodes = 256; // Maximum nodes in route
+ uint16 _oldWalkDirection; // Last direction char
+
byte _boundaryMap[kYPix][kXPix]; // Boundary byte map
segment_t _segment[kMaxSeg]; // List of points in fill-path
Point _route[kMaxNodes]; // List of nodes in route (global)
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index d255bf93b5..43796b6214 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -46,7 +46,7 @@
namespace Hugo {
-Scheduler::Scheduler(HugoEngine *vm) : _vm(vm), _actListArr(0) {
+Scheduler::Scheduler(HugoEngine *vm) : _vm(vm), _actListArr(0), _curTick(0), _oldTime(0), _refreshTimeout(0) {
memset(_events, 0, sizeof(_events));
}
@@ -117,24 +117,21 @@ uint32 Scheduler::getWinTicks() const {
uint32 Scheduler::getDosTicks(const bool updateFl) {
debugC(5, kDebugSchedule, "getDosTicks(%s)", (updateFl) ? "TRUE" : "FALSE");
- static uint32 tick = 0; // Current system time in ticks
- static uint32 t_old = 0; // The previous wall time in ticks
-
uint32 t_now; // Current wall time in ticks
if (!updateFl)
- return(tick);
+ return(_curTick);
- if (t_old == 0)
- t_old = (uint32) floor((double) (g_system->getMillis() * _vm->getTPS() / 1000));
+ if (_oldTime == 0)
+ _oldTime = (uint32) floor((double) (g_system->getMillis() * _vm->getTPS() / 1000));
// Calculate current wall time in ticks
t_now = g_system->getMillis() * _vm->getTPS() / 1000 ;
- if ((t_now - t_old) > 0) {
- t_old = t_now;
- tick++;
+ if ((t_now - _oldTime) > 0) {
+ _oldTime = t_now;
+ _curTick++;
}
- return(tick);
+ return(_curTick);
}
/**
@@ -221,15 +218,14 @@ void Scheduler::restoreScreen(const int screenIndex) {
void Scheduler::waitForRefresh() {
debugC(5, kDebugSchedule, "waitForRefresh()");
- static uint32 timeout = 0;
uint32 t;
- if (timeout == 0)
- timeout = getDosTicks(true);
+ if (_refreshTimeout == 0)
+ _refreshTimeout = getDosTicks(true);
- while ((t = getDosTicks(true)) < timeout)
+ while ((t = getDosTicks(true)) < _refreshTimeout)
;
- timeout = ++t;
+ _refreshTimeout = ++t;
}
/**
diff --git a/engines/hugo/schedule.h b/engines/hugo/schedule.h
index 7b3c515117..c6b664b892 100644
--- a/engines/hugo/schedule.h
+++ b/engines/hugo/schedule.h
@@ -477,17 +477,21 @@ public:
protected:
HugoEngine *_vm;
- static const int kFilenameLength = 12; // Max length of a DOS file name
- static const int kMaxEvents = 50; // Max events in event queue
- static const int kShiftSize = 8; // Place hero this far inside bounding box
+ static const int kFilenameLength = 12; // Max length of a DOS file name
+ static const int kMaxEvents = 50; // Max events in event queue
+ static const int kShiftSize = 8; // Place hero this far inside bounding box
uint16 _actListArrSize;
uint16 _alNewscrIndex;
- event_t *_freeEvent; // Free list of event structures
- event_t *_headEvent; // Head of list (earliest time)
- event_t *_tailEvent; // Tail of list (latest time)
- event_t _events[kMaxEvents]; // Statically declare event structures
+ uint32 _curTick; // Current system time in ticks
+ uint32 _oldTime; // The previous wall time in ticks
+ uint32 _refreshTimeout;
+
+ event_t *_freeEvent; // Free list of event structures
+ event_t *_headEvent; // Head of list (earliest time)
+ event_t *_tailEvent; // Tail of list (latest time)
+ event_t _events[kMaxEvents]; // Statically declare event structures
act **_actListArr;
@@ -518,9 +522,7 @@ public:
protected:
virtual const char *getCypher() const;
-
virtual uint32 getTicks();
-
virtual void promptAction(act *action);
};
diff --git a/engines/hugo/sound.cpp b/engines/hugo/sound.cpp
index a1b47a1dbb..b382f449b0 100644
--- a/engines/hugo/sound.cpp
+++ b/engines/hugo/sound.cpp
@@ -47,12 +47,16 @@
namespace Hugo {
MidiPlayer::MidiPlayer(MidiDriver *driver)
- : _driver(driver), _parser(0), _midiData(0), _isLooping(false), _isPlaying(false), _paused(false), _masterVolume(0) {
+ : _driver(driver), _parser(0), _midiData(0) {
assert(_driver);
memset(_channelsTable, 0, sizeof(_channelsTable));
for (int i = 0; i < kNumbChannels; i++) {
_channelsVolume[i] = 127;
}
+ _isLooping = false;
+ _isPlaying = false;
+ _paused = false;
+ _masterVolume = 0;
}
MidiPlayer::~MidiPlayer() {
@@ -236,6 +240,10 @@ SoundHandler::SoundHandler(HugoEngine *vm) : _vm(vm) {
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle,
_speakerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
DOSSongPtr = 0;
+ curPriority = 0;
+ pcspkrTimer = 0;
+ pcspkrOctave = 3;
+ pcspkrNoteDuration = 2;
}
SoundHandler::~SoundHandler() {
@@ -309,7 +317,6 @@ void SoundHandler::playSound(int16 sound, const byte priority) {
// uint32 dwVolume; // Left, right volume of sound
sound_pt sound_p; // Sound data
uint16 size; // Size of data
- static byte curPriority = 0; // Priority of currently playing sound
// Sound disabled
if (!_vm->_config.soundFl || !_vm->_mixer->isReady())
@@ -374,12 +381,9 @@ void SoundHandler::loopPlayer(void *refCon) {
* Timer: >0 - song still going, 0 - Stop note, -1 - Set next note
*/
void SoundHandler::pcspkr_player() {
- static int8 pcspkrTimer = 0; // Timer (ticks) for note being played
- static int8 pcspkrOctave = 3; // Current octave 1..7
- static int8 pcspkrNoteDuration = 2; // Current length of note (ticks)
- static uint16 pcspkrNotes[8] = {1352, 1205, 2274, 2026, 1805, 1704, 1518}; // The 3rd octave note counts A..G
- static uint16 pcspkrSharps[8] = {1279, 1171, 2150, 1916, 1755, 1611, 1435}; // The sharps, A# to B#
- static uint16 pcspkrFlats[8] = {1435, 1279, 2342, 2150, 1916, 1755, 1611}; // The flats, Ab to Bb
+ static const uint16 pcspkrNotes[8] = {1352, 1205, 2274, 2026, 1805, 1704, 1518}; // The 3rd octave note counts A..G
+ static const uint16 pcspkrSharps[8] = {1279, 1171, 2150, 1916, 1755, 1611, 1435}; // The sharps, A# to B#
+ static const uint16 pcspkrFlats[8] = {1435, 1279, 2342, 2150, 1916, 1755, 1611}; // The flats, Ab to Bb
_vm->getTimerManager()->removeTimerProc(&loopPlayer);
_vm->getTimerManager()->installTimerProc(&loopPlayer, 1000000 / 9, this);
diff --git a/engines/hugo/sound.h b/engines/hugo/sound.h
index 4d97fe4e99..0e8905c762 100644
--- a/engines/hugo/sound.h
+++ b/engines/hugo/sound.h
@@ -96,6 +96,10 @@ public:
static const int kHugoCNT = 1190000;
+ int8 pcspkrTimer; // Timer (ticks) for note being played
+ int8 pcspkrOctave; // Current octave 1..7
+ int8 pcspkrNoteDuration; // Current length of note (ticks)
+
char *DOSSongPtr;
char *DOSIntroSong;
@@ -111,6 +115,9 @@ public:
void checkMusic();
void loadIntroSong(Common::File &in);
void initPcspkrPlayer();
+protected:
+ byte curPriority; // Priority of currently playing sound
+
private:
HugoEngine *_vm;
Audio::SoundHandle _soundHandle;