resize events to render system

beta.r3js.org
-=yb4f310 2017-12-12 11:13:51 +01:00
parent 5e6fc54181
commit 20163c4f93
4 changed files with 179 additions and 35 deletions

12
build/game-lib-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
// COMPILE TIME DEFINITIONS (Generated via gulp)
var __DATE__ = "Mon Dec 11 2017 13:43:48 GMT+0100 (CET)";
var __DATE__ = "Tue Dec 12 2017 11:13:34 GMT+0100 (CET)";
// END COMPILE TIME DEFINITIONS
/**
@ -25758,7 +25758,8 @@ GameLib.System.Animation.prototype.start = function() {
function(mesh) {
this.attachAnimation(animation, mesh);
}.bind(this)
)
);
this.animations[animation.id] = animation;
}.bind(this));
this.animationMeshAddedSubscription = GameLib.Event.Subscribe(
@ -25817,6 +25818,15 @@ GameLib.System.Animation.prototype.instanceCreated = function(data) {
this.textures[data.component.id] = data.component;
this.textureIds = Object.keys(this.textures);
}
if (data.component instanceof GameLib.D3.Animation) {
this.animations[data.component.id] = data.component;
data.component.meshes.map(
function(mesh){
this.attachAnimation(data.component, mesh)
}.bind(this)
);
}
};
GameLib.System.Animation.prototype.removeComponent = function(data) {
@ -25831,6 +25841,17 @@ GameLib.System.Animation.prototype.removeComponent = function(data) {
this.textureIds = Object.keys(this.textures);
}
}
if (data.component instanceof GameLib.D3.Animation) {
data.component.meshes.map(
function(mesh){
this.detachAnimation(mesh)
}.bind(this)
);
delete this.animations[data.component.id];
}
};
GameLib.System.Animation.prototype.textureAnimatedChange = function(data) {
@ -26827,24 +26848,24 @@ GameLib.System.Animation.prototype.stop = function() {
this.animationMeshRemovedSubscription.remove();
this.animations = {};
Object.keys(this.animations).map(
function(animationId) {
var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH);
meshes.map(
function(mesh) {
for (var property in this.latest) {
if (
this.latest.hasOwnProperty(property) &&
property === mesh.id
) {
this.detachAnimation(mesh);
}
if (
this.animations[animationId] &&
this.animations[animationId].meshes
) {
this.animations[animationId].meshes.map(
function (mesh) {
this.detachAnimation(mesh);
}.bind(this)
)
}
}.bind(this)
);
this.animations = {};
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
@ -32044,6 +32065,59 @@ GameLib.System.Render.prototype.start = function() {
this.render
);
this.windowResizeSubscription = this.subscribe(
GameLib.Event.WINDOW_RESIZE,
this.windowResize
);
window.addEventListener(
'resize',
this.nativeWindowResize,
false
);
};
GameLib.System.Render.prototype.nativeWindowResize = function() {
GameLib.Event.Emit(
GameLib.Event.WINDOW_RESIZE,
{
width : window.innerWidth,
height : window.innerHeight
}
);
};
GameLib.System.Render.prototype.windowResize = function(data) {
var aspect = (data.width / data.height);
var cameras = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAMERA);
cameras.map(function(camera){
camera.aspect = aspect;
camera.updateInstance('aspect');
});
var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
renderers.map(
function(renderer) {
renderer.setSize(
data.width,
data.height
);
}
);
GameLib.Event.Emit(
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE,
{
aspect : aspect,
width : data.width,
height : data.height
}
);
};
/**
@ -32170,6 +32244,14 @@ GameLib.System.Render.prototype.stop = function() {
this.renderSubscription.remove();
window.removeEventListener(
'resize',
this.nativeWindowResize,
false
);
this.windowResizeSubscription.remove();
this.renderers.map(
function(renderer) {
if (renderer.statistics) {

View File

@ -47,7 +47,8 @@ GameLib.System.Animation.prototype.start = function() {
function(mesh) {
this.attachAnimation(animation, mesh);
}.bind(this)
)
);
this.animations[animation.id] = animation;
}.bind(this));
this.animationMeshAddedSubscription = GameLib.Event.Subscribe(
@ -1136,24 +1137,24 @@ GameLib.System.Animation.prototype.stop = function() {
this.animationMeshRemovedSubscription.remove();
this.animations = {};
Object.keys(this.animations).map(
function(animationId) {
var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH);
meshes.map(
function(mesh) {
for (var property in this.latest) {
if (
this.latest.hasOwnProperty(property) &&
property === mesh.id
) {
this.detachAnimation(mesh);
}
if (
this.animations[animationId] &&
this.animations[animationId].meshes
) {
this.animations[animationId].meshes.map(
function (mesh) {
this.detachAnimation(mesh);
}.bind(this)
)
}
}.bind(this)
);
this.animations = {};
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();

View File

@ -45,6 +45,59 @@ GameLib.System.Render.prototype.start = function() {
this.render
);
this.windowResizeSubscription = this.subscribe(
GameLib.Event.WINDOW_RESIZE,
this.windowResize
);
window.addEventListener(
'resize',
this.nativeWindowResize,
false
);
};
GameLib.System.Render.prototype.nativeWindowResize = function() {
GameLib.Event.Emit(
GameLib.Event.WINDOW_RESIZE,
{
width : window.innerWidth,
height : window.innerHeight
}
);
};
GameLib.System.Render.prototype.windowResize = function(data) {
var aspect = (data.width / data.height);
var cameras = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAMERA);
cameras.map(function(camera){
camera.aspect = aspect;
camera.updateInstance('aspect');
});
var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
renderers.map(
function(renderer) {
renderer.setSize(
data.width,
data.height
);
}
);
GameLib.Event.Emit(
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE,
{
aspect : aspect,
width : data.width,
height : data.height
}
);
};
/**
@ -171,6 +224,14 @@ GameLib.System.Render.prototype.stop = function() {
this.renderSubscription.remove();
window.removeEventListener(
'resize',
this.nativeWindowResize,
false
);
this.windowResizeSubscription.remove();
this.renderers.map(
function(renderer) {
if (renderer.statistics) {