Ejemplo n.º 1
0
        public Factory Clear()
        {
            // Clean up all workers.
            for (int i = 0; i < Capacity; i++)
            {
                workers[i]?.Dispose();
                workers[i]?.ClearBehaviors();
                // ? Not entirely sure if this is necessary, but I am going to keep it.
                workers[i] = null;
            }

            // Make sure to dispose of any behaviors that were about to be added.
            foreach (Tuple <uint, Trade[]> entry in behaviorAddition)
            {
                for (int i = 0; i < entry.Item2.Length; i++)
                {
                    if (entry.Item2[i] is IDisposable disposable)
                    {
                        disposable.Dispose();
                    }
                }
            }

            behaviorAddition.Clear();
            behaviorSubtraction.Clear();
            entityRemoval.Clear();
            vacancies.Clear();

            workerIndex  = 0;
            dataModified = false;

            return(this);
        }
Ejemplo n.º 2
0
        ///<summary>
        /// Clears all entities of any attached components and systems.
        ///</summary>
        public MorroFactory ClearEntities()
        {
            // Remove any attached components and systems from each entity.
            for (int i = 0; i < EntityCapacity; i++)
            {
                attachedComponents[i].Clear();
                attachedSystems[i].Clear();
            }

            // Make sure the component for each entity is empty.
            for (int i = 0; i < componentIndex; i++)
            {
                for (int j = 0; j < EntityCapacity; j++)
                {
                    // ! Might want to have Dispose() here.
                    componentData[i][j] = null;
                }
            }

            // Remove all references to entities from each system.
            for (int i = 0; i < systemIndex; i++)
            {
                systems[i].ClearEntities();
            }

            componentAddition.Clear();
            componentSubtraction.Clear();
            entityRemovalQueue.Clear();
            vacancies.Clear();

            nextEntity           = 0;
            totalEntitiesCreated = 0;
            dataModified         = false;

            return(this);
        }