Skip to content

added registration for nested SyncableFields #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

CoreAidan
Copy link

Added the ability for the EntityClassData constructor to find and register nested SyncableFields and their SyncVars

Since reference types are stored in the parent object as a pointer to a separately‐allocated object I've created a map that allows for chaining to the target offset.

NOTE: this is just a rough pass idea that is not final. while it does work I don't know much about optimizations. I more or less want to get your opinion as I know the multiple calls to traverse the object is a bit much I couldn't think of another way. Though as I mention it does seem to work, but was not thoroughly test.

internal struct SyncableFieldInfo
{
    public readonly string Name;

    public readonly int[] Offsets;

    public readonly SyncFlags Flags;

    public ushort RPCOffset;

    public SyncableFieldInfo(string name, int[] offsets, SyncFlags flags)
    {
        Name = name;
        Offsets = offsets;
        Flags = flags;
        RPCOffset = ushort.MaxValue;
    }
}
internal static SyncVar<T> GetSyncableSyncVar<T>(InternalBaseClass baseClass, int[] offsets) where T : unmanaged
{
    InternalBaseClass syncable = baseClass;
    for (int i = 0; i < offsets.Length-1; i++)
    {
        syncable = RefMagic.RefFieldValue<InternalBaseClass>(syncable, offsets[i]);
        if (syncable == null)
            throw new NullReferenceException($"SyncableField at offset {offsets[i]} is null");
    }
    ref var a = ref RefMagic.RefFieldValue<SyncVar<T>>(syncable, offsets[offsets.Length-1]);

    return a;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant