예제 #1
0
파일: EntityPool.cs 프로젝트: IronFox/Shard
        public bool CheckFindAndRemove(EntityID id)
        {
            Container ctr;

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