Example #1
0
        static GroupTag()
        {
            if (Interlocked.CompareExchange(ref isInitializing, 1, 0) == 0)
            {
                var group = new ExclusiveGroup();
                _Groups.Add(group);

#if DEBUG
                var typeInfo = typeof(T);
                var name     = $"Compound: {typeInfo.Name} ID {(uint) group.id}";

                var typeInfoBaseType = typeInfo.BaseType;
                if (typeInfoBaseType.GenericTypeArguments[0] != typeInfo) //todo: this should shield from using a pattern different than public class GROUP_NAME : GroupTag<GROUP_NAME> {} however I am not sure it's working
                {
                    throw new ECSException("Invalid Group Tag declared");
                }

                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(GroupTag <T>).FullName);

                _GroupsHashSet = new HashSet <ExclusiveGroupStruct>(_Groups.ToArrayFast(out _));
            }
        }
Example #2
0
        static GroupTag()
        {
            if (Interlocked.CompareExchange(ref isInitializing, 1, 0) == 0)
            {
                var group = new ExclusiveGroup();
                _Groups.Add(group);


                var typeInfo = typeof(T);

                var name = $"Compound: {typeInfo.Name} ID {(uint) @group}";
#if DEBUG
                var typeInfoBaseType = typeInfo.BaseType;
                if (typeInfoBaseType.GenericTypeArguments[0] != typeInfo)
                {
                    throw new ECSException("Invalid Group Tag declared");
                }

                GroupNamesMap.idToName[(uint)group] = name;
#endif
                GroupHashMap.RegisterGroup(group, name);

                _GroupsHashSet = new HashSet <ExclusiveGroupStruct>(_Groups.ToArrayFast(out _));
            }
        }
Example #3
0
        static EnginesRoot()
        {
            GroupHashMap.Init();
            SharedDictonary.Init();
            SerializationDescriptorMap.Init();

            _swapEntities   = SwapEntities;
            _removeEntities = RemoveEntities;
            _removeGroup    = RemoveGroup;
            _swapGroup      = SwapGroup;
        }
Example #4
0
 static EnginesRoot()
 {
     GroupHashMap.Init();
     SerializationDescriptorMap.Init();
 }
Example #5
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);
            }
        }
Example #6
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);
            }
        }