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;
        }
예제 #2
0
        public SveltoOnDOTSEntitiesSubmissionGroup(SimpleEntitiesSubmissionScheduler submissionScheduler,
                                                   EnginesRoot enginesRoot)
        {
            _submissionScheduler = submissionScheduler;
            _submissionEngines   = new FasterList <SveltoOnDOTSHandleCreationEngine>();
            _cachedList          = new List <DOTSEntityToSetup>();
            _sveltoOnDotsHandleLifeTimeEngines = new FasterList <ISveltoOnDOTSHandleLifeTimeEngine>();

            var defaultSveltoOnDotsHandleLifeTimeEngine = new SveltoOnDOTSHandleLifeTimeEngine <DOTSEntityComponent>();

            enginesRoot.AddEngine(defaultSveltoOnDotsHandleLifeTimeEngine);
            _sveltoOnDotsHandleLifeTimeEngines.Add(defaultSveltoOnDotsHandleLifeTimeEngine);
        }
예제 #3
0
        static Console()
        {
            _loggers = new FasterList <DataStructures.WeakReference <ILogger> >();

#if UNITY_5_3_OR_NEWER || UNITY_5
            _standardLogger = new SlowUnityLogger();
#else
            _standardLogger = new SimpleLogger();
#endif
            _standardLogger.OnLoggerAdded();

            _loggers.Add(new DataStructures.WeakReference <ILogger>(_standardLogger));
        }
        static SerializableEntityDescriptor()
        {
            IComponentBuilder[] defaultEntities = EntityDescriptorTemplate <TType> .descriptor.componentsToBuild;

            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) = SetupSpecialEntityComponent(defaultEntities, out ComponentsToBuild);
            if (index == -1)
            {
                index = ComponentsToBuild.Length - 1;
            }

            // Stores the hash of this EntityDescriptor
            ComponentsToBuild[index] = new ComponentBuilder <SerializableEntityComponent>(new SerializableEntityComponent
            {
                descriptorHash = _hash
            });

            // If the current serializable is an ExtendibleDescriptor, I have to update it.
            if (dynamicIndex != -1)
            {
                ComponentsToBuild[dynamicIndex] = new ComponentBuilder <EntityInfoViewComponent>(new EntityInfoViewComponent
                {
                    componentsToBuild = ComponentsToBuild
                });
            }

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

            _entityComponentsToSerializeMap = new FasterDictionary <RefWrapper <Type>, ISerializableComponentBuilder>();
            foreach (IComponentBuilder e in defaultEntities)
            {
                if (e is ISerializableComponentBuilder serializableEntityBuilder)
                {
                    var entityType = serializableEntityBuilder.GetEntityComponentType();
                    _entityComponentsToSerializeMap[new RefWrapper <Type>(entityType)] = serializableEntityBuilder;
                    entitiesToSerialize.Add(serializableEntityBuilder);
                }
            }

            _entitiesToSerialize = entitiesToSerialize.ToArray();
        }
예제 #5
0
        /// <summary>
        /// 创建实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns>如果已经存在将返回id为-1的实体</returns>
        public IcSkSEntity CreateEntity(int id)
        {
            IcSkSEntity entity = id;

            if (_checkEntity(entity))
            {
                return(-1);
            }

            _entitys.Add(entity);
            BuffManager.AddEntity(entity);

            return(entity);
        }
        public static void Add(ExclusiveGroupStruct @group)
        {
            for (int i = 0; i < _Groups.count; ++i)
            {
                if (_Groups[i] == group)
                {
                    throw new Exception("temporary must be transformed in unit test");
                }
            }

            _Groups.Add(group);

            //  GroupCompound<G1, G2, G3>._Groups = _Groups;
        }
 public void DequeueInto(FasterList <T> list, int count)
 {
     _lockQ.EnterWriteLock();
     try
     {
         int originalSize = _queue.Count;
         while (_queue.Count > 0 && originalSize - _queue.Count < count)
         {
             list.Add(_queue.Dequeue());
         }
     }
     finally
     {
         _lockQ.ExitWriteLock();
     }
 }
예제 #8
0
        public void TestAdd()
        {
            FasterList <int> list = new FasterList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(i);
            }

            for (int i = 0; i < 10; i++)
            {
                Assert.That(list[i], Is.EqualTo(i));
            }

            Assert.That(list.capacity, Is.EqualTo(10));
            Assert.That(list.count, Is.EqualTo(10));
        }
예제 #9
0
        public LocalFasterReadOnlyList <ExclusiveGroupStruct> FindGroups <T1, T2>()
            where T1 : IBaseEntityComponent where T2 : IBaseEntityComponent
        {
            FasterList <ExclusiveGroupStruct> result = localgroups.Value.groupArray;

            result.FastClear();
            if (groupsPerComponent.TryGetValue(TypeRefWrapper <T1> .wrapper
                                               , out FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary> result1)
                == false)
            {
                return(result);
            }
            if (groupsPerComponent.TryGetValue(TypeRefWrapper <T2> .wrapper
                                               , out FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary> result2)
                == false)
            {
                return(result);
            }

            var result1Count           = result1.count;
            var result2Count           = result2.count;
            var fasterDictionaryNodes1 = result1.unsafeKeys;
            var fasterDictionaryNodes2 = result2.unsafeKeys;

            for (int i = 0; i < result1Count; i++)
            {
                var groupID = fasterDictionaryNodes1[i].key;
                if (!groupID.IsEnabled())
                {
                    continue;
                }

                for (int j = 0; j < result2Count; j++)
                {
                    //if the same group is found used with both T1 and T2
                    if (groupID == fasterDictionaryNodes2[j].key)
                    {
                        result.Add(groupID);
                        break;
                    }
                }
            }

            return(result);
        }
예제 #10
0
        static EntityView()
        {
            cachedFields = new FasterList <KeyValuePair <Type, ActionCast <T> > >();

            var type = typeof(T);

            var fields = type.GetFields(BindingFlags.Public |
                                        BindingFlags.Instance);

            for (int i = fields.Length - 1; i >= 0; --i)
            {
                var field = fields[i];

                ActionCast <T> setter = FastInvoke <T> .MakeSetter(field);

                cachedFields.Add(new KeyValuePair <Type, ActionCast <T> >(field.FieldType, setter));
            }
        }
예제 #11
0
        public void TestTrim()
        {
            FasterList <int> list = new FasterList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(i);
            }

            list.UnorderedRemoveAt(3);
            list.UnorderedRemoveAt(0);
            list.UnorderedRemoveAt(7);

            list.Trim();

            Assert.That(list.capacity, Is.EqualTo(7));
            Assert.That(list.count, Is.EqualTo(7));
        }
예제 #12
0
        public virtual FasterList <INode> BuildNodes(int ID)
        {
            var nodes = new FasterList <INode>();

            for (int index = 0; index < _nodesToBuild.Count; index++)
            {
                var nodeBuilder = _nodesToBuild[index];
                var node        = nodeBuilder.Build(ID);

                if (nodeBuilder.reflects != FillNodeMode.None)
                {
                    node = FillNode(node, nodeBuilder.reflects);
                }

                nodes.Add(node);
            }

            return(nodes);
        }
예제 #13
0
        public void TestRemoveAt()
        {
            FasterList <int> list = new FasterList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(i);
            }

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

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

            list.RemoveAt(7);

            Assert.That(list.capacity, Is.EqualTo(10));
            Assert.That(list.count, Is.EqualTo(7));
        }
예제 #14
0
        virtual public FasterList <INode> BuildNodes(int ID, Action <INode> removeAction)
        {
            var nodes = new FasterList <INode>();

            for (int index = 0; index < _nodesToBuild.Length; index++)
            {
                var nodeBuilder = _nodesToBuild[index];
                var node        = FillNode(nodeBuilder.Build(ID), () =>
                {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        removeAction(nodes[i]);
                    }
                }
                                           );

                nodes.Add(node);
            }

            return(nodes);
        }
        public LocalFasterReadOnlyList <ExclusiveGroupStruct> FindGroups <T1>() where T1 : IEntityComponent
        {
            FasterList <ExclusiveGroupStruct> result = groups.Value;

            result.FastClear();
            if (_groupsPerEntity.TryGetValue(TypeRefWrapper <T1> .wrapper
                                             , out FasterDictionary <uint, ITypeSafeDictionary> result1) == false)
            {
                return(result);
            }

            var result1Count           = result1.count;
            var fasterDictionaryNodes1 = result1.unsafeKeys;

            for (int j = 0; j < result1Count; j++)
            {
                result.Add(new ExclusiveGroupStruct(fasterDictionaryNodes1[j].key));
            }

            return(result);
        }
예제 #16
0
        static GroupCompound()
        {
            if ((Groups = GroupCompound <G3, G1, G2> .Groups) == null)
            {
                if ((Groups = GroupCompound <G2, G3, G1> .Groups) == null)
                {
                    if ((Groups = GroupCompound <G3, G2, G1> .Groups) == null)
                    {
                        if ((Groups = GroupCompound <G1, G3, G2> .Groups) == null)
                        {
                            if ((Groups = GroupCompound <G2, G1, G3> .Groups) == null)
                            {
                                Groups = new FasterList <ExclusiveGroupStruct>(1);

                                var Group = new ExclusiveGroup();
                                Groups.Add(Group);

                                Console.LogDebug("<color=orange>".FastConcat(typeof(G1).ToString().FastConcat("-", typeof(G2).ToString(), "-").FastConcat(typeof(G3).ToString(), "- Initialized ", Groups[0].ToString()), "</color>"));

                                GroupCompound <G1, G2> .Add(Group); //<G1/G2> and <G2/G1> must share the same array

                                GroupCompound <G1, G3> .Add(Group);

                                GroupCompound <G2, G3> .Add(Group);

                                GroupTag <G1> .Add(Group);

                                GroupTag <G2> .Add(Group);

                                GroupTag <G3> .Add(Group);
                            }
                            else
                            {
                                Console.LogDebug(typeof(G1).ToString().FastConcat("-", typeof(G2).ToString(), "-").FastConcat(typeof(G3).ToString(), "-", Groups[0].ToString()));
                            }
                        }
                    }
                }
            }
        }
        static GroupCompound()
        {
            if ((_Groups = GroupCompound <G3, G1, G2> ._Groups) == null)
            {
                if ((_Groups = GroupCompound <G2, G3, G1> ._Groups) == null)
                {
                    if ((_Groups = GroupCompound <G3, G2, G1> ._Groups) == null)
                    {
                        if ((_Groups = GroupCompound <G1, G3, G2> ._Groups) == null)
                        {
                            if ((_Groups = GroupCompound <G2, G1, G3> ._Groups) == null)
                            {
                                _Groups = new FasterList <ExclusiveGroupStruct>(1);

                                var Group = new ExclusiveGroup();
                                _Groups.Add(Group);

                                GroupCompound <G1, G2> .Add(Group); //<G1/G2> and <G2/G1> must share the same array

                                GroupCompound <G1, G3> .Add(Group);

                                GroupCompound <G2, G3> .Add(Group);

                                //This is done here to be sure that the group is added once per group tag
                                //(if done inside the previous group compound it would be added multiple times)
                                GroupTag <G1> .Add(Group);

                                GroupTag <G2> .Add(Group);

                                GroupTag <G3> .Add(Group);

#if DEBUG
                                GroupMap.idToName[(uint)Group] = $"Compound: {typeof(G1).Name}-{typeof(G2).Name}-{typeof(G3).Name}";
#endif
                            }
                        }
                    }
                }
            }
        }
        static GroupCompound()
        {
            if ((_Groups = GroupCompound <G3, G1, G2> ._Groups) == null)
            {
                if ((_Groups = GroupCompound <G2, G3, G1> ._Groups) == null)
                {
                    if ((_Groups = GroupCompound <G3, G2, G1> ._Groups) == null)
                    {
                        if ((_Groups = GroupCompound <G1, G3, G2> ._Groups) == null)
                        {
                            if ((_Groups = GroupCompound <G2, G1, G3> ._Groups) == null)
                            {
                                _Groups = new FasterList <ExclusiveGroupStruct>(1);

                                var Group = new ExclusiveGroup();
                                _Groups.Add(Group);

                                GroupCompound <G1, G2> .Add(Group); //<G1/G2> and <G2/G1> must share the same array

                                GroupCompound <G1, G3> .Add(Group);

                                GroupCompound <G2, G3> .Add(Group);

                                GroupTag <G1> .Add(Group);

                                GroupTag <G2> .Add(Group);

                                GroupTag <G3> .Add(Group);

#if DEBUG
                                GroupMap.idToName[(uint)Group] = $"Compound: {typeof(G1).Name}-{typeof(G2).Name}-{typeof(G3).Name}";
#endif
                            }
                        }
                    }
                }
            }
        }
        public LocalFasterReadOnlyList <ExclusiveGroupStruct> FindGroups <T1, T2>() where T1 : IEntityComponent  where T2 : IEntityComponent
        {
            FasterList <ExclusiveGroupStruct> result = groups.Value;

            result.FastClear();
            if (_groupsPerEntity.TryGetValue(TypeRefWrapper <T1> .wrapper
                                             , out FasterDictionary <uint, ITypeSafeDictionary> result1) == false)
            {
                return(result);
            }
            if (_groupsPerEntity.TryGetValue(TypeRefWrapper <T2> .wrapper
                                             , out FasterDictionary <uint, ITypeSafeDictionary> result2) == false)
            {
                return(result);
            }

            var result1Count           = result1.count;
            var result2Count           = result2.count;
            var fasterDictionaryNodes1 = result1.unsafeKeys;
            var fasterDictionaryNodes2 = result2.unsafeKeys;

            for (int i = 0; i < result1Count; i++)
            {
                for (int j = 0; j < result2Count; j++)
                {
                    //if the same group is found used with both T1 and T2
                    if (fasterDictionaryNodes1[i].key == fasterDictionaryNodes2[j].key)
                    {
                        result.Add(new ExclusiveGroupStruct(fasterDictionaryNodes1[i].key));
                        break;
                    }
                }
            }

            return(result);
        }
예제 #20
0
        public static void AddLogger(ILogger log)
        {
            log.OnLoggerAdded();

            _loggers.Add(new DataStructures.WeakReference <ILogger>(log));
        }
예제 #21
0
        static GroupCompound()
        {
            if (GroupCompoundInitializer.isInitializing4.Value == false)
            {
                _Groups = new FasterList <ExclusiveGroupStruct>(1);

                var Group = new ExclusiveGroup();
                _Groups.Add(Group);
                _GroupsHashSet = new HashSet <ExclusiveGroupStruct>(_Groups.ToArrayFast(out _));

                GroupCompound <G1, G2, G3> .Add(Group);

                GroupCompound <G1, G2, G4> .Add(Group);

                GroupCompound <G1, G3, G4> .Add(Group);

                GroupCompound <G2, G3, G4> .Add(Group);

                GroupCompound <G1, G2> .Add(Group); //<G1/G2> and <G2/G1> must share the same array

                GroupCompound <G1, G3> .Add(Group);

                GroupCompound <G1, G4> .Add(Group);

                GroupCompound <G2, G3> .Add(Group);

                GroupCompound <G2, G4> .Add(Group);

                GroupCompound <G3, G4> .Add(Group);

                //This is done here to be sure that the group is added once per group tag
                //(if done inside the previous group compound it would be added multiple times)
                GroupTag <G1> .Add(Group);

                GroupTag <G2> .Add(Group);

                GroupTag <G3> .Add(Group);

                GroupTag <G4> .Add(Group);

#if DEBUG
                GroupMap.idToName[(uint)Group] =
                    $"Compound: {typeof(G1).Name}-{typeof(G2).Name}-{typeof(G3).Name}-{typeof(G4).Name} ID {(uint) Group}";
#endif
                GroupCompoundInitializer.isInitializing4.Value = true;

                //all the combinations must share the same group and group hashset
                GroupCompound <G1, G2, G4, G3> ._Groups = _Groups;
                GroupCompound <G1, G3, G2, G4> ._Groups = _Groups;
                GroupCompound <G1, G3, G4, G2> ._Groups = _Groups;
                GroupCompound <G1, G4, G2, G3> ._Groups = _Groups;
                GroupCompound <G2, G1, G3, G4> ._Groups = _Groups;
                GroupCompound <G2, G3, G4, G1> ._Groups = _Groups;
                GroupCompound <G3, G1, G2, G4> ._Groups = _Groups;
                GroupCompound <G4, G1, G2, G3> ._Groups = _Groups;
                GroupCompound <G1, G4, G3, G2> ._Groups = _Groups;
                GroupCompound <G2, G1, G4, G3> ._Groups = _Groups;
                GroupCompound <G2, G4, G3, G1> ._Groups = _Groups;
                GroupCompound <G3, G1, G4, G2> ._Groups = _Groups;
                GroupCompound <G4, G1, G3, G2> ._Groups = _Groups;
                GroupCompound <G2, G3, G1, G4> ._Groups = _Groups;
                GroupCompound <G3, G4, G1, G2> ._Groups = _Groups;
                GroupCompound <G2, G4, G1, G3> ._Groups = _Groups;
                GroupCompound <G3, G2, G1, G4> ._Groups = _Groups;
                GroupCompound <G3, G2, G4, G1> ._Groups = _Groups;
                GroupCompound <G3, G4, G2, G1> ._Groups = _Groups;
                GroupCompound <G4, G2, G1, G3> ._Groups = _Groups;
                GroupCompound <G4, G2, G3, G1> ._Groups = _Groups;
                GroupCompound <G4, G3, G1, G2> ._Groups = _Groups;
                GroupCompound <G4, G3, G2, G1> ._Groups = _Groups;

                GroupCompound <G1, G2, G4, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G3, G2, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G3, G4, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G4, G2, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G1, G3, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G3, G4, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G1, G2, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G1, G2, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G4, G3, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G1, G4, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G4, G3, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G1, G4, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G1, G3, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G3, G1, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G4, G1, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G4, G1, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G2, G1, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G2, G4, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G4, G2, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G2, G1, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G2, G3, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G3, G1, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G3, G2, G1> ._GroupsHashSet = _GroupsHashSet;

                GroupCompoundInitializer.isInitializing4.Value = false;
            }
        }
예제 #22
0
        public static void AddLogger(ILogger log)
        {
            _loggers.Add(log);

            log.OnLoggerAdded();
        }
예제 #23
0
        static GroupTag()
        {
            Groups.Add(new ExclusiveGroup());

            Console.LogDebug(typeof(T).ToString() + "-" + Groups[0].ToString());
        }
 void AddSveltoEngineToTick(IJobifiedEngine engine)
 {
     _enginesRoot.AddEngine(engine);
     _enginesToTick.Add(engine);
 }
예제 #25
0
 static void AddSveltoEngineToTick
     (IJobifiedEngine engine, EnginesRoot enginesRoot, FasterList <IJobifiedEngine> enginesToTick)
 {
     enginesRoot.AddEngine(engine);
     enginesToTick.Add(engine);
 }
예제 #26
0
        static GroupCompound()
        {
            //avoid race conditions if compounds are using on multiple thread
            if (Interlocked.CompareExchange(ref isInitializing, 1, 0) == 0 &&
                GroupCompoundInitializer.skipStaticCompoundConstructorsWith4Tags.Value == false)
            {
                _Groups = new FasterList <ExclusiveGroupStruct>(1);

                var group = new ExclusiveGroup();
                _Groups.Add(group);

                var name =
                    $"Compound: {typeof(G1).Name}-{typeof(G2).Name}-{typeof(G3).Name}-{typeof(G4).Name} ID {(uint) group}";
#if DEBUG
                GroupNamesMap.idToName[(uint)group] = name;
#endif
                GroupHashMap.RegisterGroup(group, name);

                _GroupsHashSet = new HashSet <ExclusiveGroupStruct>(_Groups.ToArrayFast(out _));

                GroupCompoundInitializer.skipStaticCompoundConstructorsWith4Tags.Value = true;

                //all the permutations must share the same group and group hashset. Warm them up, avoid call the
                //constructors again, set the desired value
                GroupCompound <G1, G2, G4, G3> ._Groups = _Groups;
                GroupCompound <G1, G3, G2, G4> ._Groups = _Groups;
                GroupCompound <G1, G3, G4, G2> ._Groups = _Groups;
                GroupCompound <G1, G4, G2, G3> ._Groups = _Groups;
                GroupCompound <G2, G1, G3, G4> ._Groups = _Groups;
                GroupCompound <G2, G3, G4, G1> ._Groups = _Groups;
                GroupCompound <G3, G1, G2, G4> ._Groups = _Groups;
                GroupCompound <G4, G1, G2, G3> ._Groups = _Groups;
                GroupCompound <G1, G4, G3, G2> ._Groups = _Groups;
                GroupCompound <G2, G1, G4, G3> ._Groups = _Groups;
                GroupCompound <G2, G4, G3, G1> ._Groups = _Groups;
                GroupCompound <G3, G1, G4, G2> ._Groups = _Groups;
                GroupCompound <G4, G1, G3, G2> ._Groups = _Groups;
                GroupCompound <G2, G3, G1, G4> ._Groups = _Groups;
                GroupCompound <G3, G4, G1, G2> ._Groups = _Groups;
                GroupCompound <G2, G4, G1, G3> ._Groups = _Groups;
                GroupCompound <G3, G2, G1, G4> ._Groups = _Groups;
                GroupCompound <G3, G2, G4, G1> ._Groups = _Groups;
                GroupCompound <G3, G4, G2, G1> ._Groups = _Groups;
                GroupCompound <G4, G2, G1, G3> ._Groups = _Groups;
                GroupCompound <G4, G2, G3, G1> ._Groups = _Groups;
                GroupCompound <G4, G3, G1, G2> ._Groups = _Groups;
                GroupCompound <G4, G3, G2, G1> ._Groups = _Groups;

                //all the permutations are warmed up now
                GroupCompoundInitializer.skipStaticCompoundConstructorsWith4Tags.Value = false;

                GroupCompound <G1, G2, G4, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G3, G2, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G3, G4, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G4, G2, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G1, G3, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G3, G4, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G1, G2, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G1, G2, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G4, G3, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G1, G4, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G4, G3, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G1, G4, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G1, G3, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G3, G1, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G4, G1, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G4, G1, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G2, G1, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G2, G4, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G4, G2, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G2, G1, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G2, G3, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G3, G1, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G3, G2, G1> ._GroupsHashSet = _GroupsHashSet;

                GroupCompound <G1, G2, G3> .Add(group);

                GroupCompound <G1, G2, G4> .Add(group);

                GroupCompound <G1, G3, G4> .Add(group);

                GroupCompound <G2, G3, G4> .Add(group);

                GroupCompound <G1, G2> .Add(group); //<G1/G2> and <G2/G1> must share the same array

                GroupCompound <G1, G3> .Add(group);

                GroupCompound <G1, G4> .Add(group);

                GroupCompound <G2, G3> .Add(group);

                GroupCompound <G2, G4> .Add(group);

                GroupCompound <G3, G4> .Add(group);

                //This is done here to be sure that the group is added once per group tag
                //(if done inside the previous group compound it would be added multiple times)
                GroupTag <G1> .Add(group);

                GroupTag <G2> .Add(group);

                GroupTag <G3> .Add(group);

                GroupTag <G4> .Add(group);
            }
        }
예제 #27
0
 public static void AddLogger(ILogger log)
 {
     _loggers.Add(new Svelto.DataStructures.WeakReference <ILogger>(log));
 }
예제 #28
0
 void AddTickEngine(IJobifiedEngine engine)
 {
     _enginesRoot.AddEngine(engine);
     _enginesToTick.Add(engine);
 }
예제 #29
0
        static GroupCompound()
        {
            //avoid race conditions if compounds are using on multiple thread
            if (Interlocked.CompareExchange(ref isInitializing, 1, 0) == 0 &&
                GroupCompoundInitializer.skipStaticCompoundConstructorsWith4Tags.Value == false)
            {
                var group = new ExclusiveGroup(); //todo: it's a bit of a waste to create a class here even if this is a static constructor

                _Groups = new FasterList <ExclusiveGroupStruct>(1);
                _Groups.Add(group);

#if DEBUG
                var name =
                    $"Compound: {typeof(G1).Name}-{typeof(G2).Name}-{typeof(G3).Name}-{typeof(G4).Name} ID {(uint) group.id}";
                GroupNamesMap.idToName[group] = name;
#endif
                //The hashname is independent from the actual group ID. this is fundamental because it is want
                //guarantees the hash to be the same across different machines
                GroupHashMap.RegisterGroup(group, typeof(GroupCompound <G1, G2, G3, G4>).FullName);

                _GroupsHashSet = new HashSet <ExclusiveGroupStruct>(_Groups.ToArrayFast(out _));

                GroupCompoundInitializer.skipStaticCompoundConstructorsWith4Tags.Value = true;

                //all the permutations must share the same group and group hashset. Warm them up, avoid call the
                //constructors again, set the desired value
                GroupCompound <G1, G2, G4, G3> ._Groups = _Groups;
                GroupCompound <G1, G3, G2, G4> ._Groups = _Groups;
                GroupCompound <G1, G3, G4, G2> ._Groups = _Groups;
                GroupCompound <G1, G4, G2, G3> ._Groups = _Groups;
                GroupCompound <G2, G1, G3, G4> ._Groups = _Groups;
                GroupCompound <G2, G3, G4, G1> ._Groups = _Groups;
                GroupCompound <G3, G1, G2, G4> ._Groups = _Groups;
                GroupCompound <G4, G1, G2, G3> ._Groups = _Groups;
                GroupCompound <G1, G4, G3, G2> ._Groups = _Groups;
                GroupCompound <G2, G1, G4, G3> ._Groups = _Groups;
                GroupCompound <G2, G4, G3, G1> ._Groups = _Groups;
                GroupCompound <G3, G1, G4, G2> ._Groups = _Groups;
                GroupCompound <G4, G1, G3, G2> ._Groups = _Groups;
                GroupCompound <G2, G3, G1, G4> ._Groups = _Groups;
                GroupCompound <G3, G4, G1, G2> ._Groups = _Groups;
                GroupCompound <G2, G4, G1, G3> ._Groups = _Groups;
                GroupCompound <G3, G2, G1, G4> ._Groups = _Groups;
                GroupCompound <G3, G2, G4, G1> ._Groups = _Groups;
                GroupCompound <G3, G4, G2, G1> ._Groups = _Groups;
                GroupCompound <G4, G2, G1, G3> ._Groups = _Groups;
                GroupCompound <G4, G2, G3, G1> ._Groups = _Groups;
                GroupCompound <G4, G3, G1, G2> ._Groups = _Groups;
                GroupCompound <G4, G3, G2, G1> ._Groups = _Groups;

                //all the permutations are warmed up now
                GroupCompoundInitializer.skipStaticCompoundConstructorsWith4Tags.Value = false;

                GroupCompound <G1, G2, G4, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G3, G2, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G3, G4, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G4, G2, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G1, G3, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G3, G4, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G1, G2, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G1, G2, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G1, G4, G3, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G1, G4, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G4, G3, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G1, G4, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G1, G3, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G3, G1, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G4, G1, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G2, G4, G1, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G2, G1, G4> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G2, G4, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G3, G4, G2, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G2, G1, G3> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G2, G3, G1> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G3, G1, G2> ._GroupsHashSet = _GroupsHashSet;
                GroupCompound <G4, G3, G2, G1> ._GroupsHashSet = _GroupsHashSet;

                GroupCompound <G1, G2, G3> .Add(group);

                GroupCompound <G1, G2, G4> .Add(group);

                GroupCompound <G1, G3, G4> .Add(group);

                GroupCompound <G2, G3, G4> .Add(group);

                GroupCompound <G1, G2> .Add(group); //<G1/G2> and <G2/G1> must share the same array

                GroupCompound <G1, G3> .Add(group);

                GroupCompound <G1, G4> .Add(group);

                GroupCompound <G2, G3> .Add(group);

                GroupCompound <G2, G4> .Add(group);

                GroupCompound <G3, G4> .Add(group);

                //This is done here to be sure that the group is added once per group tag
                //(if done inside the previous group compound it would be added multiple times)
                GroupTag <G1> .Add(group);

                GroupTag <G2> .Add(group);

                GroupTag <G3> .Add(group);

                GroupTag <G4> .Add(group);
            }
        }
예제 #30
0
        /// <summary>
        /// Remember that this operation os O(N*M*P) where N,M,P are the number of groups where each component
        /// is found.
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <returns></returns>
        public LocalFasterReadOnlyList <ExclusiveGroupStruct> FindGroups <T1, T2, T3>()
            where T1 : IEntityComponent where T2 : IEntityComponent where T3 : IEntityComponent
        {
            FasterList <ExclusiveGroupStruct> result = groups.Value;

            result.FastClear();
            if (groupsPerEntity.TryGetValue(TypeRefWrapper <T1> .wrapper
                                            , out FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary>
                                            groupOfEntities1) == false)
            {
                return(result);
            }
            if (groupsPerEntity.TryGetValue(TypeRefWrapper <T2> .wrapper
                                            , out FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary>
                                            groupOfEntities2) == false)
            {
                return(result);
            }
            if (groupsPerEntity.TryGetValue(TypeRefWrapper <T3> .wrapper
                                            , out FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary>
                                            groupOfEntities3) == false)
            {
                return(result);
            }

            var result1Count           = groupOfEntities1.count;
            var result2Count           = groupOfEntities2.count;
            var result3Count           = groupOfEntities3.count;
            var fasterDictionaryNodes1 = groupOfEntities1.unsafeKeys;
            var fasterDictionaryNodes2 = groupOfEntities2.unsafeKeys;
            var fasterDictionaryNodes3 = groupOfEntities3.unsafeKeys;

            //
            //TODO: I have to find once for ever a solution to be sure that the entities in the groups match
            //Currently this returns group where the entities are found, but the entities may not match in these
            //groups.
            //Checking the size of the entities is an early check, needed, but not sufficient, as entities components may
            //coincidentally match in number but not from which entities they are generated

            //foreach group where T1 is found
            for (int i = 0; i < result1Count; i++)
            {
                var groupT1 = fasterDictionaryNodes1[i].key;

                //foreach group where T2 is found
                for (int j = 0; j < result2Count; ++j)
                {
                    if (groupT1 == fasterDictionaryNodes2[j].key)
                    {
                        //foreach group where T3 is found
                        for (int k = 0; k < result3Count; ++k)
                        {
                            if (groupT1 == fasterDictionaryNodes3[k].key)
                            {
                                result.Add(new ExclusiveGroupStruct(groupT1));
                                break;
                            }
                        }

                        break;
                    }
                }
            }

            return(result);
        }
예제 #31
0
        internal static uint ToECS(T resource)
        {
            _resources.Add(resource);

            return((uint)_resources.Count);
        }