Example #1
0
        private static void GenerateCsharpContent(ParseResult parseResult, CodeGenBuilders builders)
        {
            CppParser.CppStruct cppStruct = parseResult.structs[0];

            // CS: Generate struct
            string allMembers = "";

            foreach (var member in cppStruct.members)
            {
                if (String.IsNullOrEmpty(member))
                {
                    throw new Exception(string.Format("Struct {0} has a blank member, perhaps an unsupported type when converting C++ to C#", cppStruct.name));
                }
                allMembers += string.Format("\tpublic {0}\n", member);
            }

            string structFormat =
                "public struct {0}\n" +
                "{{\n" +
                "{1}" +
                "}}\n";

            builders.Csharp.Structs.Append(string.Format(structFormat, cppStruct.name, allMembers));

            // CS: Generate delegate state/components
            string delegateReturnType = cppStruct.name;
            string delegateParam      = ECSParseResultUtilities.IsStateFile(parseResult.rawText) ?
                                        "" :
                                        "UInt32 entity";
            string getFunctionName      = GenerateGetFunctionName(ECSParseResultUtilities.IsStateFile(parseResult.rawText), cppStruct.name);
            string delegateDelclaration = string.Format(
                "\t[UnmanagedFunctionPointer(CallingConvention.Cdecl)]\n" +
                "\tpublic delegate {0} {1}Type({2});\n" +
                "\tpublic static {1}Type {1};\n\n",
                delegateReturnType,
                getFunctionName,
                delegateParam);

            builders.Csharp.DelegateDeclaration.Append(delegateDelclaration);

            // CS: Generate getter state/components
            string delegateAssignment = string.Format(
                "\t\t{0} = Bindings.GetDelegate<{0}Type>(libraryHandle, \"{0}\");\n",
                getFunctionName
                );

            builders.Csharp.DelegateAssignment.Append(delegateAssignment);
        }
Example #2
0
        private static void GenerateCppContent(ParseResult parseResult, CodeGenBuilders builders)
        {
            string include = string.Format("#include \"Components/{0}\"\n", parseResult.fileName);

            builders.Cpp.HeaderFiles.Append(include);

            // CPP: Generate functionName
            string componentTypeName = parseResult.structs[0].name;
            string getFunctionName   = GenerateGetFunctionName(ECSParseResultUtilities.IsStateFile(parseResult.rawText), componentTypeName);

            // CPP: Get component/state
            if (ECSParseResultUtilities.IsComponentFile(parseResult.rawText))
            {
                builders.Cpp.GetComponentFunctions.Append(string.Format("DEFINE_GET_COMPONENT({0}, {1})\n", componentTypeName, getFunctionName));
            }
            else if (ECSParseResultUtilities.IsStateFile(parseResult.rawText))
            {
                builders.Cpp.GetStateFunctions.Append(string.Format("DEFINE_GET_GAME_STATE({0}, {1})\n", componentTypeName, getFunctionName));
            }
        }