Skip to content

Commit 5ae2649

Browse files
committed
Introduce Self-Mirroring in development mode
Signed-off-by: Mikhail Agapov <mikhail.agapov@decentraland.org>
1 parent 6f77812 commit 5ae2649

File tree

6 files changed

+306
-6
lines changed

6 files changed

+306
-6
lines changed

src/DCLPulse/DCLPulse.sln.DotSettings.user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIMessage_00601_002Ecs_002Fl_003AC_0021_003FUsers_003Fagapo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8ac5df484cef4ddabb15fdcaf03dc5076a118_003F0e_003F0c2692d4_003FIMessage_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
99
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALogger_00601_002Ecs_002Fl_003AC_0021_003FUsers_003Fagapo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F436aa929069b4451a1f15ef16423b31810708_003F34_003Fc52369b4_003FLogger_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1010
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AServiceCollectionServiceExtensions_002Ecs_002Fl_003AC_0021_003FUsers_003Fagapo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F6aa57ddeb02b4bef8365bcdc6f7c52dd10338_003F00_003F243b1034_003FServiceCollectionServiceExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
11+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector3_002Ecs_002Fl_003AC_0021_003FUsers_003Fagapo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fd2fc4e5236f74a0d8789f902be54d3bbf48938_003Fb0_003F90f6c211_003FVector3_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1112
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">Code Style Reformat DCL</s:String>
1213
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=70eda9a7_002D816d_002D4cde_002D89b3_002D0c64dd72a349/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;DCLPulseTests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
1314
&lt;Project Location="/Users/nicolas.lorusso/Documents/workspace/Pulse/src/DCLPulseTests" Presentation="&amp;lt;DCLPulseTests&amp;gt;" /&gt;

src/DCLPulse/Peers/PeerOptions.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Pulse.Peers;
1+
using Pulse.Peers.Simulation;
2+
3+
namespace Pulse.Peers;
24

35
public sealed class PeerOptions
46
{
@@ -10,4 +12,15 @@ public sealed class PeerOptions
1012
/// Simulation steps in milliseconds for tiers
1113
/// </summary>
1214
public uint[] SimulationSteps { get; set; } = new[] { 50u, 100u, 200u };
15+
16+
/// <summary>
17+
/// When enabled, each peer receives its own state updates as if from another peer
18+
/// identified by <see cref="PeerSimulation.SELF_MIRROR_WALLET_ID" />.
19+
/// </summary>
20+
public bool SelfMirrorEnabled { get; set; }
21+
22+
/// <summary>
23+
/// Tier index (0, 1, 2) used for self-mirror updates, controlling update frequency and field detail.
24+
/// </summary>
25+
public int SelfMirrorTier { get; set; }
1326
}

src/DCLPulse/Peers/PeersManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
106106
{
107107
var simulation = new PeerSimulation(
108108
areaOfInterest, snapshotBoard, spatialGrid, identityBoard,
109-
messagePipe, peerOptions.SimulationSteps, timeProvider, transport, profileBoard, emoteBoard, peerSimulationLogger);
109+
messagePipe, peerOptions.SimulationSteps, timeProvider, transport, profileBoard, emoteBoard, peerSimulationLogger,
110+
peerOptions.SelfMirrorEnabled, peerOptions.SelfMirrorTier);
110111

111112
tasks[i + 1] = WorkerAsync(i, messageChannels[i].Reader,
112113
peerLifeCycleChannels[i].Reader, simulation, stoppingToken);

src/DCLPulse/Peers/Simulation/PeerSimulation.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public sealed class PeerSimulation : IPeerSimulation
2222
private const uint PEER_DISCONNECTION_CLEAN_TIMEOUT = 5000;
2323
private const uint PEER_PENDING_AUTH_CLEAN_TIMEOUT = 30000;
2424

25+
public const string SELF_MIRROR_WALLET_ID = "self_mirror";
26+
2527
private readonly IAreaOfInterest areaOfInterest;
2628
private readonly SnapshotBoard snapshotBoard;
2729
private readonly SpatialGrid spatialGrid;
@@ -33,6 +35,8 @@ public sealed class PeerSimulation : IPeerSimulation
3335
private readonly ProfileBoard profileBoard;
3436
private readonly EmoteBoard emoteBoard;
3537
private readonly ILogger<PeerSimulation> logger;
38+
private readonly bool selfMirrorEnabled;
39+
private readonly PeerViewSimulationTier selfMirrorTier;
3640

3741
/// <summary>
3842
/// Per-observer views: observer PeerIndex → (subject PeerIndex → view).
@@ -71,7 +75,9 @@ public PeerSimulation(
7175
ITransport transport,
7276
ProfileBoard profileBoard,
7377
EmoteBoard emoteBoard,
74-
ILogger<PeerSimulation> logger)
78+
ILogger<PeerSimulation> logger,
79+
bool selfMirrorEnabled = false,
80+
int selfMirrorTier = 0)
7581
{
7682
this.areaOfInterest = areaOfInterest;
7783
this.snapshotBoard = snapshotBoard;
@@ -84,6 +90,8 @@ public PeerSimulation(
8490
this.profileBoard = profileBoard;
8591
this.emoteBoard = emoteBoard;
8692
this.logger = logger;
93+
this.selfMirrorEnabled = selfMirrorEnabled;
94+
this.selfMirrorTier = new PeerViewSimulationTier((byte)selfMirrorTier);
8795

8896
BaseTickMs = simulationSteps[0];
8997
tierDivisors = new uint[simulationSteps.Length];
@@ -145,6 +153,9 @@ public void SimulateTick(Dictionary<PeerIndex, PeerState> peers, uint tickCounte
145153
collector.Clear();
146154
areaOfInterest.GetVisibleSubjects(observerId, in observerSnapshot, collector);
147155

156+
if (selfMirrorEnabled)
157+
collector.Add(observerId, selfMirrorTier);
158+
148159
ProcessVisibleSubjects(observerId, views, observerState.ResyncRequests, tickCounter);
149160

150161
observerState.ResyncRequests?.Clear();
@@ -177,7 +188,9 @@ private void ProcessVisibleSubjects(
177188
{
178189
InterestEntry entry = collector.Entries[i];
179190

180-
if (entry.Subject == observerId)
191+
bool isSelfMirror = entry.Subject == observerId;
192+
193+
if (isSelfMirror && !selfMirrorEnabled)
181194
continue;
182195

183196
bool isNew = !views.TryGetValue(entry.Subject, out PeerToPeerView view);
@@ -213,11 +226,15 @@ private void ProcessVisibleSubjects(
213226

214227
int profileVersion = profileBoard.Get(entry.Subject);
215228

229+
string? userId = isSelfMirror
230+
? SELF_MIRROR_WALLET_ID
231+
: identityBoard.GetWalletIdByPeerIndex(entry.Subject);
232+
216233
messagePipe.Send(new OutgoingMessage(observerId, new ServerMessage
217234
{
218235
PlayerJoined = new PlayerJoined
219236
{
220-
UserId = identityBoard.GetWalletIdByPeerIndex(entry.Subject),
237+
UserId = userId,
221238
ProfileVersion = profileVersion,
222239
State = CreateFullState(entry.Subject, subjectSnapshot),
223240
},
@@ -277,7 +294,7 @@ void TryAnnounceProfile()
277294

278295
void SyncEmoteState()
279296
{
280-
// If the emote completion has not been process by the peer's worker yet, try to complete it now
297+
// If the emote completion has not been processed by the peer's worker yet, try to complete it now
281298
emoteBoard.TryComplete(entry.Subject, timeProvider.MonotonicTime);
282299

283300
EmoteState? emoteState = emoteBoard.Get(entry.Subject);

src/DCLPulse/appsettings.Development.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
"Default": "Information",
55
"Microsoft.Hosting.Lifetime": "Information"
66
}
7+
},
8+
"Peers": {
9+
"SelfMirrorEnabled": true,
10+
"SelfMirrorTier": 0
711
}
812
}

0 commit comments

Comments
 (0)