Esempio n. 1
0
        public bool CheckFindAndRemove(EntityID id)
        {
            Container ctr;

            if (!fullMap.TryRemove(id, out ctr))
            {
                return(false);
            }
            guidMap.ForceRemove(id.Guid);
            return(true);
        }
Esempio n. 2
0
        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)
        {
        }
Esempio n. 3
0
        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)
        {
        }
Esempio n. 4
0
 public T FindOrigin(EntityID id)
 {
     foreach (var c in bag)
     {
         if (c.Origin == id)
         {
             return(c);
         }
     }
     return(null);
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
        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;
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
            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;
                }
            }
Esempio n. 12
0
 public void Kill(EntityID entityID)
 {
     removals.Add(entityID);
 }
Esempio n. 13
0
 public bool Contains(EntityID id)
 {
     return(fullMap.ContainsKey(id));
 }
Esempio n. 14
0
 public EntityChange.StateAdvertisement FindAdvertisementFor(EntityID id)
 {
     return(advertisements.FindOrigin(id));
 }
Esempio n. 15
0
 public Actor(EntityID id)
 {
     Guid     = id.Guid;
     Position = id.Position;
     IsEntity = true;
 }
Esempio n. 16
0
 public bool HasContact(EntityID id)
 {
     return(FindContact(id) != -1);
 }
Esempio n. 17
0
 public MessageKey(OrderedEntityMessage msg) : this()
 {
     orderID  = msg.OrderID;
     senderID = new EntityID(msg.Message.Sender.Guid, msg.Message.Sender.Position);
 }
Esempio n. 18
0
 public ExecutionException(EntityID eID, string message, Exception nested = null) : base(message, nested)
 {
     EntityID = eID;
 }
Esempio n. 19
0
 public EntityContact(EntityID id, EntityAppearanceCollection appearances, Vec3 velocity)
 {
     ID          = id;
     Appearances = appearances;
     Velocity    = velocity;
 }