Example #1
0
        public void InsertAt(T item, int index)
        {
            //Public API for adding at a specific index.
            //Note: Has linear performance
            if (index < arrayAllocation.Length && arrayAllocation.Get(index))
            {
                //this.innerArray[index] = item; //If something's already there, just replace it
            }
            else
            {
                CheckCapacity(index + 1);
                if (index < PeakCount)
                {
                    int indexIndex = Array.BinarySearch <int>(OpenSlots.innerArray, index);
                    OpenSlots.innerArray.Shift(indexIndex, OpenSlots.innerArray.Length, -1);
                }
                else if (index >= PeakCount)
                {
                    for (; PeakCount < index; PeakCount++)
                    {
                        OpenSlots.Add(PeakCount);
                    }
                    PeakCount++;
                }

                Count++;
            }
            this.innerArray[index] = item;
            arrayAllocation[index] = true;
        }
Example #2
0
 public static void EndEffect(LSEffect effect)
 {
     if (EffectActive[effect.ID] == false)
     {
         return;
     }
     effect.Deactivate();
     EffectPool[effect.MyEffectCode].Add(effect);
     EffectActive[effect.ID] = false;
     Effects[effect.ID]      = null;
     OpenSlots.Add(effect.ID);
 }
        public static void StopCoroutine(Coroutine _coroutine)
        {
            leIndex = _coroutine.Index;
            OpenSlots.Add(leIndex);
            _coroutine.End();

            /*
             * //Lower HighCount as much as possible
             * if (_coroutine.Index == HighCount - 1)
             * {
             *      HighCount--;
             *      for (i = HighCount - 1; i >= 0; i--)
             *      {
             *              coroutine = Coroutines[i];
             *              if (coroutine.Active == false)
             *              {
             *                      HighCount--;
             *              }
             *              else {
             *                      break;
             *              }
             *      }
             * }
             */
        }
Example #4
0
 public void RemoveAt(int index)
 {
     shiftedIndex = (ulong)1 << index;
     OpenSlots.Add(index);
     arrayAllocation ^= shiftedIndex;
     Count--;
 }
Example #5
0
 public void RemoveAt(int index)
 {
     OpenSlots.Add(index);
     arrayAllocation.Set(index, false);
     this.innerArray[index] = default(T);
     Count--;
 }
Example #6
0
        public static void StopCoroutine(Coroutine _coroutine)
        {
            int leIndex = _coroutine.Index;

            OpenSlots.Add(leIndex);
            _coroutine.End();
        }
Example #7
0
        public static void Pool(MovementGroup group)
        {
            int indexID = group.indexID;

            activeGroups.RemoveAt(indexID);
            pooledGroups.Add(group);
        }
        internal static void Dessimilate(LSBody body)
        {
            int tid = body.ID;

            if (!SimObjectExists[tid])
            {
                Debug.LogWarning("Object with ID" + body.ID.ToString() + "cannot be dessimilated because it it not assimilated");
                return;
            }

            SimObjectExists[tid] = false;
            CachedIDs.Add(tid);

            for (int i = 0; i < PhysicsManager.PeakCount; i++)
            {
                if (PhysicsManager.SimObjectExists[i])
                {
                    if (i != tid)
                    {
                        int           pairIndex = GetCollisionPairIndex(i, tid);
                        CollisionPair pair;
                        if (CollisionPairs.TryGetValue(pairIndex, out pair))
                        {
                            pair.Deactivate();
                        }
                    }
                }
            }


            // body.Deactivate(); BUG ? body.Deactivate() call PhysicsManager.Dessimilate() !!!
        }
 public static void Remove(LSAgent agent)
 {
     leIndex = agent.BoxedAgentsIndex;
     agent.BoxedAgentsIndex = -1;
     OpenSlots.Add(leIndex);
     arrayAllocated[leIndex] = false;
     Count--;
 }
Example #10
0
 public static void PoolPair(CollisionPair pair)
 {
     pair.Deactivate();
     if (LockstepManager.PoolingEnabled)
     {
         CachedCollisionPairs.Add(pair);
     }
 }
Example #11
0
        private static void Generate()
        {
            #region Pooling; no need to create all those nodes again

            if (Grid != null)
            {
                int min = Grid.Length;
                CachedGridNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        CachedGridNodes.Add(Grid[i]);
                    }
                }
            }


            if (ScanGrid != null)
            {
                int min = ScanGrid.Length;
                CachedScanNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        CachedScanNodes.Add(ScanGrid[i]);
                    }
                }
            }
            #endregion

            long startMem = System.GC.GetTotalMemory(true);
            ScanGrid = new ScanNode[ScanGridSize];
            for (int i = ScanWidth - 1; i >= 0; i--)
            {
                for (int j = ScanHeight - 1; j >= 0; j--)
                {
                    ScanNode node = CachedScanNodes.Count > 0 ? CachedScanNodes.Pop() : new ScanNode();
                    node.Setup(i, j);
                    ScanGrid[GetScanIndex(i, j)] = node;
                }
            }
            Grid = new GridNode[GridSize];
            for (int i = Width - 1; i >= 0; i--)
            {
                for (int j = Height - 1; j >= 0; j--)
                {
                    GridNode node = CachedGridNodes.Count > 0 ? CachedGridNodes.Pop() : new GridNode();
                    node.Setup(i, j);
                    Grid[GetGridIndex(i, j)] = node;
                }
            }
            long usedMem = System.GC.GetTotalMemory(true) - startMem;
            //Debug.Log ("Grid generated using " + usedMem + " Bytes!");
        }
Example #12
0
        private static void Generate()
        {
            #region Pooling; no need to create all those nodes again

            if (Grid != null)
            {
                int min = Grid.Length;
                CachedGridNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        CachedGridNodes.Add(Grid[i]);
                    }
                }
            }


            if (ScanGrid != null)
            {
                int min = ScanGrid.Length;
                CachedScanNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        ;
                    }
                    CachedScanNodes.Add(ScanGrid[i]);
                }
            }
            #endregion


            ScanGrid = new ScanNode[ScanGridSize];
            for (int i = ScanWidth - 1; i >= 0; i--)
            {
                for (int j = ScanHeight - 1; j >= 0; j--)
                {
                    ScanNode node = CachedScanNodes.Count > 0 ? CachedScanNodes.Pop() : new ScanNode();
                    node.Setup(i, j);
                    ScanGrid [GetScanIndex(i, j)] = node;
                }
            }
            Grid = new GridNode[GridSize];
            for (int i = Width - 1; i >= 0; i--)
            {
                for (int j = Height - 1; j >= 0; j--)
                {
                    GridNode node = CachedGridNodes.Count > 0 ? CachedGridNodes.Pop() : new GridNode();
                    node.Setup(i, j);
                    Grid [GetGridIndex(i, j)] = node;
                }
            }
        }
        public static void DestroyAgent(LSAgent agent, bool Immediate = false)
        {
            GlobalAgentActive[agent.GlobalID] = false;

            AgentController leController = agent.Controller;

            leController.LocalAgentActive[agent.LocalID] = false;
            leController.OpenLocalIDs.Add(agent.LocalID);
            OpenGlobalIDs.Add(agent.GlobalID);

            agent.Deactivate(Immediate);
        }
Example #14
0
 public void InsertAt(T item, int index)
 {
     //Public API for adding at a specific index.
     //Note: Has linear performance
     if (arrayAllocation.Get(index))
     {
         this.innerArray[index] = item; //If something's already there, just replace it
     }
     else
     {
         int indexIndex = Array.BinarySearch <int> (OpenSlots.innerArray, index);
         if (index >= PeakCount)
         {
             for (; PeakCount < index; PeakCount++)
             {
                 OpenSlots.Add(PeakCount);
             }
             PeakCount++;
         }
     }
 }
		internal static void Dessimilate(LSBody body)
		{
			int tid = body.ID;

			if (!SimObjects[tid].IsNotNull()) {
				Debug.LogWarning("Object with ID" + body.ID.ToString() + "cannot be dessimilated because it it not assimilated");
				return;
			}

			SimObjects[tid] = null;
			CachedIDs.Add(tid);


			if (body.DynamicID >= 0) {
				DynamicSimObjects.RemoveAt(body.DynamicID);
				body.DynamicID = -1;
			}
		}
        public static void ChangeController(LSAgent agent, AgentController newCont)
        {
            AgentController leController = agent.Controller;

            leController.LocalAgentActive [agent.LocalID] = false;
            GlobalAgentActive[agent.GlobalID]             = false;
            leController.OpenLocalIDs.Add(agent.LocalID);
            OpenGlobalIDs.Add(agent.GlobalID);

            if (newCont == null)
            {
                agent.InitializeController(null, 0, 0);
            }
            else
            {
                agent.Influencer.Deactivate();

                newCont.AddAgent(agent);
                agent.Influencer.Initialize();
            }
        }
        public static void Dessimilate(LSBody body)
        {
            if (!SimObjectExists [body.ID])
            {
                Debug.LogWarning("Object with ID" + body.ID.ToString() + "cannot be dessimilated because it it not assimilated");
                return;
            }

            SimObjectExists [body.ID] = false;
            CachedIDs.Add(body.ID);

            for (i = 0; i < FastCollisionPairs.Count; i++)
            {
                pair = FastCollisionPairs.innerArray [i];
                if (pair.Body1 == body || pair.Body2 == body)
                {
                    pair.Deactivate();
                }
            }

            AssimilatedCount--;
        }