-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Twos code cleanup #1220
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
Twos code cleanup #1220
Conversation
FintasticMan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to use std::array instead of raw arrays? It should be possible to just replace the raw arrays with std::array because nCols, nRows and nCells are constexpr.
|
I had the same thought, but I'm not sure it'll help to make the code more readable. For example |
| TwosTile grid[4][4]; | ||
| static constexpr int nCols = 4; | ||
| static constexpr int nRows = 4; | ||
| static constexpr int nCells = nCols * nRows; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that a lot of the variables here are full (unsigned) ints, but they could just be (u)int8_ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that sometimes using smaller integers results in a larger binary size. These specifically don't make a difference, but if tryMerge() and tryMove() functions used uint8_t, the binary size would increase. This is why I'm not always sure which is best to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm interesting... Maybe with smaller integers the compiler isn't able to do as many optimisations? Anyway, if it increases the binary size, I don't see much benifit to using smaller integers.
Made the interface slightly larger.
Removed magic row and col counts. The size can be increased to 5x5 for example just by incrementing a value.
Fixed many warnings.
Reduced for loop count. Each either save a few bytes or no change.
Reduced library dependency.
In
updateGridDisplay()only a for loop was removed and the indentation changed. The diff looks more complicated.