Showing the changes to interface/src/Menu.cpp (1 of 64 files). Show all
Unified · Split
| @@ -70,7 +70,8 @@ Menu::Menu() : · 69 unmodified lines | ||
| 70 | 70 | _maxVoxels(DEFAULT_MAX_VOXELS_PER_SYSTEM), |
| 71 | 71 | _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), |
| 72 | 72 | _boundaryLevelAdjust(0), |
| 73 | − _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS) | |
| 73 | + _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), | |
| 74 | + _lastAdjust(usecTimestampNow()) | |
| 74 | 75 | { |
| 75 | 76 | Application *appInstance = Application::getInstance(); |
| 76 | 77 | |
| @@ -168,14 +169,7 @@ Menu::Menu() : · 91 unmodified lines | ||
| 168 | 169 | |
| 169 | 170 | addCheckableActionToQMenuAndActionHash(editMenu, MenuOption::ClickToFly); |
| 170 | 171 | |
| 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); | |
| 179 | 173 | |
| 180 | 174 | QMenu* toolsMenu = addMenu("Tools"); |
| 181 | 175 | |
| @@ -318,6 +312,7 @@ Menu::Menu() : · 136 unmodified lines | ||
| 318 | 312 | addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::VoxelTextures); |
| 319 | 313 | addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::AmbientOcclusion); |
| 320 | 314 | addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::DontFadeOnVoxelServerChanges); |
| 315 | + addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::AutoAdjustLOD); | |
| 321 | 316 | addActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools())); |
| 322 | 317 | |
| 323 | 318 | QMenu* voxelProtoOptionsMenu = voxelOptionsMenu->addMenu("Voxel Server Protocol Options"); |
| @@ -343,6 +338,8 @@ Menu::Menu() : · 19 unmodified lines | ||
| 343 | 338 | SLOT(setTCPEnabled(bool))); |
| 344 | 339 | addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::ChatCircling, 0, false); |
| 345 | 340 | |
| 341 | + addAvatarCollisionSubMenu(avatarOptionsMenu); | |
| 342 | + | |
| 346 | 343 | QMenu* handOptionsMenu = developerMenu->addMenu("Hand Options"); |
| 347 | 344 | |
| 348 | 345 | addCheckableActionToQMenuAndActionHash(handOptionsMenu, |
| @@ -517,6 +514,11 @@ void Menu::loadSettings(QSettings* settings) { · 168 unmodified lines | ||
| 517 | 514 | Application::getInstance()->getProfile()->loadData(settings); |
| 518 | 515 | Application::getInstance()->updateWindowTitle(); |
| 519 | 516 | 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(); | |
| 520 | 522 | } |
| 521 | 523 | |
| 522 | 524 | void Menu::saveSettings(QSettings* settings) { |
| @@ -896,6 +898,17 @@ void Menu::editPreferences() { · 373 unmodified lines | ||
| 896 | 898 | sendFakeEnterEvent(); |
| 897 | 899 | } |
| 898 | 900 | |
| 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 | + | |
| 899 | 912 | void Menu::goToDomain() { |
| 900 | 913 | |
| 901 | 914 | QString currentDomainHostname = NodeList::getInstance()->getDomainHostname(); |
| @@ -920,15 +933,75 @@ void Menu::goToDomain() { · 18 unmodified lines | ||
| 920 | 933 | // the user input a new hostname, use that |
| 921 | 934 | newHostname = domainDialog.textValue(); |
| 922 | 935 | } |
| 936 | + | |
| 937 | + goToDomain(newHostname); | |
| 938 | + } | |
| 923 | 939 | |
| 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 | +} | |
| 926 | 942 | |
| 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 | + } | |
| 929 | 971 | } |
| 972 | +} | |
| 930 | 973 | |
| 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; | |
| 932 | 1005 | } |
| 933 | 1006 | |
| 934 | 1007 | void Menu::goTo() { |
| @@ -946,31 +1019,8 @@ void Menu::goTo() { · 11 unmodified lines | ||
| 946 | 1019 | |
| 947 | 1020 | destination = gotoDialog.textValue(); |
| 948 | 1021 | |
| 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)) { | |
| 974 | 1024 | // there's a username entered by the user, make a request to the data-server |
| 975 | 1025 | DataServerClient::getValuesForKeysAndUserString( |
| 976 | 1026 | QStringList() |
| @@ -1001,29 +1051,7 @@ void Menu::goToLocation() { · 24 unmodified lines | ||
| 1001 | 1051 | |
| 1002 | 1052 | int dialogReturn = coordinateDialog.exec(); |
| 1003 | 1053 | 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()); | |
| 1027 | 1055 | } |
| 1028 | 1056 | |
| 1029 | 1057 | sendFakeEnterEvent(); |
| @@ -1103,14 +1131,38 @@ void Menu::voxelStatsDetailsClosed() { · 73 unmodified lines | ||
| 1103 | 1131 | } |
| 1104 | 1132 | } |
| 1105 | 1133 | |
| 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 | + | |
| 1106 | 1160 | void Menu::setVoxelSizeScale(float sizeScale) { |
| 1107 | 1161 | _voxelSizeScale = sizeScale; |
| 1108 | − Application::getInstance()->getVoxels()->redrawInViewVoxels(); | |
| 1109 | 1162 | } |
| 1110 | 1163 | |
| 1111 | 1164 | void Menu::setBoundaryLevelAdjust(int boundaryLevelAdjust) { |
| 1112 | 1165 | _boundaryLevelAdjust = boundaryLevelAdjust; |
| 1113 | − Application::getInstance()->getVoxels()->redrawInViewVoxels(); | |
| 1114 | 1166 | } |
| 1115 | 1167 | |
| 1116 | 1168 | void Menu::lodTools() { |
| @@ -1192,6 +1244,22 @@ void Menu::updateFrustumRenderModeAction() { · 75 unmodified lines | ||
| 1192 | 1244 | } |
| 1193 | 1245 | } |
| 1194 | 1246 | |
| 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 | + | |
| 1195 | 1263 | QString Menu::replaceLastOccurrence(QChar search, QChar replace, QString string) { |
| 1196 | 1264 | int lastIndex; |
| 1197 | 1265 | lastIndex = string.lastIndexOf(search); |
| @@ -1202,4 +1270,3 @@ QString Menu::replaceLastOccurrence(QChar search, QChar replace, QString string) · 4 unmodified lines | ||
| 1202 | 1270 | |
| 1203 | 1271 | return string; |
| 1204 | 1272 | } |
| 1205 | − | |