Skip to content

Commit

Permalink
Tweaks to enhance compatibility with zooming out
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 authored Nov 6, 2024
1 parent a5681cc commit 9d1f96a
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Effects/AllSideTentacles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Effects/CustomStars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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++) {
Expand Down
23 changes: 14 additions & 9 deletions Entities/CustomizableGlassBlockController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,30 @@ public override void Awake(Scene scene) {
// initialize stars and rays from scratch like vanilla does.
List<MTexture> 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);
}
}
}

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<CustomizableGlassBlock> glassBlocks = getGlassBlocksToAffect().ToList();
hasBlocks = (glassBlocks.Count > 0);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Entities/FancyTextTutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public override void Render() {
Camera camera = SceneAs<Level>().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;

Expand Down
2 changes: 1 addition & 1 deletion Entities/FlagSwitchGate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion Entities/MultiNodeFlagSwitchGate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 11 additions & 1 deletion Entities/SeekerBarrierColorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,21 @@ 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;

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"));
Expand All @@ -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 {
Expand Down Expand Up @@ -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();

Check failure on line 429 in Entities/SeekerBarrierColorController.cs

View workflow job for this annotation

GitHub Actions / build

'SeekerBarrierRenderer' does not contain a definition for 'ensureBufferIsCorrect' and no accessible extension method 'ensureBufferIsCorrect' accepting a first argument of type 'SeekerBarrierRenderer' could be found (are you missing a using directive or an assembly reference?)
Engine.Instance.GraphicsDevice.SetRenderTarget(controllerOnScreen.levelRenderTarget);
Engine.Instance.GraphicsDevice.Clear(Color.Transparent);
level.Background.Render(level);
Expand Down
20 changes: 10 additions & 10 deletions Entities/SidewaysLava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down Expand Up @@ -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<Level>().Bounds.Right - 304;
// same, except the lava is offset by 320px. That gives Right - 320 + 16.
X = SceneAs<Level>().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
Expand Down Expand Up @@ -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<InstantLavaBlockerTrigger>()) {
Expand Down
10 changes: 9 additions & 1 deletion Entities/StylegroundFadeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Triggers/CameraOffsetBorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static Vector2 modCameraTarget(Func<Player, Vector2> 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<CameraOffsetBorder>()) {
while (border.Collidable && border.CollideRect(viewpoint)) {
// the border is enabled and on-screen, unacceptable!
Expand Down
2 changes: 1 addition & 1 deletion Triggers/GradientDustTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions Triggers/OneWayCameraTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public override void OnEnter(Player player) {
if (blockPlayer) {
Level level = SceneAs<Level>();
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)));
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 9d1f96a

Please sign in to comment.