void IModuleBase.OnConstruct() { this.localOrderIndex = 0; this.rpcId = 0; this.ping = 0d; this.registry = PoolDictionary <int, System.Reflection.MethodInfo> .Spawn(100); this.objectToKey = PoolDictionary <object, Key> .Spawn(100); this.keyToObjects = PoolDictionary <long, object> .Spawn(100); this.runLocalOnly = PoolHashSet <int> .Spawn(100); this.currentObjectRegistryId = 1000; this.statesHistoryModule = this.world.GetModule <StatesHistory.IStatesHistoryModule <TState> >(); this.statesHistoryModule.SetEventRunner(this); this.world.SetNetworkModule(this); this.RegisterRPC(NetworkModule <TState> .CANCEL_EVENT_RPC_ID, new System.Action <byte[]>(this.CancelEvent_RPC).Method); this.RegisterRPC(NetworkModule <TState> .PING_RPC_ID, new System.Action <double, bool>(this.Ping_RPC).Method); this.RegisterRPC(NetworkModule <TState> .SYNC_RPC_ID, new System.Action <Tick, int>(this.Sync_RPC).Method); this.RegisterObject(this, -1, -1); this.OnInitialize(); }
void ISystemBase.OnConstruct() { var network = this.world.GetModule <ME.ECS.Network.INetworkModuleBase>(); this.testEventCallId = network.RegisterRPC(new System.Action <Entity, Color, float>(this.MovePointEvent_RPC).Method); network.RegisterObject(this, 2); }
void IModuleBase.OnDeconstruct() { this.OnDeInitialize(); this.replayMode = default; this.asyncMode = default; this.localOrderIndex = default; this.rpcId = default; this.ping = default; this.pingTime = default; this.syncTime = default; this.syncedTick = default; this.syncHash = default; this.syncTickSent = default; this.revertingTo = default; this.isReverting = default; this.currentObjectRegistryId = default; this.world.SetNetworkModule(null); this.statesHistoryModule = null; this.UnRegisterObject(this, -1); this.currentObjectRegistryId = 1000; PoolHashSet <int> .Recycle(ref this.runLocalOnly); PoolDictionary <long, object> .Recycle(ref this.keyToObjects); PoolDictionary <object, Key> .Recycle(ref this.objectToKey); PoolDictionary <int, System.Reflection.MethodInfo> .Recycle(ref this.registry); }
public void RPC <T1>(object instance, RPCId rpcId, T1 p1) where T1 : struct { var arr = PoolArray <object> .Spawn(1); arr[0] = p1; this.CallRPC(instance, rpcId, true, arr); }
void ISystemBase.OnConstruct() { var network = this.world.GetModule <ME.ECS.Network.INetworkModuleBase>(); this.createUnitCallId = network.RegisterRPC(new System.Action <Color, int, ViewId, ViewId>(this.CreateUnit_RPC).Method); network.RegisterObject(this, 1); }
public void RPC <T1, T2>(object instance, RPCId rpcId, T1 p1, T2 p2) where T1 : struct where T2 : struct { var arr = PoolArray <object> .Spawn(2); arr[0] = p1; arr[1] = p2; this.CallRPC(instance, rpcId, true, arr); }
public System.Reflection.MethodInfo GetMethodInfo(RPCId rpcId) { System.Reflection.MethodInfo methodInfo; if (this.registry.TryGetValue(rpcId, out methodInfo) == true) { return(methodInfo); } return(null); }
public void RPC <T1, T2, T3, T4>(object instance, RPCId rpcId, T1 p1, T2 p2, T3 p3, T4 p4) where T1 : struct where T2 : struct where T3 : struct where T4 : struct { var arr = PoolArray <object> .Spawn(4); arr[0] = p1; arr[1] = p2; arr[2] = p3; arr[3] = p4; this.CallRPC(instance, rpcId, true, arr); }
public bool RegisterRPC(RPCId rpcId, System.Reflection.MethodInfo methodInfo) { if (this.registry.ContainsKey(rpcId) == false) { this.registry.Add(rpcId, methodInfo); return(true); } return(false); }
protected override void OnConstruct() { this.AddModule <KeyboardInputModule>(); this.AddSystem <MarkerToRPCSystem>(); var net = this.world.GetModule <NetworkModule>(); net.RegisterObject(this, 2); this.movePlayerRpcId = net.RegisterRPC(new System.Action <int, InputDir>(this.MovePlayer_RPC).Method); this.fireRpcId = net.RegisterRPC(new System.Action <int, InputFire>(this.Fire_RPC).Method); }
protected override void OnConstruct() { this.playerViewId = this.world.RegisterViewSource(this.playerView); var net = this.world.GetModule <NetworkModule>(); net.RegisterObject(this, 1); this.createPlayerRpcId = net.RegisterRPC(new System.Action <int>(this.CreatePlayer_RPC).Method); this.AddSystem <NetworkMessagesSystem>(); }
public InputAction(InputFeature feature, InputEventType inputEventType, ME.ECS.Network.INetworkModuleBase networkModule, System.Action <Entity, TMarker> rpc) { this.networkModule = networkModule; this.networkObject = feature; this.getEntity = null; this.rpcId = default; this.tag = default; this.inputEventType = inputEventType; this.tag = this.networkObject; this.rpcId = this.networkModule.RegisterRPC(rpc.Method); }
private void CallRPC(object instance, RPCId rpcId, bool storeInHistory, params object[] parameters) { Key key; if (this.objectToKey.TryGetValue(instance, out key) == true) { if (this.transporter.IsConnected() == false) { return; } var evt = new ME.ECS.StatesHistory.HistoryEvent(); evt.tick = this.world.GetStateTick() + Tick.One; // Call RPC on next tick evt.order = this.GetRPCOrder(); evt.localOrder = ++this.localOrderIndex; evt.parameters = parameters; evt.rpcId = rpcId; evt.objId = key.objId; evt.groupId = key.groupId; evt.storeInHistory = storeInHistory; var storedInHistory = false; if (storeInHistory == true && (this.GetNetworkType() & NetworkType.RunLocal) != 0) { this.statesHistoryModule.AddEvent(evt); storedInHistory = true; } if ((this.GetNetworkType() & NetworkType.SendToNet) != 0) { if (this.transporter != null && this.serializer != null) { this.transporter.Send(this.serializer.Serialize(evt)); } } if (storedInHistory == false && parameters != null) { // Return parameters into pool if we are not storing them locally PoolArray <object> .Recycle(ref parameters); } } else { throw new RegisterObjectMissingException(instance, rpcId); } }
private void CallRPC(object instance, RPCId rpcId, bool storeInHistory, object[] parameters) { if (this.world.HasStep(WorldStep.LogicTick) == true) { InStateException.ThrowWorldStateCheck(); } if (this.objectToKey.TryGetValue(instance, out var key) == true) { var evt = new ME.ECS.StatesHistory.HistoryEvent(); evt.tick = this.world.GetStateTick() + this.statesHistoryModule.GetEventForwardTick(); // Call RPC on next N tick evt.parameters = parameters; evt.rpcId = rpcId; evt.objId = key.objId; evt.groupId = key.groupId; // If event run only on local machine // we need to write data through all states and run this event immediately on each // then return current state back // so we don't need to store this event in history, we just need to rewrite reset data var runLocalOnly = this.runLocalOnly.Contains(rpcId); if (runLocalOnly == true) { { // Apply data to current state this.statesHistoryModule.RunEvent(evt); } var currentState = this.world.GetState(); var resetState = this.world.GetResetState(); this.world.SetStateDirect(resetState); { this.statesHistoryModule.RunEvent(evt); } foreach (var entry in this.statesHistoryModule.GetDataStates().GetEntries()) { if (entry.isEmpty == false) { this.world.SetStateDirect(entry.state); this.statesHistoryModule.RunEvent(evt); } } this.world.SetStateDirect(currentState); return; } // Set up other event data evt.order = this.GetRPCOrder(); evt.localOrder = ++this.localOrderIndex; evt.storeInHistory = storeInHistory; var storedInHistory = false; if (this.GetNetworkType() == NetworkType.RunLocal && storeInHistory == true) { this.statesHistoryModule.AddEvent(evt); storedInHistory = true; } if (storedInHistory == false && storeInHistory == true && (this.GetNetworkType() & NetworkType.RunLocal) != 0) { //var dEvt = this.serializer.Deserialize(this.serializer.Serialize(evt)); this.statesHistoryModule.AddEvent(evt); storedInHistory = true; } if (this.transporter != null && this.transporter.IsConnected() == true) { if (runLocalOnly == false && (this.GetNetworkType() & NetworkType.SendToNet) != 0) { if (this.transporter != null && this.serializer != null) { if (storeInHistory == false) { this.transporter.SendSystem(this.serializer.Serialize(evt)); } else { this.transporter.Send(this.serializer.Serialize(evt)); } } } } if (storedInHistory == false && parameters != null) { // Return parameters into pool if we are not storing them locally PoolArray <object> .Recycle(ref parameters); } } else { throw new RegisterObjectMissingException(instance, rpcId); } }
public bool UnRegisterRPC(RPCId rpcId) { return(this.registry.Remove(rpcId)); }
public RegisterObjectMissingException(object instance, RPCId rpcId) : base("[NetworkModule] Object " + instance + " could not send RPC with id " + rpcId + " because RegisterObject() call should run before this call.") { }
public void RPC(object instance, RPCId rpcId) { this.CallRPC(instance, rpcId, true, null); }
public void SystemRPC(object instance, RPCId rpcId, params object[] parameters) { this.CallRPC(instance, rpcId, false, parameters); }