Exemple #1
0
        public void re_modify(Sequence sequence, MotionState state)
        {
            uint numAnims = 0;

            while (state.Modifiers.Count > 0)
            {
                var modifier = state.Modifiers.First();
                state.remove_modifier(modifier);
                GetObjectSequence(modifier.ID, state, sequence, modifier.SpeedMod, ref numAnims, false);
            }
        }
Exemple #2
0
        public void initialize_state(Sequence sequence)
        {
            uint numAnims = 0;

            State = new MotionState();
            if (Table != null)
            {
                Table.SetDefaultState(State, sequence, ref numAnims);
            }

            add_to_queue(0x41000003, numAnims, sequence);   // hardcoded motion?
        }
Exemple #3
0
        public bool is_allowed(uint motion, MotionData motionData, MotionState state)
        {
            if (motionData == null)
            {
                return(false);
            }

            if ((motionData.Bitfield & 2) == 0 || motion == state.Substate)
            {
                return(true);
            }

            uint style = 0;

            StyleDefaults.TryGetValue(state.Style, out style);
            return(style == state.Substate);
        }
Exemple #4
0
        public MotionState(MotionState state)
        {
            Style       = state.Style;
            Substate    = state.Substate;
            SubstateMod = state.SubstateMod;

            Modifiers = new LinkedList <Motion>();
            foreach (var modifier in state.Modifiers)
            {
                Modifiers.AddLast(modifier);
            }

            Actions = new LinkedList <Motion>();
            foreach (var action in state.Actions)
            {
                Actions.AddLast(action);
            }
        }
Exemple #5
0
        public bool StopSequenceMotion(uint motion, float speed, MotionState currState, Sequence sequence, ref uint numAnims)
        {
            numAnims = 0;
            if ((motion & (uint)CommandMask.SubState) != 0 && currState.Substate == motion)
            {
                uint style = 0;
                StyleDefaults.TryGetValue(currState.Style, out style);
                GetObjectSequence(style, currState, sequence, 1.0f, ref numAnims, true);
                return(true);
            }
            if ((motion & (uint)CommandMask.Modifier) == 0)
            {
                return(false);
            }

            var modifier = currState.Modifiers.First;
            LinkedListNode <Motion> prevMod = null;

            while (modifier != null)
            {
                if (modifier.Value.ID == motion)
                {
                    var key = (modifier.Value.ID << 16) | (motion & 0xFFFFFF);

                    Modifiers.TryGetValue(key, out var motionData);
                    if (motionData == null)
                    {
                        Modifiers.TryGetValue(motion & 0xFFFFFF, out motionData);
                    }
                    if (motionData == null)
                    {
                        return(false);
                    }

                    subtract_motion(sequence, motionData, modifier.Value.SpeedMod);
                    currState.remove_modifier(modifier);
                    return(true);
                }
                prevMod  = modifier;
                modifier = modifier.Next;
            }
            return(false);
        }
Exemple #6
0
        public void re_modify(Sequence sequence, MotionState pstate)
        {
            if (pstate.Modifiers.First == null)
            {
                return;
            }

            var state = new MotionState(pstate);

            while (state.Modifiers.First != null)
            {
                var speedMod = pstate.Modifiers.First.Value.SpeedMod;
                var motion   = pstate.Modifiers.First.Value.ID;

                pstate.remove_modifier(pstate.Modifiers.First); // second param null?
                state.remove_modifier(state.Modifiers.First);

                uint numAnims = 0;
                GetObjectSequence(motion, pstate, sequence, speedMod, ref numAnims, false);
            }
        }
Exemple #7
0
        public bool StopSequenceMotion(uint motion, float speed, MotionState currState, Sequence sequence, ref uint numAnims)
        {
            numAnims = 0;
            if ((motion & 0x40000000) != 0 && currState.Substate == motion)
            {
                uint style = 0;
                StyleDefaults.TryGetValue(currState.Style, out style);
                GetObjectSequence(style, currState, sequence, 1.0f, ref numAnims, true);
                return(true);
            }
            if ((motion & 0x20000000) == 0)
            {
                return(false);
            }

            Motion lastMod = null;

            foreach (var modifier in currState.Modifiers)
            {
                if (modifier.ID == motion)
                {
                    var        key        = (modifier.ID << 16) | (motion & 0xFFFFFF);
                    MotionData motionData = null;
                    if (!Modifiers.TryGetValue(motion & 0xFFFFFF, out motionData))
                    {
                        return(false);
                    }

                    subtract_motion(sequence, motionData, modifier.SpeedMod);
                    currState.remove_modifier(modifier);
                    return(true);
                }
                lastMod = modifier;
            }
            return(false);
        }
Exemple #8
0
 public void Init()
 {
     State             = new MotionState();
     PendingAnimations = new LinkedList <AnimNode>();
 }
Exemple #9
0
        public bool GetObjectSequence(uint motion, MotionState currState, Sequence sequence, float speedMod, ref uint numAnims, bool stopModifiers)
        {
            numAnims = 0;
            if (currState.Style == 0 || currState.Substate == 0)
            {
                return(false);
            }

            MotionData motionData  = null;
            MotionData motionData_ = null;
            MotionData cycles      = null;
            uint       substate    = 0;

            StyleDefaults.TryGetValue(currState.Style, out substate);

            if (motion == substate && !stopModifiers && (currState.Substate & (uint)CommandMask.Modifier) != 0)
            {
                return(true);
            }

            if ((motion & (uint)CommandMask.Style) != 0)
            {
                if (currState.Style == motion)
                {
                    return(true);
                }

                if (substate != currState.Substate)
                {
                    motionData = get_link(currState.Style, currState.Substate, currState.SubstateMod, substate, speedMod);
                }

                if (substate != 0)
                {
                    Cycles.TryGetValue((motion << 16) | (substate & 0xFFFFFF), out cycles);
                    if (cycles != null)
                    {
                        if ((cycles.Bitfield & 1) != 0)
                        {
                            currState.clear_modifiers();
                        }

                        var link = get_link(currState.Style, substate, currState.SubstateMod, motion, speedMod);
                        if (link == null && currState.Style != motion)
                        {
                            link = get_link(currState.Style, substate, 1.0f, DefaultStyle, 1.0f);

                            uint defaultStyle = 0;
                            StyleDefaults.TryGetValue(DefaultStyle, out defaultStyle);
                            motionData_ = get_link(DefaultStyle, defaultStyle, 1.0f, motion, 1.0f);
                        }
                        sequence.clear_physics();
                        sequence.remove_cyclic_anims();

                        add_motion(sequence, motionData, speedMod);
                        add_motion(sequence, link, speedMod);
                        add_motion(sequence, motionData_, speedMod);
                        add_motion(sequence, cycles, speedMod);

                        currState.Substate    = substate;
                        currState.Style       = motion;
                        currState.SubstateMod = speedMod;

                        re_modify(sequence, currState);

                        numAnims = (uint)((motionData != null ? motionData.Anims.Count : 0) + (link != null ? link.Anims.Count : 0) +
                                          (motionData_ != null ? motionData_.Anims.Count : 0) + (cycles != null ? cycles.Anims.Count : 0) - 1);

                        return(true);
                    }
                }
            }
            if ((motion & (uint)CommandMask.SubState) != 0)
            {
                var motionID = motion & 0xFFFFFF;

                Cycles.TryGetValue(currState.Style << 16 | motionID, out motionData);
                if (motionData == null)
                {
                    Cycles.TryGetValue(DefaultStyle << 16 | motionID, out motionData);
                }
                if (motionData != null)
                {
                    if (is_allowed(motion, motionData, currState))
                    {
                        if (motion == currState.Substate && sequence.HasAnims() && Math.Sign(speedMod) == Math.Sign(currState.SubstateMod))
                        {
                            change_cycle_speed(sequence, motionData, currState.SubstateMod, speedMod);
                            subtract_motion(sequence, motionData, currState.SubstateMod);
                            combine_motion(sequence, motionData, speedMod);
                            currState.SubstateMod = speedMod;
                            return(true);
                        }

                        if ((motionData.Bitfield & 1) != 0)
                        {
                            currState.clear_modifiers();
                        }

                        var link = get_link(currState.Style, currState.Substate, currState.SubstateMod, motion, speedMod);    // verify
                        if (link == null || Math.Sign(speedMod) != Math.Sign(currState.SubstateMod))
                        {
                            uint defaultMotion = 0;
                            StyleDefaults.TryGetValue(currState.Style, out defaultMotion);
                            link        = get_link(currState.Style, currState.Substate, currState.SubstateMod, defaultMotion, 1.0f);
                            motionData_ = get_link(currState.Style, defaultMotion, 1.0f, motion, speedMod);
                        }
                        sequence.clear_physics();
                        sequence.remove_cyclic_anims();

                        if (motionData_ != null)
                        {
                            add_motion(sequence, link, currState.SubstateMod);
                            add_motion(sequence, motionData_, speedMod);
                        }
                        else
                        {
                            var newSpeedMod = speedMod;
                            if (currState.SubstateMod < 0.0f && speedMod > 0.0f)
                            {
                                newSpeedMod *= -1.0f;
                            }
                            add_motion(sequence, link, newSpeedMod);
                        }

                        add_motion(sequence, motionData, speedMod);

                        if (currState.Substate != motion && (currState.Substate & (uint)CommandMask.Modifier) != 0)
                        {
                            uint defaultMotion = 0;
                            StyleDefaults.TryGetValue(currState.Style, out defaultMotion);
                            if (defaultMotion != motion)
                            {
                                currState.add_modifier_no_check(currState.Substate, currState.SubstateMod);
                            }
                        }

                        currState.SubstateMod = speedMod;
                        currState.Substate    = motion;
                        re_modify(sequence, currState);

                        numAnims = (uint)((motionData == null ? 0 : motionData.Anims.Count) + (link == null ? 0 : link.Anims.Count) +
                                          (motionData_ == null ? 0 : motionData_.Anims.Count) - 1);

                        return(true);
                    }
                }
            }
            if ((motion & (uint)CommandMask.Action) != 0)
            {
                var cycleKey = (currState.Style << 16) | (currState.Substate & 0xFFFFFF);
                Cycles.TryGetValue(cycleKey, out motionData);
                if (motionData != null)
                {
                    var link = get_link(currState.Style, currState.Substate, currState.SubstateMod, motion, speedMod);
                    if (link != null)
                    {
                        currState.add_action(motion, speedMod);
                        sequence.clear_physics();
                        sequence.remove_cyclic_anims();

                        add_motion(sequence, link, speedMod);
                        add_motion(sequence, motionData, currState.SubstateMod);
                        re_modify(sequence, currState);

                        numAnims = (uint)link.Anims.Count;
                        return(true);
                    }
                    else
                    {
                        StyleDefaults.TryGetValue(currState.Style, out substate);
                        motionData = get_link(currState.Style, currState.Substate, currState.SubstateMod, substate, 1.0f);
                        if (motionData != null)
                        {
                            link = get_link(currState.Style, substate, 1.0f, motion, speedMod);
                            if (link != null && Cycles.TryGetValue(cycleKey, out cycles))
                            {
                                motionData_ = get_link(currState.Style, substate, 1.0f, currState.Substate, currState.SubstateMod);
                                currState.add_action(motion, speedMod);
                                sequence.clear_physics();
                                sequence.remove_cyclic_anims();
                                add_motion(sequence, motionData, 1.0f);
                                add_motion(sequence, link, speedMod);
                                add_motion(sequence, motionData_, 1.0f);
                                add_motion(sequence, cycles, currState.SubstateMod);
                                re_modify(sequence, currState);
                                numAnims = (uint)(motionData.Anims.Count + link.Anims.Count + (motionData_ == null ? 0 : motionData.Anims.Count));
                                return(true);
                            }
                        }
                    }
                }
            }
            if ((motion & (uint)CommandMask.Modifier) != 0)
            {
                var styleKey = currState.Style << 16;
                Cycles.TryGetValue(styleKey | (currState.Substate & 0xFFFFFF), out cycles);
                if (cycles != null && (cycles.Bitfield & 1) == 0)
                {
                    Modifiers.TryGetValue(styleKey | motion, out motionData);
                    if (motionData == null)
                    {
                        Modifiers.TryGetValue(motion & 0xFFFFFF, out motionData);
                    }
                    if (motionData != null)
                    {
                        if (!currState.add_modifier(motion, speedMod))
                        {
                            StopSequenceMotion(motion, 1.0f, currState, sequence, ref numAnims);
                            if (!currState.add_modifier(motion, speedMod))
                            {
                                return(false);
                            }
                        }
                        combine_motion(sequence, motionData, speedMod);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #10
0
 public bool DoObjectMotion(uint motion, MotionState currState, Sequence sequence, float speedMod, ref uint numAnims)
 {
     return(GetObjectSequence(motion, currState, sequence, speedMod, ref numAnims, false));
 }
Exemple #11
0
 public bool StopObjectMotion(uint motion, float speed, MotionState currState, Sequence sequence, ref uint numAnims)
 {
     return(StopSequenceMotion(motion, speed, currState, sequence, ref numAnims));
 }