Ejemplo n.º 1
0
        public new void Update()
        {
            orig_Update();
            string path;

            try {
                path = Path.Combine("Maps", SaveData.Instance?.LastArea.GetSID() ?? "").Replace('\\', '/');
            } catch (ArgumentException) {
                path = "Maps";
            }
            if (SaveData.Instance != null && Everest.Content.TryGet(path, out ModAsset asset))
            {
                MapMeta meta;
                if (asset != null && (meta = asset.GetMeta <MapMeta>()) != null && meta.Mountain != null && hasCustomSettings(meta))
                {
                    MountainResources resources = MTNExt.MountainMappings[path];
                    customFog.Rotate((0f - Engine.DeltaTime) * 0.01f);
                    customFog.TopColor = (customFog.BotColor = Color.Lerp((resources.MountainStates?[currState] ?? mountainStates[currState]).FogColor, (resources.MountainStates?[nextState] ?? mountainStates[nextState]).FogColor, easeState));
                    customFog2.Rotate((0f - Engine.DeltaTime) * 0.01f);
                    customFog2.TopColor = (customFog2.BotColor = Color.White * 0.3f * NearFogAlpha);
                    customStarstream1.Rotate(Engine.DeltaTime * 0.01f);
                    customStarstream2.Rotate(Engine.DeltaTime * 0.02f);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the custom mountain textures for mods.
        /// </summary>
        public static void LoadMod()
        {
            if (!ModsLoaded)
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                lock (Everest.Content.Map) {
                    foreach (KeyValuePair <string, ModAsset> kvp in Everest.Content.Map)
                    {
                        MapMeta meta;
                        // Check if the meta for this asset exists and if it has a MountainTextureDirectory specified
                        if (kvp.Value != null && (meta = kvp.Value.GetMeta <MapMeta>()) != null && meta.Mountain != null && !string.IsNullOrEmpty(meta.Mountain.MountainTextureDirectory))
                        {
                            // Create the mountain resources for this map if they don't exist already
                            if (!MountainMappings.TryGetValue(kvp.Key, out MountainResources resources))
                            {
                                resources = new MountainResources();
                                MountainMappings.Add(kvp.Key, resources);
                            }

                            resources.MountainTerrainTextures  = new VirtualTexture[3];
                            resources.MountainBuildingTextures = new VirtualTexture[3];
                            resources.MountainSkyboxTextures   = new VirtualTexture[3];
                            for (int i = 0; i < 3; i++)
                            {
                                if (MTN.Mountain.Has(Path.Combine(meta.Mountain.MountainTextureDirectory, "skybox_" + i).Replace('\\', '/')))
                                {
                                    resources.MountainSkyboxTextures[i] = MTN.Mountain[Path.Combine(meta.Mountain.MountainTextureDirectory, "skybox_" + i).Replace('\\', '/')].Texture;
                                }
                                if (MTN.Mountain.Has(Path.Combine(meta.Mountain.MountainTextureDirectory, "mountain_" + i).Replace('\\', '/')))
                                {
                                    resources.MountainTerrainTextures[i] = MTN.Mountain[Path.Combine(meta.Mountain.MountainTextureDirectory, "mountain_" + i).Replace('\\', '/')].Texture;
                                }
                                if (MTN.Mountain.Has(Path.Combine(meta.Mountain.MountainTextureDirectory, "buildings_" + i).Replace('\\', '/')))
                                {
                                    resources.MountainBuildingTextures[i] = MTN.Mountain[Path.Combine(meta.Mountain.MountainTextureDirectory, "buildings_" + i).Replace('\\', '/')].Texture;
                                }
                            }
                            if (MTN.Mountain.Has(Path.Combine(meta.Mountain.MountainTextureDirectory, "fog").Replace('\\', '/')))
                            {
                                resources.MountainFogTexture = MTN.Mountain[Path.Combine(meta.Mountain.MountainTextureDirectory, "fog").Replace('\\', '/')].Texture;
                            }

                            // Use the default textures if no custom ones were loaded
                            resources.MountainStates[0] = new MountainState(resources.MountainTerrainTextures[0] ?? MTN.MountainTerrainTextures[0], resources.MountainBuildingTextures[0] ?? MTN.MountainBuildingTextures[0], resources.MountainSkyboxTextures[0] ?? MTN.MountainSkyboxTextures[0], Calc.HexToColor("010817"));
                            resources.MountainStates[1] = new MountainState(resources.MountainTerrainTextures[1] ?? MTN.MountainTerrainTextures[1], resources.MountainBuildingTextures[1] ?? MTN.MountainBuildingTextures[1], resources.MountainSkyboxTextures[1] ?? MTN.MountainSkyboxTextures[1], Calc.HexToColor("13203E"));
                            resources.MountainStates[2] = new MountainState(resources.MountainTerrainTextures[2] ?? MTN.MountainTerrainTextures[2], resources.MountainBuildingTextures[2] ?? MTN.MountainBuildingTextures[2], resources.MountainSkyboxTextures[2] ?? MTN.MountainSkyboxTextures[2], Calc.HexToColor("281A35"));
                            resources.MountainStates[3] = new MountainState(resources.MountainTerrainTextures[0] ?? MTN.MountainTerrainTextures[0], resources.MountainBuildingTextures[0] ?? MTN.MountainBuildingTextures[0], resources.MountainSkyboxTextures[0] ?? MTN.MountainSkyboxTextures[0], Calc.HexToColor("010817"));
                        }
                    }
                }
                Console.WriteLine(" - MODDED MTN LOAD: " + stopwatch.ElapsedMilliseconds + "ms");
            }
            ModsLoaded = true;
        }
Ejemplo n.º 3
0
        public new void Update()
        {
            orig_Update();

            string path;

            try {
                path = Path.Combine("Maps", SaveData.Instance?.LastArea.GetSID() ?? "").Replace('\\', '/');
            } catch (ArgumentException) {
                path = "Maps";
            }
            if (SaveData.Instance != null && Everest.Content.TryGet(path, out ModAsset asset))
            {
                MapMeta meta;
                if (asset != null && (meta = asset.GetMeta <MapMeta>()) != null && meta.Mountain != null && hasCustomSettings(meta))
                {
                    // the mountain is custom!
                    if (firstUpdate || PreviousSID == (SaveData.Instance?.LastArea.GetSID() ?? ""))
                    {
                        // we aren't fading out, so we can update the fog color.
                        MountainResources resources = MTNExt.MountainMappings[path];
                        Color             fogColor  = (resources.MountainStates?[nextState] ?? mountainStates[nextState]).FogColor;
                        if (firstUpdate || fade == 1f)
                        {
                            // we faded to black, or just came back from a map with a custom mountain: snap the fog color.
                            targetFogColor = fogColor;
                            fogFade        = 1f;
                        }
                        else if (fogColor != targetFogColor)
                        {
                            // the fog color changed! start fading from the current fog color to the new color.
                            previousFogColor = customFog.TopColor;
                            targetFogColor   = fogColor;
                            fogFade          = 0f;
                        }

                        // fade between previousFogColor and targetFogColor.
                        customFog.TopColor = customFog.BotColor = Color.Lerp(previousFogColor, targetFogColor, fogFade);
                        fogFade            = Calc.Approach(fogFade, 1f, Engine.DeltaTime);
                    }

                    // refresh custom mountain objets (rotate the fog, etc)
                    customFog.Rotate((0f - Engine.DeltaTime) * 0.01f);
                    customFog2.Rotate((0f - Engine.DeltaTime) * 0.01f);
                    customFog2.TopColor = (customFog2.BotColor = Color.White * 0.3f * NearFogAlpha);
                    customStarstream1.Rotate(Engine.DeltaTime * 0.01f);
                    customStarstream2.Rotate(Engine.DeltaTime * 0.02f);
                    customStarfog.Rotate(-Engine.DeltaTime * 0.01f);
                }
            }

            firstUpdate = false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Load the custom mountain models for mods.
        /// </summary>
        public static void LoadModData()
        {
            if (!ModsDataLoaded)
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                lock (Everest.Content.Map) {
                    foreach (KeyValuePair <string, ModAsset> kvp in Everest.Content.Map)
                    {
                        MapMeta meta;
                        // Check if the meta for this asset exists and if it has a MountainModelDirectory specified
                        if (kvp.Value != null && (meta = kvp.Value.GetMeta <MapMeta>()) != null && meta.Mountain != null && !string.IsNullOrEmpty(meta.Mountain.MountainModelDirectory))
                        {
                            // Create the mountain resources for this map if they don't exist already
                            if (!MountainMappings.TryGetValue(kvp.Key, out MountainResources resources))
                            {
                                resources = new MountainResources();
                                MountainMappings.Add(kvp.Key, resources);
                            }

                            if (Everest.Content.TryGet(Path.Combine(meta.Mountain.MountainModelDirectory, "mountain"), out ModAsset mountain))
                            {
                                resources.MountainTerrain = ObjModelExt.CreateFromStream(mountain.Stream, Path.Combine(meta.Mountain.MountainModelDirectory, "mountain.obj"));
                            }

                            if (Everest.Content.TryGet(Path.Combine(meta.Mountain.MountainModelDirectory, "buildings"), out ModAsset buildings))
                            {
                                resources.MountainBuildings = ObjModelExt.CreateFromStream(buildings.Stream, Path.Combine(meta.Mountain.MountainModelDirectory, "buildings.obj"));
                            }

                            if (Everest.Content.TryGet(Path.Combine(meta.Mountain.MountainModelDirectory, "mountain_wall"), out ModAsset coreWall))
                            {
                                resources.MountainCoreWall = ObjModelExt.CreateFromStream(coreWall.Stream, Path.Combine(meta.Mountain.MountainModelDirectory, "mountain_wall.obj"));
                            }

                            if (Everest.Content.TryGet(Path.Combine(meta.Mountain.MountainModelDirectory, "bird"), out ModAsset bird))
                            {
                                resources.MountainBird = ObjModelExt.CreateFromStream(bird.Stream, Path.Combine(meta.Mountain.MountainModelDirectory, "bird.obj"));
                            }

                            if (Everest.Content.TryGet(Path.Combine(meta.Mountain.MountainModelDirectory, "moon"), out ModAsset moon))
                            {
                                resources.MountainMoon = ObjModelExt.CreateFromStream(moon.Stream, Path.Combine(meta.Mountain.MountainModelDirectory, "moon.obj"));
                            }
                        }
                    }
                }
                Console.WriteLine(" - MODDED MTN DATA LOAD: " + stopwatch.ElapsedMilliseconds + "ms");
            }

            ModsDataLoaded = true;
        }
Ejemplo n.º 5
0
        public new void Update()
        {
            orig_Update();
            string path = Path.Combine("Maps", SaveData.Instance?.LastArea.GetSID() ?? "").Replace('\\', '/');

            if (SaveData.Instance != null && Everest.Content.TryGet(path, out ModAsset asset))
            {
                MapMeta meta;
                if (asset != null && (meta = asset.GetMeta <MapMeta>()) != null && meta.Mountain != null && !(string.IsNullOrEmpty(meta.Mountain.MountainModelDirectory) && string.IsNullOrEmpty(meta.Mountain.MountainTextureDirectory)))
                {
                    MountainResources resources = MTNExt.MountainMappings[path];
                    customFog.Rotate((0f - Engine.DeltaTime) * 0.01f);
                    customFog.TopColor = (customFog.BotColor = Color.Lerp((resources.MountainStates?[currState] ?? mountainStates[currState]).FogColor, (resources.MountainStates?[nextState] ?? mountainStates[nextState]).FogColor, easeState));
                    customFog2.Rotate((0f - Engine.DeltaTime) * 0.01f);
                    customFog2.TopColor = (customFog2.BotColor = Color.White * 0.3f * NearFogAlpha);
                }
            }
        }
Ejemplo n.º 6
0
        public new void BeforeRender(Scene scene)
        {
            if (vanillaMoonParticles == null)
            {
                // back up the vanilla particles.
                vanillaMoonParticles = (Engine.Scene as Overworld)?.Entities.OfType <MoonParticle3D>().First();
            }

            string path;

            try {
                path = Path.Combine("Maps", SaveData.Instance?.LastArea.GetSID() ?? "").Replace('\\', '/');
            } catch (ArgumentException) {
                path = "Maps";
            }

            string SIDToUse = SaveData.Instance?.LastArea.GetSID() ?? "";
            bool   fadingIn = true;

            // Check if we're changing any mountain parameter
            // If so, we want to fade out and then back in
            if (PreviousSID != null && !(SaveData.Instance?.LastArea.GetSID() ?? "").Equals(PreviousSID))
            {
                MapMetaMountain oldMountain = null;
                MapMetaMountain newMountain = null;
                if (SaveData.Instance != null && Everest.Content.TryGet(path, out ModAsset asset1))
                {
                    MapMeta meta;
                    if (asset1 != null && (meta = asset1.GetMeta <MapMeta>()) != null && meta.Mountain != null)
                    {
                        newMountain = meta.Mountain;
                    }
                }
                string oldPath;
                try {
                    oldPath = Path.Combine("Maps", PreviousSID ?? "").Replace('\\', '/');
                } catch (ArgumentException) {
                    oldPath = "Maps";
                }
                if (SaveData.Instance != null && Everest.Content.TryGet(oldPath, out asset1))
                {
                    MapMeta meta;
                    if (asset1 != null && (meta = asset1.GetMeta <MapMeta>()) != null && meta.Mountain != null)
                    {
                        oldMountain = meta.Mountain;
                    }
                }

                if (oldMountain?.MountainModelDirectory != newMountain?.MountainModelDirectory ||
                    oldMountain?.MountainTextureDirectory != newMountain?.MountainTextureDirectory ||
                    (oldMountain?.FogColors == null) != (newMountain?.FogColors == null) || // only fade to black if one end has custom fog colors and the other doesn't.
                    oldMountain?.StarFogColor != newMountain?.StarFogColor ||
                    (oldMountain?.ShowSnow ?? true) != (newMountain?.ShowSnow ?? true) ||
                    !arrayEqual(oldMountain?.StarStreamColors, newMountain?.StarStreamColors) ||
                    !arrayEqual(oldMountain?.StarBeltColors1, newMountain?.StarBeltColors1) ||
                    !arrayEqual(oldMountain?.StarBeltColors2, newMountain?.StarBeltColors2))
                {
                    if (fade != 1f)
                    {
                        // fade out, and continue using the old mountain during the fadeout.
                        SIDToUse = PreviousSID;
                        path     = oldPath;
                        fade     = Calc.Approach(fade, 1f, Engine.DeltaTime * 4f);
                        fadingIn = false;
                    }
                    else
                    {
                        // start holding the black screen
                        fadeHoldCountdown = .3f;
                    }
                }
            }

            if (fadingIn && fade != 0f)
            {
                if (fadeHoldCountdown <= 0)
                {
                    // fade in
                    fade = Calc.Approach(fade, 0f, Engine.DeltaTime * 4f);
                }
                else
                {
                    // hold the black screen
                    fadeHoldCountdown -= Engine.DeltaTime;
                }
            }

            if (SaveData.Instance != null && Everest.Content.TryGet(path, out ModAsset asset))
            {
                MapMeta meta;
                if (asset != null && (meta = asset.GetMeta <MapMeta>()) != null && meta.Mountain != null && hasCustomSettings(meta))
                {
                    // there is a custom mountain! render it, similarly to vanilla.
                    MountainResources resources = MTNExt.MountainMappings[path];

                    ResetRenderTargets();
                    Quaternion rotation = Camera.Rotation;
                    if (ignoreCameraRotation)
                    {
                        rotation = lastCameraRotation;
                    }
                    Matrix matrix  = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, (float)Engine.Width / (float)Engine.Height, 0.25f, 50f);
                    Matrix matrix2 = Matrix.CreateTranslation(-Camera.Position) * Matrix.CreateFromQuaternion(rotation);
                    Matrix matrix3 = matrix2 * matrix;
                    Forward = Vector3.Transform(Vector3.Forward, Camera.Rotation.Conjugated());
                    Engine.Graphics.GraphicsDevice.SetRenderTarget(buffer);

                    if (StarEase < 1f)
                    {
                        Matrix matrix4 = Matrix.CreateTranslation(0f, 5f - Camera.Position.Y * 1.1f, 0f) * Matrix.CreateFromQuaternion(rotation) * matrix;

                        if (currState == nextState)
                        {
                            (resources.MountainStates?[currState] ?? mountainStates[currState]).Skybox.Draw(matrix4, Color.White);
                        }
                        else
                        {
                            (resources.MountainStates?[currState] ?? mountainStates[currState]).Skybox.Draw(matrix4, Color.White);
                            (resources.MountainStates?[nextState] ?? mountainStates[nextState]).Skybox.Draw(matrix4, Color.White * easeState);
                        }
                        if (currState != nextState)
                        {
                            GFX.FxMountain.Parameters["ease"].SetValue(easeState);
                            GFX.FxMountain.CurrentTechnique = GFX.FxMountain.Techniques["Easing"];
                        }
                        else
                        {
                            GFX.FxMountain.CurrentTechnique = GFX.FxMountain.Techniques["Single"];
                        }
                        Engine.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        Engine.Graphics.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
                        Engine.Graphics.GraphicsDevice.RasterizerState   = MountainRasterizer;
                        GFX.FxMountain.Parameters["WorldViewProj"].SetValue(matrix3);
                        GFX.FxMountain.Parameters["fog"].SetValue(customFog.TopColor.ToVector3());
                        Engine.Graphics.GraphicsDevice.Textures[0]      = (resources.MountainStates?[currState] ?? mountainStates[currState]).TerrainTexture.Texture;
                        Engine.Graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                        if (currState != nextState)
                        {
                            Engine.Graphics.GraphicsDevice.Textures[1]      = (resources.MountainStates?[nextState] ?? mountainStates[nextState]).TerrainTexture.Texture;
                            Engine.Graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
                        }
                        (resources.MountainTerrain ?? MTN.MountainTerrain).Draw(GFX.FxMountain);
                        GFX.FxMountain.Parameters["WorldViewProj"].SetValue(Matrix.CreateTranslation(CoreWallPosition) * matrix3);
                        (resources.MountainCoreWall ?? MTN.MountainCoreWall).Draw(GFX.FxMountain);

                        GFX.FxMountain.Parameters["WorldViewProj"].SetValue(matrix3);
                        for (int i = 0; i < resources.MountainExtraModels.Count; i++)
                        {
                            Engine.Graphics.GraphicsDevice.Textures[0]      = (resources.MountainExtraModelTextures[i][currState] ?? mountainStates[currState].TerrainTexture).Texture;
                            Engine.Graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                            if (currState != nextState)
                            {
                                Engine.Graphics.GraphicsDevice.Textures[1]      = (resources.MountainExtraModelTextures[i][nextState] ?? mountainStates[nextState].TerrainTexture).Texture;
                                Engine.Graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
                            }
                            resources.MountainExtraModels[i].Draw(GFX.FxMountain);
                        }
                        GFX.FxMountain.Parameters["WorldViewProj"].SetValue(matrix3);
                        Engine.Graphics.GraphicsDevice.Textures[0]      = (resources.MountainStates?[currState] ?? mountainStates[currState]).BuildingsTexture.Texture;
                        Engine.Graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                        if (currState != nextState)
                        {
                            Engine.Graphics.GraphicsDevice.Textures[1]      = (resources.MountainStates?[nextState] ?? mountainStates[nextState]).BuildingsTexture.Texture;
                            Engine.Graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
                        }
                        (resources.MountainBuildings ?? MTN.MountainBuildings).Draw(GFX.FxMountain);
                        customFog.Draw(matrix3);
                    }

                    if (StarEase > 0f)
                    {
                        Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null);
                        Draw.Rect(0f, 0f, buffer.Width, buffer.Height, Color.Black * Ease.CubeInOut(Calc.ClampedMap(StarEase, 0f, 0.6f)));
                        Draw.SpriteBatch.End();
                        Matrix matrix5 = Matrix.CreateTranslation(starCenter - Camera.Position) * Matrix.CreateFromQuaternion(rotation) * matrix;
                        float  alpha   = Calc.ClampedMap(StarEase, 0.8f, 1f);
                        customStarsky.Draw(matrix5, CullCCRasterizer, alpha);
                        customStarfog.Draw(matrix5, CullCCRasterizer, alpha);
                        customStardots0.Draw(matrix5, CullCCRasterizer, alpha);
                        customStarstream0.Draw(matrix5, CullCCRasterizer, alpha);
                        customStarstream1.Draw(matrix5, CullCCRasterizer, alpha);
                        customStarstream2.Draw(matrix5, CullCCRasterizer, alpha);
                        Engine.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        Engine.Graphics.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
                        Engine.Graphics.GraphicsDevice.RasterizerState   = CullCRasterizer;
                        Engine.Graphics.GraphicsDevice.Textures[0]       = (resources.MountainMoonTexture ?? MTN.MountainMoonTexture).Texture;
                        Engine.Graphics.GraphicsDevice.SamplerStates[0]  = SamplerState.LinearClamp;
                        GFX.FxMountain.CurrentTechnique = GFX.FxMountain.Techniques["Single"];
                        GFX.FxMountain.Parameters["WorldViewProj"].SetValue(matrix3);
                        GFX.FxMountain.Parameters["fog"].SetValue(fog.TopColor.ToVector3());
                        (resources.MountainMoon ?? MTN.MountainMoon).Draw(GFX.FxMountain);
                        float  num     = birdTimer * 0.2f;
                        Matrix matrix6 = Matrix.CreateScale(0.25f) * Matrix.CreateRotationZ((float)Math.Cos(num * 2f) * 0.5f) * Matrix.CreateRotationX(0.4f + (float)Math.Sin(num) * 0.05f) * Matrix.CreateRotationY(0f - num - (float)Math.PI / 2f) * Matrix.CreateTranslation((float)Math.Cos(num) * 2.2f, 31f + (float)Math.Sin(num * 2f) * 0.8f, (float)Math.Sin(num) * 2.2f);
                        GFX.FxMountain.Parameters["WorldViewProj"].SetValue(matrix6 * matrix3);
                        GFX.FxMountain.Parameters["fog"].SetValue(fog.TopColor.ToVector3());
                        (resources.MountainBird ?? MTN.MountainBird).Draw(GFX.FxMountain);
                    }

                    DrawBillboards(matrix3, scene.Tracker.GetComponents <Billboard>());

                    if (StarEase < 1f)
                    {
                        customFog2.Draw(matrix3, CullCRasterizer);
                    }

                    if (DrawDebugPoints && DebugPoints.Count > 0)
                    {
                        GFX.FxDebug.World              = Matrix.Identity;
                        GFX.FxDebug.View               = matrix2;
                        GFX.FxDebug.Projection         = matrix;
                        GFX.FxDebug.TextureEnabled     = false;
                        GFX.FxDebug.VertexColorEnabled = true;
                        VertexPositionColor[] array = DebugPoints.ToArray();
                        foreach (EffectPass pass in GFX.FxDebug.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            Engine.Graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, array, 0, array.Length / 3);
                        }
                    }
                    GaussianBlur.Blur((RenderTarget2D)buffer, blurA, blurB, 0.75f, clear: true, samples: GaussianBlur.Samples.Five);

                    // render the fade to black.
                    Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null);
                    Draw.Rect(-10f, -10f, 1940f, 1100f, Color.Black * fade);
                    Draw.SpriteBatch.End();

                    // Initialize new custom fog and star belt when we switch between maps
                    if (!(SIDToUse).Equals(PreviousSID))
                    {
                        // save values to make transition smoother.
                        Color fogColorBeforeReload = customFog?.TopColor ?? Color.White;
                        float spinBeforeReload     = customFog.Verts[1].TextureCoordinate.X;

                        // build new objects with custom textures.
                        customFog         = new Ring(6f, -1f, 20f, 0f, 24, Color.White, resources.MountainFogTexture ?? MTN.MountainFogTexture);
                        customFog2        = new Ring(6f, -4f, 10f, 0f, 24, Color.White, resources.MountainFogTexture ?? MTN.MountainFogTexture);
                        customStarsky     = new Ring(18f, -18f, 20f, 0f, 24, Color.White, Color.Transparent, resources.MountainSpaceTexture ?? MTN.MountainStarSky);
                        customStarfog     = new Ring(10f, -18f, 19.5f, 0f, 24, resources.StarFogColor ?? Calc.HexToColor("020915"), Color.Transparent, resources.MountainFogTexture ?? MTN.MountainFogTexture);
                        customStardots0   = new Ring(16f, -18f, 19f, 0f, 24, Color.White, Color.Transparent, resources.MountainSpaceStarsTexture ?? MTN.MountainStars, 4f);
                        customStarstream0 = new Ring(5f, -8f, 18.5f, 0.2f, 80, resources.StarStreamColors?[0] ?? Color.Black, resources.MountainStarStreamTexture ?? MTN.MountainStarStream);
                        customStarstream1 = new Ring(4f, -6f, 18f, 1f, 80, resources.StarStreamColors?[1] ?? Calc.HexToColor("9228e2") * 0.5f, resources.MountainStarStreamTexture ?? MTN.MountainStarStream);
                        customStarstream2 = new Ring(3f, -4f, 17.9f, 1.4f, 80, resources.StarStreamColors?[2] ?? Calc.HexToColor("30ffff") * 0.5f, resources.MountainStarStreamTexture ?? MTN.MountainStarStream);

                        // restore values saved earlier.
                        customFog.TopColor = customFog.BotColor = fogColorBeforeReload;
                        customFog.Rotate(spinBeforeReload);
                        customFog2.Rotate(spinBeforeReload);

                        if (Engine.Scene is Overworld thisOverworld)
                        {
                            thisOverworld.Remove(customMoonParticles);
                            if (resources.StarBeltColors1 != null && resources.StarBeltColors2 != null)
                            {
                                // there are custom moon particle colors. build the new particles and add them to the scene
                                thisOverworld.Remove(vanillaMoonParticles);
                                thisOverworld.Add(customMoonParticles = new patch_MoonParticle3D(this, new Vector3(0f, 31f, 0f), resources.StarBeltColors1, resources.StarBeltColors2));
                            }
                            else
                            {
                                // there are no more moon particle colors. restore the vanilla particles
                                customMoonParticles = null;
                                thisOverworld.Add(vanillaMoonParticles);
                            }
                        }
                    }

                    PreviousSID = SIDToUse;
                    return;
                }
            }

            // if we are here, it means we don't have a custom mountain.

            if (customMoonParticles != null && Engine.Scene is Overworld overworld)
            {
                // revert back the moon particles to vanilla.
                overworld.Remove(customMoonParticles);
                customMoonParticles = null;
                overworld.Add(vanillaMoonParticles);
            }

            // run vanilla code.
            orig_BeforeRender(scene);

            // render the fade to black.
            Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null);
            Draw.Rect(-10f, -10f, 1940f, 1100f, Color.Black * fade);
            Draw.SpriteBatch.End();

            PreviousSID = SIDToUse;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Load the custom mountain models for mods.
        /// </summary>
        public static void LoadModData()
        {
            if (!ModsDataLoaded)
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                lock (Everest.Content.Map) {
                    foreach (KeyValuePair <string, ModAsset> kvp in Everest.Content.Map)
                    {
                        MapMeta meta;
                        // Check if the meta for this asset exists and if it has a MountainModelDirectory specified
                        if (kvp.Value != null && (meta = kvp.Value.GetMeta <MapMeta>()) != null && meta.Mountain != null && !string.IsNullOrEmpty(meta.Mountain.MountainModelDirectory))
                        {
                            // Create the mountain resources for this map if they don't exist already
                            if (!MountainMappings.TryGetValue(kvp.Key, out MountainResources resources))
                            {
                                resources = new MountainResources();
                                MountainMappings.Add(kvp.Key, resources);
                            }

                            if (resolveModel(meta, "mountain", out ModAsset mountain, out string mountainPath))
                            {
                                resources.MountainTerrain = loadModelFile(mountain, mountainPath);
                            }

                            if (resolveModel(meta, "buildings", out ModAsset buildings, out string buildingsPath))
                            {
                                resources.MountainBuildings = loadModelFile(buildings, buildingsPath);
                            }

                            if (resolveModel(meta, "mountain_wall", out ModAsset coreWall, out string coreWallPath))
                            {
                                resources.MountainCoreWall = loadModelFile(coreWall, coreWallPath);
                            }

                            if (resolveModel(meta, "bird", out ModAsset bird, out string birdPath))
                            {
                                resources.MountainBird = loadModelFile(bird, birdPath);
                            }

                            if (resolveModel(meta, "moon", out ModAsset moon, out string moonPath))
                            {
                                resources.MountainMoon = loadModelFile(moon, moonPath);
                            }

                            resources.MountainExtraModels.Clear();
                            resources.MountainExtraModelTextures.Clear();

                            while (resolveModel(meta, "extra" + resources.MountainExtraModels.Count, out ModAsset extra, out string extraPath))
                            {
                                // load the extra model.
                                int extraIndex = resources.MountainExtraModels.Count;
                                resources.MountainExtraModels.Add(loadModelFile(extra, extraPath));

                                // load the textures associated with the extra model.
                                VirtualTexture[] textures = new VirtualTexture[4];
                                for (int i = 0; i < 4; i++)
                                {
                                    if (MTN.Mountain.Has(Path.Combine(meta.Mountain.MountainTextureDirectory, "extra" + extraIndex + "_" + i).Replace('\\', '/')))
                                    {
                                        textures[i] = MTN.Mountain[Path.Combine(meta.Mountain.MountainTextureDirectory, "extra" + extraIndex + "_" + i).Replace('\\', '/')].Texture;
                                    }
                                }
                                resources.MountainExtraModelTextures.Add(textures);
                            }
                        }
                    }
                }
                Console.WriteLine(" - MODDED MTN DATA LOAD: " + stopwatch.ElapsedMilliseconds + "ms");
            }

            ModsDataLoaded = true;
        }
Ejemplo n.º 8
0
        public new void BeforeRender(Scene scene)
        {
            string path     = Path.Combine("Maps", SaveData.Instance?.LastArea.GetSID() ?? "").Replace('\\', '/');
            string SIDToUse = SaveData.Instance?.LastArea.GetSID() ?? "";
            bool   fadingIn = true;

            // Check if we're changing mountain models or textures
            // If so, we want to fade out and then back in
            if (!(SaveData.Instance?.LastArea.GetSID() ?? "").Equals(PreviousSID))
            {
                string oldModelDir = "", oldTextureDir = "", newModelDir = "", newTextureDir = "";
                if (SaveData.Instance != null && Everest.Content.TryGet(path, out ModAsset asset1))
                {
                    MapMeta meta;
                    if (asset1 != null && (meta = asset1.GetMeta <MapMeta>()) != null && meta.Mountain != null)
                    {
                        newModelDir   = meta.Mountain.MountainModelDirectory ?? "";
                        newTextureDir = meta.Mountain.MountainTextureDirectory ?? "";
                    }
                }
                string oldPath = Path.Combine("Maps", PreviousSID ?? "").Replace('\\', '/');
                if (SaveData.Instance != null && Everest.Content.TryGet(oldPath, out asset1))
                {
                    MapMeta meta;
                    if (asset1 != null && (meta = asset1.GetMeta <MapMeta>()) != null && meta.Mountain != null)
                    {
                        oldModelDir   = meta.Mountain.MountainModelDirectory ?? "";
                        oldTextureDir = meta.Mountain.MountainTextureDirectory ?? "";
                    }
                }

                if (!oldModelDir.Equals(newModelDir) || !oldTextureDir.Equals(newTextureDir))
                {
                    if (fade != 1f)
                    {
                        SIDToUse = PreviousSID;
                        path     = oldPath;
                        fade     = Calc.Approach(fade, 1f, Engine.DeltaTime * 4f);
                        fadingIn = false;
                    }
                    else
                    {
                        // How long we want it to stay opaque before fading back in
                        fadeHoldCountdown = .3f;
                    }
                }
            }

            if (fadingIn && fade != 0f)
            {
                if (fadeHoldCountdown <= 0)
                {
                    fade = Calc.Approach(fade, 0f, Engine.DeltaTime * 4f);
                }
                else
                {
                    fadeHoldCountdown -= Engine.DeltaTime;
                }
            }

            if (SaveData.Instance != null && Everest.Content.TryGet(path, out ModAsset asset))
            {
                MapMeta meta;
                if (asset != null && (meta = asset.GetMeta <MapMeta>()) != null && meta.Mountain != null && !(string.IsNullOrEmpty(meta.Mountain.MountainModelDirectory) && string.IsNullOrEmpty(meta.Mountain.MountainTextureDirectory)))
                {
                    MountainResources resources = MTNExt.MountainMappings[path];

                    ResetRenderTargets();
                    Quaternion rotation = Camera.Rotation;
                    if (ignoreCameraRotation)
                    {
                        rotation = lastCameraRotation;
                    }
                    Matrix matrix  = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, (float)Engine.Width / (float)Engine.Height, 0.25f, 50f);
                    Matrix matrix2 = Matrix.CreateTranslation(-Camera.Position) * Matrix.CreateFromQuaternion(rotation);
                    Matrix matrix3 = matrix2 * matrix;
                    Forward = Vector3.Transform(Vector3.Forward, Camera.Rotation.Conjugated());
                    Engine.Graphics.GraphicsDevice.SetRenderTarget(buffer);

                    Matrix matrix4 = Matrix.CreateTranslation(0f, 5f - Camera.Position.Y * 1.1f, 0f) * Matrix.CreateFromQuaternion(rotation) * matrix;

                    if (currState == nextState)
                    {
                        (resources.MountainStates?[currState] ?? mountainStates[currState]).Skybox.Draw(matrix4, Color.White);
                    }
                    else
                    {
                        (resources.MountainStates?[currState] ?? mountainStates[currState]).Skybox.Draw(matrix4, Color.White);
                        (resources.MountainStates?[currState] ?? mountainStates[currState]).Skybox.Draw(matrix4, Color.White * easeState);
                    }
                    if (currState != nextState)
                    {
                        GFX.FxMountain.Parameters["ease"].SetValue(easeState);
                        GFX.FxMountain.CurrentTechnique = GFX.FxMountain.Techniques["Easing"];
                    }
                    else
                    {
                        GFX.FxMountain.CurrentTechnique = GFX.FxMountain.Techniques["Single"];
                    }
                    Engine.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                    Engine.Graphics.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
                    Engine.Graphics.GraphicsDevice.RasterizerState   = MountainRasterizer;
                    GFX.FxMountain.Parameters["WorldViewProj"].SetValue(matrix3);
                    GFX.FxMountain.Parameters["fog"].SetValue(customFog.TopColor.ToVector3());
                    Engine.Graphics.GraphicsDevice.Textures[0]      = (resources.MountainStates?[currState] ?? mountainStates[currState]).TerrainTexture.Texture;
                    Engine.Graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                    if (currState != nextState)
                    {
                        Engine.Graphics.GraphicsDevice.Textures[1]      = (resources.MountainStates?[nextState] ?? mountainStates[nextState]).TerrainTexture.Texture;
                        Engine.Graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
                    }
                    (resources.MountainTerrain ?? MTN.MountainTerrain).Draw(GFX.FxMountain);
                    GFX.FxMountain.Parameters["WorldViewProj"].SetValue(Matrix.CreateTranslation(CoreWallPosition) * matrix3);
                    (resources.MountainCoreWall ?? MTN.MountainCoreWall).Draw(GFX.FxMountain);
                    GFX.FxMountain.Parameters["WorldViewProj"].SetValue(matrix3);
                    Engine.Graphics.GraphicsDevice.Textures[0]      = (resources.MountainStates?[currState] ?? mountainStates[currState]).BuildingsTexture.Texture;
                    Engine.Graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                    if (currState != nextState)
                    {
                        Engine.Graphics.GraphicsDevice.Textures[1]      = (resources.MountainStates?[nextState] ?? mountainStates[nextState]).BuildingsTexture.Texture;
                        Engine.Graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
                    }
                    (resources.MountainBuildings ?? MTN.MountainBuildings).Draw(GFX.FxMountain);
                    customFog.Draw(matrix3);

                    DrawBillboards(matrix3, scene.Tracker.GetComponents <Billboard>());
                    customFog2.Draw(matrix3, CullCRasterizer);

                    if (DrawDebugPoints && DebugPoints.Count > 0)
                    {
                        GFX.FxDebug.World              = Matrix.Identity;
                        GFX.FxDebug.View               = matrix2;
                        GFX.FxDebug.Projection         = matrix;
                        GFX.FxDebug.TextureEnabled     = false;
                        GFX.FxDebug.VertexColorEnabled = true;
                        VertexPositionColor[] array = DebugPoints.ToArray();
                        foreach (EffectPass pass in GFX.FxDebug.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            Engine.Graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, array, 0, array.Length / 3);
                        }
                    }
                    GaussianBlur.Blur((RenderTarget2D)buffer, blurA, blurB, 0.75f, clear: true, samples: GaussianBlur.Samples.Five);

                    Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null);
                    Draw.Rect(-10f, -10f, 1940f, 1100f, Color.Black * fade);
                    Draw.SpriteBatch.End();

                    // Initialize new custom fog when we switch between maps
                    if (!(SIDToUse).Equals(PreviousSID) && resources.MountainFogTexture != null)
                    {
                        customFog  = new Ring(6f, -1f, 20f, 0f, 24, Color.White, resources.MountainFogTexture ?? MTN.MountainFogTexture);
                        customFog2 = new Ring(6f, -4f, 10f, 0f, 24, Color.White, resources.MountainFogTexture ?? MTN.MountainFogTexture);
                    }
                    PreviousSID = SIDToUse;
                    return;
                }
            }

            orig_BeforeRender(scene);

            Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null);
            Draw.Rect(-10f, -10f, 1940f, 1100f, Color.Black * fade);
            Draw.SpriteBatch.End();

            PreviousSID = SIDToUse;
        }