/// <summary>
            /// Here we want to register all the EntityDescriptors that need to be serialized for network play.
            ///
            /// Remember! This needs to in sync across different clients and server as the values are serialized across
            /// the network also want this to not change so we can save to a DB
            /// </summary>
            internal SerializationDescriptorMap()
            {
                _descriptors = new Dictionary <uint, ISerializableEntityDescriptor>();
                _factories   = new Dictionary <uint, IDeserializationFactory>();

                using (new StandardProfiler("Assemblies Scan"))
                {
                    List <Assembly> assemblies = AssemblyUtility.GetCompatibleAssemblies();

                    Type d1 = typeof(DefaultVersioningFactory <>);
                    foreach (Assembly assembly in assemblies)
                    {
                        foreach (Type type in AssemblyUtility.GetTypesSafe(assembly))
                        {
                            if (type != null && type.IsClass && type.IsAbstract == false && type.BaseType != null &&
                                type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition()
                                == typeof(SerializableEntityDescriptor <>))
                            {
                                var descriptor = Activator.CreateInstance(type) as ISerializableEntityDescriptor;

                                RegisterEntityDescriptor(descriptor, type, d1);
                            }
                        }
                    }
                }
            }
Пример #2
0
        /// <summary>
        /// c# Static constructors are guaranteed to be thread safe
        /// </summary>
        public static void Init()
        {
            List <Assembly> assemblies = AssemblyUtility.GetCompatibleAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                try
                {
                    var typeOfExclusiveGroup       = typeof(ExclusiveGroup);
                    var typeOfExclusiveGroupStruct = typeof(ExclusiveGroupStruct);

                    foreach (Type type in AssemblyUtility.GetTypesSafe(assembly))
                    {
                        if (type != null && type.IsClass && type.IsSealed &&
                            type.IsAbstract) //this means only static classes
                        {
                            var fields = type.GetFields();

                            foreach (var field in fields)
                            {
                                if (field.IsStatic)
                                {
                                    if (typeOfExclusiveGroup.IsAssignableFrom(field.FieldType))
                                    {
                                        var group = (ExclusiveGroup)field.GetValue(null);
#if DEBUG
                                        GroupNamesMap.idToName[@group] =
                                            $"{$"{type.FullName}.{field.Name}"} {group.id})";
#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
                                        RegisterGroup(group, $"{type.FullName}.{field.Name}");
                                    }
                                    else
                                    if (typeOfExclusiveGroupStruct.IsAssignableFrom(field.FieldType))
                                    {
                                        var group = (ExclusiveGroupStruct)field.GetValue(null);
#if DEBUG
                                        GroupNamesMap.idToName[@group] =
                                            $"{$"{type.FullName}.{field.Name}"} {group.id})";
#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
                                        RegisterGroup(@group, $"{type.FullName}.{field.Name}");
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    Console.LogDebugWarning(
                        "something went wrong while gathering group names on the assembly: ".FastConcat(
                            assembly.FullName));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// c# Static constructors are guaranteed to be thread safe
        /// </summary>

        public static void Init()
        {
            List <Assembly> assemblies = AssemblyUtility.GetCompatibleAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                try
                {
                    var typeOfExclusiveGroup       = typeof(ExclusiveGroup);
                    var typeOfExclusiveGroupStruct = typeof(ExclusiveGroupStruct);

                    foreach (Type type in AssemblyUtility.GetTypesSafe(assembly))
                    {
                        if (type != null && type.IsClass && type.IsSealed && type.IsAbstract) //this means only static classes
                        {
                            var fields = type.GetFields();

                            foreach (var field in fields)
                            {
                                if (field.IsStatic)
                                {
                                    if (typeOfExclusiveGroup.IsAssignableFrom(field.FieldType))
                                    {
                                        var group = (ExclusiveGroup)field.GetValue(null);
                                        var name  = $"{type.FullName}.{field.Name}";
#if DEBUG
                                        GroupNamesMap.idToName[(uint)@group] = $"{name} {(uint)group})";
#endif
                                        RegisterGroup(group, name);
                                    }
                                    else
                                    {
                                        if (typeOfExclusiveGroupStruct.IsAssignableFrom(field.FieldType))
                                        {
                                            var group = (ExclusiveGroupStruct)field.GetValue(null);
                                            var name  = $"{type.FullName}.{field.Name}";
#if DEBUG
                                            GroupNamesMap.idToName[(uint)@group] = $"{name} {(uint)group})";
#endif
                                            RegisterGroup(@group, name);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    Console.LogDebugWarning(
                        "something went wrong while gathering group names on the assembly: ".FastConcat(assembly.FullName));
                }
            }
        }
        static EntityDescriptorHolder()
        {
            var  assemblies = AssemblyUtility.GetCompatibleAssemblies();
            Type d1         = typeof(IEntityDescriptor);

            foreach (var assembly in assemblies)
            {
                foreach (Type type in AssemblyUtility.GetTypesSafe(assembly))
                {
                    if (type != null && d1.IsAssignableFrom(type) && type.IsAbstract == false)
                    {
                        DescriptorList.Add(type);
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// c# Static constructors are guaranteed to be thread safe
        /// </summary>
        internal static void Init()
        {
            List <Assembly> assemblies = AssemblyUtility.GetCompatibleAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                try
                {
                    var typeOfExclusiveGroup       = typeof(ExclusiveGroup);
                    var typeOfExclusiveGroupStruct = typeof(ExclusiveGroupStruct);
                    var typeOfExclusiveBuildGroup  = typeof(ExclusiveBuildGroup);

                    foreach (Type type in AssemblyUtility.GetTypesSafe(assembly))
                    {
                        CheckForGroupCompounds(type);

                        if (type != null && type.IsClass && type.IsSealed &&
                            type.IsAbstract) //IsClass and IsSealed and IsAbstract means only static classes
                        {
                            var subClasses = type.GetNestedTypes();

                            foreach (var subclass in subClasses)
                            {
                                CheckForGroupCompounds(subclass);
                            }

                            var fields = type.GetFields();

                            foreach (var field in fields)
                            {
                                if (field.IsStatic &&
                                    (typeOfExclusiveGroup.IsAssignableFrom(field.FieldType) ||
                                     typeOfExclusiveGroupStruct.IsAssignableFrom(field.FieldType) ||
                                     typeOfExclusiveBuildGroup.IsAssignableFrom(field.FieldType)))
                                {
                                    uint groupID;

                                    if (typeOfExclusiveGroup.IsAssignableFrom(field.FieldType))
                                    {
                                        var group = (ExclusiveGroup)field.GetValue(null);
                                        groupID = ((ExclusiveGroupStruct)@group).id;
                                    }
                                    else
                                    if (typeOfExclusiveGroupStruct.IsAssignableFrom(field.FieldType))
                                    {
                                        var group = (ExclusiveGroupStruct)field.GetValue(null);
                                        groupID = @group.id;
                                    }
                                    else
                                    {
                                        var group = (ExclusiveBuildGroup)field.GetValue(null);
                                        groupID = ((ExclusiveGroupStruct)@group).id;
                                    }

                                    {
                                        ExclusiveGroupStruct group = new ExclusiveGroupStruct(groupID);
#if DEBUG && !PROFILE_SVELTO
                                        if (GroupNamesMap.idToName.ContainsKey(@group) == false)
                                        {
                                            GroupNamesMap.idToName[@group] =
                                                $"{type.FullName}.{field.Name} {@group.id})";
                                        }
#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
                                        RegisterGroup(@group, $"{type.FullName}.{field.Name}");
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    Console.LogDebugWarning(
                        "something went wrong while gathering group names on the assembly: ".FastConcat(
                            assembly.FullName));
                }
            }
        }