From 9d1f96a3a8309558f7e2622bfd8da8ca76d04a69 Mon Sep 17 00:00:00 2001 From: Maddie <52103563+maddie480@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:45:44 +0100 Subject: [PATCH] Tweaks to enhance compatibility with zooming out --- Effects/AllSideTentacles.cs | 4 ++-- Effects/CustomStars.cs | 10 ++++----- Entities/CustomizableGlassBlockController.cs | 23 ++++++++++++-------- Entities/FancyTextTutorial.cs | 2 +- Entities/FlagSwitchGate.cs | 2 +- Entities/MultiNodeFlagSwitchGate.cs | 2 +- Entities/SeekerBarrierColorController.cs | 12 +++++++++- Entities/SidewaysLava.cs | 20 ++++++++--------- Entities/StylegroundFadeController.cs | 10 ++++++++- Triggers/CameraOffsetBorder.cs | 2 +- Triggers/GradientDustTrigger.cs | 2 +- Triggers/OneWayCameraTrigger.cs | 12 +++++----- 12 files changed, 62 insertions(+), 39 deletions(-) diff --git a/Effects/AllSideTentacles.cs b/Effects/AllSideTentacles.cs index 96bb1a0d..43ba7719 100644 --- a/Effects/AllSideTentacles.cs +++ b/Effects/AllSideTentacles.cs @@ -37,9 +37,9 @@ private static void modTentaclesUpdate(ILContext il) { if (player != null) { if (allSideSelf.side == Side.Left) { - return (player.X - camera.X) - 160f; + return (player.X - camera.X) - (GameplayBuffers.Gameplay.Width / 2f); } else if (allSideSelf.side == Side.Top) { - return player.Y - camera.Y - 180f; + return player.Y - camera.Y - GameplayBuffers.Gameplay.Height; } } } diff --git a/Effects/CustomStars.cs b/Effects/CustomStars.cs index 3b2f87b3..963fe249 100644 --- a/Effects/CustomStars.cs +++ b/Effects/CustomStars.cs @@ -62,7 +62,7 @@ public CustomStars(int? starCount, Color? tint, string spriteDirectory, float wr stars = new Star[starCount ?? 100]; for (int i = 0; i < stars.Length; i++) { stars[i] = new Star { - Position = new Vector2(Calc.Random.NextFloat(320f), Calc.Random.NextFloat(wrapHeight)), + Position = new Vector2(Calc.Random.NextFloat(GameplayBuffers.Gameplay.Width), Calc.Random.NextFloat(wrapHeight)), Timer = Calc.Random.NextFloat((float) Math.PI * 2f), Rate = 2f + Calc.Random.NextFloat(2f), TextureSet = Calc.Random.Next(textures.Count) @@ -90,7 +90,7 @@ public override void Update(Scene scene) { public override void Render(Scene scene) { float fadeAlpha = GetFadeAlpha(scene); - Draw.Rect(0f, 0f, 320f, 180f, Color.Black * bgAlpha); + Draw.Rect(0f, 0f, GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height, Color.Black * bgAlpha); Level level = scene as Level; Color color = (tint * (starAlpha ?? 1f)) ?? (level.Session.Dreaming ? Color.Teal * (starAlpha ?? 0.7f) : Color.White); int count = starCount ?? (level.Session.Dreaming ? 100 : 50); @@ -105,9 +105,9 @@ public override void Render(Scene scene) { // parallax X position.X -= level.Camera.X * effectiveScroll.X; - position.X %= 320; + position.X %= GameplayBuffers.Gameplay.Width; if (position.X < 0f) { - position.X += 320; + position.X += GameplayBuffers.Gameplay.Width; } // parallax Y @@ -117,7 +117,7 @@ public override void Render(Scene scene) { if (position.Y < 0f) { position.Y += wrapHeight; } - position.Y -= (wrapHeight - 180f) / 2; + position.Y -= (wrapHeight - GameplayBuffers.Gameplay.Height) / 2; if (level.Session.Dreaming) { for (int j = 0; j < colors.Length; j++) { diff --git a/Entities/CustomizableGlassBlockController.cs b/Entities/CustomizableGlassBlockController.cs index a8673047..9903fb78 100644 --- a/Entities/CustomizableGlassBlockController.cs +++ b/Entities/CustomizableGlassBlockController.cs @@ -138,16 +138,16 @@ public override void Awake(Scene scene) { // initialize stars and rays from scratch like vanilla does. List starTextures = GFX.Game.GetAtlasSubtextures("particles/stars/"); for (int i = 0; i < stars.Length; i++) { - stars[i].Position.X = Calc.Random.Next(320); - stars[i].Position.Y = Calc.Random.Next(180); + stars[i].Position.X = Calc.Random.Next(GameplayBuffers.Gameplay.Width); + stars[i].Position.Y = Calc.Random.Next(GameplayBuffers.Gameplay.Height); stars[i].Texture = Calc.Random.Choose(starTextures); stars[i].Color = Calc.Random.Choose(starColors); stars[i].Scroll = Vector2.One * Calc.Random.NextFloat(0.05f); } for (int j = 0; j < rays.Length; j++) { - rays[j].Position.X = Calc.Random.Next(320); - rays[j].Position.Y = Calc.Random.Next(180); + rays[j].Position.X = Calc.Random.Next(GameplayBuffers.Gameplay.Width); + rays[j].Position.Y = Calc.Random.Next(GameplayBuffers.Gameplay.Height); rays[j].Width = Calc.Random.Range(4f, 16f); rays[j].Length = Calc.Random.Choose(48, 96, 128); rays[j].Color = Color.White * Calc.Random.Range(0.2f, 0.4f); @@ -155,6 +155,13 @@ public override void Awake(Scene scene) { } } + private void ensureBufferIsCorrect() { + if (starsTarget == null || starsTarget.Width != GameplayBuffers.Gameplay.Width || starsTarget.Height != GameplayBuffers.Gameplay.Height) { + starsTarget?.Dispose(); + starsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-surfaces", GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height); + } + } + private void BeforeRender() { List glassBlocks = getGlassBlocksToAffect().ToList(); hasBlocks = (glassBlocks.Count > 0); @@ -163,13 +170,11 @@ private void BeforeRender() { } Camera camera = (Scene as Level).Camera; - int screenWidth = 320; - int screenHeight = 180; + int screenWidth = GameplayBuffers.Gameplay.Width; + int screenHeight = GameplayBuffers.Gameplay.Height; // draw stars - if (starsTarget == null) { - starsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-surfaces", screenWidth, screenHeight); - } + ensureBufferIsCorrect(); Engine.Graphics.GraphicsDevice.SetRenderTarget(starsTarget); Engine.Graphics.GraphicsDevice.Clear(Color.Transparent); diff --git a/Entities/FancyTextTutorial.cs b/Entities/FancyTextTutorial.cs index c1e2d5e5..e4133950 100644 --- a/Entities/FancyTextTutorial.cs +++ b/Entities/FancyTextTutorial.cs @@ -90,7 +90,7 @@ public override void Render() { Camera camera = SceneAs().Camera; Vector2 drawPosition = Position - camera.Position.Floor(); if (SaveData.Instance != null && SaveData.Instance.Assists.MirrorMode) { - drawPosition.X = 320f - drawPosition.X; + drawPosition.X = GameplayBuffers.Gameplay.Width - drawPosition.X; } drawPosition *= 6f; diff --git a/Entities/FlagSwitchGate.cs b/Entities/FlagSwitchGate.cs index 9badfddf..7af8e716 100644 --- a/Entities/FlagSwitchGate.cs +++ b/Entities/FlagSwitchGate.cs @@ -172,7 +172,7 @@ public override void Awake(Scene scene) { [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool InView() { Camera camera = (Scene as Level).Camera; - return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + 320f && Position.Y < camera.Y + 180f; + return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + GameplayBuffers.Gameplay.Width && Position.Y < camera.Y + GameplayBuffers.Gameplay.Height; } public override void Render() { diff --git a/Entities/MultiNodeFlagSwitchGate.cs b/Entities/MultiNodeFlagSwitchGate.cs index 7bd0b88c..4bca2eff 100644 --- a/Entities/MultiNodeFlagSwitchGate.cs +++ b/Entities/MultiNodeFlagSwitchGate.cs @@ -161,7 +161,7 @@ public override void Awake(Scene scene) { [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool InView() { Camera camera = (Scene as Level).Camera; - return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + 320f && Position.Y < camera.Y + 180f; + return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + GameplayBuffers.Gameplay.Width && Position.Y < camera.Y + GameplayBuffers.Gameplay.Height; } public override void Render() { diff --git a/Entities/SeekerBarrierColorController.cs b/Entities/SeekerBarrierColorController.cs index 946e0998..c933cae8 100644 --- a/Entities/SeekerBarrierColorController.cs +++ b/Entities/SeekerBarrierColorController.cs @@ -86,6 +86,7 @@ private static void onLoadLevel(On.Celeste.Level.orig_LoadLevel orig, Level self private bool wavy; private bool renderBloom; private bool persistent; + private int entityID; private VirtualRenderTarget levelRenderTarget; @@ -93,6 +94,13 @@ internal static bool HasControllerOnNextScreen() { return nextController != null; } + private void ensureBufferIsCorrect() { + if (levelRenderTarget == null || levelRenderTarget.Width != GameplayBuffers.Gameplay.Width || levelRenderTarget.Height != GameplayBuffers.Gameplay.Height) { + levelRenderTarget?.Dispose(); + levelRenderTarget = VirtualContent.CreateRenderTarget("helping-hand-seeker-barrier-color-controller-" + entityID, GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height); + } + } + public SeekerBarrierColorController(EntityData data, Vector2 offset) : base(data.Position + offset) { color = Calc.HexToColor(data.Attr("color", "FFFFFF")); particleColor = Calc.HexToColor(data.Attr("particleColor", "FFFFFF")); @@ -102,12 +110,13 @@ public SeekerBarrierColorController(EntityData data, Vector2 offset) : base(data wavy = data.Bool("wavy", defaultValue: true); renderBloom = data.Bool("renderBloom", defaultValue: true); persistent = data.Bool("persistent"); + entityID = data.ID; if (int.TryParse(data.Attr("depth"), out int depthInt)) { depth = depthInt; // we are going to need this for bloom rendering. - levelRenderTarget = VirtualContent.CreateRenderTarget("helping-hand-seeker-barrier-color-controller-" + data.ID, 320, 180); + ensureBufferIsCorrect(); } Add(new TransitionListener { @@ -417,6 +426,7 @@ private static void onSeekerBarrierRendererRender(On.Celeste.SeekerBarrierRender GameplayRenderer.End(); // first, build the scene with background + gameplay that was rendered so far. + self.ensureBufferIsCorrect(); Engine.Instance.GraphicsDevice.SetRenderTarget(controllerOnScreen.levelRenderTarget); Engine.Instance.GraphicsDevice.Clear(Color.Transparent); level.Background.Render(level); diff --git a/Entities/SidewaysLava.cs b/Entities/SidewaysLava.cs index f82c301c..bbc9bedf 100644 --- a/Entities/SidewaysLava.cs +++ b/Entities/SidewaysLava.cs @@ -82,13 +82,13 @@ public SidewaysLava(EntityData data, Vector2 offset) { if (lavaMode == LavaMode.LeftToRight) { // one hitbox on the left. - Collider = new Hitbox(340f, 200f, -340f); + Collider = new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, -GameplayBuffers.Gameplay.Height - 20f); } else if (lavaMode == LavaMode.RightToLeft) { // one hitbox on the right. - Collider = new Hitbox(340f, 200f, 320f); + Collider = new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, GameplayBuffers.Gameplay.Width); } else { // hitboxes on both sides, 280px apart. - Collider = new ColliderList(new Hitbox(340f, 200f, -340f), new Hitbox(340f, 200f, 280f)); + Collider = new ColliderList(new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, -GameplayBuffers.Gameplay.Width - 20f), new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, GameplayBuffers.Gameplay.Width - 40f)); } Visible = false; @@ -97,7 +97,7 @@ public SidewaysLava(EntityData data, Vector2 offset) { Add(loopSfx = new SoundSource()); // lava can travel at up to 40 px/s * speedMultiplier, and we want it to extend enough so that you don't see it scrolling past the screen. - float lavaWidth = 320f + speedMultiplier * 80f; + float lavaWidth = GameplayBuffers.Gameplay.Width + speedMultiplier * 80f; if (lavaMode != LavaMode.RightToLeft) { // add the left lava rect, just off-screen (it is 340px wide) @@ -108,7 +108,7 @@ public SidewaysLava(EntityData data, Vector2 offset) { if (lavaMode != LavaMode.LeftToRight) { // add the right lava rect, just off-screen (the screen is 320px wide) Add(rightRect = new SidewaysLavaRect(lavaWidth, 200f, 4, SidewaysLavaRect.OnlyModes.OnlyRight)); - rightRect.Position = new Vector2(lavaMode == LavaMode.Sandwich ? 280f : 320f, 0f); + rightRect.Position = new Vector2(lavaMode == LavaMode.Sandwich ? GameplayBuffers.Gameplay.Width - 40f : GameplayBuffers.Gameplay.Width, 0f); rightRect.SmallWaveAmplitude = 2f; } @@ -173,10 +173,10 @@ public override void Added(Scene scene) { loopSfx.Position = new Vector2(0f, Height / 2f); } else if (lavaMode == LavaMode.RightToLeft) { - // same, except the lava is offset by 320px. That gives Right - 320 + 16 = Right - 304. - X = SceneAs().Bounds.Right - 304; + // same, except the lava is offset by 320px. That gives Right - 320 + 16. + X = SceneAs().Bounds.Right - GameplayBuffers.Gameplay.Width + 16; // sound comes from the right side. - loopSfx.Position = new Vector2(320f, Height / 2f); + loopSfx.Position = new Vector2(GameplayBuffers.Gameplay.Width, Height / 2f); } else { // the position should be set on the first Update call, in case the level starts with a room with lava in it @@ -319,8 +319,8 @@ public override void Update() { // stop 32px to the left of the player. target = player.X - 32f; } else { - // stop 32px to the right of the player. since lava is offset by 320px, that gives 320 - 32 = 288px. - target = player.X - 288f; + // stop 32px to the right of the player. since lava is offset by 320px, that gives 320 - 32. + target = player.X - GameplayBuffers.Gameplay.Width + 32; } if (!intro && player != null && player.JustRespawned && !player.CollideCheck()) { diff --git a/Entities/StylegroundFadeController.cs b/Entities/StylegroundFadeController.cs index a42065d7..e603c5d2 100644 --- a/Entities/StylegroundFadeController.cs +++ b/Entities/StylegroundFadeController.cs @@ -80,10 +80,17 @@ public override void SceneEnd(Scene scene) { deregisterFlag(); } + private static void ensureBufferIsCorrect() { + if (tempRenderTarget == null || tempRenderTarget.Width != GameplayBuffers.Gameplay.Width || tempRenderTarget.Height != GameplayBuffers.Gameplay.Height) { + tempRenderTarget?.Dispose(); + tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height); + } + } + private void initializeFlag() { // enable the hooks on backdrop rendering. if (controllers.Count == 0) { - tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", 320, 180); + ensureBufferIsCorrect(); } foreach (string key in keys) { @@ -185,6 +192,7 @@ private static void modBackdropRendererRender(ILContext il) { if (hasFlag || hasNotFlag) { self.EndSpritebatch(); + ensureBufferIsCorrect(); Engine.Graphics.GraphicsDevice.SetRenderTarget(tempRenderTarget); Engine.Graphics.GraphicsDevice.Clear(Color.Transparent); diff --git a/Triggers/CameraOffsetBorder.cs b/Triggers/CameraOffsetBorder.cs index 091d6757..9e48cf42 100644 --- a/Triggers/CameraOffsetBorder.cs +++ b/Triggers/CameraOffsetBorder.cs @@ -88,7 +88,7 @@ private static Vector2 modCameraTarget(Func orig, Player self) Vector2 target = orig(self); - Rectangle viewpoint = new Rectangle((int) target.X, (int) target.Y, 320, 180); + Rectangle viewpoint = new Rectangle((int) target.X, (int) target.Y, GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height); foreach (CameraOffsetBorder border in self.Scene.Tracker.GetEntities()) { while (border.Collidable && border.CollideRect(viewpoint)) { // the border is enabled and on-screen, unacceptable! diff --git a/Triggers/GradientDustTrigger.cs b/Triggers/GradientDustTrigger.cs index 1e59941f..226a63d0 100644 --- a/Triggers/GradientDustTrigger.cs +++ b/Triggers/GradientDustTrigger.cs @@ -142,7 +142,7 @@ private static void onDustEdgesBeforeRender(On.Celeste.DustEdges.orig_BeforeRend // draw our image in ""substractive"" mode over the resort dust layer. float shift = (Engine.Scene.TimeActive * speed) % image.Width; Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, substractive, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.Identity); - for (float offset = -shift; offset < 320; offset += image.Width) { + for (float offset = -shift; offset < GameplayBuffers.Gameplay.Width; offset += image.Width) { Draw.SpriteBatch.Draw(image.Texture.Texture, new Vector2(offset, 0), Color.White); } Draw.SpriteBatch.End(); diff --git a/Triggers/OneWayCameraTrigger.cs b/Triggers/OneWayCameraTrigger.cs index 9529edb2..b3d31d24 100644 --- a/Triggers/OneWayCameraTrigger.cs +++ b/Triggers/OneWayCameraTrigger.cs @@ -51,16 +51,16 @@ public override void OnEnter(Player player) { if (blockPlayer) { Level level = SceneAs(); if (!left) { - Scene.Add(leftBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitX * 9, 8, 180)); + Scene.Add(leftBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitX * 9, 8, GameplayBuffers.Gameplay.Height)); } if (!right) { - Scene.Add(rightBound = new InvisibleBarrier(level.Camera.Position + Vector2.UnitX * 320, 8, 180)); + Scene.Add(rightBound = new InvisibleBarrier(level.Camera.Position + Vector2.UnitX * GameplayBuffers.Gameplay.Width, 8, GameplayBuffers.Gameplay.Height)); } if (!up) { - Scene.Add(upperBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitY * 9, 320, 8)); + Scene.Add(upperBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitY * 9, GameplayBuffers.Gameplay.Width, 8)); } if (!down) { - Scene.Add(lowerBound = new Killbox(new EntityData { Width = 320 }, level.Camera.Position + Vector2.UnitY * 186)); + Scene.Add(lowerBound = new Killbox(new EntityData { Width = GameplayBuffers.Gameplay.Width }, level.Camera.Position + Vector2.UnitY * (GameplayBuffers.Gameplay.Height + 6))); } } } @@ -88,13 +88,13 @@ public override void OnStay(Player player) { leftBound.Position = level.Camera.Position - Vector2.UnitX * 9; } if (rightBound != null) { - rightBound.Position = level.Camera.Position + Vector2.UnitX * 320; + rightBound.Position = level.Camera.Position + Vector2.UnitX * GameplayBuffers.Gameplay.Width; } if (upperBound != null) { upperBound.Position = level.Camera.Position - Vector2.UnitY * 9; } if (lowerBound != null) { - lowerBound.Position = level.Camera.Position + Vector2.UnitY * 186f; + lowerBound.Position = level.Camera.Position + Vector2.UnitY * (GameplayBuffers.Gameplay.Height + 6f); } }