fixed render problem for now
parent
5fa8e6583d
commit
1aa01c95a3
|
@ -107,8 +107,8 @@ GameLib.Component.prototype.performInstanceCreation = function() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* Some systems require a restart in order to create the delayed components (like System.Input for
|
* Some systems require an instance creation at an exact time, like System.Input for Edit Controls -
|
||||||
* Edit Controls) - we need to give them the opportunity to restart
|
* we need to give them the opportunity to handle this situation
|
||||||
*/
|
*/
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,
|
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,
|
||||||
|
@ -997,30 +997,24 @@ GameLib.Component.prototype.generateNewIds = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: don't remove components which are still in use elsewhere - this is important to prevent 'register out
|
||||||
|
* of sync' messages
|
||||||
|
*/
|
||||||
GameLib.Component.prototype.remove = function() {
|
GameLib.Component.prototype.remove = function() {
|
||||||
|
|
||||||
this.buildIdToObject();
|
this.buildIdToObject();
|
||||||
|
|
||||||
var dependencies = this.getDependencies();
|
Object.keys(this.idToObject).map(
|
||||||
|
function(componentId){
|
||||||
dependencies.map(
|
|
||||||
function(objectId) {
|
|
||||||
|
|
||||||
var childComponent = this.idToObject[objectId];
|
|
||||||
|
|
||||||
if (childComponent instanceof GameLib.Component) {
|
|
||||||
childComponent.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.REMOVE_COMPONENT,
|
GameLib.Event.REMOVE_COMPONENT,
|
||||||
{
|
{
|
||||||
component : this
|
component : this.idToObject[componentId]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,9 @@
|
||||||
*/
|
*/
|
||||||
GameLib.API.Controls = function(
|
GameLib.API.Controls = function(
|
||||||
id,
|
id,
|
||||||
controlsType,
|
|
||||||
name,
|
name,
|
||||||
|
controlsType,
|
||||||
domElement,
|
domElement,
|
||||||
// fullscreen,
|
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
@ -23,19 +22,19 @@ GameLib.API.Controls = function(
|
||||||
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
||||||
|
|
||||||
if (this instanceof GameLib.Controls.D3.Editor) {
|
if (this instanceof GameLib.Controls.D3.Editor) {
|
||||||
controlsType = GameLib.Controls.CONTROLS_TYPE_EDITOR;
|
controlsType = GameLib.API.Controls.CONTROLS_TYPE_EDITOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this instanceof GameLib.Controls.Touch) {
|
if (this instanceof GameLib.Controls.Touch) {
|
||||||
controlsType = GameLib.Controls.CONTROLS_TYPE_TOUCH;
|
controlsType = GameLib.API.Controls.CONTROLS_TYPE_TOUCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this instanceof GameLib.Controls.Keyboard) {
|
if (this instanceof GameLib.Controls.Keyboard) {
|
||||||
controlsType = GameLib.Controls.CONTROLS_TYPE_KEYBOARD;
|
controlsType = GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this instanceof GameLib.Controls.Mouse) {
|
if (this instanceof GameLib.Controls.Mouse) {
|
||||||
controlsType = GameLib.Controls.CONTROLS_TYPE_MOUSE;
|
controlsType = GameLib.API.Controls.CONTROLS_TYPE_MOUSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
||||||
|
@ -46,19 +45,19 @@ GameLib.API.Controls = function(
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
|
||||||
if (controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_EDITOR) {
|
||||||
name = 'Editing Controls';
|
name = 'Editing Controls';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controlsType === GameLib.Controls.CONTROLS_TYPE_TOUCH) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_TOUCH) {
|
||||||
name = 'Touch Controls';
|
name = 'Touch Controls';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controlsType === GameLib.Controls.CONTROLS_TYPE_KEYBOARD) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD) {
|
||||||
name = 'Keyboard Controls';
|
name = 'Keyboard Controls';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controlsType === GameLib.Controls.CONTROLS_TYPE_MOUSE) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_MOUSE) {
|
||||||
name = 'Mouse Controls';
|
name = 'Mouse Controls';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,19 +72,19 @@ GameLib.API.Controls = function(
|
||||||
|
|
||||||
var componentType = GameLib.Component.CONTROLS;
|
var componentType = GameLib.Component.CONTROLS;
|
||||||
|
|
||||||
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_EDITOR) {
|
||||||
componentType = GameLib.Component.CONTROLS_EDITOR;
|
componentType = GameLib.Component.CONTROLS_EDITOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_TOUCH) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_TOUCH) {
|
||||||
componentType = GameLib.Component.CONTROLS_TOUCH
|
componentType = GameLib.Component.CONTROLS_TOUCH
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_KEYBOARD) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD) {
|
||||||
componentType = GameLib.Component.CONTROLS_KEYBOARD
|
componentType = GameLib.Component.CONTROLS_KEYBOARD
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_MOUSE) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_MOUSE) {
|
||||||
componentType = GameLib.Component.CONTROLS_MOUSE
|
componentType = GameLib.Component.CONTROLS_MOUSE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +98,18 @@ GameLib.API.Controls = function(
|
||||||
GameLib.API.Controls.prototype = Object.create(GameLib.API.Component.prototype);
|
GameLib.API.Controls.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
GameLib.API.Controls.prototype.constructor = GameLib.API.Controls;
|
GameLib.API.Controls.prototype.constructor = GameLib.API.Controls;
|
||||||
|
|
||||||
|
GameLib.API.Controls.D3 = function() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls Type
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.API.Controls.CONTROLS_TYPE_EDITOR = 0x0;
|
||||||
|
GameLib.API.Controls.CONTROLS_TYPE_TOUCH = 0x1;
|
||||||
|
GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
|
||||||
|
GameLib.API.Controls.CONTROLS_TYPE_MOUSE = 0x3;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an API Controls from an Object
|
* Returns an API Controls from an Object
|
||||||
* @param objectControls
|
* @param objectControls
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
* @param apiControls
|
||||||
|
* @param raycaster
|
||||||
|
* @param camera
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Controls.D3.Editor = function(
|
||||||
|
apiControls,
|
||||||
|
raycaster,
|
||||||
|
camera
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||||
|
apiControls = {
|
||||||
|
controlsType : GameLib.API.Controls.CONTROLS_TYPE_EDITOR
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Controls.call(
|
||||||
|
this,
|
||||||
|
apiControls.id,
|
||||||
|
apiControls.name,
|
||||||
|
apiControls.controlsType,
|
||||||
|
apiControls.domElement,
|
||||||
|
apiControls.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
||||||
|
raycaster = new GameLib.D3.API.Raycaster();
|
||||||
|
}
|
||||||
|
this.raycaster = raycaster;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
|
camera = new GameLib.D3.API.Camera();
|
||||||
|
}
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.CONTROLS_EDITOR
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.API.Controls.D3.Editor.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||||
|
GameLib.API.Controls.D3.Editor.prototype.constructor = GameLib.API.Controls.D3.Editor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an API.Controls.D3.Editor from an Object Cast
|
||||||
|
* @param objectControls
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Controls.D3.Editor.FromObject = function(objectControls) {
|
||||||
|
|
||||||
|
var apiControls = GameLib.API.Controls.FromObject(objectControls);
|
||||||
|
|
||||||
|
return new GameLib.API.Controls.D3.Editor(
|
||||||
|
apiControls,
|
||||||
|
objectControls.raycaster,
|
||||||
|
objectControls.camera
|
||||||
|
);
|
||||||
|
};
|
|
@ -14,12 +14,20 @@ GameLib.API.Socket.Cast = function(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
||||||
apiSocket = {};
|
apiSocket = {
|
||||||
|
socketType : GameLib.API.Socket.SOCKET_CAST
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.API.Socket.call(
|
GameLib.API.Socket.call(
|
||||||
this,
|
this,
|
||||||
apiSocket
|
apiSocket.id,
|
||||||
|
apiSocket.name,
|
||||||
|
apiSocket.socketType,
|
||||||
|
apiSocket.roomId,
|
||||||
|
apiSocket.peerId,
|
||||||
|
apiSocket.server,
|
||||||
|
apiSocket.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(castType)) {
|
if (GameLib.Utils.UndefinedOrNull(castType)) {
|
||||||
|
|
|
@ -14,12 +14,20 @@ GameLib.API.Socket.Receive = function(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
||||||
apiSocket = {};
|
apiSocket = {
|
||||||
|
socketType : GameLib.API.Socket.SOCKET_RECEIVE
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.API.Socket.call(
|
GameLib.API.Socket.call(
|
||||||
this,
|
this,
|
||||||
apiSocket
|
apiSocket.id,
|
||||||
|
apiSocket.name,
|
||||||
|
apiSocket.socketType,
|
||||||
|
apiSocket.roomId,
|
||||||
|
apiSocket.peerId,
|
||||||
|
apiSocket.server,
|
||||||
|
apiSocket.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(receiveType)) {
|
if (GameLib.Utils.UndefinedOrNull(receiveType)) {
|
||||||
|
|
|
@ -29,6 +29,12 @@ GameLib.API.Vector2.prototype.equals = function (v) {
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Vector2.FromObject = function (objectVector) {
|
GameLib.API.Vector2.FromObject = function (objectVector) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(objectVector)) {
|
||||||
|
console.warn('vector from db undefined - stale version in db');
|
||||||
|
objectVector = {};
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.API.Vector2(
|
return new GameLib.API.Vector2(
|
||||||
objectVector.x,
|
objectVector.x,
|
||||||
objectVector.y
|
objectVector.y
|
||||||
|
|
|
@ -263,6 +263,12 @@ GameLib.API.Vector3.prototype.angleTo = function (v) {
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Vector3.FromObject = function (objectVector) {
|
GameLib.API.Vector3.FromObject = function (objectVector) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(objectVector)) {
|
||||||
|
console.warn('vector from db undefined - stale version in db');
|
||||||
|
objectVector = {};
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.API.Vector3(
|
return new GameLib.API.Vector3(
|
||||||
objectVector.x,
|
objectVector.x,
|
||||||
objectVector.y,
|
objectVector.y,
|
||||||
|
|
|
@ -31,6 +31,12 @@ GameLib.API.Vector4.prototype.equals = function (v) {
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Vector4.FromObject = function (objectVector) {
|
GameLib.API.Vector4.FromObject = function (objectVector) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(objectVector)) {
|
||||||
|
console.warn('vector from db undefined - stale version in db');
|
||||||
|
objectVector = {};
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.API.Vector4(
|
return new GameLib.API.Vector4(
|
||||||
objectVector.x,
|
objectVector.x,
|
||||||
objectVector.y,
|
objectVector.y,
|
||||||
|
|
|
@ -14,8 +14,8 @@ GameLib.Controls = function (
|
||||||
GameLib.API.Controls.call(
|
GameLib.API.Controls.call(
|
||||||
this,
|
this,
|
||||||
apiControls.id,
|
apiControls.id,
|
||||||
apiControls.controlsType,
|
|
||||||
apiControls.name,
|
apiControls.name,
|
||||||
|
apiControls.controlsType,
|
||||||
apiControls.domElement,
|
apiControls.domElement,
|
||||||
apiControls.parentEntity
|
apiControls.parentEntity
|
||||||
);
|
);
|
||||||
|
@ -26,7 +26,7 @@ GameLib.Controls = function (
|
||||||
|
|
||||||
var delayed = false;
|
var delayed = false;
|
||||||
|
|
||||||
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) {
|
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_EDITOR) {
|
||||||
|
|
||||||
linkedObjects.raycaster = GameLib.D3.Raycaster;
|
linkedObjects.raycaster = GameLib.D3.Raycaster;
|
||||||
linkedObjects.camera = GameLib.D3.Camera;
|
linkedObjects.camera = GameLib.D3.Camera;
|
||||||
|
@ -46,15 +46,6 @@ GameLib.Controls.prototype.constructor = GameLib.Controls;
|
||||||
|
|
||||||
GameLib.Controls.D3 = function() {};
|
GameLib.Controls.D3 = function() {};
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls Type
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
GameLib.Controls.CONTROLS_TYPE_EDITOR = 0x0;
|
|
||||||
GameLib.Controls.CONTROLS_TYPE_TOUCH = 0x1;
|
|
||||||
GameLib.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
|
|
||||||
GameLib.Controls.CONTROLS_TYPE_MOUSE = 0x3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mesh instance or updates it
|
* Creates a mesh instance or updates it
|
||||||
*/
|
*/
|
||||||
|
@ -77,8 +68,8 @@ GameLib.Controls.prototype.toApiObject = function() {
|
||||||
|
|
||||||
var apiControls = new GameLib.API.Controls(
|
var apiControls = new GameLib.API.Controls(
|
||||||
this.id,
|
this.id,
|
||||||
this.controlsType,
|
|
||||||
this.name,
|
this.name,
|
||||||
|
this.controlsType,
|
||||||
GameLib.Utils.IdOrNull(this.domElement),
|
GameLib.Utils.IdOrNull(this.domElement),
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,30 +1,29 @@
|
||||||
/**
|
/**
|
||||||
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
|
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
|
||||||
* @param graphics GameLib.GraphicsRuntime
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
* @param apiControls GameLib.API.Controls
|
* @param apiEditorControls
|
||||||
* @param raycaster
|
|
||||||
* @param camera
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Controls.D3.Editor = function (
|
GameLib.Controls.D3.Editor = function (
|
||||||
graphics,
|
graphics,
|
||||||
apiControls,
|
apiEditorControls
|
||||||
raycaster,
|
|
||||||
camera
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
if (GameLib.Utils.UndefinedOrNull(apiEditorControls)) {
|
||||||
raycaster = null;
|
apiEditorControls = {
|
||||||
|
controlsType : GameLib.API.Controls.CONTROLS_TYPE_EDITOR
|
||||||
|
};
|
||||||
}
|
}
|
||||||
this.raycaster = raycaster;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
GameLib.API.Controls.D3.Editor.call(
|
||||||
camera = null;
|
this,
|
||||||
}
|
apiEditorControls,
|
||||||
this.camera = camera;
|
apiEditorControls.raycaster,
|
||||||
|
apiEditorControls.camera
|
||||||
|
);
|
||||||
|
|
||||||
if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
|
if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
|
||||||
this.raycaster = new GameLib.D3.Raycaster(
|
this.raycaster = new GameLib.D3.Raycaster(
|
||||||
|
@ -42,8 +41,9 @@ GameLib.Controls.D3.Editor = function (
|
||||||
|
|
||||||
GameLib.Controls.call(
|
GameLib.Controls.call(
|
||||||
this,
|
this,
|
||||||
apiControls
|
apiEditorControls
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,11 +110,11 @@ GameLib.Controls.D3.Editor.FromObject = function(graphics, objectControls) {
|
||||||
|
|
||||||
var apiControls = GameLib.API.Controls.FromObject(objectControls);
|
var apiControls = GameLib.API.Controls.FromObject(objectControls);
|
||||||
|
|
||||||
|
var apiEditorControls = GameLib.API.Controls.D3.Editor.FromObject(objectControls);
|
||||||
|
|
||||||
return new GameLib.Controls.D3.Editor(
|
return new GameLib.Controls.D3.Editor(
|
||||||
graphics,
|
graphics,
|
||||||
apiControls,
|
apiEditorControls
|
||||||
objectControls.raycaster,
|
|
||||||
objectControls.camera
|
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
|
@ -32,6 +32,7 @@
|
||||||
* @param depth
|
* @param depth
|
||||||
* @param logarithmicDepthBuffer
|
* @param logarithmicDepthBuffer
|
||||||
* @param fullscreen
|
* @param fullscreen
|
||||||
|
* @param offset
|
||||||
* @param canvas
|
* @param canvas
|
||||||
* @param renderTarget
|
* @param renderTarget
|
||||||
* @param localClippingEnabled
|
* @param localClippingEnabled
|
||||||
|
@ -78,6 +79,8 @@ GameLib.D3.API.Renderer = function (
|
||||||
logarithmicDepthBuffer,
|
logarithmicDepthBuffer,
|
||||||
localClippingEnabled,
|
localClippingEnabled,
|
||||||
fullscreen,
|
fullscreen,
|
||||||
|
windowSize,
|
||||||
|
offset,
|
||||||
canvas,
|
canvas,
|
||||||
renderTarget,
|
renderTarget,
|
||||||
clippingPlanes,
|
clippingPlanes,
|
||||||
|
@ -99,12 +102,12 @@ GameLib.D3.API.Renderer = function (
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
width = 512;
|
width = 1;
|
||||||
}
|
}
|
||||||
this.width = width;
|
this.width = width;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
height = 512;
|
height = 1;
|
||||||
}
|
}
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
|
@ -253,12 +256,25 @@ GameLib.D3.API.Renderer = function (
|
||||||
}
|
}
|
||||||
this.fullscreen = fullscreen;
|
this.fullscreen = fullscreen;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(windowSize)) {
|
||||||
|
windowSize = new GameLib.API.Vector2(
|
||||||
|
512,
|
||||||
|
512
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.windowSize = windowSize;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(offset)) {
|
||||||
|
offset = new GameLib.API.Vector2(0,0);
|
||||||
|
}
|
||||||
|
this.offset = offset;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(canvas)) {
|
if (GameLib.Utils.UndefinedOrNull(canvas)) {
|
||||||
canvas = new GameLib.API.Canvas(
|
canvas = new GameLib.API.Canvas(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
this.width,
|
this.windowSize.x,
|
||||||
this.height
|
this.windowSize.y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
|
@ -376,6 +392,8 @@ GameLib.D3.API.Renderer.FromObject = function(objectRenderer) {
|
||||||
objectRenderer.logarithmicDepthBuffer,
|
objectRenderer.logarithmicDepthBuffer,
|
||||||
objectRenderer.localClippingEnabled,
|
objectRenderer.localClippingEnabled,
|
||||||
objectRenderer.fullscreen,
|
objectRenderer.fullscreen,
|
||||||
|
GameLib.API.Vector2.FromObject(objectRenderer.windowSize),
|
||||||
|
GameLib.API.Vector2.FromObject(objectRenderer.offset),
|
||||||
objectRenderer.canvas,
|
objectRenderer.canvas,
|
||||||
objectRenderer.renderTarget,
|
objectRenderer.renderTarget,
|
||||||
objectRenderer.clippingPlanes,
|
objectRenderer.clippingPlanes,
|
||||||
|
|
|
@ -129,7 +129,7 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
|
||||||
GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
|
GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
|
||||||
|
|
||||||
var apiMeshPlane = new GameLib.D3.API.Mesh.Plane(
|
var apiMeshPlane = new GameLib.D3.API.Mesh.Plane(
|
||||||
GameLib.D3.API.Mesh.prototype.toApiObject.call(this),
|
GameLib.D3.Mesh.prototype.toApiObject.call(this),
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.widthSegments,
|
this.widthSegments,
|
||||||
|
|
|
@ -51,6 +51,8 @@ GameLib.D3.Renderer = function (
|
||||||
apiRenderer.logarithmicDepthBuffer,
|
apiRenderer.logarithmicDepthBuffer,
|
||||||
apiRenderer.localClippingEnabled,
|
apiRenderer.localClippingEnabled,
|
||||||
apiRenderer.fullscreen,
|
apiRenderer.fullscreen,
|
||||||
|
apiRenderer.windowSize,
|
||||||
|
apiRenderer.offset,
|
||||||
apiRenderer.canvas,
|
apiRenderer.canvas,
|
||||||
apiRenderer.renderTarget,
|
apiRenderer.renderTarget,
|
||||||
apiRenderer.clippingPlanes,
|
apiRenderer.clippingPlanes,
|
||||||
|
@ -62,6 +64,18 @@ GameLib.D3.Renderer = function (
|
||||||
apiRenderer.parentEntity
|
apiRenderer.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.windowSize = new GameLib.Vector2(
|
||||||
|
this.graphics,
|
||||||
|
this.windowSize,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
this.offset = new GameLib.Vector2(
|
||||||
|
this.graphics,
|
||||||
|
this.offset,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
if (this.canvas instanceof GameLib.API.Canvas) {
|
if (this.canvas instanceof GameLib.API.Canvas) {
|
||||||
this.canvas = new GameLib.Canvas(
|
this.canvas = new GameLib.Canvas(
|
||||||
this.canvas
|
this.canvas
|
||||||
|
@ -174,10 +188,13 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance.setSize(
|
this.instance.setSize(
|
||||||
this.width,
|
this.width * this.windowSize.x,
|
||||||
this.height
|
this.height * this.windowSize.y
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px';
|
||||||
|
this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px';
|
||||||
|
|
||||||
this.instance.autoClear = this.autoClear;
|
this.instance.autoClear = this.autoClear;
|
||||||
this.instance.autoClearColor = this.autoClearColor;
|
this.instance.autoClearColor = this.autoClearColor;
|
||||||
this.instance.autoClearDepth = this.autoClearDepth;
|
this.instance.autoClearDepth = this.autoClearDepth;
|
||||||
|
@ -246,40 +263,41 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
|
||||||
throw new Error('no renderer instance');
|
throw new Error('no renderer instance');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var trueWidth;
|
||||||
|
var trueHeight;
|
||||||
|
|
||||||
if (property === 'width') {
|
if (property === 'width') {
|
||||||
|
|
||||||
this.width = Math.round(this.width);
|
trueWidth = this.width * this.windowSize.x;
|
||||||
|
|
||||||
this.canvas.width = this.width;
|
|
||||||
|
|
||||||
|
this.canvas.width = trueWidth;
|
||||||
this.canvas.updateInstance('width');
|
this.canvas.updateInstance('width');
|
||||||
|
|
||||||
this.instance.setSize(this.width, this.height);
|
this.instance.setSize(trueWidth, this.height * this.windowSize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'height') {
|
if (property === 'height') {
|
||||||
|
|
||||||
this.height = Math.round(this.height);
|
trueHeight = this.height * this.windowSize.y;
|
||||||
|
|
||||||
this.canvas.height = this.height;
|
|
||||||
|
|
||||||
|
this.canvas.height = trueHeight;
|
||||||
this.canvas.updateInstance('height');
|
this.canvas.updateInstance('height');
|
||||||
|
|
||||||
this.instance.setSize(this.width, this.height);
|
this.instance.setSize(this.width * this.windowSize.x, trueHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'widthheight') {
|
if (property === 'widthheight') {
|
||||||
|
|
||||||
this.width = Math.round(this.width);
|
trueWidth = this.width * this.windowSize.x;
|
||||||
this.height = Math.round(this.height);
|
trueHeight = this.height * this.windowSize.y;
|
||||||
|
|
||||||
this.canvas.width = this.width;
|
this.canvas.width = trueWidth;
|
||||||
this.canvas.height = this.height;
|
this.canvas.height = trueHeight;
|
||||||
|
|
||||||
this.canvas.updateInstance('width');
|
this.canvas.updateInstance('width');
|
||||||
this.canvas.updateInstance('height');
|
this.canvas.updateInstance('height');
|
||||||
|
|
||||||
this.instance.setSize(this.width, this.height);
|
this.instance.setSize(trueWidth, trueHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'renderMode') {
|
if (property === 'renderMode') {
|
||||||
|
@ -398,6 +416,31 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
|
||||||
this.instance.localClippingEnabled = this.localClippingEnabled;
|
this.instance.localClippingEnabled = this.localClippingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property === 'windowSize') {
|
||||||
|
|
||||||
|
trueWidth = this.width * this.windowSize.x;
|
||||||
|
trueHeight = this.height * this.windowSize.y;
|
||||||
|
|
||||||
|
this.canvas.width = trueWidth;
|
||||||
|
this.canvas.height = trueHeight;
|
||||||
|
|
||||||
|
this.canvas.updateInstance('width');
|
||||||
|
this.canvas.updateInstance('height');
|
||||||
|
|
||||||
|
this.instance.setSize(
|
||||||
|
trueWidth,
|
||||||
|
trueHeight
|
||||||
|
);
|
||||||
|
|
||||||
|
this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px';
|
||||||
|
this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'offset') {
|
||||||
|
this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px';
|
||||||
|
this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
if (property === 'canvas') {
|
if (property === 'canvas') {
|
||||||
console.warn('experimental canvas change for renderer');
|
console.warn('experimental canvas change for renderer');
|
||||||
this.instance.dispose();
|
this.instance.dispose();
|
||||||
|
@ -483,6 +526,9 @@ GameLib.D3.Renderer.prototype.toApiObject = function() {
|
||||||
this.depth,
|
this.depth,
|
||||||
this.logarithmicDepthBuffer,
|
this.logarithmicDepthBuffer,
|
||||||
this.localClippingEnabled,
|
this.localClippingEnabled,
|
||||||
|
this.fullscreen,
|
||||||
|
this.windowSize.toApiObject(),
|
||||||
|
this.offset.toApiObject(),
|
||||||
GameLib.Utils.IdOrNull(this.canvas),
|
GameLib.Utils.IdOrNull(this.canvas),
|
||||||
GameLib.Utils.IdOrNull(this.renderTarget),
|
GameLib.Utils.IdOrNull(this.renderTarget),
|
||||||
this.clippingPlanes.map(
|
this.clippingPlanes.map(
|
||||||
|
|
|
@ -464,9 +464,9 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.parentEntity) {
|
// if (this.parentEntity) {
|
||||||
this.parentEntity.addComponent(object);
|
// this.parentEntity.addComponent(object);
|
||||||
}
|
// }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -531,10 +531,10 @@ GameLib.D3.Scene.prototype.removeObject = function(object) {
|
||||||
if (object.parentScene === this) {
|
if (object.parentScene === this) {
|
||||||
object.parentScene = null;
|
object.parentScene = null;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
if (this.parentEntity) {
|
// if (this.parentEntity) {
|
||||||
this.parentEntity.removeComponent(object);
|
// this.parentEntity.removeComponent(object);
|
||||||
}
|
// }
|
||||||
// this.buildIdToObject();
|
// this.buildIdToObject();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1404,7 +1404,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
controllers.push(folder.add(object, property, 1, 1000, 1));
|
controllers.push(folder.add(object, property, 1, 1000, 1));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'width' ||
|
property === 'width' ||
|
||||||
property === 'height' ||
|
property === 'height'
|
||||||
|
) {
|
||||||
|
controllers.push(folder.add(object, property, 0, 1, 0.001));
|
||||||
|
} else if (
|
||||||
property === 'depth' ||
|
property === 'depth' ||
|
||||||
property === 'radius'
|
property === 'radius'
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -26,37 +26,38 @@ GameLib.System.Input = function(
|
||||||
* Touch Controls
|
* Touch Controls
|
||||||
* @type {null}
|
* @type {null}
|
||||||
*/
|
*/
|
||||||
this.touchStart = null;
|
this.touchStart = this.onTouchStart.bind(this);
|
||||||
this.touchMove = null;
|
this.touchMove = this.onTouchMove.bind(this);
|
||||||
this.touchEnd = null;
|
this.touchEnd = this.onTouchEnd.bind(this);
|
||||||
this.touchCancel = null;
|
this.touchCancel = this.onTouchCancel.bind(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keyboard Controls
|
* Keyboard Controls
|
||||||
* @type {null}
|
* @type {null}
|
||||||
*/
|
*/
|
||||||
this.keyboardKeyUp = null;
|
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
|
||||||
this.keyboardKeyDown = null;
|
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mouse Controls
|
* Mouse Controls
|
||||||
* @type {null}
|
* @type {null}
|
||||||
*/
|
*/
|
||||||
this.mouseDown = null;
|
this.mouseDown = this.onMouseDown.bind(this);
|
||||||
this.mouseMove = null;
|
this.mouseMove = this.onMouseMove.bind(this);
|
||||||
this.mouseWheel = null;
|
this.mouseWheel = this.onMouseWheel.bind(this);
|
||||||
this.mouseUp = null;
|
this.mouseUp = this.onMouseUp.bind(this);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Editor Controls
|
* Editor Controls
|
||||||
* @type {null}
|
* @type {null}
|
||||||
*/
|
*/
|
||||||
this.keyDown = null;
|
this.keyDown = this.onKeyDown.bind(this);
|
||||||
this.keyUp = null;
|
this.keyUp = this.onKeyUp.bind(this);
|
||||||
this.mouseDownEdit = null;
|
this.mouseDownEdit = this.onMouseDownEdit.bind(this);
|
||||||
this.mouseMoveEdit = null;
|
this.mouseMoveEdit = this.onMouseMoveEdit.bind(this);
|
||||||
this.mouseWheelEdit = null;
|
this.mouseWheelEdit = this.onMouseWheelEdit.bind(this);
|
||||||
this.mouseUpEdit = null;
|
this.mouseUpEdit = this.onMouseUpEdit.bind(this);
|
||||||
|
|
||||||
this.delayedInstanceEncounteredSubscription = null;
|
this.delayedInstanceEncounteredSubscription = null;
|
||||||
this.instanceCreatedSubscription = null;
|
this.instanceCreatedSubscription = null;
|
||||||
|
@ -75,14 +76,6 @@ GameLib.System.Input.prototype.start = function() {
|
||||||
|
|
||||||
GameLib.System.prototype.start.call(this);
|
GameLib.System.prototype.start.call(this);
|
||||||
|
|
||||||
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR);
|
|
||||||
|
|
||||||
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_TOUCH);
|
|
||||||
|
|
||||||
this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_KEYBOARD);
|
|
||||||
|
|
||||||
this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_MOUSE);
|
|
||||||
|
|
||||||
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
||||||
GameLib.Event.INSTANCE_CREATED,
|
GameLib.Event.INSTANCE_CREATED,
|
||||||
this.instanceCreated.bind(this)
|
this.instanceCreated.bind(this)
|
||||||
|
@ -98,16 +91,40 @@ GameLib.System.Input.prototype.start = function() {
|
||||||
this.delayedInstanceEncountered.bind(this)
|
this.delayedInstanceEncountered.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR);
|
||||||
|
|
||||||
|
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_TOUCH);
|
||||||
|
|
||||||
|
this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_KEYBOARD);
|
||||||
|
|
||||||
|
this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_MOUSE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we have touch controls - inject them first so we can override editor controls if necessary
|
* If we have touch controls - inject them first so we can override editor controls if necessary
|
||||||
*/
|
*/
|
||||||
this.registerTouchControls();
|
this.touchControls.map(
|
||||||
|
function(touchControl){
|
||||||
|
this.registerTouchControls(touchControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.registerKeyboardControls();
|
this.keyboardControls.map(
|
||||||
|
function(keyboardControl){
|
||||||
|
this.registerKeyboardControls(keyboardControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.registerMouseControls();
|
this.mouseControls.map(
|
||||||
|
function(mouseControl){
|
||||||
|
this.registerMouseControls(mouseControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.registerEditorControls();
|
this.editorControls.map(
|
||||||
|
function(editorControl){
|
||||||
|
this.registerEditorControls(editorControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -124,13 +141,29 @@ GameLib.System.Input.prototype.stop = function() {
|
||||||
|
|
||||||
this.delayedInstanceEncounteredSubscription.remove();
|
this.delayedInstanceEncounteredSubscription.remove();
|
||||||
|
|
||||||
this.deRegisterEditorControls();
|
this.touchControls.map(
|
||||||
|
function(touchControl){
|
||||||
|
this.deRegisterTouchControls(touchControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.deRegisterTouchControls();
|
this.keyboardControls.map(
|
||||||
|
function(keyboardControl){
|
||||||
|
this.deRegisterKeyboardControls(keyboardControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.deRegisterKeyboardControls();
|
this.mouseControls.map(
|
||||||
|
function(mouseControl){
|
||||||
|
this.deRegisterMouseControls(mouseControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.deRegisterMouseControls();
|
this.editorControls.map(
|
||||||
|
function(editorControl){
|
||||||
|
this.deRegisterEditorControls(editorControl);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.editorControls = [];
|
this.editorControls = [];
|
||||||
|
|
||||||
|
@ -148,66 +181,111 @@ GameLib.System.Input.prototype.stop = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.System.Input.prototype.instanceCreated = function(data) {
|
GameLib.System.Input.prototype.instanceCreated = function(data) {
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Controls.D3.Editor) {
|
if (data.component instanceof GameLib.Controls.Touch) {
|
||||||
if (this.editorControls.length > 0) {
|
|
||||||
console.log('Ignoring multiple editor controls')
|
if (this.touchControls.indexOf(data.component) !== -1) {
|
||||||
} else {
|
console.warn('Touch controls already registered');
|
||||||
this.editorControls.push(data.component);
|
return;
|
||||||
this.registerEditorControls();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Controls.Touch) {
|
|
||||||
if (this.touchControls.length > 0) {
|
|
||||||
console.log('Ignoring multiple touch controls')
|
|
||||||
} else {
|
|
||||||
this.touchControls.push(data.component);
|
this.touchControls.push(data.component);
|
||||||
this.registerTouchControls();
|
this.registerTouchControls(data.component);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Controls.Keyboard) {
|
if (data.component instanceof GameLib.Controls.Keyboard) {
|
||||||
if (this.keyboardControls.length > 0 || this.editorControls.length > 0) {
|
|
||||||
console.log('Ignoring multiple keyboard controls')
|
if (this.keyboardControls.indexOf(data.component) !== -1) {
|
||||||
} else {
|
console.warn('Keyboard controls already registered');
|
||||||
this.keyboardControls.push(data.component);
|
return;
|
||||||
this.registerKeyboardControls();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.keyboardControls.push(data.component);
|
||||||
|
this.registerKeyboardControls(data.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Controls.Mouse) {
|
if (data.component instanceof GameLib.Controls.Mouse) {
|
||||||
if (this.mouseControls.length > 0) {
|
|
||||||
console.log('Ignoring multiple mouse controls')
|
if (this.mouseControls.indexOf(data.component) !== -1) {
|
||||||
} else {
|
console.warn('Mouse controls already registered');
|
||||||
this.mouseControls.push(data.component);
|
return;
|
||||||
this.registerMouseControls();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.mouseControls.push(data.component);
|
||||||
|
this.registerMouseControls(data.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a particle engine from this system
|
* Removes controls from this system
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
GameLib.System.Input.prototype.removeComponent = function(data) {
|
GameLib.System.Input.prototype.removeComponent = function(data) {
|
||||||
|
|
||||||
|
var index;
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Controls.D3.Editor) {
|
if (data.component instanceof GameLib.Controls.D3.Editor) {
|
||||||
|
|
||||||
var index = this.editorControls.indexOf(data.component);
|
index = this.editorControls.indexOf(data.component);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index === -1) {
|
||||||
|
console.warn('Failed to find the editor controls in the system - probably it was ignored - ' + data.component.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('removing editor controls from system');
|
console.log('removing editor controls from system');
|
||||||
|
|
||||||
this.deRegisterEditorControls();
|
this.deRegisterEditorControls(data.component);
|
||||||
|
|
||||||
this.editorControls.splice(index, 1);
|
this.editorControls.splice(index, 1);
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log('failed to find the editor controls in the system - probably it was ignored - ' + data.component.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.Controls.Touch) {
|
||||||
|
|
||||||
|
index = this.touchControls.indexOf(data.component);
|
||||||
|
|
||||||
|
if (index === -1) {
|
||||||
|
console.warn('Failed to find the touch controls in the system - probably it was ignored - ' + data.component.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('removing touch controls from system');
|
||||||
|
|
||||||
|
this.deRegisterTouchControls(data.component);
|
||||||
|
|
||||||
|
this.touchControls.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.Controls.Keyboard) {
|
||||||
|
|
||||||
|
index = this.keyboardControls.indexOf(data.component);
|
||||||
|
|
||||||
|
if (index === -1) {
|
||||||
|
console.warn('Failed to find the keyboard controls in the system - probably it was ignored - ' + data.component.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('removing keyboard controls from system');
|
||||||
|
|
||||||
|
this.deRegisterKeyboardControls(data.component);
|
||||||
|
|
||||||
|
this.keyboardControls.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.Controls.Mouse) {
|
||||||
|
|
||||||
|
index = this.mouseControls.indexOf(data.component);
|
||||||
|
|
||||||
|
if (index === -1) {
|
||||||
|
console.warn('Failed to find the mouse controls in the system - probably it was ignored - ' + data.component.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('removing mouse controls from system');
|
||||||
|
|
||||||
|
this.deRegisterMouseControls(data.component);
|
||||||
|
|
||||||
|
this.mouseControls.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -220,38 +298,19 @@ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) {
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Controls.D3.Editor) {
|
if (data.component instanceof GameLib.Controls.D3.Editor) {
|
||||||
|
|
||||||
if (this.editorControls.length === 0) {
|
if (this.editorControls.indexOf(data.component) !== -1) {
|
||||||
/**
|
console.warn('Editor controls already registered');
|
||||||
* We need to register these controls so instance creation can continue
|
return;
|
||||||
*/
|
}
|
||||||
|
|
||||||
this.editorControls.push(data.component);
|
this.editorControls.push(data.component);
|
||||||
this.registerEditorControls();
|
|
||||||
} else {
|
this.registerEditorControls(data.component);
|
||||||
/**
|
|
||||||
* There are already another editor controls, these ones will never get created, we need to
|
|
||||||
* notify our linking system of this problem so loading can continue
|
|
||||||
*/
|
|
||||||
data.component.createInstance();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.registerTouchControls = function() {
|
GameLib.System.Input.prototype.registerTouchControls = function(touchControl) {
|
||||||
|
|
||||||
if (this.touchControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var touchControl = this.touchControls[0];
|
|
||||||
|
|
||||||
this.touchSensitivity = touchControl.sensitivity;
|
|
||||||
|
|
||||||
this.touchStart = this.onTouchStart.bind(this);
|
|
||||||
this.touchMove = this.onTouchMove.bind(this);
|
|
||||||
this.touchEnd = this.onTouchEnd.bind(this);
|
|
||||||
this.touchCancel = this.onTouchCancel.bind(this);
|
|
||||||
|
|
||||||
touchControl.domElement.instance.addEventListener(
|
touchControl.domElement.instance.addEventListener(
|
||||||
'touchstart',
|
'touchstart',
|
||||||
|
@ -276,16 +335,7 @@ GameLib.System.Input.prototype.registerTouchControls = function() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.registerKeyboardControls = function() {
|
GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardControl) {
|
||||||
|
|
||||||
if (this.keyboardControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var keyboardControl = this.keyboardControls[0];
|
|
||||||
|
|
||||||
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
|
|
||||||
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
|
|
||||||
|
|
||||||
keyboardControl.domElement.instance.addEventListener(
|
keyboardControl.domElement.instance.addEventListener(
|
||||||
'keyup',
|
'keyup',
|
||||||
|
@ -300,18 +350,7 @@ GameLib.System.Input.prototype.registerKeyboardControls = function() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.registerMouseControls = function() {
|
GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) {
|
||||||
|
|
||||||
if (this.mouseControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var mouseControl = this.mouseControls[0];
|
|
||||||
|
|
||||||
this.mouseDown = this.onMouseDown.bind(this);
|
|
||||||
this.mouseMove = this.onMouseMove.bind(this);
|
|
||||||
this.mouseWheel = this.onMouseWheel.bind(this);
|
|
||||||
this.mouseUp = this.onMouseUp.bind(this);
|
|
||||||
|
|
||||||
mouseControl.domElement.instance.addEventListener(
|
mouseControl.domElement.instance.addEventListener(
|
||||||
'mousedown',
|
'mousedown',
|
||||||
|
@ -337,19 +376,29 @@ GameLib.System.Input.prototype.registerMouseControls = function() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.registerEditorControls = function() {
|
GameLib.System.Input.prototype.registerEditorControls = function(editorControl) {
|
||||||
|
|
||||||
if (this.editorControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var editorControl = this.editorControls[0];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we already have mouse controls, we don't want to add another event listener onto the DOM
|
* If we already have mouse controls, we don't want to add another event listener onto the DOM
|
||||||
*/
|
*/
|
||||||
this.mouseDownEdit = this.onMouseDownEdit.bind(this);
|
this.mouseControls.map(
|
||||||
this.mouseMoveEdit = this.onMouseMoveEdit.bind(this);
|
function(mouseControl) {
|
||||||
|
if (mouseControl.domElement.instance === editorControl.domElement.instance) {
|
||||||
|
this.deRegisterMouseControls(mouseControl);
|
||||||
|
}
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
|
||||||
|
*/
|
||||||
|
this.keyboardControls.map(
|
||||||
|
function(keyboardControl) {
|
||||||
|
if (keyboardControl.domElement.instance === editorControl.domElement.instance) {
|
||||||
|
this.deRegisterKeyboardControls(keyboardControl);
|
||||||
|
}
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
editorControl.domElement.instance.addEventListener(
|
editorControl.domElement.instance.addEventListener(
|
||||||
'mousedown',
|
'mousedown',
|
||||||
|
@ -363,18 +412,6 @@ GameLib.System.Input.prototype.registerEditorControls = function() {
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
|
|
||||||
*/
|
|
||||||
if (this.keyboardControls.length > 0) {
|
|
||||||
/**
|
|
||||||
* Do Nothing
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this.keyDown = this.onKeyDown.bind(this);
|
|
||||||
this.keyUp = this.onKeyUp.bind(this);
|
|
||||||
|
|
||||||
editorControl.domElement.instance.addEventListener(
|
editorControl.domElement.instance.addEventListener(
|
||||||
'keydown',
|
'keydown',
|
||||||
this.keyDown,
|
this.keyDown,
|
||||||
|
@ -387,13 +424,11 @@ GameLib.System.Input.prototype.registerEditorControls = function() {
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* The order of creation is important here - it changes the way the DOM reacts to events
|
||||||
|
*/
|
||||||
editorControl.createInstance();
|
editorControl.createInstance();
|
||||||
|
|
||||||
this.mouseWheelEdit = this.onMouseWheelEdit.bind(this);
|
|
||||||
this.mouseUpEdit = this.onMouseUpEdit.bind(this);
|
|
||||||
|
|
||||||
editorControl.domElement.instance.addEventListener(
|
editorControl.domElement.instance.addEventListener(
|
||||||
'wheel',
|
'wheel',
|
||||||
this.mouseWheelEdit,
|
this.mouseWheelEdit,
|
||||||
|
@ -405,17 +440,9 @@ GameLib.System.Input.prototype.registerEditorControls = function() {
|
||||||
this.mouseUpEdit,
|
this.mouseUpEdit,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.deRegisterEditorControls = function() {
|
GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl) {
|
||||||
|
|
||||||
if (this.editorControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var editorControl = this.editorControls[0];
|
|
||||||
|
|
||||||
editorControl.domElement.instance.removeEventListener(
|
editorControl.domElement.instance.removeEventListener(
|
||||||
'mousedown',
|
'mousedown',
|
||||||
|
@ -429,7 +456,6 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function() {
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.keyboardControls.length < 1) {
|
|
||||||
editorControl.domElement.instance.removeEventListener(
|
editorControl.domElement.instance.removeEventListener(
|
||||||
'keydown',
|
'keydown',
|
||||||
this.keyDown,
|
this.keyDown,
|
||||||
|
@ -441,7 +467,6 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function() {
|
||||||
this.keyUp,
|
this.keyUp,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
editorControl.instance.dispose();
|
editorControl.instance.dispose();
|
||||||
|
|
||||||
|
@ -459,13 +484,7 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.deRegisterTouchControls = function() {
|
GameLib.System.Input.prototype.deRegisterTouchControls = function(touchControl) {
|
||||||
|
|
||||||
if (this.touchControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var touchControl = this.touchControls[0];
|
|
||||||
|
|
||||||
touchControl.domElement.instance.removeEventListener(
|
touchControl.domElement.instance.removeEventListener(
|
||||||
'touchstart',
|
'touchstart',
|
||||||
|
@ -493,13 +512,7 @@ GameLib.System.Input.prototype.deRegisterTouchControls = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.deRegisterKeyboardControls = function() {
|
GameLib.System.Input.prototype.deRegisterKeyboardControls = function(keyboardControl) {
|
||||||
|
|
||||||
if (this.keyboardControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var keyboardControl = this.keyboardControls[0];
|
|
||||||
|
|
||||||
keyboardControl.domElement.instance.removeEventListener(
|
keyboardControl.domElement.instance.removeEventListener(
|
||||||
'keydown',
|
'keydown',
|
||||||
|
@ -516,13 +529,7 @@ GameLib.System.Input.prototype.deRegisterKeyboardControls = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GameLib.System.Input.prototype.deRegisterMouseControls = function() {
|
GameLib.System.Input.prototype.deRegisterMouseControls = function(mouseControl) {
|
||||||
|
|
||||||
if (this.mouseControls.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var mouseControl = this.mouseControls[0];
|
|
||||||
|
|
||||||
mouseControl.domElement.instance.removeEventListener(
|
mouseControl.domElement.instance.removeEventListener(
|
||||||
'mousedown',
|
'mousedown',
|
||||||
|
@ -698,16 +705,16 @@ GameLib.System.Input.prototype.onTouchMove = function (event) {
|
||||||
zoom : zoom
|
zoom : zoom
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.sensitivityCounter >= this.touchSensitivity) {
|
// if (this.sensitivityCounter >= this.touchSensitivity) {
|
||||||
|
//
|
||||||
this.sensitivityCounter = 0;
|
// this.sensitivityCounter = 0;
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.TOUCH_MOVE,
|
GameLib.Event.TOUCH_MOVE,
|
||||||
this.touches
|
this.touches
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -829,7 +836,6 @@ GameLib.System.Input.prototype.onKeyUp = function(event) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onMouseDown = function(event) {
|
GameLib.System.Input.prototype.onMouseDown = function(event) {
|
||||||
// console.log('mouse down');
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.MOUSE_DOWN,
|
GameLib.Event.MOUSE_DOWN,
|
||||||
|
@ -840,7 +846,7 @@ GameLib.System.Input.prototype.onMouseDown = function(event) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onMouseMove = function(event) {
|
GameLib.System.Input.prototype.onMouseMove = function(event) {
|
||||||
// console.log('mouse move');
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.MOUSE_MOVE,
|
GameLib.Event.MOUSE_MOVE,
|
||||||
{
|
{
|
||||||
|
@ -850,7 +856,7 @@ GameLib.System.Input.prototype.onMouseMove = function(event) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onMouseWheel = function(event) {
|
GameLib.System.Input.prototype.onMouseWheel = function(event) {
|
||||||
// console.log('mouse wheel');
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.MOUSE_WHEEL,
|
GameLib.Event.MOUSE_WHEEL,
|
||||||
{
|
{
|
||||||
|
@ -860,7 +866,7 @@ GameLib.System.Input.prototype.onMouseWheel = function(event) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onMouseUp = function(event) {
|
GameLib.System.Input.prototype.onMouseUp = function(event) {
|
||||||
// console.log('mouse up');
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.MOUSE_UP,
|
GameLib.Event.MOUSE_UP,
|
||||||
{
|
{
|
||||||
|
|
|
@ -115,15 +115,10 @@ GameLib.System.Render.prototype.windowResize = function(data) {
|
||||||
renderers.map(
|
renderers.map(
|
||||||
function(renderer) {
|
function(renderer) {
|
||||||
|
|
||||||
if (renderer.fullscreen) {
|
renderer.windowSize.x = data.width;
|
||||||
renderer.width = data.width;
|
renderer.windowSize.y = data.height;
|
||||||
renderer.height = data.height;
|
|
||||||
/**
|
|
||||||
* widthheight simply saves a function call
|
|
||||||
*/
|
|
||||||
renderer.updateInstance('widthheight');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
renderer.updateInstance('windowSize');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -222,18 +217,30 @@ GameLib.System.Render.prototype.render = function(data) {
|
||||||
|
|
||||||
renderer.instance.clear();
|
renderer.instance.clear();
|
||||||
|
|
||||||
|
if (
|
||||||
|
renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET ||
|
||||||
|
renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET
|
||||||
|
) {
|
||||||
|
if (!renderer.target) {
|
||||||
|
console.warn('no render target');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderer.viewports.map(
|
renderer.viewports.map(
|
||||||
|
|
||||||
function(viewport) {
|
function(viewport) {
|
||||||
|
|
||||||
var trueWidth = viewport.width * renderer.width;
|
var trueOffsetX = viewport.x * renderer.width * renderer.windowSize.x;
|
||||||
var trueHeight = viewport.height * renderer.height;
|
var trueOffsetY = viewport.y * renderer.height * renderer.windowSize.y;
|
||||||
|
var trueWidth = viewport.width * renderer.width * renderer.windowSize.x;
|
||||||
|
var trueHeight = viewport.height * renderer.height * renderer.windowSize.y;
|
||||||
|
|
||||||
renderer.instance.setViewport(
|
renderer.instance.setViewport(
|
||||||
viewport.x * renderer.width,
|
trueOffsetX,
|
||||||
viewport.y * renderer.height,
|
trueOffsetY,
|
||||||
viewport.width * renderer.width,
|
trueWidth,
|
||||||
viewport.height * renderer.height
|
trueHeight
|
||||||
);
|
);
|
||||||
|
|
||||||
var aspect = trueWidth / trueHeight;
|
var aspect = trueWidth / trueHeight;
|
||||||
|
@ -259,6 +266,7 @@ GameLib.System.Render.prototype.render = function(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET) {
|
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET) {
|
||||||
|
|
||||||
renderer.instance.render(
|
renderer.instance.render(
|
||||||
scene.instance,
|
scene.instance,
|
||||||
camera.instance,
|
camera.instance,
|
||||||
|
|
|
@ -203,7 +203,8 @@ GameLib.System.Storage.prototype.delete = function(data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.send(JSON.stringify({
|
xhr.send(JSON.stringify({
|
||||||
session : this.token
|
session : this.token,
|
||||||
|
includeDependencies : data.includeDependencies
|
||||||
}));
|
}));
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -537,6 +538,9 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
|
||||||
components : __system.loaded
|
components : __system.loaded
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__system.otherDependencies = [];
|
||||||
|
__system.loaded = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue