DoubleDeez / MDFramework

A multiplayer C# game framework for Godot 3.4 Mono.
https://discord.gg/UH49eHK
MIT License
77 stars 13 forks source link

MDReplicatorNetworkKeyIdMap should consider things outside of session immutable #89

Closed Beider closed 3 years ago

Beider commented 3 years ago

Currently when the session ends we re-create the MDReplicatorNetworkKeyIdMap.

private void OnSessionEnded()
{
    NetworkIdKeyMap = new MDReplicatorNetworkKeyIdMap(ShouldShowBufferSize());
    KeyToMemberMap = new Dictionary<string, MDReplicatedMember>();
}

This has the problem that any node registered before the session (ie. autoload nodes or nodes that exist in the scene tree) will be wiped at this point as well. If another session is started later they will no longer be there and replication for these nodes will stop working.

The most sensible solution here is that the MDReplicatorNetworkKeyIdMap should treat anything registred outside of a session as immutable. Instead of recreating it on session end we should simply wipe it of everything that was not there when the session started.

Beider commented 3 years ago

Easier solution for this is just to never clear the map completely, just ensure nodes are removed properly when unregistered (they should be) and we don't need to clear the map.