Showing the changes to interface/src/Application.cpp (1 of 38 files). Show all
Unified · Split
| @@ -82,6 +82,8 @@ const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2; · 81 unmodified lines | ||
| 82 | 82 | // Startup optimistically with small jitter buffer that |
| 83 | 83 | // will start playback on the second received audio packet. |
| 84 | 84 | |
| 85 | +static const float CLIPBOARD_TREE_SCALE = 1.0f; | |
| 86 | + | |
| 85 | 87 | void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { |
| 86 | 88 | fprintf(stdout, "%s", message.toLocal8Bit().constData()); |
| 87 | 89 | LogDisplay::instance.addMessage(message.toLocal8Bit().constData()); |
| @@ -95,6 +97,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 7 unmodified lines | ||
| 95 | 97 | _frameCount(0), |
| 96 | 98 | _fps(120.0f), |
| 97 | 99 | _justStarted(true), |
| 100 | + _clipboard(CLIPBOARD_TREE_SCALE), | |
| 101 | + _voxelImporter(_window), | |
| 98 | 102 | _wantToKillLocalVoxels(false), |
| 99 | 103 | _audioScope(256, 200, true), |
| 100 | 104 | _mouseX(0), |
| @@ -119,13 +123,14 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 18 unmodified lines | ||
| 119 | 123 | _audio(&_audioScope, STARTUP_JITTER_SAMPLES), |
| 120 | 124 | #endif |
| 121 | 125 | _stopNetworkReceiveThread(false), |
| 122 | − _voxelProcessor(this), | |
| 126 | + _voxelProcessor(), | |
| 123 | 127 | _voxelEditSender(this), |
| 124 | 128 | _packetCount(0), |
| 125 | 129 | _packetsPerSecond(0), |
| 126 | 130 | _bytesPerSecond(0), |
| 127 | 131 | _bytesCount(0), |
| 128 | − _swatch(NULL) | |
| 132 | + _swatch(NULL), | |
| 133 | + _pasteMode(false) | |
| 129 | 134 | { |
| 130 | 135 | _applicationStartupTime = startup_time; |
| 131 | 136 | _window->setWindowTitle("Interface"); |
| @@ -224,6 +229,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 92 unmodified lines | ||
| 224 | 229 | _glWidget->setMouseTracking(true); |
| 225 | 230 | |
| 226 | 231 | // initialization continues in initializeGL when OpenGL context is ready |
| 232 | + | |
| 233 | + // Tell our voxel edit sender about our known jurisdictions | |
| 234 | + _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions); | |
| 227 | 235 | } |
| 228 | 236 | |
| 229 | 237 | Application::~Application() { |
| @@ -485,6 +493,11 @@ void Application::keyPressEvent(QKeyEvent* event) { · 255 unmodified lines | ||
| 485 | 493 | |
| 486 | 494 | bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier); |
| 487 | 495 | switch (event->key()) { |
| 496 | + case Qt::Key_Shift: | |
| 497 | + if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode)) { | |
| 498 | + _pasteMode = true; | |
| 499 | + } | |
| 500 | + break; | |
| 488 | 501 | case Qt::Key_BracketLeft: |
| 489 | 502 | case Qt::Key_BracketRight: |
| 490 | 503 | case Qt::Key_BraceLeft: |
| @@ -716,6 +729,9 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 225 unmodified lines | ||
| 716 | 729 | } |
| 717 | 730 | |
| 718 | 731 | switch (event->key()) { |
| 732 | + case Qt::Key_Shift: | |
| 733 | + _pasteMode = false; | |
| 734 | + break; | |
| 719 | 735 | case Qt::Key_E: |
| 720 | 736 | _myAvatar.setDriveKeys(UP, 0); |
| 721 | 737 | break; |
| @@ -808,6 +824,10 @@ void Application::mousePressEvent(QMouseEvent* event) { · 86 unmodified lines | ||
| 808 | 824 | _pieMenu.mousePressEvent(_mouseX, _mouseY); |
| 809 | 825 | } |
| 810 | 826 | |
| 827 | + if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode) && _pasteMode) { | |
| 828 | + pasteVoxels(); | |
| 829 | + } | |
| 830 | + | |
| 811 | 831 | if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) { |
| 812 | 832 | _hoverVoxelOriginalColor[0] = _hoverVoxel.red; |
| 813 | 833 | _hoverVoxelOriginalColor[1] = _hoverVoxel.green; |
| @@ -1101,6 +1121,7 @@ void Application::setFullscreen(bool fullscreen) { · 287 unmodified lines | ||
| 1101 | 1121 | } |
| 1102 | 1122 | |
| 1103 | 1123 | void Application::setRenderVoxels(bool voxelRender) { |
| 1124 | + _voxelEditSender.setShouldSend(voxelRender); | |
| 1104 | 1125 | if (!voxelRender) { |
| 1105 | 1126 | doKillLocalVoxels(); |
| 1106 | 1127 | } |
| @@ -1185,185 +1206,22 @@ void Application::exportVoxels() { · 78 unmodified lines | ||
| 1185 | 1206 | _window->activateWindow(); |
| 1186 | 1207 | } |
| 1187 | 1208 | |
| 1188 | −const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)"; | |
| 1189 | −void Application::importVoxelsToClipboard() { | |
| 1190 | − QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | |
| 1191 | − QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation, | |
| 1192 | − tr(IMPORT_FILE_TYPES)); | |
| 1193 | − | |
| 1194 | − QByteArray fileNameAscii = fileNameString.toLocal8Bit(); | |
| 1195 | − const char* fileName = fileNameAscii.data(); | |
| 1196 | − | |
| 1197 | − _clipboardTree.eraseAllVoxels(); | |
| 1198 | − if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { | |
| 1199 | − QImage pngImage = QImage(fileName); | |
| 1200 | − if (pngImage.height() != pngImage.width()) { | |
| 1201 | − qDebug("ERROR: Bad PNG size: height != width.\n"); | |
| 1202 | − return; | |
| 1203 | − } | |
| 1204 | − | |
| 1205 | − const uint32_t* pixels; | |
| 1206 | − if (pngImage.format() == QImage::Format_ARGB32) { | |
| 1207 | − pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits()); | |
| 1208 | − } else { | |
| 1209 | − QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32); | |
| 1210 | − pixels = reinterpret_cast<const uint32_t*>(tmp.constBits()); | |
| 1211 | − } | |
| 1212 | − _clipboardTree.readFromSquareARGB32Pixels(pixels, pngImage.height()); | |
| 1213 | − } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) { | |
| 1214 | − _clipboardTree.readFromSVOFile(fileName); | |
| 1215 | − } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) { | |
| 1216 | − _clipboardTree.readFromSchematicFile(fileName); | |
| 1217 | − } | |
| 1218 | − | |
| 1219 | − // restore the main window's active state | |
| 1220 | − _window->activateWindow(); | |
| 1221 | −} | |
| 1222 | − | |
| 1223 | 1209 | void Application::importVoxels() { |
| 1224 | − QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | |
| 1225 | − | |
| 1226 | − QStringList fileNameStringList = QFileDialog::getOpenFileNames(_glWidget, tr("Import Voxels"), desktopLocation, | |
| 1227 | − tr(IMPORT_FILE_TYPES)); | |
| 1228 | − | |
| 1229 | − | |
| 1230 | − // remember the "selected" voxel point before we do any importing... | |
| 1231 | − float originalX = _mouseVoxel.x; | |
| 1232 | − float originalZ = _mouseVoxel.z; | |
| 1233 | − | |
| 1234 | − const int PNG_TYPE_NAME_LENGTH = 4; | |
| 1235 | − const int SVO_TYPE_NAME_LENGTH = 4; | |
| 1236 | − const int SCH_TYPE_NAME_LENGTH = 10; | |
| 1237 | − | |
| 1238 | − // assume this is where we'll place it if filename doesn't have tiling | |
| 1239 | − int unspecifiedColumnNum = 1; | |
| 1240 | − int unspecifiedRowNum = 1; | |
| 1241 | − | |
| 1242 | − // if they select multiple files, but they don't specify the tiling, we | |
| 1243 | − // will tile them to this size | |
| 1244 | − int unspecifiedSquare = (sqrt(fileNameStringList.size()) + 0.5); | |
| 1245 | − qDebug("unspecifiedSquare: %d\n", unspecifiedSquare); | |
| 1246 | − | |
| 1247 | − for (int i = 0; i < fileNameStringList.size(); i++) { | |
| 1248 | − QString fileNameString = fileNameStringList.at(i); | |
| 1249 | − QString extension; | |
| 1250 | − QByteArray fileNameAscii = fileNameString.toLocal8Bit(); | |
| 1251 | − const char* fileName = fileNameAscii.data(); | |
| 1252 | − | |
| 1253 | − int fileTypeNameLength = 0; | |
| 1254 | − VoxelTree importVoxels; | |
| 1255 | − if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { | |
| 1256 | − extension = QString(".png"); | |
| 1257 | − QImage pngImage = QImage(fileName); | |
| 1258 | − fileTypeNameLength = PNG_TYPE_NAME_LENGTH; | |
| 1259 | − if (pngImage.height() != pngImage.width()) { | |
| 1260 | − qDebug("ERROR: Bad PNG size: height != width.\n"); | |
| 1261 | − return; | |
| 1262 | − } | |
| 1263 | − | |
| 1264 | − const uint32_t* pixels; | |
| 1265 | − if (pngImage.format() == QImage::Format_ARGB32) { | |
| 1266 | − pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits()); | |
| 1267 | − } else { | |
| 1268 | − QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32); | |
| 1269 | − pixels = reinterpret_cast<const uint32_t*>(tmp.constBits()); | |
| 1270 | − } | |
| 1271 | − | |
| 1272 | − importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height()); | |
| 1273 | − } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) { | |
| 1274 | − extension = QString(".svo"); | |
| 1275 | − importVoxels.readFromSVOFile(fileName); | |
| 1276 | − fileTypeNameLength = SVO_TYPE_NAME_LENGTH; | |
| 1277 | − } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) { | |
| 1278 | − extension = QString(".schematic"); | |
| 1279 | − importVoxels.readFromSchematicFile(fileName); | |
| 1280 | − fileTypeNameLength = SCH_TYPE_NAME_LENGTH; | |
| 1281 | − } | |
| 1282 | − | |
| 1283 | − // Where we plan to place this | |
| 1284 | − int columnNum = 1; | |
| 1285 | − int rowNum = 1; | |
| 1286 | − bool isTileLocationUnspecified = false; | |
| 1287 | − | |
| 1288 | − // If we're in multi-file mode, then look for tiling specification in the file name | |
| 1289 | − if (fileNameStringList.size() > 1) { | |
| 1290 | − int indexOfFirstPeriod = fileNameString.indexOf('.'); | |
| 1291 | − | |
| 1292 | − //qDebug("indexOfFirstPeriod: %d\n", indexOfFirstPeriod); | |
| 1293 | − | |
| 1294 | − // If the first period, is the extension, then this is not a grid name; | |
| 1295 | − if (fileNameString.mid(indexOfFirstPeriod, fileNameString.length() - indexOfFirstPeriod) == extension) { | |
| 1296 | − qDebug("not a valid grid name... treat like tile Location Unspecified\n"); | |
| 1297 | − isTileLocationUnspecified = true; | |
| 1298 | − } else { | |
| 1299 | − QString fileCoord = fileNameString.mid(indexOfFirstPeriod + 1, | |
| 1300 | − fileNameString.length() - indexOfFirstPeriod - fileTypeNameLength - 1); | |
| 1301 | − | |
| 1302 | − //qDebug() << "fileCoord: " << fileCoord << "\n"; | |
| 1303 | − indexOfFirstPeriod = fileCoord.indexOf('.'); | |
| 1304 | − | |
| 1305 | − //qDebug("indexOfFirstPeriod: %d\n", indexOfFirstPeriod); | |
| 1306 | − | |
| 1307 | − QString columnNumString = fileCoord.right(fileCoord.length() - indexOfFirstPeriod - 1); | |
| 1308 | − QString rowNumString = fileCoord.left(indexOfFirstPeriod); | |
| 1309 | − | |
| 1310 | − //qDebug() << "columnNumString: " << columnNumString << "\n"; | |
| 1311 | − //qDebug() << "rowNumString: " << rowNumString << "\n"; | |
| 1312 | − | |
| 1313 | − columnNum = columnNumString.toFloat(); | |
| 1314 | − rowNum = rowNumString.toFloat(); | |
| 1315 | − | |
| 1316 | − // If there are no "grid sections" in the filename, then we're going to get | |
| 1317 | − if (columnNum < 1 || rowNum < 1) { | |
| 1318 | − qDebug("not a valid grid name... treat like tile Location Unspecified\n"); | |
| 1319 | − isTileLocationUnspecified = true; | |
| 1320 | − } | |
| 1321 | − } | |
| 1322 | − } | |
| 1210 | + if (_voxelImporter.exec()) { | |
| 1211 | + qDebug("[DEBUG] Import succedded.\n"); | |
| 1323 | 1212 | |
| 1324 | − if (isTileLocationUnspecified) { | |
| 1325 | − qDebug("tile Location is Unspecified... \n"); | |
| 1326 | − columnNum = unspecifiedColumnNum; | |
| 1327 | − rowNum = unspecifiedRowNum; | |
| 1328 | − | |
| 1329 | − unspecifiedColumnNum++; | |
| 1330 | − if (unspecifiedColumnNum > unspecifiedSquare) { | |
| 1331 | − unspecifiedColumnNum = 1; | |
| 1332 | − unspecifiedRowNum++; | |
| 1333 | − } | |
| 1334 | − } | |
| 1335 | − qDebug("columnNum: %d\t rowNum: %d\n", columnNum, rowNum); | |
| 1336 | − | |
| 1337 | − _mouseVoxel.x = originalX + (columnNum - 1) * _mouseVoxel.s; | |
| 1338 | − _mouseVoxel.z = originalZ + (rowNum - 1) * _mouseVoxel.s; | |
| 1339 | − | |
| 1340 | − VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); | |
| 1341 | − | |
| 1342 | − // Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to | |
| 1343 | − // the server as an set voxel message, this will also rebase the voxels to the new location | |
| 1344 | − unsigned char* calculatedOctCode = NULL; | |
| 1345 | − SendVoxelsOperationArgs args; | |
| 1346 | − | |
| 1347 | − // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the | |
| 1348 | − // voxel size/position details. | |
| 1349 | − if (selectedNode) { | |
| 1350 | − args.newBaseOctCode = selectedNode->getOctalCode(); | |
| 1351 | − } else { | |
| 1352 | − args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); | |
| 1213 | + if (_voxelImporter.getImportIntoClipboard()) { | |
| 1214 | + _clipboard.killLocalVoxels(); | |
| 1215 | + _voxelImporter.getVoxelSystem()->copySubTreeIntoNewTree( | |
| 1216 | + _voxelImporter.getVoxelSystem()->getVoxelAt(0, 0, 0, 1), | |
| 1217 | + &_clipboard, | |
| 1218 | + true); | |
| 1219 | + _voxelImporter.reset(); | |
| 1353 | 1220 | } |
| 1354 | − | |
| 1355 | − qDebug("column:%d, row:%d, voxel:%f,%f,%f,%f\n", columnNum, rowNum, _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s ); | |
| 1356 | − | |
| 1357 | − // send the insert/paste of these voxels | |
| 1358 | − importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args); | |
| 1359 | − _voxelEditSender.flushQueue(); | |
| 1360 | − | |
| 1361 | − if (calculatedOctCode) { | |
| 1362 | − delete[] calculatedOctCode; | |
| 1363 | − } | |
| 1364 | − | |
| 1221 | + } else { | |
| 1222 | + qDebug("[DEBUG] Import failed.\n"); | |
| 1365 | 1223 | } |
| 1366 | − | |
| 1224 | + | |
| 1367 | 1225 | // restore the main window's active state |
| 1368 | 1226 | _window->activateWindow(); |
| 1369 | 1227 | } |
| @@ -1377,10 +1235,10 @@ void Application::copyVoxels() { · 7 unmodified lines | ||
| 1377 | 1235 | VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); |
| 1378 | 1236 | if (selectedNode) { |
| 1379 | 1237 | // clear the clipboard first... |
| 1380 | − _clipboardTree.eraseAllVoxels(); | |
| 1238 | + _clipboard.killLocalVoxels(); | |
| 1381 | 1239 | |
| 1382 | 1240 | // then copy onto it |
| 1383 | − _voxels.copySubTreeIntoNewTree(selectedNode, &_clipboardTree, true); | |
| 1241 | + _voxels.copySubTreeIntoNewTree(selectedNode, &_clipboard, true); | |
| 1384 | 1242 | } |
| 1385 | 1243 | } |
| 1386 | 1244 | |
| @@ -1401,7 +1259,12 @@ void Application::pasteVoxels() { · 14 unmodified lines | ||
| 1401 | 1259 | args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); |
| 1402 | 1260 | } |
| 1403 | 1261 | |
| 1404 | − _clipboardTree.recurseTreeWithOperation(sendVoxelsOperation, &args); | |
| 1262 | + if (_voxelImporter.getImportWaiting()) { | |
| 1263 | + _voxelImporter.getVoxelSystem()->recurseTreeWithOperation(sendVoxelsOperation, &args); | |
| 1264 | + _voxelImporter.reset(); | |
| 1265 | + } else { | |
| 1266 | + _clipboard.recurseTreeWithOperation(sendVoxelsOperation, &args); | |
| 1267 | + } | |
| 1405 | 1268 | _voxelEditSender.flushQueue(); |
| 1406 | 1269 | |
| 1407 | 1270 | if (calculatedOctCode) { |
| @@ -1443,6 +1306,10 @@ void Application::initDisplay() { · 35 unmodified lines | ||
| 1443 | 1306 | |
| 1444 | 1307 | void Application::init() { |
| 1445 | 1308 | _voxels.init(); |
| 1309 | + _clipboard.init(); | |
| 1310 | + _clipboardViewFrustum.setKeyholeRadius(1000.0f); | |
| 1311 | + _clipboardViewFrustum.calculate(); | |
| 1312 | + _clipboard.setViewFrustum(&_clipboardViewFrustum); | |
| 1446 | 1313 | |
| 1447 | 1314 | _environment.init(); |
| 1448 | 1315 | |
| @@ -2319,6 +2186,23 @@ void Application::displaySide(Camera& whichCamera) { · 870 unmodified lines | ||
| 2319 | 2186 | glEnable(GL_LIGHTING); |
| 2320 | 2187 | } |
| 2321 | 2188 | |
| 2189 | + if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode) && _pasteMode) { | |
| 2190 | + glPushMatrix(); | |
| 2191 | + glTranslatef(_mouseVoxel.x * TREE_SCALE, | |
| 2192 | + _mouseVoxel.y * TREE_SCALE, | |
| 2193 | + _mouseVoxel.z * TREE_SCALE); | |
| 2194 | + glScalef(_mouseVoxel.s * TREE_SCALE, | |
| 2195 | + _mouseVoxel.s * TREE_SCALE, | |
| 2196 | + _mouseVoxel.s * TREE_SCALE); | |
| 2197 | + | |
| 2198 | + if (_voxelImporter.getImportWaiting()) { | |
| 2199 | + _voxelImporter.getVoxelSystem()->render(true); | |
| 2200 | + } else { | |
| 2201 | + _clipboard.render(true); | |
| 2202 | + } | |
| 2203 | + glPopMatrix(); | |
| 2204 | + } | |
| 2205 | + | |
| 2322 | 2206 | _myAvatar.renderScreenTint(SCREEN_TINT_BEFORE_AVATARS, whichCamera); |
| 2323 | 2207 | |
| 2324 | 2208 | if (Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) { |
| @@ -3256,7 +3140,7 @@ void* Application::networkReceive(void* args) { · 931 unmodified lines | ||
| 3256 | 3140 | case PACKET_TYPE_VOXEL_STATS: |
| 3257 | 3141 | case PACKET_TYPE_ENVIRONMENT_DATA: { |
| 3258 | 3142 | // add this packet to our list of voxel packets and process them on the voxel processing |
| 3259 | − app->_voxelProcessor.queuePacket(senderAddress, app->_incomingPacket, bytesReceived); | |
| 3143 | + app->_voxelProcessor.queueReceivedPacket(senderAddress, app->_incomingPacket, bytesReceived); | |
| 3260 | 3144 | break; |
| 3261 | 3145 | } |
| 3262 | 3146 | case PACKET_TYPE_BULK_AVATAR_DATA: |
| @@ -3286,3 +3170,7 @@ void* Application::networkReceive(void* args) { · 23 unmodified lines | ||
| 3286 | 3170 | } |
| 3287 | 3171 | return NULL; |
| 3288 | 3172 | } |
| 3173 | + | |
| 3174 | +void Application::packetSentNotification(ssize_t length) { | |
| 3175 | + _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length); | |
| 3176 | +} | |