Exemplo n.º 1
0
        private void UpdateUnitStates(List <UnitStateMessage> receivedUnitStateMessagesSinceLastFrame)
        {
            // sort by oldest frame to newest frame
            receivedUnitStateMessagesSinceLastFrame.Sort((message1, message2) =>
            {
                return(message1.Frame == message2.Frame ? 0 : MatchSimulationUnit.IsFrameInFuture(message1.Frame, message2.Frame) ? 1 : -1);
            });

            for (int i = 0; i < receivedUnitStateMessagesSinceLastFrame.Count; i++)
            {
                UnitStateMessage unitStateMessage = receivedUnitStateMessagesSinceLastFrame[i];

                MatchSimulationUnit unitToUpdate;

                if (localPlayer != null && localPlayer.UnitId == unitStateMessage.UnitId)
                {
                    // only update the health here and ignore position and rotation for the local player,
                    // since that will be confirmed via the PositionConfirmationMessage
                    localPlayer.HealthPercent.Value = unitStateMessage.HealthPercent;
                    return;
                }
                else if (!simulationUnits.TryGetValue(unitStateMessage.UnitId, out unitToUpdate))
                {
                    return;
                }

                unitToUpdate.SetConfirmedState(unitStateMessage.XPosition, unitStateMessage.YPosition,
                                               unitStateMessage.Rotation, unitStateMessage.HealthPercent, unitStateMessage.Frame);

                //DIContainer.Logger.Debug("Received usm with frame: " + unitStateMessage.Frame);
            }
        }
Exemplo n.º 2
0
        private void UpdateUnitAbilityActivations(List <UnitAbilityActivationMessage> receivedUnitAbilityMessagesSinceLastFrame)
        {
            // sort by oldest frame to newest frame
            receivedUnitAbilityMessagesSinceLastFrame.Sort((message1, message2) =>
            {
                return(message1.StartFrame == message2.StartFrame ? 0 : MatchSimulationUnit.IsFrameInFuture(message1.StartFrame, message2.StartFrame) ? 1 : -1);
            });

            for (int i = 0; i < receivedUnitAbilityMessagesSinceLastFrame.Count; i++)
            {
                UnitAbilityActivationMessage unitAbilityActivationMessage = receivedUnitAbilityMessagesSinceLastFrame[i];

                MatchSimulationUnit unitToUpdate;
                if (simulationUnits.TryGetValue(unitAbilityActivationMessage.UnitId, out unitToUpdate))
                {
                    unitToUpdate.AbilityActivationSubject.OnNext(new AbilityActivation
                    {
                        Rotation        = UnitValueConverter.ToUnityRotation(unitAbilityActivationMessage.Rotation),
                        StartFrame      = unitAbilityActivationMessage.StartFrame,
                        ActivationFrame = unitAbilityActivationMessage.ActivationFrame
                    });
                }
            }
        }
Exemplo n.º 3
0
        private byte UpdateLocalPlayerState(List <PositionConfirmationMessage> receivedPositionConfirmationMessagesSinceLastFrame, byte currentTimebasedFrame)
        {
            if (localPlayer == null)
            {
                return(currentTimebasedFrame);
            }

            // so combined translation is max 1, so diagonal movement isn't faster.
            float[] cappedTranslations = MathHelper.GetCappedTranslations(inputProvider.XTranslation, inputProvider.YTranslation);

            byte inputFrame = (byte)MathHelper.Modulo(currentSimulationFrame + 1, byte.MaxValue);

            byte rotation = inputProvider.AbilityInputReceived ? inputProvider.GetSimulationAimingRotation() : inputProvider.GetSimulationRotation();

            localPlayer.SetLocalFrameInput((int)Math.Round(playerMaxFrameSpeed * cappedTranslations[0]),
                                           (int)Math.Round(playerMaxFrameSpeed * cappedTranslations[1]),
                                           rotation, inputFrame);

            byte frameToProcess = inputFrame;

            // this means we skipped a frame, we need to create buffer entries for all frames though
            while (frameToProcess != currentTimebasedFrame)
            {
                frameToProcess = (byte)MathHelper.Modulo(frameToProcess + 1, byte.MaxValue);
                localPlayer.SetLocalFrameInput(0, 0, rotation, frameToProcess);
            }

            // sort by oldest frame to newest frame
            receivedPositionConfirmationMessagesSinceLastFrame.Sort((message1, message2) =>
            {
                return(message1.Frame == message2.Frame ? 0 : MatchSimulationUnit.IsFrameInFuture(message1.Frame, message2.Frame) ? 1 : -1);
            });

            for (int i = 0; i < receivedPositionConfirmationMessagesSinceLastFrame.Count; i++)
            {
                PositionConfirmationMessage positionConfirmationMessage = receivedPositionConfirmationMessagesSinceLastFrame[i];

                if (positionConfirmationMessage.UnitId == localPlayer.UnitId)
                {
                    localPlayer.SetConfirmedState(positionConfirmationMessage.XPosition, positionConfirmationMessage.YPosition,
                                                  0, 0, positionConfirmationMessage.Frame);
                }
            }

            if (inputProvider.AbilityInputReceived)
            {
                byte activationFrame = (byte)MathHelper.Modulo(inputFrame + 10, byte.MaxValue);

                localPlayer.AbilityActivationSubject.OnNext(new AbilityActivation
                {
                    Rotation        = inputProvider.AimingRotation,
                    StartFrame      = inputFrame,
                    ActivationFrame = activationFrame
                });
            }
            else if (inputProvider.AimingInputReceived)
            {
                localPlayer.LocalAimingSubject.OnNext(inputProvider.AimingRotation);
            }

            return(inputFrame);
        }