Co-Op Layer

This commit is contained in:
Luis Gonzalez
2026-06-01 10:48:18 -07:00
parent 1f647dd5e1
commit e851d5f8e9
29 changed files with 667 additions and 20 deletions
@@ -45,7 +45,7 @@ namespace ProjectM.Server
var networkId = SystemAPI.GetComponent<NetworkId>(connection);
var player = ecb.Instantiate(spawner.PlayerPrefab);
ecb.SetComponent(player, LocalTransform.FromPosition(spawner.SpawnPoint));
ecb.SetComponent(player, LocalTransform.FromPosition(spawner.SpawnPoint + PlayerSpawnMath.SpawnOffset(networkId.Value, spawner.SpawnRingRadius, spawner.RingSlots)));
ecb.SetComponent(player, new GhostOwner { NetworkId = networkId.Value });
// Auto-despawn the player when its owning connection is removed.
@@ -0,0 +1,41 @@
using ProjectM.Simulation;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using Unity.Networking.Transport;
namespace ProjectM.Server
{
/// <summary>
/// Server-world half of the M4 LAN host flow. When the per-world <see cref="ConnectionConfig"/>
/// requests <see cref="ConnectionMode.Host"/>, creates a <see cref="NetworkStreamRequestListen"/>
/// entity (netcode binds the server driver and starts listening) and clears the request. Replaces the
/// old <c>AutoConnectPort</c> auto-listen. Not Burst-compiled: a cold path that fires only on an
/// explicit host request.
/// </summary>
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial struct ServerConnectionControlSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<ConnectionConfig>();
}
public void OnUpdate(ref SystemState state)
{
var cfgRef = SystemAPI.GetSingletonRW<ConnectionConfig>();
if (!cfgRef.ValueRO.Requested || cfgRef.ValueRO.Mode != ConnectionMode.Host)
return;
cfgRef.ValueRW.Requested = false;
var endpoint = NetworkEndpoint.AnyIpv4.WithPort(cfgRef.ValueRO.Port);
var ecb = new EntityCommandBuffer(Allocator.Temp);
var req = ecb.CreateEntity();
ecb.AddComponent(req, new NetworkStreamRequestListen { Endpoint = endpoint });
ecb.Playback(state.EntityManager);
ecb.Dispose();
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5530186288473432f8edcc47c1844e07