Exemple #1
0
        private bool GetPriority(
            RailEntity entity,
            Tick current,
            out float priority)
        {
            RailViewEntry lastSent = this.lastSent.GetLatest(entity.Id);

            if (lastSent.IsValid)
            {
                return(this.EvaluateEntity(entity, current - lastSent.Tick, out priority));
            }
            return(this.EvaluateEntity(entity, int.MaxValue, out priority));
        }
Exemple #2
0
        /// <summary>
        /// Records an acked status from the peer for a given entity ID.
        /// </summary>
        internal void RecordUpdate(EntityId entityId, RailViewEntry entry)
        {
            RailViewEntry currentEntry;

            if (this.latestUpdates.TryGetValue(entityId, out currentEntry))
            {
                if (currentEntry.Tick > entry.Tick)
                {
                    return;
                }
            }

            this.latestUpdates[entityId] = entry;
        }
Exemple #3
0
 /// <summary>
 /// Produces deltas for all non-acked destroyed entities.
 /// </summary>
 private void ProduceDestroyed(
     IRailController target,
     IEnumerable <RailEntity> destroyedEntities)
 {
     foreach (RailEntity entity in destroyedEntities)
     {
         RailViewEntry latest = this.ackedByClient.GetLatest(entity.Id);
         if (latest.IsValid && (latest.Tick < entity.RemovedTick))
         {
             // Note: Because the removed tick is valid, this should force-create
             this.destroyedList.Add(entity.ProduceDelta(latest.Tick, target));
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Divides the active entities into those that are in scope and those
        /// out of scope. If an entity is out of scope and hasn't been acked as
        /// such by the client, we will add it to the outgoing frozen delta list.
        /// Otherwise, if an entity is in scope we will add it to the sorted
        /// active delta list.
        /// </summary>
        private void ProduceScoped(
            IRailController target,
            Tick serverTick,
            IEnumerable <RailEntity> activeEntities)
        {
            this.entryList.Clear();
            float priority;

            foreach (RailEntity entity in activeEntities)
            {
                // Controlled entities are always in scope with highest priority
                if (entity.Controller == target)
                {
                    this.entryList.Add(
                        new KeyValuePair <float, RailEntity>(float.MinValue, entity));
                }
                else if (this.GetPriority(entity, serverTick, out priority))
                {
                    this.entryList.Add(
                        new KeyValuePair <float, RailEntity>(priority, entity));
                }
                else
                {
                    // We only want to send a freeze state if we aren't already frozen
                    RailViewEntry latest = this.ackedByClient.GetLatest(entity.Id);
                    if (latest.IsFrozen == false)
                    {
                        this.frozenList.Add(
                            RailStateDelta.CreateFrozen(serverTick, entity.Id));
                    }
                }
            }

            this.entryList.Sort(RailScope.Comparer);
            foreach (KeyValuePair <float, RailEntity> entry in this.entryList)
            {
                RailViewEntry  latest = this.ackedByClient.GetLatest(entry.Value.Id);
                RailStateDelta delta  = entry.Value.ProduceDelta(latest.Tick, target);
                if (delta != null)
                {
                    this.activeList.Add(delta);
                }
            }
        }