cleanup linking system
parent
5b4e5a708a
commit
b6bb9cb9a7
|
@ -18,7 +18,7 @@ GameLib.Event.OnceSubscriptions = {};
|
||||||
GameLib.Event.WINDOW_RESIZE = 0x1;
|
GameLib.Event.WINDOW_RESIZE = 0x1;
|
||||||
GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
|
GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
|
||||||
GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
|
GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
|
||||||
GameLib.Event.IMAGE_INSTANCE_CREATED = 0x4;
|
GameLib.Event.INSTANCE_CLONED = 0x4;
|
||||||
GameLib.Event.LOAD_IMAGE = 0x5;
|
GameLib.Event.LOAD_IMAGE = 0x5;
|
||||||
GameLib.Event.NEW_ENTITY = 0x6;
|
GameLib.Event.NEW_ENTITY = 0x6;
|
||||||
GameLib.Event.MATERIAL_TYPE_CHANGED = 0x7;
|
GameLib.Event.MATERIAL_TYPE_CHANGED = 0x7;
|
||||||
|
@ -29,17 +29,17 @@ GameLib.Event.LOAD_COMPONENT = 0xb;
|
||||||
GameLib.Event.LOAD_COMPONENT_ERROR = 0xc;
|
GameLib.Event.LOAD_COMPONENT_ERROR = 0xc;
|
||||||
GameLib.Event.LOGGED_IN = 0xd;
|
GameLib.Event.LOGGED_IN = 0xd;
|
||||||
GameLib.Event.COMPONENT_CREATED = 0xe;
|
GameLib.Event.COMPONENT_CREATED = 0xe;
|
||||||
GameLib.Event.SCENE_INSTANCE_CREATED = 0xf;
|
GameLib.Event.COMPONENT_CLONED = 0xf;
|
||||||
GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED = 0x10;
|
//GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED = 0x10;
|
||||||
GameLib.Event.PHYSICS_WORLD_INSTANCE_CREATED = 0x11;
|
//GameLib.Event.PHYSICS_WORLD_INSTANCE_CREATED = 0x11;
|
||||||
GameLib.Event.RIGID_BODY_INSTANCE_CREATED = 0x12;
|
//GameLib.Event.RIGID_BODY_INSTANCE_CREATED = 0x12;
|
||||||
GameLib.Event.TEXTURE_INSTANCE_CREATED = 0x13;
|
//GameLib.Event.TEXTURE_INSTANCE_CREATED = 0x13;
|
||||||
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x14;
|
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x14;
|
||||||
GameLib.Event.MATERIAL_INSTANCE_CREATED = 0x15;
|
//GameLib.Event.MATERIAL_INSTANCE_CREATED = 0x15;
|
||||||
GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x16;
|
GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x16;
|
||||||
GameLib.Event.MESH_INSTANCE_CREATED = 0x17;
|
//GameLib.Event.MESH_INSTANCE_CREATED = 0x17;
|
||||||
GameLib.Event.MESH_INSTANCE_UPDATED = 0x18;
|
GameLib.Event.MESH_INSTANCE_UPDATED = 0x18;
|
||||||
GameLib.Event.LIGHT_INSTANCE_CREATED = 0x19;
|
//GameLib.Event.LIGHT_INSTANCE_CREATED = 0x19;
|
||||||
GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1a;
|
GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1a;
|
||||||
GameLib.Event.DELETE_COMPONENT = 0x1b;
|
GameLib.Event.DELETE_COMPONENT = 0x1b;
|
||||||
GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1c;
|
GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1c;
|
||||||
|
@ -67,9 +67,9 @@ GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
|
||||||
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
|
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
|
||||||
GameLib.Event.COMPONENT_DELETED = 0x33;
|
GameLib.Event.COMPONENT_DELETED = 0x33;
|
||||||
GameLib.Event.COMPONENT_TYPES_UPDATED = 0x34;
|
GameLib.Event.COMPONENT_TYPES_UPDATED = 0x34;
|
||||||
GameLib.Event.SHAPE_INSTANCE_CREATED = 0x35;
|
//GameLib.Event.SHAPE_INSTANCE_CREATED = 0x35;
|
||||||
GameLib.Event.COMPONENT_LINKED = 0x36;
|
GameLib.Event.COMPONENT_LINKED = 0x36;
|
||||||
GameLib.Event.SOLVER_INSTANCE_CREATED = 0x37;
|
//GameLib.Event.SOLVER_INSTANCE_CREATED = 0x37;
|
||||||
GameLib.Event.BEFORE_RENDER = 0x38;
|
GameLib.Event.BEFORE_RENDER = 0x38;
|
||||||
GameLib.Event.AFTER_RENDER = 0x39;
|
GameLib.Event.AFTER_RENDER = 0x39;
|
||||||
GameLib.Event.ARRAY_ITEM_ADDED = 0x3a;
|
GameLib.Event.ARRAY_ITEM_ADDED = 0x3a;
|
||||||
|
@ -101,7 +101,7 @@ GameLib.Event.GET_SCENE = 0x53;
|
||||||
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
|
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
|
||||||
GameLib.Event.LOAD_FONT = 0x55;
|
GameLib.Event.LOAD_FONT = 0x55;
|
||||||
GameLib.Event.FONT_NOT_FOUND = 0x56;
|
GameLib.Event.FONT_NOT_FOUND = 0x56;
|
||||||
GameLib.Event.FONT_INSTANCE_CREATED = 0x57;
|
//GameLib.Event.FONT_INSTANCE_CREATED = 0x57;
|
||||||
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
|
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
|
||||||
GameLib.Event.GAME_LOADED = 0x59;
|
GameLib.Event.GAME_LOADED = 0x59;
|
||||||
GameLib.Event.GAME_RESTART = 0x5a;
|
GameLib.Event.GAME_RESTART = 0x5a;
|
||||||
|
@ -125,7 +125,7 @@ GameLib.Event.GetEventName = function(number) {
|
||||||
case 0x1 : return 'window_resize';
|
case 0x1 : return 'window_resize';
|
||||||
case 0x2 : return 'parent_scene_change';
|
case 0x2 : return 'parent_scene_change';
|
||||||
case 0x3 : return 'parent_entity_change';
|
case 0x3 : return 'parent_entity_change';
|
||||||
case 0x4 : return 'image_instance_created';
|
case 0x4 : return 'instance_cloned';
|
||||||
case 0x5 : return 'load_image';
|
case 0x5 : return 'load_image';
|
||||||
case 0x6 : return 'new_entity';
|
case 0x6 : return 'new_entity';
|
||||||
case 0x7 : return 'material_type_changed';
|
case 0x7 : return 'material_type_changed';
|
||||||
|
@ -136,17 +136,17 @@ GameLib.Event.GetEventName = function(number) {
|
||||||
case 0xc : return 'load_component_error';
|
case 0xc : return 'load_component_error';
|
||||||
case 0xd : return 'logged_in';
|
case 0xd : return 'logged_in';
|
||||||
case 0xe : return 'component_created';
|
case 0xe : return 'component_created';
|
||||||
case 0xf : return 'scene_instance_created';
|
case 0xf : return 'component_cloned';
|
||||||
case 0x10 : return 'scene_object_instance_created';
|
case 0x10 : return 'unused';//'scene_object_instance_created';
|
||||||
case 0x11 : return 'world_instance_created';
|
case 0x11 : return 'unused';//'world_instance_created';
|
||||||
case 0x12 : return 'rigid_body_instance_created';
|
case 0x12 : return 'unused';//'rigid_body_instance_created';
|
||||||
case 0x13 : return 'texture_instance_created';
|
case 0x13 : return 'unused';//'texture_instance_created';
|
||||||
case 0x14 : return 'texture_instance_updated';
|
case 0x14 : return 'texture_instance_updated';
|
||||||
case 0x15 : return 'material_instance_created';
|
case 0x15 : return 'unused';//'material_instance_created';
|
||||||
case 0x16 : return 'material_instance_updated';
|
case 0x16 : return 'material_instance_updated';
|
||||||
case 0x17 : return 'mesh_instance_created';
|
case 0x17 : return 'unused';//'mesh_instance_created';
|
||||||
case 0x18 : return 'mesh_instance_updated';
|
case 0x18 : return 'mesh_instance_updated';
|
||||||
case 0x19 : return 'light_instance_created';
|
case 0x19 : return 'unused';//'light_instance_created';
|
||||||
case 0x1a : return 'light_instance_updated';
|
case 0x1a : return 'light_instance_updated';
|
||||||
case 0x1b : return 'delete_component';
|
case 0x1b : return 'delete_component';
|
||||||
case 0x1c : return 'component_download_complete';
|
case 0x1c : return 'component_download_complete';
|
||||||
|
@ -174,9 +174,9 @@ GameLib.Event.GetEventName = function(number) {
|
||||||
case 0x32 : return 'delete_component_error';
|
case 0x32 : return 'delete_component_error';
|
||||||
case 0x33 : return 'component_deleted';
|
case 0x33 : return 'component_deleted';
|
||||||
case 0x34 : return 'component_types_updated';
|
case 0x34 : return 'component_types_updated';
|
||||||
case 0x35 : return 'shape_instance_created';
|
case 0x35 : return 'unused';//'shape_instance_created';
|
||||||
case 0x36 : return 'component_linked';
|
case 0x36 : return 'component_linked';
|
||||||
case 0x37 : return 'solver_instance_created';
|
case 0x37 : return 'unused';//'solver_instance_created';
|
||||||
case 0x38 : return 'before_render';
|
case 0x38 : return 'before_render';
|
||||||
case 0x39 : return 'after_render';
|
case 0x39 : return 'after_render';
|
||||||
case 0x3a : return 'array_item_added';
|
case 0x3a : return 'array_item_added';
|
||||||
|
@ -208,7 +208,7 @@ GameLib.Event.GetEventName = function(number) {
|
||||||
case 0x54 : return 'custom_code_window_resize';
|
case 0x54 : return 'custom_code_window_resize';
|
||||||
case 0x55 : return 'load_font';
|
case 0x55 : return 'load_font';
|
||||||
case 0x56 : return 'font_not_found';
|
case 0x56 : return 'font_not_found';
|
||||||
case 0x57 : return 'font_instance_created';
|
case 0x57 : return 'unused';//'font_instance_created';
|
||||||
case 0x58 : return 'register_dependencies';
|
case 0x58 : return 'register_dependencies';
|
||||||
case 0x59 : return 'game_loaded';
|
case 0x59 : return 'game_loaded';
|
||||||
case 0x5a : return 'game_restart';
|
case 0x5a : return 'game_restart';
|
||||||
|
@ -237,119 +237,6 @@ GameLib.Event.prototype.subscribe = function(
|
||||||
return GameLib.Event.Subscribe(eventName, callback.bind(this));
|
return GameLib.Event.Subscribe(eventName, callback.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Event.EmitInstanceEvents = function(component) {
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.Mesh
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.MESH_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
mesh: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.Light
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.LIGHT_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
light: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.Scene
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.SCENE_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
scene: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.Material
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.MATERIAL_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
material: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.Texture
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.TEXTURE_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
texture: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.Image
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.IMAGE_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
image: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.Shape
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.SHAPE_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
shape: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
component instanceof GameLib.D3.PhysicsWorld
|
|
||||||
) {
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.PHYSICS_WORLD_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
world: component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
component: component
|
|
||||||
}
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Stop listening for this event after the callback returns true
|
// * Stop listening for this event after the callback returns true
|
||||||
|
|
|
@ -141,7 +141,12 @@ GameLib.Component.prototype.createInstance = function() {
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
|
||||||
GameLib.Event.EmitInstanceEvents(this);
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.INSTANCE_CREATED,
|
||||||
|
{
|
||||||
|
component: this
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this instanceof GameLib.Entity) {
|
if (this instanceof GameLib.Entity) {
|
||||||
|
@ -552,12 +557,10 @@ GameLib.Component.prototype.clone = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO check below event emit
|
|
||||||
*/
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.COMPONENT_CREATED,
|
GameLib.Event.COMPONENT_CLONED,
|
||||||
{
|
{
|
||||||
|
parent : this,
|
||||||
component : runtimeObject
|
component : runtimeObject
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -572,6 +575,32 @@ GameLib.Component.prototype.clone = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones only the instance
|
||||||
|
*/
|
||||||
|
GameLib.Component.prototype.cloneInstance = function() {
|
||||||
|
|
||||||
|
var clone = null;
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.instance &&
|
||||||
|
this.instance.clone &&
|
||||||
|
typeof (this.instance.clone === 'function')) {
|
||||||
|
|
||||||
|
clone = this.instance.clone();
|
||||||
|
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.INSTANCE_CLONED,
|
||||||
|
{
|
||||||
|
component : this,
|
||||||
|
instance : clone
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.Component.prototype.getStorageDependencies = function() {
|
GameLib.Component.prototype.getStorageDependencies = function() {
|
||||||
|
|
||||||
var dependencies = {};
|
var dependencies = {};
|
||||||
|
|
|
@ -166,7 +166,7 @@ GameLib.D3.Particle.prototype.clone = function(camera) {
|
||||||
|
|
||||||
instance.lookAt(direction);
|
instance.lookAt(direction);
|
||||||
|
|
||||||
instance.userData.direction = this.direction.instance;
|
instance.userData.direction = this.direction.instance.clone();
|
||||||
instance.userData.elapsed = 0;
|
instance.userData.elapsed = 0;
|
||||||
instance.userData.lifeTime = this.lifeTime;
|
instance.userData.lifeTime = this.lifeTime;
|
||||||
this.mesh.parentScene.instance.add(instance);
|
this.mesh.parentScene.instance.add(instance);
|
||||||
|
|
|
@ -145,6 +145,8 @@ GameLib.D3.Scene = function (
|
||||||
*/
|
*/
|
||||||
this.helpers = [];
|
this.helpers = [];
|
||||||
|
|
||||||
|
this.clones = [];
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_SCENE,
|
GameLib.Component.COMPONENT_SCENE,
|
||||||
|
@ -393,7 +395,19 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Scene.prototype.addClone = function(component) {
|
||||||
|
|
||||||
|
if (component instanceof GameLib.D3.Mesh ||
|
||||||
|
component instanceof GameLib.D3.Light
|
||||||
|
) {
|
||||||
|
if (this.instance && component.instance) {
|
||||||
|
this.instance.add(component.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.Utils.PushUnique(this.clones, component);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -405,15 +419,29 @@ GameLib.D3.Scene.prototype.removeObject = function(object) {
|
||||||
var index = -1;
|
var index = -1;
|
||||||
|
|
||||||
if (object instanceof GameLib.D3.Mesh) {
|
if (object instanceof GameLib.D3.Mesh) {
|
||||||
|
|
||||||
index = this.meshes.indexOf(object);
|
index = this.meshes.indexOf(object);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.meshes.splice(index, 1);
|
this.meshes.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
index = this.clones.indexOf(object);
|
||||||
|
if (index !== -1) {
|
||||||
|
this.clones.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (object instanceof GameLib.D3.Light) {
|
} else if (object instanceof GameLib.D3.Light) {
|
||||||
|
|
||||||
index = this.lights.indexOf(object);
|
index = this.lights.indexOf(object);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.lights.splice(index, 1);
|
this.lights.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
index = this.clones.indexOf(object);
|
||||||
|
if (index !== -1) {
|
||||||
|
this.clones.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.warn('Cannot remove this object - what is this ?' + object.toString());
|
console.warn('Cannot remove this object - what is this ?' + object.toString());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -27,6 +27,7 @@ GameLib.System.Linking = function(
|
||||||
* Components
|
* Components
|
||||||
*/
|
*/
|
||||||
this.componentCreatedSubscription = null;
|
this.componentCreatedSubscription = null;
|
||||||
|
this.componentClonedSubscription = null;
|
||||||
this.registerDependenciesSubscription = null;
|
this.registerDependenciesSubscription = null;
|
||||||
this.componentRemoveSubscription = null;
|
this.componentRemoveSubscription = null;
|
||||||
|
|
||||||
|
@ -41,16 +42,7 @@ GameLib.System.Linking = function(
|
||||||
* Instances
|
* Instances
|
||||||
*/
|
*/
|
||||||
this.instanceCreatedSubscription = null;
|
this.instanceCreatedSubscription = null;
|
||||||
this.meshInstanceCreatedSubscription = null;
|
this.instanceClonedSubscription = null;
|
||||||
this.lightInstanceCreatedSubscription = null;
|
|
||||||
this.sceneInstanceCreatedSubscription = null;
|
|
||||||
this.imageInstanceCreatedSubscription = null;
|
|
||||||
this.fontInstanceCreatedSubscription = null;
|
|
||||||
this.textureInstanceCreatedSubscription = null;
|
|
||||||
this.materialInstanceCreatedSubscription = null;
|
|
||||||
this.shapeInstanceCreatedSubscription = null;
|
|
||||||
this.solverInstanceCreatedSubscription = null;
|
|
||||||
this.physicsWorldInstanceCreatedSubscription = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Meshes
|
* Meshes
|
||||||
|
@ -88,6 +80,11 @@ GameLib.System.Linking.prototype.start = function() {
|
||||||
this.componentCreated.bind(this)
|
this.componentCreated.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.componentClonedSubscription = this.subscribe(
|
||||||
|
GameLib.Event.COMPONENT_CLONED,
|
||||||
|
this.componentCloned.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.registerDependenciesSubscription = this.subscribe(
|
this.registerDependenciesSubscription = this.subscribe(
|
||||||
GameLib.Event.REGISTER_DEPENDENCIES,
|
GameLib.Event.REGISTER_DEPENDENCIES,
|
||||||
this.registerDependenciesDirect
|
this.registerDependenciesDirect
|
||||||
|
@ -124,54 +121,9 @@ GameLib.System.Linking.prototype.start = function() {
|
||||||
this.instanceCreated
|
this.instanceCreated
|
||||||
);
|
);
|
||||||
|
|
||||||
this.meshInstanceCreatedSubscription = this.subscribe(
|
this.instanceClonedSubscription = this.subscribe(
|
||||||
GameLib.Event.MESH_INSTANCE_CREATED,
|
GameLib.Event.INSTANCE_CLONED,
|
||||||
this.meshInstanceCreated
|
this.instanceCloned
|
||||||
);
|
|
||||||
|
|
||||||
this.lightInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.LIGHT_INSTANCE_CREATED,
|
|
||||||
this.lightInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.sceneInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.SCENE_INSTANCE_CREATED,
|
|
||||||
this.sceneInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.imageInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.IMAGE_INSTANCE_CREATED,
|
|
||||||
this.imageInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.fontInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.FONT_INSTANCE_CREATED,
|
|
||||||
this.fontInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.textureInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.TEXTURE_INSTANCE_CREATED,
|
|
||||||
this.textureInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.materialInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.MATERIAL_INSTANCE_CREATED,
|
|
||||||
this.materialInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.shapeInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.SHAPE_INSTANCE_CREATED,
|
|
||||||
this.shapeInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.solverInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.SOLVER_INSTANCE_CREATED,
|
|
||||||
this.solverInstanceCreated
|
|
||||||
);
|
|
||||||
|
|
||||||
this.physicsWorldInstanceCreatedSubscription = this.subscribe(
|
|
||||||
GameLib.Event.PHYSICS_WORLD_INSTANCE_CREATED,
|
|
||||||
this.physicsWorldInstanceCreated
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -517,6 +469,21 @@ GameLib.System.Linking.prototype.componentCreated = function(data) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.Linking.prototype.componentCloned = function(data) {
|
||||||
|
|
||||||
|
this.componentCreated(data);
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.D3.Mesh) {
|
||||||
|
|
||||||
|
if (!(data.parent instanceof GameLib.D3.Mesh)){
|
||||||
|
throw new Error('no scene parent');
|
||||||
|
}
|
||||||
|
|
||||||
|
data.parent.parentScene.addClone(data.component);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you want to register dependencies directly - Component constructor does this when it knows the
|
* When you want to register dependencies directly - Component constructor does this when it knows the
|
||||||
* component instance cannot be created because it has a bunch of dependencies. So it tells the linking
|
* component instance cannot be created because it has a bunch of dependencies. So it tells the linking
|
||||||
|
@ -558,8 +525,6 @@ GameLib.System.Linking.prototype.removeComponent = function(data) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.imageChanged = function(data) {
|
GameLib.System.Linking.prototype.imageChanged = function(data) {
|
||||||
|
|
||||||
var materials = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Material);
|
var materials = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Material);
|
||||||
|
@ -576,172 +541,6 @@ GameLib.System.Linking.prototype.imageChanged = function(data) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.meshInstanceCreated = function(data) {
|
|
||||||
|
|
||||||
this.resolveDependencies(data.mesh);
|
|
||||||
|
|
||||||
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene);
|
|
||||||
|
|
||||||
scenes.map(function(scene){
|
|
||||||
if (data.mesh.parentScene === scene.id) {
|
|
||||||
data.mesh.parentScene = scene;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Link Parent Meshes for other meshes
|
|
||||||
*/
|
|
||||||
meshes.map(
|
|
||||||
function(mesh) {
|
|
||||||
|
|
||||||
if (mesh === data.mesh) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesh.parentMesh === data.mesh.id) {
|
|
||||||
mesh.setParentMesh(data.mesh);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.mesh.parentMesh === mesh.id) {
|
|
||||||
data.mesh.setParentMesh(mesh);
|
|
||||||
}
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Link Parent Meshes for shapes
|
|
||||||
*/
|
|
||||||
var shapes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Shape);
|
|
||||||
shapes.map(function(shape){
|
|
||||||
if (shape.parentMesh === data.mesh.id) {
|
|
||||||
shape.parentMesh = data.mesh;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Link Parent Meshes for raycast wheels
|
|
||||||
*/
|
|
||||||
var raycastWheels = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastWheel);
|
|
||||||
raycastWheels.map(function(wheel){
|
|
||||||
if (wheel.parentMesh === data.mesh.id) {
|
|
||||||
wheel.parentMesh = data.mesh;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Link Parent Meshes for rigidbodies
|
|
||||||
*/
|
|
||||||
var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody);
|
|
||||||
rigidBodies.map(function(rigidBody){
|
|
||||||
if (rigidBody.parentMesh === data.mesh.id) {
|
|
||||||
rigidBody.parentMesh = data.mesh;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.lightInstanceCreated = function(data) {
|
|
||||||
|
|
||||||
this.resolveDependencies(data.light);
|
|
||||||
|
|
||||||
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene);
|
|
||||||
|
|
||||||
scenes.map(function(scene){
|
|
||||||
if (data.light.parentScene === scene) {
|
|
||||||
scene.addObject(data.light);
|
|
||||||
|
|
||||||
//scene.updateInstance();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
|
|
||||||
|
|
||||||
this.resolveDependencies(data.scene);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add all meshes and lights
|
|
||||||
*/
|
|
||||||
var objects = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh,GameLib.D3.Light]);
|
|
||||||
objects.map(function(object){
|
|
||||||
if (
|
|
||||||
object.parentScene === data.scene.id
|
|
||||||
) {
|
|
||||||
object.parentScene = data.scene;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//data.scene.updateInstance();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.fontInstanceCreated = function(data) {
|
|
||||||
/**
|
|
||||||
* We resolve the dependencies
|
|
||||||
*/
|
|
||||||
this.resolveDependencies(data.font);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
|
|
||||||
/**
|
|
||||||
* We resolve the dependencies
|
|
||||||
*/
|
|
||||||
this.resolveDependencies(data.image);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* At this point - updateInstance on the texture will have been called - we need to update the material
|
|
||||||
*/
|
|
||||||
var textures = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Texture]);
|
|
||||||
|
|
||||||
//var materials = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Material]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find all textures which use this image
|
|
||||||
*/
|
|
||||||
textures.map(function(texture){
|
|
||||||
|
|
||||||
if (texture.image === data.image ||
|
|
||||||
texture.images.indexOf(data.image) !== -1
|
|
||||||
) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ok - this image is in use
|
|
||||||
*/
|
|
||||||
texture.updateInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find all materials that use this texture
|
|
||||||
* This is no longer necessary - because texture updateInstance should notify materials when its image changes
|
|
||||||
*/
|
|
||||||
// materials.map(function(material){
|
|
||||||
//
|
|
||||||
// var materialNeedsUpdate = false;
|
|
||||||
//
|
|
||||||
// for (var property in material) {
|
|
||||||
// if (material.hasOwnProperty(property) &&
|
|
||||||
// material[property] === texture) {
|
|
||||||
// materialNeedsUpdate = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (materialNeedsUpdate) {
|
|
||||||
// material.updateInstance();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.solverInstanceCreated = function(data) {
|
|
||||||
console.log(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.arrayItemAdded = function(data) {
|
GameLib.System.Linking.prototype.arrayItemAdded = function(data) {
|
||||||
if (
|
if (
|
||||||
data.component instanceof GameLib.D3.PhysicsWorld &&
|
data.component instanceof GameLib.D3.PhysicsWorld &&
|
||||||
|
@ -757,103 +556,135 @@ GameLib.System.Linking.prototype.arrayItemAdded = function(data) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.Linking.prototype.instanceCloned = function(data) {
|
||||||
|
if (
|
||||||
|
data.component.parentScene
|
||||||
|
) {
|
||||||
|
// data.component.parentScene.instance.add(data.instance);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.instanceCreated = function(data) {
|
GameLib.System.Linking.prototype.instanceCreated = function(data) {
|
||||||
|
|
||||||
this.resolveDependencies(data.component);
|
this.resolveDependencies(data.component);
|
||||||
|
|
||||||
if (data.component instanceof GameLib.D3.RaycastVehicle) {
|
if (data.component instanceof GameLib.D3.Image) {
|
||||||
|
/**
|
||||||
var worlds = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld);
|
* Find all textures which use this image
|
||||||
|
*/
|
||||||
|
GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Texture).map(
|
||||||
|
function(texture) {
|
||||||
|
if (texture.image === data.component ||
|
||||||
|
texture.images.indexOf(data.component) !== -1
|
||||||
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First ensure our parent world is linked
|
* Ok - this image is in use - this should notify materials when its image changes
|
||||||
*/
|
*/
|
||||||
worlds.map(
|
texture.updateInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link all scenes
|
||||||
|
*/
|
||||||
|
if (data.component instanceof GameLib.D3.Scene) {
|
||||||
|
/**
|
||||||
|
* Check ALL components for 'parentScenes' - this is expensive so it checks the register directly
|
||||||
|
*/
|
||||||
|
GameLib.EntityManager.Instance.register.map(
|
||||||
|
function(component) {
|
||||||
|
if (component.parentScene === data.component.id) {
|
||||||
|
component.parentScene = data.component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.component.parentScene &&
|
||||||
|
typeof data.component.parentScene === 'string'
|
||||||
|
) {
|
||||||
|
GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene).map(
|
||||||
|
function (scene) {
|
||||||
|
if (data.component.parentScene === scene.id) {
|
||||||
|
data.component.parentScene = scene;
|
||||||
|
scene.addObject(data.component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link all meshes
|
||||||
|
*/
|
||||||
|
if (data.component instanceof GameLib.D3.Mesh) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this mesh is a parentMesh to any component- this is an expensive call, so check if we should call it
|
||||||
|
* Also - it inspects the register directly instead of querying it twice (since it checks ALL components)
|
||||||
|
*/
|
||||||
|
if (!data.preventParentMeshCheck) {
|
||||||
|
GameLib.EntityManager.Instance.register.map(
|
||||||
|
function (component) {
|
||||||
|
if (component.parentMesh &&
|
||||||
|
component.parentMesh === data.component.id ) {
|
||||||
|
|
||||||
|
component.parentMesh = data.component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a component has this mesh as a parent
|
||||||
|
*/
|
||||||
|
if (component instanceof GameLib.D3.Mesh) {
|
||||||
|
component.setParentMesh(data.component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maybe this component has a parent mesh
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
data.component.parentMesh &&
|
||||||
|
typeof data.component.parentMesh === 'string'
|
||||||
|
) {
|
||||||
|
GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).map(
|
||||||
|
function (mesh) {
|
||||||
|
if (data.component.parentMesh === mesh.id) {
|
||||||
|
|
||||||
|
data.component.parentMesh = mesh;
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.D3.Mesh) {
|
||||||
|
data.component.setParentMesh(mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.component.parentWorld &&
|
||||||
|
typeof data.component.parentWorld === 'string'
|
||||||
|
) {
|
||||||
|
GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld).map(
|
||||||
function (world) {
|
function (world) {
|
||||||
if (data.component.parentWorld === world.id) {
|
if (data.component.parentWorld === world.id) {
|
||||||
data.component.parentWorld = world;
|
data.component.parentWorld = world;
|
||||||
|
|
||||||
|
if (typeof data.component.instance.addToWorld === 'function') {
|
||||||
|
data.component.instance.addToWorld(world.instance);
|
||||||
|
console.log('instance added to physics world');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!data.component.parentWorld) {
|
|
||||||
console.log('no parent world');
|
|
||||||
} else {
|
|
||||||
data.component.instance.addToWorld(data.component.parentWorld.instance);
|
|
||||||
console.log('raycast vehicle instance added to its parent world');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (data.component instanceof GameLib.D3.RigidBody) {
|
|
||||||
|
|
||||||
var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh);
|
|
||||||
|
|
||||||
meshes.map(
|
|
||||||
function(mesh) {
|
|
||||||
if (data.component.parentMesh === mesh.id) {
|
|
||||||
data.component.parentMesh = mesh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.restart();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.shapeInstanceCreated = function(data) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When a shape instance is created, just check if the parentMesh is loaded somewhere and set it.
|
|
||||||
*
|
|
||||||
* We also do the reverse, when a mesh instance is created, we check if its the parent of any shape.
|
|
||||||
*/
|
|
||||||
var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh);
|
|
||||||
meshes.map(
|
|
||||||
function(mesh) {
|
|
||||||
if (data.shape.parentMesh === mesh.id) {
|
|
||||||
data.shape.parentMesh = mesh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.textureInstanceCreated = function(data) {
|
|
||||||
this.resolveDependencies(data.texture);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.materialInstanceCreated = function(data) {
|
|
||||||
this.resolveDependencies(data.material);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.physicsWorldInstanceCreated = function(data) {
|
|
||||||
|
|
||||||
var raycastVehicles = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastVehicle);
|
|
||||||
raycastVehicles.map(
|
|
||||||
function(vehicle) {
|
|
||||||
if (vehicle.parentWorld === data.world.id) {
|
|
||||||
vehicle.parentWorld = data.world;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody);
|
|
||||||
rigidBodies.map(
|
|
||||||
function(rigidBody){
|
|
||||||
if (rigidBody.parentWorld === data.world.id) {
|
|
||||||
rigidBody.parentWorld = data.world;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var contactMaterials = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.FrictionContactMaterial);
|
|
||||||
contactMaterials.map(
|
|
||||||
function(contactMaterial) {
|
|
||||||
if (contactMaterial.parentWorld === data.world.id) {
|
|
||||||
contactMaterial.parentWorld = data.world;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1055,6 +886,7 @@ GameLib.System.Linking.prototype.stop = function() {
|
||||||
* Components
|
* Components
|
||||||
*/
|
*/
|
||||||
this.componentCreatedSubscription.remove();
|
this.componentCreatedSubscription.remove();
|
||||||
|
this.componentClonedSubscription.remove();
|
||||||
this.registerDependenciesSubscription.remove();
|
this.registerDependenciesSubscription.remove();
|
||||||
this.componentRemoveSubscription.remove();
|
this.componentRemoveSubscription.remove();
|
||||||
|
|
||||||
|
@ -1069,16 +901,7 @@ GameLib.System.Linking.prototype.stop = function() {
|
||||||
* Instances
|
* Instances
|
||||||
*/
|
*/
|
||||||
this.instanceCreatedSubscription.remove();
|
this.instanceCreatedSubscription.remove();
|
||||||
this.meshInstanceCreatedSubscription.remove();
|
this.instanceClonedSubscription.remove();
|
||||||
this.lightInstanceCreatedSubscription.remove();
|
|
||||||
this.sceneInstanceCreatedSubscription.remove();
|
|
||||||
this.imageInstanceCreatedSubscription.remove();
|
|
||||||
this.fontInstanceCreatedSubscription.remove();
|
|
||||||
this.textureInstanceCreatedSubscription.remove();
|
|
||||||
this.materialInstanceCreatedSubscription.remove();
|
|
||||||
this.shapeInstanceCreatedSubscription.remove();
|
|
||||||
this.solverInstanceCreatedSubscription.remove();
|
|
||||||
this.physicsWorldInstanceCreatedSubscription.remove();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Meshes
|
* Meshes
|
||||||
|
|
|
@ -915,13 +915,7 @@ GameLib.System.Storage.prototype.loadFont = function(data) {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
data.font.instance = font;
|
data.font.instance = font;
|
||||||
data.font.loaded = true;
|
data.font.createInstance();
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.FONT_INSTANCE_CREATED,
|
|
||||||
{
|
|
||||||
font: data.font
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue