History

merged from master

Jose Carlos committed 12 years ago

Commit e7b54a92 parents 73e0c0c 26d076f64 files · +2478 −500Browse files

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

Unified · Split

interface/src/Menu.cpp+132−65
@@ -70,7 +70,8 @@ Menu::Menu() : · 69 unmodified lines
7070 _maxVoxels(DEFAULT_MAX_VOXELS_PER_SYSTEM),
7171 _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE),
7272 _boundaryLevelAdjust(0),
73− _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS)
73+ _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS),
74+ _lastAdjust(usecTimestampNow())
7475 {
7576 Application *appInstance = Application::getInstance();
7677
@@ -168,14 +169,7 @@ Menu::Menu() : · 91 unmodified lines
168169
169170 addCheckableActionToQMenuAndActionHash(editMenu, MenuOption::ClickToFly);
170171
171− QMenu* collisionsOptionsMenu = editMenu->addMenu("Collision Options");
172−
173− QObject* avatar = appInstance->getAvatar();
174− addCheckableActionToQMenuAndActionHash(collisionsOptionsMenu, MenuOption::CollideWithEnvironment, 0, false, avatar, SLOT(updateCollisionFlags()));
175− addCheckableActionToQMenuAndActionHash(collisionsOptionsMenu, MenuOption::CollideWithAvatars, 0, false, avatar, SLOT(updateCollisionFlags()));
176− addCheckableActionToQMenuAndActionHash(collisionsOptionsMenu, MenuOption::CollideWithVoxels, 0, false, avatar, SLOT(updateCollisionFlags()));
177− // TODO: make this option work
178− //addCheckableActionToQMenuAndActionHash(collisionsOptionsMenu, MenuOption::CollideWithParticles, 0, false, avatar, SLOT(updateCollisionFlags()));
172+ addAvatarCollisionSubMenu(editMenu);
179173
180174 QMenu* toolsMenu = addMenu("Tools");
181175
@@ -318,6 +312,7 @@ Menu::Menu() : · 136 unmodified lines
318312 addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::VoxelTextures);
319313 addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::AmbientOcclusion);
320314 addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::DontFadeOnVoxelServerChanges);
315+ addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::AutoAdjustLOD);
321316 addActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools()));
322317
323318 QMenu* voxelProtoOptionsMenu = voxelOptionsMenu->addMenu("Voxel Server Protocol Options");
@@ -343,6 +338,8 @@ Menu::Menu() : · 19 unmodified lines
343338 SLOT(setTCPEnabled(bool)));
344339 addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::ChatCircling, 0, false);
345340
341+ addAvatarCollisionSubMenu(avatarOptionsMenu);
342+
346343 QMenu* handOptionsMenu = developerMenu->addMenu("Hand Options");
347344
348345 addCheckableActionToQMenuAndActionHash(handOptionsMenu,
@@ -517,6 +514,11 @@ void Menu::loadSettings(QSettings* settings) { · 168 unmodified lines
517514 Application::getInstance()->getProfile()->loadData(settings);
518515 Application::getInstance()->updateWindowTitle();
519516 NodeList::getInstance()->loadData(settings);
517+
518+ // MyAvatar caches some menu options, so we have to update them whenever we load settings.
519+ // TODO: cache more settings in MyAvatar that are checked with very high frequency.
520+ MyAvatar* myAvatar = Application::getInstance()->getAvatar();
521+ myAvatar->updateCollisionFlags();
520522 }
521523
522524 void Menu::saveSettings(QSettings* settings) {
@@ -896,6 +898,17 @@ void Menu::editPreferences() { · 373 unmodified lines
896898 sendFakeEnterEvent();
897899 }
898900
901+void Menu::goToDomain(const QString newDomain) {
902+ if (NodeList::getInstance()->getDomainHostname() != newDomain) {
903+
904+ // send a node kill request, indicating to other clients that they should play the "disappeared" effect
905+ Application::getInstance()->getAvatar()->sendKillAvatar();
906+
907+ // give our nodeList the new domain-server hostname
908+ NodeList::getInstance()->setDomainHostname(newDomain);
909+ }
910+}
911+
899912 void Menu::goToDomain() {
900913
901914 QString currentDomainHostname = NodeList::getInstance()->getDomainHostname();
@@ -920,15 +933,75 @@ void Menu::goToDomain() { · 18 unmodified lines
920933 // the user input a new hostname, use that
921934 newHostname = domainDialog.textValue();
922935 }
936+
937+ goToDomain(newHostname);
938+ }
923939
924− // send a node kill request, indicating to other clients that they should play the "disappeared" effect
925− Application::getInstance()->getAvatar()->sendKillAvatar();
940+ sendFakeEnterEvent();
941+}
926942
927− // give our nodeList the new domain-server hostname
928− NodeList::getInstance()->setDomainHostname(domainDialog.textValue());
943+void Menu::goToOrientation(QString orientation) {
944+
945+ if (orientation.isEmpty()) {
946+ return;
947+ }
948+
949+ QStringList orientationItems = orientation.split(QRegExp("_|,"), QString::SkipEmptyParts);
950+
951+ const int NUMBER_OF_ORIENTATION_ITEMS = 4;
952+ const int W_ITEM = 0;
953+ const int X_ITEM = 1;
954+ const int Y_ITEM = 2;
955+ const int Z_ITEM = 3;
956+
957+ if (orientationItems.size() == NUMBER_OF_ORIENTATION_ITEMS) {
958+
959+ double w = replaceLastOccurrence('-', '.', orientationItems[W_ITEM].trimmed()).toDouble();
960+ double x = replaceLastOccurrence('-', '.', orientationItems[X_ITEM].trimmed()).toDouble();
961+ double y = replaceLastOccurrence('-', '.', orientationItems[Y_ITEM].trimmed()).toDouble();
962+ double z = replaceLastOccurrence('-', '.', orientationItems[Z_ITEM].trimmed()).toDouble();
963+
964+ glm::quat newAvatarOrientation(w, x, y, z);
965+
966+ MyAvatar* myAvatar = Application::getInstance()->getAvatar();
967+ glm::quat avatarOrientation = myAvatar->getOrientation();
968+ if (newAvatarOrientation != avatarOrientation) {
969+ myAvatar->setOrientation(newAvatarOrientation);
970+ }
929971 }
972+}
930973
931− sendFakeEnterEvent();
974+bool Menu::goToDestination(QString destination) {
975+
976+ QStringList coordinateItems = destination.split(QRegExp("_|,"), QString::SkipEmptyParts);
977+
978+ const int NUMBER_OF_COORDINATE_ITEMS = 3;
979+ const int X_ITEM = 0;
980+ const int Y_ITEM = 1;
981+ const int Z_ITEM = 2;
982+ if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
983+
984+ double x = replaceLastOccurrence('-', '.', coordinateItems[X_ITEM].trimmed()).toDouble();
985+ double y = replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM].trimmed()).toDouble();
986+ double z = replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM].trimmed()).toDouble();
987+
988+ glm::vec3 newAvatarPos(x, y, z);
989+
990+ MyAvatar* myAvatar = Application::getInstance()->getAvatar();
991+ glm::vec3 avatarPos = myAvatar->getPosition();
992+ if (newAvatarPos != avatarPos) {
993+ // send a node kill request, indicating to other clients that they should play the "disappeared" effect
994+ MyAvatar::sendKillAvatar();
995+
996+ qDebug("Going To Location: %f, %f, %f...", x, y, z);
997+ myAvatar->setPosition(newAvatarPos);
998+ }
999+
1000+ return true;
1001+ }
1002+
1003+ // no coordinates were parsed
1004+ return false;
9321005 }
9331006
9341007 void Menu::goTo() {
@@ -946,31 +1019,8 @@ void Menu::goTo() { · 11 unmodified lines
9461019
9471020 destination = gotoDialog.textValue();
9481021
949− QStringList coordinateItems = destination.split(QRegExp("_|,"), QString::SkipEmptyParts);
950−
951− const int NUMBER_OF_COORDINATE_ITEMS = 3;
952− const int X_ITEM = 0;
953− const int Y_ITEM = 1;
954− const int Z_ITEM = 2;
955− if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
956−
957− double x = replaceLastOccurrence('-', '.', coordinateItems[X_ITEM].trimmed()).toDouble();
958− double y = replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM].trimmed()).toDouble();
959− double z = replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM].trimmed()).toDouble();
960−
961− glm::vec3 newAvatarPos(x, y, z);
962−
963− MyAvatar* myAvatar = Application::getInstance()->getAvatar();
964− glm::vec3 avatarPos = myAvatar->getPosition();
965− if (newAvatarPos != avatarPos) {
966− // send a node kill request, indicating to other clients that they should play the "disappeared" effect
967− MyAvatar::sendKillAvatar();
968−
969− qDebug("Going To Location: %f, %f, %f...", x, y, z);
970− myAvatar->setPosition(newAvatarPos);
971− }
972−
973− } else {
1022+ // go to coordinate destination or to Username
1023+ if (!goToDestination(destination)) {
9741024 // there's a username entered by the user, make a request to the data-server
9751025 DataServerClient::getValuesForKeysAndUserString(
9761026 QStringList()
@@ -1001,29 +1051,7 @@ void Menu::goToLocation() { · 24 unmodified lines
10011051
10021052 int dialogReturn = coordinateDialog.exec();
10031053 if (dialogReturn == QDialog::Accepted && !coordinateDialog.textValue().isEmpty()) {
1004− QByteArray newCoordinates;
1005−
1006− QString delimiterPattern(",");
1007− QStringList coordinateItems = coordinateDialog.textValue().split(delimiterPattern);
1008−
1009− const int NUMBER_OF_COORDINATE_ITEMS = 3;
1010− const int X_ITEM = 0;
1011− const int Y_ITEM = 1;
1012− const int Z_ITEM = 2;
1013− if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
1014− double x = coordinateItems[X_ITEM].toDouble();
1015− double y = coordinateItems[Y_ITEM].toDouble();
1016− double z = coordinateItems[Z_ITEM].toDouble();
1017− glm::vec3 newAvatarPos(x, y, z);
1018−
1019− if (newAvatarPos != avatarPos) {
1020− // send a node kill request, indicating to other clients that they should play the "disappeared" effect
1021− MyAvatar::sendKillAvatar();
1022−
1023− qDebug("Going To Location: %f, %f, %f...", x, y, z);
1024− myAvatar->setPosition(newAvatarPos);
1025− }
1026− }
1054+ goToDestination(coordinateDialog.textValue());
10271055 }
10281056
10291057 sendFakeEnterEvent();
@@ -1103,14 +1131,38 @@ void Menu::voxelStatsDetailsClosed() { · 73 unmodified lines
11031131 }
11041132 }
11051133
1134+void Menu::autoAdjustLOD(float currentFPS) {
1135+ bool changed = false;
1136+ quint64 now = usecTimestampNow();
1137+ quint64 elapsed = now - _lastAdjust;
1138+
1139+ if (elapsed > ADJUST_LOD_DOWN_DELAY && currentFPS < ADJUST_LOD_DOWN_FPS && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
1140+ _voxelSizeScale *= ADJUST_LOD_DOWN_BY;
1141+ changed = true;
1142+ _lastAdjust = now;
1143+ qDebug() << "adjusting LOD down... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale;
1144+ }
1145+
1146+ if (elapsed > ADJUST_LOD_UP_DELAY && currentFPS > ADJUST_LOD_UP_FPS && _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
1147+ _voxelSizeScale *= ADJUST_LOD_UP_BY;
1148+ changed = true;
1149+ _lastAdjust = now;
1150+ qDebug() << "adjusting LOD up... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale;
1151+ }
1152+
1153+ if (changed) {
1154+ if (_lodToolsDialog) {
1155+ _lodToolsDialog->reloadSliders();
1156+ }
1157+ }
1158+}
1159+
11061160 void Menu::setVoxelSizeScale(float sizeScale) {
11071161 _voxelSizeScale = sizeScale;
1108− Application::getInstance()->getVoxels()->redrawInViewVoxels();
11091162 }
11101163
11111164 void Menu::setBoundaryLevelAdjust(int boundaryLevelAdjust) {
11121165 _boundaryLevelAdjust = boundaryLevelAdjust;
1113− Application::getInstance()->getVoxels()->redrawInViewVoxels();
11141166 }
11151167
11161168 void Menu::lodTools() {
@@ -1192,6 +1244,22 @@ void Menu::updateFrustumRenderModeAction() { · 75 unmodified lines
11921244 }
11931245 }
11941246
1247+void Menu::addAvatarCollisionSubMenu(QMenu* overMenu) {
1248+ // add avatar collisions subMenu to overMenu
1249+ QMenu* subMenu = overMenu->addMenu("Collision Options");
1250+
1251+ Application* appInstance = Application::getInstance();
1252+ QObject* avatar = appInstance->getAvatar();
1253+ addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithEnvironment,
1254+ 0, false, avatar, SLOT(updateCollisionFlags()));
1255+ addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithAvatars,
1256+ 0, true, avatar, SLOT(updateCollisionFlags()));
1257+ addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithVoxels,
1258+ 0, false, avatar, SLOT(updateCollisionFlags()));
1259+ addCheckableActionToQMenuAndActionHash(subMenu, MenuOption::CollideWithParticles,
1260+ 0, true, avatar, SLOT(updateCollisionFlags()));
1261+}
1262+
11951263 QString Menu::replaceLastOccurrence(QChar search, QChar replace, QString string) {
11961264 int lastIndex;
11971265 lastIndex = string.lastIndexOf(search);
@@ -1202,4 +1270,3 @@ QString Menu::replaceLastOccurrence(QChar search, QChar replace, QString string) · 4 unmodified lines
12021270
12031271 return string;
12041272 }
1205−

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