public void OnActivate(MatchStateMachine matchStateMachine) { this.matchStateMachine = matchStateMachine; this.matchStateMachine.MatchInputProvider.Reset(); // this is done to change the list we add new messages to while we process a list // so one list will always be the one receiving messages, while the other will be processed in that frame // we switch to the other list at the beginning of the frame // This also avoids having to do list copy etc. which can lead to memory fragmentation unitStateMessageBuffer[0] = new List <UnitStateMessage>(); unitStateMessageBuffer[1] = new List <UnitStateMessage>(); PCMBuffer[0] = new List <PositionConfirmationMessage>(); PCMBuffer[1] = new List <PositionConfirmationMessage>(); unitAbilityMessageBuffer[0] = new List <UnitAbilityActivationMessage>(); unitAbilityMessageBuffer[1] = new List <UnitAbilityActivationMessage>(); unitSpawnMessageBuffer[0] = new List <UnitSpawnMessage>(); unitSpawnMessageBuffer[1] = new List <UnitSpawnMessage>(); messageReceiveDisposable = this.matchStateMachine.UDPClient.OnMessageReceive .Subscribe(OnMessageReceived); matchSimulation = new MatchSimulation(matchStateMachine.LocalPlayerId, matchStateMachine.MatchStartTimestamp, matchStateMachine.MatchInputProvider, matchStateMachine.MatchEventProvider, matchStateMachine.UDPClient, matchStateMachine.NetworkTimeService); }
public void OnActivate(MatchStateMachine matchStateMachine) { this.matchStateMachine = matchStateMachine; messageReceiveDisposable = this.matchStateMachine.UDPClient.OnMessageReceive .Where(message => message[0] == MessageId.MATCH_START) .Subscribe(OnMessageReceived); }
public void OnActivate(MatchStateMachine matchStateMachine) { matchStateMachine.NetworkTimeService.Synch(matchStateMachine.UDPClient, () => { matchStateMachine.AckedMessageHelper.SendAckedMessage(new TimeSyncDoneMessage(), MessageId.TIME_SYNC_DONE_ACK, ackMessage => { DIContainer.Logger.Debug("Time synch done, switching to WaitForStartMatchState"); TimeSyncDoneAckMessage receivedMessage = new TimeSyncDoneAckMessage(ackMessage); matchStateMachine.LocalPlayerId = receivedMessage.PlayerId; matchStateMachine.StartRoundTripTimeService(); matchStateMachine.ChangeMatchState(new WaitForStartMatchState()); }); }); }
public void OnActivate(MatchStateMachine matchStateMachine) { this.matchStateMachine = matchStateMachine; matchEndAckMessageToSend = new MatchEndAckMessage(matchStateMachine.LocalPlayerId).GetBytes(); }