first cut at getting pastEntities() working

This commit is contained in:
ZappoMan 2014-08-26 16:47:32 -07:00
parent 4895ee32f7
commit b14158385c
6 changed files with 60 additions and 5 deletions

View file

@ -1643,6 +1643,7 @@ _entityClipboard.dumpTree();
}
void Application::pasteEntities(float x, float y, float z) {
qDebug() << "Application::pasteEntities(" << x << ", " << y << ", " << z << ")";
_entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z);
}

View file

@ -36,6 +36,7 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI
int sizeOut = 0;
if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) {
qDebug() << "EntityItemProperties::encodeEntityEditPacket() returned TRUE.... calling queueOctreeEditMessage()....";
queueOctreeEditMessage(type, bufferOut, sizeOut);
}
}

View file

@ -431,6 +431,9 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP
bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties,
unsigned char* bufferOut, int sizeIn, int& sizeOut) {
qDebug() << "EntityItemProperties::encodeEntityEditPacket()....";
OctreePacketData packetData(false, sizeIn); // create a packetData object to add out packet details too.
bool success = true; // assume the best
@ -522,6 +525,8 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
if (headerFits) {
bool successPropertyFits;
qDebug() << " HEADER FITS.....";
propertyFlags -= PROP_LAST_ITEM; // clear the last item for now, we may or may not set it as the actual item
// These items would go here once supported....
@ -534,6 +539,9 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
LevelDetails propertyLevel = packetData.startLevel();
successPropertyFits = packetData.appendPosition(properties.getPosition());
if (successPropertyFits) {
qDebug() << " PROP_POSITION FITS.....";
propertyFlags |= PROP_POSITION;
propertiesDidntFit -= PROP_POSITION;
propertyCount++;
@ -692,6 +700,9 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
LevelDetails propertyLevel = packetData.startLevel();
successPropertyFits = packetData.appendValue(properties.getModelURL());
if (successPropertyFits) {
qDebug() << " PROP_MODEL_URL FITS.....";
propertyFlags |= PROP_MODEL_URL;
propertiesDidntFit -= PROP_MODEL_URL;
propertyCount++;
@ -1149,4 +1160,26 @@ bool EntityItemProperties::encodeEraseEntityMessage(const EntityItemID& entityIt
}
return true;
}
}
void EntityItemProperties::markAllChanged() {
_positionChanged = true;
_radiusChanged = true;
_rotationChanged = true;
_massChanged = true;
_velocityChanged = true;
_gravityChanged = true;
_dampingChanged = true;
_lifetimeChanged = true;
_scriptChanged = true;
_colorChanged = true;
_modelURLChanged = true;
_animationURLChanged = true;
_animationIsPlayingChanged = true;
_animationFrameIndexChanged = true;
_animationFPSChanged = true;
_glowLevelChanged = true;
}

View file

@ -117,6 +117,7 @@ public:
void setType(EntityTypes::EntityType type) { _type = type; }
/// set position in meter units
void setPosition(const glm::vec3& value) { _position = value; _positionChanged = true; }
void resetPosition(const glm::vec3& value) { _position = value; } /// changes the position without marking it as changed
void setRadius(float value) { _radius = value; _radiusChanged = true; }
void setRotation(const glm::quat& rotation) { _rotation = rotation; _rotationChanged = true; }
@ -193,6 +194,7 @@ public:
bool glowLevelChanged() const { return _glowLevelChanged; }
void clearID() { _id = UNKNOWN_ENTITY_ID; _idSet = false; }
void markAllChanged();
private:
void setLastEdited(quint64 lastEdited) { _lastEdited = lastEdited; }

View file

@ -1049,6 +1049,7 @@ void EntityTree::dumpTree() {
}
void EntityTree::sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z) {
qDebug() << "EntityTree::sendEntities(" << x << ", " << y << ", " << z << ")";
SendEntitiesOperationArgs args;
args.packetSender = packetSender;
args.localTree = localTree;
@ -1061,13 +1062,28 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData)
SendEntitiesOperationArgs* args = static_cast<SendEntitiesOperationArgs*>(extraData);
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
qDebug() << "EntityTree::sendEntitiesOperation()";
qDebug() << " element box:" << entityTreeElement->getAACube();
const QList<EntityItem*>& entities = entityTreeElement->getEntities();
for (int i = 0; i < entities.size(); i++) {
qDebug() << " entity[" << i <<"].id" << entities[i]->getEntityItemID();
EntityItemID newID(NEW_ENTITY, EntityItemID::getNextCreatorTokenID(), false);
qDebug() << " entity[" << i <<"].newID" << newID;
EntityItemProperties properties = entities[i]->getProperties();
properties.setPosition(properties.getPosition() + args->root);
qDebug() << " entity[" << i <<"].properties...";
properties.debugDump();
properties.resetPosition(properties.getPosition() + args->root);
qDebug() << " after resetPosition()....";
properties.debugDump();
properties.markAllChanged();
// queue the packet
qDebug() << " calling queueEditEntityMessage....";
args->packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, newID, properties);
// It would be nice to also update the local tree...

View file

@ -1,14 +1,16 @@
// REQUIRED:
1) Import/Export Models - verify it works. /copy/paste??
22a) void ModelItemProperties::copyFromNewModelItem(const ModelItem& modelItem); // XXX ??? Do we need this????
22b) Local Entities Overlay - from Local Models Overlay
22c) void ModelTree::sendModels(ModelEditPacketSender* packetSender, float x, float y, float z)....
bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData) {...
DONE -- 22d) void ModelTree::findModelsInCube(const AACube& cube, QVector<ModelItem*>& foundModels)...
DONE -- 22e) void ModelTreeElement::getModelsInside(const AACube& box, QVector<ModelItem*>& foundModels)...
DONE -- 22f) Application::exportEntities() tested/works
DONE -- 22g) Application::pasteEntities() tested/works
DONE -- 22c) void ModelTree::sendModels(ModelEditPacketSender* packetSender, float x, float y, float z)....
bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData) {...
RESOLVED -- 22a) void ModelItemProperties::copyFromNewModelItem(const ModelItem& modelItem); // Do we need this? NO!
2) Test models -> attachments logic