From b5b2b76ff0a8c4546aa4ee760207023689210e1f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sun, 2 Dec 2018 16:11:26 -0800 Subject: [PATCH] Cull empty tiles --- demo2/tiling.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/demo2/tiling.ts b/demo2/tiling.ts index 68b09d5d..9126b138 100644 --- a/demo2/tiling.ts +++ b/demo2/tiling.ts @@ -156,8 +156,12 @@ export class Tiler { } // Cut up tile strips. - //console.log("strips count:", this.strips.length); - this.tileStrips = this.strips.map(strip => this.divideStrip(strip)); + this.tileStrips = []; + for (const strip of this.strips) { + const tileStrip = this.divideStrip(strip); + if (!tileStrip.isEmpty()) + this.tileStrips.push(tileStrip); + } } private divideStrip(strip: Strip): TileStrip { @@ -192,7 +196,9 @@ export class Tiler { nextEdgeIndex++; } - tileStrip.pushTile(tile); + if (!tile.isEmpty()) + tileStrip.pushTile(tile); + tileLeft = tileRight; } @@ -403,6 +409,10 @@ class TileStrip { tileBottom(): number { return this.tileTop + TILE_SIZE.height; } + + isEmpty(): boolean { + return this.tiles.length === 0; + } } class Tile { @@ -418,6 +428,10 @@ class Tile { this.edges.push(new Edge(new Point2D(edge.from.x - this.tileLeft, edge.from.y), new Point2D(edge.to.x - this.tileLeft, edge.to.y))); } + + isEmpty(): boolean { + return this.edges.length === 0; + } } interface ClippedEdgesX { @@ -538,7 +552,6 @@ export class TileDebugger { const tileStrips = tiler.getTileStrips(); for (let tileStripIndex = 0; tileStripIndex < tileStrips.length; tileStripIndex++) { const tileStrip = tileStrips[tileStripIndex]; - const tileBottom = tileStrip.tileBottom(); for (let tileIndex = 0; tileIndex < tileStrip.tiles.length; tileIndex++) { const tile = tileStrip.tiles[tileIndex];