mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:01:09 +02:00
work around problem where EntityItem::setActionData is called before the entity tree is set up
This commit is contained in:
parent
5ab2c8d724
commit
593ed9f998
2 changed files with 48 additions and 8 deletions
|
@ -576,7 +576,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
READ_ENTITY_PROPERTY(PROP_DIMENSIONS, glm::vec3, updateDimensions);
|
READ_ENTITY_PROPERTY(PROP_DIMENSIONS, glm::vec3, updateDimensions);
|
||||||
READ_ENTITY_PROPERTY(PROP_DENSITY, float, updateDensity);
|
READ_ENTITY_PROPERTY(PROP_DENSITY, float, updateDensity);
|
||||||
READ_ENTITY_PROPERTY(PROP_GRAVITY, glm::vec3, updateGravity);
|
READ_ENTITY_PROPERTY(PROP_GRAVITY, glm::vec3, updateGravity);
|
||||||
|
|
||||||
READ_ENTITY_PROPERTY(PROP_DAMPING, float, updateDamping);
|
READ_ENTITY_PROPERTY(PROP_DAMPING, float, updateDamping);
|
||||||
READ_ENTITY_PROPERTY(PROP_RESTITUTION, float, updateRestitution);
|
READ_ENTITY_PROPERTY(PROP_RESTITUTION, float, updateRestitution);
|
||||||
READ_ENTITY_PROPERTY(PROP_FRICTION, float, updateFriction);
|
READ_ENTITY_PROPERTY(PROP_FRICTION, float, updateFriction);
|
||||||
|
@ -1411,7 +1411,15 @@ void EntityItem::clearSimulationOwnership() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer action) {
|
bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer action) {
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
setActionData(_serializedActions);
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assert(action);
|
assert(action);
|
||||||
|
assert(simulation);
|
||||||
auto actionOwnerEntity = action->getOwnerEntity().lock();
|
auto actionOwnerEntity = action->getOwnerEntity().lock();
|
||||||
assert(actionOwnerEntity);
|
assert(actionOwnerEntity);
|
||||||
assert(actionOwnerEntity.get() == this);
|
assert(actionOwnerEntity.get() == this);
|
||||||
|
@ -1429,6 +1437,13 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments) {
|
bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments) {
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
setActionData(_serializedActions);
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!_objectActions.contains(actionID)) {
|
if (!_objectActions.contains(actionID)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1441,6 +1456,13 @@ bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionI
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::removeAction(EntitySimulation* simulation, const QUuid& actionID) {
|
bool EntityItem::removeAction(EntitySimulation* simulation, const QUuid& actionID) {
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
setActionData(_serializedActions);
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_objectActions.contains(actionID)) {
|
if (_objectActions.contains(actionID)) {
|
||||||
EntityActionPointer action = _objectActions[actionID];
|
EntityActionPointer action = _objectActions[actionID];
|
||||||
_objectActions.remove(actionID);
|
_objectActions.remove(actionID);
|
||||||
|
@ -1471,13 +1493,12 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
_serializedActions = actionData;
|
_serializedActions = actionData;
|
||||||
if (_serializedActions.size() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector<QByteArray> serializedActions;
|
QVector<QByteArray> serializedActions;
|
||||||
QDataStream serializedActionsStream(actionData);
|
if (_serializedActions.size() > 0) {
|
||||||
serializedActionsStream >> serializedActions;
|
QDataStream serializedActionsStream(actionData);
|
||||||
|
serializedActionsStream >> serializedActions;
|
||||||
|
}
|
||||||
|
|
||||||
// Keep track of which actions got added or updated by the new actionData
|
// Keep track of which actions got added or updated by the new actionData
|
||||||
QSet<QUuid> updated;
|
QSet<QUuid> updated;
|
||||||
|
@ -1500,10 +1521,13 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
|
|
||||||
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 (simulation) {
|
||||||
if (entityTree) {
|
_serializedActionsProcessed = true;
|
||||||
EntityItemPointer entity = entityTree->findEntityByEntityItemID(_id);
|
EntityItemPointer entity = entityTree->findEntityByEntityItemID(_id);
|
||||||
actionFactory->factoryBA(simulation, entity, serializedAction);
|
actionFactory->factoryBA(simulation, entity, serializedAction);
|
||||||
|
} else {
|
||||||
|
// we can't yet add the action. This method will be called later.
|
||||||
|
_serializedActionsProcessed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1528,6 +1552,10 @@ void EntityItem::setActionData(QByteArray actionData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::serializeActions() const {
|
bool EntityItem::serializeActions() const {
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (_objectActions.size() == 0) {
|
if (_objectActions.size() == 0) {
|
||||||
_serializedActions = QByteArray();
|
_serializedActions = QByteArray();
|
||||||
return true;
|
return true;
|
||||||
|
@ -1562,6 +1590,14 @@ const QByteArray EntityItem::getActionData() const {
|
||||||
|
|
||||||
QVariantMap EntityItem::getActionArguments(const QUuid& actionID) {
|
QVariantMap EntityItem::getActionArguments(const QUuid& actionID) {
|
||||||
QVariantMap result;
|
QVariantMap result;
|
||||||
|
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
setActionData(_serializedActions);
|
||||||
|
if (!_serializedActionsProcessed) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_objectActions.contains(actionID)) {
|
if (_objectActions.contains(actionID)) {
|
||||||
EntityActionPointer action = _objectActions[actionID];
|
EntityActionPointer action = _objectActions[actionID];
|
||||||
result = action->getArguments();
|
result = action->getArguments();
|
||||||
|
|
|
@ -472,6 +472,10 @@ protected:
|
||||||
QHash<QUuid, EntityActionPointer> _objectActions;
|
QHash<QUuid, EntityActionPointer> _objectActions;
|
||||||
static int _maxActionsDataSize;
|
static int _maxActionsDataSize;
|
||||||
mutable QByteArray _serializedActions;
|
mutable QByteArray _serializedActions;
|
||||||
|
// when an entity-server starts up, EntityItem::setActionData is called before the entity-tree is
|
||||||
|
// ready. This means we can't find our EntityItemPointer or add the action to the simulation. This
|
||||||
|
// flag is used to keep track of and work around this situation.
|
||||||
|
bool _serializedActionsProcessed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityItem_h
|
#endif // hifi_EntityItem_h
|
||||||
|
|
Loading…
Reference in a new issue