Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOHAWK: MYST: Turn held page state into an enum #1165

Merged
merged 3 commits into from Apr 25, 2018
Merged

Conversation

@dafioram
Copy link
Member

dafioram commented Apr 23, 2018

Previously, the held page stage was an unsigned int 16
with values 0-13. The enum will make its state more clear.

Because enums are implicitly ints in c++03 and _global->heldPage
is an uint16 I have to typecast to uint16 when ever I compare
the enum. This is not ideal, but I still think the enum with
the cast is more clear.

I have also noted interesting behavior as TODO's.

@bonki
Copy link
Member

bonki commented Apr 23, 2018

Our code formatting conventions require that there be no whitespace after a cast.

Then again, why not change _globals.heldPage to be of type HeldPage?

@dafioram
Copy link
Member Author

dafioram commented Apr 23, 2018

I can make that change in /engines/mohawk/myst_state.h#L84, but how would I make that work with syncAsUint16LE() in engines/mohawk/myst_state.cpp#L313?

@bonki
Copy link
Member

bonki commented Apr 23, 2018

IIRC the serializer's syncAs-methods are templated so it should just work.

@@ -1148,40 +1148,40 @@ void Myst::o_bookGivePage(uint16 var, const ArgumentsArray &args) {
uint16 mask = 0;

switch (_globals.heldPage) {

This comment has been minimized.

Copy link
@bonki

bonki Apr 23, 2018

Member

This now needs an empty default case or will otherwise generate a compiler warning because of unhandled enum values.

This comment has been minimized.

Copy link
@dafioram

dafioram Apr 23, 2018

Author Member

That is an easy fix.

Interestingly case 13/kWhitePage is handled separately above and not in the case statement.

This comment has been minimized.

Copy link
@bonki

bonki Apr 23, 2018

Member

Indeed, maybe L1142-44 should be merged into the switch.

@dafioram dafioram force-pushed the dafioram:mystPageEnum branch from 588c0d3 to c6715f3 Apr 24, 2018
@dafioram
Copy link
Member Author

dafioram commented Apr 24, 2018

Done.

@@ -121,13 +121,13 @@ bool MystGameState::load(int slot) {

// Set our default cursor
_vm->_cursor->showCursor();
if (_globals.heldPage == 0 || _globals.heldPage > 13)
if (_globals.heldPage == kNoPage || _globals.heldPage > kWhitePage) // TODO: This second condition can never happen

This comment has been minimized.

Copy link
@bgK

bgK Apr 24, 2018

Member

Please remove the condition since it can't happen.

if (_gameState->_globals.currentAge == 2)
redrawArea(25);
} else if (page == 10) {
} else if (page == kRedStoneshipPage) { //TODO: Should this also happen for the blue page above?

This comment has been minimized.

Copy link
@bgK

bgK Apr 24, 2018

Member

This code is checked against the disassembly, so no, it does not need to happen in other cases.

uint16 bookVar = 101;
uint16 mask = 0;

switch (_globals.heldPage) {
case 7:
case kNoPage:

This comment has been minimized.

Copy link
@bgK

bgK Apr 24, 2018

Member

Here you can collapse the kNoPage and kWhitePage cases. Also the break can be removed since return already exits the function.

@dafioram dafioram force-pushed the dafioram:mystPageEnum branch from c6715f3 to 8018b9e Apr 24, 2018
@dafioram
Copy link
Member Author

dafioram commented Apr 24, 2018

Done.

Ignoring the fireplace pages, any idea why the kRedStoneshipPage is redrawn differently then the other red pages when it is dropped and the current age == 1? While the blue page in the stoneship age redrawArea is handled like the other blue pages being dropped?

@dafioram dafioram force-pushed the dafioram:mystPageEnum branch from 8018b9e to a4bb9a4 Apr 24, 2018
uint16 bookVar = 101;
uint16 mask = 0;

switch (_globals.heldPage) {
case 7:
case kNoPage:
// fallthrough

This comment has been minimized.

Copy link
@bgK

bgK Apr 24, 2018

Member

No need to put a fallthrough marker if there is no code in the case. It's used to tell the compiler we didn't forget a break. Here it's obvious the fallthrough is intentional.

if (_gameState->_globals.currentAge == 2)
redrawArea(25);
} else if (page == 10) {
} else if (page == kRedStoneshipPage) { // This code was checked against the disassembly and

This comment has been minimized.

Copy link
@bgK

bgK Apr 24, 2018

Member

The whole thing is checked. It does not make sense to add that comment here.

@bgK
Copy link
Member

bgK commented Apr 24, 2018

Ignoring the fireplace pages, any idea why the kRedStoneshipPage is redrawn differently then the other red pages when it is dropped and the current age == 1? While the blue page in the stoneship age redrawArea is handled like the other blue pages being dropped?

The red stoneship page case is different because there are three cases. The drawer is closed. The drawer is open but there is no page, the drawer is open and there is a red page. See

case 35: // Sirrus' Room Drawer #4 (Bottom) Open and Red Page State
.

_vm->setMainCursor(kRedPageCursor);
else // if (globals.heldPage == 13)
else // if (globals.heldPage == kWhitePage), i.e., the white page is held

This comment has been minimized.

Copy link
@bonki

bonki Apr 24, 2018

Member

Are these comments necessary?

dafioram added 3 commits Apr 23, 2018
Previously, the held page stage was an unsigned int 16
with values 0-13. The enum will make its state more clear.

I have also noted interesting behavior as TODO's.
Two of the cases were being handled before the switch
statement and I moved them into the switch statement.

This prevents a compile warning of not all enums
being used.
Two TODOs were added two commits ago and this
commit addresses both of them.

The first deals with a conditional checking if a
heldPage is greater than the kWhitePage which
can never happen since the kWhitePage is
numerically the last page.

The second was a curious cases were a set of conditions
for droping a page did't have the same checks for checking
dropping a blue page as it did a red page. It matches
the disassembly.
@dafioram dafioram force-pushed the dafioram:mystPageEnum branch from a4bb9a4 to cf56853 Apr 24, 2018
@dafioram
Copy link
Member Author

dafioram commented Apr 24, 2018

Done.

@bgK bgK merged commit 519e02d into scummvm:master Apr 25, 2018
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@bgK
Copy link
Member

bgK commented Apr 25, 2018

Very good, thanks

@dafioram dafioram deleted the dafioram:mystPageEnum branch Jun 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.