Esempio n. 1
0
        public void advance_to_next_animation(float timeElapsed, AnimSequenceNode currAnim, double frameNum, AFrame frame)
        {
            var firstFrame  = currAnim.Framerate >= 0.0f;
            var secondFrame = currAnim.Framerate < 0.0f;

            if (timeElapsed >= 0.0)
            {
                firstFrame  = currAnim.Framerate < 0.0f;
                secondFrame = currAnim.Framerate > 0.0f;
            }
            advance_to_next_animation_inner(timeElapsed, currAnim, frameNum, frame, firstFrame);

            if (currAnim.GetNext() != null)
            {
                currAnim = currAnim.GetNext();
            }
            else
            {
                currAnim = FirstCyclic.Value;
            }

            // ref?
            frameNum = currAnim.get_starting_frame();

            advance_to_next_animation_inner(timeElapsed, currAnim, frameNum, frame, secondFrame);
        }
Esempio n. 2
0
        public void advance_to_next_animation_inner(float timeElapsed, AnimSequenceNode currAnim, double frameNum, AFrame frame, bool checkFrame)
        {
            if (frame != null && checkFrame)
            {
                if (currAnim.Anim.PosFrames.Count > 0)
                {
                    frame.Subtract(currAnim.get_pos_frame((int)Math.Floor(frameNum)));
                }

                if (Math.Abs(currAnim.Framerate) > PhysicsGlobals.EPSILON)
                {
                    apply_physics(frame, 1.0f / currAnim.Framerate, timeElapsed);
                }
            }
        }
Esempio n. 3
0
        public void append_animation(AnimData animData)
        {
            var node = new AnimSequenceNode(animData);

            if (!node.has_anim())
            {
                return;
            }

            AnimList.AddLast(node);
            FirstCyclic = AnimList.Last;

            if (CurrAnim == null)
            {
                CurrAnim    = AnimList.First;
                FrameNumber = CurrAnim.Value.get_starting_frame();
            }
        }
Esempio n. 4
0
        public void update_internal(float timeElapsed, AnimSequenceNode currAnim, float frameNum, AFrame frame)
        {
            var framerate = currAnim.Framerate;
            var frametime = framerate * timeElapsed;

            var lastFrame = (int)Math.Floor(frameNum);

            // ref?
            frameNum += frametime;
            var frameTimeElapsed = 0.0f;
            var animDone         = false;

            if (frametime > 0.0f)
            {
                if (currAnim.get_high_frame() < Math.Floor(frameNum))
                {
                    var frameOffset = frameNum - currAnim.get_high_frame() - 1.0f;
                    if (frameOffset < 0.0f)
                    {
                        frameOffset = 0.0f;
                    }

                    if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                    {
                        frameTimeElapsed = frameOffset / framerate;
                    }

                    frameNum = currAnim.get_high_frame();
                    animDone = true;
                }
                while (Math.Floor(frameNum) > lastFrame)
                {
                    if (frame != null)
                    {
                        if (currAnim.Anim.PosFrames != null)
                        {
                            frame = AFrame.Combine(frame, currAnim.get_pos_frame(lastFrame));
                        }

                        if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                        {
                            apply_physics(frame, 1.0f / framerate, timeElapsed);
                        }
                    }

                    execute_hooks(currAnim.get_part_frame(lastFrame), AnimationHookDir.Forward);
                    lastFrame++;
                }
            }
            else if (frametime < 0.0f)
            {
                if (currAnim.get_low_frame() > Math.Floor(frameNum))
                {
                    var frameOffset = frameNum - currAnim.get_low_frame();
                    if (frameOffset > 0.0f)
                    {
                        frameOffset = 0.0f;
                    }

                    if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                    {
                        frameTimeElapsed = frameOffset / framerate;
                    }

                    frameNum = currAnim.get_low_frame();
                    animDone = true;
                }
                while (Math.Floor(frameNum) < lastFrame)
                {
                    if (frame != null)
                    {
                        if (currAnim.Anim.PosFrames != null)
                        {
                            frame = AFrame.Combine(frame, currAnim.get_pos_frame(lastFrame));
                        }

                        if (Math.Abs(framerate) > PhysicsGlobals.EPSILON)
                        {
                            apply_physics(frame, 1.0f / framerate, timeElapsed);
                        }
                    }

                    execute_hooks(currAnim.get_part_frame(lastFrame), AnimationHookDir.Backward);
                    lastFrame--;
                }
            }
            else
            {
                if (frame != null && Math.Abs(timeElapsed) > PhysicsGlobals.EPSILON)
                {
                    apply_physics(frame, timeElapsed, timeElapsed);
                }
            }

            if (!animDone)
            {
                return;
            }

            if (HookObj != null)
            {
                var node = AnimList.First;
                if (!node.Equals(FirstCyclic))
                {
                    var animHook = new AnimationHook();
                    HookObj.add_anim_hook(animHook);
                }
            }
            advance_to_next_animation(timeElapsed, currAnim, frameNum, frame);
            timeElapsed = frameTimeElapsed;

            // loop to next anim
            update_internal(timeElapsed, currAnim, frameNum, frame);
        }