fix(codegen): Adds manual dirty checking (#621)

- Adds `[ManualDirtyChecking]` for anyone that adds it themselves.
- Adds detection of `[Serializable]` and `[ManualDirtyChecking]` at startup to help identify scripts that need migration.
This commit is contained in:
Kamron Batman 2021-05-27 00:54:21 -07:00 committed by GitHub
parent 90dc5e742c
commit 81e4087acc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 79 additions and 53 deletions

View file

@ -20,10 +20,6 @@ namespace Server
{
public interface ISerializable
{
// Make sure all properties that will be serialized are calling `MarkDirty()` when they get modified.
// This should be done manually or via code gen through SerializedField attribute.
// This attribute should be virtual for any base serializalbe type (Item, Mobile, etc) that can be opt-in per type.
bool UseDirtyChecking { get; }
long SavePosition { get; protected set; }
BufferWriter SaveBuffer { get; protected internal set; }
int TypeRef { get; }
@ -43,7 +39,7 @@ namespace Server
public void InitializeSaveBuffer(byte[] buffer)
{
SaveBuffer = new BufferWriter(buffer, true);
if (UseDirtyChecking)
if (World.DirtyTrackingEnabled)
{
SavePosition = SaveBuffer.Position;
}
@ -67,7 +63,7 @@ namespace Server
SaveBuffer.Seek(0, SeekOrigin.Begin);
Serialize(SaveBuffer);
if (UseDirtyChecking)
if (World.DirtyTrackingEnabled)
{
SavePosition = SaveBuffer.Position;
}

View file

@ -0,0 +1,28 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2021 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: ManualDirtyChecking.cs *
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
namespace Server
{
/// <summary>
/// Indicates that the applied class has dirty checking. This is necessary for classes that are not code genned.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class ManualDirtyCheckingAttribute : Attribute
{
}
}