BURIED: Rewrite the head opened time code for the Mayan arrow god scene

This allows us to remove the last usage of getGlobalFlagDWord() and
setGlobalFlagDWord()
This commit is contained in:
Filippos Karapetis 2022-01-01 05:09:42 +02:00
parent b583326c5e
commit f750b97687
3 changed files with 84 additions and 23 deletions

View File

@ -1183,13 +1183,18 @@ private:
int _stillFrames[4];
int _soundID;
int _headAnimations[4];
GlobalFlags &_globalFlags;
uint32 getHeadOpenedTime(byte headId) const;
void setHeadOpenedTime(byte headId, uint32 value);
};
ArrowGodHead::ArrowGodHead(BuriedEngine *vm, Window *viewWindow, const LocationStaticData &sceneStaticData, const Location &priorLocation,
int headID, int clickLeft, int clickTop, int clickRight, int clickBottom,
int emptyClosedStill, int emptyOpenStill, int fullClosedStill, int fullOpenStill,
int emptyClosedAnim, int emptyOpenAnim, int fullClosedAnim, int fullOpenAnim) :
SceneBase(vm, viewWindow, sceneStaticData, priorLocation) {
SceneBase(vm, viewWindow, sceneStaticData, priorLocation),
_globalFlags(((SceneViewWindow *)viewWindow)->getGlobalFlags()) {
SceneViewWindow *sceneView = ((SceneViewWindow *)viewWindow);
_soundID = -1;
@ -1257,6 +1262,40 @@ int ArrowGodHead::mouseDown(Window *viewWindow, const Common::Point &pointLocati
return SC_FALSE;
}
uint32 ArrowGodHead::getHeadOpenedTime(byte headId) const {
switch (headId) {
case 0:
return _globalFlags.myAGHeadAOpenedTime;
case 1:
return _globalFlags.myAGHeadBOpenedTime;
case 2:
return _globalFlags.myAGHeadCOpenedTime;
case 3:
return _globalFlags.myAGHeadDOpenedTime;
default:
return 0;
}
}
void ArrowGodHead::setHeadOpenedTime(byte headId, uint32 value) {
switch (headId) {
case 0:
_globalFlags.myAGHeadAOpenedTime = value;
break;
case 1:
_globalFlags.myAGHeadBOpenedTime = value;
break;
case 2:
_globalFlags.myAGHeadCOpenedTime = value;
break;
case 3:
_globalFlags.myAGHeadDOpenedTime = value;
break;
default:
break;
}
}
int ArrowGodHead::mouseUp(Window *viewWindow, const Common::Point &pointLocation) {
SceneViewWindow *sceneView = ((SceneViewWindow *)viewWindow);
GlobalFlags &globalFlags = sceneView->getGlobalFlags();
@ -1324,7 +1363,7 @@ int ArrowGodHead::mouseUp(Window *viewWindow, const Common::Point &pointLocation
_vm->_sound->playSoundEffect(_vm->getFilePath(_staticData.location.timeZone, _staticData.location.environment, 11), 96);
if (headStatus & 1)
sceneView->setGlobalFlagDWord(offsetof(GlobalFlags, myAGHeadAOpenedTime) + _headID * 4, g_system->getMillis());
setHeadOpenedTime(_headID, g_system->getMillis());
bioChipRightWindow->sceneChanged();
return SC_TRUE;
@ -1418,10 +1457,10 @@ int ArrowGodHead::timerCallback(Window *viewWindow) {
BioChipRightWindow *bioChipRightWindow = ((GameUIWindow *)viewWindow->getParent())->_bioChipRightWindow;
for (int i = 0; i < 4; i++) {
uint32 lastStartedTimer = sceneView->getGlobalFlagDWord(offsetof(GlobalFlags, myAGHeadAOpenedTime) + i * 4);
uint32 lastStartedTimer = getHeadOpenedTime(i);
if (lastStartedTimer > 0 && g_system->getMillis() > (lastStartedTimer + WAR_GOD_HEAD_TIMER_VALUE)) {
sceneView->setGlobalFlagDWord(offsetof(GlobalFlags, myAGHeadAOpenedTime) + i * 4, 0);
setHeadOpenedTime(i, 0);
TempCursorChange cursorChange(kCursorWait);
@ -1529,12 +1568,16 @@ public:
private:
bool _scheduledDepthChange;
int _soundID;
GlobalFlags &_globalFlags;
bool adjustSpearVolume(Window *viewWindow);
uint32 getHeadOpenedTime(byte headId) const;
void setHeadOpenedTime(byte headId, uint32 value);
};
ArrowGodDepthChange::ArrowGodDepthChange(BuriedEngine *vm, Window *viewWindow, const LocationStaticData &sceneStaticData, const Location &priorLocation) :
SceneBase(vm, viewWindow, sceneStaticData, priorLocation) {
SceneBase(vm, viewWindow, sceneStaticData, priorLocation),
_globalFlags(((SceneViewWindow *)viewWindow)->getGlobalFlags()) {
SceneViewWindow *sceneView = ((SceneViewWindow *)viewWindow);
GlobalFlags &globalFlags = sceneView->getGlobalFlags();
@ -1662,6 +1705,40 @@ int ArrowGodDepthChange::postExitRoom(Window *viewWindow, const Location &newLoc
return SC_TRUE;
}
uint32 ArrowGodDepthChange::getHeadOpenedTime(byte headId) const {
switch (headId) {
case 0:
return _globalFlags.myAGHeadAOpenedTime;
case 1:
return _globalFlags.myAGHeadBOpenedTime;
case 2:
return _globalFlags.myAGHeadCOpenedTime;
case 3:
return _globalFlags.myAGHeadDOpenedTime;
default:
return 0;
}
}
void ArrowGodDepthChange::setHeadOpenedTime(byte headId, uint32 value) {
switch (headId) {
case 0:
_globalFlags.myAGHeadAOpenedTime = value;
break;
case 1:
_globalFlags.myAGHeadBOpenedTime = value;
break;
case 2:
_globalFlags.myAGHeadCOpenedTime = value;
break;
case 3:
_globalFlags.myAGHeadDOpenedTime = value;
break;
default:
break;
}
}
int ArrowGodDepthChange::timerCallback(Window *viewWindow) {
SceneViewWindow *sceneView = ((SceneViewWindow *)viewWindow);
GlobalFlags &globalFlags = sceneView->getGlobalFlags();
@ -1696,13 +1773,13 @@ int ArrowGodDepthChange::timerCallback(Window *viewWindow) {
// Loop through the four heads
for (int i = 0; i < 4; i++) {
uint32 lastStartedTimer = sceneView->getGlobalFlagDWord(offsetof(GlobalFlags, myAGHeadAOpenedTime) + i * 4);
uint32 lastStartedTimer = getHeadOpenedTime(i);
// Check if there is a timer going for this head
if (lastStartedTimer > 0 && (g_system->getMillis() > (lastStartedTimer + WAR_GOD_HEAD_TIMER_VALUE) ||
i == 0 || (globalFlags.generalWalkthroughMode == 1 && i == 1) ||
(sceneView->getGlobalFlagByte(offsetof(GlobalFlags, myAGHeadAStatus) + i) == 2 && i == 3))) {
sceneView->setGlobalFlagDWord(offsetof(GlobalFlags, myAGHeadAOpenedTime) + i * 4, 0);
setHeadOpenedTime(i, 0);
TempCursorChange cursorChange(kCursorWait);
byte status = sceneView->getGlobalFlagByte(offsetof(GlobalFlags, myAGHeadAStatus) + i);

View File

@ -1434,20 +1434,6 @@ bool SceneViewWindow::setGlobalFlagByte(int offset, byte value) {
return true;
}
uint32 SceneViewWindow::getGlobalFlagDWord(int offset) {
// TODO: Verify the offset
const byte *data = (const byte *)&_globalFlags;
return READ_UINT32(data + offset);
}
bool SceneViewWindow::setGlobalFlagDWord(int offset, uint32 value) {
// TODO: Verify the offset
byte *data = (byte *)&_globalFlags;
WRITE_UINT32(data + offset, value);
return true;
}
bool SceneViewWindow::addNumberToGlobalFlagTable(int tableOffset, int curItemCountOffset, int maxItems, byte numberToAdd) {
// TODO: Rewrite this
byte *data = (byte *)&_globalFlags;

View File

@ -100,8 +100,6 @@ public:
byte getGlobalFlagByte(int offset);
bool setGlobalFlagByte(int offset, byte value);
bool setGlobalFlagDWord(int offset, uint32 value);
uint32 getGlobalFlagDWord(int offset);
bool addNumberToGlobalFlagTable(int offset, int curItemCountOffset, int maxItems, byte numberToAdd);
byte getNumberFromGlobalFlagTable(int offset, int tableIndex);
bool isNumberInGlobalFlagTable(int offset, int curItemCountOffset, byte numberToCheck);