Esempio n. 1
0
        static Console()
        {
            _stringBuilder = new ThreadLocal <StringBuilder>
                                 (() => new StringBuilder(256));
            _loggers = new FasterList <ILogger>();

            AddLogger(new SimpleLogger());
        }
        public DynamicEntityDescriptor(FasterList <IEntityBuilder> extraEntityBuilders) : this()
        {
            var extraEntities       = extraEntityBuilders.ToArrayFast();
            var extraEntitiesLength = extraEntityBuilders.Count;

            _entitiesToBuild = Construct(extraEntitiesLength, extraEntities,
                                         EntityDescriptorTemplate <TType> .descriptor.entitiesToBuild);
        }
Esempio n. 3
0
        public QueryGroups Except(FasterList <ExclusiveGroupStruct> groupsToIgnore)
        {
            var groupsValue = groups.Value;

            groupsValue.Exclude(groupsToIgnore.ToArrayFast(out var count), count);

            return(this);
        }
Esempio n. 4
0
 public static void StandardTasksFlushing(ThreadSafeQueue <IPausableTask> newTaskRoutines,
                                          FasterList <IPausableTask> coroutines, FlushingOperation flushingOperation)
 {
     if (newTaskRoutines.Count > 0)
     {
         newTaskRoutines.DequeueAllInto(coroutines);
     }
 }
Esempio n. 5
0
 public DebugRoot(EnginesRoot root)
 {
     EnginesRoot = root;
     Engines     = (FasterList <IEngine>)EnginesField.GetValue(root);
     Root        = (FasterDictionary <uint, FasterDictionary <RefWrapper <Type>, ITypeSafeDictionary> >)EntityDBField.GetValue(root);
     LocatorMap  = (FasterDictionary <uint, FasterDictionary <uint, EntityLocator> >)EgidMapField.GetValue(root);
     Process();
 }
Esempio n. 6
0
 public Process(ThreadSafeQueue <T> newTaskRoutines, FasterList <T> coroutines,
                FlushingOperation flushingOperation, TRunningInfo info)
 {
     _newTaskRoutines   = newTaskRoutines;
     _coroutines        = coroutines;
     _flushingOperation = flushingOperation;
     _info = info;
 }
Esempio n. 7
0
        public FasterList(FasterList <T> listCopy)
        {
            _buffer = new T[listCopy.Count];

            listCopy.CopyTo(_buffer, 0);

            _count = (uint)listCopy.Count;
        }
        public DynamicEntityDescriptor(FasterList <IComponentBuilder> extraEntityBuilders) : this()
        {
            var extraEntities       = extraEntityBuilders.ToArrayFast(out _);
            var extraEntitiesLength = extraEntityBuilders.count;

            ComponentsToBuild = Construct((int)extraEntitiesLength, extraEntities,
                                          EntityDescriptorTemplate <TType> .descriptor.componentsToBuild);
        }
        public StaggeredMonoRunner(int maxQueueLength)
        {
            _flushingOperation.framesLength = maxQueueLength;

            var coroutines = new FasterList <PausableTask>(NUMBER_OF_INITIAL_COROUTINE);

            _runnerBehaviour.StartCoroutine(CoroutinesRunner(_newTaskRoutines, coroutines, _flushingOperation, _info,
                                                             NewFlushTasks));
        }
Esempio n. 10
0
        public void TestEnsureCapacity()
        {
            FasterList <int> listA = new FasterList <int>();

            listA.EnsureCapacity(10);

            Assert.That(listA.capacity, Is.EqualTo(10));
            Assert.That(listA.count, Is.EqualTo(0));
        }
Esempio n. 11
0
        public void TestExpandTo()
        {
            FasterList <int> list = new FasterList <int>(0);

            list.SetCountTo(10);

            Assert.That(list.capacity, Is.EqualTo(15));
            Assert.That(list.count, Is.EqualTo(10));
        }
Esempio n. 12
0
        public void TestResize()
        {
            FasterList <int> list = new FasterList <int>(0);

            list.Resize(10);

            Assert.That(list.capacity, Is.EqualTo(10));
            Assert.That(list.count, Is.EqualTo(0));
        }
Esempio n. 13
0
 public FasterListThreadSafe(FasterList <T> list)
 {
     if (list == null)
     {
         throw new ArgumentException("invalid list");
     }
     _list  = list;
     _lockQ = new ReaderWriterLockSlim();
 }
Esempio n. 14
0
 internal static IEnumerator Process(ThreadSafeQueue <IPausableTask> newTaskRoutines,
                                     FasterList <IPausableTask> coroutines,
                                     FlushingOperation flushingOperation,
                                     RunningTasksInfo info,
                                     FlushTasksDel flushTaskDel)
 {
     return(Process(newTaskRoutines, coroutines,
                    flushingOperation, info, flushTaskDel, null, null));
 }
Esempio n. 15
0
        public void TestExpandByFromZero()
        {
            FasterList <int> list = new FasterList <int>(0);

            list.ExpandBy(10);

            Assert.That(list.capacity, Is.EqualTo(10));
            Assert.That(list.count, Is.EqualTo(10));
        }
        public void TestSerializingWithEntityViewStructsAndFactories()
        {
            var init = _entityFactory.BuildEntity <SerializableEntityDescriptorWithViews>(
                0, NamedGroup1.Group, new[] { new Implementor(1) });

            init.Init(new EntityStructSerialized()
            {
                value = 5
            });
            init.Init(new EntityStructSerialized2()
            {
                value = 4
            });
            init.Init(new EntityStructPartiallySerialized()
            {
                value1 = 3
            });

            _simpleSubmissionEntityViewScheduler.SubmitEntities();

            FasterList <byte> bytes      = new FasterList <byte>();
            var generateEntitySerializer = _enginesRoot.GenerateEntitySerializer();
            var simpleSerializationData  = new SimpleSerializationData(bytes);

            generateEntitySerializer.SerializeEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData
                                                     , (int)SerializationType.Storage);

            SimpleEntitiesSubmissionScheduler simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler();
            var newEnginesRoot = new EnginesRoot(simpleSubmissionEntityViewScheduler);

            _neverDoThisIsJustForTheTest = new TestEngine();

            newEnginesRoot.AddEngine(_neverDoThisIsJustForTheTest);

            simpleSerializationData.Reset();
            generateEntitySerializer = newEnginesRoot.GenerateEntitySerializer();
            DeserializationFactory factory = new DeserializationFactory();

            generateEntitySerializer.RegisterSerializationFactory <SerializableEntityDescriptorWithViews>(factory);

            generateEntitySerializer.DeserializeNewEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData
                                                          , (int)SerializationType.Storage);

            simpleSubmissionEntityViewScheduler.SubmitEntities();

            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized>(0, NamedGroup1.Group).value
                , Is.EqualTo(5));
            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized2>(0, NamedGroup1.Group).value
                , Is.EqualTo(4));
            Assert.That(_neverDoThisIsJustForTheTest
                        .entitiesDB.QueryEntity <EntityStructPartiallySerialized>(0, NamedGroup1.Group).value1
                        , Is.EqualTo(3));

            newEnginesRoot.Dispose();
        }
Esempio n. 17
0
        FasterList <T> ReturnValidPool(int pool)
        {
            if (_pools.TryGetValue(pool, out var localPool) == false)
            {
                _pools[pool] = localPool = new FasterList <T>();
            }

            return(localPool);
        }
 protected static void NewFlushTasks(
     ThreadSafeQueue <PausableTask> newTaskRoutines,
     FasterList <PausableTask> coroutines, FlushingOperation flushingOperation)
 {
     if (newTaskRoutines.Count > 0)
     {
         newTaskRoutines.DequeueInto(coroutines, Mathf.CeilToInt(newTaskRoutines.Count / ((FlushingOperationStaggered)flushingOperation).framesLength));
     }
 }
        static SerializableEntityDescriptor()
        {
            IEntityBuilder[] defaultEntities = EntityDescriptorTemplate <TType> .descriptor.entitiesToBuild;

            var hashNameAttribute = _type.GetCustomAttribute <HashNameAttribute>();

            if (hashNameAttribute == null)
            {
                throw new Exception("HashName attribute not found on the serializable type ".FastConcat(_type.FullName));
            }

            _hash = DesignatedHash.Hash(Encoding.ASCII.GetBytes(hashNameAttribute._name));

            var(index, dynamicIndex) = SetupSpecialEntityStruct(defaultEntities, out _entitiesToBuild);
            if (index == -1)
            {
                index = _entitiesToBuild.Length - 1;
            }

            // Stores the hash of this EntityDescriptor
            _entitiesToBuild[index] = new EntityBuilder <SerializableEntityStruct>
                                      (
                new SerializableEntityStruct
            {
                descriptorHash = _hash
            }
                                      );

            // If the current serializable is an ExtendibleDescriptor, I have to update it.
            if (dynamicIndex != -1)
            {
                _entitiesToBuild[dynamicIndex] = new EntityBuilder <EntityStructInfoView>
                                                 (
                    new EntityStructInfoView
                {
                    entitiesToBuild = _entitiesToBuild
                }
                                                 );
            }

            /////
            var entitiesToSerialize = new FasterList <ISerializableEntityBuilder>();

            _entitiesToSerializeMap = new FasterDictionary <RefWrapper <Type>, ISerializableEntityBuilder>();
            foreach (IEntityBuilder e in defaultEntities)
            {
                if (e is ISerializableEntityBuilder serializableEntityBuilder)
                {
                    var entityType = serializableEntityBuilder.GetEntityType();
                    _entitiesToSerializeMap[new RefWrapper <Type>(entityType)] = serializableEntityBuilder;
                    entitiesToSerialize.Add(serializableEntityBuilder);
                }
            }

            _entitiesToSerialize = entitiesToSerialize.ToArray();
        }
 static void SequentialTasksFlushing(
     ThreadSafeQueue <IPausableTask> newTaskRoutines,
     FasterList <IPausableTask> coroutines,
     UnityCoroutineRunner.FlushingOperation flushingOperation)
 {
     if (newTaskRoutines.Count > 0 && coroutines.Count == 0)
     {
         newTaskRoutines.DequeueInto(coroutines, 1);
     }
 }
Esempio n. 21
0
        public QueryGroups(FasterDictionary <uint, ITypeSafeDictionary> findGroups)
        {
            var findGroupsCount = findGroups.count;

            groups = new FasterList <ExclusiveGroupStruct>(findGroupsCount);
            foreach (var keyvalue in findGroups)
            {
                groups.Add(new ExclusiveGroupStruct(keyvalue.Key));
            }
        }
Esempio n. 22
0
 static void SequentialTasksFlushing(
     ThreadSafeQueue <ISveltoTask <IEnumerator> > newTaskRoutines,
     FasterList <ISveltoTask <IEnumerator> > coroutines,
     UnityCoroutineRunner <T> .FlushingOperation flushingOperation)
 {
     if (newTaskRoutines.Count > 0 && coroutines.Count == 0)
     {
         newTaskRoutines.DequeueInto(coroutines, 1);
     }
 }
Esempio n. 23
0
        public void TestEnsureExtraCapacity()
        {
            FasterList <int> listA = new FasterList <int>();

            listA.IncrementCountBy(10);
            listA.IncreaseCapacityBy(10);

            Assert.That(listA.capacity, Is.EqualTo(25));
            Assert.That(listA.count, Is.EqualTo(10));
        }
Esempio n. 24
0
 public RunnerData(bool relaxed, int interval, string name)
 {
     _mevent          = new ManualResetEventEx();
     _relaxed         = relaxed;
     _watch           = new Stopwatch();
     _coroutines      = new FasterList <IPausableTask>();
     _newTaskRoutines = new ThreadSafeQueue <IPausableTask>();
     _interval        = interval;
     _name            = name;
 }
 static void StaggeredTasksFlushing(
     ThreadSafeQueue <IPausableTask> newTaskRoutines,
     FasterList <IPausableTask> coroutines,
     UnityCoroutineRunner.FlushingOperation flushingOperation)
 {
     if (newTaskRoutines.Count > 0)
     {
         newTaskRoutines.DequeueInto(coroutines, ((FlushingOperationStaggered)flushingOperation).maxTasksPerFrame);
     }
 }
Esempio n. 26
0
        void AddNodeToTheDB <T>(T node, Type nodeType) where T : INode
        {
            FasterList <INode> nodes;

            if (_nodesDB.TryGetValue(nodeType, out nodes) == false)
            {
                nodes = _nodesDB[nodeType] = new FasterList <INode>();
            }

            nodes.Add(node);
        }
Esempio n. 27
0
        void AddNodeToMetaDB(INode node, Type nodeType)
        {
            FasterList <INode> nodes;

            if (_metaNodesDB.TryGetValue(nodeType, out nodes) == false)
            {
                nodes = _metaNodesDB[nodeType] = new FasterList <INode>();
            }

            nodes.Add(node);
        }
Esempio n. 28
0
        public void TesSetAtCapacity()
        {
            FasterList <int> list = new FasterList <int>(3);

            list.AddAt(3, 10);

            Assert.That(list[3], Is.EqualTo(10));

            Assert.That(list.capacity, Is.EqualTo(4));
            Assert.That(list.count, Is.EqualTo(4));
        }
Esempio n. 29
0
        public void TesSetAt0()
        {
            FasterList <int> list = new FasterList <int>();

            list.AddAt(0, 10);

            Assert.That(list[0], Is.EqualTo(10));

            Assert.That(list.capacity, Is.EqualTo(1));
            Assert.That(list.count, Is.EqualTo(1));
        }
Esempio n. 30
0
        /// <summary>
        ///     Engines root contextualize your engines and entities. You don't need to limit yourself to one EngineRoot
        ///     as multiple engines root could promote separation of scopes. The EntitySubmissionScheduler checks
        ///     periodically if new entity must be submitted to the database and the engines. It's an external
        ///     dependencies to be independent by the running platform as the user can define it.
        ///     The EntitySubmissionScheduler cannot hold an EnginesRoot reference, that's why
        ///     it must receive a weak reference of the EnginesRoot callback.
        /// </summary>
        public EnginesRoot(EntitiesSubmissionScheduler entitiesComponentScheduler)
        {
            _entitiesOperations = new EntitiesOperations();
            _idChecker          = new FasterDictionary <ExclusiveGroupStruct, HashSet <uint> >();

            _cachedRangeOfSubmittedIndices = new FasterList <(uint, uint)>();
            _cachedIndicesToSwapBeforeSubmissionForFilters = new FasterDictionary <uint, uint>();

            _multipleOperationOnSameEGIDChecker = new FasterDictionary <EGID, uint>();
#if UNITY_NATIVE //because of the thread count, ATM this is only for unity
            _nativeSwapOperationQueue   = new Svelto.ECS.DataStructures.AtomicNativeBags(Allocator.Persistent);
            _nativeRemoveOperationQueue = new Svelto.ECS.DataStructures.AtomicNativeBags(Allocator.Persistent);
            _nativeAddOperationQueue    = new Svelto.ECS.DataStructures.AtomicNativeBags(Allocator.Persistent);
#endif
            _serializationDescriptorMap = new SerializationDescriptorMap();
            _reactiveEnginesAdd         = new FasterDictionary <RefWrapperType, FasterList <ReactEngineContainer <IReactOnAdd> > >();
            _reactiveEnginesAddEx       =
                new FasterDictionary <RefWrapperType, FasterList <ReactEngineContainer <IReactOnAddEx> > >();
            _reactiveEnginesRemove =
                new FasterDictionary <RefWrapperType, FasterList <ReactEngineContainer <IReactOnRemove> > >();
            _reactiveEnginesRemoveEx =
                new FasterDictionary <RefWrapperType, FasterList <ReactEngineContainer <IReactOnRemoveEx> > >();
            _reactiveEnginesSwap =
                new FasterDictionary <RefWrapperType, FasterList <ReactEngineContainer <IReactOnSwap> > >();
            _reactiveEnginesSwapEx =
                new FasterDictionary <RefWrapperType, FasterList <ReactEngineContainer <IReactOnSwapEx> > >();

            _reactiveEnginesDispose =
                new FasterDictionary <RefWrapperType, FasterList <ReactEngineContainer <IReactOnDispose> > >();

            _reactiveEnginesSubmission = new FasterList <IReactOnSubmission>();
            _enginesSet        = new FasterList <IEngine>();
            _enginesTypeSet    = new HashSet <Type>();
            _disposableEngines = new FasterList <IDisposable>();

            _groupEntityComponentsDB =
                new FasterDictionary <ExclusiveGroupStruct, FasterDictionary <RefWrapperType, ITypeSafeDictionary> >();
            _groupsPerEntity =
                new FasterDictionary <RefWrapperType, FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary> >();
            _groupedEntityToAdd = new DoubleBufferedEntitiesToAdd();
            _entityStreams      = EntitiesStreams.Create();
            _groupFilters       =
                new FasterDictionary <RefWrapperType, FasterDictionary <ExclusiveGroupStruct, LegacyGroupFilters> >();
            _entityLocator.InitEntityReferenceMap();
            _entitiesDB = new EntitiesDB(this, _entityLocator);

            InitFilters();

            scheduler        = entitiesComponentScheduler;
            scheduler.onTick = new EntitiesSubmitter(this);
#if UNITY_NATIVE
            AllocateNativeOperations();
#endif
        }
        public override FasterList<INode> BuildNodes(int ID, Action<INode> removeAction)
        {
            var nodes = new FasterList<INode>();
            var node = new EnemySpawningNode
            {
                spawnerComponents = _components
            };

            nodes.Add(node);
            return nodes;
        }