refactor: renderTick sense
This commit is contained in:
parent
a5c3b4190e
commit
da446e17d2
|
@ -102,13 +102,6 @@ export class EntityList extends decorate(class {}) {
|
|||
}
|
||||
}
|
||||
|
||||
renderTick(elapsed) {
|
||||
for (const uuid in this._entities) {
|
||||
const entity = this._entities[uuid];
|
||||
entity.renderTick(elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
tick(elapsed) {
|
||||
// Run after destruction tickers.
|
||||
const finishedTickers = [];
|
||||
|
|
|
@ -26,7 +26,10 @@ export class EntityListView extends Container {
|
|||
}
|
||||
|
||||
renderTick(elapsed) {
|
||||
this.entityList.renderTick(elapsed);
|
||||
for (const entity of this.entityList) {
|
||||
entity.renderTick(elapsed);
|
||||
}
|
||||
super.renderTick(elapsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ export class Container extends Renderable {
|
|||
super();
|
||||
this._children = [];
|
||||
this._childrenIndexes = new Map();
|
||||
this._isDirty = false;
|
||||
this.container = PIXI ? new PIXI.Container() : undefined;
|
||||
}
|
||||
|
||||
|
@ -42,17 +41,6 @@ export class Container extends Renderable {
|
|||
return this.container;
|
||||
}
|
||||
|
||||
get isDirty() {
|
||||
return this._isDirty;
|
||||
}
|
||||
|
||||
set isDirty(isDirty) {
|
||||
if (this.parent) {
|
||||
this.parent.isDirty = isDirty;
|
||||
}
|
||||
this._isDirty = isDirty;
|
||||
}
|
||||
|
||||
night(intensity = 1) {
|
||||
let filter;
|
||||
const {filters} = this.container;
|
||||
|
@ -114,6 +102,33 @@ export class Container extends Renderable {
|
|||
this._childrenIndexes = new Map();
|
||||
}
|
||||
|
||||
renderTick(elapsed) {
|
||||
let needsSort = false;
|
||||
for (const child of this._children) {
|
||||
if (0 !== child.zIndex) {
|
||||
needsSort = true;
|
||||
}
|
||||
if (child instanceof Container) {
|
||||
child.renderTick(elapsed);
|
||||
}
|
||||
}
|
||||
if (!needsSort) {
|
||||
return;
|
||||
}
|
||||
this._children.sort((l, r) => {
|
||||
if (l.zIndex !== r.zIndex) {
|
||||
return l.zIndex - r.zIndex;
|
||||
}
|
||||
const lIndex = this._childrenIndexes.get(l);
|
||||
const rIndex = this._childrenIndexes.get(r);
|
||||
return lIndex - rIndex;
|
||||
});
|
||||
this.container.children = this._children.map((child) => {
|
||||
return child.internal;
|
||||
});
|
||||
this._resetChildrenIndexes();
|
||||
}
|
||||
|
||||
_resetChildrenIndexes() {
|
||||
this._childrenIndexes = new Map();
|
||||
for (const i in this._children) {
|
||||
|
@ -143,34 +158,4 @@ export class Container extends Renderable {
|
|||
}
|
||||
}
|
||||
|
||||
tick() {
|
||||
if (!this.isDirty) {
|
||||
return;
|
||||
}
|
||||
let needsSort = false;
|
||||
for (const child of this._children) {
|
||||
if (0 !== child.zIndex) {
|
||||
needsSort = true;
|
||||
}
|
||||
if (child instanceof Container) {
|
||||
child.tick();
|
||||
}
|
||||
}
|
||||
if (!needsSort) {
|
||||
return;
|
||||
}
|
||||
this._children.sort((l, r) => {
|
||||
if (l.zIndex !== r.zIndex) {
|
||||
return l.zIndex - r.zIndex;
|
||||
}
|
||||
const lIndex = this._childrenIndexes.get(l);
|
||||
const rIndex = this._childrenIndexes.get(r);
|
||||
return lIndex - rIndex;
|
||||
});
|
||||
this.container.children = this._children.map((child) => {
|
||||
return child.internal;
|
||||
});
|
||||
this._resetChildrenIndexes();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,9 +104,6 @@ export class Renderable extends decorate(class {}) {
|
|||
}
|
||||
|
||||
set zIndex(zIndex) {
|
||||
if (this.parent) {
|
||||
this.parent.isDirty = true;
|
||||
}
|
||||
this._zIndex = zIndex;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ export class Stage extends decorate(Container) {
|
|||
}
|
||||
|
||||
renderTick(elapsed) {
|
||||
this.tick(0);
|
||||
super.renderTick(elapsed); 0;
|
||||
this.renderer.render(this);
|
||||
if (this.camera) {
|
||||
const inverseOffset = Vector.mul(
|
||||
|
|
|
@ -76,8 +76,4 @@ export class LayerView extends Container {
|
|||
this.layerContainer.addChild(tilesSprite);
|
||||
}
|
||||
|
||||
renderTick(elapsed) {
|
||||
this.entityListView.renderTick(elapsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,12 +30,5 @@ export class LayersView extends Container {
|
|||
this.removeChild(layerView);
|
||||
}
|
||||
|
||||
renderTick(elapsed) {
|
||||
for (const index in this.layerViews) {
|
||||
const layerView = this.layerViews[index];
|
||||
layerView.renderTick(elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,5 @@ export class RoomView extends Container {
|
|||
this.addChild(this.layersView);
|
||||
}
|
||||
|
||||
renderTick(elapsed) {
|
||||
this.layersView.renderTick(elapsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user