Esegui un'iterazione degli eventi di cambio di proprietà delle entità - AWS SimSpace Weaver

Avviso di fine del supporto: il 20 maggio 2026, AWS terminerà il supporto per AWS SimSpace Weaver. Dopo il 20 maggio 2026, non potrai più accedere alla SimSpace Weaver console o SimSpace Weaver alle risorse. Per ulteriori informazioni, consulta AWS SimSpace Weaver Fine del supporto.

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Esegui un'iterazione degli eventi di cambio di proprietà delle entità

Per visualizzare gli eventi in cui un'entità si sposta tra un'area di proprietà e un'area di sottoscrizione, confronta le modifiche tra gli eventi di proprietà e sottoscrizione dell'entità correnti e precedenti.

Puoi gestire questi eventi leggendo:

  • Api::SubscriptionChangeList

  • Api::OwnershipEvents

È quindi possibile confrontare le modifiche con i dati precedentemente memorizzati.

L'esempio seguente mostra come gestire gli eventi di modifica della proprietà delle entità. Questo esempio presuppone che per le entità che passano dall'essere entità sottoscritte a entità possedute (in entrambe le direzioni), l'remove/add event occurs first followed by the subscription remove/addevento di proprietà sia visualizzato nel segno di spunta successivo.

Esempio
Result<void> ProcessOwnershipEvents(Transaction& transaction) { using EntityIdsByAction = std::unordered_map<Api::ChangeListAction, std::vector<Api::EntityId>>; using EntityIdSetByAction = std::unordered_map<Api::ChangeListAction, std::unordered_set<Api::EntityId>>; static EntityIdsByAction m_entityIdsByPreviousOwnershipAction; EntityIdSetByAction entityIdSetByAction; /** * Enumerate Api::SubscriptionChangeList items * and store Add and Remove events. */ WEAVERRUNTIME_TRY(Api::SubscriptionChangeList subscriptionEvents, Api::AllSubscriptionEvents(transaction)); for (const Api::SubscriptionEvent& event : subscriptionEvents.changes) { const Api::ChangeListAction action = event.action; switch (action) { case Api::ChangeListAction::Add: case Api::ChangeListAction::Remove: { entityIdSetByAction[action].insert( event.entity.descriptor->id); break; } case Api::ChangeListAction::None: case Api::ChangeListAction::Update: case Api::ChangeListAction::Reject: { break; } } } EntityIdsByAction entityIdsByAction; /** * Enumerate Api::OwnershipChangeList items * and store Add and Remove events. */ WEAVERRUNTIME_TRY(Api::OwnershipChangeList ownershipChangeList, Api::OwnershipChanges(transaction)); for (const Api::OwnershipChange& event : ownershipChangeList.changes) { const Api::ChangeListAction action = event.action; switch (action) { case Api::ChangeListAction::Add: case Api::ChangeListAction::Remove: { entityIdsByAction[action].push_back( event.entity.descriptor->id); break; } case Api::ChangeListAction::None: case Api::ChangeListAction::Update: case Api::ChangeListAction::Reject: { break; } } } std::vector<Api::EntityId> fromSubscribedToOwnedEntities; std::vector<Api::EntityId> fromOwnedToSubscribedEntities; /** * Enumerate the *previous* Api::OwnershipChangeList Remove items * and check if they are now in * the *current* Api::SubscriptionChangeList Add items. * * If true, then that means * OnEntityOwnershipChanged(bool isOwned = false) */ for (const Api::EntityId& id : m_entityIdsByPreviousOwnershipAction[ Api::ChangeListAction::Remove]) { if (entityIdSetBySubscriptionAction[ Api::ChangeListAction::Add].find(id) != entityIdSetBySubscriptionAction[ Api::ChangeListAction::Add].end()) { fromOwnedToSubscribedEntities.push_back(id); } } /** * Enumerate the *previous* Api::OwnershipChangeList Add items * and check if they are now in * the *current* Api::SubscriptionChangeList Remove items. * * If true, then that means * OnEntityOwnershipChanged(bool isOwned = true) */ for (const Api::EntityId& id : m_entityIdsByPreviousOwnershipAction[ Api::ChangeListAction::Add]) { if (entityIdSetBySubscriptionAction[ Api::ChangeListAction::Remove].find(id) != entityIdSetBySubscriptionAction[ Api::ChangeListAction::Remove].end()) { fromSubscribedToOwnedEntities.push_back(id); } } m_entityIdsByPreviousOwnershipAction = entityIdsByOwnershipAction; return Success(); }