History

working on removing voxels

ZappoMan committed 11 years ago

Commit e1d80221 parent 86009854 files · +5 −329Browse files

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

Unified · Split

interface/src/Application.cpp+4−269
@@ -62,7 +62,6 @@ · 61 unmodified lines
6262 #include <GlowEffect.h>
6363 #include <HFActionEvent.h>
6464 #include <HFBackEvent.h>
65−#include <LocalVoxelsList.h>
6665 #include <LogHandler.h>
6766 #include <MainWindow.h>
6867 #include <NetworkAccessManager.h>
@@ -151,15 +150,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 82 unmodified lines
151150 _frameCount(0),
152151 _fps(60.0f),
153152 _justStarted(true),
154− _voxelImportDialog(NULL),
155− _voxelImporter(),
156− _importSucceded(false),
157− _sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard),
158153 _entities(true, this, this),
159154 _entityCollisionSystem(),
160155 _entityClipboardRenderer(false, this, this),
161156 _entityClipboard(),
162− _wantToKillLocalVoxels(false),
163157 _viewFrustum(),
164158 _lastQueriedViewFrustum(),
165159 _lastQueriedTime(usecTimestampNow()),
@@ -177,7 +171,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 11 unmodified lines
177171 _audio(),
178172 _enableProcessVoxelsThread(true),
179173 _octreeProcessor(),
180− _voxelHideShowThread(&_voxels),
181174 _packetsPerSecond(0),
182175 _bytesPerSecond(0),
183176 _nodeBoundsDisplay(this),
@@ -275,8 +268,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 91 unmodified lines
275268 connect(nodeList, &NodeList::nodeAdded, this, &Application::nodeAdded);
276269 connect(nodeList, &NodeList::nodeKilled, this, &Application::nodeKilled);
277270 connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
278− connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer)));
279− connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer)));
280271 connect(nodeList, &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID);
281272 connect(nodeList, &NodeList::limitOfSilentDomainCheckInsReached, nodeList, &NodeList::reset);
282273
@@ -313,10 +304,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 30 unmodified lines
313304 _settings = new QSettings(this);
314305 _numChangedSettings = 0;
315306
316− // Check to see if the user passed in a command line option for loading a local
317− // Voxel File.
318− _voxelsFilename = getCmdOption(argc, constArgv, "-i");
319−
320307 #ifdef _WIN32
321308 WSADATA WsaData;
322309 int wsaresult = WSAStartup(MAKEWORD(2,2), &WsaData);
@@ -327,8 +314,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 4 unmodified lines
327314 << NodeType::VoxelServer << NodeType::EntityServer
328315 << NodeType::MetavoxelServer);
329316
330− // connect to the packet sent signal of the _voxelEditSender and the _entityEditSender
331− connect(&_voxelEditSender, &VoxelEditPacketSender::packetSent, this, &Application::packetSent);
317+ // connect to the packet sent signal of the _entityEditSender
332318 connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent);
333319
334320 // move the silentNodeTimer to the _nodeThread
@@ -373,8 +359,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 38 unmodified lines
373359
374360 // initialization continues in initializeGL when OpenGL context is ready
375361
376− // Tell our voxel edit sender about our known jurisdictions
377− _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions);
362+ // Tell our entity edit sender about our known jurisdictions
378363 _entityEditSender.setServerJurisdictions(&_entityServerJurisdictions);
379364
380365 // For now we're going to set the PPS for outbound packets to be super high, this is
@@ -386,9 +371,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 5 unmodified lines
386371
387372 _overlays.init(glCanvas.data()); // do this before scripts load
388373
389− LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree());
390− LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard);
391−
392374 _runningScriptsWidget->setRunningScripts(getRunningScripts());
393375 connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript);
394376
@@ -446,9 +428,6 @@ Application::~Application() { · 51 unmodified lines
446428 // make sure we don't call the idle timer any more
447429 delete idleTimer;
448430
449− _sharedVoxelSystem.changeTree(new VoxelTree);
450− delete _voxelImportDialog;
451−
452431 // let the avatar mixer know we're out
453432 MyAvatar::sendKillAvatar();
454433
@@ -467,11 +446,8 @@ Application::~Application() { · 12 unmodified lines
467446 _audio.thread()->wait();
468447
469448 _octreeProcessor.terminate();
470− _voxelHideShowThread.terminate();
471− _voxelEditSender.terminate();
472449 _entityEditSender.terminate();
473450
474− VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
475451 Menu::getInstance()->deleteLater();
476452
477453 _myAvatar = NULL;
@@ -481,9 +457,6 @@ void Application::saveSettings() { · 3 unmodified lines
481457 Menu::getInstance()->saveSettings();
482458 _rearMirrorTools->saveSettings(_settings);
483459
484− if (_voxelImportDialog) {
485− _voxelImportDialog->saveSettings(_settings);
486− }
487460 _settings->sync();
488461 _numChangedSettings = 0;
489462 }
@@ -568,14 +541,8 @@ void Application::initializeGL() { · 78 unmodified lines
568541
569542 // create thread for parsing of voxel data independent of the main network and rendering threads
570543 _octreeProcessor.initialize(_enableProcessVoxelsThread);
571− _voxelEditSender.initialize(_enableProcessVoxelsThread);
572− _voxelHideShowThread.initialize(_enableProcessVoxelsThread);
573544 _entityEditSender.initialize(_enableProcessVoxelsThread);
574545
575− if (_enableProcessVoxelsThread) {
576− qDebug("Voxel parsing thread created.");
577− }
578−
579546 // call our timer function every second
580547 QTimer* timer = new QTimer(this);
581548 connect(timer, SIGNAL(timeout()), SLOT(timer()));
@@ -797,10 +764,6 @@ void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) · 215 unmodified lines
797764
798765 void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) {
799766 foreach(NodeType_t type, destinationNodeTypes) {
800− // Intercept data to voxel server when voxels are disabled
801− if (type == NodeType::VoxelServer && !Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) {
802− continue;
803− }
804767
805768 // Perform the broadcast for one type
806769 int nReceivingNodes = NodeList::getInstance()->broadcastToNodes(packet, NodeSet() << type);
@@ -812,7 +775,6 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod · 5 unmodified lines
812775 case NodeType::AvatarMixer:
813776 channel = BandwidthMeter::AVATARS;
814777 break;
815− case NodeType::VoxelServer:
816778 case NodeType::EntityServer:
817779 channel = BandwidthMeter::VOXELS;
818780 break;
@@ -1093,11 +1055,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 274 unmodified lines
10931055 Menu::getInstance()->triggerOption(MenuOption::DisplayFrustum);
10941056 }
10951057 break;
1096− case Qt::Key_V:
1097− if (isShifted) {
1098− Menu::getInstance()->triggerOption(MenuOption::Voxels);
1099− }
1100− break;
11011058 case Qt::Key_P:
11021059 Menu::getInstance()->triggerOption(MenuOption::FirstPerson);
11031060 break;
@@ -1442,7 +1399,7 @@ void Application::dropEvent(QDropEvent *event) { · 338 unmodified lines
14421399 void Application::sendPingPackets() {
14431400 QByteArray pingPacket = NodeList::getInstance()->constructPingPacket();
14441401 controlledBroadcastToNodes(pingPacket, NodeSet()
1445− << NodeType::VoxelServer << NodeType::EntityServer
1402+ << NodeType::EntityServer
14461403 << NodeType::AudioMixer << NodeType::AvatarMixer
14471404 << NodeType::MetavoxelServer);
14481405 }
@@ -1588,63 +1545,10 @@ void Application::setEnableVRMode(bool enableVRMode) { · 139 unmodified lines
15881545 resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight());
15891546 }
15901547
1591−void Application::setRenderVoxels(bool voxelRender) {
1592− _voxelEditSender.setShouldSend(voxelRender);
1593− if (!voxelRender) {
1594− doKillLocalVoxels();
1595− }
1596−}
1597−
15981548 void Application::setLowVelocityFilter(bool lowVelocityFilter) {
15991549 SixenseManager::getInstance().setLowVelocityFilter(lowVelocityFilter);
16001550 }
16011551
1602−void Application::doKillLocalVoxels() {
1603− _wantToKillLocalVoxels = true;
1604−}
1605−
1606−void Application::removeVoxel(glm::vec3 position,
1607− float scale) {
1608− VoxelDetail voxel;
1609− voxel.x = position.x / TREE_SCALE;
1610− voxel.y = position.y / TREE_SCALE;
1611− voxel.z = position.z / TREE_SCALE;
1612− voxel.s = scale / TREE_SCALE;
1613− _voxelEditSender.sendVoxelEditMessage(PacketTypeVoxelErase, voxel);
1614−
1615− // delete it locally to see the effect immediately (and in case no voxel server is present)
1616− _voxels.getTree()->deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s);
1617−}
1618−
1619−
1620−void Application::makeVoxel(glm::vec3 position,
1621− float scale,
1622− unsigned char red,
1623− unsigned char green,
1624− unsigned char blue,
1625− bool isDestructive) {
1626− VoxelDetail voxel;
1627− voxel.x = position.x / TREE_SCALE;
1628− voxel.y = position.y / TREE_SCALE;
1629− voxel.z = position.z / TREE_SCALE;
1630− voxel.s = scale / TREE_SCALE;
1631− voxel.red = red;
1632− voxel.green = green;
1633− voxel.blue = blue;
1634− PacketType message = isDestructive ? PacketTypeVoxelSetDestructive : PacketTypeVoxelSet;
1635− _voxelEditSender.sendVoxelEditMessage(message, voxel);
1636−
1637− // create the voxel locally so it appears immediately
1638− _voxels.getTree()->createVoxel(voxel.x, voxel.y, voxel.z, voxel.s,
1639− voxel.red, voxel.green, voxel.blue,
1640− isDestructive);
1641− }
1642−
1643−glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel) {
1644− return glm::vec3((mouseVoxel.x + mouseVoxel.s / 2.0f) * TREE_SCALE, (mouseVoxel.y + mouseVoxel.s / 2.0f) * TREE_SCALE,
1645− (mouseVoxel.z + mouseVoxel.s / 2.0f) * TREE_SCALE);
1646−}
1647−
16481552 bool Application::mouseOnScreen() const {
16491553 if (OculusManager::isConnected()) {
16501554 GLCanvas::SharedPointer glCanvas = DependencyManager::get<GLCanvas>();
@@ -1728,88 +1632,6 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa · 77 unmodified lines
17281632 return true;
17291633 }
17301634
1731−bool Application::sendVoxelsOperation(OctreeElement* element, void* extraData) {
1732− VoxelTreeElement* voxel = (VoxelTreeElement*)element;
1733− SendVoxelsOperationArgs* args = (SendVoxelsOperationArgs*)extraData;
1734− if (voxel->isColored()) {
1735− const unsigned char* nodeOctalCode = voxel->getOctalCode();
1736− unsigned char* codeColorBuffer = NULL;
1737− int codeLength = 0;
1738− int bytesInCode = 0;
1739− int codeAndColorLength;
1740−
1741− // If the newBase is NULL, then don't rebase
1742− if (args->newBaseOctCode) {
1743− codeColorBuffer = rebaseOctalCode(nodeOctalCode, args->newBaseOctCode, true);
1744− codeLength = numberOfThreeBitSectionsInCode(codeColorBuffer);
1745− bytesInCode = bytesRequiredForCodeLength(codeLength);
1746− codeAndColorLength = bytesInCode + SIZE_OF_COLOR_DATA;
1747− } else {
1748− codeLength = numberOfThreeBitSectionsInCode(nodeOctalCode);
1749− bytesInCode = bytesRequiredForCodeLength(codeLength);
1750− codeAndColorLength = bytesInCode + SIZE_OF_COLOR_DATA;
1751− codeColorBuffer = new unsigned char[codeAndColorLength];
1752− memcpy(codeColorBuffer, nodeOctalCode, bytesInCode);
1753− }
1754−
1755− // copy the colors over
1756− codeColorBuffer[bytesInCode + RED_INDEX] = voxel->getColor()[RED_INDEX];
1757− codeColorBuffer[bytesInCode + GREEN_INDEX] = voxel->getColor()[GREEN_INDEX];
1758− codeColorBuffer[bytesInCode + BLUE_INDEX] = voxel->getColor()[BLUE_INDEX];
1759− getInstance()->_voxelEditSender.queueVoxelEditMessage(PacketTypeVoxelSetDestructive,
1760− codeColorBuffer, codeAndColorLength);
1761−
1762− delete[] codeColorBuffer;
1763− }
1764− return true; // keep going
1765−}
1766−
1767−void Application::exportVoxels(const VoxelDetail& sourceVoxel) {
1768− QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
1769− QString suggestedName = desktopLocation.append("/voxels.svo");
1770−
1771− QString fileNameString = QFileDialog::getSaveFileName(DependencyManager::get<GLCanvas>().data(),
1772− tr("Export Voxels"), suggestedName,
1773− tr("Sparse Voxel Octree Files (*.svo)"));
1774− QByteArray fileNameAscii = fileNameString.toLocal8Bit();
1775− const char* fileName = fileNameAscii.data();
1776−
1777− VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s);
1778− if (selectedNode) {
1779− VoxelTree exportTree;
1780− getVoxelTree()->copySubTreeIntoNewTree(selectedNode, &exportTree, true);
1781− exportTree.writeToSVOFile(fileName);
1782− }
1783−
1784− // restore the main window's active state
1785− _window->activateWindow();
1786−}
1787−
1788−void Application::importVoxels() {
1789− _importSucceded = false;
1790−
1791− if (!_voxelImportDialog) {
1792− _voxelImportDialog = new VoxelImportDialog(_window);
1793− _voxelImportDialog->loadSettings(_settings);
1794− }
1795−
1796− if (!_voxelImportDialog->exec()) {
1797− qDebug() << "Import succeeded." << endl;
1798− _importSucceded = true;
1799− } else {
1800− qDebug() << "Import failed." << endl;
1801− if (_sharedVoxelSystem.getTree() == _voxelImporter.getVoxelTree()) {
1802− _sharedVoxelSystem.killLocalVoxels();
1803− _sharedVoxelSystem.changeTree(&_clipboard);
1804− }
1805− }
1806−
1807− // restore the main window's active state
1808− _window->activateWindow();
1809−
1810− emit importDone();
1811−}
1812−
18131635 bool Application::importEntities(const QString& filename) {
18141636 _entityClipboard.eraseAllOctreeElements();
18151637 bool success = _entityClipboard.readFromSVOFile(filename.toLocal8Bit().constData());
@@ -1823,71 +1645,6 @@ void Application::pasteEntities(float x, float y, float z) { · 7 unmodified lines
18231645 _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z);
18241646 }
18251647
1826−void Application::cutVoxels(const VoxelDetail& sourceVoxel) {
1827− copyVoxels(sourceVoxel);
1828− deleteVoxelAt(sourceVoxel);
1829−}
1830−
1831−void Application::copyVoxels(const VoxelDetail& sourceVoxel) {
1832− // switch to and clear the clipboard first...
1833− _sharedVoxelSystem.killLocalVoxels();
1834− if (_sharedVoxelSystem.getTree() != &_clipboard) {
1835− _clipboard.eraseAllOctreeElements();
1836− _sharedVoxelSystem.changeTree(&_clipboard);
1837− }
1838−
1839− // then copy onto it if there is something to copy
1840− VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s);
1841− if (selectedNode) {
1842− getVoxelTree()->copySubTreeIntoNewTree(selectedNode, _sharedVoxelSystem.getTree(), true);
1843− _sharedVoxelSystem.forceRedrawEntireTree();
1844− }
1845−}
1846−
1847−void Application::pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination) {
1848− // Recurse the clipboard tree, where everything is root relative, and send all the colored voxels to
1849− // the server as an set voxel message, this will also rebase the voxels to the new location
1850− SendVoxelsOperationArgs args;
1851− args.newBaseOctCode = octalCodeDestination;
1852− _sharedVoxelSystem.getTree()->recurseTreeWithOperation(sendVoxelsOperation, &args);
1853−
1854− // Switch back to clipboard if it was an import
1855− if (_sharedVoxelSystem.getTree() != &_clipboard) {
1856− _sharedVoxelSystem.killLocalVoxels();
1857− _sharedVoxelSystem.changeTree(&_clipboard);
1858− }
1859−
1860− _voxelEditSender.releaseQueuedMessages();
1861−}
1862−
1863−void Application::pasteVoxels(const VoxelDetail& sourceVoxel) {
1864− unsigned char* calculatedOctCode = NULL;
1865− VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s);
1866−
1867− // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
1868− // voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a
1869− // target octalCode for where the user is pointing.
1870− const unsigned char* octalCodeDestination;
1871− if (selectedNode) {
1872− octalCodeDestination = selectedNode->getOctalCode();
1873− } else {
1874− octalCodeDestination = calculatedOctCode = pointToVoxel(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s);
1875− }
1876−
1877− pasteVoxelsToOctalCode(octalCodeDestination);
1878−
1879− if (calculatedOctCode) {
1880− delete[] calculatedOctCode;
1881− }
1882−}
1883−
1884−void Application::nudgeVoxelsByVector(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec) {
1885− VoxelTreeElement* nodeToNudge = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s);
1886− if (nodeToNudge) {
1887− _voxels.getTree()->nudgeSubTree(nodeToNudge, nudgeVec, _voxelEditSender);
1888− }
1889−}
1890−
18911648 void Application::initDisplay() {
18921649 glEnable(GL_BLEND);
18931650 glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
@@ -1898,23 +1655,6 @@ void Application::initDisplay() { · 4 unmodified lines
18981655 }
18991656
19001657 void Application::init() {
1901− _sharedVoxelSystemViewFrustum.setPosition(glm::vec3(TREE_SCALE / 2.0f,
1902− TREE_SCALE / 2.0f,
1903− 3.0f * TREE_SCALE / 2.0f));
1904− _sharedVoxelSystemViewFrustum.setNearClip(TREE_SCALE / 2.0f);
1905− _sharedVoxelSystemViewFrustum.setFarClip(3.0f * TREE_SCALE / 2.0f);
1906− _sharedVoxelSystemViewFrustum.setFieldOfView(90.0f);
1907− _sharedVoxelSystemViewFrustum.setOrientation(glm::quat());
1908− _sharedVoxelSystemViewFrustum.calculate();
1909− _sharedVoxelSystem.setViewFrustum(&_sharedVoxelSystemViewFrustum);
1910−
1911− VoxelTreeElement::removeUpdateHook(&_sharedVoxelSystem);
1912−
1913− // Cleanup of the original shared tree
1914− _sharedVoxelSystem.init();
1915−
1916− _voxelImportDialog = new VoxelImportDialog(_window);
1917−
19181658 _environment.init();
19191659
19201660 DependencyManager::get<DeferredLightingEffect>()->init(this);
@@ -1987,16 +1727,11 @@ void Application::init() { · 66 unmodified lines
19871727 // fire off an immediate domain-server check in now that settings are loaded
19881728 NodeList::getInstance()->sendDomainServerCheckIn();
19891729
1990− // Set up VoxelSystem after loading preferences so we can get the desired max voxel count
1991− _voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels());
1992− _voxels.setDisableFastVoxelPipeline(false);
1993− _voxels.init();
1994−
19951730 _entities.init();
19961731 _entities.setViewFrustum(getViewFrustum());
19971732
19981733 EntityTree* entityTree = _entities.getTree();
1999− _entityCollisionSystem.init(&_entityEditSender, entityTree, _voxels.getTree(), &_audio, &_avatarManager);
1734+ _entityCollisionSystem.init(&_entityEditSender, entityTree, NULL, &_audio, &_avatarManager);
20001735 entityTree->setSimulation(&_entityCollisionSystem);
20011736
20021737 // connect the _entityCollisionSystem to our script engine's EntityScriptingInterface

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