added culling for performance improvements

This commit is contained in:
Ellpeck 2020-06-01 17:19:05 +02:00
parent 9988efca07
commit 00e5b2319f
4 changed files with 13 additions and 8 deletions

View file

@ -67,7 +67,7 @@ namespace ThemeParkClicker {
this.GraphicsDevice.Clear(Color.Black);
if (this.DrawMap) {
this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: this.Camera.ViewMatrix);
this.Map.Draw(gameTime, this.SpriteBatch, Vector2.Zero, 1, 1);
this.Map.Draw(gameTime, this.SpriteBatch, Vector2.Zero, 1, 1, true, this.Camera.GetVisibleRectangle());
this.SpriteBatch.End();
}
base.DoDraw(gameTime);

View file

@ -105,11 +105,16 @@ namespace ThemeParkClicker {
}
}
public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha, int additionalRadius = AdditionalRadius) {
public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha, bool showSurroundings, RectangleF visibleArea) {
var tileSize = Attraction.TileSize * scale;
// draw ground
for (var x = -additionalRadius; x < this.Width + additionalRadius; x++) {
for (var y = -additionalRadius; y < this.Height + additionalRadius; y++) {
var additionalRadius = showSurroundings ? AdditionalRadius : 0;
var minX = Math.Max(-additionalRadius, visibleArea.Left / tileSize.X).Floor();
var minY = Math.Max(-additionalRadius, visibleArea.Top / tileSize.Y).Floor();
var maxX = Math.Min(this.Width + additionalRadius, visibleArea.Right / tileSize.X).Ceil();
var maxY = Math.Min(this.Height + additionalRadius, visibleArea.Bottom / tileSize.Y).Ceil();
for (var x = minX; x < maxX; x++) {
for (var y = minY; y < maxY; y++) {
var pos = new Vector2(x, y);
var drawPos = position + pos * tileSize;
batch.Draw(TilesTexture[0, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0);

View file

@ -6,7 +6,7 @@
<ItemGroup>
<PackageReference Include="Coroutine" Version="1.0.4" />
<PackageReference Include="MLEM.Startup" Version="3.3.3-189" />
<PackageReference Include="MLEM.Startup" Version="3.3.3-190" />
<PackageReference Include="MonoGame.Framework.Portable" Version="3.7.1.189">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View file

@ -83,7 +83,7 @@ namespace ThemeParkClicker {
var (scaleX, scaleY) = e.DisplayArea.Size / mapSize;
var scale = Math.Min(scaleX, scaleY);
var pos = e.DisplayArea.Location + (e.DisplayArea.Size - mapSize * scale) / 2;
map.Draw(time, batch, pos, scale, alpha, 0);
map.Draw(time, batch, pos, scale, alpha, false, new RectangleF(Vector2.Zero, mapSize * scale));
},
OnPressed = e => {
var map = GameImpl.Instance.Map;