Skip to content

Commit

Permalink
finished setTransform api #66
Browse files Browse the repository at this point in the history
optimize terrain render and hexagon render recycle feature #40
change dispose api parameter, add option for not dispose texture
  • Loading branch information
tyrealgray committed Jan 24, 2018
1 parent db301c0 commit 30d2c7f
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
/.idea/workspace.xml
/npm-debug.log
/.idea
/LOMS/pixi docs-4.5.6.lnk
/LOMS/.idea
/LOMS/nwjs-v0.27.0-win-x64
3 changes: 0 additions & 3 deletions LOMS/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ dist/*
#nwjs
nwjs-v0.23.5-win-x64/*
nwjs-v0.23.5-osx-x64/*

#lnk
pixiDocs-link.lnk
5 changes: 3 additions & 2 deletions LOMS/src/render/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export default class Actor extends ElementCore{
//override in subClass
}

dispose(){
this._sprite.destroy({children:true, texture:true, baseTexture:true});
dispose(option = false){
const disposeChildren = option;
this._sprite.destroy({children: disposeChildren, texture: disposeChildren, baseTexture: disposeChildren});
this._sprite = null;

this._initPosition = null;
Expand Down
4 changes: 2 additions & 2 deletions LOMS/src/render/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ export default class Character extends Actor {
this._sprite.play();
}

dispose() {
super.dispose();
dispose(option) {
super.dispose(option);
this._frames = null;
this._destination = null;
}
Expand Down
2 changes: 1 addition & 1 deletion LOMS/src/render/elementCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ElementCore {
//override in subClass
}

dispose(){
dispose(option){
//override in subClass
}
}
4 changes: 2 additions & 2 deletions LOMS/src/render/hexagon.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default class Hexagon extends Actor {
//override in subClass
}

dispose() {
super.dispose();
dispose(option) {
super.dispose(option);
this._positionOnTerrain = null;
this._renderPosition = null;
}
Expand Down
8 changes: 4 additions & 4 deletions LOMS/src/render/layerAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export default class LayerAgent {
return this;
}

removeElement(element){
removeElement(element, option){
this._removeFromLayer(element, element.getIndex());
this._container.removeChild(element.getRenderObject());
element.dispose();
element.dispose(option);
}

moveLayerTo(layerTo) {
Expand All @@ -45,7 +45,7 @@ export default class LayerAgent {
}
}

removeElementsByIndex(index) {
removeElementsByIndex(index, option) {
let elements = this._layer[index];

this._layer[index] = null;
Expand All @@ -57,7 +57,7 @@ export default class LayerAgent {

for (let element of elements) {
this._container.removeChild(element.getRenderObject());
element.dispose();
element.dispose(option);
}
}

Expand Down
9 changes: 5 additions & 4 deletions LOMS/src/render/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ export default class Mouse extends ElementCore {
this.tick(delta);
}

dispose() {
dispose(option = false) {
const disposeChildren = option;
this._sprite.destroy({
children: true,
texture: true,
baseTexture: true,
children: disposeChildren,
texture: disposeChildren,
baseTexture: disposeChildren,
});
this._sprite = null;
}
Expand Down
4 changes: 2 additions & 2 deletions LOMS/src/render/stageAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ export default class StageAgent {
}

clearActors() {
this._layerAgent.removeElementsByIndex(this.ACTOR_LAYER_INDEX);
this._layerAgent.removeElementsByIndex(this.ACTOR_LAYER_INDEX, true);
return this;
}

clearUI(){
this._layerAgent.removeElementsByIndex(this.UI_LAYER_INDEX);
this._layerAgent.removeElementsByIndex(this.UI_LAYER_INDEX, true);
return this;
}

Expand Down
33 changes: 32 additions & 1 deletion LOMS/src/render/terrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export default class Terrain extends ElementCore {
super(props);
this._container = null;
this._resources = null;
this._isPointsOnTerrainChanged = false;
this._coordinates = props.coordinates ? props.coordinates : {x: 0, y: 0};
this._noAsset = !props.assetData;
this._assetData = props.assetData;
this._runtimeRenderSize = 5;
this._preRenderSize = 5;
this._hexagons = [];
this._renderPointOnTerrain = [];
}

isNoAsset() {
Expand Down Expand Up @@ -69,23 +71,50 @@ export default class Terrain extends ElementCore {
}

tick(delta) {

if(!this._isPointsOnTerrainChanged){
return;
}
this.hexagonRenderRecycle();
}

onRender(delta) {

}

hexagonRenderRecycle(){
for(let index = 0; index < this._hexagons.length; ++index){
const hexagon = this._hexagons[index];
let isRecyclingHexagon = true;
for(const point of this._renderPointOnTerrain){
const position = hexagon.getPositionOnTerrain();
if(position.x === point.x && position.y === point.y){
isRecyclingHexagon = false;
break;
}
}

if(isRecyclingHexagon){
this._layerAgent.removeElement(hexagon, false);
this._hexagons.splice(index,1);
index--;
}
}
}

renderHexagonRegion(topLeft) {
const terrainResource = this._resources[this._assetData.DATA.NAME];
const {height, width} = terrainResource.texture;

const topLeftX = -parseInt(topLeft.x / (height * COS_60_DEGREES)),
topLeftY = -parseInt(topLeft.y / height);

this._renderPointOnTerrain = [];

for (let index = topLeftX - this._preRenderSize; index < topLeftX + this._runtimeRenderSize; ++index) {
for (let columnIndex = topLeftY - this._preRenderSize; columnIndex < topLeftY + this._runtimeRenderSize; ++columnIndex) {

this._renderPointOnTerrain.push({x: index, y: columnIndex});

if (this._hexagons.find((hexagon) => {
let position = hexagon.getPositionOnTerrain();
return position.x === index && position.y === columnIndex;
Expand All @@ -104,6 +133,8 @@ export default class Terrain extends ElementCore {
y: columnIndex,
});

this._isPointsOnTerrainChanged = true;

this.addHexagon(hexagon);
}
}
Expand Down
4 changes: 2 additions & 2 deletions LOMS/src/render/uiText.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default class UIText extends Actor {
return this._sprite;
}

dispose(){
super.dispose();
dispose(option){
super.dispose(option);
this._style = null;
this._string = null;
}
Expand Down

0 comments on commit 30d2c7f

Please sign in to comment.