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

Fix various non-determinism bugs using useReducer and other guards #53

Merged
merged 30 commits into from
Sep 9, 2022

Conversation

bytewife
Copy link
Member

@bytewife bytewife commented Sep 7, 2022

There are bugs regarding floating blocks lingering when falling, floating cells not falling, and cells not updating their hasMatched variable. I believe this is due to React's async state updates, causing game logic conditionals to perform at incorrectly. Various guards have been added to ensure these things do not affect gameplay.

@bytewife bytewife requested a review from kkysen September 7, 2022 00:41
@@ -9,7 +9,7 @@ export const FallingBlock = React.memo( ({ fallingLetters, durationRate }: {fall
<FallingLetter
fallingLetterBeforeAndAfter={fallingLetterBeforeAndAfter}
durationRate={durationRate}
key={`f${fallingLetterBeforeAndAfter[0].r}${fallingLetterBeforeAndAfter[0].c}`}
key={`${Math.random()}${fallingLetterBeforeAndAfter[0].r}${fallingLetterBeforeAndAfter[0].c}`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Removed

Copy link
Member

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be typed. See the individual comments.

src/GameLoop.tsx Outdated
fallingLettersBeforeAndAfter: [],
};

const reducer = (state, action) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a better name than reducer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inlined

src/GameLoop.tsx Outdated
@@ -103,6 +103,39 @@ const timestamps = {
playerInstantDropAnimDurationMilliseconds: 0,
};

const playerCellsInit = generateUserCells();
const initialState = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this global?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

src/GameLoop.tsx Outdated
fallingLettersBeforeAndAfter: [],
};

const reducer = (state, action) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please type this. You probably won't need a default case if you type it correctly (as a discriminated union).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Do you have any suggested improvements for brevity?

src/GameLoop.tsx Outdated
const playerCellsInit = generateUserCells();
const initialState = {
boardCellMatrix: createBoard(BOARD_ROWS, BOARD_COLS),
playerPos:[...spawnPos] as const,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needs a format.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will format code afterwards

@bytewife bytewife merged commit b119b20 into falling_block Sep 9, 2022
@bytewife bytewife deleted the useReducer_refactor branch September 9, 2022 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants