mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixes position state update and removes dev graphs for better fps
This commit is contained in:
parent
db95465208
commit
a8adbcf140
6 changed files with 55 additions and 29 deletions
|
|
@ -45,7 +45,7 @@ function(Parent, Nc, Parser, Settings) {
|
||||||
this.player.suicide();
|
this.player.suicide();
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerController.prototype.mePositionStateUpdate = function(update) {
|
PlayerController.prototype.mePositionStateOverride = function(update) {
|
||||||
|
|
||||||
if(!this.player.isSpawned()) {
|
if(!this.player.isSpawned()) {
|
||||||
// if someone still falls but is dead on the server already
|
// if someone still falls but is dead on the server already
|
||||||
|
|
@ -57,7 +57,7 @@ function(Parent, Nc, Parser, Settings) {
|
||||||
y: Math.abs(update.p.y - this.player.doll.body.GetPosition().y)
|
y: Math.abs(update.p.y - this.player.doll.body.GetPosition().y)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(true || difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
|
if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
|
||||||
difference.y < Settings.PUNKBUSTER_DIFFERENCE_METERS) {
|
difference.y < Settings.PUNKBUSTER_DIFFERENCE_METERS) {
|
||||||
this.player.doll.updatePositionState(update);
|
this.player.doll.updatePositionState(update);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
|
|
||||||
if(this.me) {
|
if(this.me) {
|
||||||
this.me.update();
|
this.me.update();
|
||||||
this.mePositionStateUpdate();
|
this.mePositionStateOverride();
|
||||||
}
|
}
|
||||||
|
|
||||||
//for (var uid in this.gameObjects.animated) {
|
//for (var uid in this.gameObjects.animated) {
|
||||||
|
|
@ -65,9 +65,13 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
DomController.fpsStep();
|
DomController.fpsStep();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.mePositionStateUpdate = function() {
|
GameController.prototype.mePositionStateOverride = function() {
|
||||||
if(this.me.isPositionStateUpdateNeeded()) {
|
if(this.me.isPositionStateOverrideNeeded()) {
|
||||||
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "mePositionStateUpdate", this.me.getPositionStateUpdate());
|
Nc.trigger(
|
||||||
|
Nc.ns.client.to.server.gameCommand.send,
|
||||||
|
"mePositionStateOverride",
|
||||||
|
this.me.getPositionStateOverride()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -126,6 +130,17 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
GameController.prototype.updateGameObject = function (gameObject, gameObjectUpdate) {
|
||||||
|
if(gameObject === this.me.doll) {
|
||||||
|
this.me.setLastServerPositionState(gameObjectUpdate);
|
||||||
|
if(!this.me.acceptPositionStateUpdateFromServer()) {
|
||||||
|
return; // this is to ignore own doll updates from world update
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Parent.prototype.updateGameObject.call(this, gameObject, gameObjectUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
GameController.prototype.createMe = function(user) {
|
GameController.prototype.createMe = function(user) {
|
||||||
this.me = new Me(user.id, this.physicsEngine, user);
|
this.me = new Me(user.id, this.physicsEngine, user);
|
||||||
this.players[user.id] = this.me;
|
this.players[user.id] = this.me;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,8 @@ function (Parent, Settings, Nc, Assert) {
|
||||||
this.lastServerPositionState = update;
|
this.lastServerPositionState = update;
|
||||||
};
|
};
|
||||||
|
|
||||||
Me.prototype.isPositionStateUpdateNeeded = function() {
|
// Checks if client should send out its position to server
|
||||||
|
Me.prototype.isPositionStateOverrideNeeded = function() {
|
||||||
|
|
||||||
if(!this.doll) {
|
if(!this.doll) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -73,7 +74,7 @@ function (Parent, Settings, Nc, Assert) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Me.prototype.getPositionStateUpdate = function() {
|
Me.prototype.getPositionStateOverride = function() {
|
||||||
return {
|
return {
|
||||||
p: this.doll.body.GetPosition().Copy(),
|
p: this.doll.body.GetPosition().Copy(),
|
||||||
lv: this.doll.body.GetLinearVelocity().Copy()
|
lv: this.doll.body.GetLinearVelocity().Copy()
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,19 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
|
||||||
this.stats = null;
|
this.stats = null;
|
||||||
this.ping = null;
|
this.ping = null;
|
||||||
this.nickContainer = null;
|
this.nickContainer = null;
|
||||||
this.fpsContainer = "";
|
this.fpsContainer = null;
|
||||||
this.devToolsContainer = null;
|
this.devToolsContainer = null;
|
||||||
|
this.frames = 0;
|
||||||
|
|
||||||
|
this.canvas = document.getElementById("canvas");
|
||||||
|
|
||||||
this.initDevTools();
|
this.initDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
DomController.prototype.initDevTools = function() {
|
DomController.prototype.initDevTools = function() {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var li, button, label;
|
var li, button, label;
|
||||||
|
|
||||||
this.canvas = document.getElementById("canvas");
|
|
||||||
this.devToolsContainer = document.getElementById("menuBar");
|
this.devToolsContainer = document.getElementById("menuBar");
|
||||||
|
|
||||||
// create back to menu button
|
// create back to menu button
|
||||||
|
|
@ -48,6 +49,16 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
|
||||||
this.devToolsContainer.appendChild(li);
|
this.devToolsContainer.appendChild(li);
|
||||||
this.nickContainer = label;
|
this.nickContainer = label;
|
||||||
|
|
||||||
|
|
||||||
|
// create fps label with updater
|
||||||
|
li = document.createElement("li");
|
||||||
|
label = document.createElement("label");
|
||||||
|
label.id = "label-fps";
|
||||||
|
li.appendChild(label);
|
||||||
|
this.devToolsContainer.appendChild(li);
|
||||||
|
this.fpsContainer = label;
|
||||||
|
|
||||||
|
/*
|
||||||
// create new fps meter
|
// create new fps meter
|
||||||
li = document.createElement("li");
|
li = document.createElement("li");
|
||||||
var fpsCanvas = document.createElement("canvas");
|
var fpsCanvas = document.createElement("canvas");
|
||||||
|
|
@ -59,14 +70,6 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
|
||||||
|
|
||||||
this.fpsGraph = new Graph(fpsCanvas.getContext("2d"), true);
|
this.fpsGraph = new Graph(fpsCanvas.getContext("2d"), true);
|
||||||
|
|
||||||
// create fps label with updater
|
|
||||||
li = document.createElement("li");
|
|
||||||
label = document.createElement("label");
|
|
||||||
label.id = "label-fps";
|
|
||||||
li.appendChild(label);
|
|
||||||
this.devToolsContainer.appendChild(li);
|
|
||||||
this.fpsContainer = label;
|
|
||||||
|
|
||||||
this.fpsGraph.onUpdate(function(value){
|
this.fpsGraph.onUpdate(function(value){
|
||||||
self.fpsContainer.innerHTML = "FPS:" + value;
|
self.fpsContainer.innerHTML = "FPS:" + value;
|
||||||
|
|
||||||
|
|
@ -99,6 +102,12 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
|
||||||
scaleStepWidth: 0,
|
scaleStepWidth: 0,
|
||||||
scaleSteps: 0
|
scaleSteps: 0
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
setInterval(function() {
|
||||||
|
self.fpsContainer.innerHTML = "FPS:" + self.frames;
|
||||||
|
self.frames = 0;
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
// create Ping: container
|
// create Ping: container
|
||||||
li = document.createElement("li");
|
li = document.createElement("li");
|
||||||
|
|
@ -147,12 +156,13 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
|
||||||
};
|
};
|
||||||
|
|
||||||
DomController.prototype.fpsStep = function() {
|
DomController.prototype.fpsStep = function() {
|
||||||
this.fpsGraph.step();
|
this.frames++;
|
||||||
|
// this.fpsGraph.step();
|
||||||
};
|
};
|
||||||
|
|
||||||
DomController.prototype.setPing = function(ping) {
|
DomController.prototype.setPing = function(ping) {
|
||||||
this.ping.innerHTML = "Ping:" + ping;
|
this.ping.innerHTML = "Ping:" + ping;
|
||||||
this.pingGraph.addValue(ping);
|
// this.pingGraph.addValue(ping);
|
||||||
};
|
};
|
||||||
|
|
||||||
DomController.prototype.getCanvasContainer = function () {
|
DomController.prototype.getCanvasContainer = function () {
|
||||||
|
|
@ -180,13 +190,14 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
|
||||||
document.body.style.backgroundColor = '#aaaaaa';
|
document.body.style.backgroundColor = '#aaaaaa';
|
||||||
this.ping.innerHTML = "Disconnected. ".replace(/ /g, ' ');
|
this.ping.innerHTML = "Disconnected. ".replace(/ /g, ' ');
|
||||||
this.ping.style.color = "#ff0000";
|
this.ping.style.color = "#ff0000";
|
||||||
|
/*
|
||||||
self = this;
|
self = this;
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload Page...".replace(/ /g, ' ');}, 3000);
|
setTimeout(function(){self.ping.innerHTML = "Reload Page...".replace(/ /g, ' ');}, 3000);
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload in 3...".replace(/ /g, ' ');}, 6000);
|
setTimeout(function(){self.ping.innerHTML = "Reload in 3...".replace(/ /g, ' ');}, 6000);
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload in 2...".replace(/ /g, ' ');}, 7000);
|
setTimeout(function(){self.ping.innerHTML = "Reload in 2...".replace(/ /g, ' ');}, 7000);
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload in 1...".replace(/ /g, ' ');}, 8000);
|
setTimeout(function(){self.ping.innerHTML = "Reload in 1...".replace(/ /g, ' ');}, 8000);
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, ' '); location.reload(); }, 9000);
|
setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, ' '); location.reload(); }, 9000);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,15 +79,14 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameObject.setUpdateData(updateData[uid]);
|
this.updateGameObject(gameObject, updateData[uid]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
GameController.prototype.onWorldUpdateGameObject = function(body, gameObject, update) {
|
GameController.prototype.updateGameObject = function(gameObject, gameObjectUpdate) {
|
||||||
FIXME : call gameObject.setUpdateData(updateData[uid]);
|
gameObject.setUpdateData(gameObjectUpdate);
|
||||||
};
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
GameController.prototype.onResetLevel = function() {
|
GameController.prototype.onResetLevel = function() {
|
||||||
this.loadLevel(this.level.uid);
|
this.loadLevel(this.level.uid);
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
"id":10,
|
"id":10,
|
||||||
"name":"RubeDoll",
|
"name":"Small Cleaver",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue