public bool CheckFindAndRemove(EntityID id) { Container ctr; if (!fullMap.TryRemove(id, out ctr)) { return(false); } guidMap.ForceRemove(id.Guid); return(true); }
public Entity(EntityID id, Vec3 velocity, EntityLogic state #if STATE_ADV , EntityAppearanceCollection appearance = null #endif ) : this(id, velocity, state, Helper.SerializeToArray(state), #if STATE_ADV appearance, null, #endif null) { }
public Entity(EntityID id, Vec3 velocity, EntityLogic dstate, byte[] state #if STATE_ADV , EntityAppearanceCollection appearance = null #endif ) : this(id, velocity, dstate, state, #if STATE_ADV appearance, null, #endif null) { }
public T FindOrigin(EntityID id) { foreach (var c in bag) { if (c.Origin == id) { return(c); } } return(null); }
public bool Find(EntityID id, out Entity e) { Container rs; if (fullMap.TryGetValue(id, out rs)) { e = rs.entity; return(true); } e = new Entity(); return(false); }
public void ConflictFreeInsert(EntityID origin, Entity entity) { Container rs; if (guidMap.TryGetValue(entity.ID.Guid, out rs)) { rs.deferredUpdates.Add(new Tuple <EntityID, Entity>(origin, entity)); } else { deferredInserts.GetOrAdd(entity.ID.Guid, id => new ConcurrentBag <Entity>()).Add(entity); } }
public int FindContact(EntityID id) { if (Contacts == null) { return(-1); } for (int i = 0; i < Contacts.Length; i++) { if (Contacts[i].ID == id) { return(i); } } return(-1); }
public Entity(EntityID id, Vec3 velocity, EntityLogic dstate, byte[] state #if STATE_ADV , EntityAppearanceCollection appearance, EntityContact[] contacts #endif , EntityMessage[] messages) //: this() { //if (!Simulation.FullSimulationSpace.Contains(id.Position)) // throw new IntegrityViolation("New entity location is located outside simulation space: "+id+", "+Simulation.FullSimulationSpace); ID = id; Velocity = velocity; SerialLogicState = state ?? Helper.SerializeToArray(dstate); transientDeserializedLogic = dstate; #if STATE_ADV Appearances = appearance; Contacts = contacts; #endif InboundMessages = messages; }
public void FindAndRemove(EntityID id, Func <Entity, bool> verifyMatch) { Container ctr; if (!fullMap.TryRemove(id, out ctr)) { if (guidMap.ContainsKey(id.Guid)) { throw new ExecutionException(id, "Location mismatch"); } else { throw new ExecutionException(id, "ID not found for removal"); } } if (!verifyMatch(ctr.entity)) { fullMap.ForceAdd(id, ctr); throw new ExecutionException(id, "Verification failed"); } guidMap.ForceRemove(id.Guid); }
public Result CheckFindAndRemove(EntityID id, Func <Entity, bool> verifyMatch, out Vec3?outLocation) { outLocation = null; Container ctr; if (!fullMap.TryRemove(id, out ctr)) { if (guidMap.TryGetValue(id.Guid, out ctr)) { outLocation = ctr.entity.ID.Position; return(Result.IDNotFoundLocationMismatch); } return(Result.IDNotFound); } outLocation = ctr.entity.ID.Position; if (!verifyMatch(ctr.entity)) { fullMap.ForceAdd(id, ctr); return(Result.VerificationFailed); } guidMap.ForceRemove(id.Guid); return(Result.NoError); }
public MovementPriority(Entity current, EntityID presumedCurrent, Entity destination, EntityChange.ExecutionContext ctx, bool currentIsInconsistent, bool destIsInconsistent) { PresumedCurrent = presumedCurrent; Destination = destination; CurrentMatch = current.ID.Position == presumedCurrent.Position; Score = 1; if (CurrentMatch) { Score += 10; } if (destIsInconsistent) { Score *= 0.5f; } if (!CurrentMatch /*&& destIsInconsistent*/ && !currentIsInconsistent) { Score = -1; } }
public void Kill(EntityID entityID) { removals.Add(entityID); }
public bool Contains(EntityID id) { return(fullMap.ContainsKey(id)); }
public EntityChange.StateAdvertisement FindAdvertisementFor(EntityID id) { return(advertisements.FindOrigin(id)); }
public Actor(EntityID id) { Guid = id.Guid; Position = id.Position; IsEntity = true; }
public bool HasContact(EntityID id) { return(FindContact(id) != -1); }
public MessageKey(OrderedEntityMessage msg) : this() { orderID = msg.OrderID; senderID = new EntityID(msg.Message.Sender.Guid, msg.Message.Sender.Position); }
public ExecutionException(EntityID eID, string message, Exception nested = null) : base(message, nested) { EntityID = eID; }
public EntityContact(EntityID id, EntityAppearanceCollection appearances, Vec3 velocity) { ID = id; Appearances = appearances; Velocity = velocity; }