Example #1
0
        public void AddEvent(HistoryEvent historyEvent)
        {
            if (this.HasEvent(historyEvent) == true)
            {
                using (NoStackTrace.All) {
                    UnityEngine.Debug.LogWarning($"Duplicate event: {historyEvent}. Skip.");
                }
                return;
            }

            ++this.statEventsAdded;

            this.ValidatePrewarm();

            if (historyEvent.tick <= Tick.Zero)
            {
                // Tick fix if it is zero
                historyEvent.tick = Tick.One;
            }

            var key = MathUtils.GetKey(historyEvent.order, historyEvent.localOrder);

            if (this.events.TryGetValue(historyEvent.tick, out var list) == true)
            {
                list.Add(key, historyEvent);
            }
            else
            {
                list = PoolSortedList <long, HistoryEvent> .Spawn(StatesHistoryModule <TState> .POOL_HISTORY_CAPACITY);

                list.Add(key, historyEvent);
                this.events.Add(historyEvent.tick, list);
            }

            this.oldestTick = (this.oldestTick == Tick.Invalid || historyEvent.tick < this.oldestTick ? (Tick)historyEvent.tick : this.oldestTick);

            ++this.beginAddEventsCount;

            /*
             * if (this.currentTick >= historyEvent.tick) {
             *
             *  if (this.beginAddEvents == false) {
             *
             *      this.Simulate(historyEvent.tick, this.currentTick);
             *
             *  } else {
             *
             *      if (this.beginAddEventsTick > historyEvent.tick) {
             *
             *          this.beginAddEventsTick = historyEvent.tick;
             *
             *      }
             *
             *  }
             *
             * }*/
        }
Example #2
0
        public void AddEvent(HistoryEvent historyEvent)
        {
            ++this.statEventsAdded;

            this.ValidatePrewarm();

            if (historyEvent.tick <= Tick.Zero)
            {
                // Tick fix if it is zero
                historyEvent.tick = Tick.One;
            }

            SortedList <long, HistoryEvent> list;

            if (this.events.TryGetValue(historyEvent.tick, out list) == true)
            {
                list.Add(MathUtils.GetKey(historyEvent.order, historyEvent.localOrder), historyEvent);
            }
            else
            {
                list = PoolSortedList <long, HistoryEvent> .Spawn(StatesHistoryModule <TState> .POOL_HISTORY_CAPACITY);

                list.Add(MathUtils.GetKey(historyEvent.order, historyEvent.localOrder), historyEvent);
                this.events.Add(historyEvent.tick, list);
            }

            this.oldestTick = (this.oldestTick == Tick.Invalid || historyEvent.tick < this.oldestTick ? (Tick)historyEvent.tick : this.oldestTick);

            /*if (this.currentTick >= historyEvent.tick) {
             *
             *  if (this.beginAddEvents == false) {
             *
             *      this.Simulate(historyEvent.tick, this.currentTick);
             *
             *  } else {
             *
             ++this.beginAddEventsCount;
             *      if (this.beginAddEventsTick > historyEvent.tick) {
             *
             *          this.beginAddEventsTick = historyEvent.tick;
             *
             *      }
             *
             *  }
             *
             * }*/
        }
Example #3
0
        public void AddEvent(HistoryEvent historyEvent)
        {
            ++this.statEventsAdded;

            this.ValidatePrewarm();

            if (historyEvent.tick <= 0UL)
            {
                // Tick fix if it is zero
                historyEvent.tick = 1UL;
            }

            SortedList <long, HistoryEvent> list;

            if (this.events.TryGetValue(historyEvent.tick, out list) == true)
            {
                list.Add(MathUtils.GetKey(historyEvent.order, historyEvent.localOrder), historyEvent);
            }
            else
            {
                list = PoolSortedList <long, HistoryEvent> .Spawn(2);

                list.Add(MathUtils.GetKey(historyEvent.order, historyEvent.localOrder), historyEvent);
                this.events.Add(historyEvent.tick, list);
            }

            if (this.currentTick >= historyEvent.tick)
            {
                var tick         = this.currentTick;
                var searchTick   = historyEvent.tick - 1;
                var historyState = this.GetStateBeforeTick(searchTick);
                //var cloneState = this.world.CreateState();
                //cloneState.Initialize(this.world, freeze: true, restore: false);
                if (historyState != null)
                {
                    // State found - simulate from this state to current tick
                    this.world.GetState().CopyFrom(historyState);
                    this.world.GetState().tick = tick;
                    //cloneState.CopyFrom(state);
                    //this.world.SetState(cloneState);
                    if (this.beginAddEvents == false)
                    {
                        this.world.SetPreviousTick(historyState.tick);
                        this.world.Simulate(tick);
                    }
                }
                else
                {
                    // Previous state was not found - need to rewind from initial state
                    var resetState = this.world.GetResetState();
                    this.world.GetState().CopyFrom(resetState);
                    this.world.GetState().tick = tick;
                    //cloneState.CopyFrom(resetState);
                    //this.world.SetState(cloneState);
                    if (this.beginAddEvents == false)
                    {
                        this.world.SetPreviousTick(resetState.tick);
                        this.world.Simulate(tick);
                    }

                    //throw new StateNotFoundException("Tick: " + searchTick);
                }
            }
        }