Cleanup/Housekeeping (#242)
This commit is contained in:
parent
90ede0659f
commit
741e8d8300
228 changed files with 6292 additions and 2690 deletions
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* BinaryMemoryWriter.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace Server
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* DualSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System.Threading;
|
||||
|
||||
namespace Server
|
||||
|
|
@ -42,7 +22,9 @@ namespace Server
|
|||
|
||||
if (permitBackgroundWrite && UseSequentialWriters
|
||||
) // If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
{
|
||||
World.NotifyDiskWriteComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,4 @@
|
|||
/***************************************************************************
|
||||
* DynamicSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : December 16, 2010
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -137,7 +117,10 @@ namespace Server
|
|||
writer.QueueForIndex(item, size);
|
||||
|
||||
if (item.Decays && item.Parent == null && item.Map != Map.Internal &&
|
||||
DateTime.UtcNow > item.LastMoved + item.DecayTime) _decayBag.Add(item);
|
||||
DateTime.UtcNow > item.LastMoved + item.DecayTime)
|
||||
{
|
||||
_decayBag.Add(item);
|
||||
}
|
||||
|
||||
return writer;
|
||||
},
|
||||
|
|
@ -230,8 +213,12 @@ namespace Server
|
|||
public override void ProcessDecay()
|
||||
{
|
||||
while (_decayBag.TryTake(out var item))
|
||||
{
|
||||
if (item.OnDecay())
|
||||
{
|
||||
item.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenFiles()
|
||||
|
|
@ -287,7 +274,10 @@ namespace Server
|
|||
|
||||
bfw.Write(types.Count);
|
||||
|
||||
foreach (var type in types) bfw.Write(type.FullName);
|
||||
foreach (var type in types)
|
||||
{
|
||||
bfw.Write(type.FullName);
|
||||
}
|
||||
|
||||
bfw.Flush();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* FileOperations.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System.IO;
|
||||
|
||||
#if WINDOWS
|
||||
|
|
@ -48,7 +28,9 @@ namespace Server
|
|||
var options = FileOptions.SequentialScan;
|
||||
|
||||
if (Concurrency > 0)
|
||||
{
|
||||
options |= FileOptions.Asynchronous;
|
||||
}
|
||||
|
||||
#if !WINDOWS
|
||||
return new FileStream(path, mode, access, share, BufferSize, options);
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* FileQueue.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -47,11 +27,16 @@ namespace Server
|
|||
|
||||
public FileQueue(int concurrentWrites, FileCommitCallback callback)
|
||||
{
|
||||
if (concurrentWrites < 1) throw new ArgumentOutOfRangeException(nameof(concurrentWrites));
|
||||
if (concurrentWrites < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(concurrentWrites));
|
||||
}
|
||||
|
||||
if (bufferSize < 1)
|
||||
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(FileOperations.BufferSize));
|
||||
}
|
||||
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
|
||||
|
||||
syncRoot = new object();
|
||||
|
|
@ -79,11 +64,15 @@ namespace Server
|
|||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (activeCount == 0) idle.Reset();
|
||||
if (activeCount == 0)
|
||||
{
|
||||
idle.Reset();
|
||||
}
|
||||
|
||||
++activeCount;
|
||||
|
||||
for (var slot = 0; slot < active.Length; ++slot)
|
||||
{
|
||||
if (active[slot] == null)
|
||||
{
|
||||
active[slot] = new Chunk(this, slot, page.buffer, 0, page.length);
|
||||
|
|
@ -92,6 +81,7 @@ namespace Server
|
|||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pending.Enqueue(page);
|
||||
}
|
||||
|
|
@ -111,15 +101,15 @@ namespace Server
|
|||
if (pending.Count > 0 ) {
|
||||
idle.Reset();
|
||||
}
|
||||
|
||||
|
||||
for ( int slot = 0; slot < active.Length && pending.Count > 0; ++slot ) {
|
||||
if (active[slot] == null ) {
|
||||
Page page = pending.Dequeue();
|
||||
|
||||
|
||||
active[slot] = new Chunk( this, slot, page.buffer, 0, page.length );
|
||||
|
||||
|
||||
++activeCount;
|
||||
|
||||
|
||||
callback( active[slot] );
|
||||
}
|
||||
}
|
||||
|
|
@ -130,11 +120,17 @@ namespace Server
|
|||
|
||||
private void Commit(Chunk chunk, int slot)
|
||||
{
|
||||
if (slot < 0 || slot >= active.Length) throw new ArgumentOutOfRangeException(nameof(slot));
|
||||
if (slot < 0 || slot >= active.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(slot));
|
||||
}
|
||||
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (active[slot] != chunk) throw new ArgumentException("active slot is not the current chunk");
|
||||
if (active[slot] != chunk)
|
||||
{
|
||||
throw new ArgumentException("active slot is not the current chunk");
|
||||
}
|
||||
|
||||
ArrayPool<byte>.Shared.Return(chunk.Buffer);
|
||||
|
||||
|
|
@ -153,17 +149,34 @@ namespace Server
|
|||
|
||||
--activeCount;
|
||||
|
||||
if (activeCount == 0) idle.Set();
|
||||
if (activeCount == 0)
|
||||
{
|
||||
idle.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Enqueue(byte[] buffer, int offset, int size)
|
||||
{
|
||||
if (buffer == null) throw new ArgumentNullException(nameof(buffer));
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
if (size < 0) throw new ArgumentOutOfRangeException(nameof(size));
|
||||
if (buffer.Length - offset < size) throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
if (offset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
}
|
||||
|
||||
if (size < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(size));
|
||||
}
|
||||
|
||||
if (buffer.Length - offset < size)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
}
|
||||
|
||||
Position += size;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* ParallelSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -77,14 +57,23 @@ namespace Server
|
|||
|
||||
consumers = new Consumer[GetThreadCount()];
|
||||
|
||||
for (var i = 0; i < consumers.Length; ++i) consumers[i] = new Consumer(this, 256);
|
||||
for (var i = 0; i < consumers.Length; ++i)
|
||||
{
|
||||
consumers[i] = new Consumer(this, 256);
|
||||
}
|
||||
|
||||
IEnumerable<ISerializable> collection = new Producer();
|
||||
|
||||
foreach (var value in collection)
|
||||
{
|
||||
while (!Enqueue(value))
|
||||
{
|
||||
if (!Commit())
|
||||
{
|
||||
Thread.Sleep(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finished = true;
|
||||
|
||||
|
|
@ -108,7 +97,10 @@ namespace Server
|
|||
{
|
||||
var item = _decayQueue.Dequeue();
|
||||
|
||||
if (item.OnDecay()) item.Delete();
|
||||
if (item.OnDecay())
|
||||
{
|
||||
item.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +116,10 @@ namespace Server
|
|||
|
||||
bfw.Write(types.Count);
|
||||
|
||||
foreach (var type in types) bfw.Write(type.FullName);
|
||||
foreach (var type in types)
|
||||
{
|
||||
bfw.Write(type.FullName);
|
||||
}
|
||||
|
||||
bfw.Flush();
|
||||
|
||||
|
|
@ -179,11 +174,17 @@ namespace Server
|
|||
var writer = entry.writer;
|
||||
|
||||
if (value is Item item)
|
||||
{
|
||||
Save(item, writer);
|
||||
}
|
||||
else if (value is Mobile mob)
|
||||
{
|
||||
Save(mob, writer);
|
||||
}
|
||||
else if (value is BaseGuild guild)
|
||||
{
|
||||
Save(guild, writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void Save(Item item, BinaryMemoryWriter writer)
|
||||
|
|
@ -191,7 +192,10 @@ namespace Server
|
|||
writer.CommitTo(itemData, itemIndex, item.TypeRef, item.Serial);
|
||||
|
||||
if (item.Decays && item.Parent == null && item.Map != Map.Internal &&
|
||||
DateTime.UtcNow > item.LastMoved + item.DecayTime) _decayQueue.Enqueue(item);
|
||||
DateTime.UtcNow > item.LastMoved + item.DecayTime)
|
||||
{
|
||||
_decayQueue.Enqueue(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void Save(Mobile mob, BinaryMemoryWriter writer)
|
||||
|
|
@ -273,11 +277,20 @@ namespace Server
|
|||
|
||||
public IEnumerator<ISerializable> GetEnumerator()
|
||||
{
|
||||
foreach (var item in items) yield return item;
|
||||
foreach (var item in items)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
|
||||
foreach (var mob in mobiles) yield return mob;
|
||||
foreach (var mob in mobiles)
|
||||
{
|
||||
yield return mob;
|
||||
}
|
||||
|
||||
foreach (var guild in guilds) yield return guild;
|
||||
foreach (var guild in guilds)
|
||||
{
|
||||
yield return guild;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
|
||||
|
|
@ -305,7 +318,10 @@ namespace Server
|
|||
|
||||
buffer = new ConsumableEntry[bufferSize];
|
||||
|
||||
for (var i = 0; i < buffer.Length; ++i) buffer[i].writer = new BinaryMemoryWriter();
|
||||
for (var i = 0; i < buffer.Length; ++i)
|
||||
{
|
||||
buffer[i].writer = new BinaryMemoryWriter();
|
||||
}
|
||||
|
||||
completionEvent = new ManualResetEvent(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: Persistence.cs *
|
||||
* *
|
||||
|
|
@ -30,9 +30,14 @@ namespace Server
|
|||
file.Refresh();
|
||||
|
||||
if (file.Directory?.Exists == false)
|
||||
{
|
||||
file.Directory.Create();
|
||||
}
|
||||
|
||||
if (!file.Exists) file.Create().Close();
|
||||
if (!file.Exists)
|
||||
{
|
||||
file.Create().Close();
|
||||
}
|
||||
|
||||
file.Refresh();
|
||||
|
||||
|
|
@ -72,7 +77,9 @@ namespace Server
|
|||
if (file.Directory?.Exists == false)
|
||||
{
|
||||
if (!ensure)
|
||||
{
|
||||
throw new DirectoryNotFoundException();
|
||||
}
|
||||
|
||||
file.Directory.Create();
|
||||
}
|
||||
|
|
@ -80,10 +87,12 @@ namespace Server
|
|||
if (!file.Exists)
|
||||
{
|
||||
if (!ensure)
|
||||
{
|
||||
throw new FileNotFoundException
|
||||
{
|
||||
Source = file.FullName
|
||||
};
|
||||
}
|
||||
|
||||
file.Create().Close();
|
||||
}
|
||||
|
|
@ -99,7 +108,10 @@ namespace Server
|
|||
}
|
||||
catch (EndOfStreamException eos)
|
||||
{
|
||||
if (file.Length > 0) Console.WriteLine("[Persistence]: {0}", eos);
|
||||
if (file.Length > 0)
|
||||
{
|
||||
Console.WriteLine("[Persistence]: {0}", eos);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* QueuedMemoryWriter.cs
|
||||
* -------------------
|
||||
* begin : December 16, 2010
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* SaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public abstract class SaveStrategy
|
||||
|
|
@ -31,8 +11,10 @@ namespace Server
|
|||
var processorCount = Core.ProcessorCount;
|
||||
|
||||
if (processorCount > 2)
|
||||
{
|
||||
return
|
||||
new DualSaveStrategy(); // return new DynamicSaveStrategy(); (4.0 or return new ParallelSaveStrategy(processorCount); (2.0)
|
||||
}
|
||||
|
||||
return new DualSaveStrategy();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* SequentialFileWriter.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
|
|
@ -32,7 +12,10 @@ namespace Server
|
|||
|
||||
public SequentialFileWriterStream(string path)
|
||||
{
|
||||
if (path == null) throw new ArgumentNullException(nameof(path));
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
fileStream = FileOperations.OpenSequentialStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* StandardSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -60,7 +40,9 @@ namespace Server
|
|||
|
||||
if (permitBackgroundWrite && UseSequentialWriters
|
||||
) // If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
{
|
||||
World.NotifyDiskWriteComplete();
|
||||
}
|
||||
}
|
||||
|
||||
protected void SaveMobiles()
|
||||
|
|
@ -90,7 +72,9 @@ namespace Server
|
|||
tdb.Write(World.m_MobileTypes.Count);
|
||||
|
||||
for (var i = 0; i < World.m_MobileTypes.Count; ++i)
|
||||
{
|
||||
tdb.Write(World.m_MobileTypes[i].FullName);
|
||||
}
|
||||
|
||||
tdb.Close();
|
||||
}
|
||||
|
|
@ -151,7 +135,9 @@ namespace Server
|
|||
tdb.Write(World.m_ItemTypes.Count);
|
||||
|
||||
for (var i = 0; i < World.m_ItemTypes.Count; ++i)
|
||||
{
|
||||
tdb.Write(World.m_ItemTypes[i].FullName);
|
||||
}
|
||||
|
||||
tdb.Close();
|
||||
}
|
||||
|
|
@ -243,7 +229,9 @@ namespace Server
|
|||
var item = _decayQueue.Dequeue();
|
||||
|
||||
if (item.OnDecay())
|
||||
{
|
||||
item.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue