Core Game Loop Additions

This commit is contained in:
2026-06-03 22:41:27 -07:00
parent 79ff06a7df
commit 8e9b4412ce
70 changed files with 3084 additions and 2 deletions
@@ -0,0 +1,34 @@
using ProjectM.Simulation;
using Unity.Entities;
using UnityEngine;
namespace ProjectM.Authoring
{
/// <summary>
/// Authoring for the GLOBAL cycle-director ghost prefab: an ownerless INTERPOLATED ghost (the
/// GhostAuthoringComponent is inherited when this prefab is duplicated from UpgradePickup.prefab) that
/// carries the replicated macro-loop state (<see cref="CycleState"/>) and the shared resource ledger
/// (a <see cref="StorageEntry"/> buffer marked by <see cref="ResourceLedger"/>). It is GLOBAL — it must
/// carry NO <see cref="RegionTag"/> so GhostRelevancy keeps it relevant to every connection regardless of
/// region. The server CycleDirectorSpawnSystem overrides the baked CycleState at spawn (real PhaseEndTick)
/// and adds the server-only CycleRuntime.
/// </summary>
public class CycleDirectorAuthoring : MonoBehaviour
{
private class CycleDirectorBaker : Baker<CycleDirectorAuthoring>
{
public override void Bake(CycleDirectorAuthoring authoring)
{
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
AddComponent(entity, new CycleState
{
Phase = CyclePhase.Expedition,
CycleNumber = 1,
PhaseEndTick = 0u,
});
AddComponent<ResourceLedger>(entity);
AddBuffer<StorageEntry>(entity);
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 843fd0d567f48ad46840dcce0ce84bbc
@@ -0,0 +1,31 @@
using ProjectM.Simulation;
using Unity.Entities;
using UnityEngine;
namespace ProjectM.Authoring
{
/// <summary>
/// Authoring for the baked <see cref="CycleDirectorSpawner"/> singleton (mirrors StorageSpawnerAuthoring).
/// Place once in the gameplay subscene; the server-only CycleDirectorSpawnSystem reads it, instantiates the
/// global cycle-director ghost, then destroys the singleton so it fires exactly once. Carries no transform.
/// </summary>
public class CycleDirectorSpawnerAuthoring : MonoBehaviour
{
[Tooltip("Cycle-director ghost prefab. Must carry CycleDirectorAuthoring + a GhostAuthoringComponent (ownerless, interpolated).")]
public GameObject DirectorPrefab;
private class CycleDirectorSpawnerBaker : Baker<CycleDirectorSpawnerAuthoring>
{
public override void Bake(CycleDirectorSpawnerAuthoring authoring)
{
var entity = GetEntity(authoring, TransformUsageFlags.None);
AddComponent(entity, new CycleDirectorSpawner
{
Prefab = authoring.DirectorPrefab != null
? GetEntity(authoring.DirectorPrefab, TransformUsageFlags.Dynamic)
: Entity.Null,
});
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1f4d2cb1e17d6a1429525674969dd3f0
@@ -0,0 +1,45 @@
using ProjectM.Simulation;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
namespace ProjectM.Authoring
{
/// <summary>
/// Authoring for a walk-in <see cref="ExpeditionGate"/>. Place on a visible gate object in the gameplay
/// subscene; baked into both worlds at the gate's position (the server reads its LocalTransform for the
/// overlap test, the client renders the mesh). Set From/To regions + the arrival point in the destination
/// region (offset from that region's gate so the player doesn't immediately re-trigger).
/// </summary>
public class ExpeditionGateAuthoring : MonoBehaviour
{
public enum Region : byte { Base = 0, Expedition = 1 }
[Tooltip("Region a player must be in for this gate to act on them.")]
public Region From = Region.Base;
[Tooltip("Region the player is transited to.")]
public Region To = Region.Expedition;
[Min(0.5f)] public float Radius = 2.5f;
[Tooltip("Where the player arrives in the destination region (offset from that region's gate).")]
public Vector3 ArrivalPos = new Vector3(1000f, 1f, 0f);
private class ExpeditionGateBaker : Baker<ExpeditionGateAuthoring>
{
public override void Bake(ExpeditionGateAuthoring authoring)
{
// Dynamic so the baked entity carries a LocalTransform the server can read for the overlap test.
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
AddComponent(entity, new ExpeditionGate
{
FromRegion = (byte)authoring.From,
ToRegion = (byte)authoring.To,
Radius = authoring.Radius,
ArrivalPos = new float3(authoring.ArrivalPos.x, authoring.ArrivalPos.y, authoring.ArrivalPos.z),
});
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 22f744b59ad23834abe28fc09b661005