Co-Op Layer
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace ProjectM.Simulation
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection intent for the M4 LAN host/join flow. Lives in Simulation so both the server and
|
||||
/// client worlds can read it. A UI (<c>ConnectionUI</c>) — or, in the editor, the auto-host system —
|
||||
/// writes the desired <see cref="Mode"/> + endpoint and sets <see cref="Requested"/> true; the
|
||||
/// per-world ConnectionControlSystem turns it into a netcode <c>NetworkStreamRequestListen</c> /
|
||||
/// <c>NetworkStreamRequestConnect</c> and clears <see cref="Requested"/>. Direct IP/LAN only for now —
|
||||
/// Unity Relay is deferred to a later pass. Created per-world as a singleton.
|
||||
/// </summary>
|
||||
public enum ConnectionMode : byte
|
||||
{
|
||||
None,
|
||||
Host,
|
||||
Join,
|
||||
}
|
||||
|
||||
public struct ConnectionConfig : IComponentData
|
||||
{
|
||||
/// <summary>What to do with this world's network stream.</summary>
|
||||
public ConnectionMode Mode;
|
||||
|
||||
/// <summary>Dotted IPv4 to connect to (Join). Ignored for Host (binds AnyIpv4).</summary>
|
||||
public FixedString64Bytes Address;
|
||||
|
||||
/// <summary>Listen/connect port.</summary>
|
||||
public ushort Port;
|
||||
|
||||
/// <summary>Set true to request the control system act on Mode this frame; it clears the flag.</summary>
|
||||
public bool Requested;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85356726c8f524aebb6cc93336fa09dd
|
||||
@@ -0,0 +1,35 @@
|
||||
#if UNITY_EDITOR
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
|
||||
namespace ProjectM.Simulation
|
||||
{
|
||||
/// <summary>
|
||||
/// EDITOR-ONLY dev convenience for the M4 LAN flow. With auto-connect disabled in <c>GameBootstrap</c>,
|
||||
/// this seeds a <see cref="ConnectionConfig"/> in each world on its first update so entering Play "just
|
||||
/// works" multi-client: the server world hosts on loopback and every client / thin-client world joins
|
||||
/// it — reproducing the old single-key playflow but for N players. Runs once per world then disables
|
||||
/// itself, and skips seeding if a <see cref="ConnectionConfig"/> already exists (e.g. set by
|
||||
/// ConnectionUI). Does not exist in player builds.
|
||||
/// </summary>
|
||||
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation | WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
|
||||
public partial struct EditorAutoHostSystem : ISystem
|
||||
{
|
||||
public void OnUpdate(ref SystemState state)
|
||||
{
|
||||
state.Enabled = false; // run exactly once per world
|
||||
|
||||
if (SystemAPI.HasSingleton<ConnectionConfig>())
|
||||
return;
|
||||
|
||||
const ushort port = 7979;
|
||||
var cfg = state.WorldUnmanaged.IsServer()
|
||||
? new ConnectionConfig { Mode = ConnectionMode.Host, Address = "127.0.0.1", Port = port, Requested = true }
|
||||
: new ConnectionConfig { Mode = ConnectionMode.Join, Address = "127.0.0.1", Port = port, Requested = true };
|
||||
|
||||
var e = state.EntityManager.CreateEntity();
|
||||
state.EntityManager.AddComponentData(e, cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 642fc5c4d71654becba10814a2d08e92
|
||||
Reference in New Issue
Block a user