From a8adbcf1404cbe489c30e08bac45fccff9737b07 Mon Sep 17 00:00:00 2001 From: Jeena Date: Sun, 2 Aug 2015 16:06:32 +0200 Subject: [PATCH] fixes position state update and removes dev graphs for better fps --- app/Game/Channel/Control/PlayerController.js | 4 +- app/Game/Client/GameController.js | 23 ++++++++++-- app/Game/Client/Me.js | 5 ++- app/Game/Client/View/DomController.js | 39 +++++++++++++------- app/Game/Core/GameController.js | 11 +++--- static/maps/tiled/debug.json | 2 +- 6 files changed, 55 insertions(+), 29 deletions(-) diff --git a/app/Game/Channel/Control/PlayerController.js b/app/Game/Channel/Control/PlayerController.js index cf7a306..8da9da3 100755 --- a/app/Game/Channel/Control/PlayerController.js +++ b/app/Game/Channel/Control/PlayerController.js @@ -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 { diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index b64ea92..39e7eb4 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -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; diff --git a/app/Game/Client/Me.js b/app/Game/Client/Me.js index 047befd..64d1e2f 100644 --- a/app/Game/Client/Me.js +++ b/app/Game/Client/Me.js @@ -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() diff --git a/app/Game/Client/View/DomController.js b/app/Game/Client/View/DomController.js index bb4c74d..f50f170 100755 --- a/app/Game/Client/View/DomController.js +++ b/app/Game/Client/View/DomController.js @@ -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, ' '); this.ping.style.color = "#ff0000"; - + /* self = this; 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 2...".replace(/ /g, ' ');}, 7000); setTimeout(function(){self.ping.innerHTML = "Reload in 1...".replace(/ /g, ' ');}, 8000); setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, ' '); location.reload(); }, 9000); + */ } }; diff --git a/app/Game/Core/GameController.js b/app/Game/Core/GameController.js index 5274bdb..04a4c6d 100755 --- a/app/Game/Core/GameController.js +++ b/app/Game/Core/GameController.js @@ -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); diff --git a/static/maps/tiled/debug.json b/static/maps/tiled/debug.json index b26ed3f..21c0db6 100644 --- a/static/maps/tiled/debug.json +++ b/static/maps/tiled/debug.json @@ -215,7 +215,7 @@ { "height":0, "id":10, - "name":"RubeDoll", + "name":"Small Cleaver", "properties": {