using System.Numerics; using AcDream.App.Input; using AcDream.App.Streaming; using AcDream.Core.Physics; using AcDream.Core.World; namespace AcDream.App.Rendering; internal interface IWorldSceneSkyStateSource { DayGroupData? ActiveDayGroup { get; } float DayFraction { get; } } internal interface IWorldSceneEntitySource { IEnumerable<(uint LandblockId, Vector3 AabbMin, Vector3 AabbMax, IReadOnlyList Entities, IReadOnlyDictionary? AnimatedById)> LandblockEntries { get; } IEnumerable<(uint LandblockId, Vector3 AabbMin, Vector3 AabbMax)> LandblockBounds { get; } } internal sealed class RuntimeWorldSceneEntitySource : IWorldSceneEntitySource { private readonly GpuWorldState _world; public RuntimeWorldSceneEntitySource(GpuWorldState world) { _world = world ?? throw new ArgumentNullException(nameof(world)); } public IEnumerable<(uint LandblockId, Vector3 AabbMin, Vector3 AabbMax, IReadOnlyList Entities, IReadOnlyDictionary? AnimatedById)> LandblockEntries => _world.LandblockEntries; public IEnumerable<(uint LandblockId, Vector3 AabbMin, Vector3 AabbMax)> LandblockBounds => _world.LandblockBounds; } internal interface IWorldScenePViewDiagnosticSource { Vector3 RawPlayerPositionOr(Vector3 fallback); float PlayerYaw { get; } float? SampleTerrainZ(float worldX, float worldY); CameraCellResolution CameraCellResolution { get; } } internal sealed class RuntimeWorldScenePViewDiagnosticSource : IWorldScenePViewDiagnosticSource { private readonly ILocalPlayerControllerSource _player; private readonly PhysicsEngine _physics; private readonly CellVisibility _visibility; public RuntimeWorldScenePViewDiagnosticSource( ILocalPlayerControllerSource player, PhysicsEngine physics, CellVisibility visibility) { _player = player ?? throw new ArgumentNullException(nameof(player)); _physics = physics ?? throw new ArgumentNullException(nameof(physics)); _visibility = visibility ?? throw new ArgumentNullException(nameof(visibility)); } public Vector3 RawPlayerPositionOr(Vector3 fallback) => _player.Controller?.Position ?? fallback; public float PlayerYaw => _player.Controller?.Yaw ?? 0f; public float? SampleTerrainZ(float worldX, float worldY) => _physics.SampleTerrainZ(worldX, worldY); public CameraCellResolution CameraCellResolution => _visibility.LastCameraCellResolution; } internal interface IWorldSceneDebugStateSource { bool CollisionWireframesVisible { get; } } internal sealed class WorldSceneDebugState : IWorldSceneDebugStateSource { public bool CollisionWireframesVisible { get; private set; } public bool ToggleCollisionWireframes() { CollisionWireframesVisible = !CollisionWireframesVisible; return CollisionWireframesVisible; } }