Description:
Add culling for trees.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r212:d06f5425f7df -

@@ -478,7 +478,11
478 return ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
478 return ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
479 }
479 }
480
480
481 protected Boolean cull(int gridX, int gridY)
481 protected Boolean cull(int gridX, int gridY)
482 {
483 return cull(gridX, gridY, 0);
484 }
485 protected Boolean cull(int gridX, int gridY, int margin)
482 {
486 {
483 int screenX = (gridX - gridY) * Tile.TileSpriteWidth / 2;
487 int screenX = (gridX - gridY) * Tile.TileSpriteWidth / 2;
484 int screenY = (gridX + gridY) * Tile.TileSpriteHeight / 2;
488 int screenY = (gridX + gridY) * Tile.TileSpriteHeight / 2;
@@ -486,8 +490,8
486 Vector2 original = Vector2.Transform(new Vector2(screenX, screenY), camera.get_transformation(GraphicsDevice));
490 Vector2 original = Vector2.Transform(new Vector2(screenX, screenY), camera.get_transformation(GraphicsDevice));
487
491
488 return (!FNAGame.enableCulling ||
492 return (!FNAGame.enableCulling ||
489 (MathUtils.Between(original.X, -Tile.TileSpriteWidth, FNAGame.width)
493 (MathUtils.Between(original.X, -Tile.TileSpriteWidth - margin, FNAGame.width)
490 && MathUtils.Between(original.Y, -Tile.TileSpriteHeight, FNAGame.height)));
494 && MathUtils.Between(original.Y, -Tile.TileSpriteHeight - margin, FNAGame.height)));
491 }
495 }
492
496
493 //Convenience method I'm not super sure about anymore.
497 //Convenience method I'm not super sure about anymore.
@@ -743,7 +747,8
743 for (int j = 0; j < this.simulation.map.MapWidth; j += 1)
747 for (int j = 0; j < this.simulation.map.MapWidth; j += 1)
744 {
748 {
745
749
746 if (this.simulation.map.cells[i][j].hasTree)
750 if (this.simulation.map.cells[i][j].hasTree
751 && this.cull(i, j))
747 { //until we actually simulate:
752 { //until we actually simulate:
748 drawTileAt(i, j, 142, 2);
753 drawTileAt(i, j, 142, 2);
749 // if ((i + j) % 8 == 0)
754 // if ((i + j) % 8 == 0)
@@ -756,7 +761,9
756 // }
761 // }
757 this.treesDrawn++;
762 this.treesDrawn++;
758 }
763 }
759 else if (this.simulation.map.cells[i][j].status == CellStatus.DeadTree) {
764 else if (this.simulation.map.cells[i][j].status == CellStatus.DeadTree
765 && this.cull(i, j))
766 {
760 drawTileAt(i, j, 141, 2);
767 drawTileAt(i, j, 141, 2);
761 // System.Console.WriteLine(String.Format("Drew Dead Tree at {0},{1}", i, j));
768 // System.Console.WriteLine(String.Format("Drew Dead Tree at {0},{1}", i, j));
762 this.treesDrawn++;
769 this.treesDrawn++;
You need to be logged in to leave comments. Login now