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 a8fc877e9e..0000000000 --- a/Graphics/Primitives/PrimitiveTrail.cs +++ /dev/null @@ -1,262 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using CalamityMod.DataStructures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -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 a4667b375d..bb9ad9f7bc 100644 --- a/NPCs/AcidRain/AcidEel.cs +++ b/NPCs/AcidRain/AcidEel.cs @@ -3,6 +3,7 @@ using System.Linq; using CalamityMod.BiomeManagers; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Dusts; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Weapons.Magic; @@ -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; @@ -79,7 +78,7 @@ namespace CalamityMod.NPCs.AcidRain public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { - bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.AcidEel") }); @@ -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 9fd27bd385..7d5e03ca02 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using CalamityMod.Events; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Potions; using CalamityMod.Items.Weapons.DraedonsArsenal; using CalamityMod.NPCs.ExoMechs.Ares; @@ -116,13 +117,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 }; @@ -172,7 +166,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { - bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Apollo") }); @@ -1497,16 +1491,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")); @@ -1569,7 +1553,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); @@ -1634,11 +1618,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); + } } @@ -1720,7 +1705,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo public override void HitEffect(NPC.HitInfo hit) { for (int k = 0; k < 3; k++) - Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1f); + Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1f); if (NPC.soundDelay == 0) { @@ -1732,14 +1717,14 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo { for (int num193 = 0; num193 < 2; num193++) { - Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); + Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); } for (int i = 0; i < 20; i++) { - int plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 0, new Color(0, 255, 255), 2.5f); + int plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 0, new Color(0, 255, 255), 2.5f); Main.dust[plasmaDust].noGravity = true; Main.dust[plasmaDust].velocity *= 3f; - plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); + plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); Main.dust[plasmaDust].velocity *= 2f; Main.dust[plasmaDust].noGravity = true; } diff --git a/NPCs/ExoMechs/Ares/AresBody.cs b/NPCs/ExoMechs/Ares/AresBody.cs index 321d6ad872..2d8c35b838 100644 --- a/NPCs/ExoMechs/Ares/AresBody.cs +++ b/NPCs/ExoMechs/Ares/AresBody.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; 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; @@ -199,7 +196,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { - bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Ares") }); @@ -316,7 +313,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares Vector2 NeuronLeft = new Vector2(NPC.Center.X - xoffset, NPC.Center.Y + yoffset); NPC.alpha = 0; NPC.dontTakeDamage = true; - neurontimer++; + neurontimer++; if (Main.netMode != NetmodeID.MultiplayerClient) { if (neurontimer >= 180) @@ -330,7 +327,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares Vector2 betweenR = NeuronRight + velocity * 650; Vector2 betweenL = NeuronLeft + velocity * 650; - + Terraria.Audio.SoundEngine.PlaySound(CommonCalamitySounds.LaserCannonSound with { Volume = CommonCalamitySounds.LaserCannonSound.Volume - 0.2f, Pitch = CommonCalamitySounds.LaserCannonSound.Pitch + 0.2f }, NeuronRight); Projectile.NewProjectile(NPC.GetSource_FromAI(), betweenL, betweenL + velocity, ModContent.ProjectileType(), 111, 0f, Main.myPlayer, 7, NPC.whoAmI); Projectile.NewProjectile(NPC.GetSource_FromAI(), betweenR, betweenR + velocity, ModContent.ProjectileType(), 111, 0f, Main.myPlayer, 7, NPC.whoAmI); @@ -922,7 +919,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares if (calamityGlobalNPC.newAI[2] == deathrayTelegraphDuration) { DeathraySoundSlot = SoundEngine.PlaySound(LaserStartSound, NPC.Center); - + if (Main.netMode != NetmodeID.MultiplayerClient) { int type = ModContent.ProjectileType(); @@ -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; @@ -1597,7 +1589,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares public override void HitEffect(NPC.HitInfo hit) { for (int k = 0; k < 3; k++) - Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1f); + Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1f); if (NPC.soundDelay == 0) { @@ -1609,14 +1601,14 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { for (int i = 0; i < 2; i++) { - Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); + Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); } for (int j = 0; j < 20; j++) { - int plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 0, new Color(0, 255, 255), 2.5f); + int plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 0, new Color(0, 255, 255), 2.5f); Main.dust[plasmaDust].noGravity = true; Main.dust[plasmaDust].velocity *= 3f; - plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); + plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); Main.dust[plasmaDust].velocity *= 2f; Main.dust[plasmaDust].noGravity = true; } diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs index 9970ea88c2..397b881b92 100644 --- a/NPCs/ExoMechs/Artemis/Artemis.cs +++ b/NPCs/ExoMechs/Artemis/Artemis.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; 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; @@ -204,7 +198,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { - bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Artemis") }); @@ -1128,7 +1122,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis { calamityGlobalNPC.newAI[3] = 0f; AIState = (float)Phase.Deathray; - for (int i = 0; i < Main.maxProjectiles; i++) + for (int i = 0; i < Main.maxProjectiles; i ++) { if (Main.projectile[i].type == ModContent.ProjectileType()) { @@ -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); } } @@ -1552,7 +1536,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis public override void HitEffect(NPC.HitInfo hit) { for (int k = 0; k < 3; k++) - Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1f); + Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1f); if (NPC.soundDelay == 0) { @@ -1564,14 +1548,14 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis { for (int i = 0; i < 2; i++) { - Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); + Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); } for (int j = 0; j < 20; j++) { - int plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 0, new Color(0, 255, 255), 2.5f); + int plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 0, new Color(0, 255, 255), 2.5f); Main.dust[plasmaDust].noGravity = true; Main.dust[plasmaDust].velocity *= 3f; - plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); + plasmaDust = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); Main.dust[plasmaDust].velocity *= 2f; Main.dust[plasmaDust].noGravity = true; } diff --git a/NPCs/SupremeCalamitas/BrimstoneHeart.cs b/NPCs/SupremeCalamitas/BrimstoneHeart.cs index 3128221115..c7d82c8f11 100644 --- a/NPCs/SupremeCalamitas/BrimstoneHeart.cs +++ b/NPCs/SupremeCalamitas/BrimstoneHeart.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using CalamityMod.Graphics.Primitives; using CalamityMod.Projectiles.Rogue; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -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 ea876140c8..45dd64c478 100644 --- a/Projectiles/Boss/ApolloChargeTelegraph.cs +++ b/Projectiles/Boss/ApolloChargeTelegraph.cs @@ -1,5 +1,6 @@ using System.IO; using CalamityMod.Events; +using CalamityMod.Graphics.Primitives; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; @@ -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 9866dbc17b..02cd9981bf 100644 --- a/Projectiles/Boss/AresTeslaOrb.cs +++ b/Projectiles/Boss/AresTeslaOrb.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; 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() @@ -95,7 +94,7 @@ namespace CalamityMod.Projectiles.Boss Vector2 dustVel = new Vector2(dustSpeed, 0.0f).RotatedBy(Projectile.velocity.ToRotation()); dustVel = dustVel.RotatedBy(-angleRandom); dustVel = dustVel.RotatedByRandom(2f * angleRandom); - int randomDustType = Main.rand.NextBool(2)? 206 : 229; + int randomDustType = Main.rand.Next(2) == 0 ? 206 : 229; float scale = randomDustType == 206 ? 1.5f : 1f; int teslaDust = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 200, default, 2.5f * scale); @@ -121,7 +120,7 @@ namespace CalamityMod.Projectiles.Boss Vector2 dustVel = new Vector2(dustSpeed, 0f).RotatedBy(Projectile.velocity.ToRotation()); dustVel = dustVel.RotatedBy(-angleRandom); dustVel = dustVel.RotatedByRandom(2f * angleRandom); - int randomDustType = Main.rand.NextBool(2)? 206 : 229; + int randomDustType = Main.rand.Next(2) == 0 ? 206 : 229; float scale = randomDustType == 206 ? 1.5f : 1f; int teslaDust2 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 0, default, 3f * scale); @@ -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 fac2cb4b07..63e62c0438 100644 --- a/Projectiles/Boss/ArtemisChargeTelegraph.cs +++ b/Projectiles/Boss/ArtemisChargeTelegraph.cs @@ -1,4 +1,5 @@ using System.IO; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; 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 470c51f720..c83141068b 100644 --- a/Projectiles/Boss/ArtemisSpinLaserbeam.cs +++ b/Projectiles/Boss/ArtemisSpinLaserbeam.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; 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 f7bd1a2d3c..399da5d9fb 100644 --- a/Projectiles/Boss/CirrusPhotonRipperPrismTooth.cs +++ b/Projectiles/Boss/CirrusPhotonRipperPrismTooth.cs @@ -1,5 +1,6 @@ using System; 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 4bc06823b1..5b8ad0cdf6 100644 --- a/Projectiles/Boss/DraedonSummonLaser.cs +++ b/Projectiles/Boss/DraedonSummonLaser.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.DraedonsArsenal; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -17,10 +18,9 @@ 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() + public override void SetStaticDefaults() { ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 10000; } @@ -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 baeff5fe51..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; @@ -11,8 +12,7 @@ namespace CalamityMod.Projectiles.Boss { public class DyingSun : ModProjectile, ILocalizedModType { - public new string LocalizationCategory => "Projectiles.Boss"; - public PrimitiveTrail FireDrawer; + public new string LocalizationCategory => "Projectiles.Boss"; 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 75ec27bad5..10fb38c403 100644 --- a/Projectiles/Boss/InfernadoRevenge.cs +++ b/Projectiles/Boss/InfernadoRevenge.cs @@ -1,6 +1,7 @@ using System.IO; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.CalPlayer; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -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 1783e1261d..107e412e22 100644 --- a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs +++ b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using CalamityMod.Dusts; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items; using CalamityMod.Items.Weapons.DraedonsArsenal; using CalamityMod.Items.Weapons.Ranged; @@ -137,7 +138,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal // This formula ensures that the sword has a sudden and extremely harsh responsiveness penalty when the mouse is close to the player. // Otherwise it controls perfectly fine. - float aimResponsiveness = 0.035f + 0.3f * (float)Math.Pow(distRatio, 1D / 3); + float aimResponsiveness = 0.035f + 0.3f * (float)Math.Pow(distRatio, 1D/3); // Update the sword's angle with the responsiveness determined by mouse position. // Also flag for netcode sync if applicable (this is the only way the sword can rotate in multiplayer). @@ -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 c131735ff8..52955ecffb 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 b03b00d9d1..14912610a2 100644 --- a/Projectiles/Enemy/GammRayBurst.cs +++ b/Projectiles/Enemy/GammRayBurst.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; 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 a6adb89c45..328f95e38e 100644 --- a/Projectiles/Magic/ApotheosisEnergy.cs +++ b/Projectiles/Magic/ApotheosisEnergy.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; 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 a201c6825d..9f79ccc6c2 100644 --- a/Projectiles/Magic/ArtAttackStar.cs +++ b/Projectiles/Magic/ArtAttackStar.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Magic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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; @@ -60,7 +60,7 @@ namespace CalamityMod.Projectiles.Magic for (int i = end - 1; i >= start; i--) { float distanceFromStar = Vector2.Distance(Projectile.position, Projectile.oldPos[i]); - if (distanceFromStar < (distanceTraveled * 0.7f + 30f)) + if (distanceFromStar < (distanceTraveled * 0.7f + 30f)) { shapeIsComplete = true; @@ -119,7 +119,7 @@ namespace CalamityMod.Projectiles.Magic for (int i = 0; i < 3; i++) { Dust rainbowMagic = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(8f, 8f), 261); - rainbowMagic.velocity = Main.rand.NextVector2Circular(6f, 6f) - ((Projectile.position - Projectile.oldPos[1]) / 3f).RotatedByRandom(0.51f); + rainbowMagic.velocity = Main.rand.NextVector2Circular(6f, 6f) - ((Projectile.position - Projectile.oldPos[1])/3f).RotatedByRandom(0.51f); rainbowMagic.color = Main.hslToRgb(Main.rand.NextFloat(), 1f, Main.rand.NextFloat(0.5f, 0.9f)); rainbowMagic.color.A = 128; @@ -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 966f886570..d9c6520850 100644 --- a/Projectiles/Magic/EternityHex.cs +++ b/Projectiles/Magic/EternityHex.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; @@ -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 6391799a4a..86500b03e3 100644 --- a/Projectiles/Magic/ExoVortex.cs +++ b/Projectiles/Magic/ExoVortex.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Magic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -13,7 +14,6 @@ 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 7336fa6672..2392c49eb8 100644 --- a/Projectiles/Magic/ExoVortex2.cs +++ b/Projectiles/Magic/ExoVortex2.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Magic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -13,7 +14,6 @@ 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 50e0b38524..4d5ae16c3f 100644 --- a/Projectiles/Magic/FabBolt.cs +++ b/Projectiles/Magic/FabBolt.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; 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 4ac70fa440..04a02e2e4e 100644 --- a/Projectiles/Magic/FabRay.cs +++ b/Projectiles/Magic/FabRay.cs @@ -1,5 +1,6 @@ using System; using CalamityMod.Buffs.Alcohol; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -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 1d18910c61..68aeb679cd 100644 --- a/Projectiles/Magic/RainbowRocket.cs +++ b/Projectiles/Magic/RainbowRocket.cs @@ -1,5 +1,6 @@ using System; using CalamityMod.DataStructures; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -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 9808074c5c..0647fd9e8b 100644 --- a/Projectiles/Magic/RancorLaserbeam.cs +++ b/Projectiles/Magic/RancorLaserbeam.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Graphics.Metaballs; +using CalamityMod.Graphics.Primitives; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; @@ -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 ed9ef2487c..4a2252092f 100644 --- a/Projectiles/Magic/WulfrumBolt.cs +++ b/Projectiles/Magic/WulfrumBolt.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Particles; using Microsoft.Xna.Framework; @@ -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"; @@ -127,7 +127,7 @@ namespace CalamityMod.Projectiles.Magic { float distanceFromTarget = (Target.Center - Projectile.Center).Length(); - Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow((1 - distanceFromTarget / HomingRange), 2)); + Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow(( 1 - distanceFromTarget / HomingRange), 2)); } Projectile.velocity *= 0.983f; @@ -170,7 +170,7 @@ namespace CalamityMod.Projectiles.Magic Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(4, 10); GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(center, velocity, Main.rand.NextFloat(1f, 2f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25)); - + } } } @@ -183,7 +183,7 @@ namespace CalamityMod.Projectiles.Magic internal float WidthFunction(float completionRatio) { - return 9.4f; + return 9.4f; } public override bool PreDraw(ref Color lightColor) @@ -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 20f05a8c10..16957c1ace 100644 --- a/Projectiles/Melee/EonBolt.cs +++ b/Projectiles/Melee/EonBolt.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -13,7 +14,6 @@ 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 463de701dc..08c49e8108 100644 --- a/Projectiles/Melee/Exobeam.cs +++ b/Projectiles/Melee/Exobeam.cs @@ -1,5 +1,6 @@ using System; using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Melee; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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) @@ -179,22 +170,19 @@ namespace CalamityMod.Projectiles.Melee GameShaders.Misc["CalamityMod:ExobladePierce"].Apply(); 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 d6f5e63e85..f72f1a710d 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 aae6536ebc..483bc1e142 100644 --- a/Projectiles/Melee/MarniteObliteratorProj.cs +++ b/Projectiles/Melee/MarniteObliteratorProj.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Tools; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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]; @@ -63,8 +63,8 @@ namespace CalamityMod.Projectiles.Melee Lighting.AddLight(Projectile.Center, Color.Blue.ToVector3() * 0.7f); } - if (MoveInIntervals > 0f) - MoveInIntervals -= 1f; + if (MoveInIntervals > 0f) + MoveInIntervals -= 1f; if (Owner.CantUseHoldout()) Projectile.Kill(); @@ -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 9bcd34667d..4e7e0d672c 100644 --- a/Projectiles/Melee/PrismTooth.cs +++ b/Projectiles/Melee/PrismTooth.cs @@ -1,5 +1,6 @@ using System; using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -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 1efdbc7ad3..01868f9745 100644 --- a/Projectiles/Melee/RendingNeedle.cs +++ b/Projectiles/Melee/RendingNeedle.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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; @@ -54,12 +54,12 @@ namespace CalamityMod.Projectiles.Melee Projectile.velocity *= (1 - (float)Math.Pow(Timer / MaxTime, 3) * 0.3f); - if (Main.rand.NextBool(2)) + if (Main.rand.Next(2) == 0) { Particle smoke = new HeavySmokeParticle(Projectile.Center, Projectile.velocity * 0.5f, Color.Lerp(Color.DodgerBlue, Color.MediumVioletRed, (float)Math.Sin(Main.GlobalTimeWrappedHourly * 6f)), 30, Main.rand.NextFloat(0.6f, 1.2f) * Projectile.scale * 0.6f, 0.28f, 0, false, 0, true); GeneralParticleHandler.SpawnParticle(smoke); - if (Main.rand.NextBool(3)) + if (Main.rand.Next(3) == 0) { Particle smokeGlow = new HeavySmokeParticle(Projectile.Center, Projectile.velocity * 0.5f, Main.hslToRgb(Main.rand.NextFloat(), 1, 0.7f), 20, Main.rand.NextFloat(0.4f, 0.7f) * Projectile.scale * 0.6f, 0.8f, 0, true, 0.05f, true); GeneralParticleHandler.SpawnParticle(smokeGlow); @@ -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); @@ -114,14 +112,12 @@ namespace CalamityMod.Projectiles.Melee Vector2 sparkCenter = Projectile.Center - Utils.SafeNormalize(Projectile.velocity, Vector2.Zero) * 30.5f - Main.screenPosition; - Main.EntitySpriteDraw(bloomTexture, sparkCenter, null, color * 0.5f, 0, bloomTexture.Size() / 2f, 4 * properBloomSize, SpriteEffects.None, 0); + Main.EntitySpriteDraw(bloomTexture, sparkCenter, null, color* 0.5f, 0, bloomTexture.Size() / 2f, 4 * properBloomSize, SpriteEffects.None, 0); Main.EntitySpriteDraw(starTexture, sparkCenter, null, color * 0.5f, rotation + MathHelper.PiOver4, starTexture.Size() / 2f, 2 * 0.75f, SpriteEffects.None, 0); Main.EntitySpriteDraw(starTexture, sparkCenter, null, Color.White, rotation, starTexture.Size() / 2f, 2, SpriteEffects.None, 0); 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 f16a1ae215..ca7f2628c3 100644 --- a/Projectiles/Melee/StygianShieldAttack.cs +++ b/Projectiles/Melee/StygianShieldAttack.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Particles; using Microsoft.Xna.Framework; @@ -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 }; @@ -56,11 +56,11 @@ namespace CalamityMod.Projectiles.Melee { if (Owner is null || Owner.dead || Owner.ActiveItem().type != ModContent.ItemType()) Projectile.Kill(); - + Owner.heldProj = Projectile.whoAmI; // TODO -- Windup sound (definitely requires a custom looping sound) - + // Dashing behavior Projectile.Opacity = Utils.GetLerpValue(0f, DashDuration * 0.7f, DashTime, true); if (DashDestination != Vector2.Zero) @@ -150,7 +150,7 @@ namespace CalamityMod.Projectiles.Melee Projectile.ExpandHitboxBy(100); Projectile.tileCollide = true; return; - } + } } // Otherwise, kill the projectile Projectile.Kill(); @@ -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()); @@ -237,7 +235,7 @@ namespace CalamityMod.Projectiles.Melee // Blooming shield and rings Main.spriteBatch.EnterShaderRegion(BlendState.Additive); - + float shieldRot = arrowFace - MathHelper.Pi; Main.EntitySpriteDraw(shieldTex, Projectile.Center + extraOffset, null, shieldColor, shieldRot, shieldTex.Size() / 2f, 1.25f * scaleMult, SpriteEffects.None); Main.EntitySpriteDraw(bloomTex, Projectile.Center + extraOffset, null, shieldColor * 0.75f, 0f, bloomTex.Size() / 2f, 0.5f * scaleMult, SpriteEffects.None); diff --git a/Projectiles/Melee/TaintedBladeSlasher.cs b/Projectiles/Melee/TaintedBladeSlasher.cs index 21bd122615..224be6887f 100644 --- a/Projectiles/Melee/TaintedBladeSlasher.cs +++ b/Projectiles/Melee/TaintedBladeSlasher.cs @@ -1,6 +1,7 @@ using System; using System.IO; using CalamityMod.CalPlayer; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -15,7 +16,6 @@ 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 f19f17cad7..438a5eaac9 100644 --- a/Projectiles/Melee/TerratomereBeam.cs +++ b/Projectiles/Melee/TerratomereBeam.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -12,8 +13,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; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; @@ -43,15 +42,12 @@ namespace CalamityMod.Projectiles.Melee public float SlashWidthFunction(float completionRatio) => Projectile.scale * 22f; public Color SlashColorFunction(float completionRatio) => Color.Lime * Utils.GetLerpValue(0.04f, 0.27f, completionRatio, true) * Projectile.Opacity; - + 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(); - + TerratomereHoldoutProj.PrepareSlashShader(Flipped); List points = new List(); @@ -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 cf3acf5879..eb46b38302 100644 --- a/Projectiles/Melee/TerratomereBigSlash.cs +++ b/Projectiles/Melee/TerratomereBigSlash.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 Terraria; @@ -12,9 +13,7 @@ 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"; public override void SetStaticDefaults() @@ -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 60245f5b9e..8b10698548 100644 --- a/Projectiles/Melee/TerratomereHoldoutProj.cs +++ b/Projectiles/Melee/TerratomereHoldoutProj.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Melee; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -17,7 +18,6 @@ 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]; @@ -153,7 +153,7 @@ namespace CalamityMod.Projectiles.Melee // Create the slash. if (Time == (int)(Terratomere.SwingTime * (SwingCompletionRatio + 0.15f))) SoundEngine.PlaySound(Terratomere.SwingSound, Projectile.Center); - + if (Main.myPlayer == Projectile.owner && Time == (int)(Terratomere.SwingTime * (SwingCompletionRatio + 0.34f))) { Vector2 bigSlashVelocity = Projectile.SafeDirectionTo(Main.MouseWorld) * Owner.ActiveItem().shootSpeed; @@ -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(); } @@ -274,7 +271,7 @@ namespace CalamityMod.Projectiles.Melee { if (Owner.moonLeech) return; - + Owner.statLife += Terratomere.TrueMeleeHitHeal; Owner.HealEffect(Terratomere.TrueMeleeHitHeal); } diff --git a/Projectiles/Melee/ViolenceSlashProjectile.cs b/Projectiles/Melee/ViolenceSlashProjectile.cs index e682973c6f..c8a7fccde0 100644 --- a/Projectiles/Melee/ViolenceSlashProjectile.cs +++ b/Projectiles/Melee/ViolenceSlashProjectile.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Melee; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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 da013a8fb7..f0a57b1625 100644 --- a/Projectiles/Melee/ViolenceThrownProjectile.cs +++ b/Projectiles/Melee/ViolenceThrownProjectile.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Particles; using Microsoft.Xna.Framework; @@ -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 bc8df550fd..eb527dbfcf 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 bd0f46c185..274d145215 100644 --- a/Projectiles/Ranged/ExoCrystalArrow.cs +++ b/Projectiles/Ranged/ExoCrystalArrow.cs @@ -1,7 +1,9 @@ using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Particles; using CalamityMod.Sounds; +using Microsoft.CodeAnalysis; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -15,7 +17,6 @@ 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 ef688fdc4e..50bebe3253 100644 --- a/Projectiles/Ranged/ExoLightningBolt.cs +++ b/Projectiles/Ranged/ExoLightningBolt.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Ranged; using Microsoft.Xna.Framework; using Terraria; @@ -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; @@ -78,7 +78,7 @@ namespace CalamityMod.Projectiles.Ranged float adjustedTimeLife = Projectile.timeLeft / Projectile.MaxUpdates; Projectile.Opacity = Utils.GetLerpValue(0f, 9f, adjustedTimeLife, true) * Utils.GetLerpValue(Lifetime, Lifetime - 3f, adjustedTimeLife, true); Projectile.scale = Projectile.Opacity; - + // Play a strike sound on the first frame. if (!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 53452a11e1..9b2427d1b6 100644 --- a/Projectiles/Ranged/MeowCreature.cs +++ b/Projectiles/Ranged/MeowCreature.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +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 927420b69e..dfacd5f717 100644 --- a/Projectiles/Ranged/PristineFire.cs +++ b/Projectiles/Ranged/PristineFire.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; 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; @@ -69,7 +67,7 @@ namespace CalamityMod.Projectiles.Ranged GeneralParticleHandler.SpawnParticle(spark); LineParticle spark2 = new LineParticle(Projectile.Center, -Projectile.velocity.RotatedBy(Main.rand.NextFloat(-0.23f, -0.56f)) * Main.rand.NextFloat(0.4f, 2.5f), false, 8, 1.2f, Main.rand.NextBool() ? Color.Orange : Color.DarkOrange); GeneralParticleHandler.SpawnParticle(spark2); - + for (int i = 0; i <= 3; i++) { Dust dust = Dust.NewDustPerfect(Projectile.Center, Main.rand.NextBool() ? 169 : 158, new Vector2(5, 5).RotatedByRandom(100) * Main.rand.NextFloat(0.2f, 1.5f), 0, default, Main.rand.NextFloat(1.6f, 2.2f)); @@ -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 7cf68cabb7..1cb35c3b0c 100644 --- a/Projectiles/Ranged/SpeedBlasterShot.cs +++ b/Projectiles/Ranged/SpeedBlasterShot.cs @@ -1,5 +1,6 @@ using System.Linq; using CalamityMod.Graphics.Metaballs; +using CalamityMod.Graphics.Primitives; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Terraria; @@ -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 6af0a7e785..7d00090138 100644 --- a/Projectiles/Ranged/TelluricGlareArrow.cs +++ b/Projectiles/Ranged/TelluricGlareArrow.cs @@ -1,6 +1,7 @@ using System; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -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; } @@ -128,11 +125,11 @@ namespace CalamityMod.Projectiles.Ranged } for (int i = 0; i < 20; i++) { - Dust holyFire = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.GoldCoin, 0f, 0f, 100, default, 3f); + Dust holyFire = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, 246, 0f, 0f, 100, default, 3f); holyFire.noGravity = true; holyFire.velocity *= 5f; - holyFire = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.GoldCoin, 0f, 0f, 100, default, 2f); + holyFire = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, 246, 0f, 0f, 100, default, 2f); holyFire.velocity *= 2f; } } diff --git a/Projectiles/Ranged/TheMaelstromShark.cs b/Projectiles/Ranged/TheMaelstromShark.cs index 43c1c5bc97..dc828efa75 100644 --- a/Projectiles/Ranged/TheMaelstromShark.cs +++ b/Projectiles/Ranged/TheMaelstromShark.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 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 d58ac4cdb1..e0b1f441a0 100644 --- a/Projectiles/Rogue/DynamicPursuerElectricity.cs +++ b/Projectiles/Rogue/DynamicPursuerElectricity.cs @@ -1,6 +1,5 @@ using System; -using System.IO; -using System.Linq; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -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 fb70eaac1d..ae8746334d 100644 --- a/Projectiles/Rogue/ScarletDevilProjectile.cs +++ b/Projectiles/Rogue/ScarletDevilProjectile.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.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"; @@ -44,7 +44,7 @@ namespace CalamityMod.Projectiles.Rogue if (!Main.dedServ) { for (int i = 0; i < (Projectile.Calamity().stealthStrike && Main.rand.NextBool() ? 2 : 1); i++) - Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.Firework_Red, Projectile.velocity.X * 0.25f, Projectile.velocity.Y * 0.25f, 0, new Color(255, 255, 255), 0.85f); + Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 130, Projectile.velocity.X * 0.25f, Projectile.velocity.Y * 0.25f, 0, new Color(255, 255, 255), 0.85f); } ShootTimer++; @@ -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 314409c3dc..5d2a2c36ed 100644 --- a/Projectiles/Rogue/StormfrontLightning.cs +++ b/Projectiles/Rogue/StormfrontLightning.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; 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 @@ -48,7 +48,7 @@ namespace CalamityMod.Projectiles.Rogue Projectile.width = 35; Projectile.height = 35; Projectile.alpha = 255; - Projectile.penetrate = 4; + Projectile.penetrate =4; Projectile.ignoreWater = true; Projectile.tileCollide = false; Projectile.friendly = true; @@ -83,7 +83,7 @@ namespace CalamityMod.Projectiles.Rogue //dust sparks are now a feature if (Main.rand.NextBool(10)) { - int d = Dust.NewDust(Projectile.Center, Projectile.width, Projectile.height, DustID.Electric, 0f, 0f, 100, new Color(Main.rand.Next(20, 100), 204, 250), 1f); + int d = Dust.NewDust(Projectile.Center, Projectile.width, Projectile.height, 226, 0f, 0f, 100, new Color(Main.rand.Next(20, 100), 204, 250), 1f); Main.dust[d].scale += (float)Main.rand.Next(50) * 0.01f; Main.dust[d].noGravity = true; Main.dust[d].position = Projectile.Center; @@ -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 4b2990a20d..16dbf23652 100644 --- a/Projectiles/Rogue/WulfrumKnifeProj.cs +++ b/Projectiles/Rogue/WulfrumKnifeProj.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Particles; using Microsoft.Xna.Framework; @@ -15,7 +16,6 @@ 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 4dccb5ca13..47530f606a 100644 --- a/Projectiles/Summon/CnidarianJellyfishOnTheString.cs +++ b/Projectiles/Summon/CnidarianJellyfishOnTheString.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using CalamityMod.DataStructures; +using CalamityMod.Graphics.Primitives; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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 5f873bd32b..c013827096 100644 --- a/Projectiles/Summon/CosmilampBeam.cs +++ b/Projectiles/Summon/CosmilampBeam.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Summon; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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 8e736ea2fa..e198f289a5 100644 --- a/Projectiles/Summon/DaedalusLightning.cs +++ b/Projectiles/Summon/DaedalusLightning.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -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 3e170ccf8e..9ebc57cc6b 100644 --- a/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs +++ b/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Summon; using CalamityMod.Projectiles.Boss; using Microsoft.Xna.Framework; @@ -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 111729a0ad..8bdb9532f5 100644 --- a/Projectiles/Summon/WulfrumDroid.cs +++ b/Projectiles/Summon/WulfrumDroid.cs @@ -2,6 +2,7 @@ using System.IO; using CalamityMod.Buffs.Summon; using CalamityMod.CalPlayer; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Accessories; using CalamityMod.Items.Weapons.Summon; using CalamityMod.Particles; @@ -44,7 +45,6 @@ namespace CalamityMod.Projectiles.Summon } } - internal PrimitiveTrail TrailDrawer; internal Color PrimColorMult; public Player healedPlayer; @@ -150,7 +150,7 @@ namespace CalamityMod.Projectiles.Summon { Vector2 direction = Main.rand.NextVector2CircularEdge(1f, 1f); - Dust wishyDust = Dust.NewDustPerfect(Projectile.Center + direction * Main.rand.NextFloat(1f, 8f), 229, Alpha: 100, Scale: Main.rand.NextFloat(1f, 1.4f)); + Dust wishyDust = Dust.NewDustPerfect(Projectile.Center + direction * Main.rand.NextFloat(1f, 8f), 229, Alpha : 100, Scale: Main.rand.NextFloat(1f, 1.4f)); wishyDust.noGravity = true; wishyDust.noLight = true; wishyDust.velocity = direction * Main.rand.NextFloat(2f, 4); @@ -160,7 +160,7 @@ namespace CalamityMod.Projectiles.Summon Projectile.soundDelay = NewSoundDelay; ShootTimer = ShootDelay; - Initialized++; + Initialized ++; } if (Owner.Calamity().mouseRight && Owner.HeldItem.type == ModContent.ItemType()) @@ -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 c6b30f7c8e..5b2779a14f 100644 --- a/Projectiles/Summon/WulfrumEnergyBurst.cs +++ b/Projectiles/Summon/WulfrumEnergyBurst.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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 1c7f5350aa..6da9fc7847 100644 --- a/Projectiles/Summon/WulfrumFusionBolt.cs +++ b/Projectiles/Summon/WulfrumFusionBolt.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Particles; using Microsoft.Xna.Framework; @@ -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"; @@ -111,7 +111,7 @@ namespace CalamityMod.Projectiles.Summon if (Projectile.timeLeft == 140) { Projectile.rotation = Projectile.velocity.ToRotation(); - + Target = null; } else @@ -124,7 +124,7 @@ namespace CalamityMod.Projectiles.Summon if (Target != null) { float distanceFromTarget = (Target.Center - Projectile.Center).Length(); - Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow((1 - distanceFromTarget / HomingRange), 2)); + Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow(( 1 - distanceFromTarget / HomingRange), 2)); } Projectile.velocity *= 0.983f; @@ -166,7 +166,7 @@ namespace CalamityMod.Projectiles.Summon Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(4, 10); GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(center, velocity, Main.rand.NextFloat(1f, 2f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25)); - + } } } @@ -179,7 +179,7 @@ namespace CalamityMod.Projectiles.Summon internal float WidthFunction(float completionRatio) { - return 6.4f; + return 6.4f; } public override bool PreDraw(ref Color lightColor) @@ -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 d340b90fe4..b336eaccd0 100644 --- a/Projectiles/Typeless/GemTechArmorGem.cs +++ b/Projectiles/Typeless/GemTechArmorGem.cs @@ -1,4 +1,5 @@ using CalamityMod.DataStructures; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -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 1d384f3176..3981836bce 100644 --- a/Projectiles/Typeless/SuicideBomberDemon.cs +++ b/Projectiles/Typeless/SuicideBomberDemon.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using CalamityMod.Graphics.Primitives; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -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; @@ -186,7 +186,7 @@ namespace CalamityMod.Projectiles.Typeless SoundEngine.PlaySound(SoundID.DD2_KoboldExplosion, Projectile.Center); for (int i = 0; i < 40; i++) { - Dust explosion = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.RainbowMk2); + Dust explosion = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, 267); explosion.velocity = Main.rand.NextVector2Circular(4f, 4f); explosion.color = Color.Red; explosion.scale = 1.35f; @@ -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 52db046de4..9096654a32 100644 --- a/Projectiles/Typeless/WulfrumHook.cs +++ b/Projectiles/Typeless/WulfrumHook.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using CalamityMod.Graphics.Primitives; using CalamityMod.Items.Accessories; using CalamityMod.Items.Materials; using CalamityMod.Particles; @@ -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 { @@ -164,7 +164,7 @@ namespace CalamityMod.Projectiles.Typeless continue; OnGrapple(worldPos, x, y); - + break; } @@ -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 }; + 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;