Пример #1
0
        public void RegisterClockTimeObserver(ClockTimeObserver observer, float tickSize)
        {
            if (observer == null)
            {
                return;
            }
            float accumulator = 0.0f;
            bool  flag        = false;
            int   index       = 0;

            for (int count = this.clockTimeObservers.Count; index < count; ++index)
            {
                ViewClockTimeObserver clockTimeObserver = this.clockTimeObservers[index];
                if (clockTimeObserver.Observer == observer)
                {
                    return;
                }
                if (!flag && (double)clockTimeObserver.TickSize == (double)tickSize)
                {
                    accumulator = clockTimeObserver.Accumulator;
                    flag        = true;
                }
            }
            if (!flag)
            {
                accumulator = MathUtils.FloatMod(this.timeLast, tickSize);
            }
            this.clockTimeObservers.Add(new ViewClockTimeObserver(observer, tickSize, accumulator));
        }
Пример #2
0
        public void OnUpdate()
        {
            float num1 = this.Now();
            float dt1  = num1 - this.timeLast;

            this.timeLast = num1;
            float num2 = dt1;
            int   num3 = 0;

            while ((double)num2 > 0.0)
            {
                float dt2 = (double)num2 <= (double)this.timePerFrame ? num2 : this.timePerFrame;
                this.physMiter.Init((ICollection)this.physTimeObservers);
                while (this.physMiter.Active())
                {
                    this.physTimeObservers[this.physMiter.Index].OnViewPhysicsTime(dt2);
                    this.physMiter.Next();
                }
                this.physMiter.Reset();
                if (++num3 != MAX_PHYS_FRAMES_PER_VIEW_FRAME)
                {
                    num2 -= dt2;
                }
                else
                {
                    break;
                }
            }
            this.frameMiter.Init((ICollection)this.frameTimeObservers);
            while (this.frameMiter.Active())
            {
                this.frameTimeObservers[this.frameMiter.Index].OnViewFrameTime(dt1);
                this.frameMiter.Next();
            }
            this.frameMiter.Reset();
            this.clockMiter.Init((ICollection)this.clockTimeObservers);
            while (this.clockMiter.Active())
            {
                ViewClockTimeObserver clockTimeObserver = this.clockTimeObservers[this.clockMiter.Index];
                float num4     = clockTimeObserver.Accumulator + dt1;
                float tickSize = clockTimeObserver.TickSize;
                while ((double)num4 >= (double)tickSize)
                {
                    clockTimeObserver.Observer.OnViewClockTime(tickSize);
                    num4 -= tickSize;
                }
                clockTimeObserver.Accumulator = num4;
                this.clockMiter.Next();
            }
            this.clockMiter.Reset();
        }