Skip to content

Commit

Permalink
HOPKINS: Move more variables and functions out of Globals
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Mar 24, 2013
1 parent ac338c3 commit 165681b
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 160 deletions.
92 changes: 0 additions & 92 deletions engines/hopkins/globals.cpp
Expand Up @@ -82,9 +82,6 @@ Globals::Globals(HopkinsEngine *vm) {
Common::fill((byte *)&VBob[i], (byte *)&VBob[i] + sizeof(VBobItem), 0);
for (int i = 0; i < 300; ++i)
Common::fill((byte *)&_objectAuthIcons[i], (byte *)&_objectAuthIcons[i] + sizeof(ObjectAuthIcon), 0);
for (int i = 0; i < 25; ++i)
Common::fill((byte *)&_hidingItem[i], (byte *)&_hidingItem[i] + sizeof(HidingItem), 0);

for (int i = 0; i < 500; ++i)
_spriteSize[i] = 0;
for (int i = 0; i < 70; ++i)
Expand Down Expand Up @@ -129,8 +126,6 @@ Globals::Globals(HopkinsEngine *vm) {
_oceanDirection = DIR_NONE;

// Initialize pointers
for (int i = 0; i < 6; ++i)
_hidingItemData[i] = g_PTRNUL;
_levelSpriteBuf = NULL;
_saveData = NULL;
_answerBuffer = g_PTRNUL;
Expand All @@ -143,21 +138,11 @@ Globals::Globals(HopkinsEngine *vm) {
_disableInventFl = false;
_freezeCharacterFl = false;
_optionDialogFl = false;
_hidingActiveFl = false;
_introSpeechOffFl = false;
_baseMapColor = 50;

// Reset indexed variables
_oldRouteFromX = 0;
_oldRouteFromY = 0;
_oldRouteDestX = 0;
_oldRouteDestY = 0;
_oldZoneNum = 0;
}

Globals::~Globals() {
for (int idx = 0; idx < 6; ++idx)
_hidingItemData[idx] = freeMemory(_hidingItemData[idx]);
freeMemory(_levelSpriteBuf);
freeMemory((byte *)_saveData);
freeMemory(_answerBuffer);
Expand Down Expand Up @@ -206,9 +191,6 @@ void Globals::setConfig() {
}

void Globals::clearAll() {
for (int idx = 0; idx < 6; ++idx)
_hidingItemData[idx] = g_PTRNUL;

initAnimBqe();

_vm->_fontManager->clearAll();
Expand Down Expand Up @@ -319,83 +301,9 @@ byte *Globals::freeMemory(byte *p) {
return g_PTRNUL;
}

// Reset Hiding Items
void Globals::resetHidingItems() {

for (int idx = 1; idx <= 5; ++idx) {
_hidingItemData[idx] = freeMemory(_hidingItemData[idx]);
}

for (int idx = 0; idx <= 20; ++idx) {
HidingItem *hid = &_hidingItem[idx];
hid->_spriteData = g_PTRNUL;
hid->_x = 0;
hid->_y = 0;
hid->_spriteIndex = 0;
hid->_useCount = 0;
hid->_width = 0;
hid->_height = 0;
hid->_resetUseCount = false;
hid->_yOffset = 0;
}

_hidingActiveFl = false;
}

void Globals::enableHiding() {
_hidingActiveFl = true;
}

void Globals::disableHiding() {
_hidingActiveFl = false;
}

void Globals::B_CACHE_OFF(int idx) {
assert(idx < 36);
_vm->_objectsManager->_bob[idx].field34 = true;
}

void Globals::resetHidingUseCount(int idx) {
_hidingItem[idx]._useCount = 0;
}

void Globals::setHidingUseCount(int idx) {
_hidingItem[idx]._useCount = 1;
}

// Load Hiding Items
void Globals::loadHidingItems(const Common::String &file) {
resetHidingItems();
byte *ptr = _vm->_fileManager->loadFile(file);
Common::String filename = Common::String((const char *)ptr);

Common::File f;
if (!f.exists(filename))
return;

byte *spriteData = _vm->_fileManager->loadFile(filename);
_hidingItemData[1] = spriteData;
int curBufIdx = 60;
for (int i = 0; i <= 21; i++) {
_hidingItem[i]._spriteIndex = READ_LE_INT16((uint16 *)ptr + curBufIdx);
_hidingItem[i]._x = READ_LE_INT16((uint16 *)ptr + curBufIdx + 1);
_hidingItem[i]._y = READ_LE_INT16((uint16 *)ptr + curBufIdx + 2);
_hidingItem[i]._yOffset = READ_LE_INT16((uint16 *)ptr + curBufIdx + 4);
if (spriteData == g_PTRNUL) {
_hidingItem[i]._useCount = 0;
} else {
_hidingItem[i]._spriteData = spriteData;
_hidingItem[i]._width = _vm->_objectsManager->getWidth(spriteData, _hidingItem[i]._spriteIndex);
_hidingItem[i]._height = _vm->_objectsManager->getHeight(spriteData, _hidingItem[i]._spriteIndex);
_hidingItem[i]._useCount = 1;
}

if ( !_hidingItem[i]._x && !_hidingItem[i]._y && !_hidingItem[i]._spriteIndex)
_hidingItem[i]._useCount = 0;
curBufIdx += 5;
}
enableHiding();
freeMemory(ptr);
}

} // End of namespace Hopkins
17 changes: 2 additions & 15 deletions engines/hopkins/globals.h
Expand Up @@ -176,7 +176,8 @@ enum SauvegardeOffset {
, svField401 = 401
};

// TODO: Sauvegrade1 fields should really be mapped into data array
// As Script engine directly access savegame fields,
// refactoring it in separated fields properly named is impossible
struct Savegame {
byte _data[2050];
CharacterLocation _cloneHopkins;
Expand Down Expand Up @@ -230,7 +231,6 @@ class Globals {
bool _linuxEndDemoFl;
bool _censorshipFl;
bool _introSpeechOffFl;
bool _hidingActiveFl;
int _exitId;
Directions _oceanDirection;
int _actionDirection;
Expand Down Expand Up @@ -266,17 +266,10 @@ class Globals {

byte *_optionDialogSpr;
bool _optionDialogFl;
int _oldRouteFromX;
int _oldRouteFromY;
int _oldRouteDestX;
int _oldRouteDestY;
int _oldZoneNum;

bool _actionMoveTo;
bool _freezeCharacterFl;
bool _checkDistanceFl;
byte *_hidingItemData[6];
HidingItem _hidingItem[25];
BqeAnimItem _animBqe[35];
ObjectAuthIcon _objectAuthIcons[300];
int _curObjectFileNum;
Expand All @@ -300,12 +293,6 @@ class Globals {
void loadObjects();
void clearAll();
void loadCharacterData();
void resetHidingItems();
void loadHidingItems(const Common::String &file);
void enableHiding();
void disableHiding();
void resetHidingUseCount(int idx);
void setHidingUseCount(int idx);
void clearVBob();

void B_CACHE_OFF(int idx);
Expand Down
4 changes: 2 additions & 2 deletions engines/hopkins/hopkins.cpp
Expand Up @@ -2043,15 +2043,15 @@ void HopkinsEngine::playUnderwaterBaseCutscene() {
_eventsManager->refreshScreenAndEvents();

_graphicsManager->fadeInLong();
_globals->enableHiding();
_objectsManager->enableHiding();

do
_eventsManager->refreshScreenAndEvents();
while (_objectsManager->getBobAnimDataIdx(8) != 22);

_graphicsManager->fadeOutLong();
_graphicsManager->endDisplayBob();
_globals->resetHidingItems();
_objectsManager->resetHidingItems();
_globals->_disableInventFl = false;
_globals->_exitId = 93;
_globals->iRegul = 0;
Expand Down
21 changes: 13 additions & 8 deletions engines/hopkins/lines.cpp
Expand Up @@ -80,6 +80,11 @@ LinesManager::LinesManager(HopkinsEngine *vm) {
_oldMouseZoneId = 0;
_oldMouseX = 0;
_oldMouseY = 0;
_oldRouteFromX = 0;
_oldRouteFromY = 0;
_oldRouteDestX = 0;
_oldRouteDestY = 0;
_oldZoneNum = 0;
}

LinesManager::~LinesManager() {
Expand Down Expand Up @@ -1084,22 +1089,22 @@ RouteItem *LinesManager::PARCOURS2(int fromX, int fromY, int destX, int destY) {
if (destY <= 24)
clipDestY = 25;
if (!_vm->_globals->_checkDistanceFl) {
if (abs(fromX - _vm->_globals->_oldRouteFromX) <= 4 && abs(fromY - _vm->_globals->_oldRouteFromY) <= 4 &&
abs(_vm->_globals->_oldRouteDestX - destX) <= 4 && abs(_vm->_globals->_oldRouteDestY - clipDestY) <= 4)
if (abs(fromX - _oldRouteFromX) <= 4 && abs(fromY - _oldRouteFromY) <= 4 &&
abs(_oldRouteDestX - destX) <= 4 && abs(_oldRouteDestY - clipDestY) <= 4)
return (RouteItem *)g_PTRNUL;

if (abs(fromX - destX) <= 4 && abs(fromY - clipDestY) <= 4)
return (RouteItem *)g_PTRNUL;

if (_vm->_globals->_oldZoneNum > 0 && _vm->_objectsManager->_zoneNum > 0 && _vm->_globals->_oldZoneNum == _vm->_objectsManager->_zoneNum)
if (_oldZoneNum > 0 && _vm->_objectsManager->_zoneNum > 0 && _oldZoneNum == _vm->_objectsManager->_zoneNum)
return (RouteItem *)g_PTRNUL;
}
_vm->_globals->_checkDistanceFl = false;
_vm->_globals->_oldZoneNum = _vm->_objectsManager->_zoneNum;
_vm->_globals->_oldRouteFromX = fromX;
_vm->_globals->_oldRouteDestX = destX;
_vm->_globals->_oldRouteFromY = fromY;
_vm->_globals->_oldRouteDestY = clipDestY;
_oldZoneNum = _vm->_objectsManager->_zoneNum;
_oldRouteFromX = fromX;
_oldRouteDestX = destX;
_oldRouteFromY = fromY;
_oldRouteDestY = clipDestY;
_pathFindingMaxDepth = 0;
int routeIdx = 0;
if (destX <= 19)
Expand Down
5 changes: 5 additions & 0 deletions engines/hopkins/lines.h
Expand Up @@ -124,6 +124,11 @@ class LinesManager {
int _newPosX;
int _newPosY;
int _oldMouseX, _oldMouseY;
int _oldRouteFromX;
int _oldRouteFromY;
int _oldRouteDestX;
int _oldRouteDestY;
int _oldZoneNum;

byte *_largeBuf;
RouteItem *_testRoute0;
Expand Down

0 comments on commit 165681b

Please sign in to comment.