private bool EvaluateEntity( RailEntity entity, int ticksSinceSend, out float priority) { return(this.Evaluator.Evaluate(entity, ticksSinceSend, out priority)); }
/// <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); }
/// <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); }
/// <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); }
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); }
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)); }
/// <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); } }
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); } } }
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); } }
protected internal virtual void Invoke(RailRoom room, IRailController sender, RailEntity entity) { }
internal void AddEntity(RailEntity entity) { this.entities.Add(entity.Id, entity); entity.Room = this; }
private List <EntityId> toRemove; // Pre-allocated removal list public bool TryGet(EntityId id, out RailEntity value) { return(this.entities.TryGetValue(id, out value)); }