Fixed issue with decay erroneously triggering world save warnings.

This commit is contained in:
krrios 2007-04-20 22:35:41 +00:00
parent 0c7efa2419
commit 5be90584b6
4 changed files with 32 additions and 20 deletions

View file

@ -39,6 +39,8 @@ namespace Server {
public ParallelSaveStrategy( int processorCount ) { public ParallelSaveStrategy( int processorCount ) {
this.processorCount = processorCount; this.processorCount = processorCount;
_decayQueue = new Queue<Item>();
} }
private int GetThreadCount() { private int GetThreadCount() {
@ -51,7 +53,7 @@ namespace Server {
private SequentialFileWriter mobileData, mobileIndex; private SequentialFileWriter mobileData, mobileIndex;
private SequentialFileWriter guildData, guildIndex; private SequentialFileWriter guildData, guildIndex;
private List<Item> decaying; private Queue<Item> _decayQueue;
private Consumer[] consumers; private Consumer[] consumers;
private int cycle; private int cycle;
@ -95,12 +97,14 @@ namespace Server {
Commit(); Commit();
CloseFiles(); CloseFiles();
}
if ( decaying != null ) { public override void ProcessDecay() {
foreach ( Item item in decaying ) { while ( _decayQueue.Count > 0 ) {
if ( item.OnDecay() ) { Item item = _decayQueue.Dequeue();
item.Delete();
} 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 ( item.Decays && item.Parent == null && item.Map != Map.Internal && DateTime.Now > ( item.LastMoved + item.DecayTime ) ) {
if ( decaying == null ) { _decayQueue.Enqueue( item );
decaying = new List<Item>();
}
decaying.Add( item );
} }
} }

View file

@ -46,5 +46,7 @@ namespace Server {
public abstract string Name { get; } public abstract string Name { get; }
public abstract void Save( SaveMetrics metrics ); public abstract void Save( SaveMetrics metrics );
public abstract void ProcessDecay();
} }
} }

View file

@ -34,7 +34,10 @@ namespace Server {
get { return "Standard"; } get { return "Standard"; }
} }
private Queue<Item> _decayQueue;
public StandardSaveStrategy() { public StandardSaveStrategy() {
_decayQueue = new Queue<Item>();
} }
public override void Save( SaveMetrics metrics ) { public override void Save( SaveMetrics metrics ) {
@ -109,8 +112,9 @@ namespace Server {
idx.Write( ( int ) items.Count ); idx.Write( ( int ) items.Count );
foreach ( Item item in items.Values ) { foreach ( Item item in items.Values ) {
if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) {
decaying.Add( item ); _decayQueue.Enqueue( item );
}
long start = bin.Position; long start = bin.Position;
@ -136,13 +140,6 @@ namespace Server {
idx.Close(); idx.Close();
tdb.Close(); tdb.Close();
bin.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 ) { protected void SaveGuilds( SaveMetrics metrics ) {
@ -177,5 +174,15 @@ namespace Server {
idx.Close(); idx.Close();
bin.Close(); bin.Close();
} }
public override void ProcessDecay() {
while ( _decayQueue.Count > 0 ) {
Item item = _decayQueue.Dequeue();
if ( item.OnDecay() ) {
item.Delete();
}
}
}
} }
} }

View file

@ -787,8 +787,11 @@ namespace Server {
watch.Stop(); watch.Stop();
m_Saving = false; m_Saving = false;
ProcessSafetyQueues(); ProcessSafetyQueues();
strategy.ProcessDecay();
Console.WriteLine( "done in {0:F2} seconds.", watch.Elapsed.TotalSeconds ); Console.WriteLine( "done in {0:F2} seconds.", watch.Elapsed.TotalSeconds );
if ( message ) if ( message )