mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 17:55:29 +02:00
some fixes to server cloneables
This commit is contained in:
parent
de05388ebf
commit
29b11b9101
7 changed files with 45 additions and 37 deletions
|
@ -3112,15 +3112,15 @@ void EntityItem::removeCloneID(const QUuid& cloneID) {
|
|||
});
|
||||
}
|
||||
|
||||
const QList<QUuid> EntityItem::getCloneIDs() const {
|
||||
QList<QUuid> result;
|
||||
const QVector<QUuid> EntityItem::getCloneIDs() const {
|
||||
QVector<QUuid> result;
|
||||
withReadLock([&] {
|
||||
result = _cloneIDs;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void EntityItem::setCloneIDs(const QList<QUuid>& cloneIDs) {
|
||||
void EntityItem::setCloneIDs(const QVector<QUuid>& cloneIDs) {
|
||||
withWriteLock([&] {
|
||||
_cloneIDs = cloneIDs;
|
||||
});
|
||||
|
|
|
@ -509,8 +509,8 @@ public:
|
|||
|
||||
void addCloneID(const QUuid& cloneID);
|
||||
void removeCloneID(const QUuid& cloneID);
|
||||
const QList<QUuid> getCloneIDs() const;
|
||||
void setCloneIDs(const QList<QUuid>& cloneIDs);
|
||||
const QVector<QUuid> getCloneIDs() const;
|
||||
void setCloneIDs(const QVector<QUuid>& cloneIDs);
|
||||
|
||||
signals:
|
||||
void requestRenderUpdate();
|
||||
|
@ -666,13 +666,13 @@ protected:
|
|||
|
||||
bool _cauterized { false }; // if true, don't draw because it would obscure 1st-person camera
|
||||
|
||||
bool _cloneable { ENTITY_ITEM_CLONEABLE };
|
||||
float _cloneLifetime { ENTITY_ITEM_CLONE_LIFETIME };
|
||||
float _cloneLimit { ENTITY_ITEM_CLONE_LIMIT };
|
||||
bool _cloneDynamic { ENTITY_ITEM_CLONE_DYNAMIC };
|
||||
bool _cloneAvatarEntity { ENTITY_ITEM_CLONE_AVATAR_ENTITY };
|
||||
bool _cloneable { ENTITY_ITEM_DEFAULT_CLONEABLE };
|
||||
float _cloneLifetime { ENTITY_ITEM_DEFAULT_CLONE_LIFETIME };
|
||||
float _cloneLimit { ENTITY_ITEM_DEFAULT_CLONE_LIMIT };
|
||||
bool _cloneDynamic { ENTITY_ITEM_DEFAULT_CLONE_DYNAMIC };
|
||||
bool _cloneAvatarEntity { ENTITY_ITEM_DEFAULT_CLONE_AVATAR_ENTITY };
|
||||
QUuid _cloneOriginID;
|
||||
QList<QUuid> _cloneIDs;
|
||||
QVector<QUuid> _cloneIDs;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, graphics::MultiMaterial> _materials;
|
||||
|
|
|
@ -3657,9 +3657,9 @@ void EntityItemProperties::convertToCloneProperties(const EntityItemID& entityID
|
|||
setLifetime(getCloneLifetime());
|
||||
setDynamic(getCloneDynamic());
|
||||
setClientOnly(getCloneAvatarEntity());
|
||||
setCloneable(ENTITY_ITEM_CLONEABLE);
|
||||
setCloneLifetime(ENTITY_ITEM_CLONE_LIFETIME);
|
||||
setCloneLimit(ENTITY_ITEM_CLONE_LIMIT);
|
||||
setCloneDynamic(ENTITY_ITEM_CLONE_DYNAMIC);
|
||||
setCloneAvatarEntity(ENTITY_ITEM_CLONE_AVATAR_ENTITY);
|
||||
setCloneable(ENTITY_ITEM_DEFAULT_CLONEABLE);
|
||||
setCloneLifetime(ENTITY_ITEM_DEFAULT_CLONE_LIFETIME);
|
||||
setCloneLimit(ENTITY_ITEM_DEFAULT_CLONE_LIMIT);
|
||||
setCloneDynamic(ENTITY_ITEM_DEFAULT_CLONE_DYNAMIC);
|
||||
setCloneAvatarEntity(ENTITY_ITEM_DEFAULT_CLONE_AVATAR_ENTITY);
|
||||
}
|
||||
|
|
|
@ -272,12 +272,12 @@ public:
|
|||
DEFINE_PROPERTY_REF(PROP_SERVER_SCRIPTS, ServerScripts, serverScripts, QString, ENTITY_ITEM_DEFAULT_SERVER_SCRIPTS);
|
||||
DEFINE_PROPERTY(PROP_RELAY_PARENT_JOINTS, RelayParentJoints, relayParentJoints, bool, ENTITY_ITEM_DEFAULT_RELAY_PARENT_JOINTS);
|
||||
|
||||
DEFINE_PROPERTY(PROP_CLONEABLE, Cloneable, cloneable, bool, ENTITY_ITEM_CLONEABLE);
|
||||
DEFINE_PROPERTY(PROP_CLONE_LIFETIME, CloneLifetime, cloneLifetime, float, ENTITY_ITEM_CLONE_LIFETIME);
|
||||
DEFINE_PROPERTY(PROP_CLONE_LIMIT, CloneLimit, cloneLimit, float, ENTITY_ITEM_CLONE_LIMIT);
|
||||
DEFINE_PROPERTY(PROP_CLONE_DYNAMIC, CloneDynamic, cloneDynamic, bool, ENTITY_ITEM_CLONE_DYNAMIC);
|
||||
DEFINE_PROPERTY(PROP_CLONE_AVATAR_ENTITY, CloneAvatarEntity, cloneAvatarEntity, bool, ENTITY_ITEM_CLONE_AVATAR_ENTITY);
|
||||
DEFINE_PROPERTY(PROP_CLONE_ORIGIN_ID, CloneOriginID, cloneOriginID, QUuid, ENTITY_ITEM_CLONE_ORIGIN_ID);
|
||||
DEFINE_PROPERTY(PROP_CLONEABLE, Cloneable, cloneable, bool, ENTITY_ITEM_DEFAULT_CLONEABLE);
|
||||
DEFINE_PROPERTY(PROP_CLONE_LIFETIME, CloneLifetime, cloneLifetime, float, ENTITY_ITEM_DEFAULT_CLONE_LIFETIME);
|
||||
DEFINE_PROPERTY(PROP_CLONE_LIMIT, CloneLimit, cloneLimit, float, ENTITY_ITEM_DEFAULT_CLONE_LIMIT);
|
||||
DEFINE_PROPERTY(PROP_CLONE_DYNAMIC, CloneDynamic, cloneDynamic, bool, ENTITY_ITEM_DEFAULT_CLONE_DYNAMIC);
|
||||
DEFINE_PROPERTY(PROP_CLONE_AVATAR_ENTITY, CloneAvatarEntity, cloneAvatarEntity, bool, ENTITY_ITEM_DEFAULT_CLONE_AVATAR_ENTITY);
|
||||
DEFINE_PROPERTY(PROP_CLONE_ORIGIN_ID, CloneOriginID, cloneOriginID, QUuid, ENTITY_ITEM_DEFAULT_CLONE_ORIGIN_ID);
|
||||
|
||||
static QString getComponentModeString(uint32_t mode);
|
||||
static QString getComponentModeAsString(uint32_t mode);
|
||||
|
|
|
@ -97,11 +97,11 @@ const QUuid ENTITY_ITEM_DEFAULT_LAST_EDITED_BY = QUuid();
|
|||
|
||||
const bool ENTITY_ITEM_DEFAULT_RELAY_PARENT_JOINTS = false;
|
||||
|
||||
const bool ENTITY_ITEM_CLONEABLE = false;
|
||||
const float ENTITY_ITEM_CLONE_LIFETIME = 300.0f;
|
||||
const int ENTITY_ITEM_CLONE_LIMIT = 0;
|
||||
const bool ENTITY_ITEM_CLONE_DYNAMIC = false;
|
||||
const bool ENTITY_ITEM_CLONE_AVATAR_ENTITY = false;
|
||||
const QUuid ENTITY_ITEM_CLONE_ORIGIN_ID = QUuid();
|
||||
const bool ENTITY_ITEM_DEFAULT_CLONEABLE = false;
|
||||
const float ENTITY_ITEM_DEFAULT_CLONE_LIFETIME = 300.0f;
|
||||
const int ENTITY_ITEM_DEFAULT_CLONE_LIMIT = 0;
|
||||
const bool ENTITY_ITEM_DEFAULT_CLONE_DYNAMIC = false;
|
||||
const bool ENTITY_ITEM_DEFAULT_CLONE_AVATAR_ENTITY = false;
|
||||
const QUuid ENTITY_ITEM_DEFAULT_CLONE_ORIGIN_ID = QUuid();
|
||||
|
||||
#endif // hifi_EntityItemPropertiesDefaults_h
|
||||
|
|
|
@ -332,13 +332,20 @@ QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QStrin
|
|||
QUuid EntityScriptingInterface::cloneEntity(QUuid entityIDToClone) {
|
||||
EntityItemID newEntityID;
|
||||
EntityItemProperties properties = getEntityProperties(entityIDToClone);
|
||||
bool cloneAvatarEntity = properties.getCloneAvatarEntity();
|
||||
properties.convertToCloneProperties(entityIDToClone);
|
||||
bool success = addLocalEntityCopy(properties, newEntityID);
|
||||
if (success) {
|
||||
getEntityPacketSender()->queueCloneEntityMessage(entityIDToClone, newEntityID);
|
||||
return newEntityID;
|
||||
|
||||
if (cloneAvatarEntity) {
|
||||
return addEntity(properties, true);
|
||||
} else {
|
||||
return QUuid();
|
||||
bool success = addLocalEntityCopy(properties, newEntityID);
|
||||
if (success) {
|
||||
getEntityPacketSender()->queueCloneEntityMessage(entityIDToClone, newEntityID);
|
||||
return newEntityID;
|
||||
}
|
||||
else {
|
||||
return QUuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -639,7 +639,7 @@ void EntityTree::cleanupCloneIDs(const EntityItemID& entityID) {
|
|||
}
|
||||
}
|
||||
// clear the clone origin ID on any clones that this entity had
|
||||
const QList<QUuid>& cloneIDs = entity->getCloneIDs();
|
||||
const QVector<QUuid>& cloneIDs = entity->getCloneIDs();
|
||||
foreach(const QUuid& cloneChildID, cloneIDs) {
|
||||
EntityItemPointer cloneChild = findEntityByEntityItemID(cloneChildID);
|
||||
if (cloneChild) {
|
||||
|
@ -1627,7 +1627,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
} else if (isClone && !isCloneable) {
|
||||
failedAdd = true;
|
||||
qCDebug(entities) << "User attempted to clone non-cloneable entity from entity ID:" << entityIDToClone;
|
||||
} else if (isClone && entityToClone && entityToClone->getCloneIDs().size() >= cloneLimit) {
|
||||
} else if (isClone && entityToClone && entityToClone->getCloneIDs().size() >= cloneLimit && cloneLimit != 0) {
|
||||
failedAdd = true;
|
||||
qCDebug(entities) << "User attempted to clone entity ID:" << entityIDToClone << " which reached it's cloneable limit.";
|
||||
} else {
|
||||
|
@ -2039,6 +2039,7 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons
|
|||
|
||||
if (shouldEraseEntity(entityID, sourceNode)) {
|
||||
entityItemIDsToDelete << entityItemID;
|
||||
cleanupCloneIDs(entityItemID);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2385,7 +2386,7 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
|||
return false;
|
||||
}
|
||||
|
||||
QMap<QUuid, QList<QUuid>> cloneIDs;
|
||||
QMap<QUuid, QVector<QUuid>> cloneIDs;
|
||||
|
||||
bool success = true;
|
||||
foreach (QVariant entityVariant, entitiesQList) {
|
||||
|
@ -2488,7 +2489,7 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
|||
|
||||
for (auto iter = cloneIDs.begin(); iter != cloneIDs.end(); ++iter) {
|
||||
const QUuid& entityID = iter.key();
|
||||
const QList<QUuid>& cloneIDs = iter.value();
|
||||
const QVector<QUuid>& cloneIDs = iter.value();
|
||||
EntityItemPointer entity = findEntityByID(entityID);
|
||||
if (entity) {
|
||||
entity->setCloneIDs(cloneIDs);
|
||||
|
|
Loading…
Reference in a new issue