Make ParticleManager an IGameComponent, remember to release native textures.

This commit is contained in:
UnknownShadow200 2016-05-13 16:26:31 +10:00
parent 03fab9182e
commit 21e8a34b36
4 changed files with 19 additions and 13 deletions

View File

@ -123,6 +123,7 @@ namespace ClassicalSharp.Gui {
posFont.Dispose();
fpsText.Dispose();
api.DeleteTexture( ref posTex );
hackStates.Dispose();
game.Events.ChatFontChanged -= ChatFontChanged;
}

View File

@ -120,6 +120,8 @@ namespace ClassicalSharp.Entities {
}
game.Events.ChatFontChanged -= ChatFontChanged;
game.Events.TextureChanged -= TextureChanged;
if( ShadowComponent.shadowTex > 0 )
game.Graphics.DeleteTexture( ref ShadowComponent.shadowTex );
}
public byte GetClosetPlayer( Player src ) {

View File

@ -67,7 +67,7 @@ namespace ClassicalSharp {
ETags.Load();
InputHandler = new InputHandler( this );
defaultIb = Graphics.MakeDefaultIb();
ParticleManager = new ParticleManager( this );
ParticleManager = AddComponent( new ParticleManager() );
LoadOptions();
LoadGuiOptions();
Chat = AddComponent( new Chat() );
@ -516,14 +516,11 @@ namespace ClassicalSharp {
public void Dispose() {
MapRenderer.Dispose();
MapBordersRenderer.Dispose();
EnvRenderer.Dispose();
SetNewScreen( null );
fpsScreen.Dispose();
TerrainAtlas.Dispose();
TerrainAtlas1D.Dispose();
ModelCache.Dispose();
ParticleManager.Dispose();
Players.Dispose();
WorldEvents.OnNewMap -= OnNewMapCore;
WorldEvents.OnNewMapLoaded -= OnNewMapLoadedCore;
@ -534,12 +531,13 @@ namespace ClassicalSharp {
if( activeScreen != null )
activeScreen.Dispose();
Graphics.DeleteIb( defaultIb );
Graphics.Dispose();
Drawer2D.DisposeInstance();
Graphics.DeleteTexture( ref CloudsTex );
Graphics.DeleteTexture( ref GuiTex );
Graphics.DeleteTexture( ref GuiClassicTex );
Graphics.DeleteTexture( ref IconsTex );
Graphics.Dispose();
foreach( WarningScreen screen in WarningOverlays )
screen.Dispose();

View File

@ -4,7 +4,7 @@ using ClassicalSharp.GraphicsAPI;
namespace ClassicalSharp.Particles {
public partial class ParticleManager : IDisposable {
public partial class ParticleManager : IGameComponent {
public int ParticlesTexId;
TerrainParticle[] terrainParticles = new TerrainParticle[maxParticles];
@ -17,12 +17,17 @@ namespace ClassicalSharp.Particles {
int vb;
const int maxParticles = 600;
public ParticleManager( Game game ) {
public void Init( Game game ) {
this.game = game;
vb = game.Graphics.CreateDynamicVb( VertexFormat.P3fT2fC4b, maxParticles * 4 );
game.Events.TerrainAtlasChanged += TerrainAtlasChanged;
}
public void Ready( Game game ) { }
public void Reset( Game game ) { rainCount = 0; terrainCount = 0; }
public void OnNewMap( Game game ) { rainCount = 0; terrainCount = 0; }
public void OnNewMapLoaded( Game game ) { }
void TerrainAtlasChanged( object sender, EventArgs e ) {
terrain1DCount = new int[game.TerrainAtlas1D.TexIds.Length];
terrain1DIndices = new int[game.TerrainAtlas1D.TexIds.Length];