Files
CalamityModPublic/Graphics/Renderers/BaseRenderer.cs
T
fryzahh b33a70fd08 GeneralDrawLayer generalization + TempParticle start
* Split up GeneralDrawLayer.BeforeTiles into BeforeAllTiles and BeforeSolidTiles.
* Moved screen renderers, metaballs and pixelated primitive drawing to use GeneralDrawLayer and subsequentially removed their own draw layer enums.
* Moved screen renderers, metaballs, particles, pixelated primitive drawing and pixelated drawers draw calls to MechanicalILChanges.
* Added TempParticle and TempParticleManager, used for defining temporary particle handlers in any file for short-term, fully-modifiable particle effects
* Removed ParticleAutoDrawingOverride and added a "CustomShader" property and "PrepareCustomShader" method to Particle.cs. These should be used in conjunction when wanting to apply shader effects to particles. If anything more precise is needed, use the new TempParticleManager class.
2025-11-15 16:41:52 -04:00

81 lines
2.4 KiB
C#

using System;
using CalamityMod.Enums;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ModLoader;
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 BaseRenderer : ModType
{
#region Fields/Properties
/// <summary>
/// The layer that the target should be drawn at.
/// </summary>
public abstract GeneralDrawLayer Layer { get; }
/// <summary>
/// Whether the target should draw and be drawn to this frame.
/// </summary>
public abstract bool ShouldDraw { get; }
/// <summary>
/// The target that the visual is drawn to. Automatically handled.
/// </summary>
public ManagedRenderTarget MainTarget
{
get;
private set;
}
#endregion
#region Methods
protected sealed override void Register()
{
ModTypeLookup<BaseRenderer>.Register(this);
if (RendererManager.Renderers.Contains(this))
throw new Exception($"Renderer '{Name}' has already been registered!");
RendererManager.Renderers.Add(this);
}
public sealed override void SetupContent() => SetStaticDefaults();
public sealed override void SetStaticDefaults() => MainTarget = new(true, ManagedRenderTarget.CreateScreenSizedTarget);
/// <summary>
/// Called from <see cref="ModSystem.PreUpdateEntities"/>.
/// </summary>
public virtual void PreUpdate()
{
}
/// <summary>
/// Called from <see cref="ModSystem.PostUpdateEverything"/>.
/// </summary>
public virtual void PostUpdate()
{
}
/// <summary>
/// Draw whatever needed to the target here.
/// </summary>
/// <param name="spriteBatch"></param>
public abstract void DrawToTarget(SpriteBatch spriteBatch);
/// <summary>
/// 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);
#endregion
}
}