diff --git a/src/game-lib-api-mouse.js b/src/game-lib-api-mouse.js index db77b28..c51b85c 100644 --- a/src/game-lib-api-mouse.js +++ b/src/game-lib-api-mouse.js @@ -20,13 +20,6 @@ GameLib.API.Mouse = function( } this.parentEntity = parentEntity; - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_MOUSE, - null, - parentEntity - ); - if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } diff --git a/src/game-lib-d3-coder.js b/src/game-lib-d3-coder.js index e908934..66de3c7 100644 --- a/src/game-lib-d3-coder.js +++ b/src/game-lib-d3-coder.js @@ -39,6 +39,11 @@ GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR = 0x1; */ GameLib.D3.Coder.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) { diff --git a/src/game-lib-d3-helper.js b/src/game-lib-d3-helper.js index 6352c0a..978e4e3 100644 --- a/src/game-lib-d3-helper.js +++ b/src/game-lib-d3-helper.js @@ -93,6 +93,11 @@ GameLib.D3.Helper.HELPER_TYPE_SKELETON = 0x6; */ GameLib.D3.Helper.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) { diff --git a/src/game-lib-d3-image.js b/src/game-lib-d3-image.js index b3ad4f8..f890d01 100644 --- a/src/game-lib-d3-image.js +++ b/src/game-lib-d3-image.js @@ -38,6 +38,11 @@ GameLib.D3.Image.prototype.constructor = GameLib.D3.Image; */ GameLib.D3.Image.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + if (update) { console.log('why the fuck are you updating an image instance?'); if (!this.instance) { diff --git a/src/game-lib-d3-light.js b/src/game-lib-d3-light.js index 3407526..663fea4 100644 --- a/src/game-lib-d3-light.js +++ b/src/game-lib-d3-light.js @@ -102,6 +102,11 @@ GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4; */ GameLib.D3.Light.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + if (update) { var oldInstance = null; diff --git a/src/game-lib-d3-look-at.js b/src/game-lib-d3-look-at.js index d7619b1..b5b9e8a 100644 --- a/src/game-lib-d3-look-at.js +++ b/src/game-lib-d3-look-at.js @@ -74,7 +74,11 @@ GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype); GameLib.D3.LookAt.prototype.constructor = GameLib.D3.LookAt; GameLib.D3.LookAt.prototype.createInstance = function() { - console.log('LookAt.createInstance()'); + console.log('GameLib.D3.LookAt.prototype.createInstance()'); + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } }; GameLib.D3.LookAt.prototype.toApiObject = function() { diff --git a/src/game-lib-d3-material.js b/src/game-lib-d3-material.js index 94ba832..456a89b 100644 --- a/src/game-lib-d3-material.js +++ b/src/game-lib-d3-material.js @@ -702,6 +702,11 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() { */ GameLib.D3.Material.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + if (update) { var typeChange = false; diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index ac93ebb..889c2ef 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -279,6 +279,11 @@ GameLib.D3.Mesh.prototype.customGeometry = function(){ */ GameLib.D3.Mesh.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + if (update) { if (this.parentMesh && this.parentMesh.loaded) { diff --git a/src/game-lib-d3-pass.js b/src/game-lib-d3-pass.js index d0f1753..48ea70a 100644 --- a/src/game-lib-d3-pass.js +++ b/src/game-lib-d3-pass.js @@ -54,13 +54,18 @@ GameLib.D3.Pass.PASS_TYPE_COPY_SHADER = 0x2; */ GameLib.D3.Pass.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) { instance = this.instance; } - if (this.passType == GameLib.D3.Pass.PASS_TYPE_RENDER) { + if (this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER) { if (this.scene && this.camera) { if (!THREE.RenderPass) { diff --git a/src/game-lib-d3-path-following.js b/src/game-lib-d3-path-following.js index 2a0076c..cb6cbfb 100644 --- a/src/game-lib-d3-path-following.js +++ b/src/game-lib-d3-path-following.js @@ -124,7 +124,14 @@ GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing. GameLib.D3.PathFollowing.prototype.constructor = GameLib.D3.PathFollowing; GameLib.D3.PathFollowing.prototype.createInstance = function() { - console.log('GameLib.D3.PathFollowing.prototype.createInstance()'); + + console.log('GameLib.D3.PathFollowing.prototype.createInstance()'); + + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + }; GameLib.D3.PathFollowing.prototype.toApiObject = function() { diff --git a/src/game-lib-d3-raycaster.js b/src/game-lib-d3-raycaster.js index 3bbfea6..d2ee3af 100644 --- a/src/game-lib-d3-raycaster.js +++ b/src/game-lib-d3-raycaster.js @@ -52,24 +52,34 @@ GameLib.D3.Raycaster.prototype.constructor = GameLib.D3.Raycaster; */ GameLib.D3.Raycaster.prototype.createInstance = function(update) { - var instance = null; + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } if (update) { - instance = this.instance; + + this.instance.set( + this.position.instance, + this.direction.instance + ); + + return null; + } else { - instance = new THREE.Raycaster(); - } + var instance = new THREE.Raycaster(); - instance.set( - this.position.instance, - this.direction.instance - ); + instance.set( + this.position.instance, + this.direction.instance + ); - return instance; + return instance; + } }; GameLib.D3.Raycaster.prototype.updateInstance = function() { - this.instance = this.createInstance(true); + this.createInstance(true); }; GameLib.D3.Raycaster.prototype.toApiObject = function() { diff --git a/src/game-lib-d3-render-target.js b/src/game-lib-d3-render-target.js index b44591c..63d571e 100644 --- a/src/game-lib-d3-render-target.js +++ b/src/game-lib-d3-render-target.js @@ -60,6 +60,11 @@ GameLib.D3.RenderTarget.RGBA_FORMAT = 1023; */ GameLib.D3.RenderTarget.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) { diff --git a/src/game-lib-d3-renderer.js b/src/game-lib-d3-renderer.js index ae69fae..743cc66 100644 --- a/src/game-lib-d3-renderer.js +++ b/src/game-lib-d3-renderer.js @@ -66,43 +66,70 @@ GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer; */ GameLib.D3.Renderer.prototype.createInstance = function(update) { - var instance = null; + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } if (update) { - instance = this.instance; - } else { - instance = new THREE.WebGLRenderer({ + + this.instance.localClippingEnabled = this.localClipping; + + this.instance.setSize( + this.width, + this.height + ); + + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + 1 - this.clearColor.a + ); + + this.instance.domElement.width = this.width; + this.instance.domElement.height = this.height; + + this.instance.autoClear = this.autoClear; + this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer; + + } else { + var instance = new THREE.WebGLRenderer({ canvas : this.domElement.instance }); + + instance.localClippingEnabled = this.localClipping; + + instance.setSize( + this.width, + this.height + ); + + instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + 1 - this.clearColor.a + ); + + instance.domElement.width = this.width; + instance.domElement.height = this.height; + + instance.autoClear = this.autoClear; + instance.preserveDrawingBuffer = this.preserveDrawingBuffer; + + return instance; } - instance.localClippingEnabled = this.localClipping; - instance.setSize( - this.width, - this.height - ); - - instance.setClearColor( - new THREE.Color( - this.clearColor.r, - this.clearColor.g, - this.clearColor.b - ), - 1 - this.clearColor.a - ); - - instance.domElement.width = this.width; - instance.domElement.height = this.height; - - instance.autoClear = this.autoClear; - instance.preserveDrawingBuffer = this.preserveDrawingBuffer; - - return instance; }; GameLib.D3.Renderer.prototype.updateInstance = function() { - this.instance = this.createInstance(true); + this.createInstance(true); }; GameLib.D3.Renderer.prototype.toApiObject = function() { diff --git a/src/game-lib-d3-scene.js b/src/game-lib-d3-scene.js index 5f8e60b..65e6728 100644 --- a/src/game-lib-d3-scene.js +++ b/src/game-lib-d3-scene.js @@ -193,6 +193,11 @@ GameLib.D3.Scene.prototype.constructor = GameLib.D3.Scene; */ GameLib.D3.Scene.prototype.createInstance = function() { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = new THREE.Scene(); instance.name = this.name; diff --git a/src/game-lib-d3-skeleton.js b/src/game-lib-d3-skeleton.js index 37ee126..dd08df0 100644 --- a/src/game-lib-d3-skeleton.js +++ b/src/game-lib-d3-skeleton.js @@ -102,6 +102,11 @@ GameLib.D3.Skeleton.prototype.constructor = GameLib.D3.Skeleton; */ GameLib.D3.Skeleton.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) { diff --git a/src/game-lib-d3-spline.js b/src/game-lib-d3-spline.js index 47dc941..e31b3ef 100644 --- a/src/game-lib-d3-spline.js +++ b/src/game-lib-d3-spline.js @@ -52,6 +52,11 @@ GameLib.D3.Spline.prototype.constructor = GameLib.D3.Spline; */ GameLib.D3.Spline.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + if (update) { return this.instance; } diff --git a/src/game-lib-d3-stats.js b/src/game-lib-d3-stats.js index e8c6255..a5ae354 100644 --- a/src/game-lib-d3-stats.js +++ b/src/game-lib-d3-stats.js @@ -62,6 +62,11 @@ GameLib.D3.Stats.prototype.resize = function() { */ GameLib.D3.Stats.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) { diff --git a/src/game-lib-d3-texture.js b/src/game-lib-d3-texture.js index a6765ea..9daf3a4 100644 --- a/src/game-lib-d3-texture.js +++ b/src/game-lib-d3-texture.js @@ -170,6 +170,11 @@ GameLib.D3.Texture.TEXTURE_TYPE_CUBE = 0x2; */ GameLib.D3.Texture.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + if (update) { if (!this.instance) { diff --git a/src/game-lib-d3-viewport.js b/src/game-lib-d3-viewport.js index 44ddcc3..4bce564 100644 --- a/src/game-lib-d3-viewport.js +++ b/src/game-lib-d3-viewport.js @@ -52,7 +52,12 @@ GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport; * @returns {*} */ GameLib.D3.Viewport.prototype.createInstance = function(update) { - + + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) { diff --git a/src/game-lib-dom-element.js b/src/game-lib-dom-element.js index eea64bd..3969fdb 100644 --- a/src/game-lib-dom-element.js +++ b/src/game-lib-dom-element.js @@ -33,15 +33,18 @@ GameLib.DomElement.prototype.constructor = GameLib.DomElement; */ GameLib.DomElement.prototype.createInstance = function(update) { - var instance = null; + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } if (update) { - instance = this.instance; + return null; } else { - instance = document.getElementById(this.domElementId); - } + var instance = document.getElementById(this.domElementId); + return instance; + } - return instance; }; /** diff --git a/src/game-lib-gui.js b/src/game-lib-gui.js index dd6b8c2..8002967 100644 --- a/src/game-lib-gui.js +++ b/src/game-lib-gui.js @@ -54,16 +54,6 @@ GameLib.GUI = function( } }; - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_GUI, - { - 'domElement': GameLib.DomElement - }, - null, - parentEntity - ); - if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } @@ -85,7 +75,18 @@ GameLib.GUI = function( } this.objects = objects; - this.instance = this.createInstance(); + if (GameLib.Utils.UndefinedOrNull(parentEntity)) { + parentEntity = null; + } + this.parentEntity = parentEntity; + + GameLib.Component.call( + this, + GameLib.Component.COMPONENT_GUI, + { + 'domElement': GameLib.DomElement + } + ); }; GameLib.GUI.prototype = Object.create(GameLib.Component.prototype); @@ -119,7 +120,7 @@ GameLib.GUI.prototype.createInstance = function(update) { * Updates the instance with the current state */ GameLib.GUI.prototype.updateInstance = function() { - this.instance = this.createInstance(true); + this.createInstance(true); }; GameLib.GUI.prototype.addObject = function(object) { diff --git a/src/game-lib-mouse.js b/src/game-lib-mouse.js index ae613e2..05d387d 100644 --- a/src/game-lib-mouse.js +++ b/src/game-lib-mouse.js @@ -26,7 +26,10 @@ GameLib.Mouse = function (graphics, apiMouse) { apiMouse.parentEntity ); - this.instance = this.createInstance(); + GameLib.Component.call( + this, + GameLib.Component.COMPONENT_MOUSE + ); }; GameLib.Mouse.prototype = Object.create(GameLib.API.Mouse.prototype); @@ -39,6 +42,11 @@ GameLib.Mouse.prototype.constructor = GameLib.Mouse; */ GameLib.Mouse.prototype.createInstance = function(update) { + if (!this.loaded) { + console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name); + return null; + } + var instance = null; if (update) {