wip: cull opaque tiles
This commit is contained in:
parent
2a07733144
commit
0929a98e2a
|
@ -20,8 +20,8 @@ export class Point2D {
|
||||||
Object.freeze(this);
|
Object.freeze(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
approxEq(other: Point2D): boolean {
|
approxEq(other: Point2D, epsilon: number | undefined): boolean {
|
||||||
return approxEq(this.x, other.x) && approxEq(this.y, other.y);
|
return approxEq(this.x, other.x, epsilon) && approxEq(this.y, other.y, epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
lerp(other: Point2D, t: number): Point2D {
|
lerp(other: Point2D, t: number): Point2D {
|
||||||
|
@ -107,8 +107,8 @@ export class Matrix2D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function approxEq(a: number, b: number): boolean {
|
export function approxEq(a: number, b: number, epsilon: number | undefined): boolean {
|
||||||
return Math.abs(a - b) <= EPSILON;
|
return Math.abs(a - b) <= (epsilon == null ? EPSILON : epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function lerp(a: number, b: number, t: number): number {
|
export function lerp(a: number, b: number, t: number): number {
|
||||||
|
|
|
@ -324,6 +324,10 @@ class App {
|
||||||
const pathTileStrips = scene.pathTileStrips[pathIndex];
|
const pathTileStrips = scene.pathTileStrips[pathIndex];
|
||||||
for (const tileStrip of pathTileStrips) {
|
for (const tileStrip of pathTileStrips) {
|
||||||
for (const tile of tileStrip.tiles) {
|
for (const tile of tileStrip.tiles) {
|
||||||
|
// TODO(pcwalton)
|
||||||
|
if (tile.isFilled())
|
||||||
|
continue;
|
||||||
|
|
||||||
for (const edge of tile.edges) {
|
for (const edge of tile.edges) {
|
||||||
let ctrl;
|
let ctrl;
|
||||||
if (edge.ctrl == null)
|
if (edge.ctrl == null)
|
||||||
|
|
|
@ -264,7 +264,7 @@ export class Tiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private clipEdgeX(edge: Edge, x: number): ClippedEdgesX {
|
private clipEdgeX(edge: Edge, x: number): ClippedEdgesX {
|
||||||
const EPSILON: number = 0.001;
|
const EPSILON: number = 0.00001;
|
||||||
|
|
||||||
if (edge.from.x < x && edge.to.x < x)
|
if (edge.from.x < x && edge.to.x < x)
|
||||||
return {left: edge, right: null};
|
return {left: edge, right: null};
|
||||||
|
@ -291,7 +291,7 @@ export class Tiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private clipEdgeY(edge: Edge, y: number): ClippedEdgesY {
|
private clipEdgeY(edge: Edge, y: number): ClippedEdgesY {
|
||||||
const EPSILON: number = 0.001;
|
const EPSILON: number = 0.00001;
|
||||||
|
|
||||||
if (edge.from.y < y && edge.to.y < y)
|
if (edge.from.y < y && edge.to.y < y)
|
||||||
return {upper: edge, lower: null};
|
return {upper: edge, lower: null};
|
||||||
|
@ -473,6 +473,19 @@ export class Tile {
|
||||||
isEmpty(): boolean {
|
isEmpty(): boolean {
|
||||||
return this.edges.length === 0;
|
return this.edges.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isFilled(): boolean {
|
||||||
|
if (this.edges.length !== 1)
|
||||||
|
return false;
|
||||||
|
const edge = this.edges[0];
|
||||||
|
if (edge.ctrl != null)
|
||||||
|
return false;
|
||||||
|
//console.log("single edge:", JSON.stringify(edge));
|
||||||
|
const left = edge.from.x < edge.to.x ? edge.from : edge.to;
|
||||||
|
const right = edge.from.x < edge.to.x ? edge.to : edge.from;
|
||||||
|
return left.approxEq(new Point2D(0, 0), 0.1) &&
|
||||||
|
right.approxEq(new Point2D(TILE_SIZE.width, 0), 0.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ClippedEdgesX {
|
interface ClippedEdgesX {
|
||||||
|
|
Loading…
Reference in New Issue