Exemplo n.º 1
0
Arquivo: Game.cs Projeto: andy-uq/Echo
        public double Update()
        {
            _tick++;
            var context = new TickContext(_tick);

            var index = 0;
            long remaining = TicksPerSlice;

            var tickTimer = Stopwatch.StartNew();
            while (remaining > 0 && _updateFunctions.Count > index)
            {
                var tickMethod = _updateFunctions[index];
                if (tickMethod.Due > _tick)
                {
                    break;
                }

                context.ElapsedTicks = _tick - tickMethod.Due;
                var nextTick = tickMethod.Tick(context);
                if (nextTick != 0)
                {
                    context.Requeue(tickMethod, nextTick);
                }

                remaining = TicksPerSlice - tickTimer.ElapsedTicks;
                index++;
            }

            _updateFunctions = _updateFunctions
                .Skip(index)
                .Concat(context.Registrations)
                .OrderBy(x => x.Due)
                .ToList();

            _idle.Enqueue(remaining/(double) TicksPerSlice);
            return remaining;
        }