WIP Make networking code thread-safe and refactor update ID

Replaces direct increments of LastClientListUpdateID with a thread-safe IncrementLastClientListUpdateID method and uses Interlocked for atomic operations. Refactors EntitySpawner to lock access to the spawn/remove queue for thread safety. Updates INetSerializableStruct to use concurrent collections for cached variables and type behaviors, improving thread safety in networking code.
This commit is contained in:
Eero
2025-12-28 13:10:17 +08:00
parent 31812d524d
commit c5fa49405f
8 changed files with 111 additions and 51 deletions
@@ -62,7 +62,7 @@ namespace Barotrauma.Networking
DebugConsole.Log($"Changed client {Name}'s team to {teamID}.");
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.LastClientListUpdateID++;
GameMain.NetworkMember.IncrementLastClientListUpdateID();
}
teamID = value;
}
@@ -86,7 +86,7 @@ namespace Barotrauma.Networking
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.LastClientListUpdateID++;
GameMain.NetworkMember.IncrementLastClientListUpdateID();
if (value != null)
{
CharacterID = value.ID;
@@ -154,7 +154,7 @@ namespace Barotrauma.Networking
#endif
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.LastClientListUpdateID++;
GameMain.NetworkMember.IncrementLastClientListUpdateID();
}
}
}
@@ -178,7 +178,7 @@ namespace Barotrauma.Networking
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.LastClientListUpdateID++;
GameMain.NetworkMember.IncrementLastClientListUpdateID();
}
inGame = value;
}