Permalink
Browse files

Proper object count calculation

  • Loading branch information...
1 parent 6b90bf2 commit 3998419999b9b23f6f74c9475bd137fb4e769567 @strager strager committed Mar 2, 2012
Showing with 22 additions and 67 deletions.
  1. +1 −37 bin/condense.js
  2. +21 −30 js/tests/sprites.js
View
@@ -60,9 +60,7 @@ un.require( ['util/report'], function(report){
var translate = spriteResults.translate;
var vals = [null];
if( translate ){
- var val = actualObjectCountFromRawData( translate.rawData );
-// vals = [translate.objectCount];
- vals = [val];
+ vals = [translate.objectCount];
if(!basicDataStructure[type]){
basicDataStructure[type] = {};
@@ -201,40 +199,6 @@ un.require( ['util/report'], function(report){
}
});
-function actualObjectCountFromRawData( rawData ){
-
- console.log( "---" );
- console.log( rawData.map( function(obj){ return [obj[0], obj[1].fps]; } ) );
-
- var mostObjectsAboveThirtyFPS = -1;
- var minObjectsBelowThirtyFPS = -1;
- for( var i = 0; i < rawData.length; i++ ){
- var temp = rawData[i];
- if( temp[1].fps > 30 ){
- if( mostObjectsAboveThirtyFPS === -1 || temp[0] > rawData[mostObjectsAboveThirtyFPS][0] ){
- mostObjectsAboveThirtyFPS = i;
- }
- }else{
- if( minObjectsBelowThirtyFPS === -1 || temp[0] < rawData[minObjectsBelowThirtyFPS][0] ){
- minObjectsBelowThirtyFPS = i;
- }
- }
- }
- if( mostObjectsAboveThirtyFPS === -1 || minObjectsBelowThirtyFPS === -1 ){
- throw new Error("uh oh, no valid answer could be found");
- }
- var m = ( rawData[mostObjectsAboveThirtyFPS][0] - rawData[minObjectsBelowThirtyFPS][0] ) /
- ( rawData[mostObjectsAboveThirtyFPS][1].fps - rawData[minObjectsBelowThirtyFPS][1].fps );
- var dx = 30 - rawData[minObjectsBelowThirtyFPS][1].fps;
- var answer = rawData[minObjectsBelowThirtyFPS][0] + m*dx;
-
- console.log( "below 30 hz:", rawData[ minObjectsBelowThirtyFPS ][0] );
- console.log( "above 30 hz:", rawData[ mostObjectsAboveThirtyFPS ][0] );
- console.log( "answer:", answer );
-
- return answer;
-}
-
function fpsForObjectCount( data, objectCount ){
for( var i = 0; i < data.length; i++ ){
if( data[i][0] === objectCount ){
View
@@ -66,44 +66,36 @@ define([ 'sprites/sources', 'sprites/transformers', 'sprites/renderers', 'util/e
// objectCount => { js, fps }
var fpsResults = { };
- // fps => objectCount
- var fpsLut = { };
-
+ // (objectCount, { js, fps })
var rawData = [ ];
function done() {
- // Linearly interpolate framerate between two closest to
- // targetFramerate
-
- var fpsAbove = Infinity;
- var objAbove = Infinity;
-
- var fpsBelow = -Infinity;
- var objBelow = -Infinity;
-
- Object.keys(fpsLut).forEach(function (fps) {
- var objectCount = fpsLut[fps];
- fps = +fps; // Number cast
-
- if (fps >= targetFramerate && fps < fpsAbove) {
- fpsAbove = fps;
- objAbove = objectCount;
- }
-
- if (fps <= targetFramerate && fps > fpsBelow) {
- fpsBelow = fps;
- objBelow = objectCount;
+ var mostObjectsAboveThirtyFPS = -1;
+ var minObjectsBelowThirtyFPS = -1;
+ for (var i = 0; i < rawData.length; i++) {
+ var temp = rawData[i];
+ if (temp[1].fps > 30) {
+ if (mostObjectsAboveThirtyFPS === -1 || temp[0] > rawData[mostObjectsAboveThirtyFPS][0]) {
+ mostObjectsAboveThirtyFPS = i;
+ }
+ } else {
+ if (minObjectsBelowThirtyFPS === -1 || temp[0] < rawData[minObjectsBelowThirtyFPS][0]) {
+ minObjectsBelowThirtyFPS = i;
+ }
}
- });
+ }
- if (!isFinite(fpsAbove) || !isFinite(fpsBelow)) {
+ if (mostObjectsAboveThirtyFPS === -1 || minObjectsBelowThirtyFPS === -1) {
callback(new Error("Bad test results"));
return;
}
- var x = (fpsAbove - fpsBelow) / fpsBelow;
- var objectCount = x * objBelow + (1 - x) * objAbove;
- var jsTime = x * fpsResults[objBelow].js + (1 - x) * fpsResults[objAbove].js;
+ var aboveData = rawData[mostObjectsAboveThirtyFPS];
+ var belowData = rawData[minObjectsBelowThirtyFPS];
+
+ var m = (aboveData[0] - belowData[0]) / (aboveData[1].fps - belowData[1].fps);
+ var objectCount = belowData[0] + m * (30 - belowData[1].fps);
+ var jsTime = belowData[0] + m * (30 - belowData[1].js);
callback(null, {
objectCount: objectCount,
@@ -129,7 +121,6 @@ define([ 'sprites/sources', 'sprites/transformers', 'sprites/renderers', 'util/e
if (err) return callback(err);
fpsResults[objectCount] = results;
- fpsLut[results.fps] = objectCount;
rawData.push([ objectCount, results ]);
if (results.fps < targetFramerate) {

0 comments on commit 3998419

Please sign in to comment.