Skip to content
Browse files

Report the number of sparks

  • Loading branch information...
1 parent 09b7346 commit 263816e06627813ab870954bda3315800e1892e4 @gfx committed
Showing with 11 additions and 3 deletions.
  1. +11 −3 Fireworks.dart
View
14 Fireworks.dart
@@ -105,6 +105,8 @@ class FireworkView {
List<Firework> fireworks;
+ int numSparks = 0;
+
FireworkView(CanvasElement canvas) : fireworks = new List<Firework>() {
cx = canvas.getContext("2d");
@@ -136,6 +138,8 @@ class FireworkView {
void update() {
if(fireworks.isEmpty()) return;
+ numSparks = 0;
+
for(int i = 0; i < fireworks.length; ++i) {
Firework fw = fireworks[i];
@@ -144,6 +148,9 @@ class FireworkView {
if(fw.dismissed()) {
fireworks.removeRange(i, 1);
}
+ else {
+ numSparks += fw.sparks.length;
+ }
}
cx.fillStyle = "rgba(0, 0, 0, 0.3)";
@@ -160,12 +167,13 @@ class FPSWatcher {
fps = 0;
}
- void update() {
+ void update(int numSparks) {
++fps;
if(watch.elapsedInMs() >= 1000) {
- String message = "FPS: $fps";
+ String message = "FPS: $fps (sparks: $numSparks)";
document.query('#fps').innerHTML = message;
+ if(numSparks > 0) print(message);
watch.reset();
fps = 0;
}
@@ -180,6 +188,6 @@ void main() {
window.setInterval(() {
view.update();
- watcher.update();
+ watcher.update(view.numSparks);
}, 0);
}

0 comments on commit 263816e

Please sign in to comment.
Something went wrong with that request. Please try again.