Example #1
0
        public bool SetDefaultState(MotionState state, Sequence sequence, ref uint numAnims)
        {
            uint defaultSubstate = 0;

            if (!StyleDefaults.TryGetValue(DefaultStyle, out defaultSubstate))
            {
                return(false);
            }

            state.clear_modifiers();
            state.clear_actions();

            var cycle = (DefaultStyle << 16) | (defaultSubstate & 0xFFFFFF);

            MotionData motionData = null;

            if (!Cycles.TryGetValue(cycle, out motionData))
            {
                return(false);
            }

            numAnims          = (uint)motionData.Anims.Count - 1;
            state.Style       = DefaultStyle;
            state.Substate    = defaultSubstate;
            state.SubstateMod = 1.0f;

            sequence.clear_physics();
            sequence.clear_animations();

            add_motion(sequence, motionData, state.SubstateMod);
            return(true);
        }
Example #2
0
        public void subtract_motion(Sequence sequence, MotionData motionData, float speed)
        {
            if (motionData == null)
            {
                return;
            }

            sequence.subtract_physics(motionData.Velocity * speed, motionData.Omega * speed);
        }
Example #3
0
        public void combine_motion(Sequence sequence, MotionData motionData, float speed)
        {
            if (motionData == null)
            {
                return;
            }

            sequence.CombinePhysics(motionData.Velocity * speed, motionData.Omega * speed);
        }
Example #4
0
        public void change_cycle_speed(Sequence sequence, MotionData motionData, float substateMod, float speedMod)
        {
            if (Math.Abs(substateMod) > PhysicsGlobals.EPSILON)
            {
                sequence.multiply_cyclic_animation_framerate(speedMod / substateMod);
            }

            else if (Math.Abs(speedMod) < PhysicsGlobals.EPSILON)
            {
                sequence.multiply_cyclic_animation_framerate(0);
            }
        }
Example #5
0
        public MotionData get_link_inner(uint style, uint first, uint second, bool checkFirst = true)
        {
            Dictionary <uint, MotionData> link = null;
            MotionData motionData = null;

            Links.TryGetValue(style << 16, out link);
            if (link == null || checkFirst && (first & 0xFFFFF) == 0)
            {
                return(null);
            }

            link.TryGetValue(second, out motionData);
            return(motionData);
        }
Example #6
0
        public void add_motion(Sequence sequence, MotionData motionData, float speed)
        {
            if (motionData == null)
            {
                return;
            }

            sequence.SetVelocity(motionData.Velocity * speed);
            sequence.SetOmega(motionData.Omega * speed);

            for (var i = 0; i < motionData.Anims.Count; i++)
            {
                sequence.append_animation(new AnimData(motionData.Anims[i], speed));
            }
        }
Example #7
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);
        }
Example #8
0
        public MotionData get_link_inner(uint style, uint first, uint second, bool checkFirst = true)
        {
            Dictionary <uint, MotionData> link = null;
            MotionData motionData = null;

            var key = style << 16;

            if (checkFirst)
            {
                key |= first & 0xFFFFF;
            }
            Links.TryGetValue(key, out link);
            if (link == null)
            {
                return(null);
            }

            link.TryGetValue(second, out motionData);
            return(motionData);
        }
Example #9
0
        /// <summary>
        /// Returns the movement distance per second from an animation
        /// </summary>
        public static float GetAnimDist(MotionData motionData)
        {
            var offset      = Vector3.Zero;
            var totalFrames = 0;

            foreach (var anim in motionData.Anims)
            {
                var animation = DatManager.PortalDat.ReadFromDat <DatLoader.FileTypes.Animation>(anim.AnimId);
                foreach (var frame in animation.PosFrames)
                {
                    // orientation?
                    offset += frame.Origin;
                    totalFrames++;
                }
            }
            var dist = offset.Length();

            if (dist == 0.0f)
            {
                return(0.0f);
            }
            return(dist / totalFrames * motionData.Anims[0].Framerate);
        }
Example #10
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);
        }
Example #11
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);
        }