From ff45607ee2995ab280ca990d53a041654f6eb2f8 Mon Sep 17 00:00:00 2001
From: Toasty <74939552+toasty599@users.noreply.github.com>
Date: Thu, 29 Feb 2024 06:17:19 +0000
Subject: [PATCH] Primitive System Remake (#23)
* - Primitive system rewrite, start of converting old code to use the newer system.
* - Tweaks to the primitive manager to match the old one.
- Finished porting old uses of the primitives to the new ones.
- Improved XML documentation on the newer ones.
* Delete en-US.hjson
* Remove cosmic shiv auto-entry
* - Indentation fixes.
* - Remove interface access modifiers
---
.../Primitives/IPixelatedPrimitiveRenderer.cs | 20 ++
.../Primitives/PixelationPrimitiveLayer.cs | 15 +
.../Primitives/PrimitivePixelationSystem.cs | 158 ++++++++++
Graphics/Primitives/PrimitiveSet.cs | 296 ++++++++++++++++++
Graphics/Primitives/PrimitiveSettings.cs | 92 ++++++
Graphics/Primitives/PrimitiveTrail.cs | 262 ----------------
.../VertexPosition2DColorTexture.cs | 46 +++
NPCs/AcidRain/AcidEel.cs | 10 +-
NPCs/ExoMechs/Apollo/Apollo.cs | 25 +-
NPCs/ExoMechs/Ares/AresBody.cs | 26 +-
NPCs/ExoMechs/Artemis/Artemis.cs | 24 +-
NPCs/SupremeCalamitas/BrimstoneHeart.cs | 8 +-
Projectiles/Boss/ApolloChargeTelegraph.cs | 7 +-
Projectiles/Boss/AresTeslaOrb.cs | 12 +-
Projectiles/Boss/ArtemisChargeTelegraph.cs | 10 +-
Projectiles/Boss/ArtemisSpinLaserbeam.cs | 10 +-
.../Boss/CirrusPhotonRipperPrismTooth.cs | 7 +-
Projectiles/Boss/DraedonSummonLaser.cs | 9 +-
Projectiles/Boss/DyingSun.cs | 8 +-
Projectiles/Boss/InfernadoRevenge.cs | 7 +-
.../DraedonsArsenal/PhaseslayerProjectile.cs | 7 +-
.../DraedonsArsenal/SnakeEyesProjectile.cs | 5 +-
Projectiles/Enemy/GammRayBurst.cs | 9 +-
Projectiles/Magic/ApotheosisEnergy.cs | 9 +-
Projectiles/Magic/ArtAttackStar.cs | 9 +-
Projectiles/Magic/EternityHex.cs | 9 +-
Projectiles/Magic/ExoVortex.cs | 8 +-
Projectiles/Magic/ExoVortex2.cs | 8 +-
Projectiles/Magic/FabBolt.cs | 9 +-
Projectiles/Magic/FabRay.cs | 10 +-
Projectiles/Magic/RainbowRocket.cs | 7 +-
Projectiles/Magic/RancorLaserbeam.cs | 7 +-
Projectiles/Magic/WulfrumBolt.cs | 9 +-
Projectiles/Melee/EonBolt.cs | 8 +-
Projectiles/Melee/Exobeam.cs | 20 +-
Projectiles/Melee/ExobladeProj.cs | 15 +-
Projectiles/Melee/MarniteObliteratorProj.cs | 11 +-
Projectiles/Melee/PrismTooth.cs | 7 +-
Projectiles/Melee/RendingNeedle.cs | 10 +-
Projectiles/Melee/StygianShieldAttack.cs | 10 +-
Projectiles/Melee/TaintedBladeSlasher.cs | 22 +-
Projectiles/Melee/TerratomereBeam.cs | 8 +-
Projectiles/Melee/TerratomereBigSlash.cs | 8 +-
Projectiles/Melee/TerratomereHoldoutProj.cs | 7 +-
Projectiles/Melee/ViolenceSlashProjectile.cs | 9 +-
Projectiles/Melee/ViolenceThrownProjectile.cs | 9 +-
Projectiles/Melee/WulfrumScrew.cs | 9 +-
Projectiles/Ranged/ExoCrystalArrow.cs | 10 +-
Projectiles/Ranged/ExoLightningBolt.cs | 7 +-
Projectiles/Ranged/MarksmanShot.cs | 7 +-
Projectiles/Ranged/MeowCreature.cs | 9 +-
Projectiles/Ranged/MineralMortarProjectile.cs | 7 +-
Projectiles/Ranged/PristineFire.cs | 9 +-
Projectiles/Ranged/SpeedBlasterShot.cs | 7 +-
Projectiles/Ranged/TelluricGlareArrow.cs | 9 +-
Projectiles/Ranged/TheMaelstromShark.cs | 7 +-
Projectiles/Ranged/WulfrumScrapBullet.cs | 8 +-
.../Rogue/DynamicPursuerElectricity.cs | 13 +-
.../Rogue/FishboneBoomerangProjectile.cs | 1 -
Projectiles/Rogue/ScarletDevilProjectile.cs | 8 +-
Projectiles/Rogue/StormfrontLightning.cs | 8 +-
Projectiles/Rogue/WulfrumKnifeProj.cs | 8 +-
.../Summon/CnidarianJellyfishOnTheString.cs | 9 +-
Projectiles/Summon/CosmilampBeam.cs | 12 +-
Projectiles/Summon/DaedalusLightning.cs | 9 +-
.../Summon/SmallAresArms/MinionTeslaOrb.cs | 16 +-
Projectiles/Summon/WulfrumDroid.cs | 6 +-
Projectiles/Summon/WulfrumEnergyBurst.cs | 8 +-
Projectiles/Summon/WulfrumFusionBolt.cs | 7 +-
Projectiles/Typeless/GemTechArmorGem.cs | 7 +-
Projectiles/Typeless/MythrilFlare.cs | 9 +-
Projectiles/Typeless/SuicideBomberDemon.cs | 8 +-
Projectiles/Typeless/WulfrumHook.cs | 9 +-
73 files changed, 818 insertions(+), 711 deletions(-)
create mode 100644 Graphics/Primitives/IPixelatedPrimitiveRenderer.cs
create mode 100644 Graphics/Primitives/PixelationPrimitiveLayer.cs
create mode 100644 Graphics/Primitives/PrimitivePixelationSystem.cs
create mode 100644 Graphics/Primitives/PrimitiveSet.cs
create mode 100644 Graphics/Primitives/PrimitiveSettings.cs
delete mode 100644 Graphics/Primitives/PrimitiveTrail.cs
create mode 100644 Graphics/Primitives/VertexPosition2DColorTexture.cs
diff --git a/Graphics/Primitives/IPixelatedPrimitiveRenderer.cs b/Graphics/Primitives/IPixelatedPrimitiveRenderer.cs
new file mode 100644
index 0000000000..7270d3e93a
--- /dev/null
+++ b/Graphics/Primitives/IPixelatedPrimitiveRenderer.cs
@@ -0,0 +1,20 @@
+using Microsoft.Xna.Framework.Graphics;
+
+namespace CalamityMod.Graphics.Primitives
+{
+ ///
+ /// Use to sucessfully render primitives with pixelation with an NPC or Projectile.
+ ///
+ public interface IPixelatedPrimitiveRenderer
+ {
+ ///
+ /// The layer to render the primitive(s) to.
+ ///
+ PixelationPrimitiveLayer LayerToRenderTo => PixelationPrimitiveLayer.BeforeProjectiles;
+
+ ///
+ /// Render primitives that use pixelation here.
+ ///
+ void RenderPixelatedPrimitives(SpriteBatch spriteBatch);
+ }
+}
diff --git a/Graphics/Primitives/PixelationPrimitiveLayer.cs b/Graphics/Primitives/PixelationPrimitiveLayer.cs
new file mode 100644
index 0000000000..1ed0348bc8
--- /dev/null
+++ b/Graphics/Primitives/PixelationPrimitiveLayer.cs
@@ -0,0 +1,15 @@
+using Microsoft.Xna.Framework.Graphics;
+
+namespace CalamityMod.Graphics.Primitives
+{
+ ///
+ /// Controls what layer the renders to.
+ ///
+ public enum PixelationPrimitiveLayer
+ {
+ BeforeNPCs,
+ AfterNPCs,
+ BeforeProjectiles,
+ AfterProjectiles
+ }
+}
diff --git a/Graphics/Primitives/PrimitivePixelationSystem.cs b/Graphics/Primitives/PrimitivePixelationSystem.cs
new file mode 100644
index 0000000000..27a40a1efd
--- /dev/null
+++ b/Graphics/Primitives/PrimitivePixelationSystem.cs
@@ -0,0 +1,158 @@
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Terraria;
+using Terraria.ModLoader;
+
+namespace CalamityMod.Graphics.Primitives
+{
+ public class PrimitivePixelationSystem : ModSystem
+ {
+ #region Fields/Properties
+ private static ManagedRenderTarget PixelationTarget_BeforeNPCs;
+
+ private static ManagedRenderTarget PixelationTarget_AfterNPCs;
+
+ private static ManagedRenderTarget PixelationTarget_BeforeProjectiles;
+
+ private static ManagedRenderTarget PixelationTarget_AfterProjectiles;
+
+ private static RenderTarget2D CreatePixelTarget(int width, int height) => new(Main.instance.GraphicsDevice, width / 2, height / 2);
+
+ ///
+ /// Whether the system is currently rendering any primitives.
+ ///
+ public static bool CurrentlyRendering
+ {
+ get;
+ private set;
+ }
+ #endregion
+
+ #region Loading
+ public override void Load()
+ {
+ On_Main.CheckMonoliths += DrawToTargets;
+ On_Main.DoDraw_DrawNPCsOverTiles += DrawTarget_NPCs;
+ On_Main.DrawProjectiles += DrawTarget_Projectiles;
+
+ PixelationTarget_BeforeNPCs = new(true, CreatePixelTarget);
+ PixelationTarget_AfterNPCs = new(true, CreatePixelTarget);
+ PixelationTarget_BeforeProjectiles = new(true, CreatePixelTarget);
+ PixelationTarget_AfterProjectiles = new(true, CreatePixelTarget);
+ }
+
+ public override void Unload()
+ {
+ On_Main.CheckMonoliths -= DrawToTargets;
+ On_Main.DoDraw_DrawNPCsOverTiles -= DrawTarget_NPCs;
+ }
+ #endregion
+
+ #region Drawing To Targets
+ private void DrawToTargets(On_Main.orig_CheckMonoliths orig)
+ {
+ if (Main.gameMenu)
+ {
+ orig();
+ return;
+ }
+
+ var beforeNPCs = new List();
+ var afterNPCs = new List();
+ var beforeProjectiles = new List();
+ var afterProjectiles = new List();
+
+ // Check every active projectile.
+ for (int i = 0; i < Main.maxProjectiles; i++)
+ {
+ var projectile = Main.projectile[i];
+
+ // If the projectile is active, a mod projectile, and uses the interface, add it to the list of primitives to draw this frame.
+ if (projectile.active && projectile.ModProjectile != null && projectile.ModProjectile is IPixelatedPrimitiveRenderer pixelPrimitiveProjectile)
+ {
+ var listToUse = pixelPrimitiveProjectile.LayerToRenderTo switch
+ {
+ PixelationPrimitiveLayer.BeforeNPCs => beforeNPCs,
+ PixelationPrimitiveLayer.AfterNPCs => afterNPCs,
+ PixelationPrimitiveLayer.BeforeProjectiles => beforeProjectiles,
+ _ => afterProjectiles
+ };
+ listToUse.Add(pixelPrimitiveProjectile);
+ }
+ }
+
+ // Check every active NPC.
+ for (int i = 0; i < Main.maxNPCs; i++)
+ {
+ var npc = Main.npc[i];
+
+ // If the NPC is active, a mod NPC, and uses the interface, add it to the list of primitives to draw this frame.
+ if (npc.active && npc.ModNPC != null && npc.ModNPC is IPixelatedPrimitiveRenderer pixelPrimitiveNPC)
+ {
+ var listToUse = pixelPrimitiveNPC.LayerToRenderTo switch
+ {
+ PixelationPrimitiveLayer.BeforeNPCs => beforeNPCs,
+ PixelationPrimitiveLayer.AfterNPCs => afterNPCs,
+ PixelationPrimitiveLayer.BeforeProjectiles => beforeProjectiles,
+ _ => afterProjectiles
+ };
+ listToUse.Add(pixelPrimitiveNPC);
+ }
+ }
+
+ CurrentlyRendering = true;
+
+ DrawPrimsToRenderTarget(PixelationTarget_BeforeNPCs, beforeNPCs);
+ DrawPrimsToRenderTarget(PixelationTarget_AfterNPCs, afterNPCs);
+ DrawPrimsToRenderTarget(PixelationTarget_BeforeProjectiles, beforeProjectiles);
+ DrawPrimsToRenderTarget(PixelationTarget_AfterProjectiles, afterProjectiles);
+
+ Main.instance.GraphicsDevice.SetRenderTarget(null);
+
+ CurrentlyRendering = false;
+ orig();
+ }
+
+ private static void DrawPrimsToRenderTarget(RenderTarget2D renderTarget, List pixelPrimitives)
+ {
+ // Swap to the target regardless, in order to clear any leftover content from last frame. Not doing this results in the final frame lingering once it stops rendering.
+ renderTarget.SwapTo();
+
+ if (pixelPrimitives.Any())
+ {
+ Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null);
+
+ foreach (var pixelPrimitiveDrawer in pixelPrimitives)
+ pixelPrimitiveDrawer.RenderPixelatedPrimitives(Main.spriteBatch);
+
+ Main.spriteBatch.End();
+ }
+ }
+ #endregion
+
+ #region Target Drawing
+ private void DrawTarget_NPCs(On_Main.orig_DoDraw_DrawNPCsOverTiles orig, Main self)
+ {
+ DrawTargetScaled(PixelationTarget_BeforeNPCs);
+ orig(self);
+ DrawTargetScaled(PixelationTarget_AfterNPCs);
+ }
+
+ private void DrawTarget_Projectiles(On_Main.orig_DrawProjectiles orig, Main self)
+ {
+ DrawTargetScaled(PixelationTarget_BeforeProjectiles);
+ orig(self);
+ DrawTargetScaled(PixelationTarget_AfterProjectiles);
+ }
+
+ private static void DrawTargetScaled(ManagedRenderTarget target)
+ {
+ Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
+ Main.spriteBatch.Draw(target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f);
+ Main.spriteBatch.End();
+ }
+ #endregion
+ }
+}
diff --git a/Graphics/Primitives/PrimitiveSet.cs b/Graphics/Primitives/PrimitiveSet.cs
new file mode 100644
index 0000000000..a911dd3b20
--- /dev/null
+++ b/Graphics/Primitives/PrimitiveSet.cs
@@ -0,0 +1,296 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Terraria;
+using Terraria.Graphics.Shaders;
+
+namespace CalamityMod.Graphics.Primitives
+{
+ ///
+ /// This both acts as an instanceable struct containing primitive trail data, and as a manager that creates and renders said instances.
+ /// To use normally, in the draw method of an NPC or Projectile call .
+ ///
+ /// - The first param should be the positions to use for the trail.
+ /// - The second is a struct that allows you to choose a desired configuration of settings to use with the trail, to allow for customization.
+ /// - The third controls how many points are created for the trail, and the fourth determines whether the primitive is subsequently rendered.
+ /// - If you do not render in , you MUST call manually on the created instance to make it actually appear.
+ ///
+ /// If you wish to use pixelation, you MUST make the NPC/Projectile inherit and use instead.
+ /// You can also optionally specify a render layer with . It is by default.
+ ///
+ public readonly struct PrimitiveSet
+ {
+ #region Instance Members
+ ///
+ /// The vertices of the set.
+ ///
+ public readonly VertexPosition2DColorTexture[] Vertices;
+
+ ///
+ /// The indices of the set.
+ ///
+ public readonly int[] Indices;
+
+ ///
+ /// The settings of the set.
+ ///
+ public readonly PrimitiveSettings Settings;
+
+ private PrimitiveSet(VertexPosition2DColorTexture[] vertices, int[] indices, PrimitiveSettings settings)
+ {
+ Vertices = vertices;
+ Indices = indices;
+ Settings = settings;
+ }
+ #endregion
+
+ #region Static Members
+ private static void PerformPixelationSafetyChecks(PrimitiveSettings settings)
+ {
+ // Don't allow accidental screw ups with these.
+ if (settings.Pixelate && !PrimitivePixelationSystem.CurrentlyRendering)
+ throw new Exception("Error: Primitives using pixelation MUST be prepared/rendered from the IPixelatedPrimitiveRenderer.RenderPixelatedPrimitives method, did you forget to use the interface?");
+ else if (!settings.Pixelate && PrimitivePixelationSystem.CurrentlyRendering)
+ throw new Exception("Error: Primitives not using pixelation MUST NOT be prepared/rendered from the IPixelatedPrimitiveRenderer.RenderPixelatedPrimitives method.");
+ }
+
+ ///
+ /// Prepares a based on the provided information, and optionally renders it.
+ ///
+ /// The list of positions to use. Keep in mind that these are expected to be in world position, and is automatically subtracted from them all.
+ /// The primitive draw settings to use.
+ /// The amount of points to use. More is higher detailed, but less performant. By default, is the number of positions provided. Going above 100 is NOT recommended.
+ /// Whether to render the set.
+ /// The prepared set.
+ public static PrimitiveSet? Prepare(IEnumerable positions, PrimitiveSettings settings, int? pointsToCreate = null, bool render = true)
+ {
+ PerformPixelationSafetyChecks(settings);
+
+ int positionCount = positions.Count();
+
+ // Return if not enough to draw anything.
+ if (positionCount <= 2)
+ return null;
+
+ // Cull out any zeroed points.
+ positions = positions.Where(p => p != Vector2.Zero);
+ List trailPoints = PreparePointsRectangleTrail(positions, settings, pointsToCreate ?? positionCount).ToList();
+
+ // A trail with only one point or less has nothing to connect to, and therefore, can't make a trail.
+ if (trailPoints.Count <= 2)
+ return null;
+
+ // If the trail point has any NaN positions, don't draw anything.
+ if (trailPoints.Any(point => point.HasNaNs()))
+ return null;
+
+ // If the trail points are all equal, don't draw anything.
+ if (trailPoints.All(point => point == trailPoints[0]))
+ return null;
+
+ IEnumerable vertices = CreateVerticesRectangleTrail(trailPoints.ToList(), settings);
+ int[] indices = CreateIndicesRectangleTrail(trailPoints.Count);
+
+ // Create the set, and just return it if not asked to render.
+ PrimitiveSet set = new(vertices.ToArray(), indices, settings);
+ if (!render)
+ return set;
+
+ // Else render the set and return it.
+ return set.Render();
+ }
+ #endregion
+
+ #region Instance Methods
+ ///
+ /// Renders the provided primitive set to the screen.
+ ///
+ /// The provided set.
+ public PrimitiveSet Render()
+ {
+ PerformPixelationSafetyChecks(Settings);
+
+ if (Indices.Length % 6 != 0 || Vertices.Length <= 3)
+ return this;
+
+ // Perform screen culling, for performance reasons.
+ Main.instance.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
+ Main.instance.GraphicsDevice.RasterizerState.ScissorTestEnable = true;
+ Main.instance.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, Main.screenWidth, Main.screenHeight);
+
+ Matrix view;
+ Matrix projection;
+ if (Settings.Pixelate)
+ CalcuatePixelatedPerspectiveMatrices(out view, out projection);
+ else
+ CalamityUtils.CalculatePerspectiveMatricies(out view, out projection);
+
+ var shaderToUse = Settings.Shader ?? GameShaders.Misc["CalamityMod:StandardPrimitiveShader"];
+ shaderToUse.Shader.Parameters["uWorldViewProjection"].SetValue(view * projection);
+ shaderToUse.Apply();
+
+ // Render the set.
+ Main.instance.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, Vertices, 0, Vertices.Length, Indices, 0, Indices.Length / 3);
+ Main.pixelShader.CurrentTechnique.Passes[0].Apply();
+ return this;
+ }
+ #endregion
+
+ #region Set Preperation
+ private static IEnumerable PreparePointsRectangleTrail(IEnumerable positions, PrimitiveSettings settings, int pointsToCreate)
+ {
+ // Don't smoothen the points unless explicitly told do so.
+ if (!settings.Smoothen)
+ {
+ List basePoints = positions.Where(originalPosition => originalPosition != Vector2.Zero).ToList();
+ List endPoints = new();
+
+ if (basePoints.Count <= 2)
+ return endPoints;
+
+ // Remap the original positions across a certain length.
+ for (int i = 0; i < pointsToCreate; i++)
+ {
+ float completionRatio = i / (float)(pointsToCreate - 1f);
+ int currentIndex = (int)(completionRatio * (basePoints.Count - 1));
+ Vector2 currentPoint = basePoints[currentIndex];
+ Vector2 nextPoint = basePoints[(currentIndex + 1) % basePoints.Count];
+ endPoints.Add(Vector2.Lerp(currentPoint, nextPoint, completionRatio * (basePoints.Count - 1) % 0.99999f) - Main.screenPosition);
+ }
+ return endPoints;
+ }
+
+ List controlPoints = new();
+ for (int i = 0; i < positions.Count(); i++)
+ {
+ // Don't incorporate points that are zeroed out.
+ // They are almost certainly a result of incomplete oldPos arrays.
+ if (positions.ElementAt(i) == Vector2.Zero)
+ continue;
+
+ float completionRatio = i / (float)positions.Count();
+ Vector2 offset = -Main.screenPosition;
+ if (settings.OffsetFunction != null)
+ offset += settings.OffsetFunction(completionRatio);
+ controlPoints.Add(positions.ElementAt(i) + offset);
+ }
+ List points = new();
+
+ // Avoid stupid index errors.
+ if (controlPoints.Count <= 4)
+ return controlPoints;
+
+ for (int j = 0; j < pointsToCreate; j++)
+ {
+ float splineInterpolant = j / (float)pointsToCreate;
+ float localSplineInterpolant = splineInterpolant * (controlPoints.Count - 1f) % 1f;
+ int localSplineIndex = (int)(splineInterpolant * (controlPoints.Count - 1f));
+
+ Vector2 farLeft;
+ Vector2 left = controlPoints[localSplineIndex];
+ Vector2 right = controlPoints[localSplineIndex + 1];
+ Vector2 farRight;
+
+ // Special case: If the spline attempts to access the previous/next index but the index is already at the very beginning/end, simply
+ // cheat a little bit by creating a phantom point that's mirrored from the previous one.
+ if (localSplineIndex <= 0)
+ {
+ Vector2 mirrored = left * 2f - right;
+ farLeft = mirrored;
+ }
+ else
+ farLeft = controlPoints[localSplineIndex - 1];
+
+ if (localSplineIndex >= controlPoints.Count - 2)
+ {
+ Vector2 mirrored = right * 2f - left;
+ farRight = mirrored;
+ }
+ else
+ farRight = controlPoints[localSplineIndex + 2];
+
+ points.Add(Vector2.CatmullRom(farLeft, left, right, farRight, localSplineInterpolant));
+ }
+
+ // Manually insert the front and end points.
+ points.Insert(0, controlPoints.First());
+ points.Add(controlPoints.Last());
+
+ return points;
+ }
+
+ private static IEnumerable CreateVerticesRectangleTrail(List positions, PrimitiveSettings settings)
+ {
+ List vertices = new();
+
+ for (int i = 0; i < positions.Count; i++)
+ {
+ float completionRatio = i / (float)(positions.Count - 1);
+ float widthAtVertex = settings.WidthFunction(completionRatio);
+ Color vertexColor = settings.ColorFunction(completionRatio);
+ Vector2 currentPosition = positions[i];
+ Vector2 directionToAhead = i == positions.Count - 1 ? (positions[i] - positions[i - 1]).SafeNormalize(Vector2.Zero) : (positions[i + 1] - positions[i]).SafeNormalize(Vector2.Zero);
+
+ Vector2 leftCurrentTextureCoord = new(completionRatio, 0f);
+ Vector2 rightCurrentTextureCoord = new(completionRatio, 1f);
+
+ // Point 90 degrees away from the direction towards the next point, and use it to mark the edges of the rectangle.
+ // This doesn't use RotatedBy for the sake of performance (there can potentially be a lot of trail points).
+ Vector2 sideDirection = new(-directionToAhead.Y, directionToAhead.X);
+
+ Vector2 left = currentPosition - sideDirection * widthAtVertex;
+ Vector2 right = currentPosition + sideDirection * widthAtVertex;
+
+ // Override the initial vertex positions if requested.
+ if (i == 0 && settings.InitialVertexPositionsOverride.HasValue && settings.InitialVertexPositionsOverride.Value.Item1 != Vector2.Zero && settings.InitialVertexPositionsOverride.Value.Item2 != Vector2.Zero)
+ {
+ left = settings.InitialVertexPositionsOverride.Value.Item1;
+ right = settings.InitialVertexPositionsOverride.Value.Item2;
+ }
+
+ // What this is doing, at its core, is defining a rectangle based on two triangles.
+ // These triangles are defined based on the width of the strip at that point.
+ // The resulting rectangles combined are what make the trail itself.
+ vertices.Add(new VertexPosition2DColorTexture(left, vertexColor, leftCurrentTextureCoord));
+ vertices.Add(new VertexPosition2DColorTexture(right, vertexColor, rightCurrentTextureCoord));
+ }
+
+ return vertices;
+ }
+
+ private static int[] CreateIndicesRectangleTrail(int pointCount)
+ {
+ // What this is doing is basically representing each point on the vertices list as
+ // indices. These indices should come together to create a tiny rectangle that acts
+ // as a segment on the trail. This is achieved here by splitting the indices (or rather, points)
+ // into 2 triangles, which requires 6 points.
+ // The logic here basically determines which indices are connected together.
+ int totalIndices = (pointCount - 1) * 6;
+ int[] indices = new int[totalIndices];
+
+ for (int i = 0; i < pointCount - 2; i++)
+ {
+ int startingTriangleIndex = i * 6;
+ int connectToIndex = i * 2;
+ indices[startingTriangleIndex] = connectToIndex;
+ indices[startingTriangleIndex + 1] = connectToIndex + 1;
+ indices[startingTriangleIndex + 2] = connectToIndex + 2;
+ indices[startingTriangleIndex + 3] = connectToIndex + 2;
+ indices[startingTriangleIndex + 4] = connectToIndex + 1;
+ indices[startingTriangleIndex + 5] = connectToIndex + 3;
+ }
+
+ return indices;
+ }
+
+ private static void CalcuatePixelatedPerspectiveMatrices(out Matrix viewMatrix, out Matrix projectionMatrix)
+ {
+ // Due to the scaling, the normal transformation calcuations do not work with pixelated primitives.
+ projectionMatrix = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -1, 1);
+ viewMatrix = Matrix.Identity;
+ }
+ #endregion
+ }
+}
diff --git a/Graphics/Primitives/PrimitiveSettings.cs b/Graphics/Primitives/PrimitiveSettings.cs
new file mode 100644
index 0000000000..bbee27c4a7
--- /dev/null
+++ b/Graphics/Primitives/PrimitiveSettings.cs
@@ -0,0 +1,92 @@
+using Microsoft.Xna.Framework;
+using Terraria.Graphics.Shaders;
+
+namespace CalamityMod.Graphics.Primitives
+{
+ ///
+ /// Contains all the various options to use when creating a primitive trail. New members can be added freely without breaking existing implementations.
+ ///
+ public readonly struct PrimitiveSettings
+ {
+ #region Delegates
+ ///
+ /// A delegate to dynamically determine the width of the trail at each position.
+ ///
+ /// The current position along the trail as a 0-1 interlopant value.
+ /// The width for the current point.
+ public delegate float VertexWidthFunction(float trailLengthInterpolant);
+
+ ///
+ /// A delegate to dynamically determine the color of the trail at each position.
+ ///
+ /// The current position along the trail as a 0-1 interlopant value.
+ /// The color for the current point.
+ public delegate Color VertexColorFunction(float trailLengthInterpolant);
+
+ ///
+ /// A delegate to dynamically determine the offset of the trail at each position.
+ ///
+ /// The current position along the trail as a 0-1 interlopant value.
+ /// The offset for the current point.
+ public delegate Vector2 VertexOffsetFunction(float trailLengthInterpolant);
+ #endregion
+
+ #region Instance Fields
+ ///
+ /// Used to determine the width of each vertex.
+ ///
+ public readonly VertexWidthFunction WidthFunction;
+
+ ///
+ /// Used to determine the color of each vertex.
+ ///
+ public readonly VertexColorFunction ColorFunction;
+
+ ///
+ /// Used to offset each position when generating them.
+ ///
+ public readonly VertexOffsetFunction OffsetFunction;
+
+ ///
+ /// Whether to use smoothening when generating the vertex positions from the provided ones Recommended to be on by default.
+ ///
+ public readonly bool Smoothen;
+
+ ///
+ /// Whether to pixelate the primitives. Recommended to be on by default.
+ ///
+ public readonly bool Pixelate;
+
+ ///
+ /// The shader to apply when rendering.
+ ///
+ public readonly MiscShaderData Shader;
+
+ ///
+ /// An optional override to force the trail to use the provided positions as the side positions of the initial vertex. They are the left and right positions respectively.
+ ///
+ public readonly (Vector2, Vector2)? InitialVertexPositionsOverride;
+ #endregion
+
+ ///
+ /// Contains all the various options to use when creating a primitive trail.
+ ///
+ /// Used to determine the width of each vertex.
+ /// Used to determine the color of each vertex.
+ /// Used to offset each position when generating them.
+ /// Whether to use smoothening when generating the vertex positions from the provided ones. Recommended to be enabled.
+ /// Whether to pixelate the primitives. Recommended to be enabled if the effect was designed with this in mind.
+ /// The shader to apply when rendering the primitives.
+ /// An optional override to force the trail to use the provided positions as the side positions of the initial vertex. They are the left and right positions respectively and should be in screen space.
+ public PrimitiveSettings(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, VertexOffsetFunction offsetFunction = null, bool smoothen = true, bool pixelate = false, MiscShaderData shader = null, (Vector2, Vector2)? initialVertexPositionsOverride = null)
+ {
+ WidthFunction = widthFunction;
+ ColorFunction = colorFunction;
+ OffsetFunction = offsetFunction;
+ Smoothen = smoothen;
+ Pixelate = pixelate;
+ Shader = shader;
+ InitialVertexPositionsOverride = initialVertexPositionsOverride;
+ }
+ }
+}
diff --git a/Graphics/Primitives/PrimitiveTrail.cs b/Graphics/Primitives/PrimitiveTrail.cs
deleted file mode 100644
index 16e3b48dd7..0000000000
--- a/Graphics/Primitives/PrimitiveTrail.cs
+++ /dev/null
@@ -1,262 +0,0 @@
-using CalamityMod.DataStructures;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Terraria;
-using Terraria.Graphics.Shaders;
-
-namespace CalamityMod
-{
- public class PrimitiveTrail
- {
- public struct VertexPosition2DColor : IVertexType
- {
- public Vector2 Position;
- public Color Color;
- public Vector2 TextureCoordinates;
- public VertexDeclaration VertexDeclaration => _vertexDeclaration;
-
- private static readonly VertexDeclaration _vertexDeclaration = new VertexDeclaration(new VertexElement[]
- {
- new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0),
- new VertexElement(8, VertexElementFormat.Color, VertexElementUsage.Color, 0),
- new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
- });
- public VertexPosition2DColor(Vector2 position, Color color, Vector2 textureCoordinates)
- {
- Position = position;
- Color = color;
- TextureCoordinates = textureCoordinates;
- }
- }
-
- public delegate float VertexWidthFunction(float completionRatio);
- public delegate Color VertexColorFunction(float completionRatio);
-
- public int DegreeOfBezierCurveCornerSmoothening;
- public VertexWidthFunction WidthFunction;
- public VertexColorFunction ColorFunction;
-
- public MiscShaderData SpecialShader;
- public TrailPointRetrievalFunction TrailPointFunction;
-
- public Vector2 OverridingStickPointStart = Vector2.Zero;
- public Vector2 OverridingStickPointEnd = Vector2.Zero;
-
- public delegate List TrailPointRetrievalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null);
-
- public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, TrailPointRetrievalFunction pointFunction = null, MiscShaderData specialShader = null)
- {
- if (widthFunction is null || colorFunction is null)
- throw new NullReferenceException($"In order to create a primitive trail, a non-null {(widthFunction is null ? "width" : "color")} function must be specified.");
- WidthFunction = widthFunction;
- ColorFunction = colorFunction;
-
- // Default to bezier smoothening if nothing else is inputted.
- if (pointFunction is null)
- pointFunction = SmoothBezierPointRetreivalFunction;
-
- TrailPointFunction = pointFunction;
-
- SpecialShader = specialShader ?? GameShaders.Misc["CalamityMod:StandardPrimitiveShader"];
-
- if (specialShader != null)
- SpecialShader = specialShader;
- }
-
- public static List RigidPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable _ = null)
- {
- List basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList();
- List endPoints = new List();
-
- if (basePoints.Count < 2)
- {
- for (int i = 0; i < basePoints.Count; i++)
- basePoints[i] += generalOffset;
- return basePoints;
- }
-
- // Remap the original positions across a certain length.
- for (int i = 0; i < totalTrailPoints; i++)
- {
- float completionRatio = i / (float)(totalTrailPoints - 1f);
- int currentIndex = (int)(completionRatio * (basePoints.Count - 1));
- Vector2 currentPoint = basePoints[currentIndex];
- Vector2 nextPoint = basePoints[(currentIndex + 1) % basePoints.Count];
- endPoints.Add(Vector2.Lerp(currentPoint, nextPoint, completionRatio * (basePoints.Count - 1) % 0.99999f) + generalOffset);
- }
- endPoints.Add(basePoints.Last() + generalOffset);
- return endPoints;
- }
-
- // NOTE: Beziers can be laggy when a lot of control points are used, since our implementation
- // uses a recursive Lerp that gets more computationally expensive the more original indices.
- // n(n + 1)/2 linear interpolations to be precise, where n is the amount of original indices.
- public List SmoothBezierPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null)
- {
- List controlPoints = new List();
- for (int i = 0; i < originalPositions.Count(); i++)
- {
- // Don't incorporate points that are zeroed out.
- // They are almost certainly a result of incomplete oldPos arrays.
- if (originalPositions.ElementAt(i) == Vector2.Zero)
- continue;
- controlPoints.Add(originalPositions.ElementAt(i) + generalOffset);
- }
-
- bool pointCountCondition = DegreeOfBezierCurveCornerSmoothening <= 0 || controlPoints.Count < DegreeOfBezierCurveCornerSmoothening * 3;
- int effectivePointCount = DegreeOfBezierCurveCornerSmoothening > 0 ? totalTrailPoints * DegreeOfBezierCurveCornerSmoothening : totalTrailPoints;
- BezierCurve bezierCurve = new BezierCurve(controlPoints.Where((_, i) =>
- {
- return DegreeOfBezierCurveCornerSmoothening <= 0 ||
- i % DegreeOfBezierCurveCornerSmoothening == 0 ||
- i == 0 ||
- i == controlPoints.Count - 1 ||
- pointCountCondition;
- }).ToArray());
- return controlPoints.Count <= 1 ? controlPoints : bezierCurve.GetPoints(effectivePointCount);
- }
-
- // Using this method requires oldRot be supplied to the Draw method for the sake of determining how many points need to be made at a given time step.
- // Furthermore, since the point count is dynamic, the point count int parameter has no purpose. It can be supplied simply with zero.
- public static List SmoothCatmullRomPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int _, IEnumerable originalRotations)
- {
- List smoothenedPoints = new List();
- for (int i = 0; i < originalPositions.Count() - 1; i++)
- {
- Vector2 currentPosition = originalPositions.ElementAt(i);
- Vector2 aheadPosition = originalPositions.ElementAt(i + 1);
-
- // Don't incorporate points that are zeroed out.
- // They are almost certainly a result of incomplete oldPos arrays.
- if (currentPosition == Vector2.Zero || aheadPosition == Vector2.Zero)
- continue;
-
- float currentRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i));
- float aheadRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i + 1));
-
- // Determine the amount of extra points to draw based on the rotational offset between the two time steps.
- int pointsToAdd = (int)Math.Round(Math.Abs(MathHelper.WrapAngle(aheadRotation - currentRotation)) * 8f / MathHelper.Pi);
-
- // Add a base point.
- smoothenedPoints.Add(currentPosition + generalOffset);
-
- // If no new points are needed, skip this.
- if (pointsToAdd == 0)
- continue;
-
- float segmentLength = Vector2.Distance(currentPosition, aheadPosition);
- float increment = 1f / (pointsToAdd + 2);
- Vector2 backEnd = currentPosition + currentRotation.ToRotationVector2() * segmentLength;
- Vector2 frontEnd = aheadPosition + aheadRotation.ToRotationVector2() * -segmentLength;
-
- // Create smoothened points based on a Catmull-Rom spline.
- for (float j = increment; j < 1f; j += increment)
- smoothenedPoints.Add(Vector2.CatmullRom(backEnd, currentPosition, aheadPosition, frontEnd, j) + generalOffset);
- }
- return smoothenedPoints;
- }
-
- public VertexPosition2DColor[] GetVerticesFromTrailPoints(List trailPoints)
- {
- VertexPosition2DColor[] vertices = new VertexPosition2DColor[trailPoints.Count * 2 - 2];
- for (int i = 0; i < trailPoints.Count - 1; i++)
- {
- float completionRatio = i / (float)trailPoints.Count;
- float widthAtVertex = WidthFunction(completionRatio);
- Color vertexColor = ColorFunction(completionRatio);
-
- Vector2 currentPosition = trailPoints[i];
- Vector2 positionAhead = trailPoints[i + 1];
- Vector2 directionToAhead = (positionAhead - trailPoints[i]).SafeNormalize(Vector2.Zero);
-
- Vector2 leftCurrentTextureCoord = new Vector2(completionRatio, 0f);
- Vector2 rightCurrentTextureCoord = new Vector2(completionRatio, 1f);
-
- // Point 90 degrees away from the direction towards the next point, and use it to mark the edges of the rectangle.
- // This doesn't use RotatedBy for the sake of performance (there can potentially be a lot of trail points).
- Vector2 sideDirection = new Vector2(-directionToAhead.Y, directionToAhead.X);
-
- Vector2 left = currentPosition - sideDirection * widthAtVertex;
- Vector2 right = currentPosition + sideDirection * widthAtVertex;
- if (i == 0 && OverridingStickPointStart != Vector2.Zero)
- {
- left = OverridingStickPointStart;
- right = OverridingStickPointEnd;
- }
-
- // What this is doing, at its core, is defining a rectangle based on two triangles.
- // These triangles are defined based on the width of the strip at that point.
- // The resulting rectangles combined are what make the trail itself.
- vertices[i * 2] = new VertexPosition2DColor(left, vertexColor, leftCurrentTextureCoord);
- vertices[i * 2 + 1] = new VertexPosition2DColor(right, vertexColor, rightCurrentTextureCoord);
- }
-
- return vertices.ToArray();
- }
-
- public short[] GetIndicesFromTrailPoints(int pointCount)
- {
- // What this is doing is basically representing each point on the vertices list as
- // indices. These indices should come together to create a tiny rectangle that acts
- // as a segment on the trail. This is achieved here by splitting the indices (or rather, points)
- // into 2 triangles, which requires 6 points.
- // The logic here basically determines which indices are connected together.
- int totalIndices = (pointCount - 1) * 6;
- short[] indices = new short[totalIndices];
-
- for (int i = 0; i < pointCount - 2; i++)
- {
- int startingTriangleIndex = i * 6;
- int connectToIndex = i * 2;
- indices[startingTriangleIndex] = (short)connectToIndex;
- indices[startingTriangleIndex + 1] = (short)(connectToIndex + 1);
- indices[startingTriangleIndex + 2] = (short)(connectToIndex + 2);
- indices[startingTriangleIndex + 3] = (short)(connectToIndex + 2);
- indices[startingTriangleIndex + 4] = (short)(connectToIndex + 1);
- indices[startingTriangleIndex + 5] = (short)(connectToIndex + 3);
- }
-
- return indices;
- }
-
- public void Draw(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null)
- {
- List trailPoints = TrailPointFunction(originalPositions, generalOffset, totalTrailPoints, originalRotations);
-
- // A trail with only one point or less has nothing to connect to, and therefore, can't make a trail.
- if (trailPoints.Count < 2)
- return;
-
- // If the trail points have any NaN positions, don't draw anything.
- if (trailPoints.Any(point => point.HasNaNs()))
- return;
-
- // If the trail points are all equal, don't draw anything.
- if (trailPoints.All(point => point == trailPoints[0]))
- return;
-
- CalamityUtils.CalculatePerspectiveMatricies(out Matrix view, out Matrix projection);
- VertexPosition2DColor[] vertices = GetVerticesFromTrailPoints(trailPoints);
-
- short[] triangleIndices = GetIndicesFromTrailPoints(trailPoints.Count);
-
- // Don't draw anything if the indicies/vertices are in any way invalid.
- // If they are, the graphics engine, along with the entire game, will crash.
- if (triangleIndices.Length % 6 != 0 || vertices.Length % 2 != 0)
- return;
-
- Main.instance.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
- Main.instance.GraphicsDevice.RasterizerState.ScissorTestEnable = true;
- Main.instance.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, Main.screenWidth, Main.screenHeight); //offscreen culling
-
- SpecialShader.Shader.Parameters["uWorldViewProjection"].SetValue(view * projection);
- SpecialShader.Apply();
-
- Main.instance.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, triangleIndices, 0, triangleIndices.Length / 3);
- Main.pixelShader.CurrentTechnique.Passes[0].Apply();
- }
- }
-}
diff --git a/Graphics/Primitives/VertexPosition2DColorTexture.cs b/Graphics/Primitives/VertexPosition2DColorTexture.cs
new file mode 100644
index 0000000000..0ac7154e44
--- /dev/null
+++ b/Graphics/Primitives/VertexPosition2DColorTexture.cs
@@ -0,0 +1,46 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace CalamityMod.Graphics.Primitives
+{
+ ///
+ /// A custom vertex type with a position using Vector2 instead of Vector4, as Terraria is only a 2D game.
+ ///
+ /// This represents a vertex that will be rendered by the GPU.
+ public readonly struct VertexPosition2DColorTexture : IVertexType
+ {
+ ///
+ /// The position of the vertex.
+ ///
+ public readonly Vector2 Position;
+
+ ///
+ /// The color of the vertex.
+ ///
+ public readonly Color Color;
+
+ ///
+ /// The texture-coordinate of the vertex.
+ ///
+ public readonly Vector2 TextureCoordinates;
+
+ ///
+ /// The vertex declaration. This declares the layout and size of the data in the vertex shader.
+ ///
+ public VertexDeclaration VertexDeclaration => VertexDeclaration2D;
+
+ public static readonly VertexDeclaration VertexDeclaration2D = new(new VertexElement[]
+ {
+ new(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0),
+ new(8, VertexElementFormat.Color, VertexElementUsage.Color, 0),
+ new(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
+ });
+
+ public VertexPosition2DColorTexture(Vector2 position, Color color, Vector2 textureCoordinates)
+ {
+ Position = position;
+ Color = color;
+ TextureCoordinates = textureCoordinates;
+ }
+ }
+}
diff --git a/NPCs/AcidRain/AcidEel.cs b/NPCs/AcidRain/AcidEel.cs
index 6a0ee223b7..d0112e8897 100644
--- a/NPCs/AcidRain/AcidEel.cs
+++ b/NPCs/AcidRain/AcidEel.cs
@@ -15,6 +15,7 @@ using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Graphics.Shaders;
using System.Linq;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.NPCs.AcidRain
{
@@ -22,8 +23,6 @@ namespace CalamityMod.NPCs.AcidRain
{
public Player Target => Main.player[NPC.target];
- public PrimitiveTrail SegmentDrawer = null;
-
public override void SetStaticDefaults()
{
Main.npcFrameCount[NPC.type] = 6;
@@ -187,9 +186,6 @@ namespace CalamityMod.NPCs.AcidRain
return false;
}
- // Initialize the segment drawer.
- SegmentDrawer ??= new(SegmentWidthFunction, _ => NPC.GetAlpha(Color.White), null, GameShaders.Misc["CalamityMod:PrimitiveTexture"]);
-
Texture2D headTexture = ModContent.Request(Texture).Value;
Texture2D tailTexture = ModContent.Request("CalamityMod/NPCs/AcidRain/AcidEelTail").Value;
Vector2[] segmentPositions = (Vector2[])NPC.oldPos.Clone();
@@ -205,7 +201,7 @@ namespace CalamityMod.NPCs.AcidRain
for (int i = 0; i < segmentPositions.Length; i++)
{
- segmentPositions[i] += NPC.Size * 0.5f - screenPos - NPC.rotation.ToRotationVector2() * Math.Sign(NPC.velocity.X) * 8f;
+ segmentPositions[i] += NPC.Size * 0.5f - NPC.rotation.ToRotationVector2() * Math.Sign(NPC.velocity.X) * 8f;
if (segmentAreaTopLeft.X > segmentPositions[i].X)
segmentAreaTopLeft.X = segmentPositions[i].X;
if (segmentAreaTopLeft.Y > segmentPositions[i].Y)
@@ -234,7 +230,7 @@ namespace CalamityMod.NPCs.AcidRain
Vector2 tailDrawPosition = segmentPositions[^1] - tailRotation.ToRotationVector2() * 4f;
SpriteEffects tailDirection = NPC.velocity.X < 0f ? SpriteEffects.None : SpriteEffects.FlipVertically;
Main.EntitySpriteDraw(tailTexture, tailDrawPosition, tailArea, NPC.GetAlpha(Color.White), tailRotation, tailArea.Size() * new Vector2(0f, 0.5f), NPC.scale, tailDirection, 0);
- SegmentDrawer.Draw(segmentPositions, Vector2.Zero, 36);
+ PrimitiveSet.Prepare(segmentPositions, new(SegmentWidthFunction, _ => NPC.GetAlpha(Color.White), pixelate: false, shader: GameShaders.Misc["CalamityMod:PrimitiveTexture"]), 36);
}
return false;
diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs
index 76814037a9..c70828ca3d 100644
--- a/NPCs/ExoMechs/Apollo/Apollo.cs
+++ b/NPCs/ExoMechs/Apollo/Apollo.cs
@@ -1,4 +1,5 @@
using CalamityMod.Events;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Potions;
using CalamityMod.Items.Weapons.DraedonsArsenal;
using CalamityMod.NPCs.ExoMechs.Ares;
@@ -117,13 +118,6 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
// Intensity of flash effects during the charge combo
public float ChargeComboFlash;
- // Primitive trail drawers for thrusters when charging
- public PrimitiveTrail ChargeFlameTrail = null;
- public PrimitiveTrail ChargeFlameTrailBig = null;
-
- // Primitive trail drawer for the ribbon things
- public PrimitiveTrail RibbonTrail = null;
-
public static string NameToDisplay = "XS-03 Apollo";
public static readonly SoundStyle MissileLaunchSound = new("CalamityMod/Sounds/Custom/ExoMechs/ApolloMissileLaunch") { Volume = 1.3f };
@@ -1498,16 +1492,6 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
- // Declare the trail drawers if they have yet to be defined.
- if (ChargeFlameTrail is null)
- ChargeFlameTrail = new PrimitiveTrail(FlameTrailWidthFunction, FlameTrailColorFunction, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
- if (ChargeFlameTrailBig is null)
- ChargeFlameTrailBig = new PrimitiveTrail(FlameTrailWidthFunctionBig, FlameTrailColorFunctionBig, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
- if (RibbonTrail is null)
- RibbonTrail = new PrimitiveTrail(RibbonTrailWidthFunction, RibbonTrailColorFunction);
-
// Prepare the flame trail shader with its map texture.
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
@@ -1570,7 +1554,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
currentSegmentRotation += segmentRotationOffset;
}
- RibbonTrail.Draw(ribbonDrawPositions, -screenPos, 66);
+ PrimitiveSet.Prepare(ribbonDrawPositions, new(RibbonTrailWidthFunction, RibbonTrailColorFunction), 66);
}
int instanceCount = (int)MathHelper.Lerp(1f, 15f, ChargeComboFlash);
@@ -1635,11 +1619,12 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
for (int i = 0; i < 4; i++)
{
Vector2 drawOffset = (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 8f;
- ChargeFlameTrailBig.Draw(drawPositions, drawOffset - screenPos, 70);
+ PrimitiveSet.Prepare(drawPositions, new(FlameTrailWidthFunctionBig, FlameTrailColorFunctionBig, (_) => drawOffset, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 70);
}
}
else
- ChargeFlameTrail.Draw(drawPositions, -screenPos, 70);
+ PrimitiveSet.Prepare(drawPositions, new(FlameTrailWidthFunction, FlameTrailColorFunction, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 70);
+
}
}
diff --git a/NPCs/ExoMechs/Ares/AresBody.cs b/NPCs/ExoMechs/Ares/AresBody.cs
index 29cce48bd9..9cbccf3f5a 100644
--- a/NPCs/ExoMechs/Ares/AresBody.cs
+++ b/NPCs/ExoMechs/Ares/AresBody.cs
@@ -1,4 +1,5 @@
using CalamityMod.Events;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items;
using CalamityMod.Items.Accessories;
using CalamityMod.Items.Armor.Vanity;
@@ -94,10 +95,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
public ThanatosSmokeParticleSet SmokeDrawer = new ThanatosSmokeParticleSet(-1, 3, 0f, 16f, 1.5f);
- // Drawers for arm segments.
- public PrimitiveTrail LightningDrawer;
- public PrimitiveTrail LightningBackgroundDrawer;
-
// This stores the sound slot of the deathray sound Ares makes, so it may be properly updated in terms of position and looped.
public SlotId DeathraySoundSlot;
@@ -1279,11 +1276,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
public void DrawArm(SpriteBatch spriteBatch, Vector2 handPosition, Vector2 screenOffset, Color glowmaskColor, int direction, bool backArm)
{
- if (LightningDrawer is null)
- LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
- if (LightningBackgroundDrawer is null)
- LightningBackgroundDrawer = new PrimitiveTrail(BackgroundWidthFunction, BackgroundColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
-
SpriteEffects spriteDirection = direction == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
float distanceFromHand = NPC.Distance(handPosition);
float frameTime = Main.GlobalTimeWrappedHourly * 0.9f % 1f;
@@ -1336,13 +1328,13 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
if (NPC.Opacity > 0f && !NPC.IsABestiaryIconDummy)
{
List arm2ElectricArcPoints = AresTeslaOrb.DetermineElectricArcPoints(armSegmentDrawPosition, arm2DrawPosition + arm2Rotation.ToRotationVector2() * -direction * 20f, 250290787);
- LightningBackgroundDrawer.Draw(arm2ElectricArcPoints, -Main.screenPosition, 90);
- LightningDrawer.Draw(arm2ElectricArcPoints, -Main.screenPosition, 90);
+ PrimitiveSet.Prepare(arm2ElectricArcPoints, new(BackgroundWidthFunction, BackgroundColorFunction, smoothen: false), 90);
+ PrimitiveSet.Prepare(arm2ElectricArcPoints, new(WidthFunction, ColorFunction, smoothen: false), 90);
// Draw electricity between the final arm and the hand.
List handElectricArcPoints = AresTeslaOrb.DetermineElectricArcPoints(arm2DrawPosition - arm2Rotation.ToRotationVector2() * direction * 100f, handPosition, 27182);
- LightningBackgroundDrawer.Draw(handElectricArcPoints, -Main.screenPosition, 90);
- LightningDrawer.Draw(handElectricArcPoints, -Main.screenPosition, 90);
+ PrimitiveSet.Prepare(handElectricArcPoints, new(BackgroundWidthFunction, BackgroundColorFunction, smoothen: false), 90);
+ PrimitiveSet.Prepare(handElectricArcPoints, new(WidthFunction, ColorFunction, smoothen: false), 90);
}
shoulderDrawPosition += Vector2.UnitY * NPC.gfxOffY - screenOffset;
@@ -1398,13 +1390,13 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
if (NPC.Opacity > 0f && !NPC.IsABestiaryIconDummy)
{
List arm2ElectricArcPoints = AresTeslaOrb.DetermineElectricArcPoints(arm1DrawPosition - arm2Rotation.ToRotationVector2() * direction * 10f, arm1DrawPosition + arm2Rotation.ToRotationVector2() * direction * 20f, 31416);
- LightningBackgroundDrawer.Draw(arm2ElectricArcPoints, -Main.screenPosition, 90);
- LightningDrawer.Draw(arm2ElectricArcPoints, -Main.screenPosition, 90);
+ PrimitiveSet.Prepare(arm2ElectricArcPoints, new(BackgroundWidthFunction, BackgroundColorFunction, smoothen: false), 90);
+ PrimitiveSet.Prepare(arm2ElectricArcPoints, new(WidthFunction, ColorFunction, smoothen: false), 90);
// Draw electricity between the final arm and the hand.
List handElectricArcPoints = AresTeslaOrb.DetermineElectricArcPoints(arm2DrawPosition - arm2Rotation.ToRotationVector2() * direction * 20f, handPosition, 27182);
- LightningBackgroundDrawer.Draw(handElectricArcPoints, -Main.screenPosition, 90);
- LightningDrawer.Draw(handElectricArcPoints, -Main.screenPosition, 90);
+ PrimitiveSet.Prepare(handElectricArcPoints, new(BackgroundWidthFunction, BackgroundColorFunction, smoothen: false), 90);
+ PrimitiveSet.Prepare(handElectricArcPoints, new(WidthFunction, ColorFunction, smoothen: false), 90);
}
shoulderDrawPosition += Vector2.UnitY * NPC.gfxOffY - screenOffset;
diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs
index e54e13a4a1..39be2d8378 100644
--- a/NPCs/ExoMechs/Artemis/Artemis.cs
+++ b/NPCs/ExoMechs/Artemis/Artemis.cs
@@ -1,4 +1,5 @@
using CalamityMod.Events;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Potions;
using CalamityMod.NPCs.ExoMechs.Ares;
using CalamityMod.NPCs.ExoMechs.Thanatos;
@@ -148,13 +149,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
// Intensity of flash effects during the charge combo
public float ChargeFlash;
- // Primitive trail drawers for thrusters when charging
- public PrimitiveTrail ChargeFlameTrail = null;
- public PrimitiveTrail ChargeFlameTrailBig = null;
-
- // Primitive trail drawer for the ribbon things
- public PrimitiveTrail RibbonTrail = null;
-
//This stores the sound slot of the ML laser sound it makes, so it may be properly updated in terms of position.
private SlotId DeathraySoundSlot;
@@ -1392,16 +1386,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
- // Declare the trail drawers if they have yet to be defined.
- if (ChargeFlameTrail is null)
- ChargeFlameTrail = new PrimitiveTrail(FlameTrailWidthFunction, FlameTrailColorFunction, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
- if (ChargeFlameTrailBig is null)
- ChargeFlameTrailBig = new PrimitiveTrail(FlameTrailWidthFunctionBig, FlameTrailColorFunctionBig, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
- if (RibbonTrail is null)
- RibbonTrail = new PrimitiveTrail(RibbonTrailWidthFunction, RibbonTrailColorFunction);
-
// Prepare the flame trail shader with its map texture.
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
@@ -1464,7 +1448,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
currentSegmentRotation += segmentRotationOffset;
}
- RibbonTrail.Draw(ribbonDrawPositions, -screenPos, 66);
+ PrimitiveSet.Prepare(ribbonDrawPositions, new(RibbonTrailWidthFunction, RibbonTrailColorFunction), 66);
}
int instanceCount = (int)MathHelper.Lerp(1f, 15f, ChargeFlash);
@@ -1529,11 +1513,11 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
for (int i = 0; i < 4; i++)
{
Vector2 drawOffset = (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 8f;
- ChargeFlameTrailBig.Draw(drawPositions, drawOffset - screenPos, 70);
+ PrimitiveSet.Prepare(drawPositions, new(FlameTrailWidthFunctionBig, FlameTrailColorFunctionBig, (_) => drawOffset, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 70);
}
}
else
- ChargeFlameTrail.Draw(drawPositions, -screenPos, 70);
+ PrimitiveSet.Prepare(drawPositions, new(FlameTrailWidthFunction, FlameTrailColorFunction, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 70);
}
}
diff --git a/NPCs/SupremeCalamitas/BrimstoneHeart.cs b/NPCs/SupremeCalamitas/BrimstoneHeart.cs
index 397b1b1bf0..23144ecd84 100644
--- a/NPCs/SupremeCalamitas/BrimstoneHeart.cs
+++ b/NPCs/SupremeCalamitas/BrimstoneHeart.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Projectiles.Rogue;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Projectiles.Rogue;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -13,7 +14,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas
{
public class BrimstoneHeart : ModNPC
{
- public PrimitiveTrail ChainDrawer = null;
public int ChainHeartIndex => (int)NPC.ai[0];
public List ChainEndpoints = new();
public override void SetStaticDefaults()
@@ -113,8 +113,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas
public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
- if (ChainDrawer is null)
- ChainDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction);
if (NPC.IsABestiaryIconDummy)
return true;
@@ -125,7 +123,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas
NPC.Center,
ChainEndpoints[i] + NPC.DirectionTo(ChainEndpoints[i]) * 25f
};
- ChainDrawer.Draw(points, -screenPos, 40);
+ PrimitiveSet.Prepare(points, new(PrimitiveWidthFunction, PrimitiveColorFunction), 40);
}
return true;
diff --git a/Projectiles/Boss/ApolloChargeTelegraph.cs b/Projectiles/Boss/ApolloChargeTelegraph.cs
index 508eafd00c..a5bb6afc74 100644
--- a/Projectiles/Boss/ApolloChargeTelegraph.cs
+++ b/Projectiles/Boss/ApolloChargeTelegraph.cs
@@ -1,4 +1,5 @@
using CalamityMod.Events;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using System.IO;
@@ -17,7 +18,6 @@ namespace CalamityMod.Projectiles.Boss
public NPC ThingToAttachTo => Main.npc.IndexInRange((int)Projectile.ai[1]) ? Main.npc[(int)Projectile.ai[1]] : null;
- public PrimitiveTrail TelegraphDrawer = null;
public const float TelegraphFadeTime = 15f;
public const float TelegraphWidth = 1132.07774f; // a squared plus b squared equals c squared, dumbass
@@ -113,9 +113,6 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(ref Color lightColor)
{
- if (TelegraphDrawer is null)
- TelegraphDrawer = new PrimitiveTrail(TelegraphPrimitiveWidth, TelegraphPrimitiveColor, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:Flame"]);
-
GameShaders.Misc["CalamityMod:Flame"].UseImage1("Images/Misc/Perlin");
GameShaders.Misc["CalamityMod:Flame"].UseSaturation(0.41f);
@@ -131,7 +128,7 @@ namespace CalamityMod.Projectiles.Boss
// It is not used anywhere else.
Projectile.ai[0] = i;
- TelegraphDrawer.Draw(positions, Projectile.Size * 0.5f - Main.screenPosition, 55);
+ PrimitiveSet.Prepare(positions, new(TelegraphPrimitiveWidth, TelegraphPrimitiveColor, (_) => Projectile.Size * 0.5f, smoothen: false, shader: GameShaders.Misc["CalamityMod:Flame"]), 55);
}
return false;
}
diff --git a/Projectiles/Boss/AresTeslaOrb.cs b/Projectiles/Boss/AresTeslaOrb.cs
index 499fcd342c..99d55c8eba 100644
--- a/Projectiles/Boss/AresTeslaOrb.cs
+++ b/Projectiles/Boss/AresTeslaOrb.cs
@@ -1,4 +1,5 @@
using CalamityMod.Events;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.NPCs;
using CalamityMod.NPCs.ExoMechs.Ares;
using CalamityMod.World;
@@ -16,8 +17,6 @@ namespace CalamityMod.Projectiles.Boss
{
public new string LocalizationCategory => "Projectiles.Boss";
public ref float Identity => ref Projectile.ai[0];
- public PrimitiveTrail LightningDrawer;
- public PrimitiveTrail LightningBackgroundDrawer;
private const int timeLeft = 480;
public override void SetStaticDefaults()
@@ -226,17 +225,12 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(ref Color lightColor)
{
- if (LightningDrawer is null)
- LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
- if (LightningBackgroundDrawer is null)
- LightningBackgroundDrawer = new PrimitiveTrail(BackgroundWidthFunction, BackgroundColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
-
Projectile orbToAttachTo = GetOrbToAttachTo();
if (orbToAttachTo != null)
{
List arcPoints = DetermineElectricArcPoints(Projectile.Center, orbToAttachTo.Center, 117);
- LightningBackgroundDrawer.Draw(arcPoints, -Main.screenPosition, 90);
- LightningDrawer.Draw(arcPoints, -Main.screenPosition, 90);
+ PrimitiveSet.Prepare(arcPoints, new(BackgroundWidthFunction, BackgroundColorFunction, smoothen: false), 90);
+ PrimitiveSet.Prepare(arcPoints, new(WidthFunction, ColorFunction, smoothen: false), 90);
}
lightColor.R = (byte)(255 * Projectile.Opacity);
diff --git a/Projectiles/Boss/ArtemisChargeTelegraph.cs b/Projectiles/Boss/ArtemisChargeTelegraph.cs
index 356a3035a0..fd7e3467be 100644
--- a/Projectiles/Boss/ArtemisChargeTelegraph.cs
+++ b/Projectiles/Boss/ArtemisChargeTelegraph.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework;
+using CalamityMod.Graphics.Primitives;
+using Microsoft.Xna.Framework;
using System.IO;
using Terraria;
using Terraria.Graphics.Shaders;
@@ -15,7 +16,6 @@ namespace CalamityMod.Projectiles.Boss
public NPC ThingToAttachTo => Main.npc.IndexInRange((int)Projectile.ai[1]) ? Main.npc[(int)Projectile.ai[1]] : null;
public Vector2 OldVelocity;
- public PrimitiveTrail TelegraphDrawer = null;
public const float TelegraphWidth = 2000f;
public override void SetStaticDefaults()
@@ -89,9 +89,6 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(ref Color lightColor)
{
- if (TelegraphDrawer is null)
- TelegraphDrawer = new PrimitiveTrail(TelegraphPrimitiveWidth, TelegraphPrimitiveColor, specialShader: GameShaders.Misc["CalamityMod:Flame"]);
-
GameShaders.Misc["CalamityMod:Flame"].UseImage1("Images/Misc/Perlin");
GameShaders.Misc["CalamityMod:Flame"].UseSaturation(0.28f);
Vector2[] drawPositions = new Vector2[]
@@ -99,8 +96,7 @@ namespace CalamityMod.Projectiles.Boss
Projectile.Center,
Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.UnitY) * TelegraphWidth
};
-
- TelegraphDrawer.Draw(drawPositions, Projectile.Size * 0.5f - Main.screenPosition, 87);
+ PrimitiveSet.Prepare(drawPositions, new(TelegraphPrimitiveWidth, TelegraphPrimitiveColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:Flame"]), 87);
return false;
}
}
diff --git a/Projectiles/Boss/ArtemisSpinLaserbeam.cs b/Projectiles/Boss/ArtemisSpinLaserbeam.cs
index 9833e6233a..6a55ac5076 100644
--- a/Projectiles/Boss/ArtemisSpinLaserbeam.cs
+++ b/Projectiles/Boss/ArtemisSpinLaserbeam.cs
@@ -1,4 +1,5 @@
using CalamityMod.Buffs.DamageOverTime;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.NPCs.ExoMechs.Artemis;
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
@@ -17,11 +18,6 @@ namespace CalamityMod.Projectiles.Boss
public class ArtemisSpinLaserbeam : BaseLaserbeamProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Boss";
- public PrimitiveTrail LaserDrawer
- {
- get;
- set;
- } = null;
public int OwnerIndex
{
@@ -136,7 +132,6 @@ namespace CalamityMod.Projectiles.Boss
// This should never happen, but just in case.
if (Projectile.velocity == Vector2.Zero)
return false;
- LaserDrawer ??= new(LaserWidthFunction, LaserColorFunction, null, GameShaders.Misc["CalamityMod:ArtemisLaser"]);
Vector2 laserEnd = Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.UnitY) * LaserLength;
Vector2[] baseDrawPoints = new Vector2[8];
@@ -147,8 +142,7 @@ namespace CalamityMod.Projectiles.Boss
GameShaders.Misc["CalamityMod:ArtemisLaser"].UseColor(Color.Cyan);
GameShaders.Misc["CalamityMod:ArtemisLaser"].UseImage1("Images/Extra_189");
GameShaders.Misc["CalamityMod:ArtemisLaser"].UseImage2("Images/Misc/Perlin");
-
- LaserDrawer.Draw(baseDrawPoints, -Main.screenPosition, 64);
+ PrimitiveSet.Prepare(baseDrawPoints, new(LaserWidthFunction, LaserColorFunction, shader: GameShaders.Misc["CalamityMod:ArtemisLaser"]), 64);
return false;
}
diff --git a/Projectiles/Boss/CirrusPhotonRipperPrismTooth.cs b/Projectiles/Boss/CirrusPhotonRipperPrismTooth.cs
index 1c5aa96e60..49bfa8f1d4 100644
--- a/Projectiles/Boss/CirrusPhotonRipperPrismTooth.cs
+++ b/Projectiles/Boss/CirrusPhotonRipperPrismTooth.cs
@@ -1,4 +1,5 @@
using CalamityMod.Buffs.DamageOverTime;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.NPCs.SupremeCalamitas;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -17,7 +18,6 @@ namespace CalamityMod.Projectiles.Boss
public override string Texture => "CalamityMod/Projectiles/Melee/PrismTooth";
- internal PrimitiveTrail TrailDrawer;
public const int Lifetime = 80;
public NPC Cirrus => Main.npc.IndexInRange((int)Projectile.ai[2]) ? Main.npc[(int)Projectile.ai[2]] : null;
@@ -138,9 +138,6 @@ namespace CalamityMod.Projectiles.Boss
if (Time <= 5f)
return true;
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PrismaticStreak"]);
-
// Variable adjustment vector used to prevent the trail for starting somewhat that isn't behind
// the crystal. This may appear in small amounts, with offsets of a few pixels, but at the speed
// these crystals go, it's probably not something to worry too much about.
@@ -158,7 +155,7 @@ namespace CalamityMod.Projectiles.Boss
Main.spriteBatch.EnterShaderRegion();
GameShaders.Misc["CalamityMod:PrismaticStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f + generalOffset - Main.screenPosition, 65);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + generalOffset, shader: GameShaders.Misc["CalamityMod:PrismaticStreak"]), 65);
Main.spriteBatch.ExitShaderRegion();
return true;
}
diff --git a/Projectiles/Boss/DraedonSummonLaser.cs b/Projectiles/Boss/DraedonSummonLaser.cs
index 530ceaae74..a14e209bfc 100644
--- a/Projectiles/Boss/DraedonSummonLaser.cs
+++ b/Projectiles/Boss/DraedonSummonLaser.cs
@@ -7,6 +7,7 @@ using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
using CalamityMod.Items.Weapons.DraedonsArsenal;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Boss
{
@@ -17,7 +18,6 @@ namespace CalamityMod.Projectiles.Boss
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
- public PrimitiveTrail RayDrawer = null;
private const int Lifetime = CalamityWorld.DraedonSummonCountdownMax - 60;
public override void SetStaticDefaults()
@@ -80,17 +80,14 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(ref Color lightColor)
{
- if (RayDrawer is null)
- RayDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:Flame"]);
-
GameShaders.Misc["CalamityMod:Flame"].UseImage1("Images/Misc/Perlin");
Vector2[] basePoints = new Vector2[8];
for (int i = 0; i < basePoints.Length; i++)
basePoints[i] = Projectile.Center - Vector2.UnitY * i / basePoints.Length * LaserLength;
- Vector2 overallOffset = Projectile.Size * 0.5f - Main.screenPosition;
- RayDrawer.Draw(basePoints, overallOffset, 92);
+ Vector2 overallOffset = Projectile.Size * 0.5f;
+ PrimitiveSet.Prepare(basePoints, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => overallOffset, shader: GameShaders.Misc["CalamityMod:Flame"]), 92);
return false;
}
diff --git a/Projectiles/Boss/DyingSun.cs b/Projectiles/Boss/DyingSun.cs
index 6b84165ff6..eaa8d6dbed 100644
--- a/Projectiles/Boss/DyingSun.cs
+++ b/Projectiles/Boss/DyingSun.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Terraria;
@@ -12,7 +13,6 @@ namespace CalamityMod.Projectiles.Boss
public class DyingSun : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Boss";
- public PrimitiveTrail FireDrawer;
public ref float Time => ref Projectile.ai[0];
public ref float Radius => ref Projectile.ai[1];
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
@@ -51,9 +51,6 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(ref Color lightColor)
{
- if (FireDrawer is null)
- FireDrawer = new PrimitiveTrail(SunWidthFunction, SunColorFunction, null, GameShaders.Misc["CalamityMod:Flame"]);
-
GameShaders.Misc["CalamityMod:Flame"].UseSaturation(0.45f);
GameShaders.Misc["CalamityMod:Flame"].UseImage1("Images/Misc/Perlin");
@@ -72,8 +69,7 @@ namespace CalamityMod.Projectiles.Boss
rotationPoints.Add(adjustedAngle);
drawPoints.Add(Vector2.Lerp(Projectile.Center - offsetDirection * Radius / 2f, Projectile.Center + offsetDirection * Radius / 2f, i / 16f));
}
-
- FireDrawer.Draw(drawPoints, -Main.screenPosition, 24);
+ PrimitiveSet.Prepare(drawPoints, new(SunWidthFunction, SunColorFunction, shader: GameShaders.Misc["CalamityMod:Flame"]), 24);
}
return false;
}
diff --git a/Projectiles/Boss/InfernadoRevenge.cs b/Projectiles/Boss/InfernadoRevenge.cs
index 888954ad7f..aa22ca54c2 100644
--- a/Projectiles/Boss/InfernadoRevenge.cs
+++ b/Projectiles/Boss/InfernadoRevenge.cs
@@ -1,5 +1,6 @@
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.CalPlayer;
+using CalamityMod.Graphics.Primitives;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
@@ -13,7 +14,6 @@ namespace CalamityMod.Projectiles.Boss
public class InfernadoRevenge : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Boss";
- internal PrimitiveTrail TornadoDrawer;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public const int TornadoHeight = 8800;
public override void SetStaticDefaults()
@@ -72,9 +72,6 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(ref Color lightColor)
{
- if (TornadoDrawer is null)
- TornadoDrawer = new PrimitiveTrail(_ => Projectile.width * 0.5f + 16f, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:Bordernado"]);
-
GameShaders.Misc["CalamityMod:Bordernado"].UseSaturation(-0.2f);
GameShaders.Misc["CalamityMod:Bordernado"].SetShaderTexture(ModContent.Request("Terraria/Images/Misc/Perlin"));
Vector2[] drawPoints = new Vector2[5];
@@ -87,7 +84,7 @@ namespace CalamityMod.Projectiles.Boss
drawPoints[i] = Vector2.Lerp(top, bottom, i / (float)(drawPoints.Length - 1));
drawPoints[drawPoints.Length - 1] = bottom;
- TornadoDrawer.Draw(drawPoints, -Main.screenPosition, 85);
+ PrimitiveSet.Prepare(drawPoints, new((_) => Projectile.width * 0.5f + 16f, ColorFunction, shader: GameShaders.Misc["CalamityMod:Bordernado"]), 85);
Texture2D vortexTexture = ModContent.Request("CalamityMod/Projectiles/Boss/OldDukeVortex").Value;
for (int i = 0; i < 110; i++)
diff --git a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs
index eb565f44ce..908b0ed959 100644
--- a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs
+++ b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs
@@ -1,4 +1,5 @@
using CalamityMod.Dusts;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items;
using CalamityMod.Items.Weapons.DraedonsArsenal;
using CalamityMod.Items.Weapons.Ranged;
@@ -271,7 +272,6 @@ namespace CalamityMod.Projectiles.DraedonsArsenal
}
}
- internal PrimitiveTrail TrailDrawer;
internal Color ColorFunction(float completionRatio)
{
float averageRotation = Projectile.oldRot.Take(20).Average(angle => MathHelper.WrapAngle(angle) + MathHelper.Pi);
@@ -307,9 +307,6 @@ namespace CalamityMod.Projectiles.DraedonsArsenal
Rectangle frame = IsSmall ? bladeTexture.Frame(1, 3, 0, BladeFrameY) : bladeTexture.Frame(3, 7, BladeFrameX, BladeFrameY);
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]);
-
GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SwordSlashTexture"));
Player player = Main.player[Projectile.owner];
@@ -327,8 +324,8 @@ namespace CalamityMod.Projectiles.DraedonsArsenal
float angularTurn = i * swingAngularDirection * -0.09f;
drawPoints[i] = Projectile.position + perpendicularDirection.RotatedBy(angularTurn) * offsetFactor;
}
+ PrimitiveSet.Prepare(drawPoints, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + bladeOffset, shader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]), 50);
- TrailDrawer.Draw(drawPoints, Projectile.Size * 0.5f + bladeOffset - Main.screenPosition, 50);
Main.EntitySpriteDraw(bladeTexture, Projectile.Center + bladeOffset - Main.screenPosition, frame, Color.White, Projectile.rotation + MathHelper.PiOver2, origin, Projectile.scale, SpriteEffects.None, 0);
Main.EntitySpriteDraw(hiltTexture, Projectile.Center - Main.screenPosition, null, lightColor, Projectile.rotation + MathHelper.PiOver2, hiltTexture.Size() * 0.5f, Projectile.scale, SpriteEffects.None, 0);
diff --git a/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs b/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs
index fbdbb0d135..9659a70e50 100644
--- a/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs
+++ b/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.DraedonsArsenal;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
@@ -184,10 +185,8 @@ namespace CalamityMod.Projectiles.DraedonsArsenal
Vector2 origin = frame.Size() * 0.5f;
Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, SpriteEffects.None, 0);
- PrimitiveTrail trail = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
- trail.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 92);
-
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 92);
return false;
}
}
diff --git a/Projectiles/Enemy/GammRayBurst.cs b/Projectiles/Enemy/GammRayBurst.cs
index cbc1e035da..a4e3fe6007 100644
--- a/Projectiles/Enemy/GammRayBurst.cs
+++ b/Projectiles/Enemy/GammRayBurst.cs
@@ -1,4 +1,5 @@
using CalamityMod.Buffs.DamageOverTime;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.NPCs.AcidRain;
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
@@ -17,11 +18,6 @@ namespace CalamityMod.Projectiles.Enemy
public class GammaRayBurst : BaseLaserbeamProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Enemy";
- public PrimitiveTrail LaserDrawer
- {
- get;
- set;
- } = null;
public int OwnerIndex
{
@@ -112,7 +108,6 @@ namespace CalamityMod.Projectiles.Enemy
// This should never happen, but just in case.
if (Projectile.velocity == Vector2.Zero)
return false;
- LaserDrawer ??= new(LaserWidthFunction, LaserColorFunction, null, GameShaders.Misc["CalamityMod:ArtemisLaser"]);
Vector2 laserEnd = Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.UnitY) * LaserLength;
Vector2[] baseDrawPoints = new Vector2[8];
@@ -124,7 +119,7 @@ namespace CalamityMod.Projectiles.Enemy
GameShaders.Misc["CalamityMod:ArtemisLaser"].UseImage1("Images/Extra_189");
GameShaders.Misc["CalamityMod:ArtemisLaser"].UseImage2("Images/Misc/Perlin");
- LaserDrawer.Draw(baseDrawPoints, -Main.screenPosition, 64);
+ PrimitiveSet.Prepare(baseDrawPoints, new(LaserWidthFunction, LaserColorFunction, shader: GameShaders.Misc["CalamityMod:ArtemisLaser"]), 64);
return false;
}
diff --git a/Projectiles/Magic/ApotheosisEnergy.cs b/Projectiles/Magic/ApotheosisEnergy.cs
index eead2d2676..3b07f3cd4f 100644
--- a/Projectiles/Magic/ApotheosisEnergy.cs
+++ b/Projectiles/Magic/ApotheosisEnergy.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework;
+using CalamityMod.Graphics.Primitives;
+using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
@@ -8,7 +9,6 @@ namespace CalamityMod.Projectiles.Magic
public class ApotheosisEnergy : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
- internal PrimitiveTrail TrailDrawer = null;
public override void SetStaticDefaults()
{
@@ -88,10 +88,7 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction);
-
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 85);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f), 85);
return false;
}
}
diff --git a/Projectiles/Magic/ArtAttackStar.cs b/Projectiles/Magic/ArtAttackStar.cs
index 763c943aed..5df5a7651c 100644
--- a/Projectiles/Magic/ArtAttackStar.cs
+++ b/Projectiles/Magic/ArtAttackStar.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Weapons.Magic;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Weapons.Magic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -15,7 +16,6 @@ namespace CalamityMod.Projectiles.Magic
public class ArtAttackStar : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
- public PrimitiveTrail TrailDrawer = null;
public Player Owner => Main.player[Projectile.owner];
public ref float Time => ref Projectile.ai[0];
public const int StarShapeCreationDelay = 12;
@@ -217,9 +217,6 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(TrailWidth, TrailColor, null, GameShaders.Misc["CalamityMod:ArtAttack"]);
-
Texture2D texture = ModContent.Request(Texture).Value;
Vector2 drawPosition = Projectile.Center - Main.screenPosition + Vector2.UnitY * Projectile.gfxOffY;
Vector2 origin = texture.Size() * 0.5f;
@@ -228,7 +225,7 @@ namespace CalamityMod.Projectiles.Magic
GameShaders.Misc["CalamityMod:ArtAttack"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
GameShaders.Misc["CalamityMod:ArtAttack"].Apply();
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 180);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(TrailWidth, TrailColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ArtAttack"]), 180);
Main.spriteBatch.ExitShaderRegion();
Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(Color.White), Projectile.rotation, origin, Projectile.scale, 0, 0);
diff --git a/Projectiles/Magic/EternityHex.cs b/Projectiles/Magic/EternityHex.cs
index cbc6cf6de6..687f365e50 100644
--- a/Projectiles/Magic/EternityHex.cs
+++ b/Projectiles/Magic/EternityHex.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Weapons.Magic;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Weapons.Magic;
using CalamityMod.Projectiles.Typeless;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -16,7 +17,6 @@ namespace CalamityMod.Projectiles.Magic
public new string LocalizationCategory => "Projectiles.Magic";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
- internal PrimitiveTrail LemniscateDrawer = null;
public int TargetNPCIndex
{
get => (int)Projectile.ai[0];
@@ -228,11 +228,8 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(ref Color lightColor)
{
- if (LemniscateDrawer is null)
- LemniscateDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, null, GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/EternityStreak"));
- LemniscateDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 84);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 84);
return false;
}
}
diff --git a/Projectiles/Magic/ExoVortex.cs b/Projectiles/Magic/ExoVortex.cs
index e6f3720f81..6c6d692ac4 100644
--- a/Projectiles/Magic/ExoVortex.cs
+++ b/Projectiles/Magic/ExoVortex.cs
@@ -7,13 +7,13 @@ using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Magic
{
public class ExoVortex : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
- public PrimitiveTrail EnergyTrail = null;
public float Hue => Projectile.ai[0];
@@ -105,6 +105,8 @@ namespace CalamityMod.Projectiles.Magic
return c * Utils.GetLerpValue(0.04f, 0.2f, completionRatio, true) * velocityOpacityFadeout;
}
+ public Vector2 PrimitiveOffsetFunction(float completionRatio) => Projectile.Size * 0.5f + Projectile.velocity.SafeNormalize(Vector2.Zero) * Projectile.scale * 2f;
+
public override bool PreDraw(ref Color lightColor)
{
Main.spriteBatch.EnterShaderRegion(BlendState.Additive);
@@ -114,10 +116,8 @@ namespace CalamityMod.Projectiles.Magic
Main.spriteBatch.EnterShaderRegion();
// Draw the streak trail.
- EnergyTrail ??= new(PrimitiveWidthFunction, PrimitiveTrailColor, null, GameShaders.Misc["CalamityMod:SideStreakTrail"]);
-
GameShaders.Misc["CalamityMod:SideStreakTrail"].UseImage1("Images/Misc/Perlin");
- EnergyTrail.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + Projectile.velocity.SafeNormalize(Vector2.Zero) * Projectile.scale * 2f, 51);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveTrailColor, PrimitiveOffsetFunction, shader: GameShaders.Misc["CalamityMod:SideStreakTrail"]), 51);
Main.spriteBatch.EnterShaderRegion(BlendState.Additive);
GameShaders.Misc["CalamityMod:ExoVortex"].Apply();
diff --git a/Projectiles/Magic/ExoVortex2.cs b/Projectiles/Magic/ExoVortex2.cs
index 4702883dab..709bc151f2 100644
--- a/Projectiles/Magic/ExoVortex2.cs
+++ b/Projectiles/Magic/ExoVortex2.cs
@@ -7,13 +7,13 @@ using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Magic
{
public class ExoVortex2 : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
- public PrimitiveTrail EnergyTrail = null;
public float Hue => Projectile.ai[0];
@@ -109,6 +109,8 @@ namespace CalamityMod.Projectiles.Magic
return c * Utils.GetLerpValue(0.04f, 0.2f, completionRatio, true) * velocityOpacityFadeout;
}
+ public Vector2 PrimitiveOffsetFunction(float completionRatio) => Projectile.Size * 0.5f + Projectile.velocity.SafeNormalize(Vector2.Zero) * Projectile.scale * 2f;
+
public override bool PreDraw(ref Color lightColor)
{
Main.spriteBatch.EnterShaderRegion(BlendState.Additive);
@@ -118,10 +120,8 @@ namespace CalamityMod.Projectiles.Magic
Main.spriteBatch.EnterShaderRegion();
// Draw the streak trail.
- EnergyTrail ??= new(PrimitiveWidthFunction, PrimitiveTrailColor, null, GameShaders.Misc["CalamityMod:SideStreakTrail"]);
-
GameShaders.Misc["CalamityMod:SideStreakTrail"].UseImage1("Images/Misc/Perlin");
- EnergyTrail.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + Projectile.velocity.SafeNormalize(Vector2.Zero) * Projectile.scale * 2f, 51);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveTrailColor, PrimitiveOffsetFunction, shader: GameShaders.Misc["CalamityMod:SideStreakTrail"]), 51);
Main.spriteBatch.EnterShaderRegion(BlendState.Additive);
GameShaders.Misc["CalamityMod:ExoVortex"].Apply();
diff --git a/Projectiles/Magic/FabBolt.cs b/Projectiles/Magic/FabBolt.cs
index 7dde3ba8c4..aaa9f19de2 100644
--- a/Projectiles/Magic/FabBolt.cs
+++ b/Projectiles/Magic/FabBolt.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework;
+using CalamityMod.Graphics.Primitives;
+using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
@@ -10,7 +11,6 @@ namespace CalamityMod.Projectiles.Magic
public class FabBolt : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
- internal PrimitiveTrail TrailDrawer;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public bool FadingOut
@@ -71,11 +71,8 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 80, Projectile.oldRot);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, smoothen: false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 80);
return false;
}
diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs
index c9823efc97..a8549dc517 100644
--- a/Projectiles/Magic/FabRay.cs
+++ b/Projectiles/Magic/FabRay.cs
@@ -1,4 +1,5 @@
using CalamityMod.Buffs.Alcohol;
+using CalamityMod.Graphics.Primitives;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -12,7 +13,7 @@ namespace CalamityMod.Projectiles.Magic
public class FabRay : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
- internal PrimitiveTrail TrailDrawer;
+
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetStaticDefaults()
@@ -100,13 +101,12 @@ namespace CalamityMod.Projectiles.Magic
return MathHelper.Lerp(0f, 32f * Projectile.Opacity, expansionCompletion);
}
+ internal Vector2 OffsetFunction(float completionRatio) => Projectile.Size * 0.5f;
+
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 32);
+ PrimitiveSet.Prepare(Projectile.oldPos, new PrimitiveSettings(WidthFunction, ColorFunction, OffsetFunction, pixelate: false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 32);
return false;
}
diff --git a/Projectiles/Magic/RainbowRocket.cs b/Projectiles/Magic/RainbowRocket.cs
index 3fd639b4f8..5f877720b9 100644
--- a/Projectiles/Magic/RainbowRocket.cs
+++ b/Projectiles/Magic/RainbowRocket.cs
@@ -6,6 +6,7 @@ using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Magic
{
@@ -24,7 +25,6 @@ namespace CalamityMod.Projectiles.Magic
Count = 7
}
- internal PrimitiveTrail TrailDrawer = null;
public ref float Time => ref Projectile.ai[0];
public PartyCannonExplosionType RocketType
{
@@ -135,11 +135,8 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction);
-
Projectile.oldPos[0] = Projectile.position + Projectile.velocity.SafeNormalize(Vector2.Zero) * 50f;
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + Projectile.velocity, 80);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + Projectile.velocity), 80);
Texture2D rocketTexture = ModContent.Request(Texture).Value;
Main.EntitySpriteDraw(rocketTexture,
diff --git a/Projectiles/Magic/RancorLaserbeam.cs b/Projectiles/Magic/RancorLaserbeam.cs
index 86ab25cc1b..8730747df1 100644
--- a/Projectiles/Magic/RancorLaserbeam.cs
+++ b/Projectiles/Magic/RancorLaserbeam.cs
@@ -1,5 +1,6 @@
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Graphics.Metaballs;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using System;
@@ -15,7 +16,6 @@ namespace CalamityMod.Projectiles.Magic
public class RancorLaserbeam : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
- public PrimitiveTrail RayDrawer = null;
public Player Owner => Main.player[Projectile.owner];
public Projectile MagicCircle
{
@@ -162,16 +162,13 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(ref Color lightColor)
{
- RayDrawer ??= new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:Flame"]);
-
GameShaders.Misc["CalamityMod:Flame"].UseImage1("Images/Misc/Perlin");
Vector2[] basePoints = new Vector2[24];
for (int i = 0; i < basePoints.Length; i++)
basePoints[i] = Projectile.Center + Projectile.velocity * i / (basePoints.Length - 1f) * LaserLength;
- Vector2 overallOffset = -Main.screenPosition;
- RayDrawer.Draw(basePoints, overallOffset, 92);
+ PrimitiveSet.Prepare(basePoints, new(PrimitiveWidthFunction, PrimitiveColorFunction, shader: GameShaders.Misc["CalamityMod:Flame"]), 92);
return false;
}
diff --git a/Projectiles/Magic/WulfrumBolt.cs b/Projectiles/Magic/WulfrumBolt.cs
index 370e1c8199..348177d500 100644
--- a/Projectiles/Magic/WulfrumBolt.cs
+++ b/Projectiles/Magic/WulfrumBolt.cs
@@ -9,6 +9,7 @@ using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using CalamityMod.Particles;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Magic
{
@@ -38,7 +39,6 @@ namespace CalamityMod.Projectiles.Magic
public static float HomingRange = 250;
public static float HomingAngle = MathHelper.PiOver4 * 1.65f;
- internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult = Color.White;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
@@ -191,20 +191,15 @@ namespace CalamityMod.Projectiles.Magic
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/BasicTrail"));
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 3.5f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + offset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
});
-
-
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
diff --git a/Projectiles/Melee/EonBolt.cs b/Projectiles/Melee/EonBolt.cs
index b518b8ee34..d1ddcad5d6 100644
--- a/Projectiles/Melee/EonBolt.cs
+++ b/Projectiles/Melee/EonBolt.cs
@@ -7,13 +7,13 @@ using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Melee
{
public class EonBolt : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
- internal PrimitiveTrail TrailDrawer;
public override string Texture => "CalamityMod/Projectiles/Melee/GalaxiaBolt";
@@ -102,15 +102,11 @@ namespace CalamityMod.Projectiles.Melee
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
Texture2D texture = Request("CalamityMod/Projectiles/Melee/GalaxiaBolt").Value;
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, null, Color.Lerp(lightColor, Color.White, 0.5f), Projectile.rotation, texture.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
-
return false;
}
}
diff --git a/Projectiles/Melee/Exobeam.cs b/Projectiles/Melee/Exobeam.cs
index d26bb9b959..7c8c37c4a7 100644
--- a/Projectiles/Melee/Exobeam.cs
+++ b/Projectiles/Melee/Exobeam.cs
@@ -11,6 +11,7 @@ using static Terraria.ModLoader.ModContent;
using System;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Melee
{
@@ -21,8 +22,6 @@ namespace CalamityMod.Projectiles.Melee
public static float MaxWidth = 30;
public ref float Time => ref Projectile.ai[0];
- public PrimitiveTrail TrailDrawer = null;
- public PrimitiveTrail MiniTrailDrawer = null;
public static Asset BloomTex;
public static Asset SlashTex;
@@ -148,10 +147,6 @@ namespace CalamityMod.Projectiles.Melee
//Draw the blade.
Main.EntitySpriteDraw(texture, Projectile.oldPos[2] + Projectile.Size / 2f - Main.screenPosition, null, Color.White with { A = 0 }, Projectile.rotation + MathHelper.PiOver4, texture.Size() / 2f, bladeScale * Projectile.scale, 0, 0);
-
-
-
-
if (BloomTex == null)
BloomTex = ModContent.Request("CalamityMod/Particles/BloomCircle");
Texture2D bloomTex = BloomTex.Value;
@@ -163,10 +158,6 @@ namespace CalamityMod.Projectiles.Melee
Main.EntitySpriteDraw(bloomTex, Projectile.oldPos[2] + Projectile.Size / 2f - Main.screenPosition, null, (mainColor * 0.1f) with { A = 0 }, 0, bloomTex.Size() / 2f, 1.3f * Projectile.scale, 0, 0);
Main.EntitySpriteDraw(bloomTex, Projectile.oldPos[1] + Projectile.Size / 2f - Main.screenPosition, null, (mainColor * 0.5f) with { A = 0 }, 0, bloomTex.Size() / 2f, 0.34f * Projectile.scale, 0, 0);
-
- TrailDrawer ??= new(TrailWidth, TrailColor, null, GameShaders.Misc["CalamityMod:ExobladePierce"]);
- MiniTrailDrawer ??= new(MiniTrailWidth, MiniTrailColor, null, GameShaders.Misc["CalamityMod:ExobladePierce"]);
-
Main.spriteBatch.EnterShaderRegion();
if (TrailTex == null)
@@ -180,21 +171,18 @@ namespace CalamityMod.Projectiles.Melee
GameShaders.Misc["CalamityMod:ExobladePierce"].Apply();
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30, Projectile.oldRot);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(TrailWidth, TrailColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ExobladePierce"]), 30);
GameShaders.Misc["CalamityMod:ExobladePierce"].UseColor(Color.White);
GameShaders.Misc["CalamityMod:ExobladePierce"].UseSecondaryColor(Color.White);
- MiniTrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30, Projectile.oldRot);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(MiniTrailWidth, MiniTrailColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ExobladePierce"]), 30);
Main.spriteBatch.ExitShaderRegion();
//Draw the bloom above the trail
Main.EntitySpriteDraw(bloomTex, Projectile.oldPos[2] + Projectile.Size / 2f - Main.screenPosition, null, (Color.White * 0.2f) with { A = 0 }, 0, bloomTex.Size() / 2f, 0.78f * Projectile.scale, 0, 0);
- Main.EntitySpriteDraw(bloomTex, Projectile.oldPos[1] + Projectile.Size / 2f - Main.screenPosition, null, (Color.White * 0.5f) with { A = 0 }, 0, bloomTex.Size() / 2f, 0.2f * Projectile.scale, 0, 0);
-
-
-
+ Main.EntitySpriteDraw(bloomTex, Projectile.oldPos[1] + Projectile.Size / 2f - Main.screenPosition, null, (Color.White * 0.5f) with { A = 0 }, 0, bloomTex.Size() / 2f, 0.2f * Projectile.scale, 0, 0);
return false;
}
}
diff --git a/Projectiles/Melee/ExobladeProj.cs b/Projectiles/Melee/ExobladeProj.cs
index f5f53cd703..e0be4a3565 100644
--- a/Projectiles/Melee/ExobladeProj.cs
+++ b/Projectiles/Melee/ExobladeProj.cs
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using CalamityMod.Buffs.StatDebuffs;
using CalamityMod.Dusts;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
@@ -25,10 +26,6 @@ namespace CalamityMod.Projectiles.Melee
public override LocalizedText DisplayName => CalamityUtils.GetItemName();
public Player Owner => Main.player[Projectile.owner];
- public PrimitiveTrail SlashDrawer = null;
-
- public PrimitiveTrail PierceAfterimageDrawer = null;
-
const float BladeLength = 180;
public int GetSwingTime
@@ -454,10 +451,6 @@ namespace CalamityMod.Projectiles.Melee
if (Projectile.Opacity <= 0f || InPostBonkStasis)
return false;
- // Initialize the primitives drawers.
- SlashDrawer ??= new(SlashWidthFunction, SlashColorFunction, null, GameShaders.Misc["CalamityMod:ExobladeSlash"]);
- PierceAfterimageDrawer ??= new(PierceWidthFunction, PierceColorFunction, null, GameShaders.Misc["CalamityMod:ExobladePierce"]);
-
DrawSlash();
DrawPierceTrail();
DrawBlade();
@@ -480,7 +473,7 @@ namespace CalamityMod.Projectiles.Melee
GameShaders.Misc["CalamityMod:ExobladeSlash"].Shader.Parameters["flipped"].SetValue(Direction == 1);
GameShaders.Misc["CalamityMod:ExobladeSlash"].Apply();
- SlashDrawer.Draw(GenerateSlashPoints(), Projectile.Center - Main.screenPosition, 95);
+ PrimitiveSet.Prepare(GenerateSlashPoints(), new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Center, shader: GameShaders.Misc["CalamityMod:ExobladeSlash"]), 95);
Main.spriteBatch.ExitShaderRegion();
}
@@ -499,13 +492,13 @@ namespace CalamityMod.Projectiles.Melee
mainColor = Color.Lerp(Color.White, mainColor, 0.4f + 0.6f * (float)Math.Pow(LungeProgression, 0.5f));
secondaryColor = Color.Lerp(Color.White, secondaryColor, 0.4f + 0.6f * (float)Math.Pow(LungeProgression, 0.5f));
- Vector2 trailOffset = (Projectile.rotation - Direction * MathHelper.PiOver4).ToRotationVector2() * 98f + Projectile.Size * 0.5f - Main.screenPosition;
+ Vector2 trailOffset = (Projectile.rotation - Direction * MathHelper.PiOver4).ToRotationVector2() * 98f + Projectile.Size * 0.5f;
GameShaders.Misc["CalamityMod:ExobladePierce"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/EternityStreak"));
GameShaders.Misc["CalamityMod:ExobladePierce"].UseImage2("Images/Extra_189");
GameShaders.Misc["CalamityMod:ExobladePierce"].UseColor(mainColor);
GameShaders.Misc["CalamityMod:ExobladePierce"].UseSecondaryColor(secondaryColor);
GameShaders.Misc["CalamityMod:ExobladePierce"].Apply();
- PierceAfterimageDrawer.Draw(Projectile.oldPos.Take(51), trailOffset, 53);
+ PrimitiveSet.Prepare(Projectile.oldPos.Take(51), new(PierceWidthFunction, PierceColorFunction, (_) => trailOffset, shader: GameShaders.Misc["CalamityMod:ExobladePierce"]), 53);
Main.spriteBatch.ExitShaderRegion();
}
diff --git a/Projectiles/Melee/MarniteObliteratorProj.cs b/Projectiles/Melee/MarniteObliteratorProj.cs
index d067452dab..3461ff88b1 100644
--- a/Projectiles/Melee/MarniteObliteratorProj.cs
+++ b/Projectiles/Melee/MarniteObliteratorProj.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Tools;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Tools;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
@@ -19,7 +20,6 @@ namespace CalamityMod.Projectiles.Melee
public override string Texture => "CalamityMod/Items/Tools/MarniteObliterator";
public static Asset GlowmaskTex;
public static Asset BloomTex;
- internal PrimitiveTrail TrailDrawer;
public Player Owner => Main.player[Projectile.owner];
public ref float MoveInIntervals => ref Projectile.localAI[0];
@@ -125,7 +125,6 @@ namespace CalamityMod.Projectiles.Melee
return 29.4f * completionRatio;
}
-
public void DrawBeam(Texture2D beamTex, Vector2 direction, int beamIndex)
{
Vector2 startPos = Owner.MountedCenter + direction * 17f + direction.RotatedBy(MathHelper.PiOver2) * (float)Math.Cos(MathHelper.TwoPi * beamIndex / 3f + SpeenBeams * 0.06f) * 13f;
@@ -174,12 +173,8 @@ namespace CalamityMod.Projectiles.Melee
Main.EntitySpriteDraw(bloomTex, Projectile.Center - Main.screenPosition, null, Color.DeepSkyBlue * 0.3f, MathHelper.PiOver2, bloomTex.Size() / 2f, 0.3f * Projectile.scale, SpriteEffects.None, 0);
-
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/DoubleTrail"));
- TrailDrawer.Draw(new Vector2[] { Projectile.Center , Owner.MountedCenter - normalizedVelocity * 13f}, - Main.screenPosition, 30);
+ PrimitiveSet.Prepare(new Vector2[] { Projectile.Center, Owner.MountedCenter - normalizedVelocity * 13f }, new(WidthFunction, ColorFunction, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
diff --git a/Projectiles/Melee/PrismTooth.cs b/Projectiles/Melee/PrismTooth.cs
index 3bd6d025e7..fb8c3375b6 100644
--- a/Projectiles/Melee/PrismTooth.cs
+++ b/Projectiles/Melee/PrismTooth.cs
@@ -1,4 +1,5 @@
using CalamityMod.Buffs.DamageOverTime;
+using CalamityMod.Graphics.Primitives;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -13,7 +14,6 @@ namespace CalamityMod.Projectiles.Melee
public class PrismTooth : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
- internal PrimitiveTrail TrailDrawer;
public const int Lifetime = 80;
public Player Owner => Main.player[Projectile.owner];
public ref float ShootReach => ref Projectile.ai[0];
@@ -115,9 +115,6 @@ namespace CalamityMod.Projectiles.Melee
if (Time <= 5f)
return true;
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PrismaticStreak"]);
-
// Variable adjustment vector used to prevent the trail for starting somewhat that isn't behind
// the crystal. This may appear in small amounts, with offsets of a few pixels, but at the speed
// these crystals go, it's probably not something to worry too much about.
@@ -135,7 +132,7 @@ namespace CalamityMod.Projectiles.Melee
Main.spriteBatch.EnterShaderRegion();
GameShaders.Misc["CalamityMod:PrismaticStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f + generalOffset - Main.screenPosition, 65);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + generalOffset, shader: GameShaders.Misc["CalamityMod:PrismaticStreak"]), 65);
Main.spriteBatch.ExitShaderRegion();
return true;
}
diff --git a/Projectiles/Melee/RendingNeedle.cs b/Projectiles/Melee/RendingNeedle.cs
index 60ff8d71ef..b898c7ee36 100644
--- a/Projectiles/Melee/RendingNeedle.cs
+++ b/Projectiles/Melee/RendingNeedle.cs
@@ -8,6 +8,7 @@ using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Melee
@@ -16,7 +17,6 @@ namespace CalamityMod.Projectiles.Melee
{
public new string LocalizationCategory => "Projectiles.Melee";
- internal PrimitiveTrail TrailDrawer;
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10;
@@ -85,6 +85,7 @@ namespace CalamityMod.Projectiles.Melee
return MathHelper.Lerp(0f, 14f * Projectile.scale, expansionCompletion);
}
+ public Vector2 OffsetFunction(float completionRatio) => Projectile.Size * 0.5f - Utils.SafeNormalize(Projectile.velocity, Vector2.Zero) * 30.5f;
public override bool PreDraw(ref Color lightColor)
{
@@ -93,11 +94,8 @@ namespace CalamityMod.Projectiles.Melee
Texture2D texture = Request("CalamityMod/Projectiles/Melee/RendingNeedle").Value;
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Utils.SafeNormalize(Projectile.velocity, Vector2.Zero) * 30.5f - Main.screenPosition, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, OffsetFunction, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, null, Color.Lerp(lightColor, Color.White, 0.5f), Projectile.rotation, texture.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
@@ -120,8 +118,6 @@ namespace CalamityMod.Projectiles.Melee
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
-
-
return false;
}
diff --git a/Projectiles/Melee/StygianShieldAttack.cs b/Projectiles/Melee/StygianShieldAttack.cs
index 2ac58dc92d..56dd24393d 100644
--- a/Projectiles/Melee/StygianShieldAttack.cs
+++ b/Projectiles/Melee/StygianShieldAttack.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Weapons.Melee;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -30,7 +31,6 @@ namespace CalamityMod.Projectiles.Melee
public ref float DashTime => ref Projectile.ai[1];
public Vector2 DashDestination = Vector2.Zero;
- internal PrimitiveTrail TrailDrawer;
// Rawest placeholder sound
public static readonly SoundStyle DashSound = new("CalamityMod/Sounds/Custom/ExoMechs/ApolloMissileLaunch") { Volume = 0.6f };
@@ -220,11 +220,9 @@ namespace CalamityMod.Projectiles.Melee
Color shieldColor = Color.LightSalmon;
// Main trail
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f + extraOffset - (direction * 80f), 10);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + extraOffset + Main.screenPosition - direction * 80f,
+ shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 10);
ArrowEffect.Parameters["halfSpreadAngle"].SetValue(MathHelper.ToRadians(7.5f));
ArrowEffect.Parameters["edgeColor"].SetValue(headColor.ToVector3());
diff --git a/Projectiles/Melee/TaintedBladeSlasher.cs b/Projectiles/Melee/TaintedBladeSlasher.cs
index aa3684678e..95cecc3c2c 100644
--- a/Projectiles/Melee/TaintedBladeSlasher.cs
+++ b/Projectiles/Melee/TaintedBladeSlasher.cs
@@ -9,13 +9,13 @@ using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
using Terraria.GameContent;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Melee
{
public class TaintedBladeSlasher : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
- internal PrimitiveTrail TrailDrawer = null;
public ref float SwordItemID => ref Projectile.ai[1];
public ref float VerticalOffset => ref Projectile.localAI[0];
public ref float Time => ref Projectile.localAI[1];
@@ -209,9 +209,6 @@ namespace CalamityMod.Projectiles.Melee
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:FadingSolidTrail"]);
-
Texture2D forearmTexture = ModContent.Request("CalamityMod/Projectiles/Melee/TaintedForearm").Value;
Texture2D armTexture = ModContent.Request("CalamityMod/Projectiles/Melee/TaintedArm").Value;
Texture2D handTexture = ModContent.Request("CalamityMod/Projectiles/Melee/TaintedHand").Value;
@@ -248,13 +245,6 @@ namespace CalamityMod.Projectiles.Melee
Vector2 top = BladeCenterPosition + BladeOffsetDirection * BladeFrame.Height * 0.5f - Main.screenPosition;
Vector2 offsetToBlade = (top - bottom).SafeNormalize(Vector2.Zero).RotatedBy(MathHelper.PiOver2) * 5f;
- TrailDrawer.OverridingStickPointStart = BladeCenterPosition - BladeOffsetDirection * BladeFrame.Height * 0.5f + offsetToBlade - Main.screenPosition;
- TrailDrawer.OverridingStickPointEnd = BladeCenterPosition + BladeOffsetDirection * BladeFrame.Height * 0.5f + offsetToBlade - Main.screenPosition;
-
- // Swap the ends if needed so that the trail faces the right direction.
- if (Owner.direction == -1)
- Utils.Swap(ref TrailDrawer.OverridingStickPointStart, ref TrailDrawer.OverridingStickPointEnd);
-
Vector2[] drawPoints = new Vector2[Projectile.oldPos.Length];
Vector2 perpendicularDirection = BladeOffsetDirection.SafeNormalize(Vector2.UnitY).RotatedBy(MathHelper.PiOver2);
for (int i = 1; i < drawPoints.Length; i++)
@@ -265,7 +255,15 @@ namespace CalamityMod.Projectiles.Melee
drawPoints[i] = Projectile.Center + perpendicularDirection.RotatedBy(i * -0.014f * Owner.direction) * i * -Owner.direction * 6f;
}
- TrailDrawer.Draw(drawPoints, BladeCenterPosition - Projectile.position - Main.screenPosition, 67);
+ var leftVertexPosition = BladeCenterPosition - BladeOffsetDirection * BladeFrame.Height * 0.5f + offsetToBlade - Main.screenPosition;
+ var rightVertexPosition = BladeCenterPosition + BladeOffsetDirection * BladeFrame.Height * 0.5f + offsetToBlade - Main.screenPosition;
+
+ // Swap the ends if needed so that the trail faces the right direction.
+ if (Owner.direction == -1)
+ Utils.Swap(ref leftVertexPosition, ref rightVertexPosition);
+
+ PrimitiveSet.Prepare(drawPoints, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => BladeCenterPosition - Projectile.position,
+ shader: GameShaders.Misc["CalamityMod:FadingSolidTrail"], initialVertexPositionsOverride: (leftVertexPosition, rightVertexPosition)), 67);
}
// Draw the blade.
diff --git a/Projectiles/Melee/TerratomereBeam.cs b/Projectiles/Melee/TerratomereBeam.cs
index 115f4ad104..3f247b6ddb 100644
--- a/Projectiles/Melee/TerratomereBeam.cs
+++ b/Projectiles/Melee/TerratomereBeam.cs
@@ -4,6 +4,7 @@ using Terraria.ModLoader;
using Terraria.Graphics.Shaders;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Melee
{
@@ -11,8 +12,6 @@ namespace CalamityMod.Projectiles.Melee
{
public new string LocalizationCategory => "Projectiles.Melee";
public Vector2[] ControlPoints;
-
- public PrimitiveTrail SlashDrawer = null;
public bool Flipped => Projectile.ai[0] == 1f;
@@ -46,9 +45,6 @@ namespace CalamityMod.Projectiles.Melee
public override bool PreDraw(ref Color lightColor)
{
- // Initialize the primitive drawer.
- SlashDrawer ??= new(SlashWidthFunction, SlashColorFunction, null, GameShaders.Misc["CalamityMod:ExobladeSlash"]);
-
// Draw the slash effect.
Main.spriteBatch.EnterShaderRegion();
@@ -59,7 +55,7 @@ namespace CalamityMod.Projectiles.Melee
points.Add(ControlPoints[i] + ControlPoints[i].SafeNormalize(Vector2.Zero) * (Projectile.scale - 1f) * 40f);
for (int i = 0; i < 3; i++)
- SlashDrawer.Draw(points, Projectile.Center - Main.screenPosition, 65);
+ PrimitiveSet.Prepare(points, new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Center, shader: GameShaders.Misc["CalamityMod:ExobladeSlash"]), 65);
Main.spriteBatch.ExitShaderRegion();
return false;
diff --git a/Projectiles/Melee/TerratomereBigSlash.cs b/Projectiles/Melee/TerratomereBigSlash.cs
index a156170c03..641f0fb86c 100644
--- a/Projectiles/Melee/TerratomereBigSlash.cs
+++ b/Projectiles/Melee/TerratomereBigSlash.cs
@@ -5,6 +5,7 @@ using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Terraria.Graphics.Shaders;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Melee
{
@@ -12,8 +13,6 @@ namespace CalamityMod.Projectiles.Melee
{
public new string LocalizationCategory => "Projectiles.Melee";
public int TargetIndex = -1;
-
- public PrimitiveTrail SlashDrawer = null;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
@@ -63,16 +62,13 @@ namespace CalamityMod.Projectiles.Melee
public override bool PreDraw(ref Color lightColor)
{
- // Initialize the slash drawer.
- SlashDrawer ??= new PrimitiveTrail(SlashWidthFunction, SlashColorFunction, null, GameShaders.Misc["CalamityMod:ExobladePierce"]);
-
GameShaders.Misc["CalamityMod:ExobladePierce"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/BlobbyNoise"));
GameShaders.Misc["CalamityMod:ExobladePierce"].UseImage2("Images/Extra_189");
GameShaders.Misc["CalamityMod:ExobladePierce"].UseColor(Terratomere.TerraColor1);
GameShaders.Misc["CalamityMod:ExobladePierce"].UseSecondaryColor(Terratomere.TerraColor2);
for (int i = 0; i < 4; i++)
- SlashDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ExobladePierce"]), 30);
return false;
}
diff --git a/Projectiles/Melee/TerratomereHoldoutProj.cs b/Projectiles/Melee/TerratomereHoldoutProj.cs
index 64f582b1a2..8790e3996c 100644
--- a/Projectiles/Melee/TerratomereHoldoutProj.cs
+++ b/Projectiles/Melee/TerratomereHoldoutProj.cs
@@ -11,13 +11,13 @@ using Terraria.Graphics.Shaders;
using Terraria.Audio;
using static CalamityMod.CalamityUtils;
using System.Linq;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Melee
{
public class TerratomereHoldoutProj : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
- public PrimitiveTrail SlashDrawer = null;
public Player Owner => Main.player[Projectile.owner];
@@ -230,9 +230,6 @@ namespace CalamityMod.Projectiles.Melee
public void DrawSlash()
{
- // Initialize the primitive drawer.
- SlashDrawer ??= new(SlashWidthFunction, SlashColorFunction, null, GameShaders.Misc["CalamityMod:ExobladeSlash"]);
-
// Draw the slash effect.
Main.spriteBatch.EnterShaderRegion();
@@ -240,7 +237,7 @@ namespace CalamityMod.Projectiles.Melee
PrepareSlashShader(Direction == 1);
if (SwingCompletionAtStartOfTrail > SwingCompletionRatio)
- SlashDrawer.Draw(GenerateSlashPoints(), Projectile.Center - Main.screenPosition, 95);
+ PrimitiveSet.Prepare(GenerateSlashPoints(), new(SlashWidthFunction, SlashColorFunction, (_) => Projectile.Center, shader: GameShaders.Misc["CalamityMod:ExobladeSlash"]), 95);
Main.spriteBatch.ExitShaderRegion();
}
diff --git a/Projectiles/Melee/ViolenceSlashProjectile.cs b/Projectiles/Melee/ViolenceSlashProjectile.cs
index 6d97af7fcb..89736bbf14 100644
--- a/Projectiles/Melee/ViolenceSlashProjectile.cs
+++ b/Projectiles/Melee/ViolenceSlashProjectile.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Weapons.Melee;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Weapons.Melee;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -15,7 +16,6 @@ namespace CalamityMod.Projectiles.Melee
public class ViolenceSlashProjectile : ModProjectile
{
public override LocalizedText DisplayName => CalamityUtils.GetItemName();
- internal PrimitiveTrail SliceAfterimageDrawer = null;
internal Player Owner => Main.player[Projectile.owner];
internal ref float Time => ref Projectile.ai[0];
internal float SwingSine => (float)Math.Sin(MathHelper.TwoPi * Time / 50f);
@@ -98,9 +98,6 @@ namespace CalamityMod.Projectiles.Melee
public override bool PreDraw(ref Color lightColor)
{
- if (SliceAfterimageDrawer is null)
- SliceAfterimageDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]);
-
GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SwordSlashTexture"));
Texture2D spearProjectile = ModContent.Request(Texture).Value;
@@ -116,7 +113,7 @@ namespace CalamityMod.Projectiles.Melee
positions.Add(position);
}
- SliceAfterimageDrawer.Draw(positions, Projectile.Size * 0.5f - Main.screenPosition, 50);
+ PrimitiveSet.Prepare(positions, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]), 50);
return true;
}
}
diff --git a/Projectiles/Melee/ViolenceThrownProjectile.cs b/Projectiles/Melee/ViolenceThrownProjectile.cs
index 7afda2d432..da80a0724f 100644
--- a/Projectiles/Melee/ViolenceThrownProjectile.cs
+++ b/Projectiles/Melee/ViolenceThrownProjectile.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Weapons.Melee;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -15,7 +16,6 @@ namespace CalamityMod.Projectiles.Melee
public class ViolenceThrownProjectile : ModProjectile
{
public override LocalizedText DisplayName => CalamityUtils.GetItemName();
- internal PrimitiveTrail StreakDrawer = null;
internal Player Owner => Main.player[Projectile.owner];
internal ref float Time => ref Projectile.ai[0];
public override string Texture => "CalamityMod/Items/Weapons/Melee/Violence";
@@ -197,9 +197,6 @@ namespace CalamityMod.Projectiles.Melee
public override bool PreDraw(ref Color lightColor)
{
- if (StreakDrawer is null)
- StreakDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
Texture2D spearProjectile = ModContent.Request(Texture).Value;
@@ -218,7 +215,7 @@ namespace CalamityMod.Projectiles.Melee
drawPoints[i] -= (Projectile.oldRot[i] + MathHelper.PiOver4).ToRotationVector2() * Projectile.height * 0.5f;
if (Time > Projectile.oldPos.Length)
- StreakDrawer.Draw(drawPoints, Projectile.Size * 0.5f - Main.screenPosition, 88);
+ PrimitiveSet.Prepare(drawPoints, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 88);
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
for (int i = 0; i < 6; i++)
diff --git a/Projectiles/Melee/WulfrumScrew.cs b/Projectiles/Melee/WulfrumScrew.cs
index c7c5861ff4..d497a35f4c 100644
--- a/Projectiles/Melee/WulfrumScrew.cs
+++ b/Projectiles/Melee/WulfrumScrew.cs
@@ -1,4 +1,5 @@
using System;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Items.Weapons.Rogue;
using CalamityMod.Sounds;
@@ -18,7 +19,6 @@ namespace CalamityMod.Projectiles.Melee
public class WulfrumScrew : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
- internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult = Color.White;
@@ -200,17 +200,12 @@ namespace CalamityMod.Projectiles.Melee
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
- //Draw a trail
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/BasicTrail"));
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
-
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + offset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
});
//Draw the screw with chroma abberation
diff --git a/Projectiles/Ranged/ExoCrystalArrow.cs b/Projectiles/Ranged/ExoCrystalArrow.cs
index 88af4e505c..f795becc29 100644
--- a/Projectiles/Ranged/ExoCrystalArrow.cs
+++ b/Projectiles/Ranged/ExoCrystalArrow.cs
@@ -9,13 +9,14 @@ using CalamityMod.Particles;
using Terraria.Graphics.Shaders;
using Microsoft.Xna.Framework.Graphics;
using CalamityMod.Items.Weapons.Ranged;
+using CalamityMod.Graphics.Primitives;
+using Microsoft.CodeAnalysis;
namespace CalamityMod.Projectiles.Ranged
{
public class ExoCrystalArrow : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
- public PrimitiveTrail PierceAfterimageDrawer = null;
public bool CreateLightning => Projectile.ai[0] == 1f;
@@ -77,8 +78,6 @@ namespace CalamityMod.Projectiles.Ranged
public override bool PreDraw(ref Color lightColor)
{
- PierceAfterimageDrawer ??= new(PrimitiveWidthFunction, PrimitiveColorFunction, null, GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"]);
-
float localIdentityOffset = Projectile.identity * 0.1372f;
Color mainColor = CalamityUtils.MulticolorLerp((Main.GlobalTimeWrappedHourly * 2f + localIdentityOffset) % 1f, Color.Cyan, Color.Lime, Color.GreenYellow, Color.Goldenrod, Color.Orange);
Color secondaryColor = CalamityUtils.MulticolorLerp((Main.GlobalTimeWrappedHourly * 2f + localIdentityOffset + 0.2f) % 1f, Color.Cyan, Color.Lime, Color.GreenYellow, Color.Goldenrod, Color.Orange);
@@ -86,14 +85,13 @@ namespace CalamityMod.Projectiles.Ranged
mainColor = Color.Lerp(Color.White, mainColor, 0.85f);
secondaryColor = Color.Lerp(Color.White, secondaryColor, 0.85f);
- Vector2 trailOffset = Projectile.Size * 0.5f - Main.screenPosition;
+ Vector2 trailOffset = Projectile.Size * 0.5f;
GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/EternityStreak"));
GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"].UseImage2("Images/Extra_189");
GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"].UseColor(mainColor);
GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"].UseSecondaryColor(secondaryColor);
GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"].Apply();
- PierceAfterimageDrawer.Draw(Projectile.oldPos, trailOffset, 53);
-
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => trailOffset, shader: GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"]), 53);
Texture2D tex = ModContent.Request(Texture).Value;
Vector2 origin = tex.Size() * 0.5f;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
diff --git a/Projectiles/Ranged/ExoLightningBolt.cs b/Projectiles/Ranged/ExoLightningBolt.cs
index cbc45ce972..307fb9d459 100644
--- a/Projectiles/Ranged/ExoLightningBolt.cs
+++ b/Projectiles/Ranged/ExoLightningBolt.cs
@@ -1,4 +1,5 @@
using CalamityMod.Buffs.DamageOverTime;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.Ranged;
using Microsoft.Xna.Framework;
using System;
@@ -17,7 +18,6 @@ namespace CalamityMod.Projectiles.Ranged
public class ExoLightningBolt : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
- internal PrimitiveTrail LightningDrawer;
public bool HasPlayedSound;
@@ -162,13 +162,10 @@ namespace CalamityMod.Projectiles.Ranged
public override bool PreDraw(ref Color lightColor)
{
- if (LightningDrawer is null)
- LightningDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"]);
-
GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"].UseImage1("Images/Misc/Perlin");
GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"].Apply();
- LightningDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 18);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, false, shader: GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"]), 18);
return false;
}
diff --git a/Projectiles/Ranged/MarksmanShot.cs b/Projectiles/Ranged/MarksmanShot.cs
index 70214893b6..b4048dfc0c 100644
--- a/Projectiles/Ranged/MarksmanShot.cs
+++ b/Projectiles/Ranged/MarksmanShot.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Systems;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -17,7 +18,6 @@ namespace CalamityMod.Projectiles.Ranged
public new string LocalizationCategory => "Projectiles.Ranged";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
private static readonly int trailLength = 35;
- private PrimitiveTrail trailDrawer;
internal List trailPositions;
// Lifetime of a bullet. Defined in terms of updates because Terraria's engine is trash.
@@ -212,11 +212,8 @@ namespace CalamityMod.Projectiles.Ranged
if (trailPositions is null)
return false;
- if (trailDrawer is null)
- trailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/BasicTrail"));
- trailDrawer.Draw(trailPositions, Projectile.Size * 0.5f - Main.screenPosition, trailLength);
+ PrimitiveSet.Prepare(trailPositions, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), trailLength);
return false;
}
diff --git a/Projectiles/Ranged/MeowCreature.cs b/Projectiles/Ranged/MeowCreature.cs
index 94a6ac41c4..3daeb2a679 100644
--- a/Projectiles/Ranged/MeowCreature.cs
+++ b/Projectiles/Ranged/MeowCreature.cs
@@ -1,3 +1,4 @@
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -14,8 +15,6 @@ namespace CalamityMod.Projectiles.Ranged
{
public new string LocalizationCategory => "Projectiles.Ranged";
- internal PrimitiveTrail TrailDrawer;
-
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 36;
@@ -63,11 +62,7 @@ namespace CalamityMod.Projectiles.Ranged
// The creature glows
public override void PostDraw(Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction);
-
- TrailDrawer.Draw(Projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), Projectile.Size * 0.5f - Main.screenPosition, 30);
-
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f), 30);
Texture2D glow = ModContent.Request(Texture).Value;
Main.EntitySpriteDraw(glow, Projectile.Center - Main.screenPosition, null, Color.White, Projectile.rotation, glow.Size() * 0.5f, Projectile.scale, SpriteEffects.None);
}
diff --git a/Projectiles/Ranged/MineralMortarProjectile.cs b/Projectiles/Ranged/MineralMortarProjectile.cs
index 77b5756a05..b21bc0299c 100644
--- a/Projectiles/Ranged/MineralMortarProjectile.cs
+++ b/Projectiles/Ranged/MineralMortarProjectile.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Particles;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
@@ -176,10 +177,8 @@ namespace CalamityMod.Projectiles.Ranged
float rotation = Projectile.rotation + MathHelper.PiOver2;
Vector2 origin = texture.Size() * 0.5f;
- PrimitiveTrail trail = new PrimitiveTrail(TrailWidthFunction, ColorTrailFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SwordSlashTexture"));
- trail.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 50);
-
+ PrimitiveSet.Prepare(Projectile.oldPos, new(TrailWidthFunction, ColorTrailFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 50);
if (CalamityConfig.Instance.Afterimages)
{
for (int i = 0; i < 3; i++)
diff --git a/Projectiles/Ranged/PristineFire.cs b/Projectiles/Ranged/PristineFire.cs
index 66e34181a0..7ac5652133 100644
--- a/Projectiles/Ranged/PristineFire.cs
+++ b/Projectiles/Ranged/PristineFire.cs
@@ -1,5 +1,6 @@
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Dusts;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -16,9 +17,6 @@ namespace CalamityMod.Projectiles.Ranged
public new string LocalizationCategory => "Projectiles.Ranged";
public override string Texture => "CalamityMod/Particles/MediumMist";
- // Helix trail thing
- public PrimitiveTrail HelixTrail = null;
-
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Type] = 20;
@@ -92,9 +90,6 @@ namespace CalamityMod.Projectiles.Ranged
public override bool PreDraw(ref Color lightColor)
{
- if (HelixTrail is null)
- HelixTrail = new PrimitiveTrail(HelixTrailWidthFunction, HelixTrailColorFunction);
-
// Draw a double helix trail
for (int direction = -1; direction <= 1; direction += 2)
{
@@ -109,7 +104,7 @@ namespace CalamityMod.Projectiles.Ranged
Vector2 sinOffset = (Vector2.UnitY * direction * MathF.Sin(i * MathHelper.Pi * 0.125f) * 24f).RotatedBy(Projectile.oldRot[i]);
trailPositions.Add(Projectile.oldPos[i] + sinOffset);
}
- HelixTrail.Draw(trailPositions, Projectile.Size * 0.5f- Main.screenPosition, 60);
+ PrimitiveSet.Prepare(trailPositions, new(HelixTrailWidthFunction, HelixTrailColorFunction, (_) => Projectile.Size * 0.5f), 60);
}
return false;
}
diff --git a/Projectiles/Ranged/SpeedBlasterShot.cs b/Projectiles/Ranged/SpeedBlasterShot.cs
index 40755b24cf..0a3cfc47dc 100644
--- a/Projectiles/Ranged/SpeedBlasterShot.cs
+++ b/Projectiles/Ranged/SpeedBlasterShot.cs
@@ -1,4 +1,5 @@
using CalamityMod.Graphics.Metaballs;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using System.Linq;
@@ -18,7 +19,6 @@ namespace CalamityMod.Projectiles.Ranged
public static readonly SoundStyle ShotImpact = new("CalamityMod/Sounds/Item/SplatshotImpact") { PitchVariance = 0.3f, Volume = 2.5f };
public static readonly SoundStyle ShotImpactBig = new("CalamityMod/Sounds/Item/SplatshotBigImpact") { PitchVariance = 0.3f, Volume = 4f };
- internal PrimitiveTrail TrailDrawer;
public override void SetStaticDefaults()
{
@@ -180,10 +180,7 @@ namespace CalamityMod.Projectiles.Ranged
internal Color ColorFunction(float completionRatio) => GetColor(Projectile.ai[0]) * Projectile.Opacity;
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction);
-
- TrailDrawer.Draw(Projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), Projectile.Size * 0.5f - Main.screenPosition, 20);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f), 20);
return true;
}
}
diff --git a/Projectiles/Ranged/TelluricGlareArrow.cs b/Projectiles/Ranged/TelluricGlareArrow.cs
index 8b540dd328..2dab8db792 100644
--- a/Projectiles/Ranged/TelluricGlareArrow.cs
+++ b/Projectiles/Ranged/TelluricGlareArrow.cs
@@ -8,6 +8,7 @@ using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Ranged
{
@@ -16,7 +17,6 @@ namespace CalamityMod.Projectiles.Ranged
public new string LocalizationCategory => "Projectiles.Ranged";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
- public PrimitiveTrail TrailDrawer = null;
private const int Lifetime = 180;
private static Color ShaderColorOne = new Color(237, 194, 66);
private static Color ShaderColorTwo = new Color(235, 227, 117);
@@ -100,13 +100,10 @@ namespace CalamityMod.Projectiles.Ranged
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
- Vector2 overallOffset = Projectile.Size * 0.5f - Main.screenPosition;
+ Vector2 overallOffset = Projectile.Size * 0.5f;
overallOffset += Projectile.velocity * 1.4f;
- TrailDrawer.Draw(Projectile.oldPos, overallOffset, 92); // 58
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => overallOffset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 92);
return false;
}
diff --git a/Projectiles/Ranged/TheMaelstromShark.cs b/Projectiles/Ranged/TheMaelstromShark.cs
index fc0f71474f..95392e0182 100644
--- a/Projectiles/Ranged/TheMaelstromShark.cs
+++ b/Projectiles/Ranged/TheMaelstromShark.cs
@@ -6,13 +6,13 @@ using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Ranged
{
public class TheMaelstromShark : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
- public PrimitiveTrail LightningTrailDrawer = null;
public override void SetStaticDefaults()
{
Main.projFrames[Projectile.type] = 6;
@@ -97,11 +97,8 @@ namespace CalamityMod.Projectiles.Ranged
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
- if (LightningTrailDrawer is null)
- LightningTrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- LightningTrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 60);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 60);
Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, direction, 0);
return false;
}
diff --git a/Projectiles/Ranged/WulfrumScrapBullet.cs b/Projectiles/Ranged/WulfrumScrapBullet.cs
index 2c1fd2b869..fd26a60f77 100644
--- a/Projectiles/Ranged/WulfrumScrapBullet.cs
+++ b/Projectiles/Ranged/WulfrumScrapBullet.cs
@@ -1,4 +1,5 @@
using System;
+using CalamityMod.Graphics.Primitives;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
@@ -12,7 +13,6 @@ namespace CalamityMod.Projectiles.Ranged
public class WulfrumScrapBullet : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
- internal PrimitiveTrail TrailDrawer;
public override void SetStaticDefaults()
{
@@ -60,12 +60,8 @@ namespace CalamityMod.Projectiles.Ranged
public override bool PreDraw(ref Color lightColor)
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/BasicTrail"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30);
-
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
return false;
}
}
diff --git a/Projectiles/Rogue/DynamicPursuerElectricity.cs b/Projectiles/Rogue/DynamicPursuerElectricity.cs
index 7692ecc939..307247065f 100644
--- a/Projectiles/Rogue/DynamicPursuerElectricity.cs
+++ b/Projectiles/Rogue/DynamicPursuerElectricity.cs
@@ -1,7 +1,6 @@
-using Microsoft.Xna.Framework;
+using CalamityMod.Graphics.Primitives;
+using Microsoft.Xna.Framework;
using System;
-using System.IO;
-using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
@@ -12,7 +11,6 @@ namespace CalamityMod.Projectiles.Rogue
public class DynamicPursuerElectricity : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
- internal PrimitiveTrail LightningDrawer;
public const int MaximumBranchingIterations = 3;
public const float LightningTurnRandomnessFactor = 1.7f;
@@ -116,7 +114,7 @@ namespace CalamityMod.Projectiles.Rogue
internal float WidthFunction(float completionRatio)
{
- float baseWidth = MathHelper.Lerp(2f, 6f, (float)Math.Sin(MathHelper.Pi * 4f * completionRatio) * 0.5f + 0.5f) * Projectile.scale;
+ float baseWidth = MathHelper.Lerp(4f, 7f, (float)Math.Sin(MathHelper.Pi * 4f * completionRatio) * 0.5f + 0.5f) * Projectile.scale;
return baseWidth * (float)Math.Sin(MathHelper.Pi * completionRatio);
}
internal Color ColorFunction(float completionRatio)
@@ -126,10 +124,7 @@ namespace CalamityMod.Projectiles.Rogue
}
public override bool PreDraw(ref Color lightColor)
{
- if (LightningDrawer is null)
- LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
-
- LightningDrawer.Draw(Projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), Projectile.Size * 0.5f - Main.screenPosition, 300);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, false), 90);
return false;
}
}
diff --git a/Projectiles/Rogue/FishboneBoomerangProjectile.cs b/Projectiles/Rogue/FishboneBoomerangProjectile.cs
index 45c298a2b4..905b5409b5 100644
--- a/Projectiles/Rogue/FishboneBoomerangProjectile.cs
+++ b/Projectiles/Rogue/FishboneBoomerangProjectile.cs
@@ -11,7 +11,6 @@ namespace CalamityMod.Projectiles.Rogue
public class FishboneBoomerangProjectile : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
- internal PrimitiveTrail TrailRenderer;
public override string Texture => "CalamityMod/Items/Weapons/Rogue/FishboneBoomerang";
public static int ChargeupTime = 10;
diff --git a/Projectiles/Rogue/ScarletDevilProjectile.cs b/Projectiles/Rogue/ScarletDevilProjectile.cs
index a4f6404e97..68bfa13cb7 100644
--- a/Projectiles/Rogue/ScarletDevilProjectile.cs
+++ b/Projectiles/Rogue/ScarletDevilProjectile.cs
@@ -6,13 +6,13 @@ using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Rogue
{
public class ScarletDevilProjectile : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
- internal PrimitiveTrail TrailDrawer;
public ref float ShootTimer => ref Projectile.ai[0];
public override string Texture => "CalamityMod/Items/Weapons/Rogue/ScarletDevil";
@@ -175,11 +175,9 @@ namespace CalamityMod.Projectiles.Rogue
}
else
{
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]);
-
GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + Projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, 60);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + Projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, false,
+ shader: GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]), 60);
Texture2D spearTexture = ModContent.Request(Texture).Value;
diff --git a/Projectiles/Rogue/StormfrontLightning.cs b/Projectiles/Rogue/StormfrontLightning.cs
index 6c3cf7292f..562e292843 100644
--- a/Projectiles/Rogue/StormfrontLightning.cs
+++ b/Projectiles/Rogue/StormfrontLightning.cs
@@ -1,4 +1,5 @@
using CalamityMod.Buffs.DamageOverTime;
+using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.Rogue;
using CalamityMod.Projectiles.Rogue;
using CalamityMod.Sounds;
@@ -21,7 +22,6 @@ namespace CalamityMod.Projectiles.Rogue
public class StormfrontLightning : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
- internal PrimitiveTrail LightningDrawer;
private int noTileHitCounter = 81; //Using other projectile's methods to not collide until a certain time has passed, allowing use inside caves
@@ -180,13 +180,11 @@ namespace CalamityMod.Projectiles.Rogue
public override bool PreDraw(ref Color lightColor)
{
//Just gonna use Dom's work on Heavenly Gale, tried to do a new one myself but I barely understand the .fx files and how they work, might revist it again eventually - Shade
- if (LightningDrawer is null)
- LightningDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"]);
-
GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"].UseImage1("Images/Misc/Perlin");
GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"].Apply();
- LightningDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.3f - Main.screenPosition, 10);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.3f, false,
+ shader: GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"]), 10);
return false;
}
diff --git a/Projectiles/Rogue/WulfrumKnifeProj.cs b/Projectiles/Rogue/WulfrumKnifeProj.cs
index 4373aa131a..00e1882c66 100644
--- a/Projectiles/Rogue/WulfrumKnifeProj.cs
+++ b/Projectiles/Rogue/WulfrumKnifeProj.cs
@@ -9,13 +9,13 @@ using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Rogue
{
public class WulfrumKnifeProj : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
- internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult = Color.White;
public override string Texture => "CalamityMod/Items/Weapons/Rogue/WulfrumKnife";
@@ -127,16 +127,12 @@ namespace CalamityMod.Projectiles.Rogue
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/BasicTrail"));
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
-
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size + offset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
});
diff --git a/Projectiles/Summon/CnidarianJellyfishOnTheString.cs b/Projectiles/Summon/CnidarianJellyfishOnTheString.cs
index 4f91de5f77..571e684ea6 100644
--- a/Projectiles/Summon/CnidarianJellyfishOnTheString.cs
+++ b/Projectiles/Summon/CnidarianJellyfishOnTheString.cs
@@ -12,6 +12,7 @@ using Terraria.ID;
using Terraria.ModLoader;
using static CalamityMod.CalamityUtils;
using static Terraria.ModLoader.ModContent;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Summon
{
@@ -28,8 +29,6 @@ namespace CalamityMod.Projectiles.Summon
public static readonly SoundStyle ZapSound = SoundID.Item94 with { Volume = SoundID.Item94.Volume * 0.5f };
public static readonly SoundStyle SlapSound = new("CalamityMod/Sounds/Custom/WetSlap", 4);
- internal PrimitiveTrail TrailRenderer;
-
public List Segments;
public Player Owner => Main.player[Projectile.owner];
public ref float Initialized => ref Projectile.ai[0];
@@ -238,13 +237,9 @@ namespace CalamityMod.Projectiles.Summon
public override bool PreDraw(ref Color lightColor)
{
- if (TrailRenderer is null)
- TrailRenderer = new PrimitiveTrail(PrimWidthFunction, PrimColorFunction);
-
Vector2[] segmentPositions = Segments.Select(x => x.position).ToArray();
- TrailRenderer.Draw(segmentPositions, -Main.screenPosition, 66);
-
+ PrimitiveSet.Prepare(segmentPositions, new(PrimWidthFunction, PrimColorFunction), 66);
Texture2D tex = Request(Texture).Value;
diff --git a/Projectiles/Summon/CosmilampBeam.cs b/Projectiles/Summon/CosmilampBeam.cs
index e4b7bb63f1..8ca0f13065 100644
--- a/Projectiles/Summon/CosmilampBeam.cs
+++ b/Projectiles/Summon/CosmilampBeam.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Weapons.Summon;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Weapons.Summon;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -12,7 +13,6 @@ namespace CalamityMod.Projectiles.Summon
public class CosmilampBeam : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Summon";
- internal PrimitiveTrail TrailDrawer;
public ref float Timer => ref Projectile.ai[0];
@@ -105,15 +105,13 @@ namespace CalamityMod.Projectiles.Summon
public override bool PreDraw(ref Color lightColor)
{
- // Initialize the trail drawer.
- TrailDrawer ??= new(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
Projectile.localAI[0] = 0f;
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 42);
+ var primSet = PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 42);
Projectile.localAI[0] = 1f;
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 42);
+ if (primSet.HasValue)
+ primSet.Value.Render();
return false;
}
}
diff --git a/Projectiles/Summon/DaedalusLightning.cs b/Projectiles/Summon/DaedalusLightning.cs
index 333bd465f0..1528615ff5 100644
--- a/Projectiles/Summon/DaedalusLightning.cs
+++ b/Projectiles/Summon/DaedalusLightning.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework;
+using CalamityMod.Graphics.Primitives;
+using Microsoft.Xna.Framework;
using System;
using System.IO;
using System.Linq;
@@ -11,7 +12,6 @@ namespace CalamityMod.Projectiles.Summon
public class DaedalusLightning : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Summon";
- internal PrimitiveTrail LightningDrawer;
public const int MaximumBranchingIterations = 3;
public const float LightningTurnRandomnessFactor = 1.7f;
@@ -137,10 +137,7 @@ namespace CalamityMod.Projectiles.Summon
}
public override bool PreDraw(ref Color lightColor)
{
- if (LightningDrawer is null)
- LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
-
- LightningDrawer.Draw(Projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), Projectile.Size * 0.5f - Main.screenPosition, 300);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, false), 90);
return false;
}
#endregion
diff --git a/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs b/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs
index c36ee78ca1..5c371e9c66 100644
--- a/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs
+++ b/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs
@@ -1,4 +1,5 @@
-using CalamityMod.Items.Weapons.Summon;
+using CalamityMod.Graphics.Primitives;
+using CalamityMod.Items.Weapons.Summon;
using CalamityMod.Projectiles.Boss;
using Microsoft.Xna.Framework;
using System;
@@ -17,10 +18,6 @@ namespace CalamityMod.Projectiles.Summon.SmallAresArms
public ref float Time => ref Projectile.ai[1];
- public PrimitiveTrail LightningDrawer;
-
- public PrimitiveTrail LightningBackgroundDrawer;
-
public override string Texture => "CalamityMod/Projectiles/Boss/AresTeslaOrb";
public override void SetStaticDefaults()
@@ -113,17 +110,12 @@ namespace CalamityMod.Projectiles.Summon.SmallAresArms
public override bool PreDraw(ref Color lightColor)
{
- if (LightningDrawer is null)
- LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
- if (LightningBackgroundDrawer is null)
- LightningBackgroundDrawer = new PrimitiveTrail(BackgroundWidthFunction, BackgroundColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
-
Projectile orbToAttachTo = GetOrbToAttachTo();
if (orbToAttachTo != null)
{
List arcPoints = AresTeslaOrb.DetermineElectricArcPoints(Projectile.Center, orbToAttachTo.Center, 117);
- LightningBackgroundDrawer.Draw(arcPoints, -Main.screenPosition, 90);
- LightningDrawer.Draw(arcPoints, -Main.screenPosition, 90);
+ PrimitiveSet.Prepare(arcPoints, new(BackgroundWidthFunction, BackgroundColorFunction, smoothen: false), 90);
+ PrimitiveSet.Prepare(arcPoints, new(WidthFunction, ColorFunction, smoothen: false), 90);
}
lightColor.R = (byte)(255 * Projectile.Opacity);
diff --git a/Projectiles/Summon/WulfrumDroid.cs b/Projectiles/Summon/WulfrumDroid.cs
index 1900e43ff9..00290cc4f6 100644
--- a/Projectiles/Summon/WulfrumDroid.cs
+++ b/Projectiles/Summon/WulfrumDroid.cs
@@ -15,6 +15,7 @@ using Terraria.Graphics.Effects;
using static Terraria.ModLoader.ModContent;
using ReLogic.Content;
using System.IO;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Summon
{
@@ -44,7 +45,6 @@ namespace CalamityMod.Projectiles.Summon
}
}
- internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult;
public Player healedPlayer;
@@ -464,8 +464,6 @@ namespace CalamityMod.Projectiles.Summon
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/ZapTrail"));
Vector2[] drawPos = new Vector2[] { Projectile.Center, Projectile.Center, healedPlayer.Center + (Projectile.Center - healedPlayer.Center) * 0.5f + Vector2.UnitY * 40f, healedPlayer.Center, healedPlayer.Center };
@@ -473,7 +471,7 @@ namespace CalamityMod.Projectiles.Summon
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1.8f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
- TrailDrawer.Draw(drawPos, - Main.screenPosition + offset, 30);
+ PrimitiveSet.Prepare(drawPos, new(WidthFunction, ColorFunction, (_) => offset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
});
Main.spriteBatch.End();
diff --git a/Projectiles/Summon/WulfrumEnergyBurst.cs b/Projectiles/Summon/WulfrumEnergyBurst.cs
index 8e1bc1fa0d..406b4e6c84 100644
--- a/Projectiles/Summon/WulfrumEnergyBurst.cs
+++ b/Projectiles/Summon/WulfrumEnergyBurst.cs
@@ -10,6 +10,7 @@ using static Terraria.ModLoader.ModContent;
using Terraria.Graphics.Shaders;
using Terraria.Graphics.Effects;
using ReLogic.Content;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Summon
{
@@ -39,7 +40,6 @@ namespace CalamityMod.Projectiles.Summon
public static float HomingRange = 350;
public static float HomingAngle = MathHelper.PiOver4 * 1f;
- internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult = Color.White;
public override void SetStaticDefaults()
@@ -180,16 +180,12 @@ namespace CalamityMod.Projectiles.Summon
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/ZapTrail"));
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1.5f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
-
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + offset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
});
Main.spriteBatch.End();
diff --git a/Projectiles/Summon/WulfrumFusionBolt.cs b/Projectiles/Summon/WulfrumFusionBolt.cs
index 3b9f7f3bc1..ac265cc5fa 100644
--- a/Projectiles/Summon/WulfrumFusionBolt.cs
+++ b/Projectiles/Summon/WulfrumFusionBolt.cs
@@ -9,6 +9,7 @@ using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using CalamityMod.Particles;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Summon
{
@@ -39,7 +40,6 @@ namespace CalamityMod.Projectiles.Summon
public static float HomingRange = 250;
public static float HomingAngle = MathHelper.PiOver4 * 1.65f;
- internal PrimitiveTrail TrailDrawer;
internal Color PrimColorMult = Color.White;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
@@ -187,15 +187,12 @@ namespace CalamityMod.Projectiles.Summon
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
- if (TrailDrawer is null)
- TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
-
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/BasicTrail"));
CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 0.5f, delegate (Vector2 offset, Color colorMod)
{
PrimColorMult = colorMod;
- TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f + offset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 30);
});
Main.spriteBatch.End();
diff --git a/Projectiles/Typeless/GemTechArmorGem.cs b/Projectiles/Typeless/GemTechArmorGem.cs
index f3640b8652..f42d9e8459 100644
--- a/Projectiles/Typeless/GemTechArmorGem.cs
+++ b/Projectiles/Typeless/GemTechArmorGem.cs
@@ -6,6 +6,7 @@ using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Typeless
{
@@ -16,7 +17,6 @@ namespace CalamityMod.Projectiles.Typeless
public ref float Variant => ref Projectile.ai[1];
public const int UpwardFlyTime = 24;
public const int RedirectTime = 12;
- public PrimitiveTrail FlameTrailDrawer = null;
public override string Texture => "CalamityMod/Projectiles/Typeless/GemTechYellowGem";
@@ -139,9 +139,6 @@ namespace CalamityMod.Projectiles.Typeless
public override bool PreDraw(ref Color lightColor)
{
- if (FlameTrailDrawer is null)
- FlameTrailDrawer = new PrimitiveTrail(TrailWidth, TrailColor, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
// Prepare the flame trail shader with its map texture.
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
@@ -174,7 +171,7 @@ namespace CalamityMod.Projectiles.Typeless
Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(Color.White), Projectile.rotation, origin, Projectile.scale, SpriteEffects.None, 0);
if (Projectile.ai[0] > UpwardFlyTime + RedirectTime)
- FlameTrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 71);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(TrailWidth, TrailColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 71);
return false;
}
diff --git a/Projectiles/Typeless/MythrilFlare.cs b/Projectiles/Typeless/MythrilFlare.cs
index 7d80270c08..0978506c57 100644
--- a/Projectiles/Typeless/MythrilFlare.cs
+++ b/Projectiles/Typeless/MythrilFlare.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework;
+using CalamityMod.Graphics.Primitives;
+using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Shaders;
@@ -10,7 +11,6 @@ namespace CalamityMod.Projectiles.Typeless
public class MythrilFlare : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Typeless";
- public PrimitiveTrail FlameTrailDrawer = null;
public ref float Time => ref Projectile.ai[0];
public const int AttackDelay = 22;
@@ -93,12 +93,9 @@ namespace CalamityMod.Projectiles.Typeless
public override bool PreDraw(ref Color lightColor)
{
- if (FlameTrailDrawer is null)
- FlameTrailDrawer = new PrimitiveTrail(TrailWidth, TrailColor, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
// Prepare the flame trail shader with its map texture.
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/EternityStreak"));
- FlameTrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 74);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(TrailWidth, TrailColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 74);
return false;
}
diff --git a/Projectiles/Typeless/SuicideBomberDemon.cs b/Projectiles/Typeless/SuicideBomberDemon.cs
index 95a4448cf0..b409412ca0 100644
--- a/Projectiles/Typeless/SuicideBomberDemon.cs
+++ b/Projectiles/Typeless/SuicideBomberDemon.cs
@@ -7,6 +7,7 @@ using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Typeless
{
@@ -20,7 +21,6 @@ namespace CalamityMod.Projectiles.Typeless
}
public ref float Time => ref Projectile.ai[1];
public Player Owner => Main.player[Projectile.owner];
- public PrimitiveTrail FlameTrailDrawer = null;
public override void SetStaticDefaults()
{
Main.projFrames[Projectile.type] = 12;
@@ -229,10 +229,6 @@ namespace CalamityMod.Projectiles.Typeless
{
Main.spriteBatch.EnterShaderRegion();
- // Initialize the flame trail drawer.
- if (FlameTrailDrawer is null)
- FlameTrailDrawer = new PrimitiveTrail(FlameTrailWidthFunction, FlameTrailColorFunction, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
-
// Prepare the flame trail shader with its map texture.
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
@@ -268,7 +264,7 @@ namespace CalamityMod.Projectiles.Typeless
Vector2 trailOffset = Projectile.Size * 0.5f;
trailOffset += (Projectile.rotation + MathHelper.PiOver2).ToRotationVector2() * 20f;
- FlameTrailDrawer.Draw(Projectile.oldPos, trailOffset - Main.screenPosition, 61);
+ PrimitiveSet.Prepare(Projectile.oldPos, new(FlameTrailWidthFunction, FlameTrailColorFunction, (_) => trailOffset, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"]), 61);
}
Main.spriteBatch.ExitShaderRegion();
diff --git a/Projectiles/Typeless/WulfrumHook.cs b/Projectiles/Typeless/WulfrumHook.cs
index 3a986703b6..cdc008c50b 100644
--- a/Projectiles/Typeless/WulfrumHook.cs
+++ b/Projectiles/Typeless/WulfrumHook.cs
@@ -13,6 +13,7 @@ using ReLogic.Utilities;
using CalamityMod.Items.Accessories;
using System.Collections.Generic;
using System.Linq;
+using CalamityMod.Graphics.Primitives;
namespace CalamityMod.Projectiles.Typeless
{
@@ -20,7 +21,6 @@ namespace CalamityMod.Projectiles.Typeless
{
public new string LocalizationCategory => "Projectiles.Typeless";
public Player Owner => Main.player[Projectile.owner];
- internal PrimitiveTrail TrailRenderer;
public HookState State
{
@@ -231,16 +231,11 @@ namespace CalamityMod.Projectiles.Typeless
public override bool PreDraw(ref Color lightColor)
{
- if (TrailRenderer is null)
- TrailRenderer = new PrimitiveTrail(PrimWidthFunction, PrimColorFunction);
-
Vector2[] segmentPositions = new Vector2[] {Projectile.Center, Owner.Center };
if (State == HookState.Grappling)
segmentPositions = Owner.GetModPlayer().Segments.Select(x => x.position).ToArray();
-
- TrailRenderer.Draw(segmentPositions, -Main.screenPosition, 30);
-
+ PrimitiveSet.Prepare(new List(segmentPositions) { Owner.Center }, new(PrimWidthFunction, PrimColorFunction), 30);
Texture2D texture = TextureAssets.Projectile[Type].Value;