using System;
using CalamityMod.Enums;
using CalamityMod.Utilities.Daybreak.Buffers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Graphics.Renderers;
///
/// A class to handle drawing a visual effect to a rendertarget, then drawing the target to the screen at selected layer.
///
[Obsolete("BaseRenderer is obsolete; developers should explore other avenues for rendering")]
public abstract class BaseRenderer : ModType
{
#region Fields/Properties
///
/// The layer that the target should be drawn at.
///
public abstract GeneralDrawLayer Layer { get; }
///
/// Whether the target should draw and be drawn to this frame.
///
public abstract bool ShouldDraw { get; }
///
/// The target that the visual is drawn to. Automatically handled.
///
public RenderTargetLease MainTarget
{
get;
private set;
}
#endregion
#region Methods
protected sealed override void Register()
{
ModTypeLookup.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()
{
if (!Main.dedServ)
{
Main.QueueMainThreadAction(() =>
{
MainTarget = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice);
});
}
}
///
/// Called from .
///
public virtual void PreUpdate()
{
}
///
/// Called from .
///
public virtual void PostUpdate()
{
}
///
/// Draw whatever needed to the target here.
///
///
public abstract void DrawToTarget(SpriteBatch spriteBatch);
///
/// Draw the target here. By default, just draws the target.
///
///
public virtual void DrawTarget(SpriteBatch spriteBatch) => spriteBatch.Draw(MainTarget.Target, Vector2.Zero, Color.White);
#endregion
}