示例#1
0
        private static ICodeBlock GetAllFactoryMethods(string factoryClassName, string baseClassName, int numberToPreAllocate, bool poolObjects)
        {
            string className = factoryClassName.Substring(0, factoryClassName.Length - "Factory".Length);

            ICodeBlock codeBlock = new CodeDocument();

            codeBlock.Line("public static FlatRedBall.Math.Axis? SortAxis { get; set;}");

            GetCreateNewFactoryMethod(codeBlock, factoryClassName, poolObjects, baseClassName);
            codeBlock._();
            GetInitializeFactoryMethod(codeBlock, className, poolObjects, "mScreenListReference");
            codeBlock._();

            GetDestroyFactoryMethod(codeBlock, factoryClassName);
            codeBlock._();
            GetFactoryInitializeMethod(codeBlock, factoryClassName, numberToPreAllocate);
            codeBlock._();
            GetMakeUnusedFactory(codeBlock, factoryClassName, poolObjects);
            codeBlock._();


            string whereClass = className;

            if (!string.IsNullOrEmpty(baseClassName))
            {
                whereClass = baseClassName.Replace("\\", ".");
            }
            AddAddListMethod(codeBlock, whereClass);
            AddRemoveListMethod(codeBlock, whereClass);
            AddClearListsToAddTo(codeBlock);

            return(codeBlock);
        }
        private static ICodeBlock GetAllFactoryMethods(string factoryClassName, string baseClassName, int numberToPreAllocate, bool poolObjects)
        {
            string className = factoryClassName.Substring(0, factoryClassName.Length - "Factory".Length);

            ICodeBlock codeBlock = new CodeDocument();

            GetCreateNewFactoryMethod(codeBlock, factoryClassName, poolObjects, baseClassName);
            codeBlock._();
            GetInitializeFactoryMethod(codeBlock, className, poolObjects, "mScreenListReference");
            codeBlock._();

            if (!string.IsNullOrEmpty(baseClassName))
            {
                GetInitializeFactoryMethod(codeBlock, FileManager.RemovePath(baseClassName), poolObjects, "mBaseScreenListReference");
                codeBlock._();
            }

            GetDestroyFactoryMethod(codeBlock, factoryClassName);
            codeBlock._();
            GetFactoryInitializeMethod(codeBlock, factoryClassName, numberToPreAllocate);
            codeBlock._();
            GetMakeUnusedFactory(codeBlock, factoryClassName, poolObjects);

            return(codeBlock);
        }
示例#3
0
        private static ICodeBlock GetGlobalContentFilesMethods()
        {
            ICodeBlock codeBlock       = new CodeDocument();
            var        currentBlock    = codeBlock;
            var        classLevelBlock = currentBlock;

            codeBlock._();

            // Don't use foreach to make this tolerate changes to the collection while it generates
            //foreach (ReferencedFileSave rfs in ProjectManager.GlueProjectSave.GlobalFiles)
            for (int i = 0; i < ProjectManager.GlueProjectSave.GlobalFiles.Count; i++)
            {
                ReferencedFileSave rfs = ProjectManager.GlueProjectSave.GlobalFiles[i];

                ReferencedFileSaveCodeGenerator.AppendFieldOrPropertyForReferencedFile(currentBlock, rfs, null);
            }

            const bool inheritsFromElement = false;

            ReferencedFileSaveCodeGenerator.GenerateGetStaticMemberMethod(ProjectManager.GlueProjectSave.GlobalFiles, currentBlock, true, inheritsFromElement);
            ReferencedFileSaveCodeGenerator.GenerateGetFileMethodByName(
                ProjectManager.GlueProjectSave.GlobalFiles, currentBlock, false, "GetFile", false);
            if (ProjectManager.GlueProjectSave.GlobalContentSettingsSave.RecordLockContention)
            {
                currentBlock.Line("public static List<string> LockRecord = new List<string>();");
            }

            currentBlock
            .AutoProperty("public static bool", "IsInitialized", "", "private");

            currentBlock
            .AutoProperty("public static bool", "ShouldStopLoading");

            currentBlock.Line("const string ContentManagerName = \"Global\";");

            var initializeFunction =
                currentBlock.Function("public static void", "Initialize", "");

            currentBlock = initializeFunction
                           ._();

            foreach (var generator in CodeWriter.GlobalContentCodeGenerators)
            {
                generator.GenerateInitializeStart(initializeFunction);
            }


            //stringBuilder.AppendLine("\t\t\tstring ContentManagerName = \"Global\";");

            // Do the high-proprity loads first
            // Update May 10, 2011
            // If loading asynchronously
            // the first Screen may load before
            // we even get to the high-priority RFS's
            // (which are localization).  This could cause
            // the first Screen to have unlocalized text.  That's
            // why we want to load it before we even start our async loading.
            foreach (ReferencedFileSave rfs in ProjectManager.GlueProjectSave.GlobalFiles)
            {
                if (ReferencedFileSaveCodeGenerator.IsRfsHighPriority(rfs))
                {
                    ReferencedFileSaveCodeGenerator.GetInitializationForReferencedFile(rfs, null, initializeFunction, LoadType.CompleteLoad);
                }
            }

            bool loadAsync = GenerateLoadAsyncCode(classLevelBlock, initializeFunction);

            if (GlobalContentCodeGenerator.SuppressGlobalContentDictionaryRefresh == false)
            {
                ReferencedFileSaveCodeGenerator.RefreshGlobalContentDictionary();
            }

            if (loadAsync)
            {
                currentBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");
            }

            foreach (ReferencedFileSave rfs in ProjectManager.GlueProjectSave.GlobalFiles)
            {
                if (!ReferencedFileSaveCodeGenerator.IsRfsHighPriority(rfs) && rfs.LoadedAtRuntime)
                {
                    var blockToUse = initializeFunction;

                    if (loadAsync)
                    {
                        blockToUse = classLevelBlock
                                     .Function("static void", "Load" + rfs.Name.Replace("/", "_").Replace(".", "_"), "");
                    }


                    ReferencedFileSaveCodeGenerator.GetInitializationForReferencedFile(rfs, null, blockToUse, LoadType.CompleteLoad);

                    if (loadAsync)
                    {
                        blockToUse.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");

                        blockToUse.Line("m" + rfs.GetInstanceName() + "Mre.Set();");
                        blockToUse.Line("#endif");

                        blockToUse.End();
                    }
                }
            }

            if (loadAsync)
            {
                currentBlock.Line("#endif");
            }

            if (!loadAsync)
            {
                currentBlock = currentBlock
                               .Line("\t\t\tIsInitialized = true;")
                               .End();
            }


            GenerateReloadFileMethod(classLevelBlock);



            foreach (var generator in CodeWriter.GlobalContentCodeGenerators)
            {
                generator.GenerateInitializeEnd(initializeFunction);
                generator.GenerateAdditionalMethods(classLevelBlock);
            }

            return(codeBlock);
        }