render scenes for viewports if defined

beta.r3js.org
Theunis J. Botha 2017-06-06 11:25:02 +02:00
parent a676543121
commit e2faf5be25
6 changed files with 63 additions and 23 deletions

View File

@ -24,11 +24,14 @@ GameLib.API.Entity = function(
}
this.parentEntityManager = parentEntityManager;
this.activeComponent = null;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY,
{
'components' : [GameLib.Component]
'components' : [GameLib.Component],
'activeComponent' : GameLib.Component
},
null,
parentEntity

View File

@ -6,6 +6,7 @@
* @param height
* @param x
* @param y
* @param scenes
* @param parentEntity
* @constructor
*/
@ -16,12 +17,15 @@ GameLib.D3.API.Viewport = function(
height,
x,
y,
scenes,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_VIEWPORT,
null,
{
'scenes' : [GameLib.D3.Scene]
},
null,
parentEntity
);
@ -55,6 +59,11 @@ GameLib.D3.API.Viewport = function(
y = 0;
}
this.y = y;
if (GameLib.Utils.UndefinedOrNull(scenes)) {
scenes = [];
}
this.scenes = scenes;
};
GameLib.D3.API.Viewport.prototype = Object.create(GameLib.Component.prototype);
@ -65,7 +74,7 @@ GameLib.D3.API.Viewport.prototype.constructor = GameLib.D3.API.Viewport;
* @param objectViewport
* @constructor
*/
GameLib.D3.API.Viewport.FromObjectViewport = function(objectViewport) {
GameLib.D3.API.Viewport.FromObjectComponent = function(objectViewport) {
return new GameLib.D3.API.Viewport(
objectViewport.id,
objectViewport.name,
@ -73,6 +82,7 @@ GameLib.D3.API.Viewport.FromObjectViewport = function(objectViewport) {
objectViewport.height,
objectViewport.x,
objectViewport.y,
objectViewport.scenes,
objectViewport.parentEntity
);
};

View File

@ -28,6 +28,7 @@ GameLib.D3.Viewport = function (
apiViewport.height,
apiViewport.x,
apiViewport.y,
apiViewport.scenes,
apiViewport.parentEntity
);
@ -77,6 +78,9 @@ GameLib.D3.Viewport.prototype.toApiObject = function() {
this.height,
this.x,
this.y,
this.scenes.map(function(scene){
return GameLib.Utils.IdOrNull(scene);
}),
GameLib.Utils.IdOrNull(this.parentEntity)
);

View File

@ -170,6 +170,10 @@ GameLib.Entity.prototype.hasComponent = function(constructor) {
*/
GameLib.Entity.prototype.removeComponent = function(component) {
if (GameLib.Utils.UndefinedOrNull(component)) {
component = this.activeComponent;
}
component.parentEntity = null;
var index = this.components.indexOf(component);

View File

@ -770,6 +770,8 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en
entityManager: entityManager
}
);
gui.build(entityManager);
} else {
/**
* Old way of doing things
@ -781,7 +783,7 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en
/**
* Properties changed - rebuild GUI
*/
gui.build(entityManager);
};
}(this)
@ -841,8 +843,15 @@ GameLib.GUI.prototype.buildEntitySelectionControlFromArray = function(
);
folder.add(object, property, options).name(property).listen().onChange(
function(entityManager) {
function(entityManager, gui) {
return function(value) {
if (value !== 'null') {
object[property] = entityManager.findEntityById(value);
} else {
object[property] = null;
}
GameLib.Event.Emit(
GameLib.Event.PARENT_ENTITY_CHANGE,
{
@ -851,9 +860,15 @@ GameLib.GUI.prototype.buildEntitySelectionControlFromArray = function(
object : object
}
);
this.initialValue = entityManager.findEntityById(value);
};
}(entityManager)
);
}(entityManager, this)
).onFinishChange(function(gui, entityManager){
return function() {
gui.build(entityManager);
}
}(this, entityManager));
};
/**

View File

@ -252,8 +252,7 @@ GameLib.System.prototype.update = function(deltaTime) {
viewport.height * renderer.height
);
scenes.map(function(scene){
function renderScene(scene) {
if (scene.activeCamera) {
renderer.instance.render(
scene.instance,
@ -264,9 +263,14 @@ GameLib.System.prototype.update = function(deltaTime) {
scene.instance,
camera.instance
);
}
}
});
if (viewport.scenes && viewport.scenes.length > 0) {
viewport.scenes.map(renderScene);
} else {
scenes.map(renderScene);
}
}
);