Skip to content

Commit

Permalink
Merge pull request Abacus#11 from rwldrn/cleanup
Browse files Browse the repository at this point in the history
Holy geez.
  • Loading branch information
boazsender committed Oct 16, 2011
2 parents e651cd7 + cb23cc7 commit 66914a4
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
.DS_Store
*.swp
node_modules
node_modules
dist/abacus.*
6 changes: 3 additions & 3 deletions Jakefile.js
Expand Up @@ -8,7 +8,6 @@ var // Dependency References
zlib = require( "zlib" ),
dateFormat = require( "dateformat" ),
stats = require( "stats" ),
jsonlint = require( "jsonlint" ),
cp = require("child_process"),
exec = cp.exec,
spawn = cp.spawn,
Expand Down Expand Up @@ -48,7 +47,8 @@ var // Program References
noempty: true,
evil: true,
forin: false,
maxerr: 100
maxerr: 100,
eqnull: true,
// "curly": true,
// "eqnull": true,
// "immed": true,
Expand Down Expand Up @@ -204,7 +204,7 @@ function gzip( src ) {
// Jake Tasks

desc( "Hint & Minify" );
task( "default", [ "hint", "min", "jsonlint", "deploy" ], function() {
task( "default", [ "hint", "min", "deploy" ], function() {
// Nothing
});

Expand Down
2 changes: 1 addition & 1 deletion build.json
Expand Up @@ -2,7 +2,7 @@
"files": {
"dist/abacus": {
"src": [
"src/boilerplate.js"
"src/abacus.timer.js"
],
"prehint": true,
"posthint": false,
Expand Down
11 changes: 7 additions & 4 deletions readme.md
Expand Up @@ -11,7 +11,7 @@ Once the dependencies are installed:
$ make setup

Future re-builds require _only_:

$ make

Or...
Expand Down Expand Up @@ -94,7 +94,7 @@ Make sure to join the W3C Games Community Group [[http://www.w3.org/community/ga
* language
* currency
* geolocation based lang/currency
* Input
* Input
* abstractly map a single api to as many inuts as possible
* Keyboard
* Mouse
Expand Down Expand Up @@ -129,13 +129,16 @@ Make sure to join the W3C Games Community Group [[http://www.w3.org/community/ga

## What we really want from browser vendors:
* GPU profiling
* GPU fingerprinting details
* GPU fingerprinting details
* Higher resolution timer (micros plz)


## Style Guide
We conform to the following conventions:

* Two space soft tabs
* Single quotes over double quotes
* Use a single var statement for multiple vars when possible
* Indent var lists by four spaces
* Indent var lists by four spaces

See Also: https://github.com/rwldrn/idiomatic.js
135 changes: 135 additions & 0 deletions src/abacus.timer.js
@@ -0,0 +1,135 @@
(function( window ) {

var requestAnimFrame = (function(){
// thanks paul irish
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback, element ) {
window.setTimeout( callback, 1000 / 60 );
};
})();

var Abacus = window.Abacus || {},
// An array of callbacks to call in our rAF
callbackQueue = [],
// the function we call on each tick of the rAF
timerLoop = function() {

var queueLength = callbackQueue.length,
i = queueLength - 1;

// If there are callbacks, then run the loop again
if ( queueLength ) {
requestAnimFrame( timerLoop );
}

timerLoop.running = !!queueLength;

// Iterate and execute all callbacks in the queue
for ( ; i >= 0; --i ) {
callbackQueue[ i ]();
}
},
noop = function() {},
guid = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
}).toUpperCase();
};

// Timer constructor (Internal)
function Timer( options ) {
// options is expected to have optional
// callback and element properties

options = options || {};

// Ensure an id is created for this Timer instance
this.id = options.id || guid();

// Instance tracking properties
this.lastTick = 0;
this.lastStart = 0;
this._until = 0;
this.isPaused = false;
this.timing = {
delta: 0,

// how many times callback is called
ticks: 0
};

// Define own property loop() function closure
this.loop = function() {
var now = Date.now();

this.timing.delta = now - this.lastTick;
this.lastTick = now;

// Check to see if the timer is paused, or run over until time but ran
// at least once
if ( this.isPaused ||
( this._until != null && this.lastTick - this.lastStart > this._until ) &&
this.timing.ticks !== 0 ) {

this.stop();

if ( options.complete ) {
options.complete( this.timing );
}
} else {

// If there is a callback pass the timing to it
if ( options.callback ) {
// Set the callback's context to this Timer instance
options.callback.call( this, this.timing );
}

// zero index, add after call
this.timing.ticks++;
}

}.bind( this );


// Define own property stop() function closure
this.stop = function() {

callbackQueue.splice( callbackQueue.indexOf( this.loop || noop ), 1 );

}.bind( this );

return this;
}

Timer.prototype = {
start: function( until ) {
this.lastStart = Date.now();
this._until = until;
this.lastTick = this.lastStart;
this.isPaused = false;

callbackQueue.push( this.loop );

if ( !timerLoop.running ) {
requestAnimFrame( timerLoop );
}
},
pause: function() {
this.isPaused = true;
}
};

// Wrap new Timer() construction in Abacus.timer() API
Abacus.timer = function( options ) {
return new Timer( options );
};

// Re-expose Abacus object
window.Abacus = Abacus;

})( this );
106 changes: 0 additions & 106 deletions src/boilerplate.js

This file was deleted.

7 changes: 3 additions & 4 deletions test/index.html
@@ -1,4 +1,3 @@

<!DOCTYPE html>
<html>
<head>
Expand All @@ -9,12 +8,12 @@
<link rel="Stylesheet" media="screen" href="qunit/qunit/qunit.css" />

<!-- Abacus -->
<script src="../src/boilerplate.js"></script>
<script src="../src/abacus.timer.js"></script>
<!-- tests -->
<script src="unit/timer.js"></script>
<script src="unit/abacus.timer.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit example</h1>
<h1 id="qunit-header">Abacus Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
Expand Down

0 comments on commit 66914a4

Please sign in to comment.