3 static const int REPLICATION_MAX_FRAME_BUDGET = 10;
4 static const int GRACEFUL_HANDLES_MAX_FRAME_BUDGET = 10;
8 protected ref array<ref SCR_ResourceSystemSubscriptionListing> m_aListings = {};
9 protected ref array<SCR_ResourceSystemSubscriptionHandleBase> m_aHandles = {};
10 protected ref array<ref SCR_ResourceSystemSubscriptionHandleBase> m_aGracefulHandles = {};
15 int higherLimitPosition = m_aListings.Count();
17 if (higherLimitPosition == 0)
23 while (
position < higherLimitPosition)
25 if (GetNextListingCandidate(
position, higherLimitPosition, listing, interactor))
31 && listing.GetInteractor() != interactor)
41 listing = m_aListings[comparePosition];
46 SCR_ResourceInteractor compareInteractor = listing.GetInteractor();
48 if (interactor > compareInteractor)
50 else if (interactor < compareInteractor)
51 higherLimitPosition = comparePosition;
54 listing = m_aListings[comparePosition];
67 int higherLimitPosition = m_aHandles.Count();
69 if (higherLimitPosition == 0)
75 while (
position < higherLimitPosition)
77 if (GetNextHandleCandidate(
position, higherLimitPosition, handle, resourceComponentRplId, interactorType, resourceType, resourceIdentifier))
83 && (handle.GetResourceComponentRplId() != resourceComponentRplId
84 || handle.GetInteractorType() != interactorType
85 || handle.GetResourceType() != resourceType
86 || handle.GetResourceIdentifier() != resourceIdentifier))
96 handle = m_aHandles[comparePosition];
101 RplId compareResourceComponentRplId = handle.GetResourceComponentRplId();
102 typename compareInteractorType = handle.GetInteractorType();
103 EResourceType compareResourceType = handle.GetResourceType();
107 if (resourceComponentRplId > compareResourceComponentRplId)
109 else if (resourceComponentRplId < compareResourceComponentRplId)
110 higherLimitPosition = comparePosition;
113 else if (interactorType.ToString() > compareInteractorType.ToString())
115 else if (interactorType.ToString() < compareInteractorType.ToString())
116 higherLimitPosition = comparePosition;
119 else if (resourceType > compareResourceType)
121 else if (resourceType < compareResourceType)
122 higherLimitPosition = comparePosition;
125 else if (resourceIdentifier > compareResourceIdentifier)
127 else if (resourceIdentifier < compareResourceIdentifier)
128 higherLimitPosition = comparePosition;
133 handle = m_aHandles[comparePosition];
144 bool SubscribeListener(RplId listener, notnull SCR_ResourceInteractor interactor)
146 if (!listener.IsValid())
153 listing.SubscribeListener(listener);
160 int maxPosition = m_aListings.Count();
161 SCR_ResourceInteractor compareInteractor;
167 compareListing = m_aListings[comparePosition];
168 compareInteractor = compareListing.GetInteractor();
170 if (interactor > compareInteractor)
172 else if (interactor < compareInteractor)
173 maxPosition = comparePosition;
181 listing.SubscribeListener(listener);
182 m_aListings.InsertAt(listing,
position);
188 bool UnsubscribeListener(RplId listener, notnull SCR_ResourceInteractor interactor)
190 if (!listener.IsValid())
198 listing.UnsubscribeListener(listener);
200 if (listing.IsEmpty())
201 m_aListings.RemoveOrdered(m_aListings.Find(listing));
207 void UnsubscribeListenerCompletely(RplId listener)
209 if (!listener.IsValid())
214 for (
int i = m_aListings.Count() - 1; i >= 0; --i)
216 listing = m_aListings[i];
220 m_aListings.RemoveOrdered(i);
225 listing.UnsubscribeListener(listener)
230 void ProcessGracefulHandles()
232 WorldTimestamp currentTime =
GetGame().GetWorld().GetTimestamp();
240 if (!handle || currentTime.DiffMilliseconds(handle.GetLastPokedAt()) >= 10000)
241 m_aGracefulHandles.RemoveItem(handle);
246 void ReplicateListeners()
257 m_aListings.RemoveItem(listing);
264 if (!ownerRplId.IsValid())
267 RplId resourceComponentRplId = Replication.FindId(interactor.GetComponent());
269 if (!resourceComponentRplId.IsValid())
272 typename interactorType = interactor.Type();
283 int maxPosition = m_aHandles.Count();
285 RplId compareResourceComponentRplId;
286 typename compareInteractorType;
293 compareHandle = m_aHandles[comparePosition];
294 compareResourceComponentRplId = compareHandle.GetResourceComponentRplId();
295 compareInteractorType = compareHandle.GetInteractorType();
296 compareResourceType = compareHandle.GetResourceType();
297 compareResourceIdentifier = compareHandle.GetResourceIdentifier();
300 if (resourceComponentRplId > compareResourceComponentRplId)
302 else if (resourceComponentRplId < compareResourceComponentRplId)
303 maxPosition = comparePosition;
306 else if (interactorType.ToString() > compareInteractorType.ToString())
308 else if (interactorType.ToString() < compareInteractorType.ToString())
309 maxPosition = comparePosition;
312 else if (resourceType > compareResourceType)
314 else if (resourceType < compareResourceType)
315 maxPosition = comparePosition;
318 else if (resourceIdentifier > compareResourceIdentifier)
320 else if (resourceIdentifier < compareResourceIdentifier)
321 maxPosition = comparePosition;
332 m_aHandles.InsertAt(handle,
position);
340 if (!ownerRplId.IsValid())
343 RplId resourceComponentRplId = Replication.FindId(interactor.GetComponent());
345 if (!resourceComponentRplId.IsValid())
348 typename interactorType = interactor.Type();
363 int maxPosition = m_aHandles.Count();
365 RplId compareResourceComponentRplId;
366 typename compareInteractorType;
373 compareHandle = m_aHandles[comparePosition];
374 compareResourceComponentRplId = compareHandle.GetResourceComponentRplId();
375 compareInteractorType = compareHandle.GetInteractorType();
376 compareResourceType = compareHandle.GetResourceType();
377 compareResourceIdentifier = compareHandle.GetResourceIdentifier();
380 if (resourceComponentRplId > compareResourceComponentRplId)
382 else if (resourceComponentRplId < compareResourceComponentRplId)
383 maxPosition = comparePosition;
386 else if (interactorType.ToString() > compareInteractorType.ToString())
388 else if (interactorType.ToString() < compareInteractorType.ToString())
389 maxPosition = comparePosition;
392 else if (resourceType > compareResourceType)
394 else if (resourceType < compareResourceType)
395 maxPosition = comparePosition;
398 else if (resourceIdentifier > compareResourceIdentifier)
400 else if (resourceIdentifier < compareResourceIdentifier)
401 maxPosition = comparePosition;
412 m_aHandles.InsertAt(handle,
position);
413 m_aGracefulHandles.Insert(handle);
422 m_aHandles.RemoveOrdered(m_aHandles.Find(handle));
424 if (m_aGracefulHandles.Contains(handle))
425 m_aGracefulHandles.RemoveItem(handle);
429 void OnResourceInteractorDeleted(notnull SCR_ResourceInteractor interactor)
436 m_aListings.RemoveItem(listing);
442 m_ReplicationBudgetManager =
new SCR_ContainerBudgetManager<array<ref SCR_ResourceSystemSubscriptionListing>,
SCR_ResourceSystemSubscriptionListing>(m_aListings, REPLICATION_MAX_FRAME_BUDGET);
443 m_GracefulHandlesBudgetManager =
new SCR_ContainerBudgetManager<array<ref SCR_ResourceSystemSubscriptionHandleBase>,
SCR_ResourceSystemSubscriptionHandleBase>(m_aGracefulHandles, GRACEFUL_HANDLES_MAX_FRAME_BUDGET);