Skip to content

Commit

Permalink
Differentiate camera dimensions and buffer dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Nov 13, 2024
1 parent c3f58b4 commit 40365f6
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Effects/AllSideTentacles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ private static void modTentaclesUpdate(ILContext il) {

if (player != null) {
if (allSideSelf.side == Side.Left) {
return (player.X - camera.X) - (MaxHelpingHandModule.GameplayWidth / 2f);
return (player.X - camera.X) - (MaxHelpingHandModule.CameraWidth / 2f);
} else if (allSideSelf.side == Side.Top) {
return player.Y - camera.Y - MaxHelpingHandModule.GameplayHeight;
return player.Y - camera.Y - MaxHelpingHandModule.CameraHeight;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Effects/CustomStars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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(MaxHelpingHandModule.GameplayWidth), Calc.Random.NextFloat(wrapHeight)),
Position = new Vector2(Calc.Random.NextFloat(MaxHelpingHandModule.BufferWidth), 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 @@ -91,7 +91,7 @@ public override void Update(Scene scene) {
public override void Render(Scene scene) {
float fadeAlpha = GetFadeAlpha(scene);

Draw.Rect(0f, 0f, MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight, Color.Black * bgAlpha);
Draw.Rect(0f, 0f, MaxHelpingHandModule.BufferWidth, MaxHelpingHandModule.BufferHeight, 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 @@ -106,9 +106,9 @@ public override void Render(Scene scene) {

// parallax X
position.X -= level.Camera.X * effectiveScroll.X;
position.X %= MaxHelpingHandModule.GameplayWidth;
position.X %= MaxHelpingHandModule.BufferWidth;
if (position.X < 0f) {
position.X += MaxHelpingHandModule.GameplayWidth;
position.X += MaxHelpingHandModule.BufferWidth;
}

// parallax Y
Expand All @@ -118,7 +118,7 @@ public override void Render(Scene scene) {
if (position.Y < 0f) {
position.Y += wrapHeight;
}
position.Y -= (wrapHeight - MaxHelpingHandModule.GameplayHeight) / 2;
position.Y -= (wrapHeight - MaxHelpingHandModule.BufferHeight) / 2;

if (level.Session.Dreaming) {
for (int j = 0; j < colors.Length; j++) {
Expand Down
16 changes: 8 additions & 8 deletions Entities/CustomizableGlassBlockController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ 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(MaxHelpingHandModule.GameplayWidth);
stars[i].Position.Y = Calc.Random.Next(MaxHelpingHandModule.GameplayHeight);
stars[i].Position.X = Calc.Random.Next(MaxHelpingHandModule.BufferWidth);
stars[i].Position.Y = Calc.Random.Next(MaxHelpingHandModule.BufferHeight);
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(MaxHelpingHandModule.GameplayWidth);
rays[j].Position.Y = Calc.Random.Next(MaxHelpingHandModule.GameplayHeight);
rays[j].Position.X = Calc.Random.Next(MaxHelpingHandModule.BufferWidth);
rays[j].Position.Y = Calc.Random.Next(MaxHelpingHandModule.BufferHeight);
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);
Expand All @@ -156,9 +156,9 @@ public override void Awake(Scene scene) {
}

private void ensureBufferIsCorrect() {
if (starsTarget == null || starsTarget.Width != MaxHelpingHandModule.GameplayWidth || starsTarget.Height != MaxHelpingHandModule.GameplayHeight) {
if (starsTarget == null || starsTarget.Width != MaxHelpingHandModule.BufferWidth || starsTarget.Height != MaxHelpingHandModule.BufferHeight) {
starsTarget?.Dispose();
starsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-surfaces", MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight);
starsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-surfaces", MaxHelpingHandModule.BufferWidth, MaxHelpingHandModule.BufferHeight);
}
}

Expand All @@ -170,8 +170,8 @@ private void BeforeRender() {
}

Camera camera = (Scene as Level).Camera;
int screenWidth = MaxHelpingHandModule.GameplayWidth;
int screenHeight = MaxHelpingHandModule.GameplayHeight;
int screenWidth = MaxHelpingHandModule.BufferWidth;
int screenHeight = MaxHelpingHandModule.BufferHeight;

// draw stars
ensureBufferIsCorrect();
Expand Down
2 changes: 1 addition & 1 deletion Entities/FancyTextTutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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 = MaxHelpingHandModule.GameplayWidth - drawPosition.X;
drawPosition.X = MaxHelpingHandModule.CameraWidth - 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 @@ -173,7 +173,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 + MaxHelpingHandModule.GameplayWidth && Position.Y < camera.Y + MaxHelpingHandModule.GameplayHeight;
return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + MaxHelpingHandModule.CameraWidth && Position.Y < camera.Y + MaxHelpingHandModule.CameraHeight;
}

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 + MaxHelpingHandModule.GameplayWidth && Position.Y < camera.Y + MaxHelpingHandModule.GameplayHeight;
return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + MaxHelpingHandModule.CameraWidth && Position.Y < camera.Y + MaxHelpingHandModule.CameraHeight;
}

public override void Render() {
Expand Down
4 changes: 2 additions & 2 deletions Entities/SeekerBarrierColorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ internal static bool HasControllerOnNextScreen() {
}

private void ensureBufferIsCorrect() {
if (levelRenderTarget == null || levelRenderTarget.Width != MaxHelpingHandModule.GameplayWidth || levelRenderTarget.Height != MaxHelpingHandModule.GameplayHeight) {
if (levelRenderTarget == null || levelRenderTarget.Width != MaxHelpingHandModule.BufferWidth || levelRenderTarget.Height != MaxHelpingHandModule.BufferHeight) {
levelRenderTarget?.Dispose();
levelRenderTarget = VirtualContent.CreateRenderTarget("helping-hand-seeker-barrier-color-controller-" + entityID, MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight);
levelRenderTarget = VirtualContent.CreateRenderTarget("helping-hand-seeker-barrier-color-controller-" + entityID, MaxHelpingHandModule.BufferWidth, MaxHelpingHandModule.BufferHeight);
}
}

Expand Down
16 changes: 8 additions & 8 deletions Entities/SidewaysLava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public SidewaysLava(EntityData data, Vector2 offset) {

if (lavaMode == LavaMode.LeftToRight) {
// one hitbox on the left.
Collider = new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, -MaxHelpingHandModule.GameplayWidth - 20f);
Collider = new Hitbox(MaxHelpingHandModule.CameraWidth + 20f, MaxHelpingHandModule.CameraHeight + 20f, -MaxHelpingHandModule.CameraWidth - 20f);
} else if (lavaMode == LavaMode.RightToLeft) {
// one hitbox on the right.
Collider = new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, MaxHelpingHandModule.GameplayWidth);
Collider = new Hitbox(MaxHelpingHandModule.CameraWidth + 20f, MaxHelpingHandModule.CameraHeight + 20f, MaxHelpingHandModule.CameraWidth);
} else {
// hitboxes on both sides, 280px apart.
Collider = new ColliderList(new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, -MaxHelpingHandModule.GameplayWidth - 20f), new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, MaxHelpingHandModule.GameplayWidth - 40f));
Collider = new ColliderList(new Hitbox(MaxHelpingHandModule.CameraWidth + 20f, MaxHelpingHandModule.CameraHeight + 20f, -MaxHelpingHandModule.CameraWidth - 20f), new Hitbox(MaxHelpingHandModule.CameraWidth + 20f, MaxHelpingHandModule.CameraHeight + 20f, MaxHelpingHandModule.CameraWidth - 40f));
}

Visible = false;
Expand All @@ -98,7 +98,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 = MaxHelpingHandModule.GameplayWidth + speedMultiplier * 80f;
float lavaWidth = MaxHelpingHandModule.CameraWidth + speedMultiplier * 80f;

if (lavaMode != LavaMode.RightToLeft) {
// add the left lava rect, just off-screen (it is 340px wide)
Expand All @@ -109,7 +109,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 ? MaxHelpingHandModule.GameplayWidth - 40f : MaxHelpingHandModule.GameplayWidth, 0f);
rightRect.Position = new Vector2(lavaMode == LavaMode.Sandwich ? MaxHelpingHandModule.CameraWidth - 40f : MaxHelpingHandModule.CameraWidth, 0f);
rightRect.SmallWaveAmplitude = 2f;
}

Expand Down Expand Up @@ -175,9 +175,9 @@ public override void Added(Scene scene) {

} else if (lavaMode == LavaMode.RightToLeft) {
// same, except the lava is offset by 320px. That gives Right - 320 + 16.
X = SceneAs<Level>().Bounds.Right - MaxHelpingHandModule.GameplayWidth + 16;
X = SceneAs<Level>().Bounds.Right - MaxHelpingHandModule.CameraWidth + 16;
// sound comes from the right side.
loopSfx.Position = new Vector2(MaxHelpingHandModule.GameplayWidth, Height / 2f);
loopSfx.Position = new Vector2(MaxHelpingHandModule.CameraWidth, 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 @@ -321,7 +321,7 @@ public override void Update() {
target = player.X - 32f;
} else {
// stop 32px to the right of the player. since lava is offset by 320px, that gives 320 - 32.
target = player.X - MaxHelpingHandModule.GameplayWidth + 32;
target = player.X - MaxHelpingHandModule.CameraWidth + 32;
}

if (!intro && player != null && player.JustRespawned && !player.CollideCheck<InstantLavaBlockerTrigger>()) {
Expand Down
4 changes: 2 additions & 2 deletions Entities/StylegroundFadeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public override void SceneEnd(Scene scene) {
}

private static void ensureBufferIsCorrect() {
if (tempRenderTarget == null || tempRenderTarget.Width != MaxHelpingHandModule.GameplayWidth || tempRenderTarget.Height != MaxHelpingHandModule.GameplayHeight) {
if (tempRenderTarget == null || tempRenderTarget.Width != MaxHelpingHandModule.BufferWidth || tempRenderTarget.Height != MaxHelpingHandModule.BufferHeight) {
tempRenderTarget?.Dispose();
tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight);
tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", MaxHelpingHandModule.BufferWidth, MaxHelpingHandModule.BufferHeight);
}
}

Expand Down
4 changes: 4 additions & 0 deletions MaddieHelpingHand.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<HintPath>lib-stripped\Celeste.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ExCameraDynamics">
<HintPath>lib-stripped\ExCameraDynamics.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="FlaglinesAndSuch">
<HintPath>lib-stripped\FlaglinesAndSuch.dll</HintPath>
<Private>false</Private>
Expand Down
78 changes: 75 additions & 3 deletions Module/MaxHelpingHandModule.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Celeste.Mod.MaxHelpingHand.Effects;
using Celeste.Mod.ExCameraDynamics.Code.Module;
using Celeste.Mod.MaxHelpingHand.Effects;
using Celeste.Mod.MaxHelpingHand.Entities;
using Celeste.Mod.MaxHelpingHand.Triggers;
using Microsoft.Xna.Framework;
using Monocle;
using MonoMod.ModInterop;
using MonoMod.RuntimeDetour;
using System;
using System.Linq;
using System.Reflection;

namespace Celeste.Mod.MaxHelpingHand.Module {
Expand All @@ -27,9 +29,42 @@ public class MaxHelpingHandModule : EverestModule {
public override Type SessionType => typeof(MaxHelpingHandSession);
public MaxHelpingHandSession Session => (MaxHelpingHandSession) _Session;

private static bool extendedCameraDynamicsEnabled = false;
private bool extendedCameraDynamicsHookEnabled = false;

private static bool zoomOutHelperPrototypeEnabled = false;
private bool zoomOutHelperPrototypeHookEnabled = false;
private MethodInfo zoomOutHelperPrototypeCheckMethod;

// size of the screen, taking zooming out into account (Extended Camera Dynamics mod)
public static int GameplayWidth => GameplayBuffers.Gameplay?.Width ?? 320;
public static int GameplayHeight => GameplayBuffers.Gameplay?.Height ?? 180;

public static int CameraWidth {
get {
if (!extendedCameraDynamicsEnabled && !zoomOutHelperPrototypeEnabled) return 320;
return (Engine.Scene as Level)?.Camera.Viewport.Width ?? 320;
}
}

public static int CameraHeight {
get {
if (!extendedCameraDynamicsEnabled && !zoomOutHelperPrototypeEnabled) return 180;
return (Engine.Scene as Level)?.Camera.Viewport.Height ?? 180;
}
}

public static int BufferWidth {
get {
if (!extendedCameraDynamicsEnabled && !zoomOutHelperPrototypeEnabled) return 320;
return GameplayBuffers.Gameplay?.Width ?? 320;
}
}

public static int BufferHeight {
get {
if (!extendedCameraDynamicsEnabled && !zoomOutHelperPrototypeEnabled) return 180;
return GameplayBuffers.Gameplay?.Height ?? 180;
}
}

private static Hook modRegister = null;

Expand Down Expand Up @@ -210,6 +245,17 @@ public override void Unload() {
if (frostBreakingBallLoaded) {
unloadFrostBreakingBall();
}

if (extendedCameraDynamicsHookEnabled) {
On.Celeste.LevelLoader.StartLevel -= checkExtendedCameraDynamics;
extendedCameraDynamicsHookEnabled = false;
}

if (zoomOutHelperPrototypeHookEnabled) {
On.Celeste.LevelLoader.StartLevel -= checkZoomOutHelperPrototype;
zoomOutHelperPrototypeCheckMethod = null;
zoomOutHelperPrototypeHookEnabled = false;
}
}

public override void LoadContent(bool firstLoad) {
Expand All @@ -232,6 +278,20 @@ private void onModRegister(Action<EverestModule> orig, EverestModule module) {
}
}

private void checkExtendedCameraDynamics(On.Celeste.LevelLoader.orig_StartLevel orig, LevelLoader self) {
checkForExtendedCameraDynamics(self);
orig(self);
}

private void checkForExtendedCameraDynamics(LevelLoader self) {
extendedCameraDynamicsEnabled = ExCameraAreaMetadata.TryGetCameraMetadata(self.Level.Session)?.EnableExtendedCamera ?? false;
}

private void checkZoomOutHelperPrototype(On.Celeste.LevelLoader.orig_StartLevel orig, LevelLoader self) {
zoomOutHelperPrototypeEnabled = (bool) zoomOutHelperPrototypeCheckMethod.Invoke(null, new object[] { self.Level.Session, null, null });
orig(self);
}

private void HookMods() {
KevinBarrier.HookMods();
MovingFlagTouchSwitch.HookMods();
Expand Down Expand Up @@ -260,6 +320,18 @@ private void HookMods() {
if (!frostBreakingBallLoaded && Everest.Loader.DependencyLoaded(new EverestModuleMetadata { Name = "FrostHelper", Version = new Version(1, 46, 0) })) {
loadFrostBreakingBall();
}

if (!extendedCameraDynamicsHookEnabled && Everest.Loader.DependencyLoaded(new EverestModuleMetadata { Name = "ExtendedCameraDynamics", Version = new Version(1, 0, 3) })) {
On.Celeste.LevelLoader.StartLevel += checkExtendedCameraDynamics;
extendedCameraDynamicsHookEnabled = true;
}

if (!zoomOutHelperPrototypeEnabled && Everest.Loader.DependencyLoaded(new EverestModuleMetadata { Name = "ZoomOutHelperPrototype", Version = new Version(0, 1, 1) })) {
On.Celeste.LevelLoader.StartLevel += checkZoomOutHelperPrototype;
zoomOutHelperPrototypeCheckMethod = Everest.Modules.First(mod => mod.GetType().ToString() == "Celeste.Mod.FunctionalZoomOut.FunctionalZoomOutModule")
.GetType().GetMethod("SessionHasZoomOut", BindingFlags.NonPublic | BindingFlags.Static);
zoomOutHelperPrototypeEnabled = true;
}
}

private void hookSineParallax() {
Expand Down
Loading

0 comments on commit 40365f6

Please sign in to comment.