Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions CentrED/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,37 @@ public void ResetCamera()
Roll = 0f;
}

private static readonly float[] ZoomLevels =
{
0.02f, 0.05f,
0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f,
1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f
};

public void ZoomIn(float delta)
{
Zoom = Math.Clamp(Zoom + delta, 0.2f, 4f);
if (delta == 0f)
return;

var notches = Math.Max(1, (int)Math.Round(Math.Abs(delta) / 0.1f));
for (var i = 0; i < notches; i++)
Zoom = delta > 0 ? NextZoomLevel(Zoom, true) : NextZoomLevel(Zoom, false);
}

private static float NextZoomLevel(float current, bool up)
{
const float eps = 1e-4f;
if (up)
{
foreach (var level in ZoomLevels)
if (level > current + eps)
return level;
return ZoomLevels[^1];
}
for (var i = ZoomLevels.Length - 1; i >= 0; i--)
if (ZoomLevels[i] < current - eps)
return ZoomLevels[i];
return ZoomLevels[0];
}

public void Update()
Expand All @@ -78,4 +106,4 @@ public void Update()
WorldViewProj.M41, WorldViewProj.M42, WorldViewProj.M43, WorldViewProj.M44
);
}
}
}
2 changes: 2 additions & 0 deletions CentrED/CentrEDGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected override void BeginRun()

protected override void UnloadContent()
{
Metrics.StopProfiling();
CEDClient.Disconnect();
}

Expand Down Expand Up @@ -125,6 +126,7 @@ protected override void Draw(GameTime gameTime)
UIManager.DrawExtraWindows();
MapManager.AfterDraw();
Metrics.Stop("Draw");
Metrics.CaptureFrame();
}
catch (Exception e)
{
Expand Down
3 changes: 2 additions & 1 deletion CentrED/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ConfigRoot
public bool ObjectBrightHighlight;
public bool LegacyMouseScroll;
public bool Viewports;
public bool PreloadMapOnConnect = true;
public string GraphicsDriver = "Auto"; //Auto,SDL_GPU,D3D11,OpenGL
public Dictionary<string, WindowState> Layout = new();
public Dictionary<string, (Keys[], Keys[])> Keymap = new();
Expand Down Expand Up @@ -74,4 +75,4 @@ public static void Save()
File.WriteAllText(_configFilePath, JsonSerializer.Serialize(Instance, SerializerOptions));
LastConfigSave = DateTime.Now;
}
}
}
25 changes: 16 additions & 9 deletions CentrED/Map/LandObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ public class LandObject : TileObject
public LandTile LandTile;

public bool IsGhost => LandTile.Block == null;
private sbyte _averageZ;

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);
public sbyte AverageZ()
{
return _averageZ;
}

private void UpdateAverageZ(Vector4 cornerZ)
{
int zTop = (int)(cornerZ.X / TILE_Z_SCALE);
int zRight= (int)(cornerZ.Y / TILE_Z_SCALE);
int zLeft= (int)(cornerZ.Z / TILE_Z_SCALE);
int zBottom= (int)(cornerZ.W / TILE_Z_SCALE);
if (Math.Abs(zTop - zBottom) <= Math.Abs(zLeft - zRight))
{
return(sbyte) ((zTop + zBottom) >> 1);
_averageZ = (sbyte)((zTop + zBottom) >> 1);
}
else
{
return (sbyte) ((zLeft + zRight) >> 1);
_averageZ = (sbyte)((zLeft + zRight) >> 1);
}
}

Expand Down Expand Up @@ -64,6 +70,7 @@ public void UpdateCorners(ushort id)
var alwaysFlat = AlwaysFlat(id);
var flatView = CEDGame.MapManager.FlatView;
Vector4 cornerZ = flatView ? Vector4.Zero : alwaysFlat ? new Vector4(Tile.Z * TILE_Z_SCALE) : GetCornerZ();
UpdateAverageZ(cornerZ);

var posX = (Tile.X - 1) * TILE_SIZE;
var posY = (Tile.Y - 1) * TILE_SIZE;
Expand Down Expand Up @@ -316,4 +323,4 @@ private bool CalculateNormal(LandTile tile, LandTile? top, LandTile? right, Land
}
return true;
}
}
}
Loading
Loading