History

checkpoint for debugging/comparing edit.js

howard-stearns committed 10 years ago

Commit c6347eb1 parent 50cc63210 files · +86 −29Browse files

Showing the changes to interface/src/Application.cpp (1 of 10 files). Show all

Unified · Split

interface/src/Application.cpp+49−13
@@ -270,7 +270,7 @@ public: · 269 unmodified lines
270270 void run() override {
271271 while (!_quit) {
272272 QThread::sleep(HEARTBEAT_UPDATE_INTERVAL_SECS);
273−
273+/* fixme
274274 uint64_t lastHeartbeat = _heartbeat; // sample atomic _heartbeat, because we could context switch away and have it updated on us
275275 uint64_t now = usecTimestampNow();
276276 auto lastHeartbeatAge = (now > lastHeartbeat) ? now - lastHeartbeat : 0;
@@ -319,6 +319,7 @@ public: · 42 unmodified lines
319319 deadlockDetectionCrash();
320320 }
321321 #endif
322+ */
322323 }
323324 }
324325
@@ -2790,43 +2791,78 @@ void Application::calibrateEyeTracker5Points() { · 2465 unmodified lines
27902791 }
27912792 #endif
27922793
2794+class EntityDatum { // For parent-first sorting and mapping.
2795+public:
2796+ EntityItemPointer item;
2797+ EntityItemProperties properties;
2798+ EntityItemID originalParentID;
2799+ EntityItemID mappedID;
2800+ EntityDatum() {};
2801+ EntityDatum(EntityItemPointer itemArg, EntityItemProperties propertiesArg, EntityItemID parentID) :
2802+ item(itemArg), properties(propertiesArg), originalParentID(parentID) {
2803+ };
2804+};
27932805 bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
2794− QVector<EntityItemPointer> entities;
2806+ QHash<EntityItemID, EntityDatum> entities;
27952807
27962808 auto entityTree = getEntities()->getTree();
27972809 auto exportTree = std::make_shared<EntityTree>();
27982810 exportTree->createRootElement();
27992811
28002812 glm::vec3 root(TREE_SCALE, TREE_SCALE, TREE_SCALE);
2801− for (auto entityID : entityIDs) {
2813+ for (auto entityID : entityIDs) { // Gather entities and properties.
28022814 auto entityItem = entityTree->findEntityByEntityItemID(entityID);
28032815 if (!entityItem) {
2816+ qCDebug(interfaceapp) << "Skipping export of" << entityID << "that is not in scene.";
28042817 continue;
28052818 }
28062819
28072820 auto properties = entityItem->getProperties();
2808− auto position = properties.getPosition();
2809−
2821+ auto position = properties.getPosition(); // see setPosition, below.
28102822 root.x = glm::min(root.x, position.x);
28112823 root.y = glm::min(root.y, position.y);
28122824 root.z = glm::min(root.z, position.z);
28132825
2814− entities << entityItem;
2826+ qCDebug(interfaceapp) << "Exporting" << entityItem->getEntityItemID() << entityItem->getName();
2827+ entities[entityID] = EntityDatum(entityItem, properties, properties.getParentID());
28152828 }
28162829
28172830 if (entities.size() == 0) {
28182831 return false;
28192832 }
28202833
2821− for (auto entityItem : entities) {
2822− auto properties = entityItem->getProperties();
2834+ for (EntityDatum& entityDatum : entities) {
2835+ // Recursively add the parents of entities to the exportTree, mapping their new identifiers as we go.
2836+ std::function<EntityItemID(EntityDatum&)> getMapped = [&](EntityDatum& datum) {
2837+ auto originalID = datum.item->getEntityItemID();
2838+ if (!datum.mappedID.isInvalidID()) {
2839+ qCDebug(interfaceapp) << "already mapped" << datum.properties.getName() << originalID << "=>" << datum.mappedID;
2840+ return datum.mappedID; // We are a parent that has already been added/mapped.
2841+ }
2842+ auto properties = datum.properties;
2843+ auto parentID = datum.originalParentID;
2844+ if (!datum.originalParentID.isInvalidID()) { // Recurse over ancestors, updating properties.
2845+ qCDebug(interfaceapp) << "FIXME recursing" << datum.originalParentID << "parent of" << datum.item->getEntityItemID();
2846+ // Warning: this is not a tail-call, so exporting a REALLY deep parent hierarchy will blow the call stack.
2847+ parentID = getMapped(entities[parentID]);
2848+ properties.setParentID(parentID);
2849+ }
2850+ // The so-called root offset (which isn't) is confusing and not what content developers want. And why would queryAACube not then be offset?
2851+ // But leaving it in for bug-compatibility right now. -HRS
2852+ properties.setPosition(properties.getPosition() - root);
2853+ datum.mappedID = originalID; //EntityItemID(QUuid::createUuid());
2854+ auto newEntity = exportTree->addEntity(datum.mappedID, properties);
2855+ qCDebug(interfaceapp) << "mapped" << properties.getName();
2856+ qCDebug(interfaceapp) << " " << originalID << "p:" << datum.originalParentID;
2857+ qCDebug(interfaceapp) << " =>" << datum.mappedID << "p:" << parentID;
28232858
2824− properties.setPosition(properties.getPosition() - root);
2825− exportTree->addEntity(entityItem->getEntityItemID(), properties);
2826− }
2859+ return datum.mappedID;
2860+ };
28272861
2862+ getMapped(entityDatum);
2863+ }
28282864 // remap IDs on export so that we aren't publishing the IDs of entities in our domain
2829− exportTree->remapIDs();
2865+ //exportTree->remapIDs();
28302866
28312867 exportTree->writeToJSONFile(filename.toLocal8Bit().constData());
28322868
@@ -2902,7 +2938,7 @@ bool Application::importEntities(const QString& urlOrFilename) { · 69 unmodified lines
29022938
29032939 bool success = _entityClipboard->readFromURL(url.toString());
29042940 if (success) {
2905− _entityClipboard->remapIDs();
2941+ // FIXME _entityClipboard->remapIDs();
29062942 _entityClipboard->reaverageOctreeElements();
29072943 }
29082944 return success;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t