public void TestDelayState()
        {
            var machine = new StateMachine();
            var state1  = new CounterState();
            var state2  = new DelayState(3);
            var state3  = new CounterState();

            machine.AddTransition(DefaultState.Enter, state1);
            machine.AddTransition(state1, state2);
            machine.AddTransition(state2, state3);

            for (var i = 0; i < 2; i++)
            {
                machine.Update(1);
            }

            Assert.AreEqual(1, state1.Entered, double.Epsilon);
            Assert.IsFalse(state2.Completed);
            Assert.AreEqual(0, state3.Entered, double.Epsilon);

            machine.Update(1);

            Assert.AreEqual(1, state1.Entered, double.Epsilon);
            Assert.IsTrue(state2.Completed);
            Assert.AreEqual(1, state3.Entered, double.Epsilon);

            machine.Update(1);
            Assert.IsFalse(state2.Completed);
        }
Example #2
0
        private unsafe void ProcessDelayStereo(ref DelayState state, Span <IntPtr> outputBuffers, ReadOnlySpan <IntPtr> inputBuffers, uint sampleCount)
        {
            const ushort channelCount = 2;

            float delayFeedbackBaseGain  = state.DelayFeedbackBaseGain;
            float delayFeedbackCrossGain = state.DelayFeedbackCrossGain;
            float inGain  = FixedPointHelper.ToFloat(Parameter.InGain, FixedPointPrecision);
            float dryGain = FixedPointHelper.ToFloat(Parameter.DryGain, FixedPointPrecision);
            float outGain = FixedPointHelper.ToFloat(Parameter.OutGain, FixedPointPrecision);

            Matrix2x2 delayFeedback = new Matrix2x2(delayFeedbackBaseGain, delayFeedbackCrossGain,
                                                    delayFeedbackCrossGain, delayFeedbackBaseGain);

            for (int i = 0; i < sampleCount; i++)
            {
                Vector2 channelInput = new Vector2
                {
                    X = *((float *)inputBuffers[0] + i) * 64,
                    Y = *((float *)inputBuffers[1] + i) * 64,
                };

                Vector2 delayLineValues = new Vector2()
                {
                    X = state.DelayLines[0].Read(),
                    Y = state.DelayLines[1].Read(),
                };

                Vector2 temp = MatrixHelper.Transform(ref channelInput, ref delayFeedback) + channelInput * inGain;

                state.UpdateLowPassFilter(ref Unsafe.As <Vector2, float>(ref temp), channelCount);

                *((float *)outputBuffers[0] + i) = (channelInput.X * dryGain + delayLineValues.X * outGain) / 64;
                *((float *)outputBuffers[1] + i) = (channelInput.Y * dryGain + delayLineValues.Y * outGain) / 64;
            }
        }
Example #3
0
    public void InitializeCharacter(CharacterIdentity ci)
    {
        characterIdentity = ci;
        trans             = model.GetComponent <Transform>();
        rigid             = GetComponent <Rigid>();

        mState      = new IdleState();
        mDelayState = new IdleDelayState();

        gameSystemState = SystemOrder.NOTHING;
        inputOrder      = InputOrder.stand;
        attackOrder     = -1;
        walkDirection   = new Vector3(0, 0, 0);
        sightRotation   = new Vector3(0, 0, 0);

        posture     = new Posture(this);
        walkPhase   = 0;
        attackPhase = 0;

        holdingItemIndex = -1;

        if (characterIdentity.isPlayer)
        {
            GetComponent <Basic>().mManager.allManager.SetCamera(gameObject);
            posture.BecomeInvisible();

            targetCharacter = null;
        }
        else
        {
            targetCharacter = GetComponent <Basic>().mManager.allManager.player;
        }
    }
Example #4
0
        private unsafe void ProcessDelaySurround(ref DelayState state, Span <IntPtr> outputBuffers, ReadOnlySpan <IntPtr> inputBuffers, uint sampleCount)
        {
            const ushort channelCount = 6;

            float feedbackGain           = FixedPointHelper.ToFloat(Parameter.FeedbackGain, FixedPointPrecision);
            float delayFeedbackBaseGain  = state.DelayFeedbackBaseGain;
            float delayFeedbackCrossGain = state.DelayFeedbackCrossGain;
            float inGain  = FixedPointHelper.ToFloat(Parameter.InGain, FixedPointPrecision);
            float dryGain = FixedPointHelper.ToFloat(Parameter.DryGain, FixedPointPrecision);
            float outGain = FixedPointHelper.ToFloat(Parameter.OutGain, FixedPointPrecision);

            Matrix6x6 delayFeedback = new Matrix6x6(delayFeedbackBaseGain, 0.0f, 0.0f, 0.0f, delayFeedbackCrossGain, delayFeedbackCrossGain,
                                                    0.0f, delayFeedbackBaseGain, 0.0f, delayFeedbackCrossGain, delayFeedbackCrossGain, 0.0f,
                                                    delayFeedbackCrossGain, 0.0f, delayFeedbackBaseGain, delayFeedbackCrossGain, 0.0f, 0.0f,
                                                    0.0f, delayFeedbackCrossGain, delayFeedbackCrossGain, delayFeedbackBaseGain, 0.0f, 0.0f,
                                                    delayFeedbackCrossGain, delayFeedbackCrossGain, 0.0f, 0.0f, delayFeedbackBaseGain, 0.0f,
                                                    0.0f, 0.0f, 0.0f, 0.0f, 0.0f, feedbackGain);

            for (int i = 0; i < sampleCount; i++)
            {
                Vector6 channelInput = new Vector6
                {
                    X = *((float *)inputBuffers[0] + i) * 64,
                    Y = *((float *)inputBuffers[1] + i) * 64,
                    Z = *((float *)inputBuffers[2] + i) * 64,
                    W = *((float *)inputBuffers[3] + i) * 64,
                    V = *((float *)inputBuffers[4] + i) * 64,
                    U = *((float *)inputBuffers[5] + i) * 64
                };

                Vector6 delayLineValues = new Vector6
                {
                    X = state.DelayLines[0].Read(),
                    Y = state.DelayLines[1].Read(),
                    Z = state.DelayLines[2].Read(),
                    W = state.DelayLines[3].Read(),
                    V = state.DelayLines[4].Read(),
                    U = state.DelayLines[5].Read()
                };

                Vector6 temp = MatrixHelper.Transform(ref channelInput, ref delayFeedback) + channelInput * inGain;

                state.UpdateLowPassFilter(ref Unsafe.As <Vector6, float>(ref temp), channelCount);

                *((float *)outputBuffers[0] + i) = (channelInput.X * dryGain + delayLineValues.X * outGain) / 64;
                *((float *)outputBuffers[1] + i) = (channelInput.Y * dryGain + delayLineValues.Y * outGain) / 64;
                *((float *)outputBuffers[2] + i) = (channelInput.Z * dryGain + delayLineValues.Z * outGain) / 64;
                *((float *)outputBuffers[3] + i) = (channelInput.W * dryGain + delayLineValues.W * outGain) / 64;
                *((float *)outputBuffers[4] + i) = (channelInput.V * dryGain + delayLineValues.V * outGain) / 64;
                *((float *)outputBuffers[5] + i) = (channelInput.U * dryGain + delayLineValues.U * outGain) / 64;
            }
        }
Example #5
0
        private unsafe void ProcessDelay(CommandList context, ref DelayState state)
        {
            Debug.Assert(Parameter.IsChannelCountValid());

            if (IsEffectEnabled && Parameter.IsChannelCountValid())
            {
                Span <IntPtr> inputBuffers  = stackalloc IntPtr[Parameter.ChannelCount];
                Span <IntPtr> outputBuffers = stackalloc IntPtr[Parameter.ChannelCount];

                for (int i = 0; i < Parameter.ChannelCount; i++)
                {
                    inputBuffers[i]  = context.GetBufferPointer(InputBufferIndices[i]);
                    outputBuffers[i] = context.GetBufferPointer(OutputBufferIndices[i]);
                }

                switch (Parameter.ChannelCount)
                {
                case 1:
                    ProcessDelayMono(ref state, (float *)outputBuffers[0], (float *)inputBuffers[0], context.SampleCount);
                    break;

                case 2:
                    ProcessDelayStereo(ref state, outputBuffers, inputBuffers, context.SampleCount);
                    break;

                case 4:
                    ProcessDelayQuadraphonic(ref state, outputBuffers, inputBuffers, context.SampleCount);
                    break;

                case 6:
                    ProcessDelaySurround(ref state, outputBuffers, inputBuffers, context.SampleCount);
                    break;

                default:
                    throw new NotImplementedException(Parameter.ChannelCount.ToString());
                }
            }
            else
            {
                for (int i = 0; i < Parameter.ChannelCount; i++)
                {
                    if (InputBufferIndices[i] != OutputBufferIndices[i])
                    {
                        context.CopyBuffer(OutputBufferIndices[i], InputBufferIndices[i]);
                    }
                }
            }
        }
    void Awake()
    {
        m_hRigidbody = this.GetComponent<Rigidbody>();
        m_hCollider  = this.GetComponent<Collider>();
        m_hParticlesController = this.GetComponentInChildren<ParticlesController>();

        m_hDelay = new DelayState(this);
        FlyState hFly = new FlyState(this);
        m_hDelay.Next = hFly;

        m_hCurrent = m_hDelay;

        damageRates = new Dictionary<ArmorType, float>();
        damageRates.Add(ArmorType.Light, LightArmorDamageRate);
        damageRates.Add(ArmorType.Medium, MediumArmorDamageRate);
        damageRates.Add(ArmorType.Heavy, HeavyArmorDamageRate);
    }
Example #7
0
        private unsafe void ProcessDelayMono(ref DelayState state, float *outputBuffer, float *inputBuffer, uint sampleCount)
        {
            float feedbackGain = FixedPointHelper.ToFloat(Parameter.FeedbackGain, FixedPointPrecision);
            float inGain       = FixedPointHelper.ToFloat(Parameter.InGain, FixedPointPrecision);
            float dryGain      = FixedPointHelper.ToFloat(Parameter.DryGain, FixedPointPrecision);
            float outGain      = FixedPointHelper.ToFloat(Parameter.OutGain, FixedPointPrecision);

            for (int i = 0; i < sampleCount; i++)
            {
                float input          = inputBuffer[i] * 64;
                float delayLineValue = state.DelayLines[0].Read();

                float temp = input * inGain + delayLineValue * feedbackGain;

                state.UpdateLowPassFilter(ref temp, 1);

                outputBuffer[i] = (input * dryGain + delayLineValue * outGain) / 64;
            }
        }
Example #8
0
    void LateUpdate()
    {
        mDelayState.PreDoSomething(this, mDeltaTime);

        GetOrder();

        RotateSight(mDeltaTime);

        CharacterState tempState = mState.UpdataState(this, inputOrder);

        mState = tempState;
        mState.DoSomething(this, mDeltaTime);
        //dosomething for attack should always be put behind the CharacterState
        DelayState tempDelayState = mDelayState.UpdateState(this, attackOrder);

        mDelayState = tempDelayState;
        mDelayState.DoSomething(this, mDeltaTime);

        mDeltaTime = 0;
        frame++;
    }
Example #9
0
        private unsafe void ProcessDelaySurround(ref DelayState state, Span <IntPtr> outputBuffers, ReadOnlySpan <IntPtr> inputBuffers, uint sampleCount)
        {
            const ushort channelCount = 6;

            Span <float> channelInput    = stackalloc float[channelCount];
            Span <float> delayLineValues = stackalloc float[channelCount];
            Span <float> temp            = stackalloc float[channelCount];

            float delayFeedbackBaseGain  = state.DelayFeedbackBaseGain;
            float delayFeedbackCrossGain = state.DelayFeedbackCrossGain;
            float inGain  = FixedPointHelper.ToFloat(Parameter.InGain, FixedPointPrecision);
            float dryGain = FixedPointHelper.ToFloat(Parameter.DryGain, FixedPointPrecision);
            float outGain = FixedPointHelper.ToFloat(Parameter.OutGain, FixedPointPrecision);

            for (int i = 0; i < sampleCount; i++)
            {
                for (int j = 0; j < channelCount; j++)
                {
                    channelInput[j]    = *((float *)inputBuffers[j] + i) * 64;
                    delayLineValues[j] = state.DelayLines[j].Read();
                }

                temp[0] = channelInput[0] * inGain + (delayLineValues[2] + delayLineValues[4]) * delayFeedbackCrossGain + delayLineValues[0] * delayFeedbackBaseGain;
                temp[1] = channelInput[1] * inGain + (delayLineValues[4] + delayLineValues[3]) * delayFeedbackCrossGain + delayLineValues[1] * delayFeedbackBaseGain;
                temp[2] = channelInput[2] * inGain + (delayLineValues[3] + delayLineValues[0]) * delayFeedbackCrossGain + delayLineValues[2] * delayFeedbackBaseGain;
                temp[3] = channelInput[3] * inGain + (delayLineValues[1] + delayLineValues[2]) * delayFeedbackCrossGain + delayLineValues[3] * delayFeedbackBaseGain;
                temp[4] = channelInput[4] * inGain + (delayLineValues[0] + delayLineValues[1]) * delayFeedbackCrossGain + delayLineValues[4] * delayFeedbackBaseGain;
                temp[5] = channelInput[5] * inGain + delayLineValues[5] * delayFeedbackBaseGain;

                for (int j = 0; j < channelCount; j++)
                {
                    float lowPassResult = state.LowPassFeedbackGain * state.LowPassZ[j] + temp[j] * state.LowPassBaseGain;

                    state.LowPassZ[j] = lowPassResult;
                    state.DelayLines[j].Update(lowPassResult);

                    *((float *)outputBuffers[j] + i) = (channelInput[j] * dryGain + delayLineValues[j] * outGain) / 64;
                }
            }
        }
Example #10
0
    public override DelayState UpdateState(Character character, int attackOrder)
    {
        DelayState tempState = this;

        if (cdTime <= 0)
        {
            if (attackOrder == -2)
            {
                tempState = new UseItemState();
            }
            else if (AttackComponent.SkillExisted(character.gameObject, attackOrder))
            {
                tempState = new AttackState(character, attackOrder);
            }
            else
            {
                tempState = new IdleDelayState();
                character.ExitAttackPosture();
            }
        }

        return(tempState);
    }
Example #11
0
        internal static TweenOperation DelayTween(float seconds)
        {
            var state = new DelayState();

            return(TweenAction <DelayState> .Prepare(state, new TweenOptions(seconds)));
        }