LAB: Get rid of a goto

This commit is contained in:
Strangerke 2015-11-30 13:09:36 +01:00 committed by Willem Jan Palenstijn
parent d45d46c2cb
commit 4a90aba77a
2 changed files with 530 additions and 528 deletions

View file

@ -618,17 +618,10 @@ void LabEngine::decIncInv(uint16 *CurInv, bool dec) {
/* The main game loop */
/******************************************************************************/
void LabEngine::mainGameLoop() {
uint32 Class;
uint16 actionMode = 4;
uint16 curInv = MAPNUM;
uint16 Qualifier, ActionMode = 4;
uint16 CurInv = MAPNUM, LastInv = MAPNUM, Old;
bool ForceDraw = false, doit, GotMessage = true;
uint16 OldRoomNum, OldDirection = 0, GadID = 0, NewDir;
CloseDataPtr OldCPtr, TempCPtr, HCPtr = NULL;
ViewData *VPtr;
bool forceDraw = false, GotMessage = true;
VGASetPal(initcolors, 8);
@ -650,11 +643,10 @@ void LabEngine::mainGameLoop() {
LongWinInFront = false;
drawPanel();
perFlipGadget(ActionMode);
perFlipGadget(actionMode);
/* Set up initial picture. */
uint16 code = 0;
while (1) {
WSDL_ProcessInput(1);
@ -680,7 +672,7 @@ void LabEngine::mainGameLoop() {
if (noupdatediff) {
_roomsFound->inclElement(_roomNum); /* Potentially entered another room */
ForceDraw = (strcmp(Test, CurFileName) != 0) || ForceDraw;
forceDraw = (strcmp(Test, CurFileName) != 0) || forceDraw;
noupdatediff = false;
CurFileName = Test;
@ -703,8 +695,8 @@ void LabEngine::mainGameLoop() {
} else
readPict(CurFileName, false);
drawRoomMessage(CurInv, CPtr);
ForceDraw = false;
drawRoomMessage(curInv, CPtr);
forceDraw = false;
mayShowCrumbIndicator();
WSDL_UpdateScreen();
@ -713,9 +705,9 @@ void LabEngine::mainGameLoop() {
eatMessages();
}
if (ForceDraw) {
drawRoomMessage(CurInv, CPtr);
ForceDraw = false;
if (forceDraw) {
drawRoomMessage(curInv, CPtr);
forceDraw = false;
WSDL_UpdateScreen();
}
}
@ -724,7 +716,6 @@ void LabEngine::mainGameLoop() {
interfaceOn();
IntuiMessage *curMsg = getMsg();
Common::Point curPos;
if (curMsg == NULL) { /* Does music load and next animation frame when you've run out of messages */
GotMessage = false;
_music->checkRoomMusic();
@ -735,21 +726,19 @@ void LabEngine::mainGameLoop() {
int result = followCrumbs();
if (result != 0) {
curPos = WSDL_GetMousePos();
Class = GADGETUP;
Qualifier = 0;
uint16 code = 0;
if (result == VKEY_UPARROW)
code = GadID = 7;
code = 7;
else if (result == VKEY_LTARROW)
code = GadID = 6;
code = 6;
else if (result == VKEY_RTARROW)
code = GadID = 8;
code = 8;
GotMessage = true;
mayShowCrumbIndicator();
WSDL_UpdateScreen();
goto from_crumbs;
if (!from_crumbs(GADGETUP, code, 0, WSDL_GetMousePos(), curInv, curMsg, forceDraw, code, actionMode))
break;
}
}
@ -758,21 +747,54 @@ void LabEngine::mainGameLoop() {
} else {
GotMessage = true;
Class = curMsg->msgClass;
code = curMsg->code;
Qualifier = curMsg->qualifier;
Common::Point curPos;
curPos.x = curMsg->mouseX;
curPos.y = curMsg->mouseY;
GadID = curMsg->gadgetID;
_followingCrumbs = false;
if (!from_crumbs(curMsg->msgClass, curMsg->code, curMsg->qualifier, curPos, curInv, curMsg, forceDraw, curMsg->gadgetID, actionMode))
break;
}
}
delete _conditions;
delete _roomsFound;
if (_rooms) {
free(_rooms);
_rooms = nullptr;
}
if (Inventory) {
for (int i = 1; i <= NumInv; i++) {
if (Inventory[i].name)
free(Inventory[i].name);
if (Inventory[i].BInvName)
free(Inventory[i].BInvName);
}
free(Inventory);
}
}
bool LabEngine::from_crumbs(uint32 tmpClass, uint16 code, uint16 Qualifier, Common::Point tmpPos, uint16 &curInv, IntuiMessage *curMsg, bool &forceDraw, uint16 gadgetId, uint16 &actionMode) {
uint32 msgClass = tmpClass;
Common::Point curPos = tmpPos;
uint16 OldRoomNum, OldDirection = 0;
uint16 LastInv = MAPNUM, Old;
CloseDataPtr OldCPtr, TempCPtr, HCPtr = NULL;
ViewData *VPtr;
bool doit;
uint16 NewDir;
from_crumbs:
DoBlack = false;
if ((Class == RAWKEY) && (!LongWinInFront)) {
if ((msgClass == RAWKEY) && (!LongWinInFront)) {
if (code == 13) { /* The return key */
Class = MOUSEBUTTONS;
msgClass = MOUSEBUTTONS;
Qualifier = IEQUALIFIER_LEFTBUTTON;
curPos = _event->getMousePos();
} else if (getPlatform() == Common::kPlatformWindows &&
@ -801,7 +823,7 @@ from_crumbs:
MainDisplay = true;
interfaceOn(); /* Sets the correct gadget list */
drawPanel();
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
WSDL_UpdateScreen();
}
} else {
@ -844,13 +866,13 @@ from_crumbs:
if (doit) {
stopDiff();
break;
return false;
} else {
ForceDraw = true;
forceDraw = true;
interfaceOn();
}
} else if (code == 9) { /* TAB key */
Class = DELTAMOVE;
msgClass = DELTAMOVE;
} else if (code == 27) { /* ESC key */
CPtr = NULL;
}
@ -859,19 +881,19 @@ from_crumbs:
}
if (LongWinInFront) {
if ((Class == RAWKEY) ||
((Class == MOUSEBUTTONS) &&
if ((msgClass == RAWKEY) ||
((msgClass == MOUSEBUTTONS) &&
((IEQUALIFIER_LEFTBUTTON & Qualifier) ||
(IEQUALIFIER_RBUTTON & Qualifier)))) {
LongWinInFront = false;
DoNotDrawMessage = false;
drawPanel();
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
WSDL_UpdateScreen();
}
} else if ((Class == GADGETUP) && !Alternate) {
if (GadID <= 5) {
if ((ActionMode == 4) && (GadID == 4) && (CPtr != NULL)) {
} else if ((msgClass == GADGETUP) && !Alternate) {
if (gadgetId <= 5) {
if ((actionMode == 4) && (gadgetId == 4) && (CPtr != NULL)) {
doMainView(&CPtr);
DoBlack = true;
@ -879,7 +901,7 @@ from_crumbs:
CPtr = NULL;
mayShowCrumbIndicator();
WSDL_UpdateScreen();
} else if (GadID == 5) {
} else if (gadgetId == 5) {
eatMessages();
Alternate = true;
@ -890,49 +912,49 @@ from_crumbs:
MainDisplay = false;
if (LastInv && _conditions->in(LastInv)) {
CurInv = LastInv;
Test = getInvName(CurInv);
curInv = LastInv;
Test = getInvName(curInv);
} else
decIncInv(&CurInv, false);
decIncInv(&curInv, false);
drawPanel();
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
mayShowCrumbIndicator();
WSDL_UpdateScreen();
} else {
Old = ActionMode;
ActionMode = GadID;
Old = actionMode;
actionMode = gadgetId;
if (Old < 5)
perFlipGadget(Old);
perFlipGadget(ActionMode);
perFlipGadget(actionMode);
if (GadID == 0)
if (gadgetId == 0)
drawStaticMessage(kTextTakeWhat);
else if (GadID == 1)
else if (gadgetId == 1)
drawStaticMessage(kTextMoveWhat);
else if (GadID == 2)
else if (gadgetId == 2)
drawStaticMessage(kTextOpenWhat);
else if (GadID == 3)
else if (gadgetId == 3)
drawStaticMessage(kTextCloseWhat);
else if (GadID == 4)
else if (gadgetId == 4)
drawStaticMessage(kTextLookWhat);
WSDL_UpdateScreen();
}
} else if (GadID == 9) {
} else if (gadgetId == 9) {
doUse(MAPNUM);
mayShowCrumbIndicator();
WSDL_UpdateScreen();
} else if (GadID >= 6) { /* Arrow Gadgets */
} else if (gadgetId >= 6) { /* Arrow Gadgets */
CPtr = NULL;
HCPtr = NULL;
if ((GadID == 6) || (GadID == 8)) {
if (GadID == 6)
if ((gadgetId == 6) || (gadgetId == 8)) {
if (gadgetId == 6)
drawStaticMessage(kTextTurnLeft);
else
drawStaticMessage(kTextTurnRight);
@ -942,15 +964,15 @@ from_crumbs:
OldDirection = Direction;
NewDir = Direction;
processArrow(&NewDir, GadID - 6);
processArrow(&NewDir, gadgetId - 6);
doTurn(Direction, NewDir, &CPtr);
DoBlack = true;
Direction = NewDir;
ForceDraw = true;
forceDraw = true;
mayShowCrumbIndicator();
WSDL_UpdateScreen();
} else if (GadID == 7) {
} else if (gadgetId == 7) {
OldRoomNum = _roomNum;
if (doGoForward(&CPtr)) {
@ -958,13 +980,13 @@ from_crumbs:
DoBlack = true;
} else {
DoBlack = true;
processArrow(&Direction, GadID - 6);
processArrow(&Direction, gadgetId - 6);
if (OldRoomNum != _roomNum) {
drawStaticMessage(kTextGoForward);
_roomsFound->inclElement(_roomNum); /* Potentially entered a new room */
CurFileName = " ";
ForceDraw = true;
forceDraw = true;
} else {
DoBlack = true;
drawStaticMessage(kTextNoPath);
@ -1016,10 +1038,10 @@ from_crumbs:
WSDL_UpdateScreen();
}
}
} else if ((Class == GADGETUP) && Alternate) {
} else if ((msgClass == GADGETUP) && Alternate) {
DoBlack = true;
if (GadID == 0) {
if (gadgetId == 0) {
eatMessages();
Alternate = false;
DoBlack = true;
@ -1028,14 +1050,14 @@ from_crumbs:
MainDisplay = true;
interfaceOn(); /* Sets the correct gadget list */
drawPanel();
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
WSDL_UpdateScreen();
}
GadID--;
gadgetId--;
if (GadID == 0) {
if (gadgetId == 0) {
interfaceOff();
stopDiff();
CurFileName = " ";
@ -1045,10 +1067,10 @@ from_crumbs:
MainDisplay = true;
CurInv = MAPNUM;
curInv = MAPNUM;
LastInv = MAPNUM;
Test = getInvName(CurInv);
Test = getInvName(curInv);
drawPanel();
@ -1062,10 +1084,10 @@ from_crumbs:
} else {
WSDL_UpdateScreen();
}
} else if (GadID == 1) {
if (!doUse(CurInv)) {
Old = ActionMode;
ActionMode = 5; /* Use button */
} else if (gadgetId == 1) {
if (!doUse(curInv)) {
Old = actionMode;
actionMode = 5; /* Use button */
if (Old < 5)
perFlipGadget(Old);
@ -1075,42 +1097,42 @@ from_crumbs:
WSDL_UpdateScreen();
}
} else if (GadID == 2) {
} else if (gadgetId == 2) {
MainDisplay = !MainDisplay;
if ((CurInv == 0) || (CurInv > NumInv)) {
CurInv = 1;
if ((curInv == 0) || (curInv > NumInv)) {
curInv = 1;
while ((CurInv <= NumInv) && (!_conditions->in(CurInv)))
CurInv++;
while ((curInv <= NumInv) && (!_conditions->in(curInv)))
curInv++;
}
if ((CurInv <= NumInv) && _conditions->in(CurInv) &&
Inventory[CurInv].BInvName)
Test = getInvName(CurInv);
if ((curInv <= NumInv) && _conditions->in(curInv) &&
Inventory[curInv].BInvName)
Test = getInvName(curInv);
WSDL_UpdateScreen();
} else if (GadID == 3) { /* Left gadget */
decIncInv(&CurInv, true);
LastInv = CurInv;
} else if (gadgetId == 3) { /* Left gadget */
decIncInv(&curInv, true);
LastInv = curInv;
DoNotDrawMessage = false;
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
WSDL_UpdateScreen();
} else if (GadID == 4) { /* Right gadget */
decIncInv(&CurInv, false);
LastInv = CurInv;
} else if (gadgetId == 4) { /* Right gadget */
decIncInv(&curInv, false);
LastInv = curInv;
DoNotDrawMessage = false;
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
WSDL_UpdateScreen();
} else if (GadID == 5) { /* bread crumbs */
} else if (gadgetId == 5) { /* bread crumbs */
_breadCrumbs[0]._roomNum = 0;
_numCrumbs = 0;
_droppingCrumbs = true;
mayShowCrumbIndicator();
WSDL_UpdateScreen();
} else if (GadID == 6) { /* follow crumbs */
} else if (gadgetId == 6) { /* follow crumbs */
if (_droppingCrumbs) {
if (_numCrumbs > 0) {
_followingCrumbs = true;
@ -1127,7 +1149,7 @@ from_crumbs:
MainDisplay = true;
interfaceOn(); /* Sets the correct gadget list */
drawPanel();
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
WSDL_UpdateScreen();
} else {
_breadCrumbs[0]._roomNum = 0;
@ -1139,7 +1161,7 @@ from_crumbs:
}
}
}
} else if ((Class == MOUSEBUTTONS) && (IEQUALIFIER_LEFTBUTTON & Qualifier) && MainDisplay) {
} else if ((msgClass == MOUSEBUTTONS) && (IEQUALIFIER_LEFTBUTTON & Qualifier) && MainDisplay) {
interfaceOff();
MainDisplay = true;
@ -1160,8 +1182,8 @@ from_crumbs:
HCPtr = NULL;
eatMessages();
if (ActionMode == 0) { /* Take something. */
if (doActionRule(Common::Point(curPos.x, curPos.y), ActionMode, _roomNum, &CPtr))
if (actionMode == 0) { /* Take something. */
if (doActionRule(Common::Point(curPos.x, curPos.y), actionMode, _roomNum, &CPtr))
CurFileName = NewFileName;
else if (takeItem(curPos.x, curPos.y, &CPtr))
drawStaticMessage(kTextTakeItem);
@ -1171,16 +1193,16 @@ from_crumbs:
CurFileName = NewFileName;
else if (curPos.y < (VGAScaleY(149) + SVGACord(2)))
drawStaticMessage(kTextNothing);
} else if ((ActionMode == 1) /* Manipulate an object */ ||
(ActionMode == 2) /* Open up a "door" */ ||
(ActionMode == 3)) { /* Close a "door" */
if (doActionRule(curPos, ActionMode, _roomNum, &CPtr))
} else if ((actionMode == 1) /* Manipulate an object */ ||
(actionMode == 2) /* Open up a "door" */ ||
(actionMode == 3)) { /* Close a "door" */
if (doActionRule(curPos, actionMode, _roomNum, &CPtr))
CurFileName = NewFileName;
else if (!doActionRule(curPos, ActionMode, 0, &CPtr)) {
else if (!doActionRule(curPos, actionMode, 0, &CPtr)) {
if (curPos.y < (VGAScaleY(149) + SVGACord(2)))
drawStaticMessage(kTextNothing);
}
} else if (ActionMode == 4) { /* Look at closeups */
} else if (actionMode == 4) { /* Look at closeups */
TempCPtr = CPtr;
setCurClose(curPos, &TempCPtr);
@ -1195,13 +1217,13 @@ from_crumbs:
drawStaticMessage(kTextNothing);
} else if (curPos.y < (VGAScaleY(149) + SVGACord(2)))
drawStaticMessage(kTextNothing);
} else if ((ActionMode == 5) &&
_conditions->in(CurInv)) { /* Use an item on something else */
if (doOperateRule(curPos.x, curPos.y, CurInv, &CPtr)) {
} else if ((actionMode == 5) &&
_conditions->in(curInv)) { /* Use an item on something else */
if (doOperateRule(curPos.x, curPos.y, curInv, &CPtr)) {
CurFileName = NewFileName;
if (!_conditions->in(CurInv))
decIncInv(&CurInv, false);
if (!_conditions->in(curInv))
decIncInv(&curInv, false);
} else if (curPos.y < (VGAScaleY(149) + SVGACord(2)))
drawStaticMessage(kTextNothing);
}
@ -1209,7 +1231,7 @@ from_crumbs:
mayShowCrumbIndicator();
WSDL_UpdateScreen();
} else if (Class == DELTAMOVE) {
} else if (msgClass == DELTAMOVE) {
VPtr = getViewData(_roomNum, Direction);
OldCPtr = VPtr->closeUps;
@ -1237,7 +1259,7 @@ from_crumbs:
if (HCPtr)
_event->setMousePos(Common::Point(scaleX((HCPtr->x1 + HCPtr->x2) / 2), scaleY((HCPtr->y1 + HCPtr->y2) / 2)));
} else if ((Class == MOUSEBUTTONS) && (IEQUALIFIER_RBUTTON & Qualifier)) {
} else if ((msgClass == MOUSEBUTTONS) && (IEQUALIFIER_RBUTTON & Qualifier)) {
eatMessages();
Alternate = !Alternate;
DoBlack = true;
@ -1247,39 +1269,18 @@ from_crumbs:
if (Alternate) {
if (LastInv && _conditions->in(LastInv))
CurInv = LastInv;
curInv = LastInv;
else
decIncInv(&CurInv, false);
decIncInv(&curInv, false);
}
drawPanel();
drawRoomMessage(CurInv, CPtr);
drawRoomMessage(curInv, CPtr);
mayShowCrumbIndicator();
WSDL_UpdateScreen();
}
}
}
delete _conditions;
delete _roomsFound;
if (_rooms) {
free(_rooms);
_rooms = nullptr;
}
if (Inventory) {
for (code = 1; code <= NumInv; code++) {
if (Inventory[code].name)
free(Inventory[code].name);
if (Inventory[code].BInvName)
free(Inventory[code].BInvName);
}
free(Inventory);
}
return true;
}
void LabEngine::go() {

View file

@ -131,6 +131,7 @@ private:
private:
bool createScreen(bool HiRes);
bool from_crumbs(uint32 tmpClass, uint16 code, uint16 Qualifier, Common::Point tmpPos, uint16 &curInv, IntuiMessage * curMsg, bool &forceDraw, uint16 gadgetId, uint16 &actionMode);
public:
void waitTOF();