History

Merge branch 'master' of https://github.com/worklist/hifi

Andrzej Kapolka committed 13 years ago

Commit 6dbaedd2 parents d63bb3a d6edf9538 files · +1695 −547Browse files

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

Unified · Split

interface/src/Application.cpp+69−181
@@ -82,6 +82,8 @@ const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2; · 81 unmodified lines
8282 // Startup optimistically with small jitter buffer that
8383 // will start playback on the second received audio packet.
8484
85+static const float CLIPBOARD_TREE_SCALE = 1.0f;
86+
8587 void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
8688 fprintf(stdout, "%s", message.toLocal8Bit().constData());
8789 LogDisplay::instance.addMessage(message.toLocal8Bit().constData());
@@ -95,6 +97,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 7 unmodified lines
9597 _frameCount(0),
9698 _fps(120.0f),
9799 _justStarted(true),
100+ _clipboard(CLIPBOARD_TREE_SCALE),
101+ _voxelImporter(_window),
98102 _wantToKillLocalVoxels(false),
99103 _audioScope(256, 200, true),
100104 _mouseX(0),
@@ -119,13 +123,14 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 18 unmodified lines
119123 _audio(&_audioScope, STARTUP_JITTER_SAMPLES),
120124 #endif
121125 _stopNetworkReceiveThread(false),
122− _voxelProcessor(this),
126+ _voxelProcessor(),
123127 _voxelEditSender(this),
124128 _packetCount(0),
125129 _packetsPerSecond(0),
126130 _bytesPerSecond(0),
127131 _bytesCount(0),
128− _swatch(NULL)
132+ _swatch(NULL),
133+ _pasteMode(false)
129134 {
130135 _applicationStartupTime = startup_time;
131136 _window->setWindowTitle("Interface");
@@ -224,6 +229,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 92 unmodified lines
224229 _glWidget->setMouseTracking(true);
225230
226231 // initialization continues in initializeGL when OpenGL context is ready
232+
233+ // Tell our voxel edit sender about our known jurisdictions
234+ _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions);
227235 }
228236
229237 Application::~Application() {
@@ -485,6 +493,11 @@ void Application::keyPressEvent(QKeyEvent* event) { · 255 unmodified lines
485493
486494 bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier);
487495 switch (event->key()) {
496+ case Qt::Key_Shift:
497+ if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode)) {
498+ _pasteMode = true;
499+ }
500+ break;
488501 case Qt::Key_BracketLeft:
489502 case Qt::Key_BracketRight:
490503 case Qt::Key_BraceLeft:
@@ -716,6 +729,9 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 225 unmodified lines
716729 }
717730
718731 switch (event->key()) {
732+ case Qt::Key_Shift:
733+ _pasteMode = false;
734+ break;
719735 case Qt::Key_E:
720736 _myAvatar.setDriveKeys(UP, 0);
721737 break;
@@ -808,6 +824,10 @@ void Application::mousePressEvent(QMouseEvent* event) { · 86 unmodified lines
808824 _pieMenu.mousePressEvent(_mouseX, _mouseY);
809825 }
810826
827+ if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode) && _pasteMode) {
828+ pasteVoxels();
829+ }
830+
811831 if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) {
812832 _hoverVoxelOriginalColor[0] = _hoverVoxel.red;
813833 _hoverVoxelOriginalColor[1] = _hoverVoxel.green;
@@ -1101,6 +1121,7 @@ void Application::setFullscreen(bool fullscreen) { · 287 unmodified lines
11011121 }
11021122
11031123 void Application::setRenderVoxels(bool voxelRender) {
1124+ _voxelEditSender.setShouldSend(voxelRender);
11041125 if (!voxelRender) {
11051126 doKillLocalVoxels();
11061127 }
@@ -1185,185 +1206,22 @@ void Application::exportVoxels() { · 78 unmodified lines
11851206 _window->activateWindow();
11861207 }
11871208
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−
12231209 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");
13231212
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();
13531220 }
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");
13651223 }
1366−
1224+
13671225 // restore the main window's active state
13681226 _window->activateWindow();
13691227 }
@@ -1377,10 +1235,10 @@ void Application::copyVoxels() { · 7 unmodified lines
13771235 VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
13781236 if (selectedNode) {
13791237 // clear the clipboard first...
1380− _clipboardTree.eraseAllVoxels();
1238+ _clipboard.killLocalVoxels();
13811239
13821240 // then copy onto it
1383− _voxels.copySubTreeIntoNewTree(selectedNode, &_clipboardTree, true);
1241+ _voxels.copySubTreeIntoNewTree(selectedNode, &_clipboard, true);
13841242 }
13851243 }
13861244
@@ -1401,7 +1259,12 @@ void Application::pasteVoxels() { · 14 unmodified lines
14011259 args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
14021260 }
14031261
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+ }
14051268 _voxelEditSender.flushQueue();
14061269
14071270 if (calculatedOctCode) {
@@ -1443,6 +1306,10 @@ void Application::initDisplay() { · 35 unmodified lines
14431306
14441307 void Application::init() {
14451308 _voxels.init();
1309+ _clipboard.init();
1310+ _clipboardViewFrustum.setKeyholeRadius(1000.0f);
1311+ _clipboardViewFrustum.calculate();
1312+ _clipboard.setViewFrustum(&_clipboardViewFrustum);
14461313
14471314 _environment.init();
14481315
@@ -2319,6 +2186,23 @@ void Application::displaySide(Camera& whichCamera) { · 870 unmodified lines
23192186 glEnable(GL_LIGHTING);
23202187 }
23212188
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+
23222206 _myAvatar.renderScreenTint(SCREEN_TINT_BEFORE_AVATARS, whichCamera);
23232207
23242208 if (Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) {
@@ -3256,7 +3140,7 @@ void* Application::networkReceive(void* args) { · 931 unmodified lines
32563140 case PACKET_TYPE_VOXEL_STATS:
32573141 case PACKET_TYPE_ENVIRONMENT_DATA: {
32583142 // 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);
32603144 break;
32613145 }
32623146 case PACKET_TYPE_BULK_AVATAR_DATA:
@@ -3286,3 +3170,7 @@ void* Application::networkReceive(void* args) { · 23 unmodified lines
32863170 }
32873171 return NULL;
32883172 }
3173+
3174+void Application::packetSentNotification(ssize_t length) {
3175+ _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length);
3176+}

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