mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added stats + ping, fixed box2d step size
This commit is contained in:
parent
ffb7db528a
commit
b4ef1203b1
8 changed files with 63 additions and 16 deletions
|
|
@ -6,10 +6,11 @@ define([
|
|||
"Game/Client/Control/PlayerController",
|
||||
"Game/Core/NotificationCenter",
|
||||
"Lib/Utilities/RequestAnimFrame",
|
||||
"Game/Config/Settings"
|
||||
"Game/Config/Settings",
|
||||
"Lib/Vendor/Stats"
|
||||
],
|
||||
|
||||
function (Box2D, Parent, PhysicsEngine, ViewController, PlayerController, NotificationCenter, requestAnimFrame, Settings) {
|
||||
function (Box2D, Parent, PhysicsEngine, ViewController, PlayerController, NotificationCenter, requestAnimFrame, Settings, Stats) {
|
||||
|
||||
function GameController () {
|
||||
this.viewController = new ViewController();
|
||||
|
|
@ -20,12 +21,19 @@ function (Box2D, Parent, PhysicsEngine, ViewController, PlayerController, Notifi
|
|||
|
||||
this.me = null;
|
||||
|
||||
this.initStats();
|
||||
|
||||
this.update();
|
||||
this.render();
|
||||
}
|
||||
|
||||
GameController.prototype = Object.create(Parent.prototype);
|
||||
|
||||
GameController.prototype.initStats = function() {
|
||||
this.stats = new Stats();
|
||||
this.stats.setMode(0);
|
||||
document.body.appendChild(this.stats.domElement);
|
||||
};
|
||||
|
||||
GameController.prototype.makeMouseJoint = function(p) {
|
||||
var ground = this.physicsEngine.getGround();
|
||||
var body = this.me.getBody();
|
||||
|
|
@ -54,19 +62,19 @@ function (Box2D, Parent, PhysicsEngine, ViewController, PlayerController, Notifi
|
|||
}
|
||||
|
||||
GameController.prototype.update = function () {
|
||||
this.stats.begin();
|
||||
|
||||
setTimeout(this.update.bind(this), Settings.BOX2D_TIME_STEP * 1000);
|
||||
requestAnimFrame(this.update.bind(this));
|
||||
|
||||
this.physicsEngine.update();
|
||||
|
||||
if(this.me) {
|
||||
this.me.update();
|
||||
}
|
||||
}
|
||||
|
||||
GameController.prototype.render = function() {
|
||||
requestAnimFrame(this.render.bind(this));
|
||||
this.viewController.render();
|
||||
|
||||
this.stats.end();
|
||||
}
|
||||
|
||||
GameController.prototype.onWorldUpdate = function (updateData) {
|
||||
|
|
|
|||
|
|
@ -63,8 +63,22 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
|
|||
console.log("already spawned player, options: ", options.spawnedPlayers[i])
|
||||
}
|
||||
}
|
||||
|
||||
this.initPing();
|
||||
}
|
||||
|
||||
Networker.prototype.initPing = function() {
|
||||
this.pingDOMElement = document.createElement("span");
|
||||
this.pingDOMElement.style.color = "white";
|
||||
this.pingDOMElement.style.fontFamily = "monospace";
|
||||
document.body.appendChild(this.pingDOMElement);
|
||||
this.ping();
|
||||
};
|
||||
|
||||
Networker.prototype.ping = function() {
|
||||
this.sendCommand("ping", Date.now());
|
||||
};
|
||||
|
||||
|
||||
// Sending commands
|
||||
|
||||
|
|
@ -97,6 +111,11 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
|
|||
ProtocolHelper.applyCommand(message, this.gameController);
|
||||
}
|
||||
|
||||
Networker.prototype.onPong = function(timestamp) {
|
||||
this.pingDOMElement.innerHTML = "Ping: " + (Date.now() - parseInt(timestamp, 10));
|
||||
setTimeout(this.ping.bind(this), 1000);
|
||||
};
|
||||
|
||||
return Networker;
|
||||
|
||||
});
|
||||
|
|
@ -35,11 +35,11 @@ define(requires, function (DomController, Three, Settings, CameraController) {
|
|||
preserveDrawingBuffer: true
|
||||
};
|
||||
|
||||
//if(isWebGlEnabled()) {
|
||||
if(Settings.USE_WEBGL) {
|
||||
this.renderer = new Three.WebGLRenderer(rendererOptions);
|
||||
//} else {
|
||||
//this.renderer = new Three.CanvasRenderer(rendererOptions);
|
||||
//}
|
||||
} else {
|
||||
this.renderer = new Three.CanvasRenderer(rendererOptions);
|
||||
}
|
||||
|
||||
this.renderer.setClearColor("#333333", 1);
|
||||
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue