mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Bugfixing - unsubscribing game related topics, to prevent double calls and leaking references, added offAll method to nc. fixes no rendering bug
This commit is contained in:
parent
40e396fc23
commit
39f684315b
8 changed files with 57 additions and 19 deletions
|
|
@ -14,8 +14,10 @@ function (Parent, KeyboardInput, MouseInput, Nc) {
|
||||||
this.keyboardInput = new KeyboardInput(this);
|
this.keyboardInput = new KeyboardInput(this);
|
||||||
this.xyInput = new MouseInput(this);
|
this.xyInput = new MouseInput(this);
|
||||||
|
|
||||||
Nc.on(Nc.ns.client.input.xy.change, this.setXY, this);
|
this.ncTokens = [
|
||||||
Nc.on(Nc.ns.client.input.handAction.request, this.handActionRequest, this);
|
Nc.on(Nc.ns.client.input.xy.change, this.setXY, this),
|
||||||
|
Nc.on(Nc.ns.client.input.handAction.request, this.handActionRequest, this)
|
||||||
|
];
|
||||||
|
|
||||||
var keys = {
|
var keys = {
|
||||||
w:87,
|
w:87,
|
||||||
|
|
@ -118,6 +120,11 @@ function (Parent, KeyboardInput, MouseInput, Nc) {
|
||||||
Nc.trigger(Nc.ns.client.game.gameInfo.toggle, false);
|
Nc.trigger(Nc.ns.client.game.gameInfo.toggle, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PlayerController.prototype.destroy = function() {
|
||||||
|
Nc.offAll(this.ncTokens);
|
||||||
|
Parent.prototype.destroy.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return PlayerController;
|
return PlayerController;
|
||||||
});
|
});
|
||||||
|
|
@ -265,8 +265,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
|
|
||||||
Parent.prototype.destroy.call(this);
|
Parent.prototype.destroy.call(this);
|
||||||
|
|
||||||
this.view.render();
|
this.view.destroy();
|
||||||
this.view.test();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return GameController;
|
return GameController;
|
||||||
|
|
|
||||||
|
|
@ -12,21 +12,24 @@ function (DomController, Settings, Exception, Nc) {
|
||||||
this.canvas = null;
|
this.canvas = null;
|
||||||
this.debugMode = false;
|
this.debugMode = false;
|
||||||
|
|
||||||
Nc.on(Nc.ns.client.view.mesh.create, this.createMesh, this);
|
this.ncTokens = [
|
||||||
Nc.on(Nc.ns.client.view.animatedMesh.create, this.createAnimatedMesh, this);
|
Nc.on(Nc.ns.client.view.mesh.create, this.createMesh, this),
|
||||||
Nc.on(Nc.ns.client.view.mesh.add, this.addMesh, this);
|
Nc.on(Nc.ns.client.view.animatedMesh.create, this.createAnimatedMesh, this),
|
||||||
Nc.on(Nc.ns.client.view.mesh.remove, this.removeMesh, this);
|
Nc.on(Nc.ns.client.view.mesh.add, this.addMesh, this),
|
||||||
Nc.on(Nc.ns.client.view.mesh.update, this.updateMesh, this);
|
Nc.on(Nc.ns.client.view.mesh.remove, this.removeMesh, this),
|
||||||
|
Nc.on(Nc.ns.client.view.mesh.update, this.updateMesh, this),
|
||||||
|
|
||||||
Nc.on(Nc.ns.client.view.fullscreen.change, this.onFullscreenChange, this);
|
Nc.on(Nc.ns.client.view.fullscreen.change, this.onFullscreenChange, this),
|
||||||
Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, this);
|
Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, this),
|
||||||
|
|
||||||
Nc.on(Nc.ns.client.view.playerInfo.createAndAdd, this.onCreateAndAddPlayerInfo, this);
|
Nc.on(Nc.ns.client.view.playerInfo.createAndAdd, this.onCreateAndAddPlayerInfo, this),
|
||||||
Nc.on(Nc.ns.client.view.playerInfo.update, this.onUpdatePlayerInfo, this);
|
Nc.on(Nc.ns.client.view.playerInfo.update, this.onUpdatePlayerInfo, this),
|
||||||
Nc.on(Nc.ns.client.view.playerInfo.remove, this.onRemovePlayerInfo, this);
|
Nc.on(Nc.ns.client.view.playerInfo.remove, this.onRemovePlayerInfo, this),
|
||||||
|
|
||||||
|
Nc.on(Nc.ns.client.view.preloadBar.update, this.onUpdateLoader, this),
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
Nc.on(Nc.ns.client.view.preloadBar.update, this.onUpdateLoader, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractView.prototype.isWebGlEnabled = function () {
|
AbstractView.prototype.isWebGlEnabled = function () {
|
||||||
|
|
@ -152,5 +155,11 @@ function (DomController, Settings, Exception, Nc) {
|
||||||
throw new Exception('Abstract Function onUpdateLoader not overwritten');
|
throw new Exception('Abstract Function onUpdateLoader not overwritten');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AbstractView.prototype.destroy = function() {
|
||||||
|
for (var i = 0; i < this.ncTokens.length; i++) {
|
||||||
|
Nc.off(this.ncTokens[i]);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return AbstractView;
|
return AbstractView;
|
||||||
});
|
});
|
||||||
|
|
@ -42,7 +42,7 @@ function (Parent, DomController, PIXI, Settings, Nc) {
|
||||||
console.log('CanvasRenderer - not using WebGL!')
|
console.log('CanvasRenderer - not using WebGL!')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stage = new PIXI.Stage(/*0x333333*/);
|
this.stage = new PIXI.Stage(0x333333);
|
||||||
|
|
||||||
this.initCamera();
|
this.initCamera();
|
||||||
this.initInfo();
|
this.initInfo();
|
||||||
|
|
@ -305,8 +305,15 @@ function (Parent, DomController, PIXI, Settings, Nc) {
|
||||||
this.loader.visible = progress < 100;
|
this.loader.visible = progress < 100;
|
||||||
};
|
};
|
||||||
|
|
||||||
PixiView.prototype.test = function() {
|
PixiView.prototype.destroy = function() {
|
||||||
console.log(this.stage.children)
|
|
||||||
|
for (var i = 0; i < this.stage.children.length; i++) {
|
||||||
|
this.stage.removeChild(this.stage.children[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderer.render(this.stage);
|
||||||
|
|
||||||
|
Parent.prototype.destroy.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
return PixiView;
|
return PixiView;
|
||||||
|
|
|
||||||
|
|
@ -43,5 +43,9 @@ define(function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerController.prototype.destroy = function() {
|
||||||
|
// extend if necessary
|
||||||
|
};
|
||||||
|
|
||||||
return PlayerController;
|
return PlayerController;
|
||||||
});
|
});
|
||||||
|
|
@ -17,7 +17,9 @@ function (Settings, Box2D, CollisionDetector, Nc) {
|
||||||
this.lastStep = Date.now();
|
this.lastStep = Date.now();
|
||||||
this.worldQueue = [];
|
this.worldQueue = [];
|
||||||
|
|
||||||
Nc.on(Nc.ns.channel.engine.worldQueue.add, this.addToWorldQueue, this);
|
this.ncTokens = [
|
||||||
|
Nc.on(Nc.ns.channel.engine.worldQueue.add, this.addToWorldQueue, this)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine.prototype.getWorld = function () {
|
Engine.prototype.getWorld = function () {
|
||||||
|
|
@ -62,6 +64,7 @@ function (Settings, Box2D, CollisionDetector, Nc) {
|
||||||
|
|
||||||
Engine.prototype.destroy = function() {
|
Engine.prototype.destroy = function() {
|
||||||
delete this.world;
|
delete this.world;
|
||||||
|
Nc.offAll(this.ncTokens);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,8 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
||||||
|
|
||||||
this.spectatorDoll.destroy();
|
this.spectatorDoll.destroy();
|
||||||
if(this.doll) this.doll.destroy();
|
if(this.doll) this.doll.destroy();
|
||||||
|
|
||||||
|
this.playerController.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype.setPlayerController = function(playerController) {
|
Player.prototype.setPlayerController = function(playerController) {
|
||||||
|
|
|
||||||
|
|
@ -224,5 +224,12 @@ function (Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationCenter.prototype.offAll = function (tokens) {
|
||||||
|
for (var i = 0; i < tokens.length; i++) {
|
||||||
|
this.off(tokens[i]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return new NotificationCenter(); // making it singletone
|
return new NotificationCenter(); // making it singletone
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue