From 5be90584b60c60f633effe0ba7f2d1f56c40587f Mon Sep 17 00:00:00 2001 From: krrios Date: Fri, 20 Apr 2007 22:35:41 +0000 Subject: [PATCH] Fixed issue with decay erroneously triggering world save warnings. --- Server/Persistence/ParallelSaveStrategy.cs | 22 +++++++++---------- Server/Persistence/SaveStrategy.cs | 2 ++ Server/Persistence/StandardSaveStrategy.cs | 25 ++++++++++++++-------- Server/World.cs | 3 +++ 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Server/Persistence/ParallelSaveStrategy.cs b/Server/Persistence/ParallelSaveStrategy.cs index aa777de67..53666b99b 100644 --- a/Server/Persistence/ParallelSaveStrategy.cs +++ b/Server/Persistence/ParallelSaveStrategy.cs @@ -39,6 +39,8 @@ namespace Server { public ParallelSaveStrategy( int processorCount ) { this.processorCount = processorCount; + + _decayQueue = new Queue(); } private int GetThreadCount() { @@ -51,7 +53,7 @@ namespace Server { private SequentialFileWriter mobileData, mobileIndex; private SequentialFileWriter guildData, guildIndex; - private List decaying; + private Queue _decayQueue; private Consumer[] consumers; private int cycle; @@ -95,12 +97,14 @@ namespace Server { Commit(); CloseFiles(); + } - if ( decaying != null ) { - foreach ( Item item in decaying ) { - if ( item.OnDecay() ) { - item.Delete(); - } + public override void ProcessDecay() { + while ( _decayQueue.Count > 0 ) { + Item item = _decayQueue.Dequeue(); + + if ( item.OnDecay() ) { + item.Delete(); } } } @@ -192,11 +196,7 @@ namespace Server { } if ( item.Decays && item.Parent == null && item.Map != Map.Internal && DateTime.Now > ( item.LastMoved + item.DecayTime ) ) { - if ( decaying == null ) { - decaying = new List(); - } - - decaying.Add( item ); + _decayQueue.Enqueue( item ); } } diff --git a/Server/Persistence/SaveStrategy.cs b/Server/Persistence/SaveStrategy.cs index 87c85da15..012d88e51 100644 --- a/Server/Persistence/SaveStrategy.cs +++ b/Server/Persistence/SaveStrategy.cs @@ -46,5 +46,7 @@ namespace Server { public abstract string Name { get; } public abstract void Save( SaveMetrics metrics ); + + public abstract void ProcessDecay(); } } \ No newline at end of file diff --git a/Server/Persistence/StandardSaveStrategy.cs b/Server/Persistence/StandardSaveStrategy.cs index e7a8a6594..171f0e028 100644 --- a/Server/Persistence/StandardSaveStrategy.cs +++ b/Server/Persistence/StandardSaveStrategy.cs @@ -34,7 +34,10 @@ namespace Server { get { return "Standard"; } } + private Queue _decayQueue; + public StandardSaveStrategy() { + _decayQueue = new Queue(); } public override void Save( SaveMetrics metrics ) { @@ -109,8 +112,9 @@ namespace Server { idx.Write( ( int ) items.Count ); foreach ( Item item in items.Values ) { - if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) - decaying.Add( item ); + if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) { + _decayQueue.Enqueue( item ); + } long start = bin.Position; @@ -136,13 +140,6 @@ namespace Server { idx.Close(); tdb.Close(); bin.Close(); - - for ( int i = 0; i < decaying.Count; ++i ) { - Item item = decaying[i]; - - if ( item.OnDecay() ) - item.Delete(); - } } protected void SaveGuilds( SaveMetrics metrics ) { @@ -177,5 +174,15 @@ namespace Server { idx.Close(); bin.Close(); } + + public override void ProcessDecay() { + while ( _decayQueue.Count > 0 ) { + Item item = _decayQueue.Dequeue(); + + if ( item.OnDecay() ) { + item.Delete(); + } + } + } } } \ No newline at end of file diff --git a/Server/World.cs b/Server/World.cs index ece3408e0..9adce52d1 100644 --- a/Server/World.cs +++ b/Server/World.cs @@ -787,8 +787,11 @@ namespace Server { watch.Stop(); m_Saving = false; + ProcessSafetyQueues(); + strategy.ProcessDecay(); + Console.WriteLine( "done in {0:F2} seconds.", watch.Elapsed.TotalSeconds ); if ( message )