Skip to content

Commit

Permalink
immutable entry for IReadOnlyEntityParticipantTable
Browse files Browse the repository at this point in the history
  • Loading branch information
NickKhalow committed Dec 18, 2024
1 parent 4a04f06 commit 7e3dcb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ public void Register(string walletId, Entity entity, RoomSource fromRoom)
public void AddRoomSource(string walletId, RoomSource fromRoom)
{
IReadOnlyEntityParticipantTable.Entry entry = walletIdToEntity[walletId];
entry.ConnectedTo |= fromRoom;
walletIdToEntity[walletId] = entry;
walletIdToEntity[walletId] = entry.WithRoomSource(fromRoom);
}

public bool Release(string walletId, RoomSource fromRoom)
{
IReadOnlyEntityParticipantTable.Entry entry = walletIdToEntity[walletId];

entry.ConnectedTo.RemoveFlag(fromRoom);
entry = entry.WithoutRoomSource(fromRoom);

if (entry.ConnectedTo == RoomSource.NONE)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
using Arch.Core;
using DCL.Multiplayer.Connections.Rooms;
using DCL.Multiplayer.Profiles.Entities;
using System.Collections.Generic;
using Utility;

namespace DCL.Multiplayer.Profiles.Tables
{
public interface IReadOnlyEntityParticipantTable
{
public struct Entry
public readonly struct Entry
{
public string WalletId;
public Entity Entity;
public RoomSource ConnectedTo;
public readonly string WalletId;
public readonly Entity Entity;
public readonly RoomSource ConnectedTo;

internal Entry(string walletId, Entity entity, RoomSource connectedTo)
{
WalletId = walletId;
Entity = entity;
ConnectedTo = connectedTo;
}

public Entry WithRoomSource(RoomSource fromRoom) =>
new (WalletId, Entity, ConnectedTo | fromRoom);

public Entry WithoutRoomSource(RoomSource fromRoom)
{
RoomSource newRoomSource = ConnectedTo;
newRoomSource.RemoveFlag(fromRoom);
return new Entry(WalletId, Entity, newRoomSource);
}
}

int Count { get; }
Expand Down

0 comments on commit 7e3dcb8

Please sign in to comment.