From 84a98df77a01b0ee9f95e03aca0c8c9126effa61 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Fri, 27 Oct 2017 10:54:26 +0200 Subject: [PATCH] cleanup subscriptions --- src/game-lib-system-linking.js | 186 ++++++++++++++++++++++----------- 1 file changed, 127 insertions(+), 59 deletions(-) diff --git a/src/game-lib-system-linking.js b/src/game-lib-system-linking.js index cbaf3ac..7b717e2 100644 --- a/src/game-lib-system-linking.js +++ b/src/game-lib-system-linking.js @@ -20,15 +20,26 @@ GameLib.System.Linking = function( * @type {{}} */ this.dependencies = {}; - - + this.resolved = []; - this.imageNotFoundSubscription = null; + /** + * Components + */ this.componentCreatedSubscription = null; + this.registerDependenciesSubscription = null; + + /** + * Parents + */ this.parentSceneChangeSubscription = null; this.parentWorldChangeSubscription = null; this.parentEntityChangeSubscription = null; + + /** + * Instances + */ + this.instanceCreatedSubscription = null; this.meshInstanceCreatedSubscription = null; this.lightInstanceCreatedSubscription = null; this.sceneInstanceCreatedSubscription = null; @@ -36,15 +47,29 @@ GameLib.System.Linking = function( this.fontInstanceCreatedSubscription = null; this.textureInstanceCreatedSubscription = null; this.materialInstanceCreatedSubscription = null; - this.meshDeletedSubscription = null; - this.imageChangedSubscription = null; - this.materialTypeChangedSubscription = null; - this.arrayItemAddedSubscription = null; - this.instanceCreatedSubscription = null; this.shapeInstanceCreatedSubscription = null; this.solverInstanceCreatedSubscription = null; - this.registerDependenciesSubscription = null; + this.physicsWorldInstanceCreatedSubscription = null; + /** + * Meshes + */ + this.meshDeletedSubscription = null; + + /** + * Images + */ + this.imageChangedSubscription = null; + + /** + * Materials + */ + this.materialTypeChangedSubscription = null; + + /** + * Arrays + */ + this.arrayItemAddedSubscription = null; }; GameLib.System.Linking.prototype = Object.create(GameLib.System.prototype); @@ -54,11 +79,22 @@ GameLib.System.Linking.prototype.start = function() { GameLib.System.prototype.start.call(this); + /** + * Components + */ this.componentCreatedSubscription = this.subscribe( GameLib.Event.COMPONENT_CREATED, this.componentCreated.bind(this) ); + this.registerDependenciesSubscription = this.subscribe( + GameLib.Event.REGISTER_DEPENDENCIES, + this.registerDependenciesDirect + ); + + /** + * Parents + */ this.parentSceneChangeSubscription = this.subscribe( GameLib.Event.PARENT_SCENE_CHANGE, this.onParentSceneChange @@ -74,9 +110,12 @@ GameLib.System.Linking.prototype.start = function() { this.onParentEntityChange ); - this.sceneInstanceCreatedSubscription = this.subscribe( - GameLib.Event.SCENE_INSTANCE_CREATED, - this.sceneInstanceCreated + /** + * Instances + */ + this.instanceCreatedSubscription = this.subscribe( + GameLib.Event.INSTANCE_CREATED, + this.instanceCreated ); this.meshInstanceCreatedSubscription = this.subscribe( @@ -89,6 +128,11 @@ GameLib.System.Linking.prototype.start = function() { this.lightInstanceCreated ); + this.sceneInstanceCreatedSubscription = this.subscribe( + GameLib.Event.SCENE_INSTANCE_CREATED, + this.sceneInstanceCreated + ); + this.imageInstanceCreatedSubscription = this.subscribe( GameLib.Event.IMAGE_INSTANCE_CREATED, this.imageInstanceCreated @@ -109,41 +153,6 @@ GameLib.System.Linking.prototype.start = function() { this.materialInstanceCreated ); - this.physicsWorldInstanceCreatedSubscription = this.subscribe( - GameLib.Event.PHYSICS_WORLD_INSTANCE_CREATED, - this.physicsWorldInstanceCreated - ); - - this.imageNotFoundSubscription = this.subscribe( - GameLib.Event.IMAGE_NOT_FOUND, - this.imageNotFound - ); - - this.meshDeletedSubscription = this.subscribe( - GameLib.Event.MESH_DELETED, - this.meshDeleted - ); - - this.imageChangedSubscription = this.subscribe( - GameLib.Event.IMAGE_CHANGED, - this.imageChanged - ); - - this.materialTypeChangedSubscription = this.subscribe( - GameLib.Event.MATERIAL_TYPE_CHANGED, - this.materialTypeChanged - ); - - this.instanceCreatedSubscription = this.subscribe( - GameLib.Event.INSTANCE_CREATED, - this.instanceCreated - ); - - this.arrayItemAddedSubscription = this.subscribe( - GameLib.Event.ARRAY_ITEM_ADDED, - this.arrayItemAdded - ); - this.shapeInstanceCreatedSubscription = this.subscribe( GameLib.Event.SHAPE_INSTANCE_CREATED, this.shapeInstanceCreated @@ -154,10 +163,43 @@ GameLib.System.Linking.prototype.start = function() { this.solverInstanceCreated ); - this.registerDependenciesSubscription = this.subscribe( - GameLib.Event.REGISTER_DEPENDENCIES, - this.registerDependenciesDirect - ) + this.physicsWorldInstanceCreatedSubscription = this.subscribe( + GameLib.Event.PHYSICS_WORLD_INSTANCE_CREATED, + this.physicsWorldInstanceCreated + ); + + + /** + * Meshes + */ + this.meshDeletedSubscription = this.subscribe( + GameLib.Event.MESH_DELETED, + this.meshDeleted + ); + + /** + * Images + */ + this.imageChangedSubscription = this.subscribe( + GameLib.Event.IMAGE_CHANGED, + this.imageChanged + ); + + /** + * Materials + */ + this.materialTypeChangedSubscription = this.subscribe( + GameLib.Event.MATERIAL_TYPE_CHANGED, + this.materialTypeChanged + ); + + /** + * Arrays + */ + this.arrayItemAddedSubscription = this.subscribe( + GameLib.Event.ARRAY_ITEM_ADDED, + this.arrayItemAdded + ); }; @@ -1051,11 +1093,23 @@ GameLib.System.Linking.prototype.meshDeleted = function(data) { GameLib.System.Linking.prototype.stop = function() { GameLib.System.prototype.stop.call(this); - this.imageNotFoundSubscription.remove(); + /** + * Components + */ this.componentCreatedSubscription.remove(); + this.registerDependenciesSubscription.remove(); + + /** + * Parents + */ this.parentSceneChangeSubscription.remove(); this.parentWorldChangeSubscription.remove(); this.parentEntityChangeSubscription.remove(); + + /** + * Instances + */ + this.instanceCreatedSubscription.remove(); this.meshInstanceCreatedSubscription.remove(); this.lightInstanceCreatedSubscription.remove(); this.sceneInstanceCreatedSubscription.remove(); @@ -1063,14 +1117,28 @@ GameLib.System.Linking.prototype.stop = function() { this.fontInstanceCreatedSubscription.remove(); this.textureInstanceCreatedSubscription.remove(); this.materialInstanceCreatedSubscription.remove(); - this.meshDeletedSubscription.remove(); - this.imageChangedSubscription.remove(); - this.materialTypeChangedSubscription.remove(); - this.instanceCreatedSubscription.remove(); - this.arrayItemAddedSubscription.remove(); - this.physicsWorldInstanceCreatedSubscription.remove(); this.shapeInstanceCreatedSubscription.remove(); this.solverInstanceCreatedSubscription.remove(); - this.registerDependenciesSubscription.remove(); + this.physicsWorldInstanceCreatedSubscription.remove(); + + /** + * Meshes + */ + this.meshDeletedSubscription.remove(); + + /** + * Images + */ + this.imageChangedSubscription.remove(); + + /** + * Materials + */ + this.materialTypeChangedSubscription.remove(); + + /** + * Arrays + */ + this.arrayItemAddedSubscription.remove(); };