Пример #1
0
        public void Init()
        {
            mCurrentGameTime = new GameTime();
            mContactCount    = eContactCount.Unknown;
            mMultiPoke_StartMaxSeparation = 0d;
            mMultiPoke_StartMaxSeparation = 0d;
            mStateMachine = new XStateMachine <eContactChange>(eContactChange.NoChange);

            txStateID start                = mStateMachine.CreateState(State_Start);
            txStateID no_contacts          = mStateMachine.CreateState(State_NoContacts);
            txStateID tracking_single_poke = mStateMachine.CreateState(State_SinglePoke);
            txStateID tracking_single_drag = mStateMachine.CreateState(State_SingleDrag);
            txStateID tracking_multi_poke  = mStateMachine.CreateState(State_MultiPoke);
            txStateID tracking_multi_drag  = mStateMachine.CreateState(State_MultiDrag);
            txStateID ignoring_contacts    = mStateMachine.CreateState(State_IgnoringContacts);
            txStateID tracking_4_contacts  = mStateMachine.CreateState(State_4Contacts);
            txStateID tracking_5_contacts  = mStateMachine.CreateState(State_5Contacts);

            mStateMachine.CreateTransition(no_contacts, tracking_single_poke, eContactChange.ZeroToOne, Transition_NoContacts_SinglePoke);
            mStateMachine.CreateTransition(no_contacts, tracking_multi_poke, eContactChange.ZeroToTwo, Transition_NoContacts_MultiPoke);
            mStateMachine.CreateTransition(no_contacts, ignoring_contacts, eContactChange.ZeroToMany, Transition_Trivial);
            mStateMachine.CreateTransition(no_contacts, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(no_contacts, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_single_poke, tracking_single_drag, eContactChange.StillToMoving, Transition_SinglePoke_SingleDrag);
            mStateMachine.CreateTransition(tracking_single_poke, no_contacts, eContactChange.OneToZero, Transition_SinglePoke_NoContacts);
            mStateMachine.CreateTransition(tracking_single_poke, tracking_multi_poke, eContactChange.OneToTwo, Transition_SinglePoke_MultiPoke);
            mStateMachine.CreateTransition(tracking_single_poke, ignoring_contacts, eContactChange.OneToMany, Transition_SinglePoke_IgnoringContacts);
            mStateMachine.CreateTransition(tracking_single_poke, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_poke, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_single_drag, tracking_multi_drag, eContactChange.SingleDragToMultiDrag, Transition_SingleDrag_MultiDrag);
            mStateMachine.CreateTransition(tracking_single_drag, no_contacts, eContactChange.OneToZero, Transition_SingleDrag_NoContacts);
            mStateMachine.CreateTransition(tracking_single_drag, ignoring_contacts, eContactChange.OneToMany, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_drag, ignoring_contacts, eContactChange.SingleDragToMultiDragTooSlow, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_drag, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_drag, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_multi_poke, no_contacts, eContactChange.TwoToZero, Transition_MultiPoke_NoContacts);
            mStateMachine.CreateTransition(tracking_multi_poke, tracking_multi_drag, eContactChange.StillToMoving, Transition_MultiPoke_MultiDrag);
            mStateMachine.CreateTransition(tracking_multi_poke, ignoring_contacts, eContactChange.TwoToOne, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_poke, ignoring_contacts, eContactChange.TwoToMany, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_poke, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_poke, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_multi_drag, no_contacts, eContactChange.TwoToZero, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, ignoring_contacts, eContactChange.TwoToOne, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, ignoring_contacts, eContactChange.TwoToMany, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(ignoring_contacts, no_contacts, eContactChange.OneToZero, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, no_contacts, eContactChange.TwoToZero, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, no_contacts, eContactChange.ManyToZero, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(start, no_contacts, eContactChange.NoInitialContacts, Transition_Trivial);
            mStateMachine.CreateTransition(start, ignoring_contacts, eContactChange.InitialContacts, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_4_contacts, no_contacts, eContactChange.FourToZero, Transition_4Contacts_Any);
            mStateMachine.CreateTransition(tracking_4_contacts, ignoring_contacts, eContactChange.FourToAnyPositive, Transition_4Contacts_Any);

            mStateMachine.CreateTransition(tracking_5_contacts, no_contacts, eContactChange.FiveToZero, Transition_5Contacts_Any);
            mStateMachine.CreateTransition(tracking_5_contacts, ignoring_contacts, eContactChange.FiveToAnyPositive, Transition_5Contacts_Any);

            mStateMachine.SetStartingState(start);
        }
Пример #2
0
        public static void UnitTest()
        {
            GameTime t = new GameTime();

            sUnitTest = new XStateMachineUnitTest();
            var sm = new XStateMachine <eTriggers>(eTriggers.None);

            //sm.Log( "empty" );

            txStateID s1 = sm.CreateState(null);

            sm.SetStartingState(s1);
            sm.Update(eTriggers.None);

            sm.CreateTransition(s1, s1, eTriggers.Jump, sUnitTest.Cb1);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            sm.CreateTransition(s1, s1, eTriggers.Poke, sUnitTest.Cb2);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            //Console.WriteLine( "test removal" );
            sm.RemoveTransition(s1, eTriggers.Jump);

            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            // sm.RemoveTransition( s1, eTriggers.Jump );  // correctly asserts missing trigger
            sm.RemoveTransition(s1, eTriggers.Poke);

            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            sm.RemoveState(s1, txStateID.kNone);

            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Poke);

            // sm.SetStartingState( txStateID.kNone );  // correctly asserts illegal starting state

            // sm.CreateTransition( s1, txStateID.kNone, sUnitTest.Cb2, eTriggers.Jump );  // asserts correctly s1 not found
            // sm.CreateTransition( txStateID.kNone, txStateID.kNone, sUnitTest.Cb2, eTriggers.Jump );  // asserts correctly kNone not found

            //Console.WriteLine( "testing non trivial transitions and static callbacks" );

            txStateID s2 = sm.CreateState(Cb3);
            txStateID s3 = sm.CreateState(sUnitTest.Cb2State);

            sm.SetStartingState(s2);

            sm.CreateTransition(s2, s3, eTriggers.Jump, sUnitTest.Cb1);
            sm.CreateTransition(s3, s2, eTriggers.Poke, sUnitTest.Cb1);

            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Poke);
            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);
            sm.Update(eTriggers.None);

            //sm.Log();

            //Console.WriteLine( "testing non trivial remove state" );

            // sm.RemoveState( s2, s2 );  // correctly asserts can't name same state
            sm.RemoveState(s2, s3);

            //sm.Log();

            //Console.WriteLine( "testing non trivial remove state, not the current" );

            txStateID s4 = sm.CreateState(sUnitTest.Cb2State);

            sm.CreateTransition(s3, s4, eTriggers.Poke, sUnitTest.Cb1);
            sm.CreateTransition(s4, s3, eTriggers.Poke, sUnitTest.Cb1);

            //sm.Log();

            sm.RemoveState(s4, s3);

            //sm.Log();
        }