Skip to content

Commit 24f91b6

Browse files
author
Adam Hammer
committed
Added an upper bounds for board size which should improve
performance on large screens.
1 parent da8812e commit 24f91b6

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/src/state/actions/minesweeper_actions.dart

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ final difficultyBombPercentages = {
1818
"Hard": 0.2,
1919
};
2020

21+
//Max cells in one dimension
22+
const kMaxCells1D = 20;
23+
2124
ThunkAction<AppState> clearTiles = (store) async {
2225
var game = store.state.mineSweeper;
2326
for (int i=0;i<game.width+game.height;i++) {
@@ -35,8 +38,30 @@ class NewGameAction extends Reducer {
3538

3639
@override
3740
get reducer {
38-
final w = (width~/difficultySizes[difficulty]);
39-
final h = (height~/difficultySizes[difficulty]);
41+
var w = (width~/difficultySizes[difficulty]);
42+
var h = (height~/difficultySizes[difficulty]);
43+
44+
//Clamp to a max size (for performance)
45+
//Basically, if one aspect ratio, scale down the kMaxCells1D on X, otherwise do on Y
46+
//Maintains aspect ratio, which I want to be squareish.
47+
48+
if (w > kMaxCells1D) {
49+
final r = kMaxCells1D / w;
50+
w = kMaxCells1D;
51+
h = (h * r).toInt();
52+
}
53+
54+
/*
55+
if (w > h) {
56+
} else {
57+
if (h > kMaxCells1D) {
58+
final r = kMaxCells1D / h;
59+
h = kMaxCells1D;
60+
w = (r * kMaxCells1D).toInt();
61+
}
62+
}
63+
*/
64+
4065
return (oldState) => oldState.rebuild((b) {
4166
return b
4267
..mineSweeper.replace(MineSweeper.newGame(

lib/src/state/mine_sweeper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ abstract class MineSweeper implements Built<MineSweeper, MineSweeperBuilder> {
6969

7070
bool isInBounds(int x, int y) => x >= 0 && y >= 0 && x < width && y < height;
7171

72-
MineSweeperNode getNode({@required int x, @required int y}) {
72+
MineSweeperNode getNode({@required int x, @required int y}) {
7373
try {
7474
return nodes[x + y * width];
7575
} catch (exception) {

0 commit comments

Comments
 (0)