Example #1
0
        private static void UnloadMenuBackdrop()
        {
            if (cameraLight != null)
            {
                AssetLocator.LightPass.RemoveLight(cameraLight);
                cameraLight = null;
            }

            if (!inDeferenceMode)
            {
                if (loadedMenuBackdrop != null)
                {
                    GameCoordinator.PassMenuBackdropAsSkybox(loadedMenuBackdrop);
                }
                loadedMenuBackdrop = null;
                AssetLocator.LightPass.SetLensProperties(Config.DofLensFocalDist, Config.DofLensMaxBlurDist);
                AssetLocator.ShadowcasterCamera.OrthographicDimensions = new Vector3(1000f, 1000f, PhysicsManager.ONE_METRE_SCALED * 100f);
            }

            foreach (var bit in activeSillyBits)
            {
                bit.Dispose();
            }
            activeSillyBits.Clear();
            worldIconTex.SetAlpha(0f);
            versionString.SetAlpha(0f);
        }
Example #2
0
        public static void LoadMenuFrontend(SkyLevelDescription preloadedSky = null, MenuState entryPointMenu = MenuState.MainMenu, Action deferenceModeAction = null)
        {
            lock (staticMutationLock) {
                MenuCoordinator.deferenceModeAction = deferenceModeAction;
                inDeferenceMode = deferenceModeAction != null;
                if (!inDeferenceMode)
                {
                    WorldModelCache.ClearAndDisposeCache();
                }
                LoadMenuBackdrop(preloadedSky ?? loadedMenuBackdrop);
                switch (entryPointMenu)
                {
                case MenuState.PlayMenu: PlayMenuTransitionIn(); break;

                case MenuState.MedalsMenu: MedalsMenuTransitionIn(); break;

                case MenuState.OptionsMenu: OptionsTransitionIn(); break;

                default: MainMenuTransitionIn(); break;
                }
            }
        }
Example #3
0
        private static void LoadMenuBackdrop(SkyLevelDescription preloadedSky)
        {
            UnloadMenuBackdrop();

            if (!inDeferenceMode)
            {
                cameraLight = new Light(Vector3.ZERO, CAMERA_LIGHT_RADIUS, Vector3.ONE * CAMERA_LIGHT_INTENSITY);
                AssetLocator.LightPass.AddLight(cameraLight);
                //AssetLoader.ClearCache(); // TODO work out whether we really need this line?
                if (!Single.IsPositiveInfinity(Config.DofLensMaxBlurDist))
                {
                    AssetLocator.LightPass.SetLensProperties(DOF_FOCAL_DIST, DOF_MAX_DIST);
                }
                AssetLocator.MainCamera.Position         = Vector3.ZERO + Vector3.DOWN * BACKDROP_CAM_VERTICAL_OFFSET;
                AssetLocator.ShadowcasterCamera.Position = Vector3.UP * SILLY_BIT_DROP_HEIGHT * 1.1f;
                AssetLocator.ShadowcasterCamera.LookAt(Vector3.DOWN, Vector3.FORWARD);
                AssetLocator.ShadowcasterCamera.OrthographicDimensions = new Vector3(100f, 100f, PhysicsManager.ONE_METRE_SCALED * 3f);
                Quaternion downTilt = Quaternion.FromAxialRotation(Vector3.LEFT, BACKDROP_CAM_UPWARD_TILT);
                AssetLocator.MainCamera.Orient(Vector3.FORWARD * downTilt, Vector3.UP * downTilt);
                BGMManager.CrossFadeToTitleMusic();
                mainMenuSinceLoad = false;
            }

            if (preloadedSky != null)
            {
                loadedMenuBackdrop = preloadedSky;
            }
            else
            {
                int worldIndex = RandomProvider.Next(0, PersistedWorldData.GetFurthestUnlockedWorldIndex() + 1);
                loadedMenuBackdrop = (SkyLevelDescription)LevelDescription.Load(
                    Path.Combine(AssetLocator.LevelsDir, LevelDatabase.SkyboxFileNames[worldIndex])
                    );
                loadedMenuBackdrop.ReinitializeAll();
                worldIconTex.Texture = AssetLocator.WorldIcons[worldIndex];
            }
        }
Example #4
0
        public static LevelDescription Load(string fullFilePath, bool includePTD = true)
        {
            if (!IOUtils.IsValidFilePath(fullFilePath))
            {
                throw new ArgumentException("File path is not valid.", "fullFilePath");
            }
            XDocument        loadFile         = XDocument.Load(fullFilePath);
            XElement         metaElement      = loadFile.Root.Element(FILE_ELEMENT_NAME_META);
            XElement         geometryElement  = loadFile.Root.Element(FILE_ELEMENT_NAME_GEOMETRY);
            XElement         materialsElement = loadFile.Root.Element(FILE_ELEMENT_NAME_MATERIALS);
            XElement         entitiesElement  = loadFile.Root.Element(FILE_ELEMENT_NAME_GEOM_ENTITIES);
            LevelDescription loadedLevel;
            string           fileType = metaElement.Element(FILE_ELEMENT_NAME_META_TYPE).Value;
            string           title    = metaElement.Element(FILE_ELEMENT_NAME_META_TITLE).Value;

            if (fileType == FILE_ELEMENT_VALUE_META_TYPE_SKY)
            {
                loadedLevel = new SkyLevelDescription(title);
            }
            else
            {
                loadedLevel = new GameLevelDescription(title);
            }

            lock (loadedLevel.instanceMutationLock) {
                loadedLevel.DeserializeMeta(metaElement);
                loadedLevel.DeserializeGeometry(geometryElement);
                loadedLevel.DeserializeMaterials(materialsElement);
                loadedLevel.DeserializeGeomEntities(entitiesElement);
                loadedLevel.ChildDeserialize(loadFile);
                var fullPTDFilePath = Path.Combine(AssetLocator.LevelsDir, Path.GetFileNameWithoutExtension(fullFilePath)) + ".ptd";
                if (!File.Exists(fullPTDFilePath))
                {
                    if (!EntryPoint.InEditor && loadedLevel is GameLevelDescription)
                    {
                        Logger.Warn("No pretriangulation data found for level '" + fullFilePath + "' -> '" + fullPTDFilePath + "'. Loading time will be longer.");
                    }
                }
                else if (includePTD)
                {
                    GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                    GC.Collect(2, GCCollectionMode.Forced, true);

                    using (FileStream fileStream = File.Open(fullPTDFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        BinaryReader br = new BinaryReader(fileStream);

                        int geomCount = br.ReadInt32();

                        for (int g = 0; g < geomCount; ++g)
                        {
                            int geomID      = br.ReadInt32();
                            int numVertices = br.ReadInt32();
                            int numIndices  = br.ReadInt32();
                            List <DefaultVertex> vertexList = new List <DefaultVertex>(numVertices);
                            List <uint>          indexList  = new List <uint>(numIndices);
                            for (int i = 0; i < numVertices; ++i)
                            {
                                DefaultVertex vert = new DefaultVertex(
                                    position: new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                                    normal: new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                                    texUv: new Vector2(br.ReadSingle(), br.ReadSingle()),
                                    tangent: new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle())
                                    );
                                vertexList.Add(vert);
                            }
                            for (int i = 0; i < numIndices; ++i)
                            {
                                indexList.Add(br.ReadUInt32());
                            }

                            loadedLevel.precalculatedTriangles.Add(geomID, Tuple.Create(vertexList, indexList));
                        }
                    }

                    GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                    GC.Collect(2, GCCollectionMode.Forced, true);
                }
            }

            return(loadedLevel);
        }