Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
letter performance tweaks (commit 3/3)
Browse files Browse the repository at this point in the history
  • Loading branch information
klikini committed Sep 13, 2015
1 parent 13f68c8 commit 54f7856
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
33 changes: 0 additions & 33 deletions lib/src/display/loop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,4 @@ update(double dt)
}

Wormhole.updateAll();
}

// Not run as part of the loop, only every 5 seconds
Future updatePlayerLetters() async {
Map players = {};
players.addAll(otherPlayers);
players.addAll(({game.username: CurrentPlayer}));

players.forEach((String username, Player player) async {
Element parentE = player.playerParentElement;

String username = parentE.id.replaceFirst("player-", "");
if (username.startsWith("pc-")) {
username = username.replaceFirst("pc-", "");
}

if (
mapData.hubData[currentStreet.hub_id] != null &&
mapData.hubData[currentStreet.hub_id]["players_have_letters"] != null &&
mapData.hubData[currentStreet.hub_id]["players_have_letters"] == true
) {
String letter = await HttpRequest.getString("http://${Configs.utilServerAddress}/letters/getPlayerLetter?username=$username");

DivElement letterDisplay = new DivElement()
..classes.addAll(["letter", "letter-$letter"]);

parentE
..children.removeWhere((Element e) => e.classes.contains("letter"))
..append(letterDisplay);
} else {
parentE.children.removeWhere((Element e) => e.classes.contains("letter"));
}
});
}
1 change: 1 addition & 0 deletions lib/src/display/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class UserInterface {
// The 'you won' splash
window.onBeforeUnload.listen((_) {
youWon.hidden = false;
transmit("gameUnloading");
});


Expand Down
34 changes: 32 additions & 2 deletions lib/src/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ class Game {
logmessage("Game loaded!");

new Timer.periodic(new Duration(seconds: 1), (_) => updatePlayerLetters());
new Service(["streetLoaded"], (_) {
HttpRequest.getString("http://${Configs.utilServerAddress}/letters/newPlayerLetter?username=${game.username}");
new Service(["streetLoaded", "gameUnloading"], (_) {
if (currentStreet.useLetters) {
HttpRequest.getString("http://${Configs.utilServerAddress}/letters/newPlayerLetter?username=${game.username}");
}
});

// Load previous GPS state
Expand Down Expand Up @@ -144,4 +146,32 @@ class Game {

//previousTag.makeCurrent();
}

Future updatePlayerLetters() async {
Map players = {};
players.addAll(otherPlayers);
players.addAll(({game.username: CurrentPlayer}));

players.forEach((String username, Player player) async {
Element parentE = player.playerParentElement;

String username = parentE.id.replaceFirst("player-", "");
if (username.startsWith("pc-")) {
username = username.replaceFirst("pc-", "");
}

if (currentStreet.useLetters) {
String letter = await HttpRequest.getString("http://${Configs.utilServerAddress}/letters/getPlayerLetter?username=$username");

DivElement letterDisplay = new DivElement()
..classes.addAll(["letter", "letter-$letter"]);

parentE
..children.removeWhere((Element e) => e.classes.contains("letter"))
..append(letterDisplay);
} else {
parentE.children.removeWhere((Element e) => e.classes.contains("letter"));
}
});
}
}
8 changes: 8 additions & 0 deletions lib/src/game/street.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class Street {
return currentStreetName;
}

bool get useLetters {
return (
mapData.hubData[hub_id] != null &&
mapData.hubData[hub_id]["players_have_letters"] != null &&
mapData.hubData[hub_id]["players_have_letters"] == true
);
}

Stopwatch loadTime;

Rectangle bounds;
Expand Down

0 comments on commit 54f7856

Please sign in to comment.