Skip to content

Commit

Permalink
[#108] also moved the fps counting to the debugPanel
Browse files Browse the repository at this point in the history
FPS information is now only available through the debug panel object
(and not anymore through the HTML element)

(Only one left now : me.debug.renderCollisionMap!)
  • Loading branch information
obiot committed Aug 27, 2013
1 parent 6458e6f commit 8af7dab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
9 changes: 9 additions & 0 deletions plugins/debug/debugPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@
me.debug.renderHitBox = me.debug.renderHitBox || false;
me.debug.renderVelocity = me.debug.renderVelocity || false;

// patch video.js
me.plugin.patch(me.timer, "update", function (context) {
// call the original me.game.draw function
this.parent();

// call the FPS counter
me.timer.countFPS();
});

// patch sprite.js
me.plugin.patch(me.SpriteObject, "draw", function (context) {
// call the original me.game.draw function
Expand Down
8 changes: 0 additions & 8 deletions src/debug/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
*/
me.debug = {

/**
* enable the FPS counter <br>
* default value : false
* @type Boolean
* @memberOf me.debug
*/
displayFPS : false,

/**
* render Collision Map layer<br>
* default value : false
Expand Down
49 changes: 18 additions & 31 deletions src/video/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
---------------------------------------------*/

//hold element to display fps
var htmlCounter = null;
var debug = false;
var framecount = 0;
var framedelta = 0;

Expand All @@ -37,15 +35,6 @@
// define some step with some margin
var minstep = (1000 / me.sys.fps) * 1.25; // IS IT NECESSARY?

/**
* draw the fps counter
* @ignore
*/
function draw(fps) {
htmlCounter.replaceChild(document.createTextNode("(" + fps + "/"
+ me.sys.fps + " fps)"), htmlCounter.firstChild);
};


/*---------------------------------------------
Expand Down Expand Up @@ -76,12 +65,6 @@
* @ignore
*/
api.init = function() {
// check if we have a fps counter display in the HTML
htmlCounter = document.getElementById("framecounter");
if (htmlCounter !== null) {
me.debug.displayFPS = true;
}

// reset variables to initial state
api.reset();
};
Expand Down Expand Up @@ -113,6 +96,24 @@
return now;
};


/**
* compute the actual frame time and fps rate
* @name computeFPS
* @ignore
* @memberOf me.timer
* @function
*/
api.countFPS = function() {
framecount++;
framedelta += delta;
if (framecount % 10 == 0) {
this.fps = (~~((1000 * framecount) / framedelta)).clamp(0, me.sys.fps);
framedelta = 0;
framecount = 0;
}
};

/**
* update game tick
* should be called once a frame
Expand All @@ -124,20 +125,6 @@

delta = (now - last);

// only draw the FPS on in the HTML page
if (me.debug.displayFPS) {
framecount++;
framedelta += delta;
if (framecount % 10 == 0) {
this.fps = (~~((1000 * framecount) / framedelta)).clamp(0, me.sys.fps);
framedelta = 0;
framecount = 0;
}
// set the element in the HTML
if (htmlCounter !== null) {
draw(this.fps);
}
}
// get the game tick
api.tick = (delta > minstep && me.sys.interpolation) ? delta / step : 1;
};
Expand Down

0 comments on commit 8af7dab

Please sign in to comment.