Fix foreground drawing, delegate clearing to a different detour.

This commit is contained in:
Tomat committed 2022-06-09 20:54:32 -07:00
1 parent 08f4885654
commit 5846f50cea
3 files changed
+20 -11

No files matched your search

+8 -11
View File
@@ -20,7 +20,6 @@ namespace CalamityMod.ForegroundDrawing
{
private static List<Point> _foregroundElements;
private static int _foregroundElementCount;
public static bool drawToScreenLastFrame = false;
internal static void Load()
{
@@ -28,31 +27,29 @@ namespace CalamityMod.ForegroundDrawing
_foregroundElementCount = 0;
}
private static bool DrawToScreen() => Lighting.UpdateEveryFrame || Main.drawToScreen;
public static void AddForegroundDrawingPoint(int x, int y)
{
if (drawToScreenLastFrame)
{
_foregroundElements.Add(new Point(x, y));
_foregroundElementCount++;
}
_foregroundElements.Add(new Point(x, y));
_foregroundElementCount++;
}
public static void DrawTiles()
{
drawToScreenLastFrame = Main.drawToScreen;
for (int i = 0; i < _foregroundElementCount; i++)
{
ushort type = Main.tile[_foregroundElements[i]].TileType;
if (TileLoader.GetTile(type) is IForegroundTile fgTile)
fgTile.ForegroundDraw(_foregroundElements[i].X, _foregroundElements[i].Y, Main.spriteBatch);
}
}
if (!Main.drawToScreen) return;
_foregroundElementCount = 0;
public static void ClearTiles()
{
_foregroundElements.Clear();
_foregroundElementCount = 0;
}
}
}
+4
View File
@@ -55,6 +55,8 @@ namespace CalamityMod.ILEditing
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += DrawCustomLava2;
IL.Terraria.Main.oldDrawWater += DrawCustomLava3;
On.Terraria.Main.DrawGore += DrawForegroundStuff;
//On.Terraria.GameContent.Drawing.TileDrawing.ClearLegacyCachedDraws += ClearForegroundStuff;
On.Terraria.GameContent.Drawing.TileDrawing.PreDrawTiles += ClearForegroundStuff;
// TODO -- Revisit this. It's not an extremely important thing, but it'd be ideal to not just abandon it.
// IL.Terraria.WaterfallManager.DrawWaterfall += DrawCustomLavafalls;
@@ -152,6 +154,8 @@ namespace CalamityMod.ILEditing
On.Terraria.NPC.Collision_DecideFallThroughPlatforms -= EnableCalamityBossPlatformCollision;
IL.Terraria.Wiring.HitWireSingle -= AddTwinklersToStatue;
On.Terraria.Main.DrawGore -= DrawForegroundStuff;
//On.Terraria.GameContent.Drawing.TileDrawing.ClearLegacyCachedDraws -= ClearForegroundStuff;
On.Terraria.GameContent.Drawing.TileDrawing.PreDrawTiles -= ClearForegroundStuff;
// Damage and health balance
IL.Terraria.Main.DamageVar -= AdjustDamageVariance;
+8
View File
@@ -899,6 +899,14 @@ namespace CalamityMod.ILEditing
if (Main.PlayerLoaded && !Main.gameMenu)
ForegroundManager.DrawTiles();
}
private static void ClearForegroundStuff(On.Terraria.GameContent.Drawing.TileDrawing.orig_PreDrawTiles orig, Terraria.GameContent.Drawing.TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets)
{
orig(self, solidLayer, forRenderTargets, intoRenderTargets);
if (!solidLayer && (intoRenderTargets || Lighting.UpdateEveryFrame))
ForegroundManager.ClearTiles();
}
#endregion
}
}