예제 #1
0
        public void RegisterClockTimeObserver(IViewClockTimeObserver observer, float tickSize)
        {
            if (observer == null)
            {
                return;
            }
            float accumulator = 0f;
            bool  flag        = false;
            int   i           = 0;
            int   length      = this.clockTimeObservers.Length;

            while (i < length)
            {
                ViewClockTimeObserver viewClockTimeObserver = this.clockTimeObservers.Array[i];
                if (viewClockTimeObserver.Observer == observer)
                {
                    return;
                }
                if (!flag && viewClockTimeObserver.TickSize == tickSize)
                {
                    accumulator = viewClockTimeObserver.Accumulator;
                    flag        = true;
                }
                i++;
            }
            if (!flag)
            {
                accumulator = MathUtils.FloatMod(this.timeLast, tickSize);
            }
            this.clockTimeObservers.Add(new ViewClockTimeObserver(observer, tickSize, accumulator));
        }
예제 #2
0
        public void OnUpdate()
        {
            float num  = this.Now();
            float num2 = num - this.timeLast;

            this.timeLast = num;
            float num3 = num2;
            int   num4 = 0;

            while (num3 > 0f)
            {
                float num5 = (num3 <= this.timePerFrame) ? num3 : this.timePerFrame;
                this.physMiter.Init(this.physTimeObservers.Length);
                while (this.physMiter.Active())
                {
                    IViewPhysicsTimeObserver viewPhysicsTimeObserver = this.physTimeObservers.Array[this.physMiter.Index];
                    viewPhysicsTimeObserver.OnViewPhysicsTime(num5);
                    this.physMiter.Next();
                }
                this.physMiter.Reset();
                if (++num4 == 5)
                {
                    break;
                }
                num3 -= num5;
            }
            this.frameMiter.Init(this.frameTimeObservers.Length);
            while (this.frameMiter.Active())
            {
                IViewFrameTimeObserver viewFrameTimeObserver = this.frameTimeObservers.Array[this.frameMiter.Index];
                viewFrameTimeObserver.OnViewFrameTime(num2);
                this.frameMiter.Next();
            }
            this.frameMiter.Reset();
            this.clockMiter.Init(this.clockTimeObservers.Length);
            while (this.clockMiter.Active())
            {
                ViewClockTimeObserver viewClockTimeObserver = this.clockTimeObservers.Array[this.clockMiter.Index];
                float num6     = viewClockTimeObserver.Accumulator + num2;
                float tickSize = viewClockTimeObserver.TickSize;
                while (num6 >= tickSize)
                {
                    viewClockTimeObserver.Observer.OnViewClockTime(tickSize);
                    num6 -= tickSize;
                }
                viewClockTimeObserver.Accumulator = num6;
                this.clockMiter.Next();
            }
            this.clockMiter.Reset();
        }