From 2ca0208fb056ef21226ef72df98f133a7ea6f8b2 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Thu, 11 Jul 2013 21:11:32 -0500 Subject: [PATCH] Cleanup and minor namespace change --- client/garageserver.io.js | 13 +++++++------ example/public/javascripts/game.js | 5 ++++- example/public/javascripts/gameloop.js | 13 +++++++------ lib/server/garageserver.io.js | 4 ++-- lib/server/garageservergame.js | 2 +- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/client/garageserver.io.js b/client/garageserver.io.js index 5025be4..dbf2e29 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -13,15 +13,16 @@ options = { logging: true } */ +var GarageServerIO = (function (socketio) { -window.GarageServerIO = (function (window, socketio) { + "use strict"; function StateController() { this.state = {}; - this.clientTime; - this.renderTime; - this.physicsDelta; - this.Id; + this.clientTime = 0; + this.renderTime = 0; + this.physicsDelta = 0.0; + this.Id = ''; this.pingDelay = 100; this.interpolationDelay = 100; this.interpolation = false; @@ -352,4 +353,4 @@ window.GarageServerIO = (function (window, socketio) { setState: setState }; -}) (window, io); \ No newline at end of file +}) (io); \ No newline at end of file diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index 0308df2..7501115 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -1,7 +1,10 @@ $(function () { + + "use strict"; + var canvas = document.getElementById('gameCanvas'), ctxCanvas = canvas.getContext('2d'), keyboard = new THREEx.KeyboardState(); - GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', { + GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', { logging: true, onUpdatePlayerPhysics: GamePhysics.getNewState, onInterpolation: GamePhysics.getInterpolatedState diff --git a/example/public/javascripts/gameloop.js b/example/public/javascripts/gameloop.js index a7f5718..ee74af1 100644 --- a/example/public/javascripts/gameloop.js +++ b/example/public/javascripts/gameloop.js @@ -1,14 +1,14 @@ -window.GameLoop = (function (window) { +var GameLoop = (function (window) { + "use strict"; + var requestAnimFrame = (function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); }; - })(), + }()), _currentTime = new Date().getTime(), _accumulator = 0.0, start = function (renderCallback, updateCallback) { - loop(); - - function loop () { + function loop() { requestAnimFrame(loop); var newTime = new Date().getTime(), frameTime = newTime - _currentTime; @@ -25,9 +25,10 @@ window.GameLoop = (function (window) { renderCallback(); } + loop(); }; return { start: start }; -}) (window); \ No newline at end of file +}(window)); \ No newline at end of file diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index ac8871a..bc36c0c 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -17,7 +17,7 @@ options = { } */ -function GarageServer (socketio, options) { +function GarageServer(socketio, options) { this.io = socketio; this.game = new garageServerGame(options); this.registerSocketEvents(options); @@ -30,7 +30,7 @@ GarageServer.prototype.registerSocketEvents = function (options) { if (options.logging) { console.log('garageserver.io:: socket ' + socket.id + ' connection'); } - socket.emit('state', { + socket.emit('state', { physicsDelta: (options.physicsInterval ? options.physicsInterval : 15) / 1000, smoothingFactor: options.smoothingFactor ? options.smoothingFactor : 1, interpolation: options.interpolation ? options.interpolation : false, diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index d42ab7b..fc0f8ac 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -7,7 +7,7 @@ function GarageServerGame(options) { this.playerController = new playerController(); this.entityController = new entityController(); this.options = options; - this.startTime; + this.startTime = 0; this.stateInterval = options.stateInterval ? options.stateInterval : 45; this.stateIntervalId = 0; }