Skip to content

Commit

Permalink
Improve static filter when land overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Jan 21, 2024
1 parent 7ab8148 commit 12b94f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
43 changes: 32 additions & 11 deletions CentrED/Map/LandObject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using CentrED.Renderer;
using ClassicUO.Assets;
using Microsoft.Xna.Framework;

Expand All @@ -7,6 +6,22 @@ namespace CentrED.Map;
public class LandObject : TileObject
{
public LandTile LandTile;

public sbyte AverageZ() //TODO Calculate me once
{
int zTop = (int)(Vertices[0].Position.Z / TILE_Z_SCALE);
int zRight= (int)(Vertices[1].Position.Z/ TILE_Z_SCALE);
int zLeft= (int)(Vertices[2].Position.Z/ TILE_Z_SCALE);
int zBottom= (int)(Vertices[3].Position.Z/ TILE_Z_SCALE);
if (Math.Abs(zTop - zBottom) <= Math.Abs(zLeft - zRight))
{
return(sbyte) ((zTop + zBottom) >> 1);
}
else
{
return (sbyte) ((zLeft + zRight) >> 1);
}
}

public LandObject(LandTile tile)
{
Expand All @@ -30,7 +45,7 @@ private bool IsFlat(float x, float y, float z, float w)

public void UpdateCorners(ushort id)
{
Vector4 cornerZ = AlwaysFlat(id) ? new Vector4(Tile.Z * TILE_Z_SCALE) : GetCornerZ(LandTile);
Vector4 cornerZ = AlwaysFlat(id) ? new Vector4(Tile.Z * TILE_Z_SCALE) : GetCornerZ();

var posX = (Tile.X - 1) * TILE_SIZE;
var posY = (Tile.Y - 1) * TILE_SIZE;
Expand Down Expand Up @@ -125,17 +140,23 @@ public void UpdateBottomCorner(float z)
Vertices[3].Position.Z = z * TILE_Z_SCALE;
UpdateId(Tile.Id);
}
private Vector4 GetCornerZ(LandTile tile)

private Vector4 GetCornerZ()
{
var client = Application.CEDClient;
var x = tile.X;
var y = tile.Y;
var top = tile;
var right = client.TryGetLandTile(Math.Min(client.Width * 8 - 1, x + 1), y, out var rightTile) ? rightTile : tile;

var left = client.TryGetLandTile(x, Math.Min(client.Height * 8 - 1, y + 1), out var leftTile) ? leftTile : tile;
var bottom = client.TryGetLandTile(Math.Min(client.Width * 8 - 1, x + 1), Math.Min(client.Height * 8 - 1, y + 1), out var bottomTile) ? bottomTile : tile;
var x = Tile.X;
var y = Tile.Y;
var top = Tile;
var right = client.TryGetLandTile
(Math.Min(client.Width * 8 - 1, x + 1), y, out var rightTile) ?
rightTile :
Tile;

var left = client.TryGetLandTile(x, Math.Min(client.Height * 8 - 1, y + 1), out var leftTile) ? leftTile : Tile;
var bottom = client.TryGetLandTile
(Math.Min(client.Width * 8 - 1, x + 1), Math.Min(client.Height * 8 - 1, y + 1), out var bottomTile) ?
bottomTile :
Tile;

return new Vector4(top.Z, right.Z, left.Z, bottom.Z) * TILE_Z_SCALE;
}
Expand Down
6 changes: 4 additions & 2 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,10 @@ private void DrawStatic(StaticObject so, Vector3 hueOverride = default)
if (!CanDrawStatic(tile.Id))
return;

var landTile = LandTiles[so.Tile.X, so.Tile.Y]?.Tile;
if (!WithinZRange(tile.Z) || landTile != null && CanDrawLand(landTile.Id) && WithinZRange(landTile.Z) && landTile.Z > tile.Z + 5)
var landTile = LandTiles[so.Tile.X, so.Tile.Y];
if (!WithinZRange(tile.Z)
|| landTile != null && CanDrawLand(landTile.Tile.Id) && WithinZRange(landTile.Tile.Z) && landTile.AverageZ() >= tile.Z + 5
)
return;

_mapRenderer.DrawMapObject(so, hueOverride);
Expand Down

0 comments on commit 12b94f7

Please sign in to comment.