diff --git a/.gitignore b/.gitignore index 34f11c273a..3b44b99e68 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,12 @@ interface/resources/visage/* # Ignore interfaceCache for Linux users interface/interfaceCache/ + +# ignore audio-client externals +libraries/audio-client/external/*/* +!libraries/audio-client/external/*/readme.txt + +gvr-interface/assets/oculussig* +gvr-interface/libs/* + +TAGS \ No newline at end of file diff --git a/BUILD.md b/BUILD.md index c7b343baa1..f7dc22882a 100644 --- a/BUILD.md +++ b/BUILD.md @@ -1,18 +1,26 @@ ###Dependencies * [cmake](http://www.cmake.org/cmake/resources/software.html) ~> 2.8.12.2 -* [Qt](http://qt-project.org/downloads) ~> 5.3.0 -* [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.4 +* [Qt](http://qt-project.org/downloads) ~> 5.3.2 * [OpenSSL](https://www.openssl.org/related/binaries.html) ~> 1.0.1g * IMPORTANT: OpenSSL 1.0.1g is critical to avoid a security vulnerability. * [Intel Threading Building Blocks](https://www.threadingbuildingblocks.org/) ~> 4.3 +* [Soxr](http://sourceforge.net/projects/soxr/) ~> 0.1.1 * [Bullet Physics Engine](https://code.google.com/p/bullet/downloads/list) ~> 2.82 * [Gverb](https://github.com/highfidelity/gverb/archive/master.zip) (direct download to latest version) +#### CMake External Project Dependencies + +The following dependencies will be downloaded, built, linked and included automatically by CMake where we require them. The CMakeLists files that handle grabbing each of the following external dependencies can be found in the [cmake/externals folder](cmake/externals). The resulting downloads, source files and binaries will be placed in the `build` directory in each of the subfolders for each external project. These are not placed in your normal build tree when doing an out of source build so that they do not need to be re-downloaded and re-compiled every time the CMake build folder is cleared. + +* [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.4 +* [gverb](https://github.com/highfidelity/gverb) + ### OS Specific Build Guides -* [BUILD_WIN.md](BUILD_WIN.md) - additional instructions for Windows. * [BUILD_OSX.md](BUILD_OSX.md) - additional instructions for OS X. * [BUILD_LINUX.md](BUILD_LINUX.md) - additional instructions for Linux. +* [BUILD_WIN.md](BUILD_WIN.md) - additional instructions for Windows. +* [BUILD_ANDROID.md](BUILD_ANDROID.md) - additional instructions for Android ###CMake Hifi uses CMake to generate build files and project files for your platform. diff --git a/BUILD_ANDROID.md b/BUILD_ANDROID.md new file mode 100644 index 0000000000..6ff3160775 --- /dev/null +++ b/BUILD_ANDROID.md @@ -0,0 +1,143 @@ +Please read the [general build guide](BUILD.md) for information on dependencies required for all platforms. Only Android specific instructions are found in this file. + +###Android Dependencies + +You will need the following tools to build our Android targets. + +* [cmake](http://www.cmake.org/download/) ~> 3.1.0 + * Note that this is a newer version required than the minimum for hifi desktop targets. +* [Qt](http://www.qt.io/download-open-source/#) ~> 5.4.0 + * Note that this is a newer version required than the minimum for hifi desktop targets. +* [ant](http://ant.apache.org/bindownload.cgi) ~> 1.9.4 +* [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html) = r10c +* [Android SDK](http://developer.android.com/sdk/installing/index.html) ~> 24.0.2 + * Install the latest Platform-tools + * Install the latest Build-tools + * Install the SDK Platform for API Level 19 + * Install Sources for Android SDK for API Level 19 + * Install the ARM EABI v7a System Image if you want to run an emulator. + +You will also need to cross-compile the dependencies required for all platforms for Android, and help CMake find these compiled libraries on your machine. + +####Optional Components + +* [Oculus Mobile SDK](https://developer.oculus.com/downloads/#sdk=mobile) ~> 0.4.2 + +####ANDROID_LIB_DIR + +Since you won't be installing Android dependencies to system paths on your development machine, CMake will need a little help tracking down your Android dependencies. + +This is most easily accomplished by installing all Android dependencies in the same folder. You can place this folder wherever you like on your machine. In this build guide and across our CMakeLists files this folder is referred to as `ANDROID_LIB_DIR`. You can set `ANDROID_LIB_DIR` in your environment or by passing when you run CMake. + +####Qt + +Install Qt 5.4 for Android for your host environment from the [Qt downloads page](http://www.qt.io/download/). Install Qt to ``$ANDROID_LIB_DIR/Qt``. This is required so that our root CMakeLists file can help CMake find your Android Qt installation. + +The component required for the Android build is the `Android armv7` component. + +If you would like to install Qt to a different location, or attempt to build with a different Qt version, you can pass `ANDROID_QT_CMAKE_PREFIX_PATH` to CMake. Point to the `cmake` folder inside `$VERSION_NUMBER/android_armv7/lib`. Otherwise, our root CMakeLists will set it to `$ANDROID_LIB_DIR/Qt/5.3/android_armv7/lib/cmake`. + +####OpenSSL + +Cross-compilation of OpenSSL has been tested from an OS X machine running 10.10 compiling OpenSSL 1.0.2. It is likely that the steps below will work for other OpenSSL versions than 1.0.2. + +The original instructions to compile OpenSSL for Android from your host environment can be found [here](http://wiki.openssl.org/index.php/Android). We required some tweaks to get OpenSSL to successfully compile, those tweaks are explained below. + +Download the [OpenSSL source](https://www.openssl.org/source/) and extract the tarball inside your `ANDROID_LIB_DIR`. Rename the extracted folder to `openssl`. + +You will need the [setenv-android.sh script](http://wiki.openssl.org/index.php/File:Setenv-android.sh) from the OpenSSL wiki. + +You must change three values at the top of the `setenv-android.sh` script - `_ANDROID_NDK`, `_ANDROID_EABI` and `_ANDROID_API`. +`_ANDROID_NDK` should be `android-ndk-r10`, `_ANDROID_EABI` should be `arm-linux-androidebi-4.9` and `_ANDROID_API` should be `19`. + +First, make sure `ANDROID_NDK_ROOT` is set in your env. This should be the path to the root of your Android NDK install. `setenv-android.sh` needs `ANDROID_NDK_ROOT` to set the environment variables required for building OpenSSL. + +Source the `setenv-android.sh` script so it can set environment variables that OpenSSL will use while compiling. If you use zsh as your shell you may need to modify the `setenv-android.sh` for it to set the correct variables in your env. + +``` +export ANDROID_NDK_ROOT=YOUR_NDK_ROOT +source setenv-android.sh +``` + +Then, from the OpenSSL directory, run the following commands. + +``` +perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org +./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API +make depend +make all +``` + +This should generate libcrypto and libssl in the root of the OpenSSL directory. YOU MUST remove the `libssl.so` and `libcrypto.so` files that are generated. They are symlinks to `libssl.so.VER` and `libcrypto.so.VER` which Android does not know how to handle. By removing `libssl.so` and `libcrypto.so` the FindOpenSSL module will find the static libs and use those instead. + +If you have been building other components it is possible that the OpenSSL compile will fail based on the values other cross-compilations (tbb, bullet) have set. Ensure that you are in a new terminal window to avoid compilation errors from previously set environment variables. + +####Intel Threading Building Blocks + +Download the [Intel Threading Building Blocks source](https://www.threadingbuildingblocks.org/download) and extract the tarball inside your `ANDROID_LIB_DIR`. Rename the extracted folder to `tbb`. + +NOTE: BEFORE YOU ATTEMPT TO CROSS-COMPILE TBB, DISCONNECT ANY DEVICES ADB WOULD DETECT. The tbb build process asks adb for a couple of strings, and if a device is plugged in extra characters get added that will cause ndk-build to fail with an error. + +From the tbb directory, execute the following commands. First, we build TBB using `ndk-build`. Then, the compiled libs are copied to a lib folder in the root of tbb directory. + +``` +cd jni +ndk-build target=android tbb tbbmalloc arch=arm +cd ../ +mkdir lib +cp `find . -name "*.so"` lib/ +``` + +####Soxr + +Download the [Soxr source](http://sourceforge.net/projects/soxr/) and extract the tarball inside your `ANDROID_LIB_DIR`. Rename the extracted folder to `soxr`. + +From the soxr directory, use cmake, along with the `android.toolchain.cmake` file (included in this repository under cmake/android) to cross-compile soxr for Android. Note that you will need ANDROID_NDK set in your environment before using the toolchain file. + +The full set of commands to build soxr for Android is shown below. It is a long command, make sure you copy the entire command (up to `-DBUILD_TESTS=0`). + +``` +cmake -DCMAKE_TOOLCHAIN_FILE=$FULL_PATH_TO_TOOLCHAIN -DCMAKE_INSTALL_PREFIX=. -DHAVE_WORDS_BIGENDIAN_EXITCODE=1 -DBUILD_TESTS=0 +make +make install +``` + +This will create the `lib` and `include` folders inside `ANDROID_LIB_DIR/soxr` that FindSoxr will look for. + +####Oculus Mobile SDK + +The Oculus Mobile SDK is optional, for Gear VR support. It is not required to compile gvr-interface. + +Download the [Oculus Mobile SDK](https://developer.oculus.com/downloads/#sdk=mobile) and extract the archive inside your `ANDROID_LIB_DIR` folder. Rename the extracted folder to `libovr`. + +From the VRLib directory, use ndk-build to build VrLib. + +``` +cd VRLib +ndk-build +``` + +This will create the liboculus.a archive that our FindLibOVR module will look for when cmake is run. + +#####Hybrid testing + +Currently the 'vr_dual' mode that would allow us to run a hybrid app has limited support in the Oculus Mobile SDK. The best way to have an application we can launch without having to connect to the GearVR is to put the Gear VR Service into developer mode. This stops Oculus Home from taking over the device when it is plugged into the Gear VR headset, and allows the application to be launched from the Applications page. + +To put the Gear VR Service into developer mode you need an application with an Oculus Signature File on your device. Generate an Oculus Signature File for your device on the [Oculus osig tool page](https://developer.oculus.com/tools/osig/). Place this file in the gvr-interface/assets directory. Cmake will automatically copy it into your apk in the right place when you execute `make gvr-interface-apk`. + +Once the application is on your device, go to `Settings->Application Manager->Gear VR Service->Manage Storage`. Tap on `VR Service Version` six times. It will scan your device to verify that you have an osig file in an application on your device, and then it will let you enable Developer mode. + + +###CMake + +We use CMake to generate the makefiles that compile and deploy the Android APKs to your device. In order to create Makefiles for the Android targets, CMake requires that some environment variables are set, and that other variables are passed to it when it is run. + +The following must be set in your environment: + +* ANDROID_NDK - the root of your Android NDK install +* ANDROID_HOME - the root of your Android SDK install +* ANDROID_LIB_DIR - the directory containing cross-compiled versions of dependencies + +The following must be passed to CMake when it is run: + +* USE_ANDROID_TOOLCHAIN - set to true to build for Android \ No newline at end of file diff --git a/BUILD_OSX.md b/BUILD_OSX.md index cd947f2af4..2d5460d39d 100644 --- a/BUILD_OSX.md +++ b/BUILD_OSX.md @@ -4,7 +4,7 @@ Please read the [general build guide](BUILD.md) for information on dependencies [Homebrew](http://brew.sh/) is an excellent package manager for OS X. It makes install of all hifi dependencies very simple. brew tap highfidelity/homebrew-formulas - brew install cmake glm openssl tbb + brew install cmake openssl tbb libsoxr brew install highfidelity/formulas/qt5 brew link qt5 --force diff --git a/BUILD_WIN.md b/BUILD_WIN.md index 27f0e02ea7..f5bc3e09b5 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -56,9 +56,6 @@ The recommended route for CMake to find the external dependencies is to place al -> bin -> include -> lib - -> glm - -> glm - -> glm.hpp -> openssl -> bin -> include @@ -129,26 +126,6 @@ Download the binary package: `glew-1.10.0-win32.zip`. Extract to %HIFI_LIB_DIR%\ Add to the PATH: `%HIFI_LIB_DIR%\glew\bin\Release\Win32` -###GLM - -This package contains only headers, so there's nothing to add to the PATH. - -Be careful with glm. For the folder other libraries would normally call 'include', the folder containing the headers, glm opts to use 'glm'. You will have a glm folder nested inside the top-level glm folder. - -###Gverb - -1. Go to https://github.com/highfidelity/gverb - Or download the sources directly via this link: - https://github.com/highfidelity/gverb/archive/master.zip - -2. Extract the archive - -3. Place the directories “include” and “src” in interface/external/gverb - (Normally next to this readme) - -4. Clear your build directory, run cmake, build and you should be all set. - - ###Bullet Bullet 2.82 source can be [downloaded here](https://code.google.com/p/bullet/downloads/detail?name=bullet-2.82-r2704.zip). Bullet does not come with prebuilt libraries, you need to make those yourself. @@ -167,7 +144,7 @@ cmake .. -G "Visual Studio 12" msbuild BULLET_PHYSICS.sln /p:Configuration=Debug ``` -This will create Debug libraries in cmakebuild\lib\Debug you can replace Debug with Release in the msbuild command and that will generate Release libraries in cmakebuild\lib\Release. +This will create Debug libraries in cmakebuild\lib\Debug. You can replace Debug with Release in the msbuild command and that will generate Release libraries in cmakebuild\lib\Release. You now have Bullet libraries compiled, now you need to put them in the right place for hifi to find them: @@ -178,6 +155,22 @@ You now have Bullet libraries compiled, now you need to put them in the right pl _Note that the INSTALL target should handle the copying of files into an install directory automatically, however, without modifications to Cmake, the install target didn't work right for me, please update this instructions if you get that working right - Leo <leo@highfidelity.io>_ +###Soxr + +Download the zip from the [soxr sourceforge page](http://sourceforge.net/projects/soxr/). + +We recommend you install it to %HIFI_LIB_DIR%\soxr. This will help our FindSoxr cmake module find what it needs. You can place it wherever you like on your machine if you specify SOXR_ROOT_DIR as an environment variable or a variable passed when cmake is run. + +Extract the soxr archive wherever you like. Then, inside the extracted folder, create a directory called `build`. From that build directory, the following commands will build and then install soxr to `%HIFI_LIB_DIR%`. + +(Make sure to run the following inside Visual Studio) + +``` +cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%HIFI_LIB_DIR%/soxr +nmake +nmake install +``` + ###Build High Fidelity using Visual Studio Follow the same build steps from the CMake section of [BUILD.md](BUILD.md), but pass a different generator to CMake. diff --git a/CMakeLists.txt b/CMakeLists.txt index 367fb88a26..bc67d622de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,10 @@ cmake_minimum_required(VERSION 2.8.12.2) +if (USE_ANDROID_TOOLCHAIN) + set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/android/android.toolchain.cmake") + set(ANDROID_NATIVE_API_LEVEL 19) +endif () + if (WIN32) cmake_policy(SET CMP0020 NEW) endif (WIN32) @@ -35,7 +40,7 @@ if (WIN32) elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic") #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-strict-aliasing") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-strict-aliasing -ggdb") endif(WIN32) if (NOT MSVC12) @@ -58,8 +63,27 @@ if (APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --stdlib=libc++") endif () -if (NOT QT_CMAKE_PREFIX_PATH) - set(QT_CMAKE_PREFIX_PATH $ENV{QT_CMAKE_PREFIX_PATH}) +if (NOT ANDROID_LIB_DIR) + set(ANDROID_LIB_DIR $ENV{ANDROID_LIB_DIR}) +endif () + +if (ANDROID) + if (NOT ANDROID_QT_CMAKE_PREFIX_PATH) + set(QT_CMAKE_PREFIX_PATH ${ANDROID_LIB_DIR}/Qt/5.4/android_armv7/lib/cmake) + else () + set(QT_CMAKE_PREFIX_PATH ${ANDROID_QT_CMAKE_PREFIX_PATH}) + endif () + + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) + + if (ANDROID_LIB_DIR) + list(APPEND CMAKE_FIND_ROOT_PATH ${ANDROID_LIB_DIR}) + endif () +else () + if (NOT QT_CMAKE_PREFIX_PATH) + set(QT_CMAKE_PREFIX_PATH $ENV{QT_CMAKE_PREFIX_PATH}) + endif () endif () set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT_CMAKE_PREFIX_PATH}) @@ -71,6 +95,8 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.8) set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) +# Instruct CMake to run rcc automatically when needed +set(CMAKE_AUTORCC ON) set(HIFI_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries") @@ -78,16 +104,30 @@ set(HIFI_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") set(MACRO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros") +set(EXTERNAL_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/externals") file(GLOB HIFI_CUSTOM_MACROS "cmake/macros/*.cmake") foreach(CUSTOM_MACRO ${HIFI_CUSTOM_MACROS}) include(${CUSTOM_MACRO}) endforeach() -# targets on all platforms -add_subdirectory(assignment-client) -add_subdirectory(domain-server) -add_subdirectory(ice-server) -add_subdirectory(interface) -add_subdirectory(tests) -add_subdirectory(tools) +if (ANDROID) + file(GLOB ANDROID_CUSTOM_MACROS "cmake/android/*.cmake") + foreach(CUSTOM_MACRO ${ANDROID_CUSTOM_MACROS}) + include(${CUSTOM_MACRO}) + endforeach() +endif () + +# add subdirectories for all targets +if (NOT ANDROID) + add_subdirectory(assignment-client) + add_subdirectory(domain-server) + add_subdirectory(ice-server) + add_subdirectory(interface) + add_subdirectory(tests) + add_subdirectory(tools) +endif () + +if (ANDROID OR DESKTOP_GVR) + add_subdirectory(gvr-interface) +endif () \ No newline at end of file diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index b56eea5c90..b16314811b 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -2,7 +2,9 @@ set(TARGET_NAME assignment-client) setup_hifi_project(Core Gui Network Script Widgets) -include_glm() +add_dependency_external_project(glm) +find_package(GLM REQUIRED) +target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) # link in the shared libraries link_hifi_libraries( diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index cb1666536f..4755d9137a 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -39,13 +39,14 @@ Agent::Agent(const QByteArray& packet) : _receivedAudioStream(AudioConstants::NETWORK_FRAME_SAMPLES_STEREO, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES, InboundAudioStream::Settings(0, false, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES, false, DEFAULT_WINDOW_STARVE_THRESHOLD, DEFAULT_WINDOW_SECONDS_FOR_DESIRED_CALC_ON_TOO_MANY_STARVES, - DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false)), - _avatarHashMap() + DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false)) { // be the parent of the script engine so it gets moved when we do _scriptEngine.setParent(this); _scriptEngine.getEntityScriptingInterface()->setPacketSender(&_entityEditSender); + + DependencyManager::set(); } void Agent::readPendingDatagrams() { @@ -133,7 +134,7 @@ void Agent::readPendingDatagrams() { || datagramPacketType == PacketTypeAvatarBillboard || datagramPacketType == PacketTypeKillAvatar) { // let the avatar hash map process it - _avatarHashMap.processAvatarMixerDatagram(receivedPacket, nodeList->sendingNodeForPacket(receivedPacket)); + DependencyManager::get()->processAvatarMixerDatagram(receivedPacket, nodeList->sendingNodeForPacket(receivedPacket)); // let this continue through to the NodeList so it updates last heard timestamp // for the sending avatar-mixer @@ -200,14 +201,14 @@ void Agent::run() { // give this AvatarData object to the script engine _scriptEngine.setAvatarData(&scriptedAvatar, "Avatar"); - _scriptEngine.setAvatarHashMap(&_avatarHashMap, "AvatarList"); + _scriptEngine.setAvatarHashMap(DependencyManager::get().data(), "AvatarList"); // register ourselves to the script engine _scriptEngine.registerGlobalObject("Agent", this); _scriptEngine.init(); // must be done before we set up the viewers - _scriptEngine.registerGlobalObject("SoundCache", &SoundCache::getInstance()); + _scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get().data()); _scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer); _entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener()); diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index ffae3c6c21..415b14c0da 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -63,8 +62,6 @@ private: MixedAudioStream _receivedAudioStream; float _lastReceivedAudioLoudness; - - AvatarHashMap _avatarHashMap; }; #endif // hifi_Agent_h diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 709f318d2c..80f3cbab5e 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : DependencyManager::registerInheritance(); auto addressManager = DependencyManager::set(); auto nodeList = DependencyManager::set(NodeType::Unassigned); + auto avatarHashMap = DependencyManager::set(); // setup a shutdown event listener to handle SIGTERM or WM_CLOSE for us #ifdef _WIN32 @@ -134,7 +136,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : // Create Singleton objects on main thread NetworkAccessManager::getInstance(); - SoundCache::getInstance(); + auto soundCache = DependencyManager::get(); } void AssignmentClient::sendAssignmentRequest() { diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index b7dfdd9b24..b862cd0c78 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -648,6 +648,7 @@ void AudioMixer::run() { // setup a QThread with us as parent that will house the AudioMixerDatagramProcessor _datagramProcessingThread = new QThread(this); + _datagramProcessingThread->setObjectName("Datagram Processor Thread"); // create an AudioMixerDatagramProcessor and move it to that thread AudioMixerDatagramProcessor* datagramProcessor = new AudioMixerDatagramProcessor(nodeList->getNodeSocket(), thread()); diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index d882ea19ac..85d0a7414c 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -147,3 +147,14 @@ void EntityServer::pruneDeletedEntities() { } } +void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectionObject) { + bool wantEditLogging = false; + readOptionBool(QString("wantEditLogging"), settingsSectionObject, wantEditLogging); + qDebug("wantEditLogging=%s", debug::valueOf(wantEditLogging)); + + + EntityTree* tree = static_cast(_tree); + tree->setWantEditLogging(wantEditLogging); +} + + diff --git a/assignment-client/src/entities/EntityServer.h b/assignment-client/src/entities/EntityServer.h index d072d18cdf..d8c2e39f3b 100644 --- a/assignment-client/src/entities/EntityServer.h +++ b/assignment-client/src/entities/EntityServer.h @@ -41,6 +41,7 @@ public: virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent); virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode); + virtual void readAdditionalConfiguration(const QJsonObject& settingsSectionObject); public slots: void pruneDeletedEntities(); diff --git a/assignment-client/src/metavoxels/MetavoxelServer.cpp b/assignment-client/src/metavoxels/MetavoxelServer.cpp index 5c4591cf61..669972cbee 100644 --- a/assignment-client/src/metavoxels/MetavoxelServer.cpp +++ b/assignment-client/src/metavoxels/MetavoxelServer.cpp @@ -271,9 +271,10 @@ void MetavoxelSession::handleMessage(const QVariant& message) { _lodPacketNumber = _sequencer.getIncomingPacketNumber(); } else if (userType == MetavoxelEditMessage::Type) { - QMetaObject::invokeMethod(_sender->getServer(), "applyEdit", Q_ARG(const MetavoxelEditMessage&, - message.value())); - + if (_node->getCanAdjustLocks()) { + QMetaObject::invokeMethod(_sender->getServer(), "applyEdit", + Q_ARG(const MetavoxelEditMessage&, message.value())); + } } else if (userType == QMetaType::QVariantList) { foreach (const QVariant& element, message.toList()) { handleMessage(element); diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index aaf37c2beb..85d4749b27 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -879,6 +879,7 @@ void OctreeServer::setupDatagramProcessingThread() { // setup a QThread with us as parent that will house the OctreeServerDatagramProcessor _datagramProcessingThread = new QThread(this); + _datagramProcessingThread->setObjectName("Octree Datagram Processor"); // create an OctreeServerDatagramProcessor and move it to that thread OctreeServerDatagramProcessor* datagramProcessor = new OctreeServerDatagramProcessor(nodeList->getNodeSocket(), thread()); diff --git a/cmake/android/AndroidManifest.xml.in b/cmake/android/AndroidManifest.xml.in new file mode 100755 index 0000000000..aa834f3384 --- /dev/null +++ b/cmake/android/AndroidManifest.xml.in @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${ANDROID_EXTRA_ACTIVITY_XML} + + + + + + ${ANDROID_EXTRA_APPLICATION_XML} + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cmake/android/QtCreateAPK.cmake b/cmake/android/QtCreateAPK.cmake new file mode 100644 index 0000000000..a8543a5fbc --- /dev/null +++ b/cmake/android/QtCreateAPK.cmake @@ -0,0 +1,162 @@ +# +# QtCreateAPK.cmake +# +# Created by Stephen Birarda on 11/18/14. +# Copyright 2013 High Fidelity, Inc. +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# + +# +# OPTIONS +# These options will modify how QtCreateAPK behaves. May be useful if somebody wants to fork. +# For High Fidelity purposes these should not need to be changed. +# +set(ANDROID_THIS_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) # Directory this CMake file is in + +if (POLICY CMP0026) + cmake_policy(SET CMP0026 OLD) +endif () + +macro(qt_create_apk) + if(ANDROID_APK_FULLSCREEN) + set(ANDROID_APK_THEME "android:theme=\"@android:style/Theme.NoTitleBar.Fullscreen\"") + else() + set(ANDROID_APK_THEME "") + endif() + + if (CMAKE_BUILD_TYPE MATCHES RELEASE) + set(ANDROID_APK_DEBUGGABLE "false") + set(ANDROID_APK_RELEASE_LOCAL ${ANDROID_APK_RELEASE}) + else () + set(ANDROID_APK_DEBUGGABLE "true") + set(ANDROID_APK_RELEASE_LOCAL "0") + endif () + + # Create "AndroidManifest.xml" + configure_file("${ANDROID_THIS_DIRECTORY}/AndroidManifest.xml.in" "${ANDROID_APK_BUILD_DIR}/AndroidManifest.xml") + + # create "strings.xml" + configure_file("${ANDROID_THIS_DIRECTORY}/strings.xml.in" "${ANDROID_APK_BUILD_DIR}/res/values/strings.xml") + + # figure out where the qt dir is + get_filename_component(QT_DIR "${QT_CMAKE_PREFIX_PATH}/../../" ABSOLUTE) + + # find androiddeployqt + find_program(ANDROID_DEPLOY_QT androiddeployqt HINTS "${QT_DIR}/bin") + + # set the path to our app shared library + set(EXECUTABLE_DESTINATION_PATH "${ANDROID_APK_OUTPUT_DIR}/libs/${ANDROID_ABI}/lib${TARGET_NAME}.so") + + # add our dependencies to the deployment file + get_property(_DEPENDENCIES TARGET ${TARGET_NAME} PROPERTY INTERFACE_LINK_LIBRARIES) + + foreach(_IGNORE_COPY IN LISTS IGNORE_COPY_LIBS) + list(REMOVE_ITEM _DEPENDENCIES ${_IGNORE_COPY}) + endforeach() + + foreach(_DEP IN LISTS _DEPENDENCIES) + if (NOT TARGET ${_DEP}) + list(APPEND _DEPS_LIST ${_DEP}) + else () + if(NOT _DEP MATCHES "Qt5::.*") + get_property(_DEP_LOCATION TARGET ${_DEP} PROPERTY "LOCATION_${CMAKE_BUILD_TYPE}") + + # recurisvely add libraries which are dependencies of this target + get_property(_DEP_DEPENDENCIES TARGET ${_DEP} PROPERTY INTERFACE_LINK_LIBRARIES) + + foreach(_SUB_DEP IN LISTS _DEP_DEPENDENCIES) + if (NOT TARGET ${_SUB_DEP} AND NOT _SUB_DEP MATCHES "Qt5::.*") + list(APPEND _DEPS_LIST ${_SUB_DEP}) + endif() + endforeach() + + list(APPEND _DEPS_LIST ${_DEP_LOCATION}) + endif() + endif () + endforeach() + + list(REMOVE_DUPLICATES _DEPS_LIST) + + # just copy static libs to apk libs folder - don't add to deps list + foreach(_LOCATED_DEP IN LISTS _DEPS_LIST) + if (_LOCATED_DEP MATCHES "\\.a$") + add_custom_command( + TARGET ${TARGET_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${_LOCATED_DEP} "${ANDROID_APK_OUTPUT_DIR}/libs/${ANDROID_ABI}" + ) + list(REMOVE_ITEM _DEPS_LIST ${_LOCATED_DEP}) + endif () + endforeach() + + string(REPLACE ";" "," _DEPS "${_DEPS_LIST}") + + configure_file("${ANDROID_THIS_DIRECTORY}/deployment-file.json.in" "${TARGET_NAME}-deployment.json") + + # copy the res folder from the target to the apk build dir + add_custom_target( + ${TARGET_NAME}-copy-res + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/res" "${ANDROID_APK_BUILD_DIR}/res" + ) + + # copy the assets folder from the target to the apk build dir + add_custom_target( + ${TARGET_NAME}-copy-assets + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/assets" "${ANDROID_APK_BUILD_DIR}/assets" + ) + + # copy the java folder from src to the apk build dir + add_custom_target( + ${TARGET_NAME}-copy-java + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/java" "${ANDROID_APK_BUILD_DIR}/src" + ) + + # copy the libs folder from src to the apk build dir + add_custom_target( + ${TARGET_NAME}-copy-libs + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/libs" "${ANDROID_APK_BUILD_DIR}/libs" + ) + + # handle setup for ndk-gdb + add_custom_target(${TARGET_NAME}-gdb DEPENDS ${TARGET_NAME}) + + if (ANDROID_APK_DEBUGGABLE) + get_property(TARGET_LOCATION TARGET ${TARGET_NAME} PROPERTY LOCATION) + + set(GDB_SOLIB_PATH ${ANDROID_APK_BUILD_DIR}/obj/local/${ANDROID_NDK_ABI_NAME}/) + + # generate essential Android Makefiles + file(WRITE ${ANDROID_APK_BUILD_DIR}/jni/Android.mk "APP_ABI := ${ANDROID_NDK_ABI_NAME}\n") + file(WRITE ${ANDROID_APK_BUILD_DIR}/jni/Application.mk "APP_ABI := ${ANDROID_NDK_ABI_NAME}\n") + + # create gdb.setup + get_directory_property(PROJECT_INCLUDES DIRECTORY ${PROJECT_SOURCE_DIR} INCLUDE_DIRECTORIES) + string(REGEX REPLACE ";" " " PROJECT_INCLUDES "${PROJECT_INCLUDES}") + file(WRITE ${ANDROID_APK_BUILD_DIR}/libs/${ANDROID_NDK_ABI_NAME}/gdb.setup "set solib-search-path ${GDB_SOLIB_PATH}\n") + file(APPEND ${ANDROID_APK_BUILD_DIR}/libs/${ANDROID_NDK_ABI_NAME}/gdb.setup "directory ${PROJECT_INCLUDES}\n") + + # copy lib to obj + add_custom_command(TARGET ${TARGET_NAME}-gdb PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${GDB_SOLIB_PATH}) + add_custom_command(TARGET ${TARGET_NAME}-gdb PRE_BUILD COMMAND cp ${TARGET_LOCATION} ${GDB_SOLIB_PATH}) + + # strip symbols + add_custom_command(TARGET ${TARGET_NAME}-gdb PRE_BUILD COMMAND ${CMAKE_STRIP} ${TARGET_LOCATION}) + endif () + + # use androiddeployqt to create the apk + add_custom_target(${TARGET_NAME}-apk + COMMAND ${ANDROID_DEPLOY_QT} --input "${TARGET_NAME}-deployment.json" --output "${ANDROID_APK_OUTPUT_DIR}" --android-platform android-${ANDROID_API_LEVEL} ${ANDROID_DEPLOY_QT_INSTALL} --verbose --deployment bundled "\\$(ARGS)" + DEPENDS ${TARGET_NAME} ${TARGET_NAME}-copy-res ${TARGET_NAME}-copy-assets ${TARGET_NAME}-copy-java ${TARGET_NAME}-copy-libs ${TARGET_NAME}-gdb + ) + + # rename the APK if the caller asked us to + if (ANDROID_APK_CUSTOM_NAME) + add_custom_command( + TARGET ${TARGET_NAME}-apk + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E rename "${ANDROID_APK_OUTPUT_DIR}/bin/QtApp-debug.apk" "${ANDROID_APK_OUTPUT_DIR}/bin/${ANDROID_APK_CUSTOM_NAME}" + ) + endif () +endmacro() \ No newline at end of file diff --git a/cmake/android/android.toolchain.cmake b/cmake/android/android.toolchain.cmake new file mode 100755 index 0000000000..e1f50abfa6 --- /dev/null +++ b/cmake/android/android.toolchain.cmake @@ -0,0 +1,1753 @@ +# Copyright (c) 2010-2011, Ethan Rublee +# Copyright (c) 2011-2014, Andrey Kamaev +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +# ------------------------------------------------------------------------------ +# Android CMake toolchain file, for use with the Android NDK r5-r10c +# Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). +# See home page: https://github.com/taka-no-me/android-cmake +# +# Usage Linux: +# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk +# $ mkdir build && cd build +# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. +# $ make -j8 +# +# Usage Linux (using standalone toolchain): +# $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain +# $ mkdir build && cd build +# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. +# $ make -j8 +# +# Usage Windows: +# You need native port of make to build your project. +# Android NDK r7 (and newer) already has make.exe on board. +# For older NDK you have to install it separately. +# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm +# +# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk +# $ mkdir build && cd build +# $ cmake.exe -G"MinGW Makefiles" +# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake +# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" .. +# $ cmake.exe --build . +# +# +# Options (can be set as cmake parameters: -D=): +# ANDROID_NDK=/opt/android-ndk - path to the NDK root. +# Can be set as environment variable. Can be set only at first cmake run. +# +# ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the +# standalone toolchain. This option is not used if full NDK is found +# (ignored if ANDROID_NDK is set). +# Can be set as environment variable. Can be set only at first cmake run. +# +# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary +# Interface (ABI). This option nearly matches to the APP_ABI variable +# used by ndk-build tool from Android NDK. +# +# Possible targets are: +# "armeabi" - ARMv5TE based CPU with software floating point operations +# "armeabi-v7a" - ARMv7 based devices with hardware FPU instructions +# this ABI target is used by default +# "armeabi-v7a with NEON" - same as armeabi-v7a, but +# sets NEON as floating-point unit +# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but +# sets VFPV3 as floating-point unit (has 32 registers instead of 16) +# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP +# "x86" - IA-32 instruction set +# "mips" - MIPS32 instruction set +# +# 64-bit ABIs for NDK r10 and newer: +# "arm64-v8a" - ARMv8 AArch64 instruction set +# "x86_64" - Intel64 instruction set (r1) +# "mips64" - MIPS64 instruction set (r6) +# +# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. +# Option is read-only when standalone toolchain is used. +# Note: building for "android-L" requires explicit configuration. +# +# ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 - the name of compiler +# toolchain to be used. The list of possible values depends on the NDK +# version. For NDK r10c the possible values are: +# +# * aarch64-linux-android-4.9 +# * aarch64-linux-android-clang3.4 +# * aarch64-linux-android-clang3.5 +# * arm-linux-androideabi-4.6 +# * arm-linux-androideabi-4.8 +# * arm-linux-androideabi-4.9 (default) +# * arm-linux-androideabi-clang3.4 +# * arm-linux-androideabi-clang3.5 +# * mips64el-linux-android-4.9 +# * mips64el-linux-android-clang3.4 +# * mips64el-linux-android-clang3.5 +# * mipsel-linux-android-4.6 +# * mipsel-linux-android-4.8 +# * mipsel-linux-android-4.9 +# * mipsel-linux-android-clang3.4 +# * mipsel-linux-android-clang3.5 +# * x86-4.6 +# * x86-4.8 +# * x86-4.9 +# * x86-clang3.4 +# * x86-clang3.5 +# * x86_64-4.9 +# * x86_64-clang3.4 +# * x86_64-clang3.5 +# +# ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions +# instead of Thumb. Is not available for "x86" (inapplicable) and +# "armeabi-v6 with VFP" (is forced to be ON) ABIs. +# +# ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker +# errors even if they are not used. +# +# ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared +# libraries. Automatically turned for NDK r5x and r6x due to GLESv2 +# problems. +# +# LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary +# files. See additional details below. +# +# ANDROID_SET_OBSOLETE_VARIABLES=ON - if set, then toolchain defines some +# obsolete variables which were used by previous versions of this file for +# backward compatibility. +# +# ANDROID_STL=gnustl_static - specify the runtime to use. +# +# Possible values are: +# none -> Do not configure the runtime. +# system -> Use the default minimal system C++ runtime library. +# Implies -fno-rtti -fno-exceptions. +# Is not available for standalone toolchain. +# system_re -> Use the default minimal system C++ runtime library. +# Implies -frtti -fexceptions. +# Is not available for standalone toolchain. +# gabi++_static -> Use the GAbi++ runtime as a static library. +# Implies -frtti -fno-exceptions. +# Available for NDK r7 and newer. +# Is not available for standalone toolchain. +# gabi++_shared -> Use the GAbi++ runtime as a shared library. +# Implies -frtti -fno-exceptions. +# Available for NDK r7 and newer. +# Is not available for standalone toolchain. +# stlport_static -> Use the STLport runtime as a static library. +# Implies -fno-rtti -fno-exceptions for NDK before r7. +# Implies -frtti -fno-exceptions for NDK r7 and newer. +# Is not available for standalone toolchain. +# stlport_shared -> Use the STLport runtime as a shared library. +# Implies -fno-rtti -fno-exceptions for NDK before r7. +# Implies -frtti -fno-exceptions for NDK r7 and newer. +# Is not available for standalone toolchain. +# gnustl_static -> Use the GNU STL as a static library. +# Implies -frtti -fexceptions. +# gnustl_shared -> Use the GNU STL as a shared library. +# Implies -frtti -fno-exceptions. +# Available for NDK r7b and newer. +# Silently degrades to gnustl_static if not available. +# +# ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on +# chosen runtime. If disabled, then the user is responsible for settings +# these options. +# +# What?: +# android-cmake toolchain searches for NDK/toolchain in the following order: +# ANDROID_NDK - cmake parameter +# ANDROID_NDK - environment variable +# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter +# ANDROID_STANDALONE_TOOLCHAIN - environment variable +# ANDROID_NDK - default locations +# ANDROID_STANDALONE_TOOLCHAIN - default locations +# +# Make sure to do the following in your scripts: +# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) +# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) +# The flags will be prepopulated with critical flags, so don't loose them. +# Also be aware that toolchain also sets configuration-specific compiler +# flags and linker flags. +# +# ANDROID and BUILD_ANDROID will be set to true, you may test any of these +# variables to make necessary Android-specific configuration changes. +# +# Also ARMEABI or ARMEABI_V7A or X86 or MIPS or ARM64_V8A or X86_64 or MIPS64 +# will be set true, mutually exclusive. NEON option will be set true +# if VFP is set to NEON. +# +# LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android +# libraries will be installed. +# Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be +# under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME} +# (depending on the target ABI). This is convenient for Android packaging. +# +# ------------------------------------------------------------------------------ + +cmake_minimum_required( VERSION 2.6.3 ) + +if( DEFINED CMAKE_CROSSCOMPILING ) + # subsequent toolchain loading is not really needed + return() +endif() + +if( CMAKE_TOOLCHAIN_FILE ) + # touch toolchain variable to suppress "unused variable" warning +endif() + +# inherit settings in recursive loads +get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE ) +if( _CMAKE_IN_TRY_COMPILE ) + include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL ) +endif() + +# this one is important +if( CMAKE_VERSION VERSION_GREATER "3.0.99" ) + set( CMAKE_SYSTEM_NAME Android ) +else() + set( CMAKE_SYSTEM_NAME Linux ) +endif() + +# this one not so much +set( CMAKE_SYSTEM_VERSION 1 ) + +# rpath makes low sence for Android +set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" ) +set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) + +# NDK search paths +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r10c -r10b -r10 -r9d -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) + if( CMAKE_HOST_WIN32 ) + file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" ) + else() + file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" ) + endif() +endif() +if(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH) + set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) +endif() + +# known ABIs +set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" ) +set( ANDROID_SUPPORTED_ABIS_arm64 "arm64-v8a" ) +set( ANDROID_SUPPORTED_ABIS_x86 "x86" ) +set( ANDROID_SUPPORTED_ABIS_x86_64 "x86_64" ) +set( ANDROID_SUPPORTED_ABIS_mips "mips" ) +set( ANDROID_SUPPORTED_ABIS_mips64 "mips64" ) + +# API level defaults +set( ANDROID_DEFAULT_NDK_API_LEVEL 8 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 ) + + +macro( __LIST_FILTER listvar regex ) + if( ${listvar} ) + foreach( __val ${${listvar}} ) + if( __val MATCHES "${regex}" ) + list( REMOVE_ITEM ${listvar} "${__val}" ) + endif() + endforeach() + endif() +endmacro() + +macro( __INIT_VARIABLE var_name ) + set( __test_path 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "PATH" ) + set( __test_path 1 ) + break() + endif() + endforeach() + if( __test_path AND NOT EXISTS "${${var_name}}" ) + unset( ${var_name} CACHE ) + endif() + if( "${${var_name}}" STREQUAL "" ) + set( __values 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "VALUES" ) + set( __values 1 ) + elseif( NOT __var STREQUAL "PATH" ) + set( __obsolete 0 ) + if( __var MATCHES "^OBSOLETE_.*$" ) + string( REPLACE "OBSOLETE_" "" __var "${__var}" ) + set( __obsolete 1 ) + endif() + if( __var MATCHES "^ENV_.*$" ) + string( REPLACE "ENV_" "" __var "${__var}" ) + set( __value "$ENV{${__var}}" ) + elseif( DEFINED ${__var} ) + set( __value "${${__var}}" ) + else() + if( __values ) + set( __value "${__var}" ) + else() + set( __value "" ) + endif() + endif() + if( NOT "${__value}" STREQUAL "" ) + if( __test_path ) + if( EXISTS "${__value}" ) + file( TO_CMAKE_PATH "${__value}" ${var_name} ) + if( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain." ) + endif() + break() + endif() + else() + set( ${var_name} "${__value}" ) + if( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain." ) + endif() + break() + endif() + endif() + endif() + endforeach() + unset( __value ) + unset( __values ) + unset( __obsolete ) + elseif( __test_path ) + file( TO_CMAKE_PATH "${${var_name}}" ${var_name} ) + endif() + unset( __test_path ) +endmacro() + +macro( __DETECT_NATIVE_API_LEVEL _var _path ) + SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" ) + FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) + if( NOT __apiFileContent ) + message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + endif() + string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) + unset( __apiFileContent ) + unset( __ndkApiLevelRegex ) +endmacro() + +macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) + if( EXISTS "${_root}" ) + file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) + __LIST_FILTER( __gccExePath "^[.].*" ) + list( LENGTH __gccExePath __gccExePathsCount ) + if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "Could not determine machine name for compiler from ${_root}" ) + set( ${_var} "" ) + else() + get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) + string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) + endif() + unset( __gccExePath ) + unset( __gccExePathsCount ) + unset( __gccExeName ) + else() + set( ${_var} "" ) + endif() +endmacro() + + +# fight against cygwin +set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools") +mark_as_advanced( ANDROID_FORBID_SYGWIN ) +if( ANDROID_FORBID_SYGWIN ) + if( CYGWIN ) + message( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." ) + endif() + + if( CMAKE_HOST_WIN32 ) + # remove cygwin from PATH + set( __new_path "$ENV{PATH}") + __LIST_FILTER( __new_path "cygwin" ) + set(ENV{PATH} "${__new_path}") + unset(__new_path) + endif() +endif() + + +# detect current host platform +if( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE) ) + set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" ) + mark_as_advanced( ANDROID_NDK_HOST_X64 ) +endif() + +set( TOOL_OS_SUFFIX "" ) +if( CMAKE_HOST_APPLE ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME2 "darwin-x86" ) +elseif( CMAKE_HOST_WIN32 ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME2 "windows" ) + set( TOOL_OS_SUFFIX ".exe" ) +elseif( CMAKE_HOST_UNIX ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME2 "linux-x86" ) +else() + message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) +endif() + +if( NOT ANDROID_NDK_HOST_X64 ) + set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) +endif() + +# see if we have path to Android NDK +__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) +if( NOT ANDROID_NDK ) + # see if we have path to Android standalone toolchain + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT ) + + if( NOT ANDROID_STANDALONE_TOOLCHAIN ) + #try to find Android NDK in one of the the default locations + set( __ndkSearchPaths ) + foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) + foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) + list( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" ) + endforeach() + endforeach() + __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) + unset( __ndkSearchPaths ) + + if( ANDROID_NDK ) + message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" ) + message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" ) + else() + #try to find Android standalone toolchain in one of the the default locations + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) + + if( ANDROID_STANDALONE_TOOLCHAIN ) + message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" ) + message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" ) + endif( ANDROID_STANDALONE_TOOLCHAIN ) + endif( ANDROID_NDK ) + endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) +endif( NOT ANDROID_NDK ) + +# remember found paths +if( ANDROID_NDK ) + get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) + set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE ) + set( BUILD_WITH_ANDROID_NDK True ) + if( EXISTS "${ANDROID_NDK}/RELEASE.TXT" ) + file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX "r[0-9]+[a-z]?" ) + string( REGEX MATCH "r([0-9]+)([a-z]?)" ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_FULL}" ) + else() + set( ANDROID_NDK_RELEASE "r1x" ) + set( ANDROID_NDK_RELEASE_FULL "unreleased" ) + endif() + string( REGEX REPLACE "r([0-9]+)([a-z]?)" "\\1*1000" ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE}" ) + string( FIND " abcdefghijklmnopqastuvwxyz" "${CMAKE_MATCH_2}" __ndkReleaseLetterNum ) + math( EXPR ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE_NUM}+${__ndkReleaseLetterNum}" ) +elseif( ANDROID_STANDALONE_TOOLCHAIN ) + get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) + # try to detect change + if( CMAKE_AR ) + string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath ) + if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN ) + message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." ) + endif() + unset( __androidStandaloneToolchainPreviousPath ) + unset( __length ) + endif() + set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE ) + set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) +else() + list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH) + message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolchain. + You should either set an environment variable: + export ANDROID_NDK=~/my-android-ndk + or + export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain + or put the toolchain or NDK in the default path: + sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH} + sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) +endif() + +# android NDK layout +if( BUILD_WITH_ANDROID_NDK ) + if( NOT DEFINED ANDROID_NDK_LAYOUT ) + # try to automatically detect the layout + if( EXISTS "${ANDROID_NDK}/RELEASE.TXT") + set( ANDROID_NDK_LAYOUT "RELEASE" ) + elseif( EXISTS "${ANDROID_NDK}/../../linux-x86/toolchain/" ) + set( ANDROID_NDK_LAYOUT "LINARO" ) + elseif( EXISTS "${ANDROID_NDK}/../../gcc/" ) + set( ANDROID_NDK_LAYOUT "ANDROID" ) + endif() + endif() + set( ANDROID_NDK_LAYOUT "${ANDROID_NDK_LAYOUT}" CACHE STRING "The inner layout of NDK" ) + mark_as_advanced( ANDROID_NDK_LAYOUT ) + if( ANDROID_NDK_LAYOUT STREQUAL "LINARO" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment + set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) + elseif( ANDROID_NDK_LAYOUT STREQUAL "ANDROID" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment + set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../gcc/${ANDROID_NDK_HOST_SYSTEM_NAME}/arm" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) + else() # ANDROID_NDK_LAYOUT STREQUAL "RELEASE" + set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/toolchains" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}" ) + endif() + get_filename_component( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK_TOOLCHAINS_PATH}" ABSOLUTE ) + + # try to detect change of NDK + if( CMAKE_AR ) + string( LENGTH "${ANDROID_NDK_TOOLCHAINS_PATH}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) + if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK_TOOLCHAINS_PATH ) + message( FATAL_ERROR "It is not possible to change the path to the NDK on subsequent CMake run. You must remove all generated files from your build folder first. + " ) + endif() + unset( __androidNdkPreviousPath ) + unset( __length ) + endif() +endif() + + +# get all the details about standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) + set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + set( __availableToolchains "standalone" ) + __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" ) + if( NOT __availableToolchainMachines ) + message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." ) + endif() + if( __availableToolchainMachines MATCHES x86_64 ) + set( __availableToolchainArchs "x86_64" ) + elseif( __availableToolchainMachines MATCHES i686 ) + set( __availableToolchainArchs "x86" ) + elseif( __availableToolchainMachines MATCHES aarch64 ) + set( __availableToolchainArchs "arm64" ) + elseif( __availableToolchainMachines MATCHES arm ) + set( __availableToolchainArchs "arm" ) + elseif( __availableToolchainMachines MATCHES mips64el ) + set( __availableToolchainArchs "mips64" ) + elseif( __availableToolchainMachines MATCHES mipsel ) + set( __availableToolchainArchs "mips" ) + endif() + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" ) + list( APPEND __availableToolchains "standalone-clang" ) + list( APPEND __availableToolchainMachines ${__availableToolchainMachines} ) + list( APPEND __availableToolchainArchs ${__availableToolchainArchs} ) + list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} ) + endif() +endif() + +macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath ) + foreach( __toolchain ${${__availableToolchainsLst}} ) + if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) + SET( __toolchainVersionRegex "^TOOLCHAIN_VERSION[\t ]+:=[\t ]+(.*)$" ) + FILE( STRINGS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}/setup.mk" __toolchainVersionStr REGEX "${__toolchainVersionRegex}" ) + if( __toolchainVersionStr ) + string( REGEX REPLACE "${__toolchainVersionRegex}" "\\1" __toolchainVersionStr "${__toolchainVersionStr}" ) + string( REGEX REPLACE "-clang3[.][0-9]$" "-${__toolchainVersionStr}" __gcc_toolchain "${__toolchain}" ) + else() + string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) + endif() + unset( __toolchainVersionStr ) + unset( __toolchainVersionRegex ) + else() + set( __gcc_toolchain "${__toolchain}" ) + endif() + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) + if( __machine MATCHES x86_64 ) + set( __arch "x86_64" ) + elseif( __machine MATCHES i686 ) + set( __arch "x86" ) + elseif( __machine MATCHES aarch64 ) + set( __arch "arm64" ) + elseif( __machine MATCHES arm ) + set( __arch "arm" ) + elseif( __machine MATCHES mips64el ) + set( __arch "mips64" ) + elseif( __machine MATCHES mipsel ) + set( __arch "mips" ) + else() + set( __arch "" ) + endif() + #message("machine: !${__machine}!\narch: !${__arch}!\nversion: !${__version}!\ntoolchain: !${__toolchain}!\n") + if (__arch) + list( APPEND __availableToolchainMachines "${__machine}" ) + list( APPEND __availableToolchainArchs "${__arch}" ) + list( APPEND __availableToolchainCompilerVersions "${__version}" ) + list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) + endif() + endif() + unset( __gcc_toolchain ) + endforeach() +endmacro() + +# get all the details about NDK +if( BUILD_WITH_ANDROID_NDK ) + file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) + string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) + set( __availableToolchains "" ) + set( __availableToolchainMachines "" ) + set( __availableToolchainArchs "" ) + set( __availableToolchainCompilerVersions "" ) + if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/" ) + # do not go through all toolchains if we know the name + set( __availableToolchainsLst "${ANDROID_TOOLCHAIN_NAME}" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) + if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) + if( __availableToolchains ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) + endif() + endif() + endif() + if( NOT __availableToolchains ) + file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" ) + if( __availableToolchains ) + list(SORT __availableToolchainsLst) # we need clang to go after gcc + endif() + __LIST_FILTER( __availableToolchainsLst "^[.]" ) + __LIST_FILTER( __availableToolchainsLst "llvm" ) + __LIST_FILTER( __availableToolchainsLst "renderscript" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) + if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) + if( __availableToolchains ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) + endif() + endif() + endif() + if( NOT __availableToolchains ) + message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." ) + endif() +endif() + +# build list of available ABIs +set( ANDROID_SUPPORTED_ABIS "" ) +set( __uniqToolchainArchNames ${__availableToolchainArchs} ) +list( REMOVE_DUPLICATES __uniqToolchainArchNames ) +list( SORT __uniqToolchainArchNames ) +foreach( __arch ${__uniqToolchainArchNames} ) + list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) +endforeach() +unset( __uniqToolchainArchNames ) +if( NOT ANDROID_SUPPORTED_ABIS ) + message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) +endif() + +# choose target ABI +__INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} ) +# verify that target ABI is supported +list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) +if( __androidAbiIdx EQUAL -1 ) + string( REPLACE ";" "\", \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) + message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. + Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" + " ) +endif() +unset( __androidAbiIdx ) + +# set target ABI options +if( ANDROID_ABI STREQUAL "x86" ) + set( X86 true ) + set( ANDROID_NDK_ABI_NAME "x86" ) + set( ANDROID_ARCH_NAME "x86" ) + set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "i686" ) +elseif( ANDROID_ABI STREQUAL "x86_64" ) + set( X86 true ) + set( X86_64 true ) + set( ANDROID_NDK_ABI_NAME "x86_64" ) + set( ANDROID_ARCH_NAME "x86_64" ) + set( CMAKE_SYSTEM_PROCESSOR "x86_64" ) + set( ANDROID_LLVM_TRIPLE "x86_64-none-linux-android" ) +elseif( ANDROID_ABI STREQUAL "mips64" ) + set( MIPS64 true ) + set( ANDROID_NDK_ABI_NAME "mips64" ) + set( ANDROID_ARCH_NAME "mips64" ) + set( ANDROID_LLVM_TRIPLE "mips64el-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "mips64" ) +elseif( ANDROID_ABI STREQUAL "mips" ) + set( MIPS true ) + set( ANDROID_NDK_ABI_NAME "mips" ) + set( ANDROID_ARCH_NAME "mips" ) + set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "mips" ) +elseif( ANDROID_ABI STREQUAL "arm64-v8a" ) + set( ARM64_V8A true ) + set( ANDROID_NDK_ABI_NAME "arm64-v8a" ) + set( ANDROID_ARCH_NAME "arm64" ) + set( ANDROID_LLVM_TRIPLE "aarch64-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "aarch64" ) + set( VFPV3 true ) + set( NEON true ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) + set( ARMEABI true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) + set( ARMEABI_V6 true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv6" ) + # need always fallback to older platform + set( ARMEABI true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a") + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) + set( NEON true ) +else() + message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) +endif() + +if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" ) + # really dirty hack + # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run... + file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) +endif() + +if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) + __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) + set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) + mark_as_advanced( ANDROID_FORCE_ARM_BUILD ) +else() + unset( ANDROID_FORCE_ARM_BUILD CACHE ) +endif() + +# choose toolchain +if( ANDROID_TOOLCHAIN_NAME ) + list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) + if( __toolchainIdx EQUAL -1 ) + list( SORT __availableToolchains ) + string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" ) + set( toolchains_list " * ${toolchains_list}") + message( FATAL_ERROR "Specified toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain. +To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" ) + endif() + list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) + if( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME ) + message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) + endif() +else() + set( __toolchainIdx -1 ) + set( __applicableToolchains "" ) + set( __toolchainMaxVersion "0.0.0" ) + list( LENGTH __availableToolchains __availableToolchainsCount ) + math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" ) + foreach( __idx RANGE ${__availableToolchainsCount} ) + list( GET __availableToolchainArchs ${__idx} __toolchainArch ) + if( __toolchainArch STREQUAL ANDROID_ARCH_NAME ) + list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) + string( REPLACE "x" "99" __toolchainVersion "${__toolchainVersion}") + if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion ) + set( __toolchainMaxVersion "${__toolchainVersion}" ) + set( __toolchainIdx ${__idx} ) + endif() + endif() + endforeach() + unset( __availableToolchainsCount ) + unset( __toolchainMaxVersion ) + unset( __toolchainVersion ) +endif() +unset( __toolchainArch ) +if( __toolchainIdx EQUAL -1 ) + message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." ) +endif() +list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) +list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) +list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) + +unset( __toolchainIdx ) +unset( __availableToolchains ) +unset( __availableToolchainMachines ) +unset( __availableToolchainArchs ) +unset( __availableToolchainCompilerVersions ) + +# choose native API level +__INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) +string( REPLACE "android-" "" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) +string( STRIP "${ANDROID_NATIVE_API_LEVEL}" ANDROID_NATIVE_API_LEVEL ) +# adjust API level +set( __real_api_level ${ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME}} ) +foreach( __level ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + if( (__level LESS ANDROID_NATIVE_API_LEVEL OR __level STREQUAL ANDROID_NATIVE_API_LEVEL) AND NOT __level LESS __real_api_level ) + set( __real_api_level ${__level} ) + endif() +endforeach() +if( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL STREQUAL __real_api_level ) + message( STATUS "Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'") + set( ANDROID_NATIVE_API_LEVEL ${__real_api_level} ) +endif() +unset(__real_api_level) +# validate +list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) +if( __levelIdx EQUAL -1 ) + message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." ) +else() + if( BUILD_WITH_ANDROID_NDK ) + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 ) + message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) + endif() + unset( __realApiLevel ) + endif() + set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) + if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + endif() +endif() +unset( __levelIdx ) + + +# remember target ABI +set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) +endif() + + +# runtime choice (STL, rtti, exceptions) +if( NOT ANDROID_STL ) + # honor legacy ANDROID_USE_STLPORT + if( DEFINED ANDROID_USE_STLPORT ) + if( ANDROID_USE_STLPORT ) + set( ANDROID_STL stlport_static ) + endif() + message( WARNING "You are using an obsolete variable ANDROID_USE_STLPORT to select the STL variant. Use -DANDROID_STL=stlport_static instead." ) + endif() + if( NOT ANDROID_STL ) + set( ANDROID_STL gnustl_static ) + endif() +endif() +set( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" ) +set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" ) +mark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES ) + +if( BUILD_WITH_ANDROID_NDK ) + if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$") + message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". +The possible values are: + none -> Do not configure the runtime. + system -> Use the default minimal system C++ runtime library. + system_re -> Same as system but with rtti and exceptions. + gabi++_static -> Use the GAbi++ runtime as a static library. + gabi++_shared -> Use the GAbi++ runtime as a shared library. + stlport_static -> Use the STLport runtime as a static library. + stlport_shared -> Use the STLport runtime as a shared library. + gnustl_static -> (default) Use the GNU STL as a static library. + gnustl_shared -> Use the GNU STL as a shared library. +" ) + endif() +elseif( BUILD_WITH_STANDALONE_TOOLCHAIN ) + if( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$") + message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". +The possible values are: + none -> Do not configure the runtime. + gnustl_static -> (default) Use the GNU STL as a static library. + gnustl_shared -> Use the GNU STL as a shared library. +" ) + endif() +endif() + +unset( ANDROID_RTTI ) +unset( ANDROID_EXCEPTIONS ) +unset( ANDROID_STL_INCLUDE_DIRS ) +unset( __libstl ) +unset( __libsupcxx ) + +if( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" ) + message( WARNING "The GNU STL armeabi-v7a binaries from NDK r7b can crash non-NEON devices. The files provided with NDK r7b were not configured properly, resulting in crashes on Tegra2-based devices and others when trying to use certain floating-point functions (e.g., cosf, sinf, expf). +You are strongly recommended to switch to another NDK release. +" ) +endif() + +if( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" ) + message( WARNING "The x86 system header file from NDK r6 has incorrect definition for ptrdiff_t. You are recommended to upgrade to a newer NDK release or manually patch the header: +See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2 + diff --git a/ndk/platforms/android-9/arch-x86/include/machine/_types.h b/ndk/platforms/android-9/arch-x86/include/machine/_types.h + index 5e28c64..65892a1 100644 + --- a/ndk/platforms/android-9/arch-x86/include/machine/_types.h + +++ b/ndk/platforms/android-9/arch-x86/include/machine/_types.h + @@ -51,7 +51,11 @@ typedef long int ssize_t; + #endif + #ifndef _PTRDIFF_T + #define _PTRDIFF_T + -typedef long ptrdiff_t; + +# ifdef __ANDROID__ + + typedef int ptrdiff_t; + +# else + + typedef long ptrdiff_t; + +# endif + #endif +" ) +endif() + + +# setup paths and STL for standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + + if( NOT ANDROID_STL STREQUAL "none" ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" ) + if( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" ) + # old location ( pre r8c ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + endif() + if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) + else() + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) + endif() + # always search static GNU STL to get the location of libsupc++.a + if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) + elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) + endif() + if( __libstl ) + set( __libsupcxx "${__libstl}/libsupc++.a" ) + set( __libstl "${__libstl}/libstdc++.a" ) + endif() + if( NOT EXISTS "${__libsupcxx}" ) + message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. + Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. + You need to either upgrade to newer NDK or manually copy + $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a + to + ${__libsupcxx} + " ) + endif() + if( ANDROID_STL STREQUAL "gnustl_shared" ) + if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + endif() + endif() + endif() +endif() + +# clang +if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" ) + set( ANDROID_COMPILER_IS_CLANG 1 ) + execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}") +elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" ) + string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}") + string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-${ANDROID_COMPILER_VERSION}" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + if( NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}" ) + message( FATAL_ERROR "Could not find the Clang compiler driver" ) + endif() + set( ANDROID_COMPILER_IS_CLANG 1 ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) +else() + set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + unset( ANDROID_COMPILER_IS_CLANG CACHE ) +endif() + +string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" ) +if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" ) + set( _clang_name "clang" ) +endif() + + +# setup paths and STL for NDK +if( BUILD_WITH_ANDROID_NDK ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) + set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) + + if( ANDROID_STL STREQUAL "none" ) + # do nothing + elseif( ANDROID_STL STREQUAL "system" ) + set( ANDROID_RTTI OFF ) + set( ANDROID_EXCEPTIONS OFF ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) + elseif( ANDROID_STL STREQUAL "system_re" ) + set( ANDROID_RTTI ON ) + set( ANDROID_EXCEPTIONS ON ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) + elseif( ANDROID_STL MATCHES "gabi" ) + if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 + message( FATAL_ERROR "gabi++ is not awailable in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.") + endif() + set( ANDROID_RTTI ON ) + set( ANDROID_EXCEPTIONS OFF ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" ) + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" ) + elseif( ANDROID_STL MATCHES "stlport" ) + if( NOT ANDROID_NDK_RELEASE_NUM LESS 8004 ) # before r8d + set( ANDROID_EXCEPTIONS ON ) + else() + set( ANDROID_EXCEPTIONS OFF ) + endif() + if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 + set( ANDROID_RTTI OFF ) + else() + set( ANDROID_RTTI ON ) + endif() + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" ) + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" ) + elseif( ANDROID_STL MATCHES "gnustl" ) + set( ANDROID_EXCEPTIONS ON ) + set( ANDROID_RTTI ON ) + if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) + if( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.7" AND ANDROID_NDK_RELEASE STREQUAL "r8d" ) + # gnustl binary for 4.7 compiler is buggy :( + # TODO: look for right fix + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6" ) + else() + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) + endif() + else() + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" ) + endif() + set( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" ) + if( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) + set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) + else() + set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" ) + endif() + else() + message( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" ) + endif() + # find libsupc++.a - rtti & exceptions + if( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" ) + set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r8b or newer + if( NOT EXISTS "${__libsupcxx}" ) + set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r7-r8 + endif() + if( NOT EXISTS "${__libsupcxx}" ) # before r7 + if( ARMEABI_V7A ) + if( ANDROID_FORCE_ARM_BUILD ) + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) + else() + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) + endif() + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD ) + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) + else() + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) + endif() + endif() + if( NOT EXISTS "${__libsupcxx}") + message( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken.") + endif() + endif() +endif() + + +# case of shared STL linkage +if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) + string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" ) + # TODO: check if .so file exists before the renaming +endif() + + +# ccache support +__INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE ) +if( _ndk_ccache ) + if( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE ) + unset( NDK_CCACHE CACHE ) + endif() + find_program( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary") +else() + unset( NDK_CCACHE CACHE ) +endif() +unset( _ndk_ccache ) + + +# setup the cross-compiler +if( NOT CMAKE_C_COMPILER ) + if( NDK_CCACHE AND NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) + set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" ) + set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" ) + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + endif() + else() + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" ) + set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" ) + endif() + endif() + set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" ) + set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) + set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) + set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) + set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) + set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) + set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) + set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) +endif() + +set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) +if( CMAKE_VERSION VERSION_LESS 2.8.5 ) + set( CMAKE_ASM_COMPILER_ARG1 "-c" ) +endif() +if( APPLE ) + find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) + if( NOT CMAKE_INSTALL_NAME_TOOL ) + message( FATAL_ERROR "Could not find install_name_tool, please check your installation." ) + endif() + mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) +endif() + +# Force set compilers because standard identification works badly for us +include( CMakeForceCompiler ) +CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ID Clang) +endif() +set( CMAKE_C_PLATFORM_ID Linux ) +if( X86_64 OR MIPS64 OR ARM64_V8A ) + set( CMAKE_C_SIZEOF_DATA_PTR 8 ) +else() + set( CMAKE_C_SIZEOF_DATA_PTR 4 ) +endif() +set( CMAKE_C_HAS_ISYSROOT 1 ) +set( CMAKE_C_COMPILER_ABI ELF ) +CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_CXX_COMPILER_ID Clang) +endif() +set( CMAKE_CXX_PLATFORM_ID Linux ) +set( CMAKE_CXX_SIZEOF_DATA_PTR ${CMAKE_C_SIZEOF_DATA_PTR} ) +set( CMAKE_CXX_HAS_ISYSROOT 1 ) +set( CMAKE_CXX_COMPILER_ABI ELF ) +set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C ) +# force ASM compiler (required for CMake < 2.8.5) +set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) +set( CMAKE_ASM_COMPILER_ID GNU ) +set( CMAKE_ASM_COMPILER_WORKS TRUE ) +set( CMAKE_ASM_COMPILER_FORCED TRUE ) +set( CMAKE_COMPILER_IS_GNUASM 1) +set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm ) + +# flags and definitions +remove_definitions( -DANDROID ) +add_definitions( -DANDROID ) + +if( ANDROID_SYSROOT MATCHES "[ ;\"]" ) + if( CMAKE_HOST_WIN32 ) + # try to convert path to 8.3 form + file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "@echo %~s1" ) + execute_process( COMMAND "$ENV{ComSpec}" /c "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "${ANDROID_SYSROOT}" + OUTPUT_VARIABLE __path OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE __result ERROR_QUIET ) + if( __result EQUAL 0 ) + file( TO_CMAKE_PATH "${__path}" ANDROID_SYSROOT ) + set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) + else() + set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) + endif() + else() + set( ANDROID_CXX_FLAGS "'--sysroot=${ANDROID_SYSROOT}'" ) + endif() + if( NOT _CMAKE_IN_TRY_COMPILE ) + # quotes can break try_compile and compiler identification + message(WARNING "Path to your Android NDK (or toolchain) has non-alphanumeric symbols.\nThe build might be broken.\n") + endif() +else() + set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) +endif() + +# NDK flags +if (ARM64_V8A ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fpic -ffunction-sections -funwind-tables" ) + set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) + endif() +elseif( ARMEABI OR ARMEABI_V7A) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fpic -funwind-tables" ) + if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) + set( ANDROID_CXX_FLAGS_RELEASE "-mthumb -fomit-frame-pointer -fno-strict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -finline-limit=64" ) + endif() + else() + # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI + set( ANDROID_CXX_FLAGS_RELEASE "-marm -fomit-frame-pointer -fstrict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) + endif() + endif() +elseif( X86 OR X86_64 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fPIC" ) + endif() + set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) +elseif( MIPS OR MIPS64 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fpic -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0" ) + set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" ) + set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) + set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) + endif() +elseif() + set( ANDROID_CXX_FLAGS_RELEASE "" ) + set( ANDROID_CXX_FLAGS_DEBUG "" ) +endif() + +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries + +if( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" ) +endif() + +if( NOT ANDROID_COMPILER_VERSION VERSION_LESS "4.6" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -no-canonical-prefixes" ) # see https://android-review.googlesource.com/#/c/47564/ +endif() + +# ABI-specific flags +if( ARMEABI_V7A ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) + if( NEON ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) + elseif( VFPV3 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" ) + endif() +elseif( ARMEABI_V6 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2 +elseif( ARMEABI ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) +endif() + +if( ANDROID_STL MATCHES "gnustl" AND (EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}") ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) + set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) + set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) +else() + set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) + set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) + set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) +endif() + +# STL +if( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" ) + if( EXISTS "${__libstl}" ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libstl}\"" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libstl}\"" ) + set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libstl}\"" ) + endif() + if( EXISTS "${__libsupcxx}" ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) + set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) + # C objects: + set( CMAKE_C_CREATE_SHARED_LIBRARY " -o " ) + set( CMAKE_C_CREATE_SHARED_MODULE " -o " ) + set( CMAKE_C_LINK_EXECUTABLE " -o " ) + set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) + set( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) + set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) + endif() + if( ANDROID_STL MATCHES "gnustl" ) + if( NOT EXISTS "${ANDROID_LIBM_PATH}" ) + set( ANDROID_LIBM_PATH -lm ) + endif() + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" ) + set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" ) + endif() +endif() + +# variables controlling optional build flags +if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 + # libGLESv2.so in NDK's prior to r7 refers to missing external symbols. + # So this flag option is required for all projects using OpenGL from native. + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON ) +else() + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) +endif() +__INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON ) +__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) +__INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON ) +__INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON ) +__INIT_VARIABLE( ANDROID_RELRO VALUES ON ) + +set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" ) +set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) +set( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) +set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker" ) +set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) +set( ANDROID_RELRO ${ANDROID_RELRO} CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" ) +mark_as_advanced( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO ) + +# linker flags +set( ANDROID_LINKER_FLAGS "" ) + +if( ARMEABI_V7A ) + # this is *required* to use the following linker flags that routes around + # a CPU bug in some Cortex-A8 implementations: + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" ) +endif() + +if( ANDROID_NO_UNDEFINED ) + if( MIPS ) + # there is some sysroot-related problem in mips linker... + if( NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" ) + endif() + else() + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" ) + endif() +endif() + +if( ANDROID_SO_UNDEFINED ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" ) +endif() + +if( ANDROID_FUNCTION_LEVEL_LINKING ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) +endif() + +if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) + if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE_NUM GREATER 8002) AND (ARMEABI OR ARMEABI_V7A OR X86) ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) + elseif( ANDROID_NDK_RELEASE_NUM GREATER 8002 ) # after r8b + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" ) + elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 + On Linux and OS X host platform you can workaround this problem using gold linker (default). + Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems. +" ) + endif() +endif() # version 4.6 + +if( ANDROID_NOEXECSTACK ) + if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) + endif() + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" ) +endif() + +if( ANDROID_RELRO ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" ) +endif() + +if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} -Qunused-arguments ${ANDROID_CXX_FLAGS}" ) + if( BUILD_WITH_ANDROID_NDK ) + set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" ) + endif() +endif() + +# cache flags +set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "" CACHE STRING "c flags" ) +set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" ) +set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" ) +set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" ) +set( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" ) +set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" ) +set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" ) + +# put flags to cache (for debug purpose only) +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android specific c/c++ flags" ) +set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE}" CACHE INTERNAL "Android specific c/c++ Release flags" ) +set( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG}" CACHE INTERNAL "Android specific c/c++ Debug flags" ) +set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android specific c/c++ linker flags" ) + +# finish flags +set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) +set( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" ) +set( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" ) +set( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" ) +set( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" ) +set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) +set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) +set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) + +if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" ) + set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) +endif() + +# configure rtti +if( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES ) + if( ANDROID_RTTI ) + set( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" ) + else() + set( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" ) + endif() +endif() + +# configure exceptios +if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES ) + if( ANDROID_EXCEPTIONS ) + set( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" ) + else() + set( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" ) + endif() +endif() + +# global includes and link directories +include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) +get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning +link_directories( "${__android_install_path}" ) + +# detect if need link crtbegin_so.o explicitly +if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK ) + set( __cmd "${CMAKE_CXX_CREATE_SHARED_LIBRARY}" ) + string( REPLACE "" "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_CXX_FLAGS}" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_SHARED_LINKER_FLAGS}" __cmd "${__cmd}" ) + string( REPLACE "" "-shared" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain_crtlink_test.so" __cmd "${__cmd}" ) + string( REPLACE "" "\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + separate_arguments( __cmd ) + foreach( __var ANDROID_NDK ANDROID_NDK_TOOLCHAINS_PATH ANDROID_STANDALONE_TOOLCHAIN ) + if( ${__var} ) + set( __tmp "${${__var}}" ) + separate_arguments( __tmp ) + string( REPLACE "${__tmp}" "${${__var}}" __cmd "${__cmd}") + endif() + endforeach() + string( REPLACE "'" "" __cmd "${__cmd}" ) + string( REPLACE "\"" "" __cmd "${__cmd}" ) + execute_process( COMMAND ${__cmd} RESULT_VARIABLE __cmd_result OUTPUT_QUIET ERROR_QUIET ) + if( __cmd_result EQUAL 0 ) + set( ANDROID_EXPLICIT_CRT_LINK ON ) + else() + set( ANDROID_EXPLICIT_CRT_LINK OFF ) + endif() +endif() + +if( ANDROID_EXPLICIT_CRT_LINK ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) +endif() + +# setup output directories +set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) +set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + +if(NOT _CMAKE_IN_TRY_COMPILE) + if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) + else() + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) + endif() + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) +endif() + +# copy shaed stl library to build directory +if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" ) + get_filename_component( __libstlname "${__libstl}" NAME ) + execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) + if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") + message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) + endif() + unset( __fileCopyProcess ) + unset( __libstlname ) +endif() + + +# set these global flags for cmake client scripts to change behavior +set( ANDROID True ) +set( BUILD_ANDROID True ) + +# where is the target environment +set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) + +# only search for libraries and includes in the ndk toolchain +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + + +# macro to find packages on the host OS +macro( find_host_package ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_package( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +# macro to find programs on the host OS +macro( find_host_program ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_program( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR ) + if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" ) + set( ${VAR} "armeabi" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" ) + set( ${VAR} "armeabi-v7a" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" ) + set( ${VAR} "x86" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "MIPS" ) + set( ${VAR} "mips" ) + else() + set( ${VAR} "unknown" ) + endif() +endmacro() + +if (POLICY CMP0054) + cmake_policy(SET CMP0054 NEW) +endif () + +# export toolchain settings for the try_compile() command +if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" ) + set( __toolchain_config "") + foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN ANDROID_SET_OBSOLETE_VARIABLES + ANDROID_NDK_HOST_X64 + ANDROID_NDK + ANDROID_NDK_LAYOUT + ANDROID_STANDALONE_TOOLCHAIN + ANDROID_TOOLCHAIN_NAME + ANDROID_ABI + ANDROID_NATIVE_API_LEVEL + ANDROID_STL + ANDROID_STL_FORCE_FEATURES + ANDROID_FORCE_ARM_BUILD + ANDROID_NO_UNDEFINED + ANDROID_SO_UNDEFINED + ANDROID_FUNCTION_LEVEL_LINKING + ANDROID_GOLD_LINKER + ANDROID_NOEXECSTACK + ANDROID_RELRO + ANDROID_LIBM_PATH + ANDROID_EXPLICIT_CRT_LINK + ) + if( DEFINED ${__var} ) + if( "${__var}" MATCHES " ") + set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) + else() + set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) + endif() + endif() + endforeach() + file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" ) + unset( __toolchain_config ) +endif() + + +# force cmake to produce / instead of \ in build commands for Ninja generator +if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 ) + # it is a bad hack after all + # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW + set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW + set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion + enable_language( C ) + enable_language( CXX ) + # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it + unset( MINGW ) +endif() + + +# set some obsolete variables for backward compatibility +set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" ) +mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES ) +if( ANDROID_SET_OBSOLETE_VARIABLES ) + set( ANDROID_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} ) + set( ARM_TARGET "${ANDROID_ABI}" ) + set( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" ) +endif() + + +# Variables controlling behavior or set by cmake toolchain: +# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips", "arm64-v8a", "x86_64", "mips64" +# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version) +# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none +# ANDROID_FORBID_SYGWIN : ON/OFF +# ANDROID_NO_UNDEFINED : ON/OFF +# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) +# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF +# ANDROID_GOLD_LINKER : ON/OFF +# ANDROID_NOEXECSTACK : ON/OFF +# ANDROID_RELRO : ON/OFF +# ANDROID_FORCE_ARM_BUILD : ON/OFF +# ANDROID_STL_FORCE_FEATURES : ON/OFF +# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF +# Can be set only at the first run: +# ANDROID_NDK +# ANDROID_STANDALONE_TOOLCHAIN +# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain +# ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems) +# ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID) +# LIBRARY_OUTPUT_PATH_ROOT : +# NDK_CCACHE : +# Obsolete: +# ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL +# ARM_TARGET : superseded by ANDROID_ABI +# ARM_TARGETS : superseded by ANDROID_ABI (can be set only) +# ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only) +# ANDROID_USE_STLPORT : superseded by ANDROID_STL=stlport_static +# ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed) +# +# Primary read-only variables: +# ANDROID : always TRUE +# ARMEABI : TRUE for arm v6 and older devices +# ARMEABI_V6 : TRUE for arm v6 +# ARMEABI_V7A : TRUE for arm v7a +# ARM64_V8A : TRUE for arm64-v8a +# NEON : TRUE if NEON unit is enabled +# VFPV3 : TRUE if VFP version 3 is enabled +# X86 : TRUE if configured for x86 +# X86_64 : TRUE if configured for x86_64 +# MIPS : TRUE if configured for mips +# MIPS64 : TRUE if configured for mips64 +# BUILD_ANDROID : always TRUE +# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used +# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used +# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform +# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86", "mips", "arm64-v8a", "x86_64", "mips64" depending on ANDROID_ABI +# ANDROID_NDK_RELEASE : from r5 to r10c; set only for NDK +# ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor) +# ANDROID_ARCH_NAME : "arm", "x86", "mips", "arm64", "x86_64", "mips64" depending on ANDROID_ABI +# ANDROID_SYSROOT : path to the compiler sysroot +# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform +# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used +# Obsolete: +# ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME +# +# Secondary (less stable) read-only variables: +# ANDROID_COMPILER_VERSION : GCC version used (not Clang version) +# ANDROID_CLANG_VERSION : version of clang compiler if clang is used +# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform +# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI +# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" +# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) +# ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools +# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK +# ANDROID_STL_INCLUDE_DIRS : stl include paths +# ANDROID_RTTI : if rtti is enabled by the runtime +# ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime +# ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used +# ANDROID_LIBM_PATH : path to libm.so (set to something like $(TOP)/out/target/product//obj/lib/libm.so) to workaround unresolved `sincos` +# +# Defaults: +# ANDROID_DEFAULT_NDK_API_LEVEL +# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} +# ANDROID_NDK_SEARCH_PATHS +# ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH +# ANDROID_SUPPORTED_ABIS_${ARCH} +# ANDROID_SUPPORTED_NDK_VERSIONS \ No newline at end of file diff --git a/cmake/android/deployment-file.json.in b/cmake/android/deployment-file.json.in new file mode 100644 index 0000000000..81ed8a6ecc --- /dev/null +++ b/cmake/android/deployment-file.json.in @@ -0,0 +1,13 @@ +{ + "qt": "@QT_DIR@", + "sdk": "@ANDROID_SDK_ROOT@", + "ndk": "@ANDROID_NDK@", + "toolchain-prefix": "@ANDROID_TOOLCHAIN_MACHINE_NAME@", + "tool-prefix": "@ANDROID_TOOLCHAIN_MACHINE_NAME@", + "toolchain-version": "@ANDROID_COMPILER_VERSION@", + "ndk-host": "@ANDROID_NDK_HOST_SYSTEM_NAME@", + "target-architecture": "@ANDROID_ABI@", + "application-binary": "@EXECUTABLE_DESTINATION_PATH@", + "android-extra-libs": "@_DEPS@", + "android-package-source-directory": "@ANDROID_APK_BUILD_DIR@" +} diff --git a/cmake/android/strings.xml.in b/cmake/android/strings.xml.in new file mode 100644 index 0000000000..6e6ce7b12e --- /dev/null +++ b/cmake/android/strings.xml.in @@ -0,0 +1,11 @@ + + + + + + ${ANDROID_APP_DISPLAY_NAME} + + Can\'t find Ministro service.\nThe application can\'t start. + This application requires Ministro service. Would you like to install it? + Your application encountered a fatal error and cannot continue. + diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt new file mode 100644 index 0000000000..b1aed7dd7f --- /dev/null +++ b/cmake/externals/glm/CMakeLists.txt @@ -0,0 +1,15 @@ +set(EXTERNAL_NAME glm) + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + PREFIX ${EXTERNAL_NAME} + URL http://pkgs.fedoraproject.org/repo/pkgs/glm/glm-0.9.5.4.zip/fab76fc982b256b46208e5c750ed456a/glm-0.9.5.4.zip + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= + LOG_DOWNLOAD ON +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE TYPE STRING) \ No newline at end of file diff --git a/cmake/externals/gverb/CMakeLists.txt b/cmake/externals/gverb/CMakeLists.txt new file mode 100644 index 0000000000..19a44781b1 --- /dev/null +++ b/cmake/externals/gverb/CMakeLists.txt @@ -0,0 +1,25 @@ +set(EXTERNAL_NAME gverb) + +if (ANDROID) + set(ANDROID_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DANDROID_NATIVE_API_LEVEL=19") +endif () + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + PREFIX ${EXTERNAL_NAME} + GIT_REPOSITORY https://github.com/birarda/gverb.git + CMAKE_ARGS ${ANDROID_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH= + LOG_DOWNLOAD ON +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE TYPE STRING) + +if (WIN32) + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/gverb.lib CACHE TYPE STRING) +else () + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/libgverb.a CACHE TYPE STRING) +endif () \ No newline at end of file diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake new file mode 100644 index 0000000000..ff0ced411e --- /dev/null +++ b/cmake/macros/AddDependencyExternalProject.cmake @@ -0,0 +1,25 @@ +# +# SetupExternalProject.cmake +# cmake/macros +# +# Copyright 2015 High Fidelity, Inc. +# Created by Stephen Birarda on February 13, 2014 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# + +macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME) + + string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER) + + if (NOT DEFINED GET_${_PROJ_NAME_UPPER} OR GET_${_PROJ_NAME_UPPER}) + if (NOT TARGET ${_PROJ_NAME}) + add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${CMAKE_BINARY_DIR}/externals/${_PROJ_NAME}) + endif () + + add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) + + endif () + +endmacro() \ No newline at end of file diff --git a/cmake/macros/AutoMTC.cmake b/cmake/macros/AutoMTC.cmake index 4d433e7b69..de60d5c21f 100644 --- a/cmake/macros/AutoMTC.cmake +++ b/cmake/macros/AutoMTC.cmake @@ -13,5 +13,11 @@ macro(AUTO_MTC) file(GLOB INCLUDE_FILES src/*.h) - add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND mtc -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS mtc ${INCLUDE_FILES}) + if (NOT ANDROID) + set(MTC_EXECUTABLE mtc) + else () + set(MTC_EXECUTABLE $ENV{MTC_PATH}/mtc) + endif () + + add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND ${MTC_EXECUTABLE} -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS ${MTC_EXECUTABLE} ${INCLUDE_FILES}) endmacro() diff --git a/cmake/macros/HifiLibrarySearchHints.cmake b/cmake/macros/HifiLibrarySearchHints.cmake index f56b3134d8..2eed364a68 100644 --- a/cmake/macros/HifiLibrarySearchHints.cmake +++ b/cmake/macros/HifiLibrarySearchHints.cmake @@ -10,18 +10,21 @@ macro(HIFI_LIBRARY_SEARCH_HINTS LIBRARY_FOLDER) string(TOUPPER ${LIBRARY_FOLDER} LIBRARY_PREFIX) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "") if (${LIBRARY_PREFIX}_ROOT_DIR) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}") + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}") + endif () + + if (ANDROID) + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "/${LIBRARY_FOLDER}") endif () if (DEFINED ENV{${LIBRARY_PREFIX}_ROOT_DIR}) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "$ENV{${LIBRARY_PREFIX}_ROOT_DIR}") + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "$ENV{${LIBRARY_PREFIX}_ROOT_DIR}") endif () if (DEFINED ENV{HIFI_LIB_DIR}) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "$ENV{HIFI_LIB_DIR}/${LIBRARY_FOLDER}") + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "$ENV{HIFI_LIB_DIR}/${LIBRARY_FOLDER}") endif () endmacro(HIFI_LIBRARY_SEARCH_HINTS _library_folder) \ No newline at end of file diff --git a/cmake/macros/IncludeGLM.cmake b/cmake/macros/IncludeGLM.cmake deleted file mode 100644 index e2fa981a3b..0000000000 --- a/cmake/macros/IncludeGLM.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# -# IncludeGLM.cmake -# -# Copyright 2013 High Fidelity, Inc. -# -# Distributed under the Apache License, Version 2.0. -# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -# - -macro(INCLUDE_GLM) - - find_package(GLM REQUIRED) - include_directories("${GLM_INCLUDE_DIRS}") - - if (APPLE OR UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${GLM_INCLUDE_DIRS}") - endif () - -endmacro(INCLUDE_GLM) \ No newline at end of file diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index ef0c8321c6..ed68103c0c 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -32,5 +32,4 @@ macro(LINK_HIFI_LIBRARIES) list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) endif() endforeach() - endmacro(LINK_HIFI_LIBRARIES) \ No newline at end of file diff --git a/cmake/macros/SetupHifiLibrary.cmake b/cmake/macros/SetupHifiLibrary.cmake index e76e1112e3..6d1de8f24d 100644 --- a/cmake/macros/SetupHifiLibrary.cmake +++ b/cmake/macros/SetupHifiLibrary.cmake @@ -9,14 +9,18 @@ macro(SETUP_HIFI_LIBRARY) - project(${TARGET_NAME}) + project(${TARGET_NAME}) # grab the implemenation and header files file(GLOB_RECURSE LIB_SRCS "src/*.h" "src/*.cpp") - set(LIB_SRCS ${LIB_SRCS}) + list(APPEND ${TARGET_NAME}_SRCS ${LIB_SRCS}) # create a library and set the property so it can be referenced later - add_library(${TARGET_NAME} ${LIB_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC}) + if (${${TARGET_NAME}_SHARED}) + add_library(${TARGET_NAME} SHARED ${LIB_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC} ${QT_RESOURCES_FILE}) + else () + add_library(${TARGET_NAME} ${LIB_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC} ${QT_RESOURCES_FILE}) + endif () set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN}) list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core) diff --git a/cmake/modules/FindBullet.cmake b/cmake/modules/FindBullet.cmake index 65d064e91b..c4f63860f2 100644 --- a/cmake/modules/FindBullet.cmake +++ b/cmake/modules/FindBullet.cmake @@ -35,27 +35,34 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") hifi_library_search_hints("bullet") macro(_FIND_BULLET_LIBRARY _var) - find_library(${_var} - NAMES - ${ARGN} + set(_${_var}_NAMES ${ARGN}) + find_library(${_var}_LIBRARY_RELEASE + NAMES ${_${_var}_NAMES} HINTS ${BULLET_SEARCH_DIRS} $ENV{BULLET_ROOT_DIR} ${BULLET_ROOT} - ${BULLET_ROOT}/out/release8/libs - ${BULLET_ROOT}/out/debug8/libs - PATH_SUFFIXES lib lib/Release lib/Debug + PATH_SUFFIXES lib lib/Release out/release8/libs ) - mark_as_advanced(${_var}) -endmacro() - -macro(_BULLET_APPEND_LIBRARIES _list _release) - set(_debug ${_release}_DEBUG) - if(${_debug}) - set(${_list} ${${_list}} optimized ${${_release}} debug ${${_debug}}) - else() - set(${_list} ${${_list}} ${${_release}}) - endif() + + foreach(_NAME IN LISTS _${_var}_NAMES) + list(APPEND _${_var}_DEBUG_NAMES "${_NAME}_Debug") + list(APPEND _${_var}_DEBUG_NAMES "${_NAME}_d") + endforeach() + + find_library(${_var}_LIBRARY_DEBUG + NAMES ${_${_var}_DEBUG_NAMES} + HINTS + ${BULLET_SEARCH_DIRS} + $ENV{BULLET_ROOT_DIR} + ${BULLET_ROOT} + PATH_SUFFIXES lib lib/Debug out/debug8/libs + ) + + select_library_configurations(${_var}) + + mark_as_advanced(${_var}_LIBRARY) + mark_as_advanced(${_var}_LIBRARY) endmacro() find_path(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h @@ -69,25 +76,18 @@ find_path(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h # Find the libraries -_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY BulletDynamics) -_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY_DEBUG BulletDynamics_Debug BulletDynamics_d) -_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY BulletCollision) -_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY_DEBUG BulletCollision_Debug BulletCollision_d) -_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY BulletMath LinearMath) -_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY_DEBUG BulletMath_Debug BulletMath_d LinearMath_Debug LinearMath_d) -_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY BulletSoftBody) -_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY_DEBUG BulletSoftBody_Debug BulletSoftBody_d) +_FIND_BULLET_LIBRARY(BULLET_DYNAMICS BulletDynamics) +_FIND_BULLET_LIBRARY(BULLET_COLLISION BulletCollision) +_FIND_BULLET_LIBRARY(BULLET_MATH BulletMath LinearMath) +_FIND_BULLET_LIBRARY(BULLET_SOFTBODY BulletSoftBody) +set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR}) +set(BULLET_LIBRARIES ${BULLET_DYNAMICS_LIBRARY} ${BULLET_COLLISION_LIBRARY} ${BULLET_MATH_LIBRARY} ${BULLET_SOFTBODY_LIBRARY}) find_package_handle_standard_args(Bullet "Could NOT find Bullet, try to set the path to Bullet root folder in the system variable BULLET_ROOT_DIR" BULLET_DYNAMICS_LIBRARY BULLET_COLLISION_LIBRARY BULLET_MATH_LIBRARY - BULLET_INCLUDE_DIR + BULLET_INCLUDE_DIRS + BULLET_LIBRARIES ) -set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR}) -if(BULLET_FOUND) - _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_DYNAMICS_LIBRARY) - _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_COLLISION_LIBRARY) - _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_MATH_LIBRARY) - _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_SOFTBODY_LIBRARY) -endif() + diff --git a/cmake/modules/FindGLM.cmake b/cmake/modules/FindGLM.cmake index 852ebbc15e..ace7360ea7 100644 --- a/cmake/modules/FindGLM.cmake +++ b/cmake/modules/FindGLM.cmake @@ -18,8 +18,7 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") hifi_library_search_hints("glm") # locate header -find_path(GLM_INCLUDE_DIR "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS}) -set(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") +find_path(GLM_INCLUDE_DIRS "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIRS) diff --git a/cmake/modules/FindGverb.cmake b/cmake/modules/FindGverb.cmake index 549c23c8a9..e54fba8083 100644 --- a/cmake/modules/FindGverb.cmake +++ b/cmake/modules/FindGverb.cmake @@ -15,25 +15,11 @@ # See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html # -if (GVERB_INCLUDE_DIRS) - # in cache already - set(GVERB_FOUND TRUE) -else (GVERB_INCLUDE_DIRS) +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("gverb") - include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") - hifi_library_search_hints("gverb") +find_path(GVERB_INCLUDE_DIRS gverb.h PATH_SUFFIXES include HINTS ${GVERB_SEARCH_DIRS}) +find_library(GVERB_LIBRARIES gverb PATH_SUFFIXES lib HINTS ${GVERB_SEARCH_DIRS}) - find_path(GVERB_INCLUDE_DIRS gverb.h PATH_SUFFIXES include HINTS ${GVERB_SEARCH_DIRS}) - find_path(GVERB_SRC_DIRS gverb.c PATH_SUFFIXES src HINTS ${GVERB_SEARCH_DIRS}) - - if (GVERB_INCLUDE_DIRS) - set(GVERB_FOUND TRUE) - endif (GVERB_INCLUDE_DIRS) - - if (GVERB_FOUND) - message(STATUS "Found Gverb: ${GVERB_INCLUDE_DIRS}") - else (GVERB_FOUND) - message(FATAL_ERROR "Could NOT find Gverb. Read ./interface/externals/gverb/readme.txt") - endif (GVERB_FOUND) - -endif(GVERB_INCLUDE_DIRS) \ No newline at end of file +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GVERB DEFAULT_MSG GVERB_INCLUDE_DIRS GVERB_LIBRARIES) \ No newline at end of file diff --git a/cmake/modules/FindLibOVR.cmake b/cmake/modules/FindLibOVR.cmake index 6ffb3ed309..62d8313d63 100644 --- a/cmake/modules/FindLibOVR.cmake +++ b/cmake/modules/FindLibOVR.cmake @@ -21,42 +21,60 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") hifi_library_search_hints("libovr") -find_path(LIBOVR_INCLUDE_DIRS OVR.h PATH_SUFFIXES Include HINTS ${LIBOVR_SEARCH_DIRS}) -find_path(LIBOVR_SRC_DIR Util_Render_Stereo.h PATH_SUFFIXES Src/Util HINTS ${LIBOVR_SEARCH_DIRS}) - include(SelectLibraryConfigurations) -if (APPLE) - find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Mac/Debug HINTS ${LIBOVR_SEARCH_DIRS}) - find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Mac/Release HINTS ${LIBOVR_SEARCH_DIRS}) - find_library(ApplicationServices ApplicationServices) - find_library(IOKit IOKit) -elseif (UNIX) - find_library(UDEV_LIBRARY_RELEASE udev /usr/lib/x86_64-linux-gnu/) - find_library(XINERAMA_LIBRARY_RELEASE Xinerama /usr/lib/x86_64-linux-gnu/) +if (NOT ANDROID) + + find_path(LIBOVR_INCLUDE_DIRS OVR.h PATH_SUFFIXES Include HINTS ${LIBOVR_SEARCH_DIRS}) + find_path(LIBOVR_SRC_DIR Util_Render_Stereo.h PATH_SUFFIXES Src/Util HINTS ${LIBOVR_SEARCH_DIRS}) - if (CMAKE_CL_64) - set(LINUX_ARCH_DIR "i386") - else() - set(LINUX_ARCH_DIR "x86_64") - endif() + if (APPLE) + find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Mac/Debug HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Mac/Release HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(ApplicationServices ApplicationServices) + find_library(IOKit IOKit) + elseif (UNIX) + find_library(UDEV_LIBRARY_RELEASE udev /usr/lib/x86_64-linux-gnu/) + find_library(XINERAMA_LIBRARY_RELEASE Xinerama /usr/lib/x86_64-linux-gnu/) - find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Linux/Debug/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) - find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Linux/Release/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) + if (CMAKE_CL_64) + set(LINUX_ARCH_DIR "i386") + else() + set(LINUX_ARCH_DIR "x86_64") + endif() - select_library_configurations(UDEV) - select_library_configurations(XINERAMA) + find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Linux/Debug/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Linux/Release/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) -elseif (WIN32) - if (MSVC10) - find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS}) - find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS}) - elseif (MSVC12) - find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS}) - find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS}) + select_library_configurations(UDEV) + select_library_configurations(XINERAMA) + + elseif (WIN32) + if (MSVC10) + find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS}) + elseif (MSVC12) + find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS}) + endif () + find_package(ATL) endif () - find_package(ATL) -endif () + +else (NOT ANDROID) + set(_VRLIB_JNI_DIR "VRLib/jni") + set(_VRLIB_LIBS_DIR "VRLib/obj/local/armeabi-v7a") + + find_path(LIBOVR_VRLIB_DIR VRLib.vcxproj PATH_SUFFIXES VRLib HINTS ${LIBOVR_SEARCH_DIRS}) + + find_path(LIBOVR_INCLUDE_DIRS OVR.h PATH_SUFFIXES ${_VRLIB_JNI_DIR}/LibOVR/Include HINTS ${LIBOVR_SEARCH_DIRS}) + find_path(LIBOVR_SRC_DIR OVR_CAPI.h PATH_SUFFIXES ${_VRLIB_JNI_DIR}/LibOVR/Src HINTS ${LIBOVR_SEARCH_DIRS}) + + find_path(MINIZIP_DIR minizip.c PATH_SUFFIXES ${_VRLIB_JNI_DIR}/3rdParty/minizip HINTS ${LIBOVR_SEARCH_DIRS}) + find_path(JNI_DIR VrCommon.h PATH_SUFFIXES ${_VRLIB_JNI_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) + + find_library(LIBOVR_LIBRARY_RELEASE NAMES oculus PATH_SUFFIXES ${_VRLIB_LIBS_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(TURBOJPEG_LIBRARY NAMES jpeg PATH_SUFFIXES 3rdParty/turbojpeg HINTS ${LIBOVR_SEARCH_DIRS}) +endif (NOT ANDROID) select_library_configurations(LIBOVR) set(LIBOVR_LIBRARIES ${LIBOVR_LIBRARY}) @@ -66,6 +84,10 @@ list(APPEND LIBOVR_ARGS_LIST LIBOVR_INCLUDE_DIRS LIBOVR_SRC_DIR LIBOVR_LIBRARY) if (APPLE) list(APPEND LIBOVR_LIBRARIES ${IOKit} ${ApplicationServices}) list(APPEND LIBOVR_ARGS_LIST IOKit ApplicationServices) +elseif (ANDROID) + + list(APPEND LIBOVR_ANDROID_LIBRARIES "-lGLESv3" "-lEGL" "-landroid" "-lOpenMAXAL" "-llog" "-lz" "-lOpenSLES") + list(APPEND LIBOVR_ARGS_LIST LIBOVR_ANDROID_LIBRARIES LIBOVR_VRLIB_DIR MINIZIP_DIR JNI_DIR TURBOJPEG_LIBRARY) elseif (UNIX) list(APPEND LIBOVR_LIBRARIES "${UDEV_LIBRARY}" "${XINERAMA_LIBRARY}") list(APPEND LIBOVR_ARGS_LIST UDEV_LIBRARY XINERAMA_LIBRARY) @@ -75,7 +97,10 @@ elseif (WIN32) endif () include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(LibOVR DEFAULT_MSG ${LIBOVR_ARGS_LIST}) +if (ANDROID) + list(APPEND LIBOVR_INCLUDE_DIRS ${LIBOVR_SRC_DIR} ${MINIZIP_DIR} ${JNI_DIR}) +endif () + mark_as_advanced(LIBOVR_INCLUDE_DIRS LIBOVR_LIBRARIES LIBOVR_SEARCH_DIRS) diff --git a/cmake/modules/FindOpenSSL.cmake b/cmake/modules/FindOpenSSL.cmake index 16db0a16f0..8298cc75b4 100644 --- a/cmake/modules/FindOpenSSL.cmake +++ b/cmake/modules/FindOpenSSL.cmake @@ -52,7 +52,9 @@ else () set(_OPENSSL_ROOT_HINTS_AND_PATHS ${OPENSSL_SEARCH_DIRS}) endif () -find_path(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_INCLUDEDIR} PATH_SUFFIXES include) +find_path(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_INCLUDEDIR} + PATH_SUFFIXES include +) if (WIN32 AND NOT CYGWIN) if (MSVC) @@ -133,7 +135,9 @@ else() PATH_SUFFIXES lib ) - find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_LIBDIR} PATH_SUFFIXES lib) + find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_LIBDIR} + PATH_SUFFIXES lib + ) mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY) @@ -179,8 +183,8 @@ endfunction() if (OPENSSL_INCLUDE_DIR) if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str - REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") - + REGEX "^#[ ]?define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") + # The version number is encoded as 0xMNNFFPPS: major minor fix patch status # The status gives if this is a developer or prerelease and is ignored here. # Major, minor, and fix directly translate into the version numbers shown in diff --git a/cmake/modules/FindRtMidi.cmake b/cmake/modules/FindRtMidi.cmake index 3b57c76f25..213c990b52 100644 --- a/cmake/modules/FindRtMidi.cmake +++ b/cmake/modules/FindRtMidi.cmake @@ -1,5 +1,5 @@ # -# FindRtMidd.cmake +# FindRtMidi.cmake # # Try to find the RtMidi library # diff --git a/cmake/modules/FindSoxr.cmake b/cmake/modules/FindSoxr.cmake new file mode 100644 index 0000000000..367022e9ec --- /dev/null +++ b/cmake/modules/FindSoxr.cmake @@ -0,0 +1,30 @@ +# +# FindSoxr.cmake +# +# Try to find the libsoxr resampling library +# +# You can provide a LIBSOXR_ROOT_DIR which contains lib and include directories +# +# Once done this will define +# +# SOXR_FOUND - system found libsoxr +# SOXR_INCLUDE_DIRS - the libsoxr include directory +# SOXR_LIBRARIES - link to this to use libsoxr +# +# Created on 1/22/2015 by Stephen Birarda +# Copyright 2015 High Fidelity, Inc. +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# + +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("soxr") + +find_path(SOXR_INCLUDE_DIRS soxr.h PATH_SUFFIXES include HINTS ${SOXR_SEARCH_DIRS}) +find_library(SOXR_LIBRARIES NAMES soxr PATH_SUFFIXES lib HINTS ${SOXR_SEARCH_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SOXR DEFAULT_MSG SOXR_INCLUDE_DIRS SOXR_LIBRARIES) + +mark_as_advanced(SOXR_INCLUDE_DIRS SOXR_LIBRARIES SOXR_SEARCH_DIRS) \ No newline at end of file diff --git a/cmake/modules/FindTBB.cmake b/cmake/modules/FindTBB.cmake index bce667b7d4..03ac99b73c 100644 --- a/cmake/modules/FindTBB.cmake +++ b/cmake/modules/FindTBB.cmake @@ -28,7 +28,7 @@ set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") if (APPLE) set(_TBB_LIB_DIR "lib/libc++") -elseif (UNIX) +elseif (UNIX AND NOT ANDROID) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(_TBB_ARCH_DIR "intel64") else() @@ -56,6 +56,13 @@ elseif (WIN32) endif() set(_TBB_LIB_DIR "lib/${_TBB_ARCH_DIR}/vc12") +elseif (ANDROID) + set(_TBB_DEFAULT_INSTALL_DIR "/tbb") + set(_TBB_LIB_NAME "tbb") + set(_TBB_LIB_DIR "lib") + set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") endif () find_library(TBB_LIBRARY_DEBUG NAMES ${_TBB_LIB_NAME}_debug PATH_SUFFIXES ${_TBB_LIB_DIR} HINTS ${TBB_SEARCH_DIRS}) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index e2f751a7f0..fdaede8c44 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -6,7 +6,7 @@ { "name": "access_token", "label": "Access Token", - "help": "This is an access token generated on the My Security page of your High Fidelity account.
Generate a token with the 'domains' scope and paste it here.
This is required to associate this domain-server with a domain in your account." + "help": "This is an access token generated on the My Security page of your High Fidelity account.
Generate a token with the 'domains' scope and paste it here.
This is required to associate this domain-server with a domain in your account." }, { "name": "id", @@ -30,7 +30,7 @@ }, { "value": "disabled", - "label": "None: use the network information I have entered for this domain at data.highfidelity.io" + "label": "None: use the network information I have entered for this domain at metaverse.highfidelity.io" } ] }, @@ -73,6 +73,20 @@ "can_set": true } ] + }, + { + "name": "allowed_editors", + "type": "table", + "label": "Allowed Editors", + "help": "List the High Fidelity names for people you want to be able lock or unlock entities in this domain.
An empty list means everyone.", + "numbered": false, + "columns": [ + { + "name": "username", + "label": "Username", + "can_set": true + } + ] } ] }, @@ -395,6 +409,13 @@ "default": "", "advanced": true }, + { + "name": "wantEditLogging", + "type": "checkbox", + "help": "Logging of all edits to entities", + "default": true, + "advanced": true + }, { "name": "verboseDebug", "type": "checkbox", @@ -433,4 +454,4 @@ } ] } -] \ No newline at end of file +] diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index bdd80df9ec..f62515c863 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -652,7 +652,7 @@ function chooseFromHighFidelityDomains(clickedButton) { clickedButton.attr('disabled', 'disabled') // get a list of user domains from data-web - data_web_domains_url = "https://data.highfidelity.io/api/v1/domains?access_token=" + data_web_domains_url = "https://metaverse.highfidelity.io/api/v1/domains?access_token=" $.getJSON(data_web_domains_url + Settings.initialValues.metaverse.access_token, function(data){ modal_buttons = { @@ -682,7 +682,7 @@ function chooseFromHighFidelityDomains(clickedButton) { modal_buttons["success"] = { label: 'Create new domain', callback: function() { - window.open("https://data.highfidelity.io/user/domains", '_blank'); + window.open("https://metaverse.highfidelity.io/user/domains", '_blank'); } } modal_body = "

You do not have any domains in your High Fidelity account." + diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 7cfeed3331..f84722a438 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,6 +41,11 @@ int const DomainServer::EXIT_CODE_REBOOT = 234923; const QString ICE_SERVER_DEFAULT_HOSTNAME = "ice.highfidelity.io"; + +const QString ALLOWED_USERS_SETTINGS_KEYPATH = "security.allowed_users"; +const QString ALLOWED_EDITORS_SETTINGS_KEYPATH = "security.allowed_editors"; + + DomainServer::DomainServer(int argc, char* argv[]) : QCoreApplication(argc, argv), _httpManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this), @@ -638,10 +643,16 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock // we got a packetUUID we didn't recognize, just add the node nodeUUID = QUuid::createUuid(); } - - SharedNodePointer newNode = DependencyManager::get()->addOrUpdateNode(nodeUUID, nodeType, - publicSockAddr, localSockAddr); + // if this user is in the editors list (or if the editors list is empty) set the user's node's canAdjustLocks to true + const QVariant* allowedEditorsVariant = + valueForKeyPath(_settingsManager.getSettingsMap(), ALLOWED_EDITORS_SETTINGS_KEYPATH); + QStringList allowedEditors = allowedEditorsVariant ? allowedEditorsVariant->toStringList() : QStringList(); + bool canAdjustLocks = allowedEditors.isEmpty() || allowedEditors.contains(username); + + SharedNodePointer newNode = + DependencyManager::get()->addOrUpdateNode(nodeUUID, nodeType, + publicSockAddr, localSockAddr, canAdjustLocks); // when the newNode is created the linked data is also created // if this was a static assignment set the UUID, set the sendingSockAddr DomainServerNodeData* nodeData = reinterpret_cast(newNode->getLinkedData()); @@ -663,7 +674,6 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock } } -const QString ALLOWED_USERS_SETTINGS_KEYPATH = "security.allowed_users"; bool DomainServer::shouldAllowConnectionFromNode(const QString& username, const QByteArray& usernameSignature, @@ -842,6 +852,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif // always send the node their own UUID back QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append); broadcastDataStream << node->getUUID(); + broadcastDataStream << node->getCanAdjustLocks(); int numBroadcastPacketLeadBytes = broadcastDataStream.device()->pos(); @@ -906,10 +917,10 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif } }); } - - // always write the last broadcastPacket - nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); } + + // always write the last broadcastPacket + nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); } void DomainServer::readAvailableDatagrams() { @@ -1925,7 +1936,7 @@ Headers DomainServer::setupCookieHeadersFromProfileReply(QNetworkReply* profileR // persist the cookie to settings file so we can get it back on DS relaunch QStringList path = QStringList() << DS_SETTINGS_SESSIONS_GROUP << cookieUUID.toString(); - SettingHandles::SettingHandle(path).set(QVariant::fromValue(sessionData)); + Setting::Handle(path).set(QVariant::fromValue(sessionData)); // setup expiry for cookie to 1 month from today QDateTime cookieExpiry = QDateTime::currentDateTimeUtc().addMonths(1); diff --git a/examples/acScripts/ambiance.js b/examples/acScripts/ambiance.js index fcc3ba0d80..f4f023a473 100644 --- a/examples/acScripts/ambiance.js +++ b/examples/acScripts/ambiance.js @@ -32,10 +32,4 @@ Script.update.connect(function() { injector = Audio.playSound(sound, audioOptions); print("Playing: " + injector); } -}); - -Script.scriptEnding.connect(function() { - if (injector !== null) { - injector.stop(); - } }); \ No newline at end of file diff --git a/examples/controllers/hydra/airGuitar.js b/examples/controllers/hydra/airGuitar.js index 29ab2f9c44..750bfb5bc7 100644 --- a/examples/controllers/hydra/airGuitar.js +++ b/examples/controllers/hydra/airGuitar.js @@ -85,10 +85,10 @@ function checkHands(deltaTime) { var chord = Controller.getTriggerValue(chordHand); if (volume > 1.0) volume = 1.0; - if ((chord > 0.1) && Audio.isInjectorPlaying(soundPlaying)) { + if ((chord > 0.1) && soundPlaying.isPlaying) { // If chord finger trigger pulled, stop current chord print("stopped sound"); - Audio.stopInjector(soundPlaying); + soundPlaying.stop(); } var BUTTON_COUNT = 6; @@ -132,16 +132,21 @@ function checkHands(deltaTime) { } function playChord(position, volume) { - if (Audio.isInjectorPlaying(soundPlaying)) { + if (soundPlaying.isPlaying) { print("stopped sound"); - Audio.stopInjector(soundPlaying); + soundPlaying.stop(); } print("Played sound: " + whichChord + " at volume " + options.volume); - soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], { - position: position, - volume: volume - }); + if (!soundPlaying) { + soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], { + position: position, + volume: volume + }); + } else { + soundPlaying.restart(); + } + } function keyPressEvent(event) { diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js new file mode 100644 index 0000000000..91ae8e6141 --- /dev/null +++ b/examples/controllers/oculus/goTo.js @@ -0,0 +1,248 @@ +// +// goTo.js +// examples +// +// Created by Thijs Wenker on 12/28/14. +// Copyright 2014 High Fidelity, Inc. +// +// Control a virtual keyboard using your favorite HMD. +// Usage: Enable VR-mode and go to First person mode, +// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. +// +// Enter a location URL using your HMD. Press Enter to pop-up the virtual keyboard and location input. +// Press Space on the keyboard or the X button on your gamepad to press a key that you have selected. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +Script.include("../../libraries/globals.js"); +Script.include("../../libraries/virtualKeyboard.js"); + +const MAX_SHOW_INSTRUCTION_TIMES = 2; +const INSTRUCTIONS_SETTING = "GoToInstructionsShowCounter" + +var windowDimensions = Controller.getViewportDimensions(); + +function Instructions(imageURL, originalWidth, originalHeight) { + var tthis = this; + this.originalSize = {w: originalWidth, h: originalHeight}; + this.visible = false; + this.overlay = Overlays.addOverlay("image", { + imageURL: imageURL, + x: 0, + y: 0, + width: originalWidth, + height: originalHeight, + alpha: 1, + visible: this.visible + }); + + this.show = function() { + var timesShown = Settings.getValue(INSTRUCTIONS_SETTING); + timesShown = timesShown === "" ? 0 : parseInt(timesShown); + print(timesShown); + if (timesShown < MAX_SHOW_INSTRUCTION_TIMES) { + Settings.setValue(INSTRUCTIONS_SETTING, timesShown + 1); + tthis.visible = true; + tthis.rescale(); + Overlays.editOverlay(tthis.overlay, {visible: tthis.visible}); + return; + } + tthis.remove(); + } + + this.remove = function() { + Overlays.deleteOverlay(tthis.overlay); + tthis.visible = false; + }; + + this.rescale = function() { + var scale = Math.min(windowDimensions.x / tthis.originalSize.w, windowDimensions.y / tthis.originalSize.h); + var newWidth = tthis.originalSize.w * scale; + var newHeight = tthis.originalSize.h * scale; + Overlays.editOverlay(tthis.overlay, { + x: (windowDimensions.x / 2) - (newWidth / 2), + y: (windowDimensions.y / 2) - (newHeight / 2), + width: newWidth, + height: newHeight + }); + }; + this.rescale(); +}; + +var theInstruction = new Instructions(HIFI_PUBLIC_BUCKET + "images/tutorial-goTo.svg", 457, 284.1); + +var firstControllerPlugged = false; + + +var cursor = new Cursor({visible: false}); +var keyboard = new Keyboard({visible: false}); +var textFontSize = 9; +var text = null; +var locationURL = ""; + +function appendChar(char) { + locationURL += char; + updateTextOverlay(); + Overlays.editOverlay(text, {text: locationURL}); +} + +function deleteChar() { + if (locationURL.length > 0) { + locationURL = locationURL.substring(0, locationURL.length - 1); + updateTextOverlay(); + } +} + +function updateTextOverlay() { + var maxLineWidth = Overlays.textSize(text, locationURL).width; + var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; + var maxFontSize = 140; + textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; + var topMargin = (250 - textFontSize) / 4; + Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin, visible: keyboard.visible}); + maxLineWidth = Overlays.textSize(text, locationURL).width; + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); +} + +keyboard.onKeyPress = function(event) { + if (event.event == 'keypress') { + appendChar(event.char); + } +}; + +keyboard.onKeyRelease = function(event) { + // you can cancel a key by releasing its focusing before releasing it + if (event.focus) { + if (event.event == 'delete') { + deleteChar(); + } else if (event.event == 'submit' || event.event == 'enter') { + print("going to hifi://" + locationURL); + location = "hifi://" + locationURL; + locationURL = ""; + keyboard.hide(); + cursor.hide(); + updateTextOverlay(); + } + } +}; + +keyboard.onFullyLoaded = function() { + print("Virtual-keyboard fully loaded."); + var dimensions = Controller.getViewportDimensions(); + text = Overlays.addOverlay("text", { + x: 0, + y: dimensions.y - keyboard.height() - 260, + width: dimensions.x, + height: 250, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 0, green: 0, blue: 0}, + topMargin: 5, + leftMargin: 0, + font: {size: textFontSize}, + text: "", + alpha: 0.8, + visible: keyboard.visible + }); + updateTextOverlay(); + // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard + cursor.initialize(); + cursor.updateVisibility(keyboard.visible); + cursor.onUpdate = function(position) { + keyboard.setFocusPosition(position.x, position.y); + }; +}; + +function keyPressEvent(event) { + if (theInstruction.visible) { + return; + } + if (event.key === SPACEBAR_CHARCODE) { + keyboard.pressFocussedKey(); + } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { + keyboard.toggle(); + if (cursor !== undefined) { + cursor.updateVisibility(keyboard.visible); + } + Overlays.editOverlay(text, {visible: keyboard.visible}); + } +} + +function keyReleaseEvent(event) { + if (theInstruction.visible) { + return; + } + if (event.key === SPACEBAR_CHARCODE) { + keyboard.releaseKeys(); + } +} + +function scriptEnding() { + keyboard.remove(); + cursor.remove(); + Overlays.deleteOverlay(text); + Overlays.deleteOverlay(textSizeMeasureOverlay); + Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); + Controller.releaseKeyEvents({key: RETURN_CHARCODE}); + Controller.releaseKeyEvents({key: ENTER_CHARCODE}); + theInstruction.remove(); +} + +function reportButtonValue(button, newValue, oldValue) { + if (theInstruction.visible) { + if (button == Joysticks.BUTTON_FACE_BOTTOM && newValue) { + theInstruction.remove(); + } + } else if (button == Joysticks.BUTTON_FACE_BOTTOM) { + if (newValue) { + keyboard.pressFocussedKey(); + } else { + keyboard.releaseKeys(); + } + } else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) { + deleteChar(); + } else if (button == Joysticks.BUTTON_FACE_LEFT && newValue) { + keyboard.hide(); + if (cursor !== undefined) { + cursor.hide(); + } + Overlays.editOverlay(text, {visible: false}); + } else if (button == Joysticks.BUTTON_RIGHT_SHOULDER && newValue) { + if (keyboard.visible) { + print("going to hifi://" + locationURL); + location = "hifi://" + locationURL; + locationURL = ""; + keyboard.hide(); + cursor.hide(); + updateTextOverlay(); + return; + } + keyboard.show(); + if (cursor !== undefined) { + cursor.show(); + } + Overlays.editOverlay(text, {visible: true}); + } +} + +function addJoystick(gamepad) { + gamepad.buttonStateChanged.connect(reportButtonValue); + if (!firstControllerPlugged) { + firstControllerPlugged = true; + theInstruction.show(); + } +} + +var allJoysticks = Joysticks.getAllJoysticks(); +for (var i = 0; i < allJoysticks.length; i++) { + addJoystick(allJoysticks[i]); +} + +Joysticks.joystickAdded.connect(addJoystick); +Controller.captureKeyEvents({key: RETURN_CHARCODE}); +Controller.captureKeyEvents({key: ENTER_CHARCODE}); +Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); +Controller.keyPressEvent.connect(keyPressEvent); +Controller.keyReleaseEvent.connect(keyReleaseEvent); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js new file mode 100644 index 0000000000..c3cb3c6316 --- /dev/null +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -0,0 +1,183 @@ +// +// virtualKeyboardTextEntityExample.js +// examples +// +// Created by Thijs Wenker on 12/28/14. +// Copyright 2014 High Fidelity, Inc. +// +// Control a virtual keyboard using your favorite HMD. +// Usage: Enable VR-mode and go to First person mode, +// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. +// +// leased some code from newEditEntities.js for Text Entity example +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +Script.include("../../libraries/globals.js"); +Script.include("../../libraries/virtualKeyboard.js"); + +const SPAWN_DISTANCE = 1; +const DEFAULT_TEXT_DIMENSION_Z = 0.02; + +const TEXT_MARGIN_TOP = 0.15; +const TEXT_MARGIN_LEFT = 0.15; +const TEXT_MARGIN_RIGHT = 0.17; +const TEXT_MARGIN_BOTTOM = 0.17; + +var windowDimensions = Controller.getViewportDimensions(); +var cursor = new Cursor(); +var keyboard = new Keyboard(); +var textFontSize = 9; +var text = null; +var textText = ""; +var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); + +function appendChar(char) { + textText += char; + updateTextOverlay(); + Overlays.editOverlay(text, {text: textText}); +} + +function deleteChar() { + if (textText.length > 0) { + textText = textText.substring(0, textText.length - 1); + updateTextOverlay(); + } +} + +function updateTextOverlay() { + var textLines = textText.split("\n"); + var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textText).width) * textFontSize * 0.90; + var maxFontSize = 170 / textLines.length; + textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; + var topMargin = (250 - (textFontSize * textLines.length)) / 4; + Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - Overlays.textSize(text, textLines).width) / 2}); +} + +keyboard.onKeyPress = function(event) { + if (event.event == 'keypress') { + appendChar(event.char); + } else if (event.event == 'enter') { + appendChar("\n"); + } +}; + +keyboard.onKeyRelease = function(event) { + print("Key release event test"); + // you can cancel a key by releasing its focusing before releasing it + if (event.focus) { + if (event.event == 'delete') { + deleteChar(); + } else if (event.event == 'submit') { + print(textText); + + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); + + var textLines = textText.split("\n"); + var maxLineWidth = Overlays.textSize(textSizeMeasureOverlay, textText).width; + var usernameLine = "--" + GlobalServices.myUsername; + var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; + if (maxLineWidth < usernameWidth) { + maxLineWidth = usernameWidth; + } else { + var spaceableWidth = maxLineWidth - usernameWidth; + //TODO: WORKAROUND WARNING BELOW Fix this when spaces are not trimmed out of the textsize calculation anymore + var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, "| |").width + - Overlays.textSize(textSizeMeasureOverlay, "||").width; + var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); + for (var i = 0; i < numberOfSpaces; i++) { + usernameLine = " " + usernameLine; + } + } + var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; + if (position.x > 0 && position.y > 0 && position.z > 0) { + Entities.addEntity({ + type: "Text", + rotation: MyAvatar.orientation, + position: position, + dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, + backgroundColor: { red: 0, green: 0, blue: 0 }, + textColor: { red: 255, green: 255, blue: 255 }, + text: textText + "\n" + usernameLine, + lineHeight: 0.1 + }); + } + textText = ""; + updateTextOverlay(); + } + } +}; + +keyboard.onFullyLoaded = function() { + print("Virtual-keyboard fully loaded."); + var dimensions = Controller.getViewportDimensions(); + text = Overlays.addOverlay("text", { + x: 0, + y: dimensions.y - keyboard.height() - 260, + width: dimensions.x, + height: 250, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 0, green: 0, blue: 0}, + topMargin: 5, + leftMargin: 0, + font: {size: textFontSize}, + text: "", + alpha: 0.8 + }); + updateTextOverlay(); + // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard + cursor.initialize(); + cursor.onUpdate = function(position) { + keyboard.setFocusPosition(position.x, position.y); + }; +}; + +function keyPressEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.pressFocussedKey(); + } +} + +function keyReleaseEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.releaseKeys(); + } +} + +function scriptEnding() { + keyboard.remove(); + cursor.remove(); + Overlays.deleteOverlay(text); + Overlays.deleteOverlay(textSizeMeasureOverlay); + Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); +} + +function reportButtonValue(button, newValue, oldValue) { + if (button == Joysticks.BUTTON_FACE_BOTTOM) { + if (newValue) { + keyboard.pressFocussedKey(); + } else { + keyboard.releaseKeys(); + } + } else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) { + deleteChar(); + } +} + +function addJoystick(gamepad) { + gamepad.buttonStateChanged.connect(reportButtonValue); +} + +var allJoysticks = Joysticks.getAllJoysticks(); +for (var i = 0; i < allJoysticks.length; i++) { + addJoystick(allJoysticks[i]); +} + +Joysticks.joystickAdded.connect(addJoystick); +Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); +Controller.keyPressEvent.connect(keyPressEvent); +Controller.keyReleaseEvent.connect(keyReleaseEvent); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index a14958dd23..65682deb74 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +Script.load("progress.js"); Script.load("lookWithTouch.js"); Script.load("editEntities.js"); Script.load("selectAudioDevice.js"); @@ -16,3 +17,4 @@ Script.load("headMove.js"); Script.load("inspect.js"); Script.load("lobby.js"); Script.load("notifications.js"); +Script.load("lookWithMouse.js") diff --git a/examples/dice.js b/examples/dice.js new file mode 100644 index 0000000000..d33da576c1 --- /dev/null +++ b/examples/dice.js @@ -0,0 +1,109 @@ +// +// dice.js +// examples +// +// Created by Philip Rosedale on February 2, 2015 +// Copyright 2015 High Fidelity, Inc. +// +// Press the dice button to throw some dice from the center of the screen. +// Change NUMBER_OF_DICE to change the number thrown (Yahtzee, anyone?) +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var isDice = false; +var NUMBER_OF_DICE = 2; +var dice = []; +var DIE_SIZE = 0.20; + +var madeSound = true; // Set false at start of throw to look for collision + +HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + +var rollSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/dice/diceRoll.wav"); + +var screenSize = Controller.getViewportDimensions(); +var offButton = Overlays.addOverlay("image", { + x: screenSize.x - 48, + y: 96, + width: 32, + height: 32, + imageURL: HIFI_PUBLIC_BUCKET + "images/close.png", + color: { red: 255, green: 255, blue: 255}, + alpha: 1 + }); +var diceButton = Overlays.addOverlay("image", { + x: screenSize.x - 48, + y: 130, + width: 32, + height: 32, + imageURL: HIFI_PUBLIC_BUCKET + "images/die.png", + color: { red: 255, green: 255, blue: 255}, + alpha: 1 + }); + +var GRAVITY = -3.5; +var LIFETIME = 300; +function shootDice(position, velocity) { + for (var i = 0; i < NUMBER_OF_DICE; i++) { + dice.push(Entities.addEntity( + { type: "Model", + modelURL: HIFI_PUBLIC_BUCKET + "models/props/Dice/goldDie.fbx", + position: position, + velocity: velocity, + rotation: Quat.fromPitchYawRollDegrees(Math.random() * 360, Math.random() * 360, Math.random() * 360), + lifetime: LIFETIME, + gravity: { x: 0, y: GRAVITY, z: 0 }, + collisionsWillMove: true + })); + position = Vec3.sum(position, Vec3.multiply(DIE_SIZE, Vec3.normalize(Quat.getRight(Camera.getOrientation())))); + } +} + +function deleteDice() { + while(dice.length > 0) { + Entities.deleteEntity(dice.pop()); + } +} + +function entityCollisionWithEntity(entity1, entity2, collision) { + if (!madeSound) { + // Is it one of our dice? + for (var i = 0; i < dice.length; i++) { + if (!dice[i].isKnownID) { + dice[i] = Entities.identifyEntity(dice[i]); + } + if ((entity1.id == dice[i].id) || (entity2.id == dice[i].id)) { + madeSound = true; + Audio.playSound(rollSound, { position: collision.contactPoint }); + } + } + + } +} + +function mousePressEvent(event) { + var clickedText = false; + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + if (clickedOverlay == offButton) { + deleteDice(); + } else if (clickedOverlay == diceButton) { + var HOW_HARD = 2.0; + var position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); + var velocity = Vec3.multiply(HOW_HARD, Quat.getFront(Camera.getOrientation())); + shootDice(position, velocity); + madeSound = false; + } +} + +function scriptEnding() { + deleteDice(); + Overlays.deleteOverlay(offButton); + Overlays.deleteOverlay(diceButton); + +} + +Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); +Controller.mousePressEvent.connect(mousePressEvent); +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/examples/editEntities.js b/examples/editEntities.js index 5c26fc0805..61100b4556 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -46,27 +46,8 @@ gridTool.setVisible(false); var entityListTool = EntityListTool(); -var hasShownPropertiesTool = false; - -var entityListVisible = false; - selectionManager.addEventListener(function() { selectionDisplay.updateHandles(); - if (selectionManager.hasSelection() && !hasShownPropertiesTool) { - // Open properties and model list, but force selection of model list tab - propertiesTool.setVisible(false); - entityListTool.setVisible(false); - gridTool.setVisible(false); - propertiesTool.setVisible(true); - entityListTool.setVisible(true); - gridTool.setVisible(true); - hasShownPropertiesTool = true; - } - if (!selectionManager.hasSelection()) { - toolBar.setActive(false); - } else { - toolBar.setActive(true); - } }); var windowDimensions = Controller.getViewportDimensions(); @@ -93,9 +74,11 @@ var DEFAULT_DIMENSIONS = { }; var MENU_INSPECT_TOOL_ENABLED = "Inspect Tool"; +var MENU_AUTO_FOCUS_ON_SELECT = "Auto Focus on Select"; var MENU_EASE_ON_FOCUS = "Ease Orientation on Focus"; var SETTING_INSPECT_TOOL_ENABLED = "inspectToolEnabled"; +var SETTING_AUTO_FOCUS_ON_SELECT = "autoFocusOnSelect"; var SETTING_EASE_ON_FOCUS = "cameraEaseOnFocus"; var modelURLs = [ @@ -111,6 +94,7 @@ var modelURLs = [ var mode = 0; var isActive = false; +var placingEntityID = null; var toolBar = (function () { var that = {}, @@ -121,15 +105,7 @@ var toolBar = (function () { newSphereButton, newLightButton, newTextButton, - browseModelsButton, - loadURLMenuItem, - loadFileMenuItem, - menuItemWidth, - menuItemOffset, - menuItemHeight, - menuItemMargin = 5, - menuTextColor = { red: 255, green: 255, blue: 255 }, - menuBackgroundColor = { red: 18, green: 66, blue: 66 }; + browseModelsButton; function initialize() { toolBar = new ToolBar(0, 0, ToolBar.VERTICAL); @@ -137,10 +113,9 @@ var toolBar = (function () { // Hide active button for now - this may come back, so not deleting yet. activeButton = toolBar.addTool({ imageURL: toolIconUrl + "models-tool.svg", - // subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, - subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: 0, height: 0 }, - width: 0,//toolWidth, - height: 0,//toolHeight, + subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, + width: toolWidth, + height: toolHeight, alpha: 0.9, visible: true }, true, false); @@ -152,7 +127,7 @@ var toolBar = (function () { height: toolHeight, alpha: 0.9, visible: true - }, true, false); + }); browseModelsButton = toolBar.addTool({ imageURL: toolIconUrl + "list-icon.svg", @@ -162,34 +137,6 @@ var toolBar = (function () { visible: true }); - menuItemOffset = toolBar.height / 3 + 2; - menuItemHeight = Tool.IMAGE_HEIGHT / 2 - 2; - - loadURLMenuItem = Overlays.addOverlay("text", { - height: menuItemHeight, - backgroundColor: menuBackgroundColor, - topMargin: menuItemMargin, - text: "Model URL", - alpha: 0.9, - backgroundAlpha: 0.9, - visible: false - }); - - loadFileMenuItem = Overlays.addOverlay("text", { - height: menuItemHeight, - backgroundColor: menuBackgroundColor, - topMargin: menuItemMargin, - text: "Model File", - alpha: 0.9, - backgroundAlpha: 0.9, - visible: false - }); - - menuItemWidth = Math.max(Overlays.textSize(loadURLMenuItem, "Model URL").width, - Overlays.textSize(loadFileMenuItem, "Model File").width) + 20; - Overlays.editOverlay(loadURLMenuItem, { width: menuItemWidth }); - Overlays.editOverlay(loadFileMenuItem, { width: menuItemWidth }); - newCubeButton = toolBar.addTool({ imageURL: toolIconUrl + "add-cube.svg", subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, @@ -228,17 +175,6 @@ var toolBar = (function () { } - function toggleNewModelButton(active) { - if (active === undefined) { - active = !toolBar.toolSelected(newModelButton); - } - toolBar.selectTool(newModelButton, active); - - Overlays.editOverlay(loadURLMenuItem, { visible: active }); - Overlays.editOverlay(loadFileMenuItem, { visible: active }); - } - - that.setActive = function(active) { if (active != isActive) { isActive = active; @@ -252,14 +188,18 @@ var toolBar = (function () { } else { hasShownPropertiesTool = false; cameraManager.enable(); + entityListTool.setVisible(true); + gridTool.setVisible(true); grid.setEnabled(true); + propertiesTool.setVisible(true); + Window.setFocus(); } } toolBar.selectTool(activeButton, active); }; var RESIZE_INTERVAL = 50; - var RESIZE_TIMEOUT = 20000; + var RESIZE_TIMEOUT = 120000; // 2 minutes var RESIZE_MAX_CHECKS = RESIZE_TIMEOUT / RESIZE_INTERVAL; function addModel(url) { var position; @@ -320,11 +260,10 @@ var toolBar = (function () { toolsY = (windowDimensions.y - toolBar.height) / 2; toolBar.move(toolsX, toolsY); - - Overlays.editOverlay(loadURLMenuItem, { x: toolsX - menuItemWidth, y: toolsY + menuItemOffset }); - Overlays.editOverlay(loadFileMenuItem, { x: toolsX - menuItemWidth, y: toolsY + menuItemOffset + menuItemHeight }); }; + var newModelButtonDown = false; + var browseModelsButtonDown = false; that.mousePressEvent = function (event) { var clickedOverlay, url, @@ -337,40 +276,14 @@ var toolBar = (function () { return true; } + // Handle these two buttons in the mouseRelease event handler so that we don't suppress a mouseRelease event from + // occurring when showing a modal dialog. if (newModelButton === toolBar.clicked(clickedOverlay)) { - toggleNewModelButton(); + newModelButtonDown = true; return true; } - - if (clickedOverlay === loadURLMenuItem) { - toggleNewModelButton(false); - url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]); - if (url !== null && url !== "") { - addModel(url); - } - return true; - } - - if (clickedOverlay === loadFileMenuItem) { - toggleNewModelButton(false); - - file = Window.browse("Select your model file ...", - Settings.getValue("LastModelUploadLocation").path(), - "Model files (*.fst *.fbx)"); - //"Model files (*.fst *.fbx *.svo)"); - if (file !== null) { - Settings.setValue("LastModelUploadLocation", file); - modelUploader.upload(file, addModel); - } - return true; - } - if (browseModelsButton === toolBar.clicked(clickedOverlay)) { - toggleNewModelButton(false); - url = Window.s3Browse(".*(fbx|FBX)"); - if (url !== null && url !== "") { - addModel(url); - } + browseModelsButtonDown = true; return true; } @@ -378,7 +291,7 @@ var toolBar = (function () { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Box", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), dimensions: DEFAULT_DIMENSIONS, @@ -395,7 +308,7 @@ var toolBar = (function () { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Sphere", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), dimensions: DEFAULT_DIMENSIONS, @@ -411,7 +324,7 @@ var toolBar = (function () { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Light", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), dimensions: DEFAULT_DIMENSIONS, @@ -432,18 +345,19 @@ var toolBar = (function () { return true; } + if (newTextButton === toolBar.clicked(clickedOverlay)) { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Text", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), - dimensions: DEFAULT_DIMENSIONS, - backgroundColor: { red: 0, green: 0, blue: 0 }, + dimensions: { x: 0.65, y: 0.3, z: 0.01 }, + backgroundColor: { red: 64, green: 64, blue: 64 }, textColor: { red: 255, green: 255, blue: 255 }, text: "some text", - lineHight: "0.1" + lineHeight: 0.06 }); } else { print("Can't create box: Text would be out of bounds."); @@ -451,14 +365,39 @@ var toolBar = (function () { return true; } - return false; }; + that.mouseReleaseEvent = function(event) { + var handled = false; + if (newModelButtonDown) { + var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); + if (newModelButton === toolBar.clicked(clickedOverlay)) { + url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]); + if (url !== null && url !== "") { + addModel(url); + } + handled = true; + } + } else if (browseModelsButtonDown) { + var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); + if (browseModelsButton === toolBar.clicked(clickedOverlay)) { + url = Window.s3Browse(".*(fbx|FBX)"); + if (url !== null && url !== "") { + addModel(url); + } + handled = true; + } + } + + newModelButtonDown = false; + browseModelsButtonDown = false; + + return handled; + } + that.cleanup = function () { toolBar.cleanup(); - Overlays.deleteOverlay(loadURLMenuItem); - Overlays.deleteOverlay(loadFileMenuItem); }; return that; @@ -548,8 +487,25 @@ var mouseCapturedByTool = false; var lastMousePosition = null; var idleMouseTimerId = null; var IDLE_MOUSE_TIMEOUT = 200; +var DEFAULT_ENTITY_DRAG_DROP_DISTANCE = 2.0; function mouseMoveEvent(event) { + if (placingEntityID) { + if (!placingEntityID.isKnownID) { + placingEntityID = Entities.identifyEntity(placingEntityID); + } + var pickRay = Camera.computePickRay(event.x, event.y); + var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; + var offset = Vec3.multiply(distance, pickRay.direction); + var position = Vec3.sum(Camera.position, offset); + Entities.editEntity(placingEntityID, { + position: position, + }); + return; + } + if (!isActive) { + return; + } if (idleMouseTimerId) { Script.clearTimeout(idleMouseTimerId); } @@ -602,6 +558,15 @@ function highlightEntityUnderCursor(position, accurateRay) { function mouseReleaseEvent(event) { + if (toolBar.mouseReleaseEvent(event)) { + return true; + } + if (placingEntityID) { + if (isActive) { + selectionManager.setSelections([placingEntityID]); + } + placingEntityID = null; + } if (isActive && selectionManager.hasSelection()) { tooltip.show(false); } @@ -617,7 +582,7 @@ function mouseReleaseEvent(event) { } function mouseClickEvent(event) { - if (!event.isRightButton) { + if (!event.isLeftButton || !isActive) { return; } @@ -670,19 +635,21 @@ function mouseClickEvent(event) { orientation = MyAvatar.orientation; intersection = rayPlaneIntersection(pickRay, P, Quat.getFront(orientation)); - if (!event.isShifted) { - selectionManager.clearSelections(); - } - var toggle = event.isShifted; - selectionManager.addEntity(foundEntity, toggle); + if (!event.isShifted) { + selectionManager.setSelections([foundEntity]); + } else { + selectionManager.addEntity(foundEntity, true); + } print("Model selected: " + foundEntity.id); selectionDisplay.select(selectedEntityID, event); - cameraManager.focus(selectionManager.worldPosition, - selectionManager.worldDimensions, - Menu.isOptionChecked(MENU_EASE_ON_FOCUS)); + if (Menu.isOptionChecked(MENU_AUTO_FOCUS_ON_SELECT)) { + cameraManager.focus(selectionManager.worldPosition, + selectionManager.worldDimensions, + Menu.isOptionChecked(MENU_EASE_ON_FOCUS)); + } } } } @@ -724,7 +691,9 @@ function setupModelMenus() { Menu.addMenuItem({ menuName: "File", menuItemName: "Import Models", shortcutKey: "CTRL+META+I", afterItem: "Export Models" }); - Menu.addMenuItem({ menuName: "View", menuItemName: MENU_EASE_ON_FOCUS, afterItem: MENU_INSPECT_TOOL_ENABLED, + Menu.addMenuItem({ menuName: "View", menuItemName: MENU_AUTO_FOCUS_ON_SELECT, afterItem: MENU_INSPECT_TOOL_ENABLED, + isCheckable: true, isChecked: Settings.getValue(SETTING_AUTO_FOCUS_ON_SELECT) == "true" }); + Menu.addMenuItem({ menuName: "View", menuItemName: MENU_EASE_ON_FOCUS, afterItem: MENU_AUTO_FOCUS_ON_SELECT, isCheckable: true, isChecked: Settings.getValue(SETTING_EASE_ON_FOCUS) == "true" }); Entities.setLightsArePickable(false); @@ -750,11 +719,12 @@ function cleanupModelMenus() { Menu.removeMenuItem("File", "Import Models"); Menu.removeMenuItem("View", MENU_INSPECT_TOOL_ENABLED); + Menu.removeMenuItem("View", MENU_AUTO_FOCUS_ON_SELECT); Menu.removeMenuItem("View", MENU_EASE_ON_FOCUS); } Script.scriptEnding.connect(function() { - Settings.setValue(SETTING_INSPECT_TOOL_ENABLED, Menu.isOptionChecked(MENU_INSPECT_TOOL_ENABLED)); + Settings.setValue(SETTING_AUTO_FOCUS_ON_SELECT, Menu.isOptionChecked(MENU_AUTO_FOCUS_ON_SELECT)); Settings.setValue(SETTING_EASE_ON_FOCUS, Menu.isOptionChecked(MENU_EASE_ON_FOCUS)); progressDialog.cleanup(); @@ -820,9 +790,7 @@ function handeMenuEvent(menuItem) { } else if (menuItem == "Import Models") { modelImporter.doImport(); } else if (menuItem == "Entity List...") { - if (isActive) { - entityListTool.toggleVisible(); - } + entityListTool.toggleVisible(); } tooltip.show(false); } @@ -1019,9 +987,18 @@ PropertiesTool = function(opts) { selectionManager.saveProperties(); for (var i = 0; i < selectionManager.selections.length; i++) { var properties = selectionManager.savedProperties[selectionManager.selections[i].id]; - Entities.editEntity(selectionManager.selections[i], { - dimensions: properties.naturalDimensions, - }); + var naturalDimensions = properties.naturalDimensions; + + // If any of the natural dimensions are not 0, resize + if (properties.type == "Model" && naturalDimensions.x == 0 + && naturalDimensions.y == 0 && naturalDimensions.z == 0) { + Window.alert("Cannot reset entity to its natural dimensions: Model URL" + + " is invalid or the model has not yet been loaded."); + } else { + Entities.editEntity(selectionManager.selections[i], { + dimensions: properties.naturalDimensions, + }); + } } pushCommandForSelections(); selectionManager._update(); diff --git a/examples/entityScripts/movable.js b/examples/entityScripts/movable.js index 21e6261179..066f258f2e 100644 --- a/examples/entityScripts/movable.js +++ b/examples/entityScripts/movable.js @@ -48,7 +48,8 @@ this.turnSounds = new Array(); this.moveSound = null; this.turnSound = null; - this.injector = null; + this.moveInjector = null; + this.turnInjector = null; var debug = false; var displayRotateTargets = true; // change to false if you don't want the rotate targets @@ -92,9 +93,14 @@ } if (this.moveSound && this.moveSound.downloaded) { if (debug) { - print("playMoveSound() --- calling this.injector = Audio.playSound(this.moveSound...)"); + print("playMoveSound() --- calling this.moveInjector = Audio.playSound(this.moveSound...)"); + } + + if (!this.moveInjector) { + this.moveInjector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 }); + } else { + this.moveInjector.restart(); } - this.injector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 }); } } @@ -105,9 +111,13 @@ } if (this.turnSound && this.turnSound.downloaded) { if (debug) { - print("playTurnSound() --- calling this.injector = Audio.playSound(this.turnSound...)"); + print("playTurnSound() --- calling this.turnInjector = Audio.playSound(this.turnSound...)"); + } + if (!this.turnInjector) { + this.turnInjector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 }); + } else { + this.turnInjector.restart(); } - this.injector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 }); } } @@ -116,9 +126,11 @@ if (debug) { print("stopSound()"); } - if (this.injector) { - Audio.stopInjector(this.injector); - this.injector = null; + if (this.turnInjector) { + this.turnInjector.stop(); + } + if (this.moveInjector) { + this.moveInjector.stop(); } } @@ -174,7 +186,7 @@ this.move = function(mouseEvent) { this.updatePosition(mouseEvent); - if (this.injector === null) { + if (this.moveInjector === null || !this.moveInjector.isPlaying) { this.playMoveSound(); } }; @@ -233,7 +245,7 @@ } } - if (this.injector === null) { + if (this.turnInjector === null || !this.turnInjector.isPlaying) { this.playTurnSound(); } }; diff --git a/examples/entityScripts/portal.js b/examples/entityScripts/portal.js new file mode 100644 index 0000000000..e1f00b0afc --- /dev/null +++ b/examples/entityScripts/portal.js @@ -0,0 +1,41 @@ +(function(){ + var teleport; + var portalDestination; + + function playSound() { + Audio.playSound(teleport, { volume: 0.40, localOnly: true }); + }; + + this.preload = function(entityID) { + teleport = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/birarda/teleport.raw"); + + var properties = Entities.getEntityProperties(entityID); + portalDestination = properties.userData; + + print("The portal destination is " + portalDestination); + } + + this.enterEntity = function(entityID) { + if (portalDestination.length > 0) { + print("Teleporting to hifi://" + portalDestination); + Window.location = "hifi://" + portalDestination; + } + + }; + + this.leaveEntity = function(entityID) { + Entities.editEntity(entityID, { + animationURL: "http://hifi-public.s3.amazonaws.com/models/content/phonebooth.fbx", + animationSettings: '{ "frameIndex": 1, "running": false }' + }); + + playSound(); + }; + + this.hoverEnterEntity = function(entityID) { + Entities.editEntity(entityID, { + animationURL: "http://hifi-public.s3.amazonaws.com/models/content/phonebooth.fbx", + animationSettings: '{ "fps": 24, "firstFrame": 1, "lastFrame": 25, "frameIndex": 1, "running": true, "hold": true }' + }); + }; +}) \ No newline at end of file diff --git a/examples/example/audio/birdSongs.js b/examples/example/audio/birdSongs.js index 267fa20b49..876f942dbc 100644 --- a/examples/example/audio/birdSongs.js +++ b/examples/example/audio/birdSongs.js @@ -75,14 +75,14 @@ function maybePlaySound(deltaTime) { //print("number playing = " + numPlaying); } for (var i = 0; i < playing.length; i++) { - if (!Audio.isInjectorPlaying(playing[i].audioId)) { + if (!playing[i].audioId.isPlaying) { Entities.deleteEntity(playing[i].entityId); if (useLights) { Entities.deleteEntity(playing[i].lightId); } playing.splice(i, 1); } else { - var loudness = Audio.getLoudness(playing[i].audioId); + var loudness = playing[i].audioId.loudness; var newColor = { red: playing[i].color.red, green: playing[i].color.green, blue: playing[i].color.blue }; if (loudness > 0.05) { newColor.red *= (1.0 - loudness); diff --git a/examples/example/audio/radio.js b/examples/example/audio/radio.js index 7ac33675a1..5a8b4cbb88 100644 --- a/examples/example/audio/radio.js +++ b/examples/example/audio/radio.js @@ -76,9 +76,6 @@ function scriptEnding() { if (entity != null) { Entities.deleteEntity(entity); } - if (injector != null) { - injector.stop(); - } } Script.update.connect(update); diff --git a/examples/example/entities/butterflies.js b/examples/example/entities/butterflies.js index 336e128d83..9cbe8f966c 100644 --- a/examples/example/entities/butterflies.js +++ b/examples/example/entities/butterflies.js @@ -13,6 +13,9 @@ // +print("BUTTERFLIES START"); + + var numButterflies = 25; @@ -109,7 +112,7 @@ function updateButterflies(deltaTime) { var properties = Entities.getEntityProperties(butterflies[i]); if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) { Entities.editEntity(butterflies[i], { position: flockPosition } ); - } else if (properties.velocity.y < 0.0) { + } else if (properties.velocity.y <= 0.0) { // If falling, Create a new direction and impulse var HORIZ_SCALE = 0.50; var VERT_SCALE = 0.50; @@ -139,3 +142,5 @@ Script.scriptEnding.connect(function() { Entities.deleteEntity(butterflies[i]); } }); + +print("BUTTERFLIES END"); diff --git a/examples/html/entityList.html b/examples/html/entityList.html index 01061f1eb0..bbfa4d81b8 100644 --- a/examples/html/entityList.html +++ b/examples/html/entityList.html @@ -168,14 +168,16 @@ -

+
- +
+ +
diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index d572ef1ad4..84a8d23a74 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -119,6 +119,7 @@ var elCollisionsWillMove = document.getElementById("property-collisions-will-move"); var elLifetime = document.getElementById("property-lifetime"); var elScriptURL = document.getElementById("property-script-url"); + var elUserData = document.getElementById("property-user-data"); var elBoxSections = document.querySelectorAll(".box-section"); var elBoxColorRed = document.getElementById("property-box-red"); @@ -154,6 +155,7 @@ var elModelAnimationSettings = document.getElementById("property-model-animation-settings"); var elModelTextures = document.getElementById("property-model-textures"); var elModelOriginalTextures = document.getElementById("property-model-original-textures"); + var elModelShapeType = document.getElementById("property-model-shape"); var elTextSections = document.querySelectorAll(".text-section"); var elTextText = document.getElementById("property-text-text"); @@ -224,6 +226,7 @@ elCollisionsWillMove.checked = properties.collisionsWillMove; elLifetime.value = properties.lifetime; elScriptURL.value = properties.script; + elUserData.value = properties.userData; if (properties.type != "Box") { for (var i = 0; i < elBoxSections.length; i++) { @@ -256,6 +259,7 @@ elModelAnimationSettings.value = properties.animationSettings; elModelTextures.value = properties.textures; elModelOriginalTextures.value = properties.originalTextures; + elModelShapeType.value = properties.shapeType; } if (properties.type != "Text") { @@ -361,6 +365,7 @@ elCollisionsWillMove.addEventListener('change', createEmitCheckedPropertyUpdateFunction('collisionsWillMove')); elLifetime.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifetime')); elScriptURL.addEventListener('change', createEmitTextPropertyUpdateFunction('script')); + elUserData.addEventListener('change', createEmitTextPropertyUpdateFunction('userData')); var boxColorChangeFunction = createEmitColorPropertyUpdateFunction( 'color', elBoxColorRed, elBoxColorGreen, elBoxColorBlue); @@ -401,6 +406,7 @@ elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex')); elModelAnimationSettings.addEventListener('change', createEmitTextPropertyUpdateFunction('animationSettings')); elModelTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures')); + elModelShapeType.addEventListener('change', createEmitNumberPropertyUpdateFunction('shapeType')); elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text')); elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight')); @@ -559,13 +565,6 @@
-
Mass
-
- -
-
- -
Density
@@ -600,6 +599,13 @@
+
+
User Data
+
+ +
+
+
Color
@@ -645,7 +651,7 @@
Animation Settings
- +
@@ -661,6 +667,17 @@
+
+
Shape Type
+
+ +
+
+
Text
diff --git a/examples/html/gridControls.html b/examples/html/gridControls.html index 7e354c5bec..941a4b5c2a 100644 --- a/examples/html/gridControls.html +++ b/examples/html/gridControls.html @@ -30,8 +30,8 @@ elPosY.value = origin.y.toFixed(2); } - if (data.minorGridSpacing !== undefined) { - elMinorSpacing.value = data.minorGridSpacing; + if (data.minorGridWidth !== undefined) { + elMinorSpacing.value = data.minorGridWidth; } if (data.majorGridEvery !== undefined) { @@ -57,7 +57,7 @@ origin: { y: elPosY.value, }, - minorGridSpacing: elMinorSpacing.value, + minorGridWidth: elMinorSpacing.value, majorGridEvery: elMajorSpacing.value, gridColor: gridColor, colorIndex: gridColorIndex, diff --git a/examples/html/style.css b/examples/html/style.css index 8b52447ea2..7177b8c8ba 100644 --- a/examples/html/style.css +++ b/examples/html/style.css @@ -86,6 +86,20 @@ input[type=button] { font-weight: bold; } +#entity-list-header { + padding: 0.5em; +} + +#search-area { + width: 100%; + padding: 0.5em; + box-sizing: border-box; +} + +#search-area input { + width: 100%; +} + textarea, input { margin: 0; padding: 1.5pt; @@ -120,6 +134,7 @@ table#entity-table { } #entity-table tr.selected { + color: rgb(43, 43, 43); background-color: #AAA; } diff --git a/examples/libraries/entityCameraTool.js b/examples/libraries/entityCameraTool.js index bf5bf6b105..bbd28dd38a 100644 --- a/examples/libraries/entityCameraTool.js +++ b/examples/libraries/entityCameraTool.js @@ -15,11 +15,11 @@ var MOUSE_SENSITIVITY = 0.9; var SCROLL_SENSITIVITY = 0.05; var PAN_ZOOM_SCALE_RATIO = 0.4; -var KEY_ORBIT_SENSITIVITY = 40; -var KEY_ZOOM_SENSITIVITY = 10; +var KEY_ORBIT_SENSITIVITY = 90; +var KEY_ZOOM_SENSITIVITY = 3; -// Scaling applied based on the size of the object being focused -var FOCUS_ZOOM_SCALE = 1.3; +// Scaling applied based on the size of the object being focused (Larger values focus further away) +var FOCUS_ZOOM_SCALE = 2.3; // Minimum zoom level when focusing on an object var FOCUS_MIN_ZOOM = 0.5; @@ -433,8 +433,13 @@ CameraManager = function() { that.targetYaw += (actions.orbitRight - actions.orbitLeft) * dt * KEY_ORBIT_SENSITIVITY; that.targetPitch += (actions.orbitUp - actions.orbitDown) * dt * KEY_ORBIT_SENSITIVITY; that.targetPitch = clamp(that.targetPitch, -90, 90); - that.targetZoomDistance += (actions.orbitBackward - actions.orbitForward) * dt * KEY_ZOOM_SENSITIVITY; - that.targetZoomDistance = clamp(that.targetZoomDistance, MIN_ZOOM_DISTANCE, MAX_ZOOM_DISTANCE); + + var dZoom = actions.orbitBackward - actions.orbitForward; + if (dZoom) { + dZoom *= that.targetZoomDistance * dt * KEY_ZOOM_SENSITIVITY; + that.targetZoomDistance += dZoom; + that.targetZoomDistance = clamp(that.targetZoomDistance, MIN_ZOOM_DISTANCE, MAX_ZOOM_DISTANCE); + } if (easing) { diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 4b931f0c57..85be97b1ce 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -1221,7 +1221,7 @@ SelectionDisplay = (function () { x: selectionManager.worldDimensions.x, y: selectionManager.worldDimensions.z }, - rotation: Quat.fromPitchYawRollDegrees(0, 0, 0), + rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), }); diff --git a/examples/libraries/modelUploader.js b/examples/libraries/modelUploader.js index 7f575a54ef..fcc96854ab 100644 --- a/examples/libraries/modelUploader.js +++ b/examples/libraries/modelUploader.js @@ -21,7 +21,7 @@ modelUploader = (function () { //svoBuffer, mapping, geometry, - API_URL = "https://data.highfidelity.io/api/v1/models", + API_URL = "https://metaverse.highfidelity.io/api/v1/models", MODEL_URL = "http://public.highfidelity.io/models/content", NAME_FIELD = "name", SCALE_FIELD = "scale", diff --git a/examples/controllers/oculus/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js similarity index 61% rename from examples/controllers/oculus/virtualKeyboard.js rename to examples/libraries/virtualKeyboard.js index d17b36ae4f..a1f952a5eb 100644 --- a/examples/controllers/oculus/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -9,179 +9,50 @@ // Usage: Enable VR-mode and go to First person mode, // look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. // -// leased some code from newEditEntities.js for Text Entity example -// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; +// experimental 3dmode +THREE_D_MODE = false; -const KBD_UPPERCASE_DEFAULT = 0; -const KBD_LOWERCASE_DEFAULT = 1; -const KBD_UPPERCASE_HOVER = 2; -const KBD_LOWERCASE_HOVER = 3; -const KBD_BACKGROUND = 4; +KBD_UPPERCASE_DEFAULT = 0; +KBD_LOWERCASE_DEFAULT = 1; +KBD_UPPERCASE_HOVER = 2; +KBD_LOWERCASE_HOVER = 3; +KBD_BACKGROUND = 4; -const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; -const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; +KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; +CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; -const SPACEBAR_CHARCODE = 32; +RETURN_CHARCODE = 0x01000004; +ENTER_CHARCODE = 0x01000005; +SPACEBAR_CHARCODE = 32; -const KEYBOARD_WIDTH = 1174.7; -const KEYBOARD_HEIGHT = 434.1; +KEYBOARD_WIDTH = 1174.7; +KEYBOARD_HEIGHT = 434.1; -const CURSOR_WIDTH = 33.9; -const CURSOR_HEIGHT = 33.9; +CURSOR_WIDTH = 33.9; +CURSOR_HEIGHT = 33.9; + +KEYBOARD_SCALE_MULTIPLIER = 0.50; // VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement. // Try setting it to 60 if it goes too fast for you. const VIEW_ANGLE = 40.0; const VIEW_ANGLE_BY_TWO = VIEW_ANGLE / 2; -const SPAWN_DISTANCE = 1; -const DEFAULT_TEXT_DIMENSION_Z = 0.02; - const BOUND_X = 0; const BOUND_Y = 1; const BOUND_W = 2; const BOUND_H = 3; -const KEY_STATE_LOWER = 0; -const KEY_STATE_UPPER = 1; - -const TEXT_MARGIN_TOP = 0.15; -const TEXT_MARGIN_LEFT = 0.15; -const TEXT_MARGIN_RIGHT = 0.17; -const TEXT_MARGIN_BOTTOM = 0.17; +KEY_STATE_LOWER = 0; +KEY_STATE_UPPER = 1; var windowDimensions = Controller.getViewportDimensions(); -var cursor = null; -var keyboard = new Keyboard(); -var textFontSize = 9; -var text = null; -var textText = ""; -var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); -function appendChar(char) { - textText += char; - updateTextOverlay(); - Overlays.editOverlay(text, {text: textText}); -} - -function deleteChar() { - if (textText.length > 0) { - textText = textText.substring(0, textText.length - 1); - updateTextOverlay(); - } -} - -function updateTextOverlay() { - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; - var maxFontSize = 190 / textLines.length; - textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; - var topMargin = (250 - (textFontSize * textLines.length)) / 4; - Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); -} - -keyboard.onKeyPress = function(event) { - if (event.event == 'keypress') { - appendChar(event.char); - } else if (event.event == 'enter') { - appendChar("\n"); - } -}; - -keyboard.onKeyRelease = function(event) { - print("Key release event test"); - // you can cancel a key by releasing its focusing before releasing it - if (event.focus) { - if (event.event == 'delete') { - deleteChar(); - } else if (event.event == 'submit') { - print(textText); - - var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); - - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var usernameLine = "--" + GlobalServices.myUsername; - var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; - if (maxLineWidth < usernameWidth) { - maxLineWidth = usernameWidth; - } else { - var spaceableWidth = maxLineWidth - usernameWidth; - var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; - var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); - for (var i = 0; i < numberOfSpaces; i++) { - usernameLine = " " + usernameLine; - } - } - var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; - if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ - type: "Text", - rotation: MyAvatar.orientation, - position: position, - dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, - backgroundColor: { red: 0, green: 0, blue: 0 }, - textColor: { red: 255, green: 255, blue: 255 }, - text: textText + "\n" + usernameLine - }); - } - textText = ""; - updateTextOverlay(); - } - } -}; - -keyboard.onFullyLoaded = function() { - print("Virtual-keyboard fully loaded."); - var dimensions = Controller.getViewportDimensions(); - text = Overlays.addOverlay("text", { - x: 0, - y: dimensions.y - keyboard.height() - 260, - width: dimensions.x, - height: 250, - backgroundColor: { red: 255, green: 255, blue: 255}, - color: { red: 0, green: 0, blue: 0}, - topMargin: 5, - leftMargin: 0, - font: {size: textFontSize}, - text: "", - alpha: 0.8 - }); - updateTextOverlay(); - // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard - cursor = new Cursor(); - cursor.onUpdate = function(position) { - keyboard.setFocusPosition(position.x, position.y); - }; -}; - -function KeyboardKey(keyboard, keyProperties) { +KeyboardKey = (function(keyboard, keyProperties) { var tthis = this; this._focus = false; this._beingPressed = false; @@ -247,6 +118,11 @@ function KeyboardKey(keyboard, keyProperties) { }); } }; + this.updateVisibility = function() { + for (var i = 0; i < tthis.bounds.length; i++) { + Overlays.editOverlay(tthis.overlays[i], {visible: tthis.keyboard.visible}); + } + }; this.rescale = function() { for (var i = 0; i < tthis.bounds.length; i++) { Overlays.editOverlay(tthis.overlays[i], { @@ -271,24 +147,48 @@ function KeyboardKey(keyboard, keyProperties) { return true; }; for (var i = 0; i < this.bounds.length; i++) { - var newOverlay = Overlays.cloneOverlay(this.keyboard.background); - Overlays.editOverlay(newOverlay, { - x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, - y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, - width: this.bounds[i][BOUND_W] * keyboard.scale, - height: this.bounds[i][BOUND_H] * keyboard.scale, - subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 - }); - this.overlays.push(newOverlay); + if (THREE_D_MODE) { + this.overlays.push(Overlays.addOverlay("billboard", { + scale: 1, + rotation: MyAvatar.rotation, + isFacingAvatar: false, + url: KEYBOARD_URL, + alpha: 1, + position: { + x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale, + y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale, + z: MyAvatar.position.z + }, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1, + visible: tthis.keyboard.visible + })); + } else { + this.overlays.push(Overlays.addOverlay("image", { + imageURL: KEYBOARD_URL, + x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, + y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1, + visible: tthis.keyboard.visible + })); + } } -} +}); -function Keyboard() { +Keyboard = (function(params) { + if (params === undefined) { + params = {}; + } var tthis = this; this.focussed_key = -1; - this.scale = windowDimensions.x / KEYBOARD_WIDTH; + this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; this.shift = false; + this.visible = params.visible != undefined ? params.visible : true; this.width = function() { return KEYBOARD_WIDTH * tthis.scale; }; @@ -301,17 +201,33 @@ function Keyboard() { this.getY = function() { return windowDimensions.y - this.height(); }; - this.background = Overlays.addOverlay("image", { - x: this.getX(), - y: this.getY(), - width: this.width(), - height: this.height(), - subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, - imageURL: KEYBOARD_URL, - alpha: 1 - }); + if (THREE_D_MODE) { + this.background = Overlays.addOverlay("billboard", { + scale: 1, + position: MyAvatar.position, + rotation: MyAvatar.rotation, + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + isFacingAvatar: false, + url: KEYBOARD_URL, + alpha: 1, + visible: this.visible + }); + } else { + this.background = Overlays.addOverlay("image", { + x: this.getX(), + y: this.getY(), + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + imageURL: KEYBOARD_URL, + alpha: 1, + visible: this.visible + }); + } this.rescale = function() { - this.scale = windowDimensions.x / KEYBOARD_WIDTH; + this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; Overlays.editOverlay(tthis.background, { x: this.getX(), y: this.getY(), @@ -349,6 +265,9 @@ function Keyboard() { }; this.pressFocussedKey = function() { + if (!tthis.visible) { + return tthis; + } if (tthis.focussed_key != -1) { if (tthis.keys[tthis.focussed_key].event == 'shift') { tthis.toggleShift(); @@ -402,6 +321,32 @@ function Keyboard() { for (var i = 0; i < this.keys.length; i++) { this.keys[i].remove(); } + // resets the cursor and magnifier + this.updateVisibility(false); + }; + + this.show = function() { + tthis.updateVisibility(true); + }; + + this.hide = function() { + tthis.updateVisibility(false); + }; + + this.toggle = function() { + tthis.updateVisibility(!tthis.visible); + }; + + this.updateVisibility = function(visible) { + tthis.visible = visible; + if (HMD.magnifier == visible) { + HMD.toggleMagnifier(); + } + Window.cursorVisible = !visible; + Overlays.editOverlay(tthis.background, { visible: tthis.visible }); + for (var i = 0; i < this.keys.length; i++) { + this.keys[i].updateVisibility(); + } }; this.onKeyPress = null; @@ -502,97 +447,94 @@ function Keyboard() { {bounds: [[899, 355, 263, 67]], event: 'submit'} ]; - + for (var i = 0; i < keyProperties.length; i++) { + this.keys.push(new KeyboardKey(this, keyProperties[i])); + } this.keyboardTextureLoaded = function() { if (Overlays.isLoaded(tthis.background)) { Script.clearInterval(tthis.keyboardTextureLoaded_timer); - for (var i = 0; i < keyProperties.length; i++) { - tthis.keys.push(new KeyboardKey(tthis, keyProperties[i])); - } if (keyboard.onFullyLoaded != null) { tthis.onFullyLoaded(); } } }; this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250); -} +}); -function Cursor() { +Cursor = (function(params) { + if (params === undefined) { + params = {}; + } var tthis = this; - this.x = windowDimensions.x / 2; - this.y = windowDimensions.y / 2; - this.overlay = Overlays.addOverlay("image", { - x: this.x, - y: this.y, - width: CURSOR_WIDTH, - height: CURSOR_HEIGHT, - imageURL: CURSOR_URL, - alpha: 1 - }); - this.remove = function() { - Overlays.deleteOverlay(this.overlay); + this.initialize = function() { + this.visible = params.visible != undefined ? params.visible : true; + this.x = windowDimensions.x / 2; + this.y = windowDimensions.y / 2; + this.overlay = Overlays.addOverlay("image", { + x: this.x, + y: this.y, + width: CURSOR_WIDTH, + height: CURSOR_HEIGHT, + imageURL: CURSOR_URL, + alpha: 1, + visible: this.visible + }); + this.remove = function() { + Overlays.deleteOverlay(this.overlay); + }; + this.getPosition = function() { + return {x: tthis.getX(), y: tthis.getY()}; + }; + this.getX = function() { + return tthis.x; + }; + this.getY = function() { + return tthis.y; + }; + this.show = function() { + tthis.updateVisibility(true); + }; + this.hide = function() { + tthis.updateVisibility(false); + }; + this.toggle = function() { + tthis.updateVisibility(!tthis.visible); + }; + this.updateVisibility = function(visible) { + tthis.visible = visible; + Overlays.editOverlay(this.overlay, { visible: tthis.visible }); + }; + this.onUpdate = null; + this.update = function() { + var newWindowDimensions = Controller.getViewportDimensions(); + if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) { + windowDimensions = newWindowDimensions; + keyboard.rescale(); + Overlays.editOverlay(text, { + y: windowDimensions.y - keyboard.height() - 260, + width: windowDimensions.x + }); + } + var editobject = {}; + var hudLookatPosition = HMD.getHUDLookAtPosition2D(); + if (hudLookatPosition === null) { + return; + } + if (tthis.x !== hudLookatPosition.x) { + tthis.x = hudLookatPosition.x; + editobject.x = tthis.x - (CURSOR_WIDTH / 2); + } + if (tthis.y !== hudLookatPosition.y) { + tthis.y = hudLookatPosition.y; + editobject.y = tthis.y - (CURSOR_HEIGHT / 2); + } + if (Object.keys(editobject).length > 0) { + Overlays.editOverlay(tthis.overlay, editobject); + if (tthis.onUpdate != null) { + tthis.onUpdate(tthis.getPosition()); + } + } + }; + Script.update.connect(this.update); }; - this.getPosition = function() { - return {x: tthis.getX(), y: tthis.getY()}; - }; - this.getX = function() { - return tthis.x; - }; - this.getY = function() { - return tthis.y; - }; - this.onUpdate = null; - this.update = function() { - var newWindowDimensions = Controller.getViewportDimensions(); - if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) { - windowDimensions = newWindowDimensions; - keyboard.rescale(); - Overlays.editOverlay(text, { - y: windowDimensions.y - keyboard.height() - 260, - width: windowDimensions.x - }); - } - var editobject = {}; - if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) { - angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; - tthis.x = angle * windowDimensions.x; - editobject.x = tthis.x - (CURSOR_WIDTH / 2); - } - if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) { - angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; - tthis.y = angle * windowDimensions.y; - editobject.y = tthis.y - (CURSOR_HEIGHT / 2); - } - if (Object.keys(editobject).length > 0) { - Overlays.editOverlay(tthis.overlay, editobject); - if (tthis.onUpdate != null) { - tthis.onUpdate(tthis.getPosition()); - } - } - }; - Script.update.connect(this.update); -} - -function keyPressEvent(event) { - if (event.key === SPACEBAR_CHARCODE) { - keyboard.pressFocussedKey(); - } -} - -function keyReleaseEvent(event) { - if (event.key === SPACEBAR_CHARCODE) { - keyboard.releaseKeys(); - } -} - -function scriptEnding() { - keyboard.remove(); - cursor.remove(); - Overlays.deleteOverlay(text); - Overlays.deleteOverlay(textSizeMeasureOverlay); - Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); -} -Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); -Controller.keyPressEvent.connect(keyPressEvent); -Controller.keyReleaseEvent.connect(keyReleaseEvent); -Script.scriptEnding.connect(scriptEnding); \ No newline at end of file +}); diff --git a/examples/lobby.js b/examples/lobby.js index fcac7a490b..5d687dc07a 100644 --- a/examples/lobby.js +++ b/examples/lobby.js @@ -55,7 +55,9 @@ var droneSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/drone.st var currentDrone = null; var latinSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/latin.stereo.raw") +var latinInjector = null; var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/elevator.stereo.raw") +var elevatorInjector = null; var currentMuzakInjector = null; var currentSound = null; @@ -140,7 +142,11 @@ function drawLobby() { if (droneSound.downloaded) { // start the drone sound - currentDrone = Audio.playSound(droneSound, { stereo: true, loop: true, localOnly: true, volume: DRONE_VOLUME }); + if (!currentDrone) { + currentDrone = Audio.playSound(droneSound, { stereo: true, loop: true, localOnly: true, volume: DRONE_VOLUME }); + } else { + currentDrone.restart(); + } } // start one of our muzak sounds @@ -152,7 +158,7 @@ var places = {}; function changeLobbyTextures() { var req = new XMLHttpRequest(); - req.open("GET", "https://data.highfidelity.io/api/v1/places?limit=21", false); + req.open("GET", "https://metaverse.highfidelity.io/api/v1/places?limit=21", false); req.send(); places = JSON.parse(req.responseText).data.places; @@ -173,6 +179,26 @@ function changeLobbyTextures() { var MUZAK_VOLUME = 0.1; +function playCurrentSound(secondOffset) { + if (currentSound == latinSound) { + if (!latinInjector) { + latinInjector = Audio.playSound(latinSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME }); + } else { + latinInjector.restart(); + } + + currentMuzakInjector = latinInjector; + } else if (currentSound == elevatorSound) { + if (!elevatorInjector) { + elevatorInjector = Audio.playSound(elevatorSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME }); + } else { + elevatorInjector.restart(); + } + + currentMuzakInjector = elevatorInjector; + } +} + function playNextMuzak() { if (panelWall) { if (currentSound == latinSound) { @@ -184,8 +210,8 @@ function playNextMuzak() { currentSound = latinSound; } } - - currentMuzakInjector = Audio.playSound(currentSound, { localOnly: true, volume: MUZAK_VOLUME }); + + playCurrentSound(0); } } @@ -200,10 +226,11 @@ function playRandomMuzak() { currentSound = elevatorSound; } - if (currentSound) { + if (currentSound) { // pick a random number of seconds from 0-10 to offset the muzak var secondOffset = Math.random() * 10; - currentMuzakInjector = Audio.playSound(currentSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME }); + + playCurrentSound(secondOffset); } else { currentMuzakInjector = null; } @@ -227,10 +254,9 @@ function cleanupLobby() { panelWall = false; orbShell = false; - Audio.stopInjector(currentDrone); - currentDrone = null; + currentDrone.stop(); + currentMuzakInjector.stop(); - Audio.stopInjector(currentMuzakInjector); currentMuzakInjector = null; places = {}; @@ -354,7 +380,7 @@ function update(deltaTime) { Overlays.editOverlay(descriptionText, { position: textOverlayPosition() }); // if the reticle is up then we may need to play the next muzak - if (currentMuzakInjector && !Audio.isInjectorPlaying(currentMuzakInjector)) { + if (currentMuzakInjector && !currentMuzakInjector.isPlaying) { playNextMuzak(); } } diff --git a/examples/lookWithMouse.js b/examples/lookWithMouse.js index 2fe12cce24..470a56bd63 100644 --- a/examples/lookWithMouse.js +++ b/examples/lookWithMouse.js @@ -80,18 +80,9 @@ Controller.mousePressEvent.connect(mousePressEvent); Controller.mouseMoveEvent.connect(mouseMoveEvent); Controller.mouseReleaseEvent.connect(mouseReleaseEvent); -// disable the standard application for mouse events -Controller.captureMouseEvents(); - -function scriptEnding() { - // re-enabled the standard application for mouse events - Controller.releaseMouseEvents(); -} - MyAvatar.bodyYaw = 0; MyAvatar.bodyPitch = 0; MyAvatar.bodyRoll = 0; // would be nice to change to update Script.update.connect(update); -Script.scriptEnding.connect(scriptEnding); diff --git a/examples/planets.js b/examples/planets.js new file mode 100644 index 0000000000..87ed774c93 --- /dev/null +++ b/examples/planets.js @@ -0,0 +1,121 @@ +// +// planets.js +// +// Created by Philip Rosedale on January 26, 2015 +// Copyright 2015 High Fidelity, Inc. +// +// Some planets are created in front of you. A physical object shot or thrown between them will move +// correctly. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var MAX_RANGE = 75.0; +var MAX_TRANSLATION = MAX_RANGE / 20.0; + +var LIFETIME = 600; +var DAMPING = 0.0; +var G = 3.0; + +// In this section, setup where you want your 'Planets' that will exert gravity on the +// smaller test particles. Use the first one for the simplest 'planets around sun' simulation. +// Add additional planets to make things a lot more complicated! + +var planetTypes = []; +planetTypes.push({ radius: 15, red: 0, green: 0, blue: 255, x: 0.0, y:0, z: 0.0 }); +//planetTypes.push({ radius: 10, red: 0, green: 255, blue: 0, x: 0.60, y:0, z: 0.60 }); +//planetTypes.push({ radius: 10, red: 0, green: 0, blue: 255, x: 0.75, y:0, z: 0.75 }); +//planetTypes.push({ radius: 5, red: 255, green: 0, blue: 0, x: 0.25, y:0, z: 0.25 }); +//planetTypes.push({ radius: 5, red: 0, green: 255, blue: 255, x: 0, y:0, z: 0 }); + +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(MAX_RANGE, Quat.getFront(Camera.getOrientation()))); + +var NUM_INITIAL_PARTICLES = 200; +var PARTICLE_MIN_SIZE = 0.50; +var PARTICLE_MAX_SIZE = 1.50; +var INITIAL_VELOCITY = 5.0; + +var planets = []; +var particles = []; + +// Create planets that will extert gravity on test particles +for (var i = 0; i < planetTypes.length; i++) { + var rotationalVelocity = 10 + Math.random() * 60; + var position = { x: planetTypes[i].x, y: planetTypes[i].y, z: planetTypes[i].z }; + position = Vec3.multiply(MAX_RANGE / 2, position); + position = Vec3.sum(center, position); + + planets.push(Entities.addEntity( + { type: "Sphere", + position: position, + dimensions: { x: planetTypes[i].radius, y: planetTypes[i].radius, z: planetTypes[i].radius }, + color: { red: planetTypes[i].red, green: planetTypes[i].green, blue: planetTypes[i].blue }, + gravity: { x: 0, y: 0, z: 0 }, + angularVelocity: { x: 0, y: rotationalVelocity, z: 0 }, + angularDamping: 0.0, + ignoreCollisions: false, + lifetime: LIFETIME, + collisionsWillMove: false })); +} + +Script.setTimeout(createParticles, 1000); + +function createParticles() { + // Create initial test particles that will move according to gravity from the planets + for (var i = 0; i < NUM_INITIAL_PARTICLES; i++) { + var radius = PARTICLE_MIN_SIZE + Math.random() * PARTICLE_MAX_SIZE; + var gray = Math.random() * 155; + var whichPlanet = Math.floor(Math.random() * planets.length); + var position = { x: (Math.random() - 0.5) * MAX_RANGE, y: (Math.random() - 0.5) * MAX_TRANSLATION, z: (Math.random() - 0.5) * MAX_RANGE }; + var separation = Vec3.length(position); + particles.push(Entities.addEntity( + { type: "Sphere", + position: Vec3.sum(center, position), + dimensions: { x: radius, y: radius, z: radius }, + color: { red: 100 + gray, green: 100 + gray, blue: 100 + gray }, + gravity: { x: 0, y: 0, z: 0 }, + angularVelocity: { x: 0, y: 0, z: 0 }, + velocity: Vec3.multiply(INITIAL_VELOCITY * Math.sqrt(separation), Vec3.normalize(Vec3.cross(position, { x: 0, y: 1, z: 0 }))), + ignoreCollisions: false, + damping: DAMPING, + lifetime: LIFETIME, + collisionsWillMove: true })); + } + Script.update.connect(update); +} + +function scriptEnding() { + for (var i = 0; i < planetTypes.length; i++) { + Entities.deleteEntity(planets[i]); + } + for (var i = 0; i < particles.length; i++) { + Entities.deleteEntity(particles[i]); + } +} + +function update(deltaTime) { + // Apply gravitational force from planets + for (var t = 0; t < particles.length; t++) { + var properties1 = Entities.getEntityProperties(particles[t]); + var velocity = properties1.velocity; + var vColor = Vec3.length(velocity) / 50 * 255; + var dV = { x:0, y:0, z:0 }; + var mass1 = Math.pow(properties1.dimensions.x / 2.0, 3.0); + for (var p = 0; p < planets.length; p++) { + var properties2 = Entities.getEntityProperties(planets[p]); + var mass2 = Math.pow(properties2.dimensions.x / 2.0, 3.0); + var between = Vec3.subtract(properties1.position, properties2.position); + var separation = Vec3.length(between); + dV = Vec3.sum(dV, Vec3.multiply(-G * mass1 * mass2 / separation, Vec3.normalize(between))); + } + if (Math.random() < 0.1) { + Entities.editEntity(particles[t], { color: { red: vColor, green: 100, blue: (255 - vColor) }, velocity: Vec3.sum(velocity, Vec3.multiply(deltaTime, dV))}); + } else { + Entities.editEntity(particles[t], { velocity: Vec3.sum(velocity, Vec3.multiply(deltaTime, dV))}); + } + + } +} + +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/examples/progress.js b/examples/progress.js new file mode 100644 index 0000000000..6ee53c55e6 --- /dev/null +++ b/examples/progress.js @@ -0,0 +1,265 @@ +// +// progress.js +// examples +// +// Created by David Rowe on 29 Jan 2015. +// Copyright 2015 High Fidelity, Inc. +// +// This script displays a progress download indicator when downloads are in progress. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function () { + + var progress = 100, // % + alpha = 0.0, + alphaDelta = 0.0, // > 0 if fading in; < 0 if fading out/ + ALPHA_DELTA_IN = 0.15, + ALPHA_DELTA_OUT = -0.02, + fadeTimer = null, + FADE_INTERVAL = 30, // ms between changes in alpha. + fadeWaitTimer = null, + FADE_OUT_WAIT = 1000, // Wait before starting to fade out after progress 100%. + visible = false, + BAR_WIDTH = 320, // Nominal dimension of SVG in pixels of visible portion (half) of the bar. + BAR_HEIGHT = 20, + BAR_URL = "http://hifi-public.s3.amazonaws.com/images/progress-bar.svg", + BACKGROUND_WIDTH = 360, + BACKGROUND_HEIGHT = 60, + BACKGROUND_URL = "http://hifi-public.s3.amazonaws.com/images/progress-bar-background.svg", + isOnHMD = false, + windowWidth = 0, + windowHeight = 0, + background2D = {}, + bar2D = {}, + SCALE_2D = 0.55, // Scale the SVGs for 2D display. + background3D = {}, + bar3D = {}, + ENABLE_VR_MODE_MENU_ITEM = "Enable VR Mode", + PROGRESS_3D_DIRECTION = 0.0, // Degrees from avatar orientation. + PROGRESS_3D_DISTANCE = 0.602, // Horizontal distance from avatar position. + PROGRESS_3D_ELEVATION = -0.8, // Height of top middle of top notification relative to avatar eyes. + PROGRESS_3D_YAW = 0.0, // Degrees relative to notifications direction. + PROGRESS_3D_PITCH = -60.0, // Degrees from vertical. + SCALE_3D = 0.0017, // Scale the bar SVG for 3D display. + BACKGROUND_3D_SIZE = { x: 0.76, y: 0.08 }, // Match up with the 3D background with those of notifications.js notices. + BACKGROUND_3D_COLOR = { red: 2, green: 2, blue: 2 }, + BACKGROUND_3D_ALPHA = 0.7; + + function fade() { + + alpha = alpha + alphaDelta; + + if (alpha < 0) { + alpha = 0; + } + + if (alpha > 1) { + alpha = 1; + } + + if (alpha === 0 || alpha === 1) { // Finished fading in or out + alphaDelta = 0; + Script.clearInterval(fadeTimer); + } + + if (alpha === 0) { // Finished fading out + visible = false; + } + + if (isOnHMD) { + Overlays.editOverlay(background3D.overlay, { + backgroundAlpha: alpha * BACKGROUND_3D_ALPHA, + visible: visible + }); + } else { + Overlays.editOverlay(background2D.overlay, { + alpha: alpha, + visible: visible + }); + } + Overlays.editOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay, { + alpha: alpha, + visible: visible + }); + } + + function onDownloadInfoChanged(info) { + var i; + + // Calculate progress + if (info.downloading.length + info.pending === 0) { + progress = 100; + } else { + progress = 0; + for (i = 0; i < info.downloading.length; i += 1) { + progress += info.downloading[i]; + } + progress = progress / (info.downloading.length + info.pending); + } + + // Update state + if (!visible) { // Not visible because no recent downloads + if (progress < 100) { // Have started downloading so fade in + visible = true; + alphaDelta = ALPHA_DELTA_IN; + fadeTimer = Script.setInterval(fade, FADE_INTERVAL); + } + } else if (alphaDelta !== 0.0) { // Fading in or out + if (alphaDelta > 0) { + if (progress === 100) { // Was donloading but now have finished so fade out + alphaDelta = ALPHA_DELTA_OUT; + } + } else { + if (progress < 100) { // Was finished downloading but have resumed so fade in + alphaDelta = ALPHA_DELTA_IN; + } + } + } else { // Fully visible because downloading or recently so + if (fadeWaitTimer === null) { + if (progress === 100) { // Was downloading but have finished so fade out soon + fadeWaitTimer = Script.setTimeout(function () { + alphaDelta = ALPHA_DELTA_OUT; + fadeTimer = Script.setInterval(fade, FADE_INTERVAL); + fadeWaitTimer = null; + }, FADE_OUT_WAIT); + } + } else { + if (progress < 100) { // Was finished and waiting to fade out but have resumed downloading so don't fade out + Script.clearInterval(fadeWaitTimer); + fadeWaitTimer = null; + } + } + } + + // Update progress bar + if (visible) { + Overlays.editOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay, { + subImage: { x: BAR_WIDTH * (1 - progress / 100), y: 0, width: BAR_WIDTH, height: BAR_HEIGHT } + }); + } + } + + function createOverlays() { + if (isOnHMD) { + + background3D.overlay = Overlays.addOverlay("rectangle3d", { + size: BACKGROUND_3D_SIZE, + color: BACKGROUND_3D_COLOR, + alpha: BACKGROUND_3D_ALPHA, + solid: true, + isFacingAvatar: false, + visible: false, + ignoreRayIntersection: true + }); + bar3D.overlay = Overlays.addOverlay("billboard", { + url: BAR_URL, + subImage: { x: BAR_WIDTH, y: 0, width: BAR_WIDTH, height: BAR_HEIGHT }, + scale: SCALE_3D * BAR_WIDTH, + isFacingAvatar: false, + visible: false, + alpha: 0.0, + ignoreRayIntersection: true + }); + + } else { + + background2D.overlay = Overlays.addOverlay("image", { + imageURL: BACKGROUND_URL, + width: background2D.width, + height: background2D.height, + visible: false, + alpha: 0.0 + }); + bar2D.overlay = Overlays.addOverlay("image", { + imageURL: BAR_URL, + subImage: { x: BAR_WIDTH, y: 0, width: BAR_WIDTH, height: BAR_HEIGHT }, + width: bar2D.width, + height: bar2D.height, + visible: false, + alpha: 0.0 + }); + } + } + + function deleteOverlays() { + Overlays.deleteOverlay(isOnHMD ? background3D.overlay : background2D.overlay); + Overlays.deleteOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay); + } + + function update() { + var viewport, + eyePosition, + avatarOrientation; + + if (isOnHMD !== Menu.isOptionChecked(ENABLE_VR_MODE_MENU_ITEM)) { + deleteOverlays(); + isOnHMD = !isOnHMD; + createOverlays(); + } + + if (visible) { + if (isOnHMD) { + // Update 3D overlays to maintain positions relative to avatar + eyePosition = MyAvatar.getDefaultEyePosition(); + avatarOrientation = MyAvatar.orientation; + + Overlays.editOverlay(background3D.overlay, { + position: Vec3.sum(eyePosition, Vec3.multiplyQbyV(avatarOrientation, background3D.offset)), + rotation: Quat.multiply(avatarOrientation, background3D.orientation) + }); + Overlays.editOverlay(bar3D.overlay, { + position: Vec3.sum(eyePosition, Vec3.multiplyQbyV(avatarOrientation, bar3D.offset)), + rotation: Quat.multiply(avatarOrientation, bar3D.orientation) + }); + + } else { + // Update 2D overlays to maintain positions at bottom middle of window + viewport = Controller.getViewportDimensions(); + + if (viewport.x !== windowWidth || viewport.y !== windowHeight) { + windowWidth = viewport.x; + windowHeight = viewport.y; + + Overlays.editOverlay(background2D.overlay, { + x: windowWidth / 2 - background2D.width / 2, + y: windowHeight - background2D.height - bar2D.height + }); + + Overlays.editOverlay(bar2D.overlay, { + x: windowWidth / 2 - bar2D.width / 2, + y: windowHeight - background2D.height - bar2D.height + (background2D.height - bar2D.height) / 2 + }); + } + } + } + } + + function setUp() { + background2D.width = SCALE_2D * BACKGROUND_WIDTH; + background2D.height = SCALE_2D * BACKGROUND_HEIGHT; + bar2D.width = SCALE_2D * BAR_WIDTH; + bar2D.height = SCALE_2D * BAR_HEIGHT; + + background3D.offset = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, PROGRESS_3D_DIRECTION, 0), + { x: 0, y: 0, z: -PROGRESS_3D_DISTANCE }); + background3D.offset.y += PROGRESS_3D_ELEVATION; + background3D.orientation = Quat.fromPitchYawRollDegrees(PROGRESS_3D_PITCH, PROGRESS_3D_DIRECTION + PROGRESS_3D_YAW, 0); + bar3D.offset = Vec3.sum(background3D.offset, { x: 0, y: 0, z: 0.001 }); // Just in front of background + bar3D.orientation = background3D.orientation; + + createOverlays(); + } + + function tearDown() { + deleteOverlays(); + } + + setUp(); + GlobalServices.downloadInfoChanged.connect(onDownloadInfoChanged); + GlobalServices.updateDownloadInfo(); + Script.update.connect(update); + Script.scriptEnding.connect(tearDown); +}()); diff --git a/examples/utilities/diagnostics/inWorldTestTone.js b/examples/utilities/diagnostics/inWorldTestTone.js index 77ec7ba3b2..4596bfe2ad 100644 --- a/examples/utilities/diagnostics/inWorldTestTone.js +++ b/examples/utilities/diagnostics/inWorldTestTone.js @@ -21,20 +21,13 @@ var offset = Vec3.normalize(Quat.getFront(MyAvatar.orientation)); var position = Vec3.sum(MyAvatar.position, offset); function update(deltaTime) { - if (!Audio.isInjectorPlaying(soundPlaying)) { - soundPlaying = Audio.playSound(sound, { - position: position, - loop: true - }); - print("Started sound loop"); - } -} - -function scriptEnding() { - if (Audio.isInjectorPlaying(soundPlaying)) { - Audio.stopInjector(soundPlaying); - print("Stopped sound loop"); - } + if (sound.downloaded && !soundPlaying) { + print("Started sound loop"); + soundPlaying = Audio.playSound(sound, { + position: position, + loop: true + }); + } } Script.update.connect(update); diff --git a/examples/utilities/diagnostics/orbitingSound.js b/examples/utilities/diagnostics/orbitingSound.js index 54e319faaa..1af6fab827 100644 --- a/examples/utilities/diagnostics/orbitingSound.js +++ b/examples/utilities/diagnostics/orbitingSound.js @@ -32,14 +32,13 @@ var sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volu function update(deltaTime) { time += deltaTime; currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS }; - trailingLoudness = 0.9 * trailingLoudness + 0.1 * Audio.getLoudness(sound); + trailingLoudness = 0.9 * trailingLoudness + 0.1 * sound.loudness; Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } ); - Audio.setInjectorOptions(sound, { position: currentPosition }); + sound.setOptions({ position: currentPosition }); } Script.scriptEnding.connect(function() { Entities.deleteEntity(objectId); - Audio.stopInjector(sound); }); Script.update.connect(update); \ No newline at end of file diff --git a/examples/utilities/diagnostics/playSoundLoop.js b/examples/utilities/diagnostics/playSoundLoop.js index faf23761b4..83c0ccf6d0 100644 --- a/examples/utilities/diagnostics/playSoundLoop.js +++ b/examples/utilities/diagnostics/playSoundLoop.js @@ -30,7 +30,7 @@ var playing = false; var ball = false; function maybePlaySound(deltaTime) { - if (sound.downloaded) { + if (sound.downloaded && !soundPlaying) { var properties = { type: "Sphere", position: options.position, @@ -45,11 +45,9 @@ function maybePlaySound(deltaTime) { } function scriptEnding() { - if (Audio.isInjectorPlaying(soundPlaying)) { - Audio.stopInjector(soundPlaying); - Entities.deleteEntity(ball); - print("Stopped sound."); - } + if (ball) { + Entities.deleteEntity(ball); + } } // Connect a call back that happens every frame diff --git a/gvr-interface/CMakeLists.txt b/gvr-interface/CMakeLists.txt new file mode 100644 index 0000000000..de0b66165b --- /dev/null +++ b/gvr-interface/CMakeLists.txt @@ -0,0 +1,90 @@ +set(TARGET_NAME gvr-interface) + +if (ANDROID) + set(ANDROID_APK_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/apk-build") + set(ANDROID_APK_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apk") + + set(ANDROID_SDK_ROOT $ENV{ANDROID_HOME}) + set(ANDROID_APP_DISPLAY_NAME Interface) + set(ANDROID_API_LEVEL 19) + set(ANDROID_APK_PACKAGE io.highfidelity.gvrinterface) + set(ANDROID_ACTIVITY_NAME io.highfidelity.gvrinterface.InterfaceActivity) + set(ANDROID_APK_VERSION_NAME "0.1") + set(ANDROID_APK_VERSION_CODE 1) + set(ANDROID_APK_FULLSCREEN TRUE) + set(ANDROID_DEPLOY_QT_INSTALL "--install") + + set(BUILD_SHARED_LIBS ON) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ANDROID_APK_OUTPUT_DIR}/libs/${ANDROID_ABI}") + + setup_hifi_library(Gui Widgets AndroidExtras) +else () + setup_hifi_project(Gui Widgets) +endif () + +include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) + +add_dependency_external_project(glm) +find_package(GLM REQUIRED) +target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) + +link_hifi_libraries(shared networking audio-client avatars) +include_dependency_includes() + +if (ANDROID) + find_package(LibOVR) + + if (LIBOVR_FOUND) + add_definitions(-DHAVE_LIBOVR) + target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES} ${LIBOVR_ANDROID_LIBRARIES} ${TURBOJPEG_LIBRARY}) + include_directories(SYSTEM ${LIBOVR_INCLUDE_DIRS}) + + # we need VRLib, so add a project.properties to our apk build folder that says that + file(RELATIVE_PATH RELATIVE_VRLIB_PATH ${ANDROID_APK_OUTPUT_DIR} "${LIBOVR_VRLIB_DIR}") + file(WRITE "${ANDROID_APK_BUILD_DIR}/project.properties" "android.library.reference.1=${RELATIVE_VRLIB_PATH}") + + list(APPEND IGNORE_COPY_LIBS ${LIBOVR_ANDROID_LIBRARIES}) + endif () + +endif () + +# the presence of a HOCKEY_APP_ID means we are making a beta build +if (ANDROID AND HOCKEY_APP_ID) + set(HOCKEY_APP_ENABLED true) + set(HOCKEY_APP_ACTIVITY "\n") + set(ANDROID_ACTIVITY_NAME io.highfidelity.gvrinterface.InterfaceBetaActivity) + set(ANDROID_DEPLOY_QT_INSTALL "") + set(ANDROID_APK_CUSTOM_NAME "Interface-beta.apk") + + # set the ANDROID_APK_VERSION_CODE to the number of git commits + execute_process( + COMMAND git rev-list --first-parent --count HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_COUNT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + set(ANDROID_APK_VERSION_CODE ${GIT_COMMIT_COUNT}) + + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/templates/InterfaceBetaActivity.java.in" "${ANDROID_APK_BUILD_DIR}/src/io/highfidelity/gvrinterface/InterfaceBetaActivity.java") +elseif (ANDROID) + set(HOCKEY_APP_ENABLED false) +endif () + +if (ANDROID) + + set(HIFI_URL_INTENT "\ + \n \ + \n \ + \n \ + \n \ + \n " + ) + + set(ANDROID_EXTRA_APPLICATION_XML "${HOCKEY_APP_ACTIVITY}") + set(ANDROID_EXTRA_ACTIVITY_XML "${HIFI_URL_INTENT}") + + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/templates/hockeyapp.xml.in" "${ANDROID_APK_BUILD_DIR}/res/values/hockeyapp.xml") + qt_create_apk() + +endif (ANDROID) \ No newline at end of file diff --git a/gvr-interface/res/drawable/icon.png b/gvr-interface/res/drawable/icon.png new file mode 100644 index 0000000000..70aaf9b4ed Binary files /dev/null and b/gvr-interface/res/drawable/icon.png differ diff --git a/gvr-interface/src/Client.cpp b/gvr-interface/src/Client.cpp new file mode 100644 index 0000000000..65238ad784 --- /dev/null +++ b/gvr-interface/src/Client.cpp @@ -0,0 +1,73 @@ +// +// Client.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 1/20/15. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include +#include +#include + +#include "Client.h" + +Client::Client(QObject* parent) : + QObject(parent) +{ + // we need to make sure that required dependencies are created + DependencyManager::set(); + + setupNetworking(); +} + +void Client::setupNetworking() { + // once Application order of instantiation is fixed this should be done from AccountManager + AccountManager::getInstance().setAuthURL(DEFAULT_NODE_AUTH_URL); + + // setup the NodeList for this client + DependencyManager::registerInheritance(); + auto nodeList = DependencyManager::set(NodeType::Agent, 0); + + // while datagram processing remains simple for targets using Client, we'll handle datagrams + connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &Client::processDatagrams); + + // every second, ask the NodeList to check in with the domain server + QTimer* domainCheckInTimer = new QTimer(this); + domainCheckInTimer->setInterval(DOMAIN_SERVER_CHECK_IN_MSECS); + connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn); + + // TODO: once the Client knows its Address on start-up we should be able to immediately send a check in here + domainCheckInTimer->start(); + + // handle the case where the domain stops talking to us + // TODO: can we just have the nodelist do this when it sets up? Is there a user of the NodeList that wouldn't want this? + connect(nodeList.data(), &NodeList::limitOfSilentDomainCheckInsReached, nodeList.data(), &NodeList::reset); +} + +void Client::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) { + DependencyManager::get()->processNodeData(senderSockAddr, incomingPacket); +} + +void Client::processDatagrams() { + HifiSockAddr senderSockAddr; + + static QByteArray incomingPacket; + + auto nodeList = DependencyManager::get(); + + while (DependencyManager::get()->getNodeSocket().hasPendingDatagrams()) { + incomingPacket.resize(nodeList->getNodeSocket().pendingDatagramSize()); + nodeList->getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), + senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); + + if (nodeList->packetVersionAndHashMatch(incomingPacket)) { + processVerifiedPacket(senderSockAddr, incomingPacket); + } + } +} \ No newline at end of file diff --git a/gvr-interface/src/Client.h b/gvr-interface/src/Client.h new file mode 100644 index 0000000000..6fbe40f165 --- /dev/null +++ b/gvr-interface/src/Client.h @@ -0,0 +1,33 @@ +// +// Client.h +// gvr-interface/src +// +// Created by Stephen Birarda on 1/20/15. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_Client_h +#define hifi_Client_h + +#include + +#include + +class Client : public QObject { + Q_OBJECT +public: + Client(QObject* parent = 0); + + virtual void cleanupBeforeQuit() = 0; +protected: + + void setupNetworking(); + virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket); +private slots: + void processDatagrams(); +}; + +#endif // hifi_Client_h diff --git a/gvr-interface/src/GVRInterface.cpp b/gvr-interface/src/GVRInterface.cpp new file mode 100644 index 0000000000..3d58396322 --- /dev/null +++ b/gvr-interface/src/GVRInterface.cpp @@ -0,0 +1,191 @@ +// +// GVRInterface.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 11/18/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifdef ANDROID + +#include + +#include +#include +#include + +#ifdef HAVE_LIBOVR + +#include +#include + +#endif +#endif + +#include +#include +#include + +#include "GVRMainWindow.h" +#include "RenderingClient.h" + +#include "GVRInterface.h" + +static QString launchURLString = QString(); + +#ifdef ANDROID + +extern "C" { + +JNIEXPORT void Java_io_highfidelity_gvrinterface_InterfaceActivity_handleHifiURL(JNIEnv *jni, jclass clazz, jstring hifiURLString) { + launchURLString = QAndroidJniObject(hifiURLString).toString(); +} + +} + +#endif + +GVRInterface::GVRInterface(int argc, char* argv[]) : + QApplication(argc, argv), + _mainWindow(NULL), + _inVRMode(false) +{ + setApplicationName("gvr-interface"); + setOrganizationName("highfidelity"); + setOrganizationDomain("io"); + + if (!launchURLString.isEmpty()) { + // did we get launched with a lookup URL? If so it is time to give that to the AddressManager + qDebug() << "We were opened via a hifi URL -" << launchURLString; + } + + _client = new RenderingClient(this, launchURLString); + + launchURLString = QString(); + + connect(this, &QGuiApplication::applicationStateChanged, this, &GVRInterface::handleApplicationStateChange); + +#if defined(ANDROID) && defined(HAVE_LIBOVR) + QAndroidJniEnvironment jniEnv; + + QPlatformNativeInterface* interface = QApplication::platformNativeInterface(); + jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity"); + + ovr_RegisterHmtReceivers(&*jniEnv, activity); + + // PLATFORMACTIVITY_REMOVAL: Temp workaround for PlatformActivity being + // stripped from UnityPlugin. Alternate is to use LOCAL_WHOLE_STATIC_LIBRARIES + // but that increases the size of the plugin by ~1MiB + OVR::linkerPlatformActivity++; +#endif + + // call our idle function whenever we can + QTimer* idleTimer = new QTimer(this); + connect(idleTimer, &QTimer::timeout, this, &GVRInterface::idle); + idleTimer->start(0); + + // call our quit handler before we go down + connect(this, &QCoreApplication::aboutToQuit, this, &GVRInterface::handleApplicationQuit); +} + +void GVRInterface::handleApplicationQuit() { + _client->cleanupBeforeQuit(); +} + +void GVRInterface::idle() { +#if defined(ANDROID) && defined(HAVE_LIBOVR) + if (!_inVRMode && ovr_IsHeadsetDocked()) { + qDebug() << "The headset just got docked - enter VR mode."; + enterVRMode(); + } else if (_inVRMode) { + + if (ovr_IsHeadsetDocked()) { + static int counter = 0; + + // Get the latest head tracking state, predicted ahead to the midpoint of the time + // it will be displayed. It will always be corrected to the real values by + // time warp, but the closer we get, the less black will be pulled in at the edges. + const double now = ovr_GetTimeInSeconds(); + static double prev; + const double rawDelta = now - prev; + prev = now; + const double clampedPrediction = std::min( 0.1, rawDelta * 2); + ovrSensorState sensor = ovrHmd_GetSensorState(OvrHmd, now + clampedPrediction, true ); + + auto ovrOrientation = sensor.Predicted.Pose.Orientation; + glm::quat newOrientation(ovrOrientation.w, ovrOrientation.x, ovrOrientation.y, ovrOrientation.z); + _client->setOrientation(newOrientation); + + if (counter++ % 100000 == 0) { + qDebug() << "GetSensorState in frame" << counter << "-" + << ovrOrientation.x << ovrOrientation.y << ovrOrientation.z << ovrOrientation.w; + } + } else { + qDebug() << "The headset was undocked - leaving VR mode."; + + leaveVRMode(); + } + } + + OVR::KeyState& backKeyState = _mainWindow->getBackKeyState(); + auto backEvent = backKeyState.Update(ovr_GetTimeInSeconds()); + + if (backEvent == OVR::KeyState::KEY_EVENT_LONG_PRESS) { + qDebug() << "Attemping to start the Platform UI Activity."; + ovr_StartPackageActivity(_ovr, PUI_CLASS_NAME, PUI_GLOBAL_MENU); + } else if (backEvent == OVR::KeyState::KEY_EVENT_DOUBLE_TAP || backEvent == OVR::KeyState::KEY_EVENT_SHORT_PRESS) { + qDebug() << "Got an event we should cancel for!"; + } else if (backEvent == OVR::KeyState::KEY_EVENT_DOUBLE_TAP) { + qDebug() << "The button is down!"; + } +#endif +} + +void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) { + switch(state) { + case Qt::ApplicationActive: + qDebug() << "The application is active."; + break; + case Qt::ApplicationSuspended: + qDebug() << "The application is being suspended."; + break; + default: + break; + } +} + +void GVRInterface::enterVRMode() { +#if defined(ANDROID) && defined(HAVE_LIBOVR) + // Default vrModeParms + ovrModeParms vrModeParms; + vrModeParms.AsynchronousTimeWarp = true; + vrModeParms.AllowPowerSave = true; + vrModeParms.DistortionFileName = NULL; + vrModeParms.EnableImageServer = false; + vrModeParms.CpuLevel = 2; + vrModeParms.GpuLevel = 2; + vrModeParms.GameThreadTid = 0; + + QAndroidJniEnvironment jniEnv; + + QPlatformNativeInterface* interface = QApplication::platformNativeInterface(); + jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity"); + + vrModeParms.ActivityObject = activity; + + ovrHmdInfo hmdInfo; + _ovr = ovr_EnterVrMode(vrModeParms, &hmdInfo); + + _inVRMode = true; +#endif +} + +void GVRInterface::leaveVRMode() { +#if defined(ANDROID) && defined(HAVE_LIBOVR) + ovr_LeaveVrMode(_ovr); + _inVRMode = false; +#endif +} diff --git a/gvr-interface/src/GVRInterface.h b/gvr-interface/src/GVRInterface.h new file mode 100644 index 0000000000..9ffbd52909 --- /dev/null +++ b/gvr-interface/src/GVRInterface.h @@ -0,0 +1,72 @@ +// +// GVRInterface.h +// gvr-interface/src +// +// Created by Stephen Birarda on 11/18/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_GVRInterface_h +#define hifi_GVRInterface_h + +#include + +#if defined(ANDROID) && defined(HAVE_LIBOVR) +class ovrMobile; +class ovrHmdInfo; + +// This is set by JNI_OnLoad() when the .so is initially loaded. +// Must use to attach each thread that will use JNI: +namespace OVR { + // PLATFORMACTIVITY_REMOVAL: Temp workaround for PlatformActivity being + // stripped from UnityPlugin. Alternate is to use LOCAL_WHOLE_STATIC_LIBRARIES + // but that increases the size of the plugin by ~1MiB + extern int linkerPlatformActivity; +} + +#endif + +class GVRMainWindow; +class RenderingClient; +class QKeyEvent; + +#if defined(qApp) +#undef qApp +#endif +#define qApp (static_cast(QApplication::instance())) + +class GVRInterface : public QApplication { + Q_OBJECT +public: + GVRInterface(int argc, char* argv[]); + RenderingClient* getClient() { return _client; } + + void setMainWindow(GVRMainWindow* mainWindow) { _mainWindow = mainWindow; } + +protected: + void keyPressEvent(QKeyEvent* event); + +private slots: + void handleApplicationStateChange(Qt::ApplicationState state); + void idle(); +private: + void handleApplicationQuit(); + + void enterVRMode(); + void leaveVRMode(); + +#if defined(ANDROID) && defined(HAVE_LIBOVR) + ovrMobile* _ovr; + ovrHmdInfo* _hmdInfo; +#endif + + GVRMainWindow* _mainWindow; + + RenderingClient* _client; + bool _inVRMode; +}; + +#endif // hifi_GVRInterface_h diff --git a/gvr-interface/src/GVRMainWindow.cpp b/gvr-interface/src/GVRMainWindow.cpp new file mode 100644 index 0000000000..7a36aba66e --- /dev/null +++ b/gvr-interface/src/GVRMainWindow.cpp @@ -0,0 +1,176 @@ +// +// GVRMainWindow.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 1/20/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef ANDROID + +#include + +#elif defined(HAVE_LIBOVR) + +#include + +const float LIBOVR_DOUBLE_TAP_DURATION = 0.25f; +const float LIBOVR_LONG_PRESS_DURATION = 0.75f; + +#endif + +#include + +#include "InterfaceView.h" +#include "LoginDialog.h" +#include "RenderingClient.h" + +#include "GVRMainWindow.h" + + + +GVRMainWindow::GVRMainWindow(QWidget* parent) : + QMainWindow(parent), +#if defined(ANDROID) && defined(HAVE_LIBOVR) + _backKeyState(LIBOVR_DOUBLE_TAP_DURATION, LIBOVR_LONG_PRESS_DURATION), + _wasBackKeyDown(false), +#endif + _mainLayout(NULL), + _menuBar(NULL), + _loginAction(NULL) +{ + +#ifndef ANDROID + const int NOTE_4_WIDTH = 2560; + const int NOTE_4_HEIGHT = 1440; + setFixedSize(NOTE_4_WIDTH / 2, NOTE_4_HEIGHT / 2); +#endif + + setupMenuBar(); + + QWidget* baseWidget = new QWidget(this); + + // setup a layout so we can vertically align to top + _mainLayout = new QVBoxLayout(baseWidget); + _mainLayout->setAlignment(Qt::AlignTop); + + // set the layout on the base widget + baseWidget->setLayout(_mainLayout); + + setCentralWidget(baseWidget); + + // add the interface view + new InterfaceView(baseWidget); +} + +GVRMainWindow::~GVRMainWindow() { + delete _menuBar; +} + +void GVRMainWindow::keyPressEvent(QKeyEvent* event) { +#ifdef ANDROID + if (event->key() == Qt::Key_Back) { + // got the Android back key, hand off to OVR KeyState + _backKeyState.HandleEvent(ovr_GetTimeInSeconds(), true, (_wasBackKeyDown ? 1 : 0)); + _wasBackKeyDown = true; + return; + } +#endif + QWidget::keyPressEvent(event); +} + +void GVRMainWindow::keyReleaseEvent(QKeyEvent* event) { +#ifdef ANDROID + if (event->key() == Qt::Key_Back) { + // release on the Android back key, hand off to OVR KeyState + _backKeyState.HandleEvent(ovr_GetTimeInSeconds(), false, 0); + _wasBackKeyDown = false; + } +#endif + QWidget::keyReleaseEvent(event); +} + +void GVRMainWindow::setupMenuBar() { + QMenu* fileMenu = new QMenu("File"); + QMenu* helpMenu = new QMenu("Help"); + + _menuBar = new QMenuBar(0); + + _menuBar->addMenu(fileMenu); + _menuBar->addMenu(helpMenu); + + QAction* goToAddress = new QAction("Go to Address", fileMenu); + connect(goToAddress, &QAction::triggered, this, &GVRMainWindow::showAddressBar); + fileMenu->addAction(goToAddress); + + _loginAction = new QAction("Login", fileMenu); + fileMenu->addAction(_loginAction); + + // change the login action depending on our logged in/out state + AccountManager& accountManager = AccountManager::getInstance(); + connect(&accountManager, &AccountManager::loginComplete, this, &GVRMainWindow::refreshLoginAction); + connect(&accountManager, &AccountManager::logoutComplete, this, &GVRMainWindow::refreshLoginAction); + + // refresh the state now + refreshLoginAction(); + + QAction* aboutQt = new QAction("About Qt", helpMenu); + connect(aboutQt, &QAction::triggered, qApp, &QApplication::aboutQt); + helpMenu->addAction(aboutQt); + + setMenuBar(_menuBar); +} + +void GVRMainWindow::showAddressBar() { + // setup the address QInputDialog + QInputDialog* addressDialog = new QInputDialog(this); + addressDialog->setLabelText("Address"); + + // add the address dialog to the main layout + _mainLayout->addWidget(addressDialog); + + connect(addressDialog, &QInputDialog::textValueSelected, + DependencyManager::get().data(), &AddressManager::handleLookupString); +} + +void GVRMainWindow::showLoginDialog() { + LoginDialog* loginDialog = new LoginDialog(this); + + // have the acccount manager handle credentials from LoginDialog + AccountManager& accountManager = AccountManager::getInstance(); + connect(loginDialog, &LoginDialog::credentialsEntered, &accountManager, &AccountManager::requestAccessToken); + connect(&accountManager, &AccountManager::loginFailed, this, &GVRMainWindow::showLoginFailure); + + _mainLayout->addWidget(loginDialog); +} + +void GVRMainWindow::showLoginFailure() { + QMessageBox::warning(this, "Login Failed", + "Could not log in with that username and password. Please try again!"); +} + +void GVRMainWindow::refreshLoginAction() { + AccountManager& accountManager = AccountManager::getInstance(); + disconnect(_loginAction, &QAction::triggered, &accountManager, 0); + + if (accountManager.isLoggedIn()) { + _loginAction->setText("Logout"); + connect(_loginAction, &QAction::triggered, &accountManager, &AccountManager::logout); + } else { + _loginAction->setText("Login"); + connect(_loginAction, &QAction::triggered, this, &GVRMainWindow::showLoginDialog); + } + +} diff --git a/gvr-interface/src/GVRMainWindow.h b/gvr-interface/src/GVRMainWindow.h new file mode 100644 index 0000000000..c28c19a6c1 --- /dev/null +++ b/gvr-interface/src/GVRMainWindow.h @@ -0,0 +1,58 @@ +// +// GVRMainWindow.h +// gvr-interface/src +// +// Created by Stephen Birarda on 1/20/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_GVRMainWindow_h +#define hifi_GVRMainWindow_h + +#include + +#if defined(ANDROID) && defined(HAVE_LIBOVR) +#include +#endif + +class QKeyEvent; +class QMenuBar; +class QVBoxLayout; + +class GVRMainWindow : public QMainWindow { + Q_OBJECT +public: + GVRMainWindow(QWidget* parent = 0); + ~GVRMainWindow(); +public slots: + void showAddressBar(); + void showLoginDialog(); + + void showLoginFailure(); + +#if defined(ANDROID) && defined(HAVE_LIBOVR) + OVR::KeyState& getBackKeyState() { return _backKeyState; } +#endif + +protected: + void keyPressEvent(QKeyEvent* event); + void keyReleaseEvent(QKeyEvent* event); +private slots: + void refreshLoginAction(); +private: + void setupMenuBar(); + +#if defined(ANDROID) && defined(HAVE_LIBOVR) + OVR::KeyState _backKeyState; + bool _wasBackKeyDown; +#endif + + QVBoxLayout* _mainLayout; + QMenuBar* _menuBar; + QAction* _loginAction; +}; + +#endif // hifi_GVRMainWindow_h diff --git a/gvr-interface/src/InterfaceView.cpp b/gvr-interface/src/InterfaceView.cpp new file mode 100644 index 0000000000..e7992d3921 --- /dev/null +++ b/gvr-interface/src/InterfaceView.cpp @@ -0,0 +1,18 @@ +// +// InterfaceView.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 1/28/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "InterfaceView.h" + +InterfaceView::InterfaceView(QWidget* parent, Qt::WindowFlags flags) : + QOpenGLWidget(parent, flags) +{ + +} \ No newline at end of file diff --git a/gvr-interface/src/InterfaceView.h b/gvr-interface/src/InterfaceView.h new file mode 100644 index 0000000000..3d358a3e64 --- /dev/null +++ b/gvr-interface/src/InterfaceView.h @@ -0,0 +1,23 @@ +// +// InterfaceView.h +// gvr-interface/src +// +// Created by Stephen Birarda on 1/28/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_InterfaceView_h +#define hifi_InterfaceView_h + +#include + +class InterfaceView : public QOpenGLWidget { + Q_OBJECT +public: + InterfaceView(QWidget* parent = 0, Qt::WindowFlags flags = 0); +}; + +#endif // hifi_InterfaceView_h diff --git a/gvr-interface/src/LoginDialog.cpp b/gvr-interface/src/LoginDialog.cpp new file mode 100644 index 0000000000..95b7451bcb --- /dev/null +++ b/gvr-interface/src/LoginDialog.cpp @@ -0,0 +1,69 @@ +// +// LoginDialog.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 2015-02-03. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include +#include +#include + +#include "LoginDialog.h" + +LoginDialog::LoginDialog(QWidget* parent) : + QDialog(parent) +{ + setupGUI(); + setWindowTitle("Login"); + setModal(true); +} + +void LoginDialog::setupGUI() { + // setup a grid layout + QGridLayout* formGridLayout = new QGridLayout(this); + + _usernameLineEdit = new QLineEdit(this); + + QLabel* usernameLabel = new QLabel(this); + usernameLabel->setText("Username"); + usernameLabel->setBuddy(_usernameLineEdit); + + formGridLayout->addWidget(usernameLabel, 0, 0); + formGridLayout->addWidget(_usernameLineEdit, 1, 0); + + _passwordLineEdit = new QLineEdit(this); + _passwordLineEdit->setEchoMode(QLineEdit::Password); + + QLabel* passwordLabel = new QLabel(this); + passwordLabel->setText("Password"); + passwordLabel->setBuddy(_passwordLineEdit); + + formGridLayout->addWidget(passwordLabel, 2, 0); + formGridLayout->addWidget(_passwordLineEdit, 3, 0); + + QDialogButtonBox* buttons = new QDialogButtonBox(this); + + QPushButton* okButton = buttons->addButton(QDialogButtonBox::Ok); + QPushButton* cancelButton = buttons->addButton(QDialogButtonBox::Cancel); + + okButton->setText("Login"); + + connect(cancelButton, &QPushButton::clicked, this, &QDialog::close); + connect(okButton, &QPushButton::clicked, this, &LoginDialog::loginButtonClicked); + + formGridLayout->addWidget(buttons, 4, 0, 1, 2); + + setLayout(formGridLayout); +} + +void LoginDialog::loginButtonClicked() { + emit credentialsEntered(_usernameLineEdit->text(), _passwordLineEdit->text()); + close(); +} \ No newline at end of file diff --git a/gvr-interface/src/LoginDialog.h b/gvr-interface/src/LoginDialog.h new file mode 100644 index 0000000000..13f630818d --- /dev/null +++ b/gvr-interface/src/LoginDialog.h @@ -0,0 +1,34 @@ +// +// LoginDialog.h +// gvr-interface/src +// +// Created by Stephen Birarda on 2015-02-03. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_LoginDialog_h +#define hifi_LoginDialog_h + +#include + +class QLineEdit; + +class LoginDialog : public QDialog { + Q_OBJECT +public: + LoginDialog(QWidget* parent = 0); +signals: + void credentialsEntered(const QString& username, const QString& password); +private slots: + void loginButtonClicked(); +private: + void setupGUI(); + + QLineEdit* _usernameLineEdit; + QLineEdit* _passwordLineEdit; +}; + +#endif // hifi_LoginDialog_h \ No newline at end of file diff --git a/gvr-interface/src/RenderingClient.cpp b/gvr-interface/src/RenderingClient.cpp new file mode 100644 index 0000000000..e6d2f6b585 --- /dev/null +++ b/gvr-interface/src/RenderingClient.cpp @@ -0,0 +1,167 @@ +// +// RenderingClient.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 1/20/15. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include + +#include +#include +#include +#include + +#include "RenderingClient.h" + +RenderingClient* RenderingClient::_instance = NULL; + +RenderingClient::RenderingClient(QObject *parent, const QString& launchURLString) : + Client(parent) +{ + _instance = this; + + // connect to AddressManager and pass it the launch URL, if we have one + auto addressManager = DependencyManager::get(); + connect(addressManager.data(), &AddressManager::locationChangeRequired, this, &RenderingClient::goToLocation); + addressManager->loadSettings(launchURLString); + + // tell the NodeList which node types all rendering clients will want to know about + DependencyManager::get()->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer); + + DependencyManager::set(); + + // get our audio client setup on its own thread + QThread* audioThread = new QThread(); + auto audioClient = DependencyManager::set(); + + audioClient->setPositionGetter(getPositionForAudio); + audioClient->setOrientationGetter(getOrientationForAudio); + + audioClient->moveToThread(audioThread); + connect(audioThread, &QThread::started, audioClient.data(), &AudioClient::start); + connect(audioClient.data(), &AudioClient::destroyed, audioThread, &QThread::quit); + connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater); + + audioThread->start(); + + + connect(&_avatarTimer, &QTimer::timeout, this, &RenderingClient::sendAvatarPacket); + _avatarTimer.setInterval(16); // 60 FPS + _avatarTimer.start(); + _fakeAvatar.setDisplayName("GearVR"); + _fakeAvatar.setFaceModelURL(QUrl(DEFAULT_HEAD_MODEL_URL)); + _fakeAvatar.setSkeletonModelURL(QUrl(DEFAULT_BODY_MODEL_URL)); + _fakeAvatar.toByteArray(); // Creates HeadData +} + +void RenderingClient::sendAvatarPacket() { + _fakeAvatar.setPosition(_position); + _fakeAvatar.setHeadOrientation(_orientation); + + QByteArray packet = byteArrayWithPopulatedHeader(PacketTypeAvatarData); + packet.append(_fakeAvatar.toByteArray()); + DependencyManager::get()->broadcastToNodes(packet, NodeSet() << NodeType::AvatarMixer); + _fakeAvatar.sendIdentityPacket(); +} + +void RenderingClient::cleanupBeforeQuit() { + + QMetaObject::invokeMethod(DependencyManager::get().data(), + "stop", Qt::BlockingQueuedConnection); + + // destroy the AudioClient so it and its thread will safely go down + DependencyManager::destroy(); +} + +void RenderingClient::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) { + auto nodeList = DependencyManager::get(); + PacketType incomingType = packetTypeForPacket(incomingPacket); + + switch (incomingType) { + case PacketTypeAudioEnvironment: + case PacketTypeAudioStreamStats: + case PacketTypeMixedAudio: + case PacketTypeSilentAudioFrame: { + + if (incomingType == PacketTypeAudioStreamStats) { + QMetaObject::invokeMethod(DependencyManager::get().data(), "parseAudioStreamStatsPacket", + Qt::QueuedConnection, + Q_ARG(QByteArray, incomingPacket)); + } else if (incomingType == PacketTypeAudioEnvironment) { + QMetaObject::invokeMethod(DependencyManager::get().data(), "parseAudioEnvironmentData", + Qt::QueuedConnection, + Q_ARG(QByteArray, incomingPacket)); + } else { + QMetaObject::invokeMethod(DependencyManager::get().data(), "addReceivedAudioToStream", + Qt::QueuedConnection, + Q_ARG(QByteArray, incomingPacket)); + } + + // update having heard from the audio-mixer and record the bytes received + SharedNodePointer audioMixer = nodeList->sendingNodeForPacket(incomingPacket); + + if (audioMixer) { + audioMixer->setLastHeardMicrostamp(usecTimestampNow()); + } + + break; + } + case PacketTypeBulkAvatarData: + case PacketTypeKillAvatar: + case PacketTypeAvatarIdentity: + case PacketTypeAvatarBillboard: { + // update having heard from the avatar-mixer and record the bytes received + SharedNodePointer avatarMixer = nodeList->sendingNodeForPacket(incomingPacket); + + if (avatarMixer) { + avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); + + QMetaObject::invokeMethod(DependencyManager::get().data(), + "processAvatarMixerDatagram", + Q_ARG(const QByteArray&, incomingPacket), + Q_ARG(const QWeakPointer&, avatarMixer)); + } + break; + } + default: + Client::processVerifiedPacket(senderSockAddr, incomingPacket); + break; + } +} + +void RenderingClient::goToLocation(const glm::vec3& newPosition, + bool hasOrientationChange, const glm::quat& newOrientation, + bool shouldFaceLocation) { + qDebug().nospace() << "RenderingClient goToLocation - moving to " << newPosition.x << ", " + << newPosition.y << ", " << newPosition.z; + + glm::vec3 shiftedPosition = newPosition; + + if (hasOrientationChange) { + qDebug().nospace() << "RenderingClient goToLocation - new orientation is " + << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; + + // orient the user to face the target + glm::quat quatOrientation = newOrientation; + + if (shouldFaceLocation) { + + quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); + + // move the user a couple units away + const float DISTANCE_TO_USER = 2.0f; + shiftedPosition = newPosition - quatOrientation * glm::vec3( 0.0f, 0.0f,-1.0f) * DISTANCE_TO_USER; + } + + _orientation = quatOrientation; + } + + _position = shiftedPosition; + +} diff --git a/gvr-interface/src/RenderingClient.h b/gvr-interface/src/RenderingClient.h new file mode 100644 index 0000000000..c4724bc086 --- /dev/null +++ b/gvr-interface/src/RenderingClient.h @@ -0,0 +1,57 @@ +// +// RenderingClient.h +// gvr-interface/src +// +// Created by Stephen Birarda on 1/20/15. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#ifndef hifi_RenderingClient_h +#define hifi_RenderingClient_h + +#include +#include + +#include + +#include + +#include "Client.h" + +class RenderingClient : public Client { + Q_OBJECT +public: + RenderingClient(QObject* parent = 0, const QString& launchURLString = QString()); + + const glm::vec3& getPosition() const { return _position; } + const glm::quat& getOrientation() const { return _orientation; } + void setOrientation(const glm::quat& orientation) { _orientation = orientation; } + + static glm::vec3 getPositionForAudio() { return _instance->getPosition(); } + static glm::quat getOrientationForAudio() { return _instance->getOrientation(); } + + virtual void cleanupBeforeQuit(); + +private slots: + void goToLocation(const glm::vec3& newPosition, + bool hasOrientationChange, const glm::quat& newOrientation, + bool shouldFaceLocation); + void sendAvatarPacket(); + +private: + virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket); + + static RenderingClient* _instance; + + glm::vec3 _position; + glm::quat _orientation; + + QTimer _avatarTimer; + AvatarData _fakeAvatar; +}; + +#endif // hifi_RenderingClient_h diff --git a/gvr-interface/src/java/io/highfidelity/gvrinterface/InterfaceActivity.java b/gvr-interface/src/java/io/highfidelity/gvrinterface/InterfaceActivity.java new file mode 100644 index 0000000000..c7cbdd3dff --- /dev/null +++ b/gvr-interface/src/java/io/highfidelity/gvrinterface/InterfaceActivity.java @@ -0,0 +1,41 @@ +// +// InterfaceActivity.java +// gvr-interface/java +// +// Created by Stephen Birarda on 1/26/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +package io.highfidelity.gvrinterface; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.view.WindowManager; +import android.util.Log; +import org.qtproject.qt5.android.bindings.QtActivity; + +public class InterfaceActivity extends QtActivity { + + public static native void handleHifiURL(String hifiURLString); + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + // Get the intent that started this activity in case we have a hifi:// URL to parse + Intent intent = getIntent(); + if (intent.getAction() == Intent.ACTION_VIEW) { + Uri data = intent.getData(); + + if (data.getScheme().equals("hifi")) { + handleHifiURL(data.toString()); + } + } + + } +} \ No newline at end of file diff --git a/gvr-interface/src/main.cpp b/gvr-interface/src/main.cpp new file mode 100644 index 0000000000..26576393fb --- /dev/null +++ b/gvr-interface/src/main.cpp @@ -0,0 +1,28 @@ +// +// main.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 11/17/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "GVRMainWindow.h" +#include "GVRInterface.h" + +int main(int argc, char* argv[]) { + GVRInterface app(argc, argv); + + GVRMainWindow mainWindow; +#ifdef ANDROID + mainWindow.showFullScreen(); +#else + mainWindow.showMaximized(); +#endif + + app.setMainWindow(&mainWindow); + + return app.exec(); +} \ No newline at end of file diff --git a/gvr-interface/templates/InterfaceBetaActivity.java.in b/gvr-interface/templates/InterfaceBetaActivity.java.in new file mode 100644 index 0000000000..6698cfa409 --- /dev/null +++ b/gvr-interface/templates/InterfaceBetaActivity.java.in @@ -0,0 +1,51 @@ +// +// InterfaceBetaActivity.java +// gvr-interface/java +// +// Created by Stephen Birarda on 1/27/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +package io.highfidelity.gvrinterface; + +import android.os.Bundle; +import net.hockeyapp.android.CrashManager; +import net.hockeyapp.android.UpdateManager; + +public class InterfaceBetaActivity extends InterfaceActivity { + + public String _hockeyAppID; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + _hockeyAppID = getString(R.string.HockeyAppID); + + checkForUpdates(); + } + + @Override + protected void onPause() { + super.onPause(); + UpdateManager.unregister(); + } + + @Override + protected void onResume() { + super.onResume(); + checkForCrashes(); + } + + private void checkForCrashes() { + CrashManager.register(this, _hockeyAppID); + } + + private void checkForUpdates() { + // Remove this for store / production builds! + UpdateManager.register(this, _hockeyAppID); + } +} \ No newline at end of file diff --git a/gvr-interface/templates/hockeyapp.xml.in b/gvr-interface/templates/hockeyapp.xml.in new file mode 100644 index 0000000000..edf2d0a8aa --- /dev/null +++ b/gvr-interface/templates/hockeyapp.xml.in @@ -0,0 +1,5 @@ + + + ${HOCKEY_APP_ID} + ${HOCKEY_APP_ENABLED} + diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 0abfa7d1ef..7d581284e5 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -2,7 +2,7 @@ set(TARGET_NAME interface) project(${TARGET_NAME}) # set a default root dir for each of our optional externals if it was not passed -set(OPTIONAL_EXTERNALS "Faceshift" "LibOVR" "PrioVR" "Sixense" "LeapMotion" "RtMidi" "Qxmpp" "SDL2" "Gverb" "RSSDK") +set(OPTIONAL_EXTERNALS "Faceshift" "LibOVR" "PrioVR" "Sixense" "LeapMotion" "RtMidi" "Qxmpp" "SDL2" "RSSDK") foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE) if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR) @@ -14,10 +14,6 @@ endforeach() find_package(Qt5LinguistTools REQUIRED) find_package(Qt5LinguistToolsMacros) - -# As Gverb is currently the only reverb library, it's required. -find_package(Gverb REQUIRED) - if (DEFINED ENV{JOB_ID}) set(BUILD_SEQ $ENV{JOB_ID}) else () @@ -36,8 +32,6 @@ elseif (WIN32) set(GL_HEADERS "#include \n#include \n#include ") endif () -# set up the external glm library -include_glm() include_bullet() # create the InterfaceConfig.h file based on GL_HEADERS above @@ -113,8 +107,14 @@ endif() # create the executable, make it a bundle on OS X add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) +# set up the external glm library +add_dependency_external_project(glm) +find_package(GLM REQUIRED) +target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) + # link required hifi libraries -link_hifi_libraries(shared octree environment gpu model fbx metavoxels networking entities avatars audio animation script-engine physics +link_hifi_libraries(shared octree environment gpu model fbx metavoxels networking entities avatars + audio audio-client animation script-engine physics render-utils entities-renderer) # find any optional and required libraries @@ -179,13 +179,6 @@ if (QXMPP_FOUND AND NOT DISABLE_QXMPP AND WIN32) add_definitions(-DQXMPP_STATIC) endif () -if (GVERB_FOUND) - file(GLOB GVERB_SRCS ${GVERB_SRC_DIRS}/*.c) - include_directories(${GVERB_INCLUDE_DIRS}) - add_library(gverb STATIC ${GVERB_SRCS}) - target_link_libraries(${TARGET_NAME} gverb) -endif (GVERB_FOUND) - # include headers for interface and InterfaceConfig. include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/includes") @@ -199,12 +192,10 @@ add_definitions(-DQT_NO_BEARERMANAGEMENT) if (APPLE) # link in required OS X frameworks and include the right GL headers - find_library(CoreAudio CoreAudio) - find_library(CoreFoundation CoreFoundation) find_library(OpenGL OpenGL) find_library(AppKit AppKit) - target_link_libraries(${TARGET_NAME} ${CoreAudio} ${CoreFoundation} ${OpenGL} ${AppKit}) + target_link_libraries(${TARGET_NAME} ${OpenGL} ${AppKit}) # install command for OS X bundle INSTALL(TARGETS ${TARGET_NAME} @@ -238,7 +229,7 @@ else (APPLE) target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARIES} "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib Winmm.lib) # try to find the Nsight package and add it to the build if we find it - #find_package(NSIGHT) + find_package(NSIGHT) if (NSIGHT_FOUND) include_directories(${NSIGHT_INCLUDE_DIRS}) add_definitions(-DNSIGHT_FOUND) diff --git a/interface/external/gverb/readme.txt b/interface/external/gverb/readme.txt deleted file mode 100644 index 2f8991b1d4..0000000000 --- a/interface/external/gverb/readme.txt +++ /dev/null @@ -1,15 +0,0 @@ - -Instructions for adding the Gverb library to Interface -(This is a required library) -Clément Brisset, October 22nd, 2014 - -1. Go to https://github.com/highfidelity/gverb - Or download the sources directly via this link: - https://github.com/highfidelity/gverb/archive/master.zip - -2. Extract the archive - -3. Place the directories “include” and “src” in interface/external/gverb - (Normally next to this readme) - -4. Clear your build directory, run cmake, build and you should be all set. diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8f31872437..ce33b04777 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -23,6 +23,7 @@ // include this before QGLWidget, which includes an earlier version of OpenGL #include "InterfaceConfig.h" +#include #include #include #include @@ -64,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -73,20 +75,23 @@ #include #include #include -#include +#include +#include #include #include #include #include #include "Application.h" -#include "Audio.h" +#include "AudioClient.h" #include "InterfaceVersion.h" #include "LODManager.h" #include "Menu.h" #include "ModelUploader.h" #include "Util.h" +#include "avatar/AvatarManager.h" + #include "audio/AudioToolBox.h" #include "audio/AudioIOStatsRenderer.h" #include "audio/AudioScope.h" @@ -106,6 +111,7 @@ #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" +#include "scripting/HMDScriptingInterface.h" #include "scripting/JoystickScriptingInterface.h" #include "scripting/GlobalServicesScriptingInterface.h" #include "scripting/LocationScriptingInterface.h" @@ -126,17 +132,12 @@ #include "ui/StandAloneJSConsole.h" #include "ui/Stats.h" - - using namespace std; // Starfield information static unsigned STARFIELD_NUM_STARS = 50000; static unsigned STARFIELD_SEED = 1; -static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored - - const qint64 MAXIMUM_CACHE_SIZE = 10737418240; // 10GB static QTimer* idleTimer = NULL; @@ -146,11 +147,45 @@ const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::D const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js"; -namespace SettingHandles { - const SettingHandle firstRun("firstRun", true); - const SettingHandle lastScriptLocation("LastScriptLocation"); - const SettingHandle scriptsLocation("scriptsLocation"); -} +#ifdef Q_OS_WIN +class MyNativeEventFilter : public QAbstractNativeEventFilter { +public: + static MyNativeEventFilter& getInstance() { + static MyNativeEventFilter staticInstance; + return staticInstance; + } + + bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result) Q_DECL_OVERRIDE { + if (eventType == "windows_generic_MSG") { + MSG* message = (MSG*)msg; + + if (message->message == UWM_IDENTIFY_INSTANCES) { + *result = UWM_IDENTIFY_INSTANCES; + return true; + } + + if (message->message == UWM_SHOW_APPLICATION) { + MainWindow* applicationWindow = Application::getInstance()->getWindow(); + if (applicationWindow->isMinimized()) { + applicationWindow->showNormal(); // Restores to windowed or maximized state appropriately. + } + Application::getInstance()->setActiveWindow(applicationWindow); // Flashes the taskbar icon if not focus. + return true; + } + + if (message->message == WM_COPYDATA) { + COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam); + QUrl url = QUrl((const char*)(pcds->lpData)); + if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { + DependencyManager::get()->handleLookupString(url.toString()); + return true; + } + } + } + return false; + } +}; +#endif void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); @@ -167,27 +202,22 @@ bool setupEssentials(int& argc, char** argv) { if (portStr) { listenPort = atoi(portStr); } - - // read the ApplicationInfo.ini file for Name/Version/Domain information - QSettings::setDefaultFormat(QSettings::IniFormat); - QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - // set the associated application properties - applicationInfo.beginGroup("INFO"); - QApplication::setApplicationName(applicationInfo.value("name").toString()); - QApplication::setApplicationVersion(BUILD_VERSION); - QApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); - QApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + // Set build version + QCoreApplication::setApplicationVersion(BUILD_VERSION); DependencyManager::registerInheritance(); + DependencyManager::registerInheritance(); // Set dependencies auto glCanvas = DependencyManager::set(); auto addressManager = DependencyManager::set(); auto nodeList = DependencyManager::set(NodeType::Agent, listenPort); auto geometryCache = DependencyManager::set(); + auto scriptCache = DependencyManager::set(); + auto soundCache = DependencyManager::set(); auto glowEffect = DependencyManager::set(); auto faceshift = DependencyManager::set(); - auto audio = DependencyManager::set