Esempio n. 1
0
 private bool EvaluateEntity(
     RailEntity entity,
     int ticksSinceSend,
     out float priority)
 {
     return(this.Evaluator.Evaluate(entity, ticksSinceSend, out priority));
 }
Esempio n. 2
0
        /// <summary>
        /// Remove an entity from being controlled by this peer.
        /// </summary>
        public virtual void RevokeControl(RailEntity entity)
        {
            RailDebug.Assert(entity.Controller == this);
            this.controlledEntities.Remove(entity);

            entity.AssignController(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an entity of a given type and adds it to the world.
        /// </summary>
        public T AddNewEntity <T>() where T : RailEntity
        {
            T entity = RailEntity.Create <T>();

            entity.AssignId(this.nextEntityId);
            this.nextEntityId = this.nextEntityId.GetNext();
            this.Room.AddEntity(entity);
            return((T)entity);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds an entity to be controlled by this peer.
        /// </summary>
        public virtual void GrantControl(RailEntity entity)
        {
            if (entity.Controller == this)
            {
                return;
            }

            RailDebug.Assert(entity.Controller == null);
            this.controlledEntities.Add(entity);

            entity.AssignController(this);
        }
Esempio n. 5
0
        public static T Create <T>(RailEntity entity)
            where T : RailEvent
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            T evnt = RailEvent.Create <T>();

            evnt.EntityId = entity.Id;
            return(evnt);
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        /// <summary>
        /// Removes an entity from the world and destroys it.
        /// </summary>
        public void DestroyEntity(RailEntity entity)
        {
            if (entity.Controller != null)
            {
                IRailControllerServer serverController =
                    (IRailControllerServer)entity.Controller;
                serverController.RevokeControl(entity);
            }

            if (entity.IsRemoving == false)
            {
                entity.MarkForRemove();
                this.destroyedEntities.Add(entity.Id, entity);
            }
        }
Esempio n. 8
0
        private void UpdateControlStatus(RailEntity entity, RailStateDelta delta)
        {
            // Can't infer anything if the delta is an empty frozen update
            if (delta.IsFrozen)
            {
                return;
            }

            if (delta.HasControllerData)
            {
                if (entity.Controller == null)
                {
                    this.serverPeer.GrantControl(entity);
                }
            }
            else
            {
                if (entity.Controller != null)
                {
                    this.serverPeer.RevokeControl(entity);
                }
            }
        }
Esempio n. 9
0
        internal void OnEventReceived(RailEvent evnt, RailPeer sender)
        {
            if (evnt.EntityId.IsValid)
            {
                RailEntity entity = null;
                this.Room.TryGet(evnt.EntityId, out entity);

#if SERVER
                // Entity events can only be executed on controlled entities
                bool safeToExecute = (entity != null) && (entity.Controller == sender);
#elif CLIENT
                bool safeToExecute = (entity != null);
#endif

                if (safeToExecute)
                {
                    evnt.Invoke(this.room, sender, entity);
                }
            }
            else
            {
                evnt.Invoke(this.room, sender);
            }
        }
Esempio n. 10
0
 protected internal virtual void Invoke(RailRoom room, IRailController sender, RailEntity entity)
 {
 }
Esempio n. 11
0
 internal void AddEntity(RailEntity entity)
 {
     this.entities.Add(entity.Id, entity);
     entity.Room = this;
 }
Esempio n. 12
0
        private List <EntityId> toRemove; // Pre-allocated removal list

        public bool TryGet(EntityId id, out RailEntity value)
        {
            return(this.entities.TryGetValue(id, out value));
        }