forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRpcLoadLevel.cs
More file actions
69 lines (63 loc) · 2.52 KB
/
Copy pathRpcLoadLevel.cs
File metadata and controls
69 lines (63 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Unity.Burst;
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.NetCode;
using Unity.Entities;
using UnityEngine.Assertions;
public struct LevelLoadRequest : IRpcCommand
{
public LevelComponent levelData;
}
[BurstCompile]
public struct RpcLevelLoaded : IComponentData, IRpcCommandSerializer<RpcLevelLoaded>
{
public void Serialize(ref DataStreamWriter writer, in RpcSerializerState state, in RpcLevelLoaded data)
{
}
public void Deserialize(ref DataStreamReader reader, in RpcDeserializerState state, ref RpcLevelLoaded data)
{
}
[BurstCompile(DisableDirectCall = true)]
[AOT.MonoPInvokeCallback(typeof(RpcExecutor.ExecuteDelegate))]
private static void InvokeExecute(ref RpcExecutor.Parameters parameters)
{
var rpcData = default(RpcLevelLoaded);
rpcData.Deserialize(ref parameters.Reader, parameters.DeserializerState, ref rpcData);
parameters.CommandBuffer.AddComponent(parameters.JobIndex, parameters.Connection, new PlayerStateComponentData());
parameters.CommandBuffer.AddComponent(parameters.JobIndex, parameters.Connection, default(NetworkStreamInGame));
parameters.CommandBuffer.AddComponent(parameters.JobIndex, parameters.Connection, default(GhostConnectionPosition));
}
static readonly PortableFunctionPointer<RpcExecutor.ExecuteDelegate> InvokeExecuteFunctionPointer =
new PortableFunctionPointer<RpcExecutor.ExecuteDelegate>(InvokeExecute);
public PortableFunctionPointer<RpcExecutor.ExecuteDelegate> CompileExecute()
{
return InvokeExecuteFunctionPointer;
}
}
[UpdateInGroup(typeof(RpcCommandRequestSystemGroup))]
[CreateAfter(typeof(RpcSystem))]
[BurstCompile]
partial struct LevelLoadedRpcCommandRequestSystem : ISystem
{
RpcCommandRequest<RpcLevelLoaded, RpcLevelLoaded> m_Request;
[BurstCompile]
struct SendRpc : IJobChunk
{
public RpcCommandRequest<RpcLevelLoaded, RpcLevelLoaded>.SendRpcData data;
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
{
Assert.IsFalse(useEnabledMask);
data.Execute(chunk, unfilteredChunkIndex);
}
}
public void OnCreate(ref SystemState state)
{
m_Request.OnCreate(ref state);
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var sendJob = new SendRpc{data = m_Request.InitJobData(ref state)};
state.Dependency = sendJob.Schedule(m_Request.Query, state.Dependency);
}
}