fixes position state update and removes dev graphs for better fps

This commit is contained in:
Jeena 2015-08-02 16:06:32 +02:00
parent db95465208
commit a8adbcf140
6 changed files with 55 additions and 29 deletions

View file

@ -45,7 +45,7 @@ function(Parent, Nc, Parser, Settings) {
this.player.suicide();
};
PlayerController.prototype.mePositionStateUpdate = function(update) {
PlayerController.prototype.mePositionStateOverride = function(update) {
if(!this.player.isSpawned()) {
// 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)
};
if(true || difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
difference.y < Settings.PUNKBUSTER_DIFFERENCE_METERS) {
this.player.doll.updatePositionState(update);
} else {

View file

@ -52,7 +52,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
if(this.me) {
this.me.update();
this.mePositionStateUpdate();
this.mePositionStateOverride();
}
//for (var uid in this.gameObjects.animated) {
@ -65,9 +65,13 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
DomController.fpsStep();
};
GameController.prototype.mePositionStateUpdate = function() {
if(this.me.isPositionStateUpdateNeeded()) {
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "mePositionStateUpdate", this.me.getPositionStateUpdate());
GameController.prototype.mePositionStateOverride = function() {
if(this.me.isPositionStateOverrideNeeded()) {
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) {
this.me = new Me(user.id, this.physicsEngine, user);
this.players[user.id] = this.me;

View file

@ -51,7 +51,8 @@ function (Parent, Settings, Nc, Assert) {
this.lastServerPositionState = update;
};
Me.prototype.isPositionStateUpdateNeeded = function() {
// Checks if client should send out its position to server
Me.prototype.isPositionStateOverrideNeeded = function() {
if(!this.doll) {
return false;
@ -73,7 +74,7 @@ function (Parent, Settings, Nc, Assert) {
return false;
};
Me.prototype.getPositionStateUpdate = function() {
Me.prototype.getPositionStateOverride = function() {
return {
p: this.doll.body.GetPosition().Copy(),
lv: this.doll.body.GetLinearVelocity().Copy()

View file

@ -15,18 +15,19 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
this.stats = null;
this.ping = null;
this.nickContainer = null;
this.fpsContainer = "";
this.fpsContainer = null;
this.devToolsContainer = null;
this.frames = 0;
this.canvas = document.getElementById("canvas");
this.initDevTools();
}
DomController.prototype.initDevTools = function() {
var self = this;
var li, button, label;
this.canvas = document.getElementById("canvas");
this.devToolsContainer = document.getElementById("menuBar");
// create back to menu button
@ -48,6 +49,16 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
this.devToolsContainer.appendChild(li);
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
li = document.createElement("li");
var fpsCanvas = document.createElement("canvas");
@ -59,14 +70,6 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
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){
self.fpsContainer.innerHTML = "FPS:" + value;
@ -99,6 +102,12 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
scaleStepWidth: 0,
scaleSteps: 0
});
*/
setInterval(function() {
self.fpsContainer.innerHTML = "FPS:" + self.frames;
self.frames = 0;
}, 1000);
// create Ping: container
li = document.createElement("li");
@ -147,12 +156,13 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
};
DomController.prototype.fpsStep = function() {
this.fpsGraph.step();
this.frames++;
// this.fpsGraph.step();
};
DomController.prototype.setPing = function(ping) {
this.ping.innerHTML = "Ping:" + ping;
this.pingGraph.addValue(ping);
// this.pingGraph.addValue(ping);
};
DomController.prototype.getCanvasContainer = function () {
@ -180,13 +190,14 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
document.body.style.backgroundColor = '#aaaaaa';
this.ping.innerHTML = "Disconnected. ".replace(/ /g, '&nbsp;');
this.ping.style.color = "#ff0000";
/*
self = this;
setTimeout(function(){self.ping.innerHTML = "Reload Page...".replace(/ /g, '&nbsp;');}, 3000);
setTimeout(function(){self.ping.innerHTML = "Reload in 3...".replace(/ /g, '&nbsp;');}, 6000);
setTimeout(function(){self.ping.innerHTML = "Reload in 2...".replace(/ /g, '&nbsp;');}, 7000);
setTimeout(function(){self.ping.innerHTML = "Reload in 1...".replace(/ /g, '&nbsp;');}, 8000);
setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, '&nbsp;'); location.reload(); }, 9000);
*/
}
};

View file

@ -79,15 +79,14 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert)
continue;
}
gameObject.setUpdateData(updateData[uid]);
this.updateGameObject(gameObject, updateData[uid]);
}
};
/*
GameController.prototype.onWorldUpdateGameObject = function(body, gameObject, update) {
FIXME : call gameObject.setUpdateData(updateData[uid]);
};
*/
GameController.prototype.updateGameObject = function(gameObject, gameObjectUpdate) {
gameObject.setUpdateData(gameObjectUpdate);
}
GameController.prototype.onResetLevel = function() {
this.loadLevel(this.level.uid);

View file

@ -215,7 +215,7 @@
{
"height":0,
"id":10,
"name":"RubeDoll",
"name":"Small Cleaver",
"properties":
{