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);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ define({
|
|||
BOX2D_GRAVITY: 16,
|
||||
BOX2D_VELOCITY_ITERATIONS: 5,
|
||||
BOX2D_POSITION_ITERATIONS: 5,
|
||||
BOX2D_TIME_STEP: 1 / 30,
|
||||
BOX2D_TIME_STEP: 1 / 60,
|
||||
|
||||
// GRAPHIC PATHS
|
||||
GRAPHICS_PATH: 'static/img/',
|
||||
|
|
@ -43,8 +43,9 @@ define({
|
|||
// BROWSER
|
||||
CANVAS_DOM_ID: 'canvasContainer',
|
||||
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
||||
USE_WEGBL: true,
|
||||
|
||||
DEBUG_MODE: true,
|
||||
DEBUG_MODE: false,
|
||||
|
||||
// NETWORKING
|
||||
WORLD_UPDATE_BROADCAST_INTERVAL: 70
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ function (Settings, Box2D, CollisionDetector) {
|
|||
Settings.BOX2D_ALLOW_SLEEP
|
||||
);
|
||||
this.ground = null;
|
||||
this.lastStep = Date.now();
|
||||
console.log(Settings.BOX2D_TIME_STEP)
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +37,9 @@ function (Settings, Box2D, CollisionDetector) {
|
|||
}
|
||||
|
||||
Engine.prototype.update = function () {
|
||||
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
var stepLength = (Date.now() - this.lastStep) / 1000;
|
||||
this.world.Step(stepLength, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
this.lastStep = Date.now();
|
||||
this.world.ClearForces();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue