proper loading of objects

beta.r3js.org
Theunis J. Botha 2017-06-16 15:49:53 +02:00
parent a111e42d63
commit bb0a861d35
55 changed files with 589 additions and 582 deletions

View File

@ -13,29 +13,7 @@ GameLib.API.EntityManager = function(
// systems,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY_MANAGER,
{
'entities' : [GameLib.Entity]
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Entity Manager (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(entities)) {
entities = [];
}
this.entities = entities;
// if (GameLib.Utils.UndefinedOrNull(systems)) {
// systems = [];

View File

@ -31,6 +31,7 @@ GameLib.Event.LOADED = 0xf;
GameLib.Event.SAVE_SUCCESS = 0x10;
GameLib.Event.SAVE_FAILURE = 0x11;
GameLib.Event.LOGGED_IN = 0x12;
GameLib.Event.COMPONENT_CREATED = 0x13;
/**
* Subscribe to some events
@ -42,62 +43,65 @@ GameLib.Event.prototype.subscribe = function(
callback
) {
var fn = callback.bind(this);
if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) {
GameLib.Event.Subscriptions[eventName].push(callback.bind(this));
GameLib.Event.Subscriptions[eventName].push(fn);
} else {
GameLib.Event.Subscriptions[eventName] = [];
GameLib.Event.Subscriptions[eventName].push(callback.bind(this));
GameLib.Event.Subscriptions[eventName].push(fn);
}
var index = GameLib.Event.Subscriptions[eventName].indexOf(fn);
/**
* Return a handle to the caller to allow us to unsubscribe to this event
*/
return {
fn : fn,
remove : function() {
GameLib.Event.Subscriptions[eventName].splice(index, 1);
}
}
};
/**
* Unsubscribe to some events
* TODO: incomplete
*
* @param eventName
* @param callback
* @param data
*/
GameLib.Event.prototype.unsubscribe = function(
eventName,
callback
) {
var index = -1;
if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) {
index = GameLib.Event.Subscriptions[eventName].indexOf(callback.bind(this));
}
if (index === -1) {
console.warn('could not unsubscribe from event - please implement this sometime (bind creates new function - store this pointer somewhere)');
} else {
GameLib.Event.Subscriptions[eventName].splice(index, 1);
}
};
/**
* Publish some event happened with some data
* @param eventName
* @param data
* @returns {number} of callbacks executed
*/
GameLib.Event.prototype.publish = function(
eventName,
data
) {
GameLib.Event.Emit(eventName, data);
return GameLib.Event.Emit(eventName, data);
};
/**
* Static method call
* @param eventName
* @param data
* @returns {number} of callbacks executed
* @constructor
*/
GameLib.Event.Emit = function(eventName, data) {
var count = 0;
if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) {
GameLib.Event.Subscriptions[eventName].map(
function(callback) {
callback(data);
count++;
}
)
}
return count;
};

View File

@ -4,11 +4,13 @@
* @param componentType
* @param linkedObjects
* @param parentEntity
* @param traverse
*/
GameLib.Component = function(
componentType,
linkedObjects,
parentEntity
parentEntity,
traverse
) {
if (GameLib.Utils.UndefinedOrNull(linkedObjects)) {
linkedObjects = {};
@ -32,11 +34,42 @@ GameLib.Component = function(
this.loaded = false;
if (GameLib.Utils.UndefinedOrNull(traverse)) {
traverse = true;
}
this.traverse = traverse;
this.dependencies = this.getDependencies();
this.publish(
GameLib.Event.COMPONENT_CREATED,
{
component : this
}
);
};
GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.Component.prototype.constructor = GameLib.Component;
GameLib.Component.prototype.getDependencies = function() {
var dependencies = [];
for (var property in this.linkedObjects) {
if (this.linkedObjects.hasOwnProperty(property)){
if (
this.hasOwnProperty(property) &&
typeof this[property] === 'string'
) {
dependencies.push(this[property]);
}
}
}
return dependencies;
};
GameLib.Component.prototype.toString = function() {
return this.id;
};
@ -72,6 +105,7 @@ GameLib.Component.COMPONENT_IMAGE_FACTORY = 0x1c;
GameLib.Component.COMPONENT_STATS = 0x1d;
GameLib.Component.COMPONENT_GUI = 0x1e;
GameLib.Component.COMPONENT_IMAGE = 0x1f;
GameLib.Component.COMPONENT_ENTITY = 0x20;
/**
* Returns string name for component number
@ -112,6 +146,7 @@ GameLib.Component.GetComponentName = function(number) {
case 0x1d : return 'GameLib.D3.Stats';
case 0x1e : return 'GameLib.GUI';
case 0x1f : return 'GameLib.D3.Image';
case 0x20 : return 'GameLib.Entity';
break;
}
};
@ -126,6 +161,10 @@ GameLib.Component.prototype.toApiObject = function() {
GameLib.Component.prototype.buildIdToObject = function() {
if (!this.traverse) {
return;
}
if (this.built) {
return;
}

View File

@ -18,13 +18,6 @@ GameLib.API.DomElement = function(
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_DOM_ELEMENT,
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}

View File

@ -26,16 +26,6 @@ GameLib.API.Entity = function(
this.activeComponent = null;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY,
{
'components' : [GameLib.Component],
'activeComponent' : GameLib.Component
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}

View File

@ -3,7 +3,6 @@
* @param id String
* @param name String
* @param systemType
* @param entityManager
* @param parentEntity
* @constructor
*/
@ -11,19 +10,9 @@ GameLib.API.System = function (
id,
name,
systemType,
entityManager,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SYSTEM,
{
'entityManager' : GameLib.EntityManager
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -39,10 +28,11 @@ GameLib.API.System = function (
}
this.systemType = systemType;
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
entityManager = null;
}
this.entityManager = entityManager;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.API.System.prototype = Object.create(GameLib.Component.prototype);
@ -58,7 +48,6 @@ GameLib.API.System.FromObject = function(objectComponent) {
objectComponent.id,
objectComponent.name,
objectComponent.systemType,
objectComponent.entityManager,
objectComponent.parentEntity
);
};

View File

@ -42,12 +42,6 @@ GameLib.D3.API.Camera = function(
eyeSeparation,
focalLength
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_CAMERA,
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -146,6 +140,11 @@ GameLib.D3.API.Camera = function(
focalLength = 150;
}
this.focalLength = focalLength;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Camera.prototype = Object.create(GameLib.Component.prototype);

View File

@ -16,18 +16,6 @@ GameLib.D3.API.Composer = function (
passes,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_COMPOSER,
{
'renderer' : GameLib.D3.Renderer,
'renderTarget' : GameLib.D3.RenderTarget,
'passes' : [GameLib.D3.Pass]
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -52,6 +40,11 @@ GameLib.D3.API.Composer = function (
passes = [];
}
this.passes = passes;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Composer.prototype = Object.create(GameLib.Component.prototype);

View File

@ -1,31 +1,21 @@
/**
* This component makes the parentEntity (ex. car) follow the path provided by the spline
* @param id String
* @param name String
* @param code String
* @param domElementId
* Custom Code Component
* @param id
* @param name
* @param parentEntity
* @param code
* @param domElementId
* @param args
* @constructor
*/
GameLib.D3.API.CustomCode = function (
id,
name,
parentEntity,
code,
domElementId,
parentEntity,
args
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_CUSTOM_CODE,
{
'args' : [GameLib.Component]
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -36,6 +26,11 @@ GameLib.D3.API.CustomCode = function (
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
if (GameLib.Utils.UndefinedOrNull(code)) {
code = '';
}
@ -65,9 +60,9 @@ GameLib.D3.API.CustomCode.FromObject = function(objectComponent) {
return new GameLib.D3.API.CustomCode(
objectComponent.id,
objectComponent.name,
objectComponent.parentEntity,
objectComponent.code,
objectComponent.domElementId,
objectComponent.parentEntity,
objectComponent.args
);
};

View File

@ -12,13 +12,6 @@ GameLib.D3.API.ImageFactory = function(
baseUrl,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_IMAGE_FACTORY,
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -34,6 +27,11 @@ GameLib.D3.API.ImageFactory = function(
console.warn('No baseURL defined for image factory');
}
this.baseUrl = baseUrl;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.ImageFactory.prototype = Object.create(GameLib.Component.prototype);

View File

@ -30,19 +30,6 @@ GameLib.D3.API.Input.Drive = function (
distanceGrain,
rotationFactor
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_INPUT_DRIVE,
{
'pathFollowingComponent' : GameLib.D3.PathFollowing,
'wheelFL' : GameLib.D3.Mesh,
'wheelFR' : GameLib.D3.Mesh,
'wheelRL' : GameLib.D3.Mesh,
'wheelRR' : GameLib.D3.Mesh
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -63,6 +50,11 @@ GameLib.D3.API.Input.Drive = function (
}
this.pathFollowingComponent = pathFollowingComponent;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
if (GameLib.Utils.UndefinedOrNull(wheelFL)) {
wheelFL = null;
}

View File

@ -14,14 +14,6 @@ GameLib.D3.API.Input.Editor = function (
camera,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_INPUT_EDITOR,
{
'camera' : GameLib.D3.Camera
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -43,6 +35,11 @@ GameLib.D3.API.Input.Editor = function (
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);

View File

@ -38,15 +38,6 @@ GameLib.D3.API.Light = function(
parentScene,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_LIGHT,
{
'parentScene' : GameLib.D3.Scene
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -126,6 +117,11 @@ GameLib.D3.API.Light = function(
parentScene = null;
}
this.parentScene = parentScene;
if (GameLib.Utils.UndefinedOrNull(parentEntity)){
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Light.prototype = Object.create(GameLib.Component.prototype);

View File

@ -19,16 +19,6 @@ GameLib.D3.API.LookAt = function (
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_LOOK_AT,
{
'currentComponent' : GameLib.Component,
'targetComponent' : GameLib.Component
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -66,6 +56,11 @@ GameLib.D3.API.LookAt = function (
this.currentRotation = new GameLib.API.Quaternion();
this.targetPosition = new GameLib.API.Vector3();
if(GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype);

View File

@ -69,7 +69,6 @@
* @param roughnessMap
* @param specularMap
* @param parentEntity
* @param selected
* @constructor
*/
GameLib.D3.API.Material = function(
@ -144,26 +143,6 @@ GameLib.D3.API.Material = function(
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_MATERIAL,
{
'alphaMap' : GameLib.D3.Texture,
'aoMap' : GameLib.D3.Texture,
'bumpMap' : GameLib.D3.Texture,
'diffuseMap' : GameLib.D3.Texture,
'displacementMap' : GameLib.D3.Texture,
'emissiveMap' : GameLib.D3.Texture,
'environmentMap' : GameLib.D3.Texture,
'lightMap' : GameLib.D3.Texture,
'metalnessMap' : GameLib.D3.Texture,
'normalMap' : GameLib.D3.Texture,
'roughnessMap' : GameLib.D3.Texture,
'specularMap' : GameLib.D3.Texture
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -504,6 +483,11 @@ GameLib.D3.API.Material = function(
}
this.specularMap = specularMap;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
this.needsUpdate = false;
};
@ -647,7 +631,6 @@ GameLib.D3.API.Material.FromObject = function(objectMaterial) {
apiNormalMap,
apiRoughnessMap,
apiSpecularMap,
objectMaterial.parentEntity,
objectMaterial.selected
objectMaterial.parentEntity
)
};

View File

@ -48,18 +48,6 @@ GameLib.D3.API.Mesh = function(
parentEntity,
renderOrder
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_MESH,
{
'parentMesh' : GameLib.D3.Mesh,
'parentScene' : GameLib.D3.Scene,
'materials' : [GameLib.D3.Material],
'skeleton' : GameLib.D3.Skeleton
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -164,6 +152,11 @@ GameLib.D3.API.Mesh = function(
renderOrder = 0;
}
this.renderOrder = renderOrder;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Mesh.prototype = Object.create(GameLib.Component.prototype);

View File

@ -18,17 +18,6 @@ GameLib.D3.API.Pass = function (
renderToScreen,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_PASS,
{
'camera' : GameLib.D3.Camera,
'scene' : GameLib.D3.Scene
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -56,7 +45,7 @@ GameLib.D3.API.Pass = function (
if (GameLib.Utils.UndefinedOrNull(renderToScreen)) {
if (this.passType == GameLib.D3.Pass.PASS_TYPE_RENDER) {
if (this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER) {
renderToScreen = false;
} else if (GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
renderToScreen = true;
@ -68,6 +57,10 @@ GameLib.D3.API.Pass = function (
}
this.renderToScreen = renderToScreen;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Pass.prototype = Object.create(GameLib.Component.prototype);

View File

@ -48,18 +48,6 @@ GameLib.D3.API.PathFollowing = function (
rotationVector,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_PATH_FOLLOWING,
{
'spline': GameLib.D3.Spline,
'mesh' : GameLib.D3.Mesh,
'raytraceMesh' : GameLib.D3.Mesh
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -164,6 +152,12 @@ GameLib.D3.API.PathFollowing = function (
rotationVector = new GameLib.API.Quaternion();
}
this.rotationVector = rotationVector;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.PathFollowing.prototype = Object.create(GameLib.Component.prototype);

View File

@ -24,16 +24,6 @@ GameLib.D3.API.RenderTarget = function (
texture,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_RENDER_TARGET,
{
'texture' : GameLib.D3.Texture
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -79,6 +69,11 @@ GameLib.D3.API.RenderTarget = function (
}
this.texture = texture;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.RenderTarget.prototype = Object.create(GameLib.Component.prototype);

View File

@ -24,16 +24,6 @@ GameLib.D3.API.Renderer = function (
clearColor,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_RENDERER,
{
'domElement' : GameLib.DomElement
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -78,6 +68,12 @@ GameLib.D3.API.Renderer = function (
clearColor = new GameLib.API.Color(0.58, 0.58, 0.58);
}
this.clearColor = clearColor;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);

View File

@ -30,19 +30,6 @@ GameLib.D3.API.Scene = function(
activeCamera,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SCENE,
{
'meshes' : [GameLib.D3.Mesh],
'lights' : [GameLib.D3.Light],
'textures' : [GameLib.D3.Texture],
'materials' : [GameLib.D3.Material],
'images' : [GameLib.D3.Image],
'activeCamera' : GameLib.D3.Camera
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -104,6 +91,11 @@ GameLib.D3.API.Scene = function(
}
this.activeCamera = activeCamera;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Scene.prototype = Object.create(GameLib.Component.prototype);

View File

@ -29,15 +29,6 @@ GameLib.D3.API.Skeleton = function (
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SKELETON,
{
'bones' : [GameLib.D3.Bone]
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}

View File

@ -12,13 +12,6 @@ GameLib.D3.API.Spline = function(
vertices,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SPLINE,
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -33,6 +26,11 @@ GameLib.D3.API.Spline = function(
vertices = [];
}
this.vertices = vertices;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Spline.prototype = Object.create(GameLib.Component.prototype);

View File

@ -53,15 +53,6 @@ GameLib.D3.API.Texture = function(
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_TEXTURE,
{
'image' : GameLib.D3.Image
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}

View File

@ -20,14 +20,6 @@ GameLib.D3.API.Viewport = function(
scenes,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_VIEWPORT,
{
'scenes' : [GameLib.D3.Scene]
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -63,6 +55,11 @@ GameLib.D3.API.Viewport = function(
scenes = [];
}
this.scenes = scenes;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Viewport.prototype = Object.create(GameLib.Component.prototype);

View File

@ -16,9 +16,9 @@ GameLib.D3.Camera = function(
apiCamera = {};
}
if (apiCamera instanceof GameLib.D3.Camera) {
return apiCamera;
}
if (apiCamera instanceof GameLib.D3.Camera) {
return apiCamera;
}
GameLib.D3.API.Camera.call(
this,
@ -76,9 +76,12 @@ GameLib.D3.Camera = function(
throw new Error('lookAt not instance of API.Vector3');
}
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_CAMERA
);
this.needsUpdate = false;
//this.needsUpdate = false;
} ;
GameLib.D3.Camera.prototype = Object.create(GameLib.D3.API.Camera.prototype);
@ -94,6 +97,11 @@ GameLib.D3.Camera.CAMERA_TYPE_STEREO = 0x3;
*/
GameLib.D3.Camera.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) {
@ -101,14 +109,14 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
}
if (!instance) {
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE ) {
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE ) {
instance = new THREE.PerspectiveCamera(
this.fov,
this.aspect,
this.near,
this.far
);
} else if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
} else if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
instance = new THREE.OrthographicCamera(
this.minX,
this.maxX,

View File

@ -30,37 +30,15 @@ GameLib.D3.Composer = function (
apiComposer.parentEntity
);
if (this.renderer instanceof GameLib.D3.API.Renderer) {
this.renderer = new GameLib.D3.Renderer(
this.graphics,
this.renderer
)
}
if (this.renderTarget instanceof GameLib.D3.API.RenderTarget) {
this.renderTarget = new GameLib.D3.RenderTarget(
this.graphics,
this.renderTarget
)
}
this.passes = this.passes.map(
function (apiPass) {
if (apiPass instanceof GameLib.D3.API.Pass) {
return GameLib.D3.Pass(
this.graphics,
apiPass
)
} else {
console.warn('apiPass not of type API.Pass');
throw new Error('apiPass not of type API.Pass');
}
}.bind(this)
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_COMPOSER,
{
'renderer' : GameLib.D3.Renderer,
'renderTarget' : GameLib.D3.RenderTarget,
'passes' : [GameLib.D3.Pass]
}
);
this.buildIdToObject();
this.instance = this.createInstance();
};
GameLib.D3.Composer.prototype = Object.create(GameLib.D3.API.Composer.prototype);
@ -73,31 +51,38 @@ GameLib.D3.Composer.prototype.constructor = GameLib.D3.Composer;
*/
GameLib.D3.Composer.prototype.createInstance = function(update) {
var instance = null;
if (update) {
instance = this.instance;
if (!this.loaded) {
console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name);
return null;
}
if (this.renderer &&
this.renderTarget) {
//TODO : Fix this too - make it nice (no circular references)
// var instance = null;
//
// if (update) {
// instance = this.instance;
// }
if (!THREE.EffectComposer) {
console.warn('No THREE.EffectComposer');
throw new Error('No THREE.EffectComposer');
}
instance = new THREE.EffectComposer(
this.renderer.instance,
this.renderTarget.instance
);
this.passes.map(
function(pass) {
this.instance.addPass(pass.instance);
}.bind(this)
);
}
//TODO : Fix this still (renderer and renderTarget should be objects)
// if (this.renderer &&
// this.renderTarget) {
//
// if (!THREE.EffectComposer) {
// console.warn('No THREE.EffectComposer');
// throw new Error('No THREE.EffectComposer');
// }
//
// instance = new THREE.EffectComposer(
// this.renderer.instance,
// this.renderTarget.instance
// );
//
// this.passes.map(
// function(pass) {
// this.instance.addPass(pass.instance);
// }.bind(this)
// );
// }
return instance;
};

View File

@ -19,15 +19,19 @@ GameLib.D3.CustomCode = function(
this,
apiCustomCode.id,
apiCustomCode.name,
apiCustomCode.parentEntity,
apiCustomCode.code,
apiCustomCode.domElementId,
apiCustomCode.parentEntity,
apiCustomCode.args
);
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_CUSTOM_CODE,
{
'args' : [GameLib.Component]
}
);
};
GameLib.D3.CustomCode.prototype = Object.create(GameLib.D3.API.CustomCode.prototype);
@ -39,6 +43,11 @@ GameLib.D3.CustomCode.prototype.constructor = GameLib.D3.CustomCode;
*/
GameLib.D3.CustomCode.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 = function(deltaTime) {
this.args['deltaTime'] = deltaTime;
var f = new Function(this.code).apply(this.parentEntity, this.args);
@ -61,22 +70,18 @@ GameLib.D3.CustomCode.prototype.updateInstance = function() {
*/
GameLib.D3.CustomCode.prototype.toApiObject = function() {
var apiArgs = [];
if (this.args) {
apiArgs = this.args.map(
function(arg) {
return GameLib.Utils.IdOrNull(arg);
}
)
}
var apiArgs = this.args.map(
function(arg) {
return GameLib.Utils.IdOrNull(arg);
}
);
return new GameLib.D3.API.CustomCode(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.parentEntity),
this.code,
this.domElementId,
GameLib.Utils.IdOrNull(this.parentEntity),
apiArgs
);

View File

@ -22,11 +22,6 @@ GameLib.D3.ImageFactory = function (
return apiImageFactory;
}
if (GameLib.Utils.UndefinedOrNull(progressCallback)) {
progressCallback = null;
}
this.progressCallback = progressCallback;
GameLib.D3.API.ImageFactory.call(
this,
apiImageFactory.id,
@ -35,18 +30,29 @@ GameLib.D3.ImageFactory = function (
apiImageFactory.parentEntity
);
this.buildIdToObject();
if (GameLib.Utils.UndefinedOrNull(progressCallback)) {
progressCallback = null;
}
this.progressCallback = progressCallback;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_IMAGE_FACTORY
);
this.promiseList = {};
this.instance = this.createInstance();
};
GameLib.D3.ImageFactory.prototype = Object.create(GameLib.D3.API.ImageFactory.prototype);
GameLib.D3.ImageFactory.prototype.constructor = GameLib.D3.ImageFactory;
GameLib.D3.ImageFactory.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) {

View File

@ -49,9 +49,17 @@ GameLib.D3.Input.Drive = function (
this.keyRight = false;
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_INPUT_DRIVE,
{
'pathFollowingComponent' : GameLib.D3.PathFollowing,
'wheelFL' : GameLib.D3.Mesh,
'wheelFR' : GameLib.D3.Mesh,
'wheelRL' : GameLib.D3.Mesh,
'wheelRR' : GameLib.D3.Mesh
}
);
};
GameLib.D3.Input.Drive.prototype = Object.create(GameLib.D3.API.Input.Drive.prototype);
@ -59,6 +67,11 @@ GameLib.D3.Input.Drive.prototype.constructor = GameLib.D3.Input.Drive;
GameLib.D3.Input.Drive.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;
}

View File

@ -68,15 +68,25 @@ GameLib.D3.Input.Editor = function (
this.graphics
);
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_INPUT_EDITOR,
{
'camera' : GameLib.D3.Camera
}
);
};
GameLib.D3.Input.Editor.prototype = Object.create(GameLib.D3.API.Input.Editor.prototype);
GameLib.D3.Input.Editor.prototype.constructor = GameLib.D3.Input.Editor;
GameLib.D3.Input.Editor.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) {

View File

@ -75,7 +75,13 @@ GameLib.D3.Light = function(
this
);
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_LIGHT,
{
'parentScene' : GameLib.D3.Scene
}
);
};
GameLib.D3.Light.prototype = Object.create(GameLib.D3.API.Light.prototype);

View File

@ -60,12 +60,23 @@ GameLib.D3.LookAt = function (
this
);
this.buildIdToObject();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_LOOK_AT,
{
'currentComponent' : GameLib.Component,
'targetComponent' : GameLib.Component
}
);
};
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()');
};
GameLib.D3.LookAt.prototype.toApiObject = function() {
var apiLookAt = new GameLib.D3.API.LookAt(

View File

@ -221,9 +221,24 @@ GameLib.D3.Material = function(
}
}
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_MATERIAL,
{
'alphaMap' : GameLib.D3.Texture,
'aoMap' : GameLib.D3.Texture,
'bumpMap' : GameLib.D3.Texture,
'diffuseMap' : GameLib.D3.Texture,
'displacementMap' : GameLib.D3.Texture,
'emissiveMap' : GameLib.D3.Texture,
'environmentMap' : GameLib.D3.Texture,
'lightMap' : GameLib.D3.Texture,
'metalnessMap' : GameLib.D3.Texture,
'normalMap' : GameLib.D3.Texture,
'roughnessMap' : GameLib.D3.Texture,
'specularMap' : GameLib.D3.Texture
}
);
this.updateTextures();
};

View File

@ -122,16 +122,16 @@ GameLib.D3.Mesh = function (
this
);
this.buildIdToObject();
this.instance = this.createInstance();
this.instance.geometry.computeBoundingBox();
this.width = this.instance.geometry.boundingBox.max.x - this.instance.geometry.boundingBox.min.x;
this.height = this.instance.geometry.boundingBox.max.y - this.instance.geometry.boundingBox.min.y;
this.depth = this.instance.geometry.boundingBox.max.z - this.instance.geometry.boundingBox.min.z;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_MESH,
{
'parentMesh' : GameLib.D3.Mesh,
'parentScene' : GameLib.D3.Scene,
'materials' : [GameLib.D3.Material],
'skeleton' : GameLib.D3.Skeleton
}
);
};
GameLib.D3.Mesh.prototype = Object.create(GameLib.D3.API.Mesh.prototype);
@ -328,6 +328,12 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
this.instance.renderOrder = this.renderOrder;
this.instance.geometry.computeBoundingBox();
this.width = this.instance.geometry.boundingBox.max.x - this.instance.geometry.boundingBox.min.x;
this.height = this.instance.geometry.boundingBox.max.y - this.instance.geometry.boundingBox.min.y;
this.depth = this.instance.geometry.boundingBox.max.z - this.instance.geometry.boundingBox.min.z;
} else {
var instance = null;
@ -432,6 +438,12 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
instance.renderOrder = this.renderOrder;
instance.geometry.computeBoundingBox();
this.width = instance.geometry.boundingBox.max.x - instance.geometry.boundingBox.min.x;
this.height = instance.geometry.boundingBox.max.y - instance.geometry.boundingBox.min.y;
this.depth = instance.geometry.boundingBox.max.z - instance.geometry.boundingBox.min.z;
this.subscribe(
GameLib.Event.MATERIAL_LOADED,
function(data) {

View File

@ -73,11 +73,9 @@ GameLib.D3.Mesh.Sphere.prototype.toApiObject = function() {
* Converts a standard object mesh to a GameLib.D3.Mesh
* @param graphics GameLib.D3.Graphics
* @param objectMesh {Object}
* @param computeNormals boolean to indicate whether or not to recalculate normals
* @param imageFactory GameLib.D3.ImageFactory
* @constructor
*/
GameLib.D3.Mesh.Sphere.FromObject = function(graphics, objectMesh, computeNormals, imageFactory) {
GameLib.D3.Mesh.Sphere.FromObject = function(graphics, objectMesh) {
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);

View File

@ -31,9 +31,14 @@ GameLib.D3.Pass = function (
apiPass.parentEntity
);
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_PASS,
{
'camera' : GameLib.D3.Camera,
'scene' : GameLib.D3.Scene
}
);
};
GameLib.D3.Pass.prototype = Object.create(GameLib.D3.API.Pass.prototype);

View File

@ -109,12 +109,24 @@ GameLib.D3.PathFollowing = function (
this.my = new GameLib.Utils.MovingAverage(10);
this.mz = new GameLib.Utils.MovingAverage(10);
this.buildIdToObject();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_PATH_FOLLOWING,
{
'spline': GameLib.D3.Spline,
'mesh' : GameLib.D3.Mesh,
'raytraceMesh' : GameLib.D3.Mesh
}
);
};
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
GameLib.D3.PathFollowing.prototype.constructor = GameLib.D3.PathFollowing;
GameLib.D3.PathFollowing.prototype.createInstance = function() {
console.log('GameLib.D3.PathFollowing.prototype.createInstance()');
};
GameLib.D3.PathFollowing.prototype.toApiObject = function() {
var apiPathFollowing = new GameLib.D3.API.PathFollowing(

View File

@ -33,9 +33,13 @@ GameLib.D3.RenderTarget = function (
apiRenderTarget.texture
);
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_RENDER_TARGET,
{
'texture' : GameLib.D3.Texture
}
);
};
GameLib.D3.RenderTarget.prototype = Object.create(GameLib.D3.API.RenderTarget.prototype);

View File

@ -46,7 +46,14 @@ GameLib.D3.Renderer = function (
);
}
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_RENDERER,
{
'domElement' : GameLib.DomElement
}
);
};
GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype);

View File

@ -100,7 +100,7 @@ GameLib.D3.Scene = function (
apiTexture
);
this.idToObject[texture.id] = texture;
// this.idToObject[texture.id] = texture;
return texture;
} else {
@ -121,7 +121,7 @@ GameLib.D3.Scene = function (
apiMaterial
);
this.idToObject[material.id] = material;
// this.idToObject[material.id] = material;
return material;
@ -143,7 +143,7 @@ GameLib.D3.Scene = function (
apiImage
);
this.idToObject[image.id] = image;
// this.idToObject[image.id] = image;
return image;
@ -162,13 +162,26 @@ GameLib.D3.Scene = function (
);
}
this.idToObject[this.id] = this;
/**
* TODO : Refactor (linking ?)
* @type {GameLib.D3.Scene}
*/
// this.idToObject[this.id] = this;
//
// this.linkObjects(this.idToObject);
this.linkObjects(this.idToObject);
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SCENE,
{
'meshes' : [GameLib.D3.Mesh],
'lights' : [GameLib.D3.Light],
'textures' : [GameLib.D3.Texture],
'materials' : [GameLib.D3.Material],
'images' : [GameLib.D3.Image],
'activeCamera' : GameLib.D3.Camera
}
);
};
GameLib.D3.Scene.prototype = Object.create(GameLib.D3.API.Scene.prototype);

View File

@ -83,9 +83,13 @@ GameLib.D3.Skeleton = function Skeleton(
}.bind(this)
);
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SKELETON,
{
'bones' : [GameLib.D3.Bone]
}
);
};
GameLib.D3.Skeleton.prototype = Object.create(GameLib.D3.API.Skeleton.prototype);
@ -122,7 +126,7 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) {
return result;
}
if (bone.parentBoneIds.length == 0) {
if (bone.parentBoneIds.length === 0) {
return bone.instance;
}

View File

@ -37,7 +37,10 @@ GameLib.D3.Spline = function (
}
);
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SPLINE
);
};
GameLib.D3.Spline.prototype = Object.create(GameLib.D3.API.Spline.prototype);

View File

@ -19,15 +19,6 @@ GameLib.D3.Stats = function(
}
this.stats = stats;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_STATS,
{
'domElement': GameLib.DomElement
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -44,7 +35,18 @@ GameLib.D3.Stats = function(
}
this.domElement = domElement;
this.instance = this.createInstance();
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_STATS,
{
'domElement': GameLib.DomElement
}
);
};
GameLib.D3.Stats.prototype = Object.create(GameLib.Component.prototype);

View File

@ -65,7 +65,13 @@ GameLib.D3.Texture = function(
);
}
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_TEXTURE,
{
'image' : GameLib.D3.Image
}
);
};
GameLib.D3.Texture.prototype = Object.create(GameLib.D3.API.Texture.prototype);

View File

@ -32,9 +32,13 @@ GameLib.D3.Viewport = function (
apiViewport.parentEntity
);
this.buildIdToObject();
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_VIEWPORT,
{
'scenes' : [GameLib.D3.Scene]
}
);
};
GameLib.D3.Viewport.prototype = Object.create(GameLib.D3.API.Viewport.prototype);

View File

@ -17,7 +17,10 @@ GameLib.DomElement = function (apiDomElement) {
apiDomElement.parentEntity
);
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_DOM_ELEMENT
);
};
GameLib.DomElement.prototype = Object.create(GameLib.API.DomElement.prototype);

View File

@ -1,85 +1,38 @@
/**
* GameLib.EntityManager
* @param graphics GameLib.D3.Graphics
* @param apiEntityManager GameLib.API.EntityManager
* @constructor
*/
GameLib.EntityManager = function(
graphics,
apiEntityManager
) {
GameLib.EntityManager = function() {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
this.id = GameLib.Utils.RandomId();
if (GameLib.Utils.UndefinedOrNull(apiEntityManager)) {
apiEntityManager = {};
}
this.name = 'Entity Manager (' + this.id + ')';
if (apiEntityManager instanceof GameLib.EntityManager) {
return apiEntityManager;
}
this.entities = [];
GameLib.API.EntityManager.call(
GameLib.Component.call(
this,
apiEntityManager.id,
apiEntityManager.name,
apiEntityManager.entities,
// apiEntityManager.systems,
apiEntityManager.parentEntity
GameLib.Component.COMPONENT_ENTITY_MANAGER,
{
'entities' : [GameLib.Entity]
},
null
);
this.entities = this.entities.map(
function(apiEntity) {
this.loaded = [];
if (apiEntity instanceof GameLib.API.Entity) {
return new GameLib.Entity(
this.graphics,
apiEntity
)
} else {
console.warn('Entity not of type API.Entity');
throw new Error('Entity not of type API.Entity');
}
this.dependencies = {};
}.bind(this)
);
// this.systems = this.systems.map(
// function(apiSystem) {
//
// if (apiSystem instanceof GameLib.API.System) {
// return new GameLib.System(
// this.graphics,
// apiSystem
// )
// } else {
// console.warn('System not of type API.System');
// throw new Error('System not of type API.System');
// }
//
// }.bind(this)
// );
this.buildIdToObject();
this.instance = this.createInstance();
this.subscriptions = [];
this.registerCallbacks();
};
GameLib.EntityManager.prototype = Object.create(GameLib.API.EntityManager.prototype);
GameLib.EntityManager.prototype = Object.create(GameLib.Component.prototype);
GameLib.EntityManager.prototype.constructor = GameLib.EntityManager;
/**
* Creates an Entity Manager instance
* @returns {*}
*/
GameLib.EntityManager.prototype.createInstance = function() {
/**
* Fuck the current ECS bullshit on the internet - both tiny-ecs and ecsjs SUCKS ASS
*/
return null;
return GameLib.EntityManager.Instance;
};
/**
@ -303,14 +256,11 @@ GameLib.EntityManager.prototype.toApiObject = function() {
* @param objectEntityManager Object
* @constructor
*/
GameLib.EntityManager.FromObject = function(graphics, objectEntityManager) {
GameLib.EntityManager.FromObject = function(objectEntityManager) {
var apiEntityManager = GameLib.API.EntityManager.FromObject(objectEntityManager);
var entityManager = new GameLib.EntityManager(
graphics,
apiEntityManager
);
var entityManager = new GameLib.EntityManager(apiEntityManager);
return entityManager;
};
@ -428,21 +378,108 @@ GameLib.EntityManager.prototype.onParentEntityChange = function(data) {
};
GameLib.EntityManager.prototype.componentCreated = function(data) {
console.log('component created : ' + data.component.name);
/**
* If we notify ourselves - ignore it
*/
if (data.component === this) {
return;
}
/**
* Store this component into our 'loaded' list
*/
this.loaded.push(data.component);
/**
* Store the dependencies too
*/
data.component.dependencies.map(function(id) {
if (GameLib.Utils.UndefinedOrNull(this.dependencies[id])) {
this.dependencies[id] = [];
}
this.dependencies[id].push(data.component);
}.bind(this));
/**
* Now find all the dependencies of this component
*/
var dependencies = this.dependencies[data.component.id];
if (GameLib.Utils.UndefinedOrNull(dependencies)) {
/**
* We have no dependencies, so mark our component as loaded and create an instance
*/
data.component.loaded = true;
data.component.instance = data.component.createInstance();
/**
* If we have none, we are done and can exit
*/
return;
}
/**
* Otherwise, now - for each dependency - update 'idToObject' and check if its loaded
*/
dependencies.map(function(component){
component.idToObject[data.component.id] = data.component;
var loaded = true;
for (var property in component.idToObject) {
if (
component.idToObject.hasOwnProperty(property) &&
component.idToObject[property] === null
) {
loaded = false
}
}
component.loaded = loaded;
if (component.loaded) {
/**
* Our component is fully loaded, time to create an instance of it
*/
component.instance = component.createInstance();
}
})
};
/**
*
*/
GameLib.EntityManager.prototype.registerCallbacks = function() {
this.subscribe(
GameLib.Event.PARENT_SCENE_CHANGE,
this.onParentSceneChange
this.subscriptions.push(
this.subscribe(
GameLib.Event.PARENT_SCENE_CHANGE,
this.onParentSceneChange
)
);
this.subscribe(
GameLib.Event.PARENT_ENTITY_CHANGE,
this.onParentEntityChange
);
this.subscriptions.push(
this.subscribe(
GameLib.Event.PARENT_ENTITY_CHANGE,
this.onParentEntityChange
)
);
this.subscriptions.push(
this.subscribe(
GameLib.Event.COMPONENT_CREATED,
this.componentCreated
)
);
};
/**

View File

@ -31,60 +31,14 @@ GameLib.Entity = function (
this.componentToCreate = 0;
// this.components = this.components.map(
//
// function (apiComponent) {
//
// if (apiComponent instanceof GameLib.D3.API.PathFollowing) {
// return new GameLib.D3.PathFollowing(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Renderer) {
// return new GameLib.D3.Renderer(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.RenderTarget) {
// return new GameLib.D3.RenderTarget(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Pass) {
// return new GameLib.D3.Pass(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Composer) {
// return new GameLib.D3.Composer(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Camera) {
// return new GameLib.D3.Camera(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.LookAt) {
// return new GameLib.D3.LookAt(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Follow) {
// return new GameLib.D3.Follow(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Input.Editor) {
// return new GameLib.D3.Input.Editor(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Input.Drive) {
// return new GameLib.D3.Input.Drive(this.graphics, apiComponent);
// }
//
// if (apiComponent instanceof GameLib.D3.API.Spline) {
// return new GameLib.D3.Spline(this.graphics, apiComponent);
// }
//
// return apiComponent;
//
// }.bind(this)
// );
this.instance = this.createInstance();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY,
{
'components' : [GameLib.Component],
'activeComponent' : GameLib.Component
}
);
};
GameLib.Entity.prototype = Object.create(GameLib.API.Entity.prototype);

View File

@ -25,20 +25,17 @@ GameLib.System = function(
apiSystem.id,
apiSystem.name,
apiSystem.systemType,
apiSystem.entityManager,
apiSystem.parentEntity
);
if (this.entityManager instanceof GameLib.API.EntityManager) {
this.entityManager = new GameLib.EntityManager(
this.graphics,
this.entityManager
);
}
this.saveCallback = null;
this.loadCallback = null;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SYSTEM
);
};
GameLib.System.prototype = Object.create(GameLib.API.System.prototype);
@ -52,6 +49,10 @@ GameLib.System.SYSTEM_TYPE_STORAGE = 0x8;
GameLib.System.SYSTEM_TYPE_GUI = 0x10;
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
GameLib.System.prototype.createInstance = function() {
console.log('GameLib.System.prototype.createInstance();');
};
/**
* @callback
* @override
@ -63,16 +64,16 @@ GameLib.System.prototype.start = function() {
/**
* Hookup all editor input capabilities
*/
var entities = this.entityManager.query([GameLib.D3.Input.Editor]);
var entities = GameLib.EntityManager.Instance.query([GameLib.D3.Input.Editor]);
entities.map(function(entity){
var component = entity.getFirstComponent(GameLib.D3.Input.Editor);
component.mouseDown = component.onMouseDown(entity, this.entityManager).bind(component);
component.mouseDown = component.onMouseDown(entity, GameLib.EntityManager.Instance).bind(component);
component.mouseMove = component.onMouseMove(entity).bind(component);
component.keyDown = component.onKeyDown(entity, this.entityManager).bind(component);
component.keyUp = component.onKeyUp(entity, this.entityManager).bind(component);
component.keyDown = component.onKeyDown(entity, GameLib.EntityManager.Instance).bind(component);
component.keyUp = component.onKeyUp(entity, GameLib.EntityManager.Instance).bind(component);
component.domElement.instance.addEventListener('mousedown', component.mouseDown, false);
component.domElement.instance.addEventListener('mousemove', component.mouseMove, false);
@ -129,7 +130,7 @@ GameLib.System.prototype.start = function() {
if (this.systemType === GameLib.System.SYSTEM_TYPE_RENDER) {
this.renderEntities = this.entityManager.query(
this.renderEntities = GameLib.EntityManager.Instance.query(
[
GameLib.D3.Viewport,
GameLib.D3.Scene,
@ -149,7 +150,7 @@ GameLib.System.prototype.start = function() {
if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) {
var guis = this.entityManager.queryComponents(GameLib.GUI);
var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
guis.map(function(gui){
gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
@ -158,12 +159,12 @@ GameLib.System.prototype.start = function() {
}
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
// this.pathFollowingObjects = this.entityManager.query([GameLib.D3.PathFollowing]);
// this.followObjects = this.entityManager.query([GameLib.D3.Follow]);
// this.meshObjects = this.entityManager.query([GameLib.D3.Mesh]);
// this.lookAtObjects = this.entityManager.query([GameLib.D3.LookAt]);
// this.cameraObjects = this.entityManager.query([GameLib.D3.Camera]);
// this.lightObjects = this.entityManager.query([GameLib.D3.Light]);
// this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
// this.followObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Follow]);
// this.meshObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Mesh]);
// this.lookAtObjects = GameLib.EntityManager.Instance.query([GameLib.D3.LookAt]);
// this.cameraObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Camera]);
// this.lightObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Light]);
}
if (this.systemType === GameLib.System.SYSTEM_TYPE_STORAGE) {
@ -312,7 +313,7 @@ GameLib.System.prototype.stop = function() {
/**
* Now remove all editor input capabilities
*/
var entities = this.entityManager.query([GameLib.D3.Input.Editor]);
var entities = GameLib.EntityManager.Instance.query([GameLib.D3.Input.Editor]);
entities.map(function(entity){
var component = entity.getFirstComponent(GameLib.D3.Input.Editor);
@ -330,7 +331,7 @@ GameLib.System.prototype.stop = function() {
if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) {
console.log('stopping GUI system');
var guis = this.entityManager.queryComponents(GameLib.GUI);
var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
guis.map(function(gui){
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement);
@ -383,7 +384,6 @@ GameLib.System.prototype.toApiObject = function() {
this.id,
this.name,
this.systemType,
GameLib.Utils.IdOrNull(this.entityManager),
GameLib.Utils.IdOrNull(this.parentEntity)
);
};

View File

@ -1,3 +1,6 @@
GameLib.EntityManager.Instance = new GameLib.EntityManager();
if (typeof module !== 'undefined') {
module.exports = GameLib;
}