Renderer fixes (#12)
* - Pull #3 requests. - Safety check for globals in miracle blight renderer to prevent MP crashes. * - Fixed load crash. - Fixed miracle blight effect getting very grainy when using the worldposition. - RealCos -> cos, as cos is now fixed in mojoshader. - Method rename for consistency. * Discard changes to Properties/launchSettings.json * Discard changes to NPCs/CalamityGlobalNPC.cs * Discard changes to NPCs/CalamityGlobalNPC.cs * Update CalamityGlobalNPC.cs * Update RendererManager.cs * - Rename for consistency. - Cached renderers are cleared when unloading. --------- Co-authored-by: tomat <xxlennygamerxx@gmail.com>
This commit is contained in:
1 parent
f0d705cdc4
commit
0869a528dc
12 files changed
+164
-205
No files matched your search
@@ -14,16 +14,6 @@ float2 uImageSize0;
|
||||
float2 uImageSize1;
|
||||
float4 uShaderSpecificData;
|
||||
|
||||
// Cosine does not work in shaders in Terraria 1.4. It returns incredibly corrupted values and nobody is sure why.
|
||||
// This reimplements cosine using trigonometric identities.
|
||||
//
|
||||
// Discovery of malfunctioning cosine attributed to ScalarVector from SLR:
|
||||
// https://discord.com/channels/103110554649894912/445276626352209920/979928448300634175
|
||||
float realCos(float value)
|
||||
{
|
||||
return sin(value + 1.57079);
|
||||
}
|
||||
|
||||
//
|
||||
// Based on Devourer of Gods' death animation (by Dominic)
|
||||
// in turn, that was based on ExampleMod's cool death animation
|
||||
@@ -39,7 +29,7 @@ float4 PixelShaderFunction(float2 coords : TEXCOORD0) : COLOR0
|
||||
// Temporal drift to make the sprite slide through the noise texture
|
||||
float2 drift = float2(5 * sin(0.04165 * uTime), 1.1 * uTime);
|
||||
|
||||
float2 noiseMapTexCoords = coords + drift + uWorldPosition;
|
||||
float2 noiseMapTexCoords = coords + drift;
|
||||
float4 noiseColor = tex2D(uImage1, noiseMapTexCoords);
|
||||
|
||||
// Define thresholds for total pixel erasure and glowing lines.
|
||||
@@ -47,12 +37,12 @@ float4 PixelShaderFunction(float2 coords : TEXCOORD0) : COLOR0
|
||||
// Rapidly flickering sinewave produced by Desmos, loosely based on the Weierstrass function
|
||||
// (infinitely sharp vague sinewave, periodic, continuous everywhere but differentiable nowhere)
|
||||
// https://en.wikipedia.org/wiki/Weierstrass_function
|
||||
float flickerOne = 0.05 * realCos(7 * uTime);
|
||||
float flickerTwo = 0.06 * realCos(31 * uTime);
|
||||
float flickerOne = 0.05 * cos(7 * uTime);
|
||||
float flickerTwo = 0.06 * cos(31 * uTime);
|
||||
float flickerThree = 0.04 * sin(167 * uTime);
|
||||
float fullErasureThreshold = uOpacity + flickerOne + flickerTwo + flickerThree;
|
||||
float glowThreshold = fullErasureThreshold - 0.1;
|
||||
|
||||
|
||||
// If the noise over the erasure threshold, completely erase this pixel.
|
||||
if (noiseColor.r > fullErasureThreshold)
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -1,77 +0,0 @@
|
||||
using CalamityMod.NPCs;
|
||||
using CalamityMod.NPCs.Providence;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
using Rectangle = Microsoft.Xna.Framework.Rectangle;
|
||||
|
||||
namespace CalamityMod.Graphics.Drawers
|
||||
{
|
||||
public class HolyInfernoDrawer : BaseDrawer
|
||||
{
|
||||
#region Fields/Properties
|
||||
|
||||
public override DrawerLayer Layer => DrawerLayer.BeforeTiles;
|
||||
|
||||
public Providence Provi => (Main.npc[CalamityGlobalNPC.holyBoss].ModNPC as Providence);
|
||||
|
||||
//Should only draw if not in the main menu, provi is active and the boolean for drawing the border is true.
|
||||
public override bool ShouldDraw => !Main.gameMenu && CalamityGlobalNPC.holyBoss != -1 &&
|
||||
Main.npc[CalamityGlobalNPC.holyBoss].active && Providence.shouldDrawInfernoBorder;
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override void DrawToTarget(SpriteBatch spriteBatch)
|
||||
{
|
||||
var npc = Main.npc[CalamityGlobalNPC.holyBoss];
|
||||
var borderDistance = Providence.borderRadius;
|
||||
if (npc.HasValidTarget)
|
||||
{
|
||||
var target = Main.player[Main.myPlayer];
|
||||
var holyInfernoIntensity = target.Calamity().holyInfernoFadeIntensity;
|
||||
var prov = Provi;
|
||||
|
||||
//Begin drawing the inferno
|
||||
var blackTile = TextureAssets.MagicPixel;
|
||||
var diagonalNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/HarshNoise");
|
||||
var upwardPerlinNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/Perlin");
|
||||
var upwardNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/MeltyNoise");
|
||||
|
||||
var maxOpacity = 1f;
|
||||
if (prov.Dying)
|
||||
{
|
||||
//Death animation timer ends at 345f.
|
||||
maxOpacity = MathHelper.Lerp(1f, 0f, Utils.GetLerpValue(0f, 344f, prov.DeathAnimationTimer));
|
||||
}
|
||||
|
||||
var shader = GameShaders.Misc["CalamityMod:HolyInfernoShader"].Shader;
|
||||
shader.Parameters["colorMult"].SetValue(Main.dayTime ? 7.35f : 7.65f); //I want you to know it took considerable restraint to deliberately misspell colour.
|
||||
shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly);
|
||||
shader.Parameters["radius"].SetValue(borderDistance);
|
||||
shader.Parameters["anchorPoint"].SetValue(npc.Center);
|
||||
shader.Parameters["screenPosition"].SetValue(Main.screenPosition);
|
||||
shader.Parameters["screenSize"].SetValue(Main.ScreenSize.ToVector2());
|
||||
shader.Parameters["burnIntensity"].SetValue(holyInfernoIntensity);
|
||||
shader.Parameters["playerPosition"].SetValue(target.Center);
|
||||
shader.Parameters["maxOpacity"].SetValue(maxOpacity);
|
||||
shader.Parameters["day"].SetValue(Main.dayTime);
|
||||
|
||||
spriteBatch.GraphicsDevice.Textures[1] = diagonalNoise.Value;
|
||||
spriteBatch.GraphicsDevice.Textures[2] = upwardNoise.Value;
|
||||
spriteBatch.GraphicsDevice.Textures[3] = upwardPerlinNoise.Value;
|
||||
|
||||
//Manual end begin for the sampler state
|
||||
spriteBatch.End();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearWrap, DepthStencilState.None, Main.Rasterizer, shader, Main.GameViewMatrix.TransformationMatrix);
|
||||
Rectangle rekt = new(Main.screenWidth / 2, Main.screenHeight / 2, Main.screenWidth, Main.screenHeight);
|
||||
spriteBatch.Draw(blackTile.Value, rekt, null, default, 0f, blackTile.Value.Size() * 0.5f, 0, 0f);
|
||||
//Inferno drawing complete
|
||||
spriteBatch.ExitShaderRegion();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,13 @@ namespace CalamityMod.Graphics
|
||||
RenderTargetManager.ManagedTargets.Add(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current render target to the provided one.
|
||||
/// </summary>
|
||||
/// <param name="target">The render target to swap to</param>
|
||||
/// <param name="flushColor">The color to clear the screen with. Transparent by default</param>
|
||||
public void SwapTo(Color? flushColor = null) => Target.SwapTo(flushColor);
|
||||
|
||||
/// <summary>
|
||||
/// Automatically called by <see cref="RenderTargetManager"/>, do not call!
|
||||
/// </summary>
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Drawers
|
||||
namespace CalamityMod.Graphics.Renderers
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to handle drawing a visual effect to a rendertarget, then drawing the target to the screen at selected layer.
|
||||
/// </summary>
|
||||
public abstract class BaseDrawer
|
||||
public abstract class BaseRenderer : ModType
|
||||
{
|
||||
#region Fields/Properties
|
||||
/// <summary>
|
||||
/// The layer that the target should be drawn at.
|
||||
/// </summary>
|
||||
public abstract DrawerLayer Layer { get; }
|
||||
public abstract DrawLayer Layer { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the target should draw and be drawn to this frame.
|
||||
@@ -30,27 +32,20 @@ namespace CalamityMod.Graphics.Drawers
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public void Load()
|
||||
protected sealed override void Register()
|
||||
{
|
||||
MainTarget = new(true, ManagedRenderTarget.CreateScreenSizedTarget);
|
||||
OnLoad();
|
||||
ModTypeLookup<BaseRenderer>.Register(this);
|
||||
|
||||
if (RendererManager.Renderers.Contains(this))
|
||||
throw new Exception($"Renderer '{Name}' has already been registered!");
|
||||
|
||||
RendererManager.Renderers.Add(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on mod load.
|
||||
/// </summary>
|
||||
public virtual void OnLoad()
|
||||
{
|
||||
|
||||
}
|
||||
public sealed override void SetupContent() => SetStaticDefaults();
|
||||
|
||||
/// <summary>
|
||||
/// Called on mod unload.
|
||||
/// </summary>
|
||||
public virtual void OnUnload()
|
||||
{
|
||||
|
||||
}
|
||||
public sealed override void SetStaticDefaults() => MainTarget = new(true, ManagedRenderTarget.CreateScreenSizedTarget);
|
||||
|
||||
/// <summary>
|
||||
/// Draw whatever needed to the target here.
|
||||
@@ -62,10 +57,7 @@ namespace CalamityMod.Graphics.Drawers
|
||||
/// Draw the target here. By default, just draws the target.
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch"></param>
|
||||
public virtual void DrawTarget(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Draw(MainTarget, Vector2.Zero, Color.White);
|
||||
}
|
||||
public virtual void DrawTarget(SpriteBatch spriteBatch) => spriteBatch.Draw(MainTarget, Vector2.Zero, Color.White);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -4,17 +4,16 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Rectangle = Microsoft.Xna.Framework.Rectangle;
|
||||
|
||||
namespace CalamityMod.Graphics.Drawers
|
||||
namespace CalamityMod.Graphics.Renderers
|
||||
{
|
||||
public class DeerclopsShadowDrawer : BaseDrawer
|
||||
public class DeerclopsShadowRenderer : BaseRenderer
|
||||
{
|
||||
#region Fields/Properties
|
||||
|
||||
public override DrawerLayer Layer => DrawerLayer.AfterEverything;
|
||||
public override DrawLayer Layer => DrawLayer.AfterEverything;
|
||||
|
||||
public NPC deerclops => Main.npc[NPC.deerclopsBoss];
|
||||
public static NPC Deerclops => Main.npc[NPC.deerclopsBoss];
|
||||
|
||||
//Should only draw if not in the main menu, deerclops is active or the border is fading post-death,
|
||||
//it's rev+ and the boolean for drawing the border is true.
|
||||
@@ -27,7 +26,7 @@ namespace CalamityMod.Graphics.Drawers
|
||||
bool shouldDraw;
|
||||
bool deerclopsInactive = false;
|
||||
if (NPC.deerclopsBoss >= 0 && NPC.deerclopsBoss.WithinBounds(Main.npc.Length))
|
||||
shouldDraw = true;
|
||||
shouldDraw = Deerclops.HasValidTarget;
|
||||
else
|
||||
{
|
||||
shouldDraw = DeerclopsAI.borderScalar > 0f;
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace CalamityMod.Graphics.Drawers
|
||||
namespace CalamityMod.Graphics.Renderers
|
||||
{
|
||||
public enum DrawerLayer
|
||||
public enum DrawLayer
|
||||
{
|
||||
AfterEverything,
|
||||
BeforeTiles,
|
||||
@@ -0,0 +1,76 @@
|
||||
using CalamityMod.NPCs;
|
||||
using CalamityMod.NPCs.Providence;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Renderers
|
||||
{
|
||||
public class HolyInfernoRenderer : BaseRenderer
|
||||
{
|
||||
#region Fields/Properties
|
||||
|
||||
public override DrawLayer Layer => DrawLayer.BeforeTiles;
|
||||
|
||||
public static Providence Provi => Main.npc[CalamityGlobalNPC.holyBoss].ModNPC as Providence;
|
||||
|
||||
//Should only draw if not in the main menu, provi is active and the boolean for drawing the border is true.
|
||||
public override bool ShouldDraw => !Main.gameMenu && CalamityGlobalNPC.holyBoss != -1 &&
|
||||
Main.npc[CalamityGlobalNPC.holyBoss].active && Providence.shouldDrawInfernoBorder;
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override void DrawToTarget(SpriteBatch spriteBatch)
|
||||
{
|
||||
var npc = Main.npc[CalamityGlobalNPC.holyBoss];
|
||||
var borderDistance = Providence.borderRadius;
|
||||
if (!npc.HasValidTarget)
|
||||
return;
|
||||
|
||||
var target = Main.player[Main.myPlayer];
|
||||
var holyInfernoIntensity = target.Calamity().holyInfernoFadeIntensity;
|
||||
var prov = Provi;
|
||||
|
||||
//Begin drawing the inferno
|
||||
var blackTile = TextureAssets.MagicPixel;
|
||||
var diagonalNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/HarshNoise");
|
||||
var upwardPerlinNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/Perlin");
|
||||
var upwardNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/MeltyNoise");
|
||||
|
||||
var maxOpacity = 1f;
|
||||
if (prov.Dying)
|
||||
{
|
||||
//Death animation timer ends at 345f.
|
||||
maxOpacity = MathHelper.Lerp(1f, 0f, Utils.GetLerpValue(0f, 344f, prov.DeathAnimationTimer));
|
||||
}
|
||||
|
||||
var shader = GameShaders.Misc["CalamityMod:HolyInfernoShader"].Shader;
|
||||
shader.Parameters["colorMult"].SetValue(Main.dayTime ? 7.35f : 7.65f); //I want you to know it took considerable restraint to deliberately misspell colour.
|
||||
shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly);
|
||||
shader.Parameters["radius"].SetValue(borderDistance);
|
||||
shader.Parameters["anchorPoint"].SetValue(npc.Center);
|
||||
shader.Parameters["screenPosition"].SetValue(Main.screenPosition);
|
||||
shader.Parameters["screenSize"].SetValue(Main.ScreenSize.ToVector2());
|
||||
shader.Parameters["burnIntensity"].SetValue(holyInfernoIntensity);
|
||||
shader.Parameters["playerPosition"].SetValue(target.Center);
|
||||
shader.Parameters["maxOpacity"].SetValue(maxOpacity);
|
||||
shader.Parameters["day"].SetValue(Main.dayTime);
|
||||
|
||||
spriteBatch.GraphicsDevice.Textures[1] = diagonalNoise.Value;
|
||||
spriteBatch.GraphicsDevice.Textures[2] = upwardNoise.Value;
|
||||
spriteBatch.GraphicsDevice.Textures[3] = upwardPerlinNoise.Value;
|
||||
|
||||
//Manual end begin for the sampler state
|
||||
spriteBatch.End();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearWrap, DepthStencilState.None, Main.Rasterizer, shader, Main.GameViewMatrix.TransformationMatrix);
|
||||
Rectangle rekt = new(Main.screenWidth / 2, Main.screenHeight / 2, Main.screenWidth, Main.screenHeight);
|
||||
spriteBatch.Draw(blackTile.Value, rekt, null, default, 0f, blackTile.Value.Size() * 0.5f, 0, 0f);
|
||||
//Inferno drawing complete
|
||||
spriteBatch.ExitShaderRegion();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using CalamityMod.NPCs;
|
||||
using CalamityMod.NPCs.ExoMechs.Ares;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
@@ -7,9 +8,9 @@ using Terraria.Graphics.Shaders;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Drawers
|
||||
namespace CalamityMod.Graphics.Renderers
|
||||
{
|
||||
public class MiracleBlightDrawer : BaseDrawer
|
||||
public class MiracleBlightRenderer : BaseRenderer
|
||||
{
|
||||
#region Fields/Properties
|
||||
/// <summary>
|
||||
@@ -41,7 +42,7 @@ namespace CalamityMod.Graphics.Drawers
|
||||
private set;
|
||||
}
|
||||
|
||||
public override DrawerLayer Layer => DrawerLayer.NPC;
|
||||
public override DrawLayer Layer => DrawLayer.NPC;
|
||||
|
||||
// Unsure whether its more performant to always draw, or to check if any NPC actually has the debuff.
|
||||
public override bool ShouldDraw => true;
|
||||
@@ -69,6 +70,11 @@ namespace CalamityMod.Graphics.Drawers
|
||||
// Draw every npc to a single target that should have the miracle blight visual.
|
||||
foreach (NPC npc in Main.npc)
|
||||
{
|
||||
// I don't know why this isnt always the case in MP, but if the global npc cant be found then the effect cannot be applied anyway as it is impossible
|
||||
// to tell if they have miracle blight.
|
||||
if (!npc.TryGetGlobalNPC<CalamityGlobalNPC>(out _))
|
||||
continue;
|
||||
|
||||
if (ValidToDraw(npc))
|
||||
Main.instance.DrawNPC(npc.whoAmI, npc.behindTiles);
|
||||
}
|
||||
@@ -83,7 +89,6 @@ namespace CalamityMod.Graphics.Drawers
|
||||
MiscShaderData blightShader = GameShaders.Misc["CalamityMod:MiracleBlight"];
|
||||
blightShader.SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/Neurons"), 1);
|
||||
blightShader.UseOpacity(0.7f);
|
||||
blightShader.Shader.Parameters["uWorldPosition"]?.SetValue(Main.screenPosition);
|
||||
blightShader.Apply();
|
||||
|
||||
Main.spriteBatch.Draw(MainTarget, Vector2.Zero, Color.White);
|
||||
@@ -1,23 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using log4net.Util;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Drawers
|
||||
namespace CalamityMod.Graphics.Renderers
|
||||
{
|
||||
public class DrawerManager : ModSystem
|
||||
public class RendererManager : ModSystem
|
||||
{
|
||||
#region Fields/Properties
|
||||
public static List<BaseDrawer> Drawers
|
||||
public static List<BaseRenderer> Renderers
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
} = new();
|
||||
#endregion
|
||||
|
||||
#region Loading
|
||||
@@ -26,29 +25,15 @@ namespace CalamityMod.Graphics.Drawers
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
Drawers = new();
|
||||
|
||||
Main.QueueMainThreadAction(() =>
|
||||
{
|
||||
// This hooks here, because doing it any sooner causes the screen position to be a frame behind.
|
||||
On_Main.CheckMonoliths += DrawToTargets;
|
||||
On_Main.DrawNPCs += DrawNPCDrawers;
|
||||
On_Main.DrawProjectiles += DrawProjectileDrawers;
|
||||
On_Main.DrawPlayers_AfterProjectiles += DrawPlayerDrawers;
|
||||
On_Main.DrawBackgroundBlackFill += DrawBeforeTileDrawers;
|
||||
On_Main.DrawInfernoRings += DrawAfterEverythingDrawers;
|
||||
|
||||
var drawerType = typeof(BaseDrawer);
|
||||
|
||||
foreach (var type in Mod.Code.GetTypes())
|
||||
{
|
||||
if (!type.IsAbstract && type.IsSubclassOf(drawerType))
|
||||
{
|
||||
var drawer = Activator.CreateInstance(type) as BaseDrawer;
|
||||
drawer.Load();
|
||||
Drawers.Add(drawer);
|
||||
}
|
||||
}
|
||||
On_Main.DrawNPCs += DrawNPCRenderers;
|
||||
On_Main.DrawProjectiles += DrawProjectileRenderers;
|
||||
On_Main.DrawPlayers_AfterProjectiles += DrawPlayerRenderers;
|
||||
On_Main.DrawBackgroundBlackFill += DrawBeforeTileRenderers;
|
||||
On_Main.DrawInfernoRings += DrawAfterEverythingRenderers;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -57,20 +42,18 @@ namespace CalamityMod.Graphics.Drawers
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
// Clear the cached renderers, so they can be readded on mod loading when initialized.
|
||||
Renderers.Clear();
|
||||
|
||||
Main.QueueMainThreadAction(() =>
|
||||
{
|
||||
// Supposed to be auto-unloaded, but considering TMods poor track record with actually doing this, manually unload them.
|
||||
On_Main.CheckMonoliths -= DrawToTargets;
|
||||
On_Main.DrawNPCs -= DrawNPCDrawers;
|
||||
On_Main.DrawProjectiles -= DrawProjectileDrawers;
|
||||
On_Main.DrawPlayers_AfterProjectiles -= DrawPlayerDrawers;
|
||||
On_Main.DrawBackgroundBlackFill -= DrawBeforeTileDrawers;
|
||||
On_Main.DrawInfernoRings -= DrawAfterEverythingDrawers;
|
||||
|
||||
foreach (var drawer in Drawers)
|
||||
drawer.OnUnload();
|
||||
|
||||
Drawers = null;
|
||||
On_Main.DrawNPCs -= DrawNPCRenderers;
|
||||
On_Main.DrawProjectiles -= DrawProjectileRenderers;
|
||||
On_Main.DrawPlayers_AfterProjectiles -= DrawPlayerRenderers;
|
||||
On_Main.DrawBackgroundBlackFill -= DrawBeforeTileRenderers;
|
||||
On_Main.DrawInfernoRings -= DrawAfterEverythingRenderers;
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
@@ -83,74 +66,75 @@ namespace CalamityMod.Graphics.Drawers
|
||||
if (Main.gameMenu)
|
||||
return;
|
||||
|
||||
foreach (var drawer in Drawers)
|
||||
foreach (var renderer in Renderers)
|
||||
{
|
||||
if (!drawer.ShouldDraw)
|
||||
if (!renderer.ShouldDraw)
|
||||
continue;
|
||||
|
||||
drawer.MainTarget.SwapTo(Color.Transparent);
|
||||
renderer.MainTarget.SwapTo(Color.Transparent);
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
|
||||
drawer.DrawToTarget(Main.spriteBatch);
|
||||
renderer.DrawToTarget(Main.spriteBatch);
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
|
||||
Main.instance.GraphicsDevice.SetRenderTarget(null);
|
||||
}
|
||||
|
||||
private void DrawNPCDrawers(On_Main.orig_DrawNPCs orig, Main self, bool behindTiles)
|
||||
private void DrawNPCRenderers(On_Main.orig_DrawNPCs orig, Main self, bool behindTiles)
|
||||
{
|
||||
orig(self, behindTiles);
|
||||
|
||||
if (behindTiles)
|
||||
return;
|
||||
|
||||
var drawers = Drawers.Where(drawer => drawer.ShouldDraw && drawer.Layer is DrawerLayer.NPC);
|
||||
var renderers = Renderers.Where(renderer => renderer.ShouldDraw && renderer.Layer is DrawLayer.NPC);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer);
|
||||
|
||||
foreach (var drawer in drawers)
|
||||
drawer.DrawTarget(Main.spriteBatch);
|
||||
foreach (var renderer in renderers)
|
||||
renderer.DrawTarget(Main.spriteBatch);
|
||||
|
||||
Main.spriteBatch.ExitShaderRegion();
|
||||
}
|
||||
|
||||
private void DrawProjectileDrawers(On_Main.orig_DrawProjectiles orig, Main self)
|
||||
private void DrawProjectileRenderers(On_Main.orig_DrawProjectiles orig, Main self)
|
||||
{
|
||||
orig(self);
|
||||
|
||||
var drawers = Drawers.Where(drawer => drawer.ShouldDraw && drawer.Layer is DrawerLayer.Projectile);
|
||||
var renderers = Renderers.Where(renderer => renderer.ShouldDraw && renderer.Layer is DrawLayer.Projectile);
|
||||
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer);
|
||||
|
||||
foreach (var drawer in drawers)
|
||||
drawer.DrawTarget(Main.spriteBatch);
|
||||
foreach (var renderer in renderers)
|
||||
renderer.DrawTarget(Main.spriteBatch);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
|
||||
private void DrawPlayerDrawers(On_Main.orig_DrawPlayers_AfterProjectiles orig, Main self)
|
||||
private void DrawPlayerRenderers(On_Main.orig_DrawPlayers_AfterProjectiles orig, Main self)
|
||||
{
|
||||
orig(self);
|
||||
|
||||
var drawers = Drawers.Where(drawer => drawer.ShouldDraw && drawer.Layer is DrawerLayer.Player);
|
||||
var renderers = Renderers.Where(renderer => renderer.ShouldDraw && renderer.Layer is DrawLayer.Player);
|
||||
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer);
|
||||
|
||||
foreach (var drawer in drawers)
|
||||
drawer.DrawTarget(Main.spriteBatch);
|
||||
foreach (var renderer in renderers)
|
||||
renderer.DrawTarget(Main.spriteBatch);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
|
||||
private void DrawBeforeTileDrawers(On_Main.orig_DrawBackgroundBlackFill orig, Main self)
|
||||
private void DrawBeforeTileRenderers(On_Main.orig_DrawBackgroundBlackFill orig, Main self)
|
||||
{
|
||||
var drawers = Drawers.Where(drawer => drawer.ShouldDraw && drawer.Layer is DrawerLayer.BeforeTiles);
|
||||
var renderers = Renderers.Where(renderer => renderer.ShouldDraw && renderer.Layer is DrawLayer.BeforeTiles);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer);
|
||||
foreach (var drawer in drawers)
|
||||
drawer.DrawTarget(Main.spriteBatch);
|
||||
|
||||
foreach (var renderer in renderers)
|
||||
renderer.DrawTarget(Main.spriteBatch);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.Transform);
|
||||
@@ -158,29 +142,19 @@ namespace CalamityMod.Graphics.Drawers
|
||||
orig(self);
|
||||
}
|
||||
|
||||
private void DrawAfterEverythingDrawers(On_Main.orig_DrawInfernoRings orig, Main self)
|
||||
private void DrawAfterEverythingRenderers(On_Main.orig_DrawInfernoRings orig, Main self)
|
||||
{
|
||||
var drawers = Drawers.Where(drawer => drawer.ShouldDraw && drawer.Layer is DrawerLayer.AfterEverything);
|
||||
var renderers = Renderers.Where(renderer => renderer.ShouldDraw && renderer.Layer is DrawLayer.AfterEverything);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer);
|
||||
foreach (var drawer in drawers)
|
||||
drawer.DrawTarget(Main.spriteBatch);
|
||||
foreach (var renderer in renderers)
|
||||
renderer.DrawTarget(Main.spriteBatch);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.Transform);
|
||||
orig(self);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Misc Methods
|
||||
public static T GetDrawer<T>() where T : BaseDrawer
|
||||
{
|
||||
if (!Drawers.Any())
|
||||
return null;
|
||||
|
||||
return Drawers.First(drawer => drawer.GetType() == typeof(T)) as T;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ using CalamityMod.Buffs.StatDebuffs;
|
||||
using CalamityMod.Buffs.Summon.Whips;
|
||||
using CalamityMod.CalPlayer;
|
||||
using CalamityMod.Events;
|
||||
using CalamityMod.Graphics.Drawers;
|
||||
using CalamityMod.Graphics.Renderers;
|
||||
using CalamityMod.Items.Accessories;
|
||||
using CalamityMod.Items.Tools;
|
||||
using CalamityMod.Items.Weapons.Melee;
|
||||
@@ -5701,8 +5701,8 @@ namespace CalamityMod.NPCs
|
||||
VulnerabilityHexFireDrawer = null;
|
||||
|
||||
// Only draw the NPC if told to by the miracle blight drawer.
|
||||
if (MiracleBlightDrawer.ValidToDraw(npc))
|
||||
return MiracleBlightDrawer.ActuallyDoPreDraw;
|
||||
if (MiracleBlightRenderer.ValidToDraw(npc))
|
||||
return MiracleBlightRenderer.ActuallyDoPreDraw;
|
||||
}
|
||||
|
||||
// Draw a pillar of light and fade the background as an animation when skipping things in the DD2 event.
|
||||
|
||||
@@ -860,13 +860,6 @@ namespace CalamityMod
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current render target to the provided one.
|
||||
/// </summary>
|
||||
/// <param name="target">The render target to swap to</param>
|
||||
/// <param name="flushColor">The color to clear the screen with. Transparent by default</param>
|
||||
public static void SwapTo(this ManagedRenderTarget target, Color? flushColor = null) => SwapTo(target.Target, flushColor);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current render target to the provided one.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user