|
|
|
@@ -7,12 +7,13 @@
|
|
|
|
|
* @param {gdjs.RuntimeScene} runtimeScene
|
|
|
|
|
* @param {gdjs.RuntimeGamePixiRenderer} runtimeGameRenderer
|
|
|
|
|
*/
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer = function(runtimeScene, runtimeGameRenderer) {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer = function (runtimeScene, runtimeGameRenderer) {
|
|
|
|
|
this._pixiRenderer = runtimeGameRenderer
|
|
|
|
|
? runtimeGameRenderer.getPIXIRenderer()
|
|
|
|
|
: null;
|
|
|
|
|
this._runtimeScene = runtimeScene;
|
|
|
|
|
this._pixiContainer = new PIXI.Container(); //The Container meant to contains all pixi objects of the scene.
|
|
|
|
|
this._pixiContainer = new PIXI.Container(); // Contains the layers of the scene (and, optionally, debug PIXI objects).
|
|
|
|
|
this._pixiContainer.sortableChildren = true;
|
|
|
|
|
|
|
|
|
|
/** @type {?PIXI.Graphics} */
|
|
|
|
|
this._debugDraw = null;
|
|
|
|
@@ -23,7 +24,7 @@ gdjs.RuntimeScenePixiRenderer = function(runtimeScene, runtimeGameRenderer) {
|
|
|
|
|
|
|
|
|
|
gdjs.RuntimeSceneRenderer = gdjs.RuntimeScenePixiRenderer; //Register the class to let the engine use it.
|
|
|
|
|
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.onGameResolutionResized = function() {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.onGameResolutionResized = function () {
|
|
|
|
|
if (!this._pixiRenderer) return;
|
|
|
|
|
|
|
|
|
|
var runtimeGame = this._runtimeScene.getGame();
|
|
|
|
@@ -33,7 +34,7 @@ gdjs.RuntimeScenePixiRenderer.prototype.onGameResolutionResized = function() {
|
|
|
|
|
this._pixiRenderer.height / runtimeGame.getGameResolutionHeight();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.render = function() {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.render = function () {
|
|
|
|
|
if (!this._pixiRenderer) return;
|
|
|
|
|
|
|
|
|
|
// this._renderProfileText(); //Uncomment to display profiling times
|
|
|
|
@@ -43,32 +44,37 @@ gdjs.RuntimeScenePixiRenderer.prototype.render = function() {
|
|
|
|
|
this._pixiRenderer.render(this._pixiContainer);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype._renderProfileText = function() {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype._renderProfileText = function () {
|
|
|
|
|
if (!this._runtimeScene.getProfiler()) return;
|
|
|
|
|
|
|
|
|
|
if (!this._profilerText) {
|
|
|
|
|
this._profilerText = new PIXI.Text(" ", {
|
|
|
|
|
align: "left",
|
|
|
|
|
stroke: "#FFF",
|
|
|
|
|
strokeThickness: 1
|
|
|
|
|
this._profilerText = new PIXI.Text(' ', {
|
|
|
|
|
align: 'left',
|
|
|
|
|
stroke: '#FFF',
|
|
|
|
|
strokeThickness: 1,
|
|
|
|
|
});
|
|
|
|
|
// Add on top of all layers:
|
|
|
|
|
this._pixiContainer.addChild(this._profilerText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var average = this._runtimeScene.getProfiler().getFramesAverageMeasures();
|
|
|
|
|
var outputs = [];
|
|
|
|
|
gdjs.Profiler.getProfilerSectionTexts("All", average, outputs);
|
|
|
|
|
gdjs.Profiler.getProfilerSectionTexts('All', average, outputs);
|
|
|
|
|
|
|
|
|
|
this._profilerText.text = outputs.join("\n");
|
|
|
|
|
this._profilerText.text = outputs.join('\n');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {gdjs.RuntimeObject[]} instances
|
|
|
|
|
* @param {Object.<string, number[]>} layersCameraCoordinates
|
|
|
|
|
*/
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.renderDebugDraw = function(instances, layersCameraCoordinates) {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.renderDebugDraw = function (
|
|
|
|
|
instances,
|
|
|
|
|
layersCameraCoordinates
|
|
|
|
|
) {
|
|
|
|
|
if (!this._debugDraw) {
|
|
|
|
|
this._debugDraw = new PIXI.Graphics();
|
|
|
|
|
// Add on top of all layers:
|
|
|
|
|
this._pixiContainer.addChild(this._debugDraw);
|
|
|
|
|
}
|
|
|
|
|
/** @type PIXI.Graphics */
|
|
|
|
@@ -80,7 +86,7 @@ gdjs.RuntimeScenePixiRenderer.prototype.renderDebugDraw = function(instances, la
|
|
|
|
|
debugDraw.fill.alpha = 0.1;
|
|
|
|
|
debugDraw.alpha = 0.8;
|
|
|
|
|
|
|
|
|
|
for(var i = 0;i < instances.length;i++) {
|
|
|
|
|
for (var i = 0; i < instances.length; i++) {
|
|
|
|
|
var object = instances[i];
|
|
|
|
|
var cameraCoords = layersCameraCoordinates[object.getLayer()];
|
|
|
|
|
var rendererObject = object.getRendererObject();
|
|
|
|
@@ -88,21 +94,45 @@ gdjs.RuntimeScenePixiRenderer.prototype.renderDebugDraw = function(instances, la
|
|
|
|
|
if (!cameraCoords || !rendererObject) continue;
|
|
|
|
|
|
|
|
|
|
var aabb = object.getAABB();
|
|
|
|
|
debugDraw.drawRect(aabb.min[0], aabb.min[1], aabb.max[0] - aabb.min[0], aabb.max[1] - aabb.min[1]);
|
|
|
|
|
debugDraw.drawRect(
|
|
|
|
|
aabb.min[0],
|
|
|
|
|
aabb.min[1],
|
|
|
|
|
aabb.max[0] - aabb.min[0],
|
|
|
|
|
aabb.max[1] - aabb.min[1]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
debugDraw.endFill();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.hideCursor = function() {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.hideCursor = function () {
|
|
|
|
|
if (!this._pixiRenderer) return;
|
|
|
|
|
this._pixiRenderer.view.style.cursor = "none";
|
|
|
|
|
this._pixiRenderer.view.style.cursor = 'none';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.showCursor = function() {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.showCursor = function () {
|
|
|
|
|
if (!this._pixiRenderer) return;
|
|
|
|
|
this._pixiRenderer.view.style.cursor = "";
|
|
|
|
|
this._pixiRenderer.view.style.cursor = '';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.getPIXIContainer = function() {
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.getPIXIContainer = function () {
|
|
|
|
|
return this._pixiContainer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {gdjs.Layer} layer
|
|
|
|
|
* @param {number} index
|
|
|
|
|
*/
|
|
|
|
|
gdjs.RuntimeScenePixiRenderer.prototype.setLayerIndex = function (
|
|
|
|
|
layer,
|
|
|
|
|
index
|
|
|
|
|
) {
|
|
|
|
|
/** @type {gdjs.LayerPixiRenderer} */
|
|
|
|
|
// @ts-ignore - assume the renderer is the correct one
|
|
|
|
|
var layerPixiRenderer = layer.getRenderer();
|
|
|
|
|
var layerPixiObject = layerPixiRenderer.getRendererObject();
|
|
|
|
|
|
|
|
|
|
if (this._pixiContainer.children.indexOf(layerPixiObject) === index) return;
|
|
|
|
|
|
|
|
|
|
this._pixiContainer.removeChild(layerPixiObject);
|
|
|
|
|
this._pixiContainer.addChildAt(layerPixiObject, index);
|
|
|
|
|
};
|
|
|
|
|