fixed render problem for now

beta.r3js.org
-=yb4f310 2018-01-09 10:56:41 +01:00
parent 5fa8e6583d
commit 1aa01c95a3
18 changed files with 512 additions and 336 deletions

View File

@ -107,8 +107,8 @@ GameLib.Component.prototype.performInstanceCreation = function() {
}
} else {
/**
* Some systems require a restart in order to create the delayed components (like System.Input for
* Edit Controls) - we need to give them the opportunity to restart
* Some systems require an instance creation at an exact time, like System.Input for Edit Controls -
* we need to give them the opportunity to handle this situation
*/
GameLib.Event.Emit(
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,
@ -997,31 +997,25 @@ 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() {
this.buildIdToObject();
var dependencies = this.getDependencies();
dependencies.map(
function(objectId) {
var childComponent = this.idToObject[objectId];
if (childComponent instanceof GameLib.Component) {
childComponent.remove();
}
Object.keys(this.idToObject).map(
function(componentId){
GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT,
{
component : this.idToObject[componentId]
}
)
}.bind(this)
);
GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT,
{
component : this
}
)
};
GameLib.Component.prototype.clone = function() {

View File

@ -9,10 +9,9 @@
*/
GameLib.API.Controls = function(
id,
controlsType,
name,
controlsType,
domElement,
// fullscreen,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
@ -23,19 +22,19 @@ GameLib.API.Controls = function(
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
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) {
controlsType = GameLib.Controls.CONTROLS_TYPE_TOUCH;
controlsType = GameLib.API.Controls.CONTROLS_TYPE_TOUCH;
}
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) {
controlsType = GameLib.Controls.CONTROLS_TYPE_MOUSE;
controlsType = GameLib.API.Controls.CONTROLS_TYPE_MOUSE;
}
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
@ -46,19 +45,19 @@ GameLib.API.Controls = function(
if (GameLib.Utils.UndefinedOrNull(name)) {
if (controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) {
name = 'Editing Controls';
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_EDITOR) {
name = 'Editing Controls';
}
if (controlsType === GameLib.Controls.CONTROLS_TYPE_TOUCH) {
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_TOUCH) {
name = 'Touch Controls';
}
if (controlsType === GameLib.Controls.CONTROLS_TYPE_KEYBOARD) {
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD) {
name = 'Keyboard Controls';
}
if (controlsType === GameLib.Controls.CONTROLS_TYPE_MOUSE) {
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_MOUSE) {
name = 'Mouse Controls';
}
@ -73,19 +72,19 @@ GameLib.API.Controls = function(
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;
}
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_TOUCH) {
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_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
}
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_MOUSE) {
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_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.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
* @param objectControls

View File

@ -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
);
};

View File

@ -14,12 +14,20 @@ GameLib.API.Socket.Cast = function(
) {
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
apiSocket = {};
apiSocket = {
socketType : GameLib.API.Socket.SOCKET_CAST
};
}
GameLib.API.Socket.call(
this,
apiSocket
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
if (GameLib.Utils.UndefinedOrNull(castType)) {

View File

@ -14,12 +14,20 @@ GameLib.API.Socket.Receive = function(
) {
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
apiSocket = {};
apiSocket = {
socketType : GameLib.API.Socket.SOCKET_RECEIVE
};
}
GameLib.API.Socket.call(
this,
apiSocket
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
if (GameLib.Utils.UndefinedOrNull(receiveType)) {

View File

@ -29,6 +29,12 @@ GameLib.API.Vector2.prototype.equals = function (v) {
* @constructor
*/
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(
objectVector.x,
objectVector.y

View File

@ -263,6 +263,12 @@ GameLib.API.Vector3.prototype.angleTo = function (v) {
* @constructor
*/
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(
objectVector.x,
objectVector.y,

View File

@ -31,6 +31,12 @@ GameLib.API.Vector4.prototype.equals = function (v) {
* @constructor
*/
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(
objectVector.x,
objectVector.y,

View File

@ -14,8 +14,8 @@ GameLib.Controls = function (
GameLib.API.Controls.call(
this,
apiControls.id,
apiControls.controlsType,
apiControls.name,
apiControls.controlsType,
apiControls.domElement,
apiControls.parentEntity
);
@ -26,7 +26,7 @@ GameLib.Controls = function (
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.camera = GameLib.D3.Camera;
@ -46,15 +46,6 @@ GameLib.Controls.prototype.constructor = GameLib.Controls;
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
*/
@ -77,9 +68,9 @@ GameLib.Controls.prototype.toApiObject = function() {
var apiControls = new GameLib.API.Controls(
this.id,
this.controlsType,
this.name,
GameLib.Utils.IdOrNull(this.domElement),
this.controlsType,
GameLib.Utils.IdOrNull(this.domElement),
GameLib.Utils.IdOrNull(this.parentEntity)
);

View File

@ -1,49 +1,49 @@
/**
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
* @param graphics GameLib.GraphicsRuntime
* @param apiControls GameLib.API.Controls
* @param raycaster
* @param camera
* @param apiEditorControls
* @constructor
*/
GameLib.Controls.D3.Editor = function (
graphics,
apiControls,
raycaster,
camera
apiEditorControls
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
raycaster = null;
}
this.raycaster = raycaster;
if (GameLib.Utils.UndefinedOrNull(apiEditorControls)) {
apiEditorControls = {
controlsType : GameLib.API.Controls.CONTROLS_TYPE_EDITOR
};
}
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
this.raycaster = new GameLib.D3.Raycaster(
this.graphics,
this.raycaster
);
}
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
GameLib.Controls.call(
GameLib.API.Controls.D3.Editor.call(
this,
apiControls
apiEditorControls,
apiEditorControls.raycaster,
apiEditorControls.camera
);
if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
this.raycaster = new GameLib.D3.Raycaster(
this.graphics,
this.raycaster
);
}
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
GameLib.Controls.call(
this,
apiEditorControls
);
};
/**
@ -110,11 +110,11 @@ GameLib.Controls.D3.Editor.FromObject = function(graphics, objectControls) {
var apiControls = GameLib.API.Controls.FromObject(objectControls);
var apiEditorControls = GameLib.API.Controls.D3.Editor.FromObject(objectControls);
return new GameLib.Controls.D3.Editor(
graphics,
apiControls,
objectControls.raycaster,
objectControls.camera
apiEditorControls
);
};

View File

@ -32,6 +32,7 @@
* @param depth
* @param logarithmicDepthBuffer
* @param fullscreen
* @param offset
* @param canvas
* @param renderTarget
* @param localClippingEnabled
@ -78,6 +79,8 @@ GameLib.D3.API.Renderer = function (
logarithmicDepthBuffer,
localClippingEnabled,
fullscreen,
windowSize,
offset,
canvas,
renderTarget,
clippingPlanes,
@ -99,12 +102,12 @@ GameLib.D3.API.Renderer = function (
this.name = name;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
width = 1;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 512;
height = 1;
}
this.height = height;
@ -253,12 +256,25 @@ GameLib.D3.API.Renderer = function (
}
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)) {
canvas = new GameLib.API.Canvas(
null,
null,
this.width,
this.height
this.windowSize.x,
this.windowSize.y
);
}
this.canvas = canvas;
@ -376,6 +392,8 @@ GameLib.D3.API.Renderer.FromObject = function(objectRenderer) {
objectRenderer.logarithmicDepthBuffer,
objectRenderer.localClippingEnabled,
objectRenderer.fullscreen,
GameLib.API.Vector2.FromObject(objectRenderer.windowSize),
GameLib.API.Vector2.FromObject(objectRenderer.offset),
objectRenderer.canvas,
objectRenderer.renderTarget,
objectRenderer.clippingPlanes,

View File

@ -129,7 +129,7 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
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.height,
this.widthSegments,

View File

@ -51,6 +51,8 @@ GameLib.D3.Renderer = function (
apiRenderer.logarithmicDepthBuffer,
apiRenderer.localClippingEnabled,
apiRenderer.fullscreen,
apiRenderer.windowSize,
apiRenderer.offset,
apiRenderer.canvas,
apiRenderer.renderTarget,
apiRenderer.clippingPlanes,
@ -61,7 +63,19 @@ GameLib.D3.Renderer = function (
apiRenderer.viewports,
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) {
this.canvas = new GameLib.Canvas(
this.canvas
@ -174,10 +188,13 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
);
this.instance.setSize(
this.width,
this.height
this.width * this.windowSize.x,
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.autoClearColor = this.autoClearColor;
this.instance.autoClearDepth = this.autoClearDepth;
@ -246,40 +263,41 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
throw new Error('no renderer instance');
}
var trueWidth;
var trueHeight;
if (property === 'width') {
this.width = Math.round(this.width);
this.canvas.width = this.width;
trueWidth = this.width * this.windowSize.x;
this.canvas.width = trueWidth;
this.canvas.updateInstance('width');
this.instance.setSize(this.width, this.height);
this.instance.setSize(trueWidth, this.height * this.windowSize.y);
}
if (property === 'height') {
this.height = Math.round(this.height);
this.canvas.height = this.height;
trueHeight = this.height * this.windowSize.y;
this.canvas.height = trueHeight;
this.canvas.updateInstance('height');
this.instance.setSize(this.width, this.height);
this.instance.setSize(this.width * this.windowSize.x, trueHeight);
}
if (property === 'widthheight') {
this.width = Math.round(this.width);
this.height = Math.round(this.height);
trueWidth = this.width * this.windowSize.x;
trueHeight = this.height * this.windowSize.y;
this.canvas.width = this.width;
this.canvas.height = this.height;
this.canvas.width = trueWidth;
this.canvas.height = trueHeight;
this.canvas.updateInstance('width');
this.canvas.updateInstance('height');
this.instance.setSize(this.width, this.height);
this.instance.setSize(trueWidth, trueHeight);
}
if (property === 'renderMode') {
@ -398,6 +416,31 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
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') {
console.warn('experimental canvas change for renderer');
this.instance.dispose();
@ -483,6 +526,9 @@ GameLib.D3.Renderer.prototype.toApiObject = function() {
this.depth,
this.logarithmicDepthBuffer,
this.localClippingEnabled,
this.fullscreen,
this.windowSize.toApiObject(),
this.offset.toApiObject(),
GameLib.Utils.IdOrNull(this.canvas),
GameLib.Utils.IdOrNull(this.renderTarget),
this.clippingPlanes.map(

View File

@ -464,9 +464,9 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
}
}
if (this.parentEntity) {
this.parentEntity.addComponent(object);
}
// if (this.parentEntity) {
// this.parentEntity.addComponent(object);
// }
};
@ -531,10 +531,10 @@ GameLib.D3.Scene.prototype.removeObject = function(object) {
if (object.parentScene === this) {
object.parentScene = null;
}
if (this.parentEntity) {
this.parentEntity.removeComponent(object);
}
//
// if (this.parentEntity) {
// this.parentEntity.removeComponent(object);
// }
// this.buildIdToObject();
};

View File

@ -1403,8 +1403,11 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
) {
controllers.push(folder.add(object, property, 1, 1000, 1));
} else if (
property === 'width' ||
property === 'height' ||
property === 'width' ||
property === 'height'
) {
controllers.push(folder.add(object, property, 0, 1, 0.001));
} else if (
property === 'depth' ||
property === 'radius'
) {

View File

@ -26,37 +26,38 @@ GameLib.System.Input = function(
* Touch Controls
* @type {null}
*/
this.touchStart = null;
this.touchMove = null;
this.touchEnd = null;
this.touchCancel = null;
this.touchStart = this.onTouchStart.bind(this);
this.touchMove = this.onTouchMove.bind(this);
this.touchEnd = this.onTouchEnd.bind(this);
this.touchCancel = this.onTouchCancel.bind(this);
/**
* Keyboard Controls
* @type {null}
*/
this.keyboardKeyUp = null;
this.keyboardKeyDown = null;
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
/**
* Mouse Controls
* @type {null}
*/
this.mouseDown = null;
this.mouseMove = null;
this.mouseWheel = null;
this.mouseUp = null;
this.mouseDown = this.onMouseDown.bind(this);
this.mouseMove = this.onMouseMove.bind(this);
this.mouseWheel = this.onMouseWheel.bind(this);
this.mouseUp = this.onMouseUp.bind(this);
/**
* Editor Controls
* @type {null}
*/
this.keyDown = null;
this.keyUp = null;
this.mouseDownEdit = null;
this.mouseMoveEdit = null;
this.mouseWheelEdit = null;
this.mouseUpEdit = null;
this.keyDown = this.onKeyDown.bind(this);
this.keyUp = this.onKeyUp.bind(this);
this.mouseDownEdit = this.onMouseDownEdit.bind(this);
this.mouseMoveEdit = this.onMouseMoveEdit.bind(this);
this.mouseWheelEdit = this.onMouseWheelEdit.bind(this);
this.mouseUpEdit = this.onMouseUpEdit.bind(this);
this.delayedInstanceEncounteredSubscription = null;
this.instanceCreatedSubscription = null;
@ -75,14 +76,6 @@ GameLib.System.Input.prototype.start = function() {
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(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
@ -98,17 +91,41 @@ GameLib.System.Input.prototype.start = function() {
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
*/
this.registerTouchControls();
this.touchControls.map(
function(touchControl){
this.registerTouchControls(touchControl);
}.bind(this)
);
this.registerKeyboardControls();
this.registerMouseControls();
this.keyboardControls.map(
function(keyboardControl){
this.registerKeyboardControls(keyboardControl);
}.bind(this)
);
this.mouseControls.map(
function(mouseControl){
this.registerMouseControls(mouseControl);
}.bind(this)
);
this.editorControls.map(
function(editorControl){
this.registerEditorControls(editorControl);
}.bind(this)
);
this.registerEditorControls();
};
/**
@ -124,13 +141,29 @@ GameLib.System.Input.prototype.stop = function() {
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 = [];
@ -148,66 +181,111 @@ GameLib.System.Input.prototype.stop = function() {
*/
GameLib.System.Input.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.Controls.D3.Editor) {
if (this.editorControls.length > 0) {
console.log('Ignoring multiple editor controls')
} else {
this.editorControls.push(data.component);
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.registerTouchControls();
if (this.touchControls.indexOf(data.component) !== -1) {
console.warn('Touch controls already registered');
return;
}
this.touchControls.push(data.component);
this.registerTouchControls(data.component);
}
if (data.component instanceof GameLib.Controls.Keyboard) {
if (this.keyboardControls.length > 0 || this.editorControls.length > 0) {
console.log('Ignoring multiple keyboard controls')
} else {
this.keyboardControls.push(data.component);
this.registerKeyboardControls();
if (this.keyboardControls.indexOf(data.component) !== -1) {
console.warn('Keyboard controls already registered');
return;
}
this.keyboardControls.push(data.component);
this.registerKeyboardControls(data.component);
}
if (data.component instanceof GameLib.Controls.Mouse) {
if (this.mouseControls.length > 0) {
console.log('Ignoring multiple mouse controls')
} else {
this.mouseControls.push(data.component);
this.registerMouseControls();
if (this.mouseControls.indexOf(data.component) !== -1) {
console.warn('Mouse controls already registered');
return;
}
this.mouseControls.push(data.component);
this.registerMouseControls(data.component);
}
};
/**
* Removes a particle engine from this system
* Removes controls from this system
* @param data
*/
GameLib.System.Input.prototype.removeComponent = function(data) {
var index;
if (data.component instanceof GameLib.Controls.D3.Editor) {
var index = this.editorControls.indexOf(data.component);
index = this.editorControls.indexOf(data.component);
if (index !== -1) {
console.log('removing editor controls from system');
this.deRegisterEditorControls();
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 (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');
this.deRegisterEditorControls(data.component);
this.editorControls.splice(index, 1);
}
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 (this.editorControls.length === 0) {
/**
* We need to register these controls so instance creation can continue
*/
this.editorControls.push(data.component);
this.registerEditorControls();
} else {
/**
* 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();
if (this.editorControls.indexOf(data.component) !== -1) {
console.warn('Editor controls already registered');
return;
}
this.editorControls.push(data.component);
this.registerEditorControls(data.component);
}
};
GameLib.System.Input.prototype.registerTouchControls = function() {
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);
GameLib.System.Input.prototype.registerTouchControls = function(touchControl) {
touchControl.domElement.instance.addEventListener(
'touchstart',
@ -276,16 +335,7 @@ GameLib.System.Input.prototype.registerTouchControls = function() {
);
};
GameLib.System.Input.prototype.registerKeyboardControls = function() {
if (this.keyboardControls.length !== 1) {
return;
}
var keyboardControl = this.keyboardControls[0];
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardControl) {
keyboardControl.domElement.instance.addEventListener(
'keyup',
@ -300,19 +350,8 @@ 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(
'mousedown',
this.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
*/
this.mouseDownEdit = this.onMouseDownEdit.bind(this);
this.mouseMoveEdit = this.onMouseMoveEdit.bind(this);
this.mouseControls.map(
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(
'mousedown',
@ -363,37 +412,23 @@ GameLib.System.Input.prototype.registerEditorControls = function() {
false
);
editorControl.domElement.instance.addEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.addEventListener(
'keyup',
this.keyUp,
false
);
/**
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
* The order of creation is important here - it changes the way the DOM reacts to events
*/
if (this.keyboardControls.length > 0) {
/**
* Do Nothing
*/
} else {
this.keyDown = this.onKeyDown.bind(this);
this.keyUp = this.onKeyUp.bind(this);
editorControl.domElement.instance.addEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.addEventListener(
'keyup',
this.keyUp,
false
);
}
editorControl.createInstance();
this.mouseWheelEdit = this.onMouseWheelEdit.bind(this);
this.mouseUpEdit = this.onMouseUpEdit.bind(this);
editorControl.domElement.instance.addEventListener(
'wheel',
this.mouseWheelEdit,
@ -405,17 +440,9 @@ GameLib.System.Input.prototype.registerEditorControls = function() {
this.mouseUpEdit,
false
);
};
GameLib.System.Input.prototype.deRegisterEditorControls = function() {
if (this.editorControls.length !== 1) {
return;
}
var editorControl = this.editorControls[0];
GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl) {
editorControl.domElement.instance.removeEventListener(
'mousedown',
@ -429,19 +456,17 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function() {
false
);
if (this.keyboardControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.removeEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.removeEventListener(
'keyup',
this.keyUp,
false
);
}
editorControl.domElement.instance.removeEventListener(
'keyup',
this.keyUp,
false
);
editorControl.instance.dispose();
@ -459,13 +484,7 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function() {
};
GameLib.System.Input.prototype.deRegisterTouchControls = function() {
if (this.touchControls.length !== 1) {
return;
}
var touchControl = this.touchControls[0];
GameLib.System.Input.prototype.deRegisterTouchControls = function(touchControl) {
touchControl.domElement.instance.removeEventListener(
'touchstart',
@ -493,13 +512,7 @@ GameLib.System.Input.prototype.deRegisterTouchControls = function() {
};
GameLib.System.Input.prototype.deRegisterKeyboardControls = function() {
if (this.keyboardControls.length !== 1) {
return;
}
var keyboardControl = this.keyboardControls[0];
GameLib.System.Input.prototype.deRegisterKeyboardControls = function(keyboardControl) {
keyboardControl.domElement.instance.removeEventListener(
'keydown',
@ -516,13 +529,7 @@ GameLib.System.Input.prototype.deRegisterKeyboardControls = function() {
};
GameLib.System.Input.prototype.deRegisterMouseControls = function() {
if (this.mouseControls.length !== 1) {
return;
}
var mouseControl = this.mouseControls[0];
GameLib.System.Input.prototype.deRegisterMouseControls = function(mouseControl) {
mouseControl.domElement.instance.removeEventListener(
'mousedown',
@ -698,16 +705,16 @@ GameLib.System.Input.prototype.onTouchMove = function (event) {
zoom : zoom
};
if (this.sensitivityCounter >= this.touchSensitivity) {
this.sensitivityCounter = 0;
// if (this.sensitivityCounter >= this.touchSensitivity) {
//
// this.sensitivityCounter = 0;
GameLib.Event.Emit(
GameLib.Event.TOUCH_MOVE,
this.touches
);
}
// }
};
@ -829,7 +836,6 @@ GameLib.System.Input.prototype.onKeyUp = function(event) {
};
GameLib.System.Input.prototype.onMouseDown = function(event) {
// console.log('mouse down');
GameLib.Event.Emit(
GameLib.Event.MOUSE_DOWN,
@ -840,7 +846,7 @@ GameLib.System.Input.prototype.onMouseDown = function(event) {
};
GameLib.System.Input.prototype.onMouseMove = function(event) {
// console.log('mouse move');
GameLib.Event.Emit(
GameLib.Event.MOUSE_MOVE,
{
@ -850,7 +856,7 @@ GameLib.System.Input.prototype.onMouseMove = function(event) {
};
GameLib.System.Input.prototype.onMouseWheel = function(event) {
// console.log('mouse wheel');
GameLib.Event.Emit(
GameLib.Event.MOUSE_WHEEL,
{
@ -860,7 +866,7 @@ GameLib.System.Input.prototype.onMouseWheel = function(event) {
};
GameLib.System.Input.prototype.onMouseUp = function(event) {
// console.log('mouse up');
GameLib.Event.Emit(
GameLib.Event.MOUSE_UP,
{

View File

@ -115,15 +115,10 @@ GameLib.System.Render.prototype.windowResize = function(data) {
renderers.map(
function(renderer) {
if (renderer.fullscreen) {
renderer.width = data.width;
renderer.height = data.height;
/**
* widthheight simply saves a function call
*/
renderer.updateInstance('widthheight');
}
renderer.windowSize.x = data.width;
renderer.windowSize.y = data.height;
renderer.updateInstance('windowSize');
}
);
@ -222,18 +217,30 @@ GameLib.System.Render.prototype.render = function(data) {
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(
function(viewport) {
var trueWidth = viewport.width * renderer.width;
var trueHeight = viewport.height * renderer.height;
var trueOffsetX = viewport.x * renderer.width * renderer.windowSize.x;
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(
viewport.x * renderer.width,
viewport.y * renderer.height,
viewport.width * renderer.width,
viewport.height * renderer.height
trueOffsetX,
trueOffsetY,
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) {
renderer.instance.render(
scene.instance,
camera.instance,

View File

@ -203,7 +203,8 @@ GameLib.System.Storage.prototype.delete = function(data) {
};
xhr.send(JSON.stringify({
session : this.token
session : this.token,
includeDependencies : data.includeDependencies
}));
}.bind(this));
@ -537,6 +538,9 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
components : __system.loaded
})
}
__system.otherDependencies = [];
__system.loaded = [];
}