Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds a basic framerate monitor and stub for benchmark app.

Squashed commit of the following:

commit 55d7581a2f3e1be2929de40c93916fa91e607765
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sat Aug 25 21:09:06 2012 -0700

    Fixes a symlink.

commit 57e7bf4b13125a359318660d85af1b3faa80866d
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sat Aug 25 21:02:46 2012 -0700

    Fixes some issues in framerate.js.

commit f15c5b0a451a278782e8bc2e9528cdcf03a153c4
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sat Aug 25 19:00:41 2012 -0700

    Stubs out Framerate a bit more.

commit dde706e942574d6eee5fd66da5e0043a9e60a9b4
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sat Aug 25 18:46:27 2012 -0700

    Starts on Framework library.
  • Loading branch information...
commit df8c33fe957c95cbf4b1a06839c883e0d252afd1 1 parent a738273
@jeremyckahn authored
View
22 ui/benchmark/index.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Pine</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta name="description" content="">
+ <meta name="author" content="">
+ </head>
+ <body>
+ <style>
+ body {
+ background: #fff;
+ }
+ </style>
+ <h1>Pine performance test</h1>
+ <script src="js/api/pine.env.js"></script>
+ <script src="js/api/pine.input.js"></script>
+ <script src="js/src/framerate.js"></script>
+ <script src="js/src/benchmark.js"></script>
+ </body>
+</html>
View
1  ui/benchmark/js/api
View
0  ui/benchmark/js/src/benchmark.js
No changes.
View
109 ui/benchmark/js/src/framerate.js
@@ -0,0 +1,109 @@
+/**
+ * Framerate.js
+ *
+ * A minimalistic framerate monitor in JavaScript.
+ * by Jeremy Kahn (jeremyckahn@gmail.com)
+ * MIT License.
+ *
+ * Usage:
+ *
+ * var framerate = new Framerate();
+ * framerate.onUpdate = function (rate) {
+ * console.log(rate);
+ * };
+ *
+ *
+ * And then, somewhere in your application code, do this once per animation
+ * frame:
+ *
+ * framerate.tick();
+ */
+;(function (global) {
+
+ 'use strict';
+
+
+ function noop () {}
+
+
+ /**
+ * @return {number}
+ */
+ function now () {
+ return +new Date();
+ }
+
+
+ /**
+ * @param {Framerate} framerate
+ * @param {number} newEpoch
+ */
+ function recycle (framerate, newEpoch) {
+ framerate._ticksAccumulated = 0;
+ framerate._cycleEpoch = newEpoch;
+ }
+
+
+ /**
+ * @param {Framerate} framerate
+ */
+ function calculateFramerate (framerate) {
+ var oldEpoch = framerate._cycleEpoch;
+ var newEpoch = now();
+ var delta = newEpoch - oldEpoch;
+ var scaledDelta = delta / 1000;
+ framerate.rate = framerate._ticksAccumulated / scaledDelta;
+ recycle(framerate, newEpoch);
+ }
+
+
+ /**
+ * @param {Framerate} framerate
+ */
+ function scheduleRecalculation (framerate) {
+ framerate._updateHandle = setTimeout(function () {
+ scheduleRecalculation(framerate);
+ calculateFramerate(framerate);
+ framerate.onUpdate(framerate.rate);
+ }, framerate._sampleRate);
+ }
+
+
+ /**
+ * @param {Object?} opts
+ * @param {number} sampleRate
+ * @constructor
+ */
+ var Framerate = global.Framerate = function (opts) {
+ opts = opts || {};
+
+ /** @type {number} */
+ this._ticksAccumulated = 0;
+
+ /** @type {number} */
+ this._sampleRate = opts.sampleRate || 500;
+
+ /** @type {number} */
+ this._cycleEpoch = now();
+
+ /** @type {number} */
+ this._updateHandle = null;
+
+ /** @type {number} */
+ this.rate = null;
+
+ /** @type {function} */
+ this.onUpdate = noop;
+
+ scheduleRecalculation(this);
+ };
+
+
+ var fn = Framerate.prototype;
+
+
+ fn.tick = function () {
+ this._ticksAccumulated++;
+ };
+
+} (this));
View
2  ui/index.html
@@ -22,7 +22,7 @@ <h1 class="welcome">Hello. Welcome to Pine.</h1>
<button class="btn main-menu-btn game-init" data-game-url="sample_game/">Sample game</button>
</li>
<li>
- <button class="btn main-menu-btn">Item 2</button>
+ <button class="btn main-menu-btn game-init" data-game-url="benchmark/">Benchmark</button>
</li>
<li>
<button class="btn main-menu-btn">Item 3</button>
Please sign in to comment.
Something went wrong with that request. Please try again.