예제 #1
0
        private Type PrepareFieldType(Type originalType)
        {
            var cppType = CppTypes.GetCppType(originalType);

            if (originalType.IsGenericType)
            {
                return(cppType.GetGenericTypeDefinition().MakeGenericType(cppType.GenericTypeArguments.Select(gp => PrepareFieldType(gp)).ToArray()));
            }

            if (cppType.Assembly == Assembly.GetExecutingAssembly() && !cppType.Assembly.IsDynamic)
            {
                return(CppTypes.CreateType("UF::" + RenameType(cppType)));
            }

            return(cppType);
        }
예제 #2
0
        private void WriteFieldDeclaration(string name, UpdateField declarationType)
        {
            var    fieldGeneratedType = CppTypes.GetCppType(declarationType.Type);
            string typeName;

            if (_writeUpdateMasks)
            {
                var bit = CppTypes.CreateConstantForTemplateParameter(_fieldBitIndex[name][0]);
                if (fieldGeneratedType.IsArray)
                {
                    if (typeof(DynamicUpdateField).IsAssignableFrom(fieldGeneratedType.GetElementType()))
                    {
                        var elementType = PrepareFieldType(fieldGeneratedType.GetElementType().GenericTypeArguments[0]);
                        typeName           = TypeHandler.GetFriendlyName(elementType);
                        fieldGeneratedType = _arrayUpdateFieldType.MakeGenericType(
                            _dynamicUpdateFieldBaseType.MakeGenericType(elementType),
                            CppTypes.CreateConstantForTemplateParameter(declarationType.Size),
                            bit,
                            CppTypes.CreateConstantForTemplateParameter(_fieldBitIndex[name][1]));
                    }
                    else
                    {
                        var elementType = PrepareFieldType(fieldGeneratedType.GetElementType());
                        typeName           = TypeHandler.GetFriendlyName(elementType);
                        fieldGeneratedType = _arrayUpdateFieldType.MakeGenericType(elementType,
                                                                                   CppTypes.CreateConstantForTemplateParameter(declarationType.Size),
                                                                                   bit,
                                                                                   CppTypes.CreateConstantForTemplateParameter(_fieldBitIndex[name][1]));
                    }
                }
                else if (typeof(DynamicUpdateField).IsAssignableFrom(declarationType.Type))
                {
                    var elementType = PrepareFieldType(fieldGeneratedType.GenericTypeArguments[0]);
                    typeName           = TypeHandler.GetFriendlyName(elementType);
                    fieldGeneratedType = _dynamicUpdateFieldType.MakeGenericType(PrepareFieldType(fieldGeneratedType.GenericTypeArguments[0]),
                                                                                 CppTypes.CreateConstantForTemplateParameter(_fieldBitIndex[name][1]),
                                                                                 bit);
                }
                else if (typeof(BlzOptionalField).IsAssignableFrom(declarationType.Type))
                {
                    var elementType = PrepareFieldType(fieldGeneratedType.GenericTypeArguments[0]);
                    typeName           = TypeHandler.GetFriendlyName(elementType);
                    fieldGeneratedType = _optionalUpdateFieldType.MakeGenericType(elementType,
                                                                                  CppTypes.CreateConstantForTemplateParameter(_fieldBitIndex[name][1]),
                                                                                  bit);
                }
                else
                {
                    var elementType = PrepareFieldType(declarationType.Type);
                    typeName           = TypeHandler.GetFriendlyName(elementType);
                    fieldGeneratedType = _updateFieldType.MakeGenericType(PrepareFieldType(declarationType.Type),
                                                                          CppTypes.CreateConstantForTemplateParameter(_fieldBitIndex[name][1]),
                                                                          bit);
                }

                _header.WriteLine($"    {TypeHandler.GetFriendlyName(fieldGeneratedType)} {name};");
            }
            else if (fieldGeneratedType.IsArray)
            {
                typeName = TypeHandler.GetFriendlyName(fieldGeneratedType.GetElementType());
                _header.WriteLine($"    {typeName} {name}[{declarationType.Size}];");
            }
            else
            {
                typeName = TypeHandler.GetFriendlyName(fieldGeneratedType);
                _header.WriteLine($"    {typeName} {name};");
            }

            if ((declarationType.CustomFlag & CustomUpdateFieldFlag.ViewerDependent) != CustomUpdateFieldFlag.None)
            {
                _header.WriteLine($"    struct {name}Tag : ViewerDependentValueTag<{typeName}> {{}};");
            }
        }