fix: Adds AfterSerialize support. Removes BeforeSerialize support. (#1208)
### Changes * Implements an AfterSerialize method that is executed synchronously. * Removes `BeforeSerialize` support since it was dangerous in its current implementation. * Moves PlayerMobile kill/virtual decay to AfterSerialize. * Adds kill decay to after Deserialize.
This commit is contained in:
parent
deabab575a
commit
49e6c6f2d1
13 changed files with 132 additions and 61 deletions
|
|
@ -44,6 +44,7 @@ public static class World
|
|||
private static Dictionary<Serial, IEntity> _pendingAdd = new();
|
||||
private static Dictionary<Serial, IEntity> _pendingDelete = new();
|
||||
private static ConcurrentQueue<Item> _decayQueue = new();
|
||||
private static ConcurrentQueue<ISerializable> _afterSerializeEntities = new();
|
||||
|
||||
private static string _tempSavePath; // Path to the temporary folder for the save
|
||||
private static bool _enableSaveStats;
|
||||
|
|
@ -147,7 +148,7 @@ public static class World
|
|||
_enableSaveStats = ServerConfiguration.GetOrUpdateSetting("world.enableSaveStats", false);
|
||||
|
||||
// Mobiles & Items
|
||||
Persistence.Register("Mobiles & Items", SaveEntities, WriteEntities, LoadEntities, 1);
|
||||
Persistence.Register("Mobiles & Items", SaveEntities, WriteEntities, LoadEntities, AfterSerialize, 1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
@ -168,6 +169,9 @@ public static class World
|
|||
_decayQueue.Enqueue(item);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void EnqueueAfterSerialization(ISerializable entity) => _afterSerializeEntities.Enqueue(entity);
|
||||
|
||||
public static void Broadcast(int hue, bool ascii, string text)
|
||||
{
|
||||
var length = OutgoingMessagePackets.GetMaxMessageLength(text);
|
||||
|
|
@ -495,7 +499,15 @@ public static class World
|
|||
*/
|
||||
public static ConcurrentQueue<Type> SerializedTypes { get; } = new();
|
||||
|
||||
internal static void SaveEntities()
|
||||
private static void AfterSerialize()
|
||||
{
|
||||
while (_afterSerializeEntities.TryDequeue(out var entity))
|
||||
{
|
||||
entity.AfterSerialize();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveEntities()
|
||||
{
|
||||
_serializationStart = DateTime.UtcNow;
|
||||
EntityPersistence.SaveEntities(Items.Values, SaveEntity);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue