Implemented proper disposal system and updated alongside RA.
This commit is contained in:
parent
8cf2fb5ae3
commit
2502556b33
@ -5,10 +5,12 @@ using RecrownedAthenaeum.Render;
|
|||||||
using RecrownedAthenaeum.UI.Modular;
|
using RecrownedAthenaeum.UI.Modular;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.Audio.Visualizer
|
namespace RhythmBullet.Audio.Visualizer
|
||||||
{
|
{
|
||||||
internal class HorizontalVisualizer : UIModule
|
internal class HorizontalVisualizer : UIModule, IDisposable
|
||||||
{
|
{
|
||||||
|
bool disposed;
|
||||||
|
private PrimitiveBatch primitiveBatch;
|
||||||
private RectangleRenderer renderer;
|
private RectangleRenderer renderer;
|
||||||
private const int BAR_COUNT = 70;
|
private const int BAR_COUNT = 70;
|
||||||
private const int SMOOTH_RANGE = 3;
|
private const int SMOOTH_RANGE = 3;
|
||||||
@ -27,12 +29,13 @@ namespace RecrownedAthenaeum.Audio.Visualizer
|
|||||||
|
|
||||||
binsPerBar = tsp.GetCurrentSpectrum().Length / BAR_COUNT;
|
binsPerBar = tsp.GetCurrentSpectrum().Length / BAR_COUNT;
|
||||||
barValue = new int[BAR_COUNT];
|
barValue = new int[BAR_COUNT];
|
||||||
|
primitiveBatch = new PrimitiveBatch(camera2D);
|
||||||
renderer = new RectangleRenderer(graphicsDevice, camera2D);
|
renderer = new RectangleRenderer(primitiveBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
if (disposed) throw new ObjectDisposedException(this.Name);
|
||||||
UpdateBars((float)gameTime.ElapsedGameTime.TotalSeconds);
|
UpdateBars((float)gameTime.ElapsedGameTime.TotalSeconds);
|
||||||
AverageBars();
|
AverageBars();
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
@ -40,6 +43,7 @@ namespace RecrownedAthenaeum.Audio.Visualizer
|
|||||||
|
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(SpriteBatch batch)
|
||||||
{
|
{
|
||||||
|
if (disposed) throw new ObjectDisposedException(this.Name);
|
||||||
for (int i = 0; i < BAR_COUNT; i++)
|
for (int i = 0; i < BAR_COUNT; i++)
|
||||||
{
|
{
|
||||||
bar.X = (i * (bar.Width + spaceBetweenBars)) + bounds.X;
|
bar.X = (i * (bar.Width + spaceBetweenBars)) + bounds.X;
|
||||||
@ -98,9 +102,24 @@ namespace RecrownedAthenaeum.Audio.Visualizer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (disposed) throw new ObjectDisposedException(this.Name);
|
||||||
|
Dispose(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && !disposed)
|
||||||
|
{
|
||||||
|
primitiveBatch.Dispose();
|
||||||
|
}
|
||||||
|
disposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
~HorizontalVisualizer()
|
~HorizontalVisualizer()
|
||||||
{
|
{
|
||||||
renderer.Dispose();
|
Dispose(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user