Starte
This commit is contained in:
1 parent
d5584c0645
commit
faea741cd9
5 files changed
+118
No files matched your search
@@ -207,7 +207,10 @@ namespace CalamityMod
|
||||
ExoChairSlowdownHotkey = RegisterHotKey("Exo Chair Slow Down", "RightShift");
|
||||
|
||||
if (!Main.dedServ)
|
||||
{
|
||||
LoadClient();
|
||||
GeneralParticleHandler.Load();
|
||||
}
|
||||
|
||||
BossRushEvent.Load();
|
||||
BossHealthBarManager.Load(this);
|
||||
@@ -396,6 +399,7 @@ namespace CalamityMod
|
||||
Main.rainTexture = rainOriginal;
|
||||
Main.manaTexture = manaOriginal;
|
||||
Main.flyingCarpetTexture = carpetOriginal;
|
||||
GeneralParticleHandler.Unload();
|
||||
}
|
||||
Mount.mounts[Mount.Unicorn].dashSpeed /= CalamityPlayer.UnicornSpeedNerfPower;
|
||||
Mount.mounts[Mount.Unicorn].runSpeed /= CalamityPlayer.UnicornSpeedNerfPower;
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace CalamityMod.ILEditing
|
||||
IL.Terraria.Player.AddBuff += AllowBuffTimeStackingForManaBurn;
|
||||
IL.Terraria.Main.DoDraw += DrawFusableParticles;
|
||||
IL.Terraria.Main.DoDraw += DrawAshParticles;
|
||||
On.Terraria.Main.DrawInterface += DrawGeneralParticles;
|
||||
On.Terraria.Main.SetDisplayMode += ResetRenderTargetSizes;
|
||||
IL.Terraria.Main.DrawTiles += DrawCustomLava;
|
||||
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += DrawCustomLava2;
|
||||
@@ -121,6 +122,7 @@ namespace CalamityMod.ILEditing
|
||||
IL.Terraria.Player.AddBuff -= AllowBuffTimeStackingForManaBurn;
|
||||
IL.Terraria.Main.DoDraw -= DrawFusableParticles;
|
||||
IL.Terraria.Main.DoDraw -= DrawAshParticles;
|
||||
On.Terraria.Main.DrawInterface -= DrawGeneralParticles;
|
||||
On.Terraria.Main.SetDisplayMode -= ResetRenderTargetSizes;
|
||||
IL.Terraria.Main.DrawTiles -= DrawCustomLava;
|
||||
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw -= DrawCustomLava2;
|
||||
|
||||
@@ -538,6 +538,18 @@ namespace CalamityMod.ILEditing
|
||||
}
|
||||
#endregion Ash Particle Rendering
|
||||
|
||||
#region General Particle Rendering
|
||||
private static void DrawParticles(On.Terraria.Main.orig_DrawInterface orig, Main self, GameTime gameTime)
|
||||
{
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, default, default, default, default, Main.GameViewMatrix.ZoomMatrix);
|
||||
GeneralParticleHandler.DrawAllParticles(Main.spriteBatch);
|
||||
Main.spriteBatch.End();
|
||||
|
||||
orig(self, gameTime);
|
||||
}
|
||||
|
||||
#endregion General Particle Rendering
|
||||
|
||||
#region Custom Lava Visuals
|
||||
private static void ResetRenderTargetSizes(On.Terraria.Main.orig_SetDisplayMode orig, int width, int height, bool fullscreen)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles
|
||||
{
|
||||
public static class GeneralParticleHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the maximum of particles allowed. Particles marked as important may replace nonimportant particles when the cap is reached
|
||||
/// </summary>
|
||||
// May be a good idea to make this into a config option
|
||||
private static readonly int particleCap = 500;
|
||||
|
||||
private static Particle[] particles;
|
||||
private static int nextVacantIndex;
|
||||
private static int activeParticles;
|
||||
//Static list for details concerning every particle type
|
||||
private static Dictionary<Type, int> particleTypes;
|
||||
private static Dictionary<int, Texture2D> particleTextures;
|
||||
private static List<Particle> particleInstances;
|
||||
//Lists used when drawing particles batched
|
||||
private static List<Particle> batchedAlphaBlendParticles;
|
||||
private static List<Particle> batchedAdditiveBlendParticles;
|
||||
|
||||
internal static void Load()
|
||||
{
|
||||
particles = new Particle[particleCap];
|
||||
particleTypes = new Dictionary<Type, int>();
|
||||
particleTextures = new Dictionary<int, Texture2D>();
|
||||
particleInstances = new List<Particle>();
|
||||
|
||||
batchedAlphaBlendParticles = new List<Particle>(particleCap);
|
||||
batchedAdditiveBlendParticles = new List<Particle>(particleCap);
|
||||
|
||||
Type baseParticleType = typeof(Particle);
|
||||
CalamityMod calamity = ModContent.GetInstance<CalamityMod>();
|
||||
|
||||
foreach (Type type in calamity.Code.GetTypes())
|
||||
{
|
||||
if (type.IsSubclassOf(baseParticleType) && !type.IsAbstract && type != baseParticleType)
|
||||
{
|
||||
int ID = particleTypes.Count; //Get the ID of the particle
|
||||
particleTypes[type] = ID;
|
||||
|
||||
Particle instance = (Particle)FormatterServices.GetUninitializedObject(type);
|
||||
particleInstances.Add(instance);
|
||||
|
||||
string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name;
|
||||
if (instance.Texture != "")
|
||||
texturePath = instance.Texture;
|
||||
particleTextures[ID] = ModContent.GetTexture(texturePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Unload()
|
||||
{
|
||||
particles = null;
|
||||
particleTypes = null;
|
||||
particleTextures = null;
|
||||
particleInstances = null;
|
||||
batchedAlphaBlendParticles = null;
|
||||
batchedAdditiveBlendParticles = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Spawns the particle instance provided into the world. If the particle limit is reached but the particle is marked as important, it will try to replace a non important particle.
|
||||
/// </summary>
|
||||
public static void SpawnParticle(Particle particle)
|
||||
{
|
||||
if (activeParticles == particleCap && !particle.Important)
|
||||
return;
|
||||
|
||||
particles[nextVacantIndex] = particle;
|
||||
particle.ID = nextVacantIndex;
|
||||
particle.Type = particleTypes[particle.GetType()];
|
||||
|
||||
if (nextVacantIndex + 1 < particles.Length && particles[nextVacantIndex + 1] == null)
|
||||
nextVacantIndex++;
|
||||
else
|
||||
for (int i = 0; i < particles.Length; i++)
|
||||
if (particles[i] == null)
|
||||
nextVacantIndex = i;
|
||||
|
||||
activeParticles++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ namespace CalamityMod.Particles
|
||||
public int Variant;
|
||||
public float Scale;
|
||||
public Vector2 RelativeOffset;
|
||||
public virtual string Texture => "";
|
||||
|
||||
public Particle(int lifetime, Vector2 relativeOffset, float scale, int variant = 0)
|
||||
{
|
||||
Time = 0;
|
||||
|
||||
Reference in new issue
Block a user