diff --git a/client/garageserver.io.js b/client/garageserver.io.js index 016b314..9be488c 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -133,6 +133,7 @@ window.GarageServerIO = (function (window, socketio) { _stateController = new StateController(), _inputController = new InputController(), _playerController = new PlayerController(), + _fps = 0, _fpsLastUpdate = (new Date()) * 1 - 1, _fpsFilter = 50, connectToGarageServer = function (path, opts) { _options = opts; @@ -315,6 +316,14 @@ window.GarageServerIO = (function (window, socketio) { amount = parseFloat((difference / range).toFixed(3)); return amount; + }, + + getFPS = function () { + var now; + var thisFrameFPS = 1000 / ((now = new Date()) - _fpsLastUpdate); + _fps += (thisFrameFPS - _fps) / _fpsFilter; + _fpsLastUpdate = now; + return Math.round(_fps); }; return { @@ -322,7 +331,8 @@ window.GarageServerIO = (function (window, socketio) { addPlayerInput: addPlayerInput, getPlayerStates: getPlayerStates, getPlayerId: getPlayerId, - setPlayerState: setPlayerState + setPlayerState: setPlayerState, + getFPS: getFPS }; }) (window, io); \ No newline at end of file diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index 0d851a2..b4db930 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -33,19 +33,9 @@ $(function () { }); var gameCanvas = document.getElementById('gameCanvas'), - keyboard = new THREEx.KeyboardState(), - ctxGameCanvas = gameCanvas.getContext('2d'), - fps = 0, - - now, - - lastUpdate = (new Date()) * 1 - 1, - - fpsFilter = 50, - requestAnimFrame = (function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); }; })(), @@ -80,11 +70,7 @@ $(function () { draw(); - var thisFrameFPS = 1000 / ((now = new Date()) - lastUpdate); - fps += (thisFrameFPS - fps) / fpsFilter; - lastUpdate = now; - - $('#fps').html('FPS: ' + Math.round(fps)); + $('#fps').html('FPS: ' + GarageServerIO.getFPS()); }; update();