mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-19 20:49:38 +02:00
use lambdas to remove some repeated code
This commit is contained in:
parent
b2db5f7fee
commit
3dbf28b7b4
2 changed files with 29 additions and 64 deletions
|
@ -451,11 +451,9 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments) {
|
bool EntityScriptingInterface::actionWorker(QUuid entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor) {
|
||||||
QUuid actionID = QUuid::createUuid();
|
|
||||||
|
|
||||||
if (!_entityTree) {
|
if (!_entityTree) {
|
||||||
return QUuid();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_entityTree->lockForWrite();
|
_entityTree->lockForWrite();
|
||||||
|
@ -463,28 +461,35 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity
|
||||||
EntitySimulation* simulation = _entityTree->getSimulation();
|
EntitySimulation* simulation = _entityTree->getSimulation();
|
||||||
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
|
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
qDebug() << "addAction -- unknown entity" << entityID;
|
qDebug() << "actionWorker -- unknown entity" << entityID;
|
||||||
_entityTree->unlock();
|
_entityTree->unlock();
|
||||||
return QUuid();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!simulation) {
|
if (!simulation) {
|
||||||
qDebug() << "addAction -- no simulation" << entityID;
|
qDebug() << "actionWorker -- no simulation" << entityID;
|
||||||
_entityTree->unlock();
|
_entityTree->unlock();
|
||||||
return QUuid();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString);
|
bool success = actor(simulation, entity);
|
||||||
|
|
||||||
if (actionType == ACTION_TYPE_NONE) {
|
|
||||||
_entityTree->unlock();
|
|
||||||
return QUuid();
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityActionPointer action = simulation->actionFactory(actionType, actionID, entity, arguments);
|
|
||||||
_entityTree->unlock();
|
_entityTree->unlock();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
if (action) {
|
|
||||||
|
|
||||||
|
QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entityID, QVariantMap arguments) {
|
||||||
|
QUuid actionID = QUuid::createUuid();
|
||||||
|
bool success = actionWorker(entityID, [actionID, actionTypeString, entityID, arguments](EntitySimulation* simulation,
|
||||||
|
EntityItemPointer entity) {
|
||||||
|
EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString);
|
||||||
|
if (actionType == ACTION_TYPE_NONE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return simulation->actionFactory(actionType, actionID, entity, arguments);
|
||||||
|
});
|
||||||
|
if (success) {
|
||||||
return actionID;
|
return actionID;
|
||||||
}
|
}
|
||||||
return QUuid();
|
return QUuid();
|
||||||
|
@ -492,55 +497,14 @@ QUuid EntityScriptingInterface::addAction(QString actionTypeString, QUuid entity
|
||||||
|
|
||||||
|
|
||||||
bool EntityScriptingInterface::updateAction(QUuid entityID, QUuid actionID, QVariantMap arguments) {
|
bool EntityScriptingInterface::updateAction(QUuid entityID, QUuid actionID, QVariantMap arguments) {
|
||||||
if (!_entityTree) {
|
return actionWorker(entityID, [entityID, actionID,arguments](EntitySimulation* simulation, EntityItemPointer entity) {
|
||||||
return false;
|
return entity->updateAction(simulation, actionID, arguments);
|
||||||
}
|
});
|
||||||
|
|
||||||
_entityTree->lockForWrite();
|
|
||||||
|
|
||||||
EntitySimulation* simulation = _entityTree->getSimulation();
|
|
||||||
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
|
|
||||||
if (!entity) {
|
|
||||||
qDebug() << "updateAction -- unknown entity" << entityID;
|
|
||||||
_entityTree->unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!simulation) {
|
|
||||||
qDebug() << "updateAction -- no simulation" << entityID;
|
|
||||||
_entityTree->unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool result = entity->updateAction(simulation, actionID, arguments);
|
|
||||||
_entityTree->unlock();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EntityScriptingInterface::deleteAction(QUuid entityID, QUuid actionID) {
|
bool EntityScriptingInterface::deleteAction(QUuid entityID, QUuid actionID) {
|
||||||
if (!_entityTree) {
|
return actionWorker(entityID, [entityID, actionID](EntitySimulation* simulation, EntityItemPointer entity) {
|
||||||
return false;
|
return entity->removeAction(simulation, actionID);
|
||||||
}
|
});
|
||||||
|
|
||||||
_entityTree->lockForWrite();
|
|
||||||
|
|
||||||
EntitySimulation* simulation = _entityTree->getSimulation();
|
|
||||||
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
|
|
||||||
if (!entity) {
|
|
||||||
qDebug() << "updateAction -- unknown entity" << entityID;
|
|
||||||
_entityTree->unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!simulation) {
|
|
||||||
qDebug() << "updateAction -- no simulation" << entityID;
|
|
||||||
_entityTree->unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool result = entity->removeAction(simulation, actionID);
|
|
||||||
|
|
||||||
_entityTree->unlock();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,7 @@ signals:
|
||||||
void clearingEntities();
|
void clearingEntities();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool actionWorker(QUuid entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor);
|
||||||
bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor);
|
bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor);
|
||||||
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue