mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 09:08:37 +02:00
when deserializing action, remove any existing actions that weren't part of the serialized data
This commit is contained in:
parent
f50ac9dcd5
commit
7f4e3f8216
1 changed files with 23 additions and 1 deletions
|
@ -1413,12 +1413,16 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
QDataStream ds(actionData);
|
QDataStream ds(actionData);
|
||||||
ds >> serializedActions;
|
ds >> serializedActions;
|
||||||
|
|
||||||
|
// Keep track of which actions got added or updated by the new actionData
|
||||||
|
QSet<QUuid> updated;
|
||||||
|
|
||||||
foreach(QByteArray serializedAction, serializedActions) {
|
foreach(QByteArray serializedAction, serializedActions) {
|
||||||
QDataStream dsForAction(serializedAction);
|
QDataStream dsForAction(serializedAction);
|
||||||
EntityActionType actionType;
|
EntityActionType actionType;
|
||||||
QUuid actionID;
|
QUuid actionID;
|
||||||
dsForAction >> actionType;
|
dsForAction >> actionType;
|
||||||
dsForAction >> actionID;
|
dsForAction >> actionID;
|
||||||
|
updated << actionID;
|
||||||
|
|
||||||
if (_objectActions.contains(actionID)) {
|
if (_objectActions.contains(actionID)) {
|
||||||
EntityActionPointer action = _objectActions[actionID];
|
EntityActionPointer action = _objectActions[actionID];
|
||||||
|
@ -1428,7 +1432,7 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
|
auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
|
||||||
|
|
||||||
EntityTree* entityTree = _element ? _element->getTree() : nullptr;
|
EntityTree* entityTree = _element ? _element->getTree() : nullptr;
|
||||||
EntitySimulation* simulation = entityTree? entityTree->getSimulation() : nullptr;
|
EntitySimulation* simulation = entityTree ? entityTree->getSimulation() : nullptr;
|
||||||
|
|
||||||
if (entityTree) {
|
if (entityTree) {
|
||||||
EntityItemPointer entity = entityTree->findEntityByEntityItemID(_id);
|
EntityItemPointer entity = entityTree->findEntityByEntityItemID(_id);
|
||||||
|
@ -1438,6 +1442,24 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove any actions that weren't included in the new data.
|
||||||
|
QHash<QUuid, EntityActionPointer>::iterator i = _objectActions.begin();
|
||||||
|
while (i != _objectActions.end()) {
|
||||||
|
const QUuid id = i.key();
|
||||||
|
if (updated.contains(id)) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EntityActionPointer action = _objectActions[id];
|
||||||
|
i = _objectActions.erase(i);
|
||||||
|
action->setOwnerEntity(nullptr);
|
||||||
|
EntityTree* entityTree = _element ? _element->getTree() : nullptr;
|
||||||
|
EntitySimulation* simulation = entityTree ? entityTree->getSimulation() : nullptr;
|
||||||
|
if (simulation) {
|
||||||
|
action->removeFromSimulation(simulation);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue