using ProjectM.Simulation;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
namespace ProjectM.Client
{
///
/// Client-side connection handshake: for every connection that has been assigned a
/// but is not yet , mark it in-game and
/// fire a RPC so the server spawns this client's player ghost.
/// Adding NetworkStreamInGame is what gates snapshot/command flow on. Mirrors the netcode
/// "networked-cube" go-in-game sample.
///
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial struct GoInGameClientSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
var builder = new EntityQueryBuilder(Allocator.Temp)
.WithAll()
.WithNone();
state.RequireForUpdate(state.GetEntityQuery(builder));
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var ecb = new EntityCommandBuffer(Allocator.Temp);
foreach (var (_, connection) in
SystemAPI.Query>().WithNone().WithEntityAccess())
{
ecb.AddComponent(connection);
var request = ecb.CreateEntity();
ecb.AddComponent(request);
ecb.AddComponent(request, new SendRpcCommandRequest { TargetConnection = connection });
}
ecb.Playback(state.EntityManager);
}
}
}