sion: 3072m Sion map loader, Ymir heightfield+trimesh physics, LOD1/LOD2 renderer, and tests
This commit is contained in:
parent
dccfbb95b5
commit
1864acecb7
14 changed files with 2242 additions and 183 deletions
155
client/Main.cs
155
client/Main.cs
|
|
@ -14,14 +14,19 @@ namespace RustToDust.Client;
|
|||
public partial class Main : Node3D
|
||||
{
|
||||
private TerrainRenderer _terrain = null!;
|
||||
private SionMapRenderer _sionMap = null!;
|
||||
private ArenaRenderer _arena = null!;
|
||||
private Camera3D _camera = null!;
|
||||
private Hud _hud = null!;
|
||||
private DirectionalLight3D _sun = null!;
|
||||
private ProceduralSkyMaterial _skyMat = null!;
|
||||
private Godot.Environment _env = null!;
|
||||
private ArenaSession? _session;
|
||||
private ArenaMapKind _mapKind = ArenaMapKind.Sion;
|
||||
|
||||
private PlayerInput? _scriptedInput;
|
||||
private float _cameraYaw;
|
||||
private float _cameraPitch = Mathf.DegToRad(12f);
|
||||
private float _cameraPitch = Mathf.DegToRad(5f);
|
||||
private float _cameraZoom = 1.0f;
|
||||
private Vector3 _cameraSmoothedAnchor = Vector3.Zero;
|
||||
private float _elapsedSeconds;
|
||||
|
|
@ -53,8 +58,11 @@ public partial class Main : Node3D
|
|||
|
||||
public ArenaSession Session => _session ?? throw new InvalidOperationException($"No active ArenaSession ({Failure ?? "uninitialized"})");
|
||||
public TerrainRenderer Terrain => _terrain;
|
||||
public SionMapRenderer SionMap => _sionMap;
|
||||
public ArenaRenderer Arena => _arena;
|
||||
public Hud Hud => _hud;
|
||||
public ArenaMapKind MapKind => _mapKind;
|
||||
public ArenaMapKind? InitialMapKindOverride { get; set; }
|
||||
public string? Failure { get; private set; }
|
||||
public int Seed => _seed;
|
||||
public float CameraYaw => _cameraYaw;
|
||||
|
|
@ -66,6 +74,9 @@ public partial class Main : Node3D
|
|||
_terrain = new TerrainRenderer { Name = "Terrain" };
|
||||
AddChild(_terrain);
|
||||
|
||||
_sionMap = new SionMapRenderer { Name = "SionMap" };
|
||||
AddChild(_sionMap);
|
||||
|
||||
_arena = new ArenaRenderer { Name = "Arena" };
|
||||
AddChild(_arena);
|
||||
|
||||
|
|
@ -74,20 +85,32 @@ public partial class Main : Node3D
|
|||
Name = "ShoulderCamera",
|
||||
Current = true,
|
||||
Fov = 58f,
|
||||
Far = 1800f
|
||||
Far = 4200f
|
||||
};
|
||||
AddChild(_camera);
|
||||
|
||||
_hud = new Hud(() => _session, OnEquipCargo, () => _cameraYaw) { Name = "Hud" };
|
||||
AddChild(_hud);
|
||||
|
||||
if (InitialMapKindOverride.HasValue)
|
||||
{
|
||||
_mapKind = InitialMapKindOverride.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
string? envMap = System.Environment.GetEnvironmentVariable("RTD_MAP");
|
||||
_mapKind = string.Equals(envMap, "desert", StringComparison.OrdinalIgnoreCase)
|
||||
? ArenaMapKind.Desert
|
||||
: ArenaMapKind.Sion;
|
||||
}
|
||||
|
||||
if (int.TryParse(System.Environment.GetEnvironmentVariable("RTD_PERF_FRAMES"), out int perfFrames) && perfFrames > 0)
|
||||
{
|
||||
_perfTargetFrames = perfFrames;
|
||||
ArenaSession.PerfEnabled = true;
|
||||
}
|
||||
|
||||
Reset(_seed);
|
||||
Reset(_seed, _mapKind);
|
||||
if (_perfTargetFrames > 0 && System.Environment.GetEnvironmentVariable("RTD_PERF_COMBAT") == "1" && _session is not null)
|
||||
{
|
||||
SetupPerfCombatScenario(_session);
|
||||
|
|
@ -149,26 +172,49 @@ public partial class Main : Node3D
|
|||
_session = null;
|
||||
}
|
||||
|
||||
public void Reset(int seed)
|
||||
public void Reset(int seed, ArenaMapKind? mapKind = null)
|
||||
{
|
||||
_seed = seed;
|
||||
if (mapKind.HasValue)
|
||||
{
|
||||
_mapKind = mapKind.Value;
|
||||
}
|
||||
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
Failure = null;
|
||||
|
||||
try
|
||||
{
|
||||
_session = new ArenaSession(seed);
|
||||
_session = new ArenaSession(seed, _mapKind);
|
||||
var p = _session.State.Player;
|
||||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = Mathf.DegToRad(12f);
|
||||
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_cameraSmoothedAnchor = ComputeTargetAnchor(p);
|
||||
_camera.Far = _mapKind == ArenaMapKind.Sion ? 4200f : 1800f;
|
||||
ApplyEnvironmentForMap(_mapKind);
|
||||
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_terrain.Visible = false;
|
||||
_sionMap.Visible = true;
|
||||
_sionMap.EnsureBuilt(_session.State.SionMap!, _session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sionMap.Visible = false;
|
||||
_terrain.Visible = true;
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_hud.Sync(_session);
|
||||
|
||||
if (DisplayServer.GetName() != "headless" && !_hud.GarageExpanded && _perfTargetFrames == 0)
|
||||
|
|
@ -214,7 +260,10 @@ public partial class Main : Node3D
|
|||
}
|
||||
break;
|
||||
case Key.R:
|
||||
Reset(_seed + 1);
|
||||
Reset(_seed + 1, _mapKind);
|
||||
break;
|
||||
case Key.M:
|
||||
Reset(_seed, _mapKind == ArenaMapKind.Sion ? ArenaMapKind.Desert : ArenaMapKind.Sion);
|
||||
break;
|
||||
case Key.Escape:
|
||||
if (_hud.GarageExpanded)
|
||||
|
|
@ -292,7 +341,10 @@ public partial class Main : Node3D
|
|||
{
|
||||
double toMs = 1000.0 / Stopwatch.Frequency;
|
||||
long tt0 = Stopwatch.GetTimestamp();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
if (_mapKind == ArenaMapKind.Desert)
|
||||
{
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
}
|
||||
long tt1 = Stopwatch.GetTimestamp();
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
long ta1 = Stopwatch.GetTimestamp();
|
||||
|
|
@ -301,7 +353,14 @@ public partial class Main : Node3D
|
|||
|
||||
long tc0 = Stopwatch.GetTimestamp();
|
||||
UpdateCamera((float)delta);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
long th0 = Stopwatch.GetTimestamp();
|
||||
_hud.Sync(_session);
|
||||
long th1 = Stopwatch.GetTimestamp();
|
||||
|
|
@ -340,10 +399,20 @@ public partial class Main : Node3D
|
|||
}
|
||||
else
|
||||
{
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
if (_mapKind == ArenaMapKind.Desert)
|
||||
{
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
}
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
UpdateCamera((float)delta);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
_hud.Sync(_session);
|
||||
}
|
||||
}
|
||||
|
|
@ -395,6 +464,10 @@ public partial class Main : Node3D
|
|||
GD.Print($"UpdateCameraMs/frame: avg={_perfCamMsSum / _perfFrameMs.Count:F2}");
|
||||
GD.Print($"StepBreakdownMs/tick: ring={ArenaSession.PerfRingMs / _perfPhysicsTicks:F2} ai={ArenaSession.PerfAiMs / _perfPhysicsTicks:F2} drive={ArenaSession.PerfDriveMs / _perfPhysicsTicks:F2} world={ArenaSession.PerfWorldMs / _perfPhysicsTicks:F2} sync={ArenaSession.PerfBodySyncMs / _perfPhysicsTicks:F2} detect={ArenaSession.PerfDetectMs / _perfPhysicsTicks:F2} weapons={ArenaSession.PerfWeaponsMs / _perfPhysicsTicks:F2}");
|
||||
GD.Print($"CombatProbes: syncDamageHeatMsTotal={VehicleVisualInstance.PerfDamageHeatMs:F2} matDups={VehicleVisualInstance.PerfMaterialDupCount} bakeTileMsTotal={TerrainRenderer.PerfBakeTileMs:F2} bakeTileCalls={TerrainRenderer.PerfBakeTileCalls} debrisActive={_arena.Debris.ActiveCount} tracers={_session?.State.Tracers.Count ?? 0}");
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
GD.Print($"SionMap: chunks={_sionMap.TerrainChunkCount} tiles={_sionMap.BuildingTileCount} lod1={_sionMap.ActiveLod1TileCount} lod2={_sionMap.ActiveLod2TileCount} culled={_sionMap.CulledTileCount}");
|
||||
}
|
||||
foreach (var kv in _arena.AssetCache.Vehicles)
|
||||
{
|
||||
int tris = 0;
|
||||
|
|
@ -617,7 +690,7 @@ public partial class Main : Node3D
|
|||
|
||||
private void SetupLightingAndSky()
|
||||
{
|
||||
var sun = new DirectionalLight3D
|
||||
_sun = new DirectionalLight3D
|
||||
{
|
||||
Name = "DesertSun",
|
||||
LightColor = new Color(1.0f, 0.92f, 0.78f),
|
||||
|
|
@ -627,19 +700,19 @@ public partial class Main : Node3D
|
|||
DirectionalShadowMaxDistance = 88f,
|
||||
RotationDegrees = new Vector3(-48f, 32f, 0f)
|
||||
};
|
||||
AddChild(sun);
|
||||
AddChild(_sun);
|
||||
|
||||
var skyMat = new ProceduralSkyMaterial
|
||||
_skyMat = new ProceduralSkyMaterial
|
||||
{
|
||||
SkyTopColor = new Color(0.24f, 0.34f, 0.44f),
|
||||
SkyHorizonColor = new Color(0.76f, 0.56f, 0.37f),
|
||||
GroundBottomColor = new Color(0.32f, 0.22f, 0.14f),
|
||||
GroundHorizonColor = new Color(0.70f, 0.50f, 0.33f)
|
||||
};
|
||||
var env = new Godot.Environment
|
||||
_env = new Godot.Environment
|
||||
{
|
||||
BackgroundMode = Godot.Environment.BGMode.Sky,
|
||||
Sky = new Sky { SkyMaterial = skyMat },
|
||||
Sky = new Sky { SkyMaterial = _skyMat },
|
||||
AmbientLightSource = Godot.Environment.AmbientSource.Sky,
|
||||
AmbientLightEnergy = 0.55f,
|
||||
FogEnabled = true,
|
||||
|
|
@ -649,6 +722,46 @@ public partial class Main : Node3D
|
|||
FogDepthBegin = 380f,
|
||||
FogDepthEnd = 1100f
|
||||
};
|
||||
AddChild(new WorldEnvironment { Name = "WorldEnv", Environment = env });
|
||||
AddChild(new WorldEnvironment { Name = "WorldEnv", Environment = _env });
|
||||
}
|
||||
|
||||
private void ApplyEnvironmentForMap(ArenaMapKind mapKind)
|
||||
{
|
||||
if (mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sun.LightColor = new Color(1.0f, 0.95f, 0.87f);
|
||||
_sun.LightEnergy = 1.25f;
|
||||
_sun.DirectionalShadowMaxDistance = 160f;
|
||||
_sun.RotationDegrees = new Vector3(-42f, 28f, 0f);
|
||||
|
||||
_skyMat.SkyTopColor = new Color(0.18f, 0.36f, 0.62f);
|
||||
_skyMat.SkyHorizonColor = new Color(0.68f, 0.79f, 0.89f);
|
||||
_skyMat.GroundBottomColor = new Color(0.24f, 0.26f, 0.22f);
|
||||
_skyMat.GroundHorizonColor = new Color(0.58f, 0.67f, 0.74f);
|
||||
|
||||
_env.AmbientLightEnergy = 0.42f;
|
||||
_env.FogLightColor = new Color(0.70f, 0.79f, 0.88f);
|
||||
_env.FogDensity = 0.42f;
|
||||
_env.FogDepthBegin = 850f;
|
||||
_env.FogDepthEnd = 3000f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_sun.LightColor = new Color(1.0f, 0.92f, 0.78f);
|
||||
_sun.LightEnergy = 1.45f;
|
||||
_sun.DirectionalShadowMaxDistance = 88f;
|
||||
_sun.RotationDegrees = new Vector3(-48f, 32f, 0f);
|
||||
|
||||
_skyMat.SkyTopColor = new Color(0.24f, 0.34f, 0.44f);
|
||||
_skyMat.SkyHorizonColor = new Color(0.76f, 0.56f, 0.37f);
|
||||
_skyMat.GroundBottomColor = new Color(0.32f, 0.22f, 0.14f);
|
||||
_skyMat.GroundHorizonColor = new Color(0.70f, 0.50f, 0.33f);
|
||||
|
||||
_env.AmbientLightEnergy = 0.55f;
|
||||
_env.FogLightColor = new Color(0.76f, 0.57f, 0.39f);
|
||||
_env.FogDensity = 0.72f;
|
||||
_env.FogDepthBegin = 380f;
|
||||
_env.FogDepthEnd = 1100f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue