From e5fc2e552550dc03fa933d8a291c5fd06490326d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 8 Oct 2015 14:03:59 -0700 Subject: [PATCH 1/9] Low level support for URL overrides when loading content --- .../src/EntityTreeRenderer.cpp | 4 +- libraries/networking/src/ResourceManager.cpp | 38 +++++++++++++++++-- libraries/networking/src/ResourceManager.h | 2 + .../procedural/src/procedural/Procedural.cpp | 1 + 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 7dea243145..fb9ab6563b 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -704,7 +704,9 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, const if (_tree && !_shuttingDown) { EntityItemPointer entity = getTree()->findEntityByEntityItemID(entityID); if (entity && !entity->getScript().isEmpty()) { - _entitiesScriptEngine->loadEntityScript(entityID, entity->getScript(), reload); + QString scriptUrl = entity->getScript(); + scriptUrl = ResourceManager::normalizeURL(scriptUrl); + _entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload); } } } diff --git a/libraries/networking/src/ResourceManager.cpp b/libraries/networking/src/ResourceManager.cpp index 774664f2c8..6b97018ed9 100644 --- a/libraries/networking/src/ResourceManager.cpp +++ b/libraries/networking/src/ResourceManager.cpp @@ -17,7 +17,37 @@ #include -QUrl ResourceManager::normalizeURL(const QUrl& url) { + +using PrefixMap = std::map; +static PrefixMap PREFIX_MAP; +static QMutex PREFIX_MAP_LOCK; + +void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) { + QMutexLocker locker(&PREFIX_MAP_LOCK); + PREFIX_MAP[prefix] = replacement; +} + +QString ResourceManager::normalizeURL(const QString& urlString) { + QString result = urlString; + QMutexLocker locker(&PREFIX_MAP_LOCK); + bool modified{ false }; + foreach(const auto& entry, PREFIX_MAP) { + const auto& prefix = entry.first; + const auto& replacement = entry.second; + if (result.startsWith(prefix)) { + qDebug() << prefix; + result.replace(0, prefix.size(), replacement); + modified = true; + } + } + if (modified) { + qDebug() << result; + } + return result; +} + +QUrl ResourceManager::normalizeURL(const QUrl& originalUrl) { + QUrl url = QUrl(normalizeURL(originalUrl.toString())); auto scheme = url.scheme(); if (!(scheme == URL_SCHEME_FILE || scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP || @@ -37,11 +67,11 @@ ResourceRequest* ResourceManager::createResourceRequest(QObject* parent, const Q auto normalizedURL = normalizeURL(url); auto scheme = normalizedURL.scheme(); if (scheme == URL_SCHEME_FILE) { - return new FileResourceRequest(parent, url); + return new FileResourceRequest(parent, normalizedURL); } else if (scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP) { - return new HTTPResourceRequest(parent, url); + return new HTTPResourceRequest(parent, normalizedURL); } else if (scheme == URL_SCHEME_ATP) { - return new AssetResourceRequest(parent, url); + return new AssetResourceRequest(parent, normalizedURL); } qDebug() << "Unknown scheme (" << scheme << ") for URL: " << url.url(); diff --git a/libraries/networking/src/ResourceManager.h b/libraries/networking/src/ResourceManager.h index 40b67b1cd1..58f4679c97 100644 --- a/libraries/networking/src/ResourceManager.h +++ b/libraries/networking/src/ResourceManager.h @@ -24,6 +24,8 @@ const QString URL_SCHEME_ATP = "atp"; class ResourceManager { public: + static void setUrlPrefixOverride(const QString& prefix, const QString& replacement); + static QString normalizeURL(const QString& urlString); static QUrl normalizeURL(const QUrl& url); static ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url); }; diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index f5448bda5c..a0020d21f3 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -88,6 +88,7 @@ void Procedural::parse(const QJsonObject& proceduralData) { // Get the path to the shader { QString shaderUrl = proceduralData[URL_KEY].toString(); + shaderUrl = ResourceManager::normalizeURL(shaderUrl); _shaderUrl = QUrl(shaderUrl); if (!_shaderUrl.isValid()) { qWarning() << "Invalid shader URL: " << shaderUrl; From 6f5f6450dfcca1877d00ffc49ab6a49d5a724112 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 11 Oct 2015 00:01:03 -0700 Subject: [PATCH 2/9] Cleanup CMake files --- assignment-client/CMakeLists.txt | 4 -- cmake/macros/LinkHifiLibraries.cmake | 1 - cmake/macros/SetupHifiLibrary.cmake | 4 ++ cmake/macros/SetupHifiProject.cmake | 3 ++ cmake/macros/SetupHifiTestCase.cmake | 6 ++- cmake/macros/TargetBullet.cmake | 18 ++++++++ cmake/macros/TargetGlew.cmake | 14 ++++++ cmake/macros/TargetGlm.cmake | 12 +++++ cmake/macros/TargetNsight.cmake | 20 +++++++++ cmake/macros/TargetOglplus.cmake | 21 +++++++++ ...tupHifiOpenGL.cmake => TargetOpenGL.cmake} | 32 ++++--------- gvr-interface/CMakeLists.txt | 4 -- interface/CMakeLists.txt | 24 +++------- libraries/animation/CMakeLists.txt | 3 -- libraries/audio-client/CMakeLists.txt | 5 --- libraries/audio/CMakeLists.txt | 7 --- libraries/auto-updater/CMakeLists.txt | 1 - libraries/avatars/CMakeLists.txt | 7 --- libraries/display-plugins/CMakeLists.txt | 21 ++------- libraries/embedded-webserver/CMakeLists.txt | 2 - libraries/entities-renderer/CMakeLists.txt | 21 +-------- libraries/entities/CMakeLists.txt | 23 ++-------- libraries/environment/CMakeLists.txt | 7 --- libraries/fbx/CMakeLists.txt | 7 --- libraries/gpu/CMakeLists.txt | 45 +------------------ libraries/input-plugins/CMakeLists.txt | 27 +++++------ libraries/model-networking/CMakeLists.txt | 7 --- libraries/model/CMakeLists.txt | 9 +--- libraries/networking/CMakeLists.txt | 3 -- libraries/octree/CMakeLists.txt | 7 --- libraries/physics/CMakeLists.txt | 23 +--------- libraries/plugins/CMakeLists.txt | 8 ---- libraries/procedural/CMakeLists.txt | 9 +--- libraries/render-utils/CMakeLists.txt | 42 ++--------------- libraries/render/CMakeLists.txt | 21 +-------- libraries/script-engine/CMakeLists.txt | 7 --- libraries/shared/CMakeLists.txt | 6 +-- libraries/ui/CMakeLists.txt | 8 ---- tests/gpu-test/CMakeLists.txt | 8 ---- tests/physics/CMakeLists.txt | 17 +------ 40 files changed, 141 insertions(+), 373 deletions(-) create mode 100644 cmake/macros/TargetBullet.cmake create mode 100644 cmake/macros/TargetGlew.cmake create mode 100644 cmake/macros/TargetGlm.cmake create mode 100644 cmake/macros/TargetNsight.cmake create mode 100644 cmake/macros/TargetOglplus.cmake rename cmake/macros/{SetupHifiOpenGL.cmake => TargetOpenGL.cmake} (58%) diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 84a36c6c51..e543b3aa21 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -2,10 +2,6 @@ set(TARGET_NAME assignment-client) setup_hifi_project(Core Gui Network Script Widgets WebSockets) -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) - # link in the shared libraries link_hifi_libraries( audio avatars octree environment gpu model fbx entities diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index d0a12f3bea..70399bedb4 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -16,7 +16,6 @@ macro(LINK_HIFI_LIBRARIES) foreach(HIFI_LIBRARY ${LIBRARIES_TO_LINK}) if (NOT TARGET ${HIFI_LIBRARY}) add_subdirectory("${RELATIVE_LIBRARY_DIR_PATH}/${HIFI_LIBRARY}" "${RELATIVE_LIBRARY_DIR_PATH}/${HIFI_LIBRARY}") - set_target_properties(${HIFI_LIBRARY} PROPERTIES FOLDER "Libraries") endif () include_directories("${HIFI_LIBRARY_DIR}/${HIFI_LIBRARY}/src") diff --git a/cmake/macros/SetupHifiLibrary.cmake b/cmake/macros/SetupHifiLibrary.cmake index ccb5ca2484..9c6cbf6831 100644 --- a/cmake/macros/SetupHifiLibrary.cmake +++ b/cmake/macros/SetupHifiLibrary.cmake @@ -36,5 +36,9 @@ macro(SETUP_HIFI_LIBRARY) # Don't make scribed shaders cumulative set(AUTOSCRIBE_SHADER_LIB_SRC "") + + target_glm() + + set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Libraries") endmacro(SETUP_HIFI_LIBRARY) \ No newline at end of file diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index bd6cbef9dc..166a3fd4b9 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -34,4 +34,7 @@ macro(SETUP_HIFI_PROJECT) foreach(QT_MODULE ${${TARGET_NAME}_DEPENDENCY_QT_MODULES}) target_link_libraries(${TARGET_NAME} Qt5::${QT_MODULE}) endforeach() + + target_glm() + endmacro() diff --git a/cmake/macros/SetupHifiTestCase.cmake b/cmake/macros/SetupHifiTestCase.cmake index 2507a30f5e..38239d6e97 100644 --- a/cmake/macros/SetupHifiTestCase.cmake +++ b/cmake/macros/SetupHifiTestCase.cmake @@ -94,6 +94,7 @@ macro(SETUP_HIFI_TESTCASE) EXCLUDE_FROM_DEFAULT_BUILD TRUE EXCLUDE_FROM_ALL TRUE) + list (APPEND ${TEST_PROJ_NAME}_TARGETS ${TARGET_NAME}) #list (APPEND ALL_TEST_TARGETS ${TARGET_NAME}) @@ -111,8 +112,9 @@ macro(SETUP_HIFI_TESTCASE) set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "hidden/test-executables") # handle testcase-specific dependencies (this a macro that should be defined in the cmakelists.txt file in each tests subdir) - - SETUP_TESTCASE_DEPENDENCIES () + SETUP_TESTCASE_DEPENDENCIES() + target_glm() + endforeach () set(TEST_TARGET ${TEST_PROJ_NAME}-tests) diff --git a/cmake/macros/TargetBullet.cmake b/cmake/macros/TargetBullet.cmake new file mode 100644 index 0000000000..600ae9e63b --- /dev/null +++ b/cmake/macros/TargetBullet.cmake @@ -0,0 +1,18 @@ +# +# Copyright 2015 High Fidelity, Inc. +# Created by Bradley Austin Davis on 2015/10/10 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# +macro(TARGET_BULLET) + add_dependency_external_projects(bullet) + find_package(Bullet REQUIRED) + # perform the system include hack for OS X to ignore warnings + if (APPLE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}") + else() + target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) + endif() + target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) +endmacro() \ No newline at end of file diff --git a/cmake/macros/TargetGlew.cmake b/cmake/macros/TargetGlew.cmake new file mode 100644 index 0000000000..5f71f021ec --- /dev/null +++ b/cmake/macros/TargetGlew.cmake @@ -0,0 +1,14 @@ +# +# Copyright 2015 High Fidelity, Inc. +# Created by Bradley Austin Davis on 2015/10/10 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# +macro(TARGET_GLEW) + add_dependency_external_projects(glew) + find_package(GLEW REQUIRED) + add_definitions(-DGLEW_STATIC) + target_include_directories(${TARGET_NAME} PUBLIC ${GLEW_INCLUDE_DIRS}) + target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARY}) +endmacro() \ No newline at end of file diff --git a/cmake/macros/TargetGlm.cmake b/cmake/macros/TargetGlm.cmake new file mode 100644 index 0000000000..324cb1c17a --- /dev/null +++ b/cmake/macros/TargetGlm.cmake @@ -0,0 +1,12 @@ +# +# Copyright 2015 High Fidelity, Inc. +# Created by Bradley Austin Davis on 2015/10/10 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# +macro(TARGET_GLM) + add_dependency_external_projects(glm) + find_package(GLM REQUIRED) + target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) +endmacro() \ No newline at end of file diff --git a/cmake/macros/TargetNsight.cmake b/cmake/macros/TargetNsight.cmake new file mode 100644 index 0000000000..4b7e87e9d3 --- /dev/null +++ b/cmake/macros/TargetNsight.cmake @@ -0,0 +1,20 @@ +# +# Copyright 2015 High Fidelity, Inc. +# Created by Bradley Austin Davis on 2015/10/10 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# +macro(TARGET_NSIGHT) + if (WIN32) + if (USE_NSIGHT) + # try to find the Nsight package and add it to the build if we find it + find_package(NSIGHT) + if (NSIGHT_FOUND) + include_directories(${NSIGHT_INCLUDE_DIRS}) + add_definitions(-DNSIGHT_FOUND) + target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") + endif () + endif() + endif (WIN32) +endmacro() \ No newline at end of file diff --git a/cmake/macros/TargetOglplus.cmake b/cmake/macros/TargetOglplus.cmake new file mode 100644 index 0000000000..16a50f3dd7 --- /dev/null +++ b/cmake/macros/TargetOglplus.cmake @@ -0,0 +1,21 @@ +# +# Copyright 2015 High Fidelity, Inc. +# Created by Bradley Austin Davis on 2015/10/10 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# +macro(TARGET_OGLPLUS) + # our OGL plus setup requires glew + target_glew() + + # our OGL plus setup requires boostconfig + add_dependency_external_projects(boostconfig) + find_package(BoostConfig REQUIRED) + target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS}) + + + add_dependency_external_projects(oglplus) + find_package(OGLPLUS REQUIRED) + target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS}) +endmacro() \ No newline at end of file diff --git a/cmake/macros/SetupHifiOpenGL.cmake b/cmake/macros/TargetOpenGL.cmake similarity index 58% rename from cmake/macros/SetupHifiOpenGL.cmake rename to cmake/macros/TargetOpenGL.cmake index 2b1858fd4b..7b3178d579 100644 --- a/cmake/macros/SetupHifiOpenGL.cmake +++ b/cmake/macros/TargetOpenGL.cmake @@ -1,38 +1,24 @@ - - -macro(SETUP_HIFI_OPENGL) - +# +# Copyright 2015 High Fidelity, Inc. +# Created by Bradley Austin Davis on 2015/10/10 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# +macro(TARGET_OPENGL) if (APPLE) - # link in required OS X frameworks and include the right GL headers find_library(OpenGL OpenGL) target_link_libraries(${TARGET_NAME} ${OpenGL}) - - elseif (WIN32) - - if (USE_NSIGHT) - # try to find the Nsight package and add it to the build if we find it - find_package(NSIGHT) - if (NSIGHT_FOUND) - include_directories(${NSIGHT_INCLUDE_DIRS}) - add_definitions(-DNSIGHT_FOUND) - target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") - endif() - endif() - elseif(ANDROID) - target_link_libraries(${TARGET_NAME} "-lGLESv3" "-lEGL") - else() - + target_nsight() find_package(OpenGL REQUIRED) if (${OPENGL_INCLUDE_DIR}) include_directories(SYSTEM "${OPENGL_INCLUDE_DIR}") endif() target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}") target_include_directories(${TARGET_NAME} PUBLIC ${OPENGL_INCLUDE_DIR}) - endif() - endmacro() diff --git a/gvr-interface/CMakeLists.txt b/gvr-interface/CMakeLists.txt index 2c1e87c8b4..175706a3ff 100644 --- a/gvr-interface/CMakeLists.txt +++ b/gvr-interface/CMakeLists.txt @@ -24,10 +24,6 @@ endif () include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared networking audio-client avatars) if (ANDROID) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 63d1445496..00f6d2ecea 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -1,8 +1,6 @@ set(TARGET_NAME interface) project(${TARGET_NAME}) -add_definitions(-DGLEW_STATIC) - # set a default root dir for each of our optional externals if it was not passed set(OPTIONAL_EXTERNALS "Faceshift" "LeapMotion" "RtMidi" "RSSDK" "3DConnexionClient" "iViewHMD") foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) @@ -97,29 +95,17 @@ else() add_executable(${TARGET_NAME} ${INTERFACE_SRCS} ${QM}) endif() -add_dependency_external_projects(glm bullet) - -# set up the external glm library -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) - -find_package(Bullet REQUIRED) - -# perform the system include hack for OS X to ignore warnings -if (APPLE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}") -else() - target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) -endif() - -target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) - # link required hifi libraries link_hifi_libraries(shared octree environment gpu procedural model render fbx networking model-networking entities avatars audio audio-client animation script-engine physics render-utils entities-renderer ui auto-updater plugins display-plugins input-plugins) +target_bullet() +target_glew() +target_opengl() + + add_dependency_external_projects(sdl2) # perform standard include and linking for found externals diff --git a/libraries/animation/CMakeLists.txt b/libraries/animation/CMakeLists.txt index 115a2e360c..3cf7bfa295 100644 --- a/libraries/animation/CMakeLists.txt +++ b/libraries/animation/CMakeLists.txt @@ -1,6 +1,3 @@ set(TARGET_NAME animation) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network Script) - link_hifi_libraries(shared gpu model fbx) diff --git a/libraries/audio-client/CMakeLists.txt b/libraries/audio-client/CMakeLists.txt index f631ec6387..90937edc5d 100644 --- a/libraries/audio-client/CMakeLists.txt +++ b/libraries/audio-client/CMakeLists.txt @@ -1,8 +1,5 @@ set(TARGET_NAME audio-client) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network Multimedia) - link_hifi_libraries(audio) # append audio includes to our list of includes to bubble @@ -10,9 +7,7 @@ target_include_directories(${TARGET_NAME} PUBLIC "${HIFI_LIBRARY_DIR}/audio/src" # have CMake grab externals for us add_dependency_external_projects(gverb) - find_package(Gverb REQUIRED) - target_link_libraries(${TARGET_NAME} ${GVERB_LIBRARIES}) target_include_directories(${TARGET_NAME} PRIVATE ${GVERB_INCLUDE_DIRS}) diff --git a/libraries/audio/CMakeLists.txt b/libraries/audio/CMakeLists.txt index 5134ccda36..c49c9547a5 100644 --- a/libraries/audio/CMakeLists.txt +++ b/libraries/audio/CMakeLists.txt @@ -1,10 +1,3 @@ set(TARGET_NAME audio) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(networking shared) diff --git a/libraries/auto-updater/CMakeLists.txt b/libraries/auto-updater/CMakeLists.txt index c3d6e74a6f..b3665af2cb 100644 --- a/libraries/auto-updater/CMakeLists.txt +++ b/libraries/auto-updater/CMakeLists.txt @@ -1,4 +1,3 @@ set(TARGET_NAME auto-updater) - setup_hifi_library(Network) link_hifi_libraries(shared networking) diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index acc939b25c..849828bbf6 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -1,10 +1,3 @@ set(TARGET_NAME avatars) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network Script) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(audio shared networking) diff --git a/libraries/display-plugins/CMakeLists.txt b/libraries/display-plugins/CMakeLists.txt index b602327f4c..504370796a 100644 --- a/libraries/display-plugins/CMakeLists.txt +++ b/libraries/display-plugins/CMakeLists.txt @@ -1,27 +1,12 @@ set(TARGET_NAME display-plugins) - -add_definitions(-DGLEW_STATIC) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(OpenGL) - -setup_hifi_opengl() - link_hifi_libraries(shared plugins gpu render-utils) +target_opengl() + GroupSources("src/display-plugins") -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - -add_dependency_external_projects(boostconfig) -find_package(BoostConfig REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS}) - -add_dependency_external_projects(oglplus) -find_package(OGLPLUS REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS}) +target_oglplus() add_dependency_external_projects(LibOVR) find_package(LibOVR REQUIRED) diff --git a/libraries/embedded-webserver/CMakeLists.txt b/libraries/embedded-webserver/CMakeLists.txt index 45d9827d42..b23be3a7a2 100644 --- a/libraries/embedded-webserver/CMakeLists.txt +++ b/libraries/embedded-webserver/CMakeLists.txt @@ -1,4 +1,2 @@ set(TARGET_NAME embedded-webserver) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index d092f188e1..bb90c04c95 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -1,29 +1,12 @@ set(TARGET_NAME entities-renderer) - AUTOSCRIBE_SHADER_LIB(gpu model render render-utils) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Widgets Network Script) +link_hifi_libraries(shared gpu procedural model model-networking script-engine render render-utils) -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - -add_dependency_external_projects(bullet) -find_package(Bullet REQUIRED) - -# perform the system include hack for OS X to ignore warnings -if (APPLE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}") -else() - target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) -endif() - -target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) +target_bullet() add_dependency_external_projects(polyvox) find_package(PolyVox REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${POLYVOX_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES}) -link_hifi_libraries(shared gpu procedural model model-networking script-engine render render-utils) diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index f7936ff125..f6b2e0e280 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -1,24 +1,7 @@ set(TARGET_NAME entities) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network Script) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - -add_dependency_external_projects(bullet) - -find_package(Bullet REQUIRED) - -# perform the system include hack for OS X to ignore warnings -if (APPLE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}") -else() - target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) -endif() - -target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) - link_hifi_libraries(avatars shared octree gpu model fbx networking animation environment) + +target_bullet() + include_hifi_library_headers(render) diff --git a/libraries/environment/CMakeLists.txt b/libraries/environment/CMakeLists.txt index e3fc143c14..11538a8f2b 100644 --- a/libraries/environment/CMakeLists.txt +++ b/libraries/environment/CMakeLists.txt @@ -1,10 +1,3 @@ set(TARGET_NAME environment) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared networking) diff --git a/libraries/fbx/CMakeLists.txt b/libraries/fbx/CMakeLists.txt index 9d9f57ad20..e10b6bcfd5 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/fbx/CMakeLists.txt @@ -1,10 +1,3 @@ set(TARGET_NAME fbx) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared gpu model networking octree) diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index 38fe5cb22f..63da1d8f8a 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -1,48 +1,7 @@ set(TARGET_NAME gpu) - AUTOSCRIBE_SHADER_LIB(gpu) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - link_hifi_libraries(shared) -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - -add_dependency_external_projects(glew) -find_package(GLEW REQUIRED) -add_definitions(-DGLEW_STATIC) -target_include_directories(${TARGET_NAME} PUBLIC ${GLEW_INCLUDE_DIRS}) -target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARY}) - -if (APPLE) - # link in required OS X frameworks and include the right GL headers - find_library(OpenGL OpenGL) - target_link_libraries(${TARGET_NAME} ${OpenGL}) -elseif (WIN32) - target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARY} opengl32.lib) - - if (USE_NSIGHT) - # try to find the Nsight package and add it to the build if we find it - # note that this will also enable NSIGHT profilers in all the projects linking gpu - find_package(NSIGHT) - if (NSIGHT_FOUND) - target_include_directories(${TARGET_NAME} PUBLIC ${NSIGHT_INCLUDE_DIRS}) - target_compile_definitions(${TARGET_NAME} PUBLIC NSIGHT_FOUND) - target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") - endif () - endif() -elseif (ANDROID) - target_link_libraries(${TARGET_NAME} "-lGLESv3" "-lEGL") -else () - - find_package(OpenGL REQUIRED) - - if (${OPENGL_INCLUDE_DIR}) - include_directories(SYSTEM "${OPENGL_INCLUDE_DIR}") - endif () - - target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}") -endif (APPLE) +target_glew() +target_opengl() \ No newline at end of file diff --git a/libraries/input-plugins/CMakeLists.txt b/libraries/input-plugins/CMakeLists.txt index 1ac8047edc..094a697012 100644 --- a/libraries/input-plugins/CMakeLists.txt +++ b/libraries/input-plugins/CMakeLists.txt @@ -1,26 +1,9 @@ set(TARGET_NAME input-plugins) - -# set a default root dir for each of our optional externals if it was not passed -set(OPTIONAL_EXTERNALS "SDL2" "Sixense") -foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) - string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE) - if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR) - string(TOLOWER ${EXTERNAL} ${EXTERNAL}_LOWERCASE) - set(${${EXTERNAL}_UPPERCASE}_ROOT_DIR "${CMAKE_SOURCE_DIR}/interface/external/${${EXTERNAL}_LOWERCASE}") - endif () -endforeach() - setup_hifi_library() - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules link_hifi_libraries(shared plugins gpu render-utils) GroupSources("src/input-plugins") -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - if (WIN32) add_dependency_external_projects(OpenVR) find_package(OpenVR REQUIRED) @@ -33,6 +16,16 @@ endif() #target_include_directories(${TARGET_NAME} PRIVATE ${SIXENSE_INCLUDE_DIRS}) #target_link_libraries(${TARGET_NAME} ${SIXENSE_LIBRARIES}) +# set a default root dir for each of our optional externals if it was not passed +set(OPTIONAL_EXTERNALS "SDL2" "Sixense") +foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) + string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE) + if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR) + string(TOLOWER ${EXTERNAL} ${EXTERNAL}_LOWERCASE) + set(${${EXTERNAL}_UPPERCASE}_ROOT_DIR "${CMAKE_SOURCE_DIR}/interface/external/${${EXTERNAL}_LOWERCASE}") + endif () +endforeach() + # perform standard include and linking for found externals foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) diff --git a/libraries/model-networking/CMakeLists.txt b/libraries/model-networking/CMakeLists.txt index f014885794..29ab17f2ec 100644 --- a/libraries/model-networking/CMakeLists.txt +++ b/libraries/model-networking/CMakeLists.txt @@ -1,11 +1,4 @@ set(TARGET_NAME model-networking) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared networking gpu model fbx) diff --git a/libraries/model/CMakeLists.txt b/libraries/model/CMakeLists.txt index c30ffb7238..63f632e484 100755 --- a/libraries/model/CMakeLists.txt +++ b/libraries/model/CMakeLists.txt @@ -1,12 +1,5 @@ set(TARGET_NAME model) - AUTOSCRIBE_SHADER_LIB(gpu model) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared gpu) + diff --git a/libraries/networking/CMakeLists.txt b/libraries/networking/CMakeLists.txt index 274dae7420..470c9145df 100644 --- a/libraries/networking/CMakeLists.txt +++ b/libraries/networking/CMakeLists.txt @@ -1,8 +1,5 @@ set(TARGET_NAME networking) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network) - link_hifi_libraries(shared) if (WIN32) diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index cc36aead15..bea036add3 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -1,10 +1,3 @@ set(TARGET_NAME octree) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared networking) diff --git a/libraries/physics/CMakeLists.txt b/libraries/physics/CMakeLists.txt index b1f9fbb79c..b734c9ac2e 100644 --- a/libraries/physics/CMakeLists.txt +++ b/libraries/physics/CMakeLists.txt @@ -1,24 +1,5 @@ set(TARGET_NAME physics) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - -add_dependency_external_projects(bullet) - -find_package(Bullet REQUIRED) - -# perform the system include hack for OS X to ignore warnings -if (APPLE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}") -else() - target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) -endif() - -target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) - link_hifi_libraries(shared fbx entities) -include_hifi_library_headers(fbx) + +target_bullet() diff --git a/libraries/plugins/CMakeLists.txt b/libraries/plugins/CMakeLists.txt index 42b8cb1625..f32650df94 100644 --- a/libraries/plugins/CMakeLists.txt +++ b/libraries/plugins/CMakeLists.txt @@ -1,11 +1,3 @@ set(TARGET_NAME plugins) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(OpenGL) - link_hifi_libraries(shared) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) - -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) diff --git a/libraries/procedural/CMakeLists.txt b/libraries/procedural/CMakeLists.txt index 9595ef5f7a..0483b8d3a8 100644 --- a/libraries/procedural/CMakeLists.txt +++ b/libraries/procedural/CMakeLists.txt @@ -1,12 +1,5 @@ set(TARGET_NAME procedural) - AUTOSCRIBE_SHADER_LIB(gpu model) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared gpu model model-networking) + diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index fa6cc6fe77..c74089a238 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -1,45 +1,9 @@ set(TARGET_NAME render-utils) - AUTOSCRIBE_SHADER_LIB(gpu model render) - # pull in the resources.qrc file qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts.qrc") - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Widgets OpenGL Network Qml Quick Script) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - -add_dependency_external_projects(boostconfig) -find_package(BoostConfig REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS}) - -add_dependency_external_projects(oglplus) -find_package(OGLPLUS REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS}) - -add_definitions(-DGLEW_STATIC) - -if (WIN32) - if (USE_NSIGHT) - # try to find the Nsight package and add it to the build if we find it - find_package(NSIGHT) - if (NSIGHT_FOUND) - include_directories(${NSIGHT_INCLUDE_DIRS}) - add_definitions(-DNSIGHT_FOUND) - target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") - endif () - endif() -endif (WIN32) - -add_dependency_external_projects(boostconfig) -find_package(BoostConfig REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS}) - -add_dependency_external_projects(oglplus) -find_package(OGLPLUS REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS}) - link_hifi_libraries(shared gpu procedural model model-networking render environment animation fbx) + +target_nsight() +target_oglplus() diff --git a/libraries/render/CMakeLists.txt b/libraries/render/CMakeLists.txt index f2bcb7c47c..76fc8303ce 100644 --- a/libraries/render/CMakeLists.txt +++ b/libraries/render/CMakeLists.txt @@ -1,24 +1,7 @@ set(TARGET_NAME render) - AUTOSCRIBE_SHADER_LIB(gpu model) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared gpu model) -if (WIN32) - if (USE_NSIGHT) - # try to find the Nsight package and add it to the build if we find it - find_package(NSIGHT) - if (NSIGHT_FOUND) - include_directories(${NSIGHT_INCLUDE_DIRS}) - add_definitions(-DNSIGHT_FOUND) - target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") - endif () - endif() -endif (WIN32) + +target_nsight() diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index a458d4de51..cfe0afd220 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -1,10 +1,3 @@ set(TARGET_NAME script-engine) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Gui Network Script WebSockets Widgets) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - link_hifi_libraries(shared networking octree gpu procedural model model-networking fbx entities animation audio physics) diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 00a80619bc..d9df5eba7f 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -1,15 +1,11 @@ set(TARGET_NAME shared) -# use setup_hifi_library macro to setup our project and link appropriate Qt modules # TODO: there isn't really a good reason to have Script linked here - let's get what is requiring it out (RegisteredMetaTypes.cpp) setup_hifi_library(Gui Network Script Widgets) find_package(ZLIB REQUIRED) target_link_libraries(${TARGET_NAME} ${ZLIB_LIBRARIES}) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS}) +target_include_directories(${TARGET_NAME} PUBLIC ${ZLIB_INCLUDE_DIRS}) if (WIN32) # Birarda will fix this when he finds it. diff --git a/libraries/ui/CMakeLists.txt b/libraries/ui/CMakeLists.txt index b07651f7d4..d4cd1fc2bb 100644 --- a/libraries/ui/CMakeLists.txt +++ b/libraries/ui/CMakeLists.txt @@ -1,11 +1,3 @@ set(TARGET_NAME ui) - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(OpenGL Network Qml Quick Script XmlPatterns) - link_hifi_libraries(render-utils shared) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) - -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index 1cb9e9f78e..0c183fc2f0 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -1,15 +1,7 @@ - set(TARGET_NAME gpu-test) - AUTOSCRIBE_SHADER_LIB(gpu model render-utils) - # This is not a testcase -- just set it up as a regular hifi project setup_hifi_project(Quick Gui OpenGL Script Widgets) set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") - -#include_oglplus() - -# link in the shared libraries link_hifi_libraries(networking gpu procedural shared fbx model model-networking animation script-engine render-utils ) - copy_dlls_beside_windows_executable() \ No newline at end of file diff --git a/tests/physics/CMakeLists.txt b/tests/physics/CMakeLists.txt index 36cf21c681..f789a7b2ba 100644 --- a/tests/physics/CMakeLists.txt +++ b/tests/physics/CMakeLists.txt @@ -1,22 +1,7 @@ # Declare dependencies macro (SETUP_TESTCASE_DEPENDENCIES) - add_dependency_external_projects(glm) - find_package(GLM REQUIRED) - target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - - add_dependency_external_projects(bullet) - - find_package(Bullet REQUIRED) - target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) - - # perform the system include hack for OS X to ignore warnings - if (APPLE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}") - else() - target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) - endif() - + target_bullet() link_hifi_libraries(shared physics) copy_dlls_beside_windows_executable() endmacro () From cd1b7585348a6468ae4f138502b9f6fbad378fdb Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 11 Oct 2015 00:07:34 -0700 Subject: [PATCH 3/9] PR comments --- libraries/networking/src/ResourceManager.cpp | 19 ++++++------------- libraries/networking/src/ResourceManager.h | 7 +++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libraries/networking/src/ResourceManager.cpp b/libraries/networking/src/ResourceManager.cpp index 6b97018ed9..fd465a0aed 100644 --- a/libraries/networking/src/ResourceManager.cpp +++ b/libraries/networking/src/ResourceManager.cpp @@ -17,32 +17,25 @@ #include +ResourceManager::PrefixMap ResourceManager::_prefixMap; +QMutex ResourceManager::_prefixMapLock; -using PrefixMap = std::map; -static PrefixMap PREFIX_MAP; -static QMutex PREFIX_MAP_LOCK; void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) { - QMutexLocker locker(&PREFIX_MAP_LOCK); - PREFIX_MAP[prefix] = replacement; + QMutexLocker locker(&_prefixMapLock); + _prefixMap[prefix] = replacement; } QString ResourceManager::normalizeURL(const QString& urlString) { QString result = urlString; - QMutexLocker locker(&PREFIX_MAP_LOCK); - bool modified{ false }; - foreach(const auto& entry, PREFIX_MAP) { + QMutexLocker locker(&_prefixMapLock); + foreach(const auto& entry, _prefixMap) { const auto& prefix = entry.first; const auto& replacement = entry.second; if (result.startsWith(prefix)) { - qDebug() << prefix; result.replace(0, prefix.size(), replacement); - modified = true; } } - if (modified) { - qDebug() << result; - } return result; } diff --git a/libraries/networking/src/ResourceManager.h b/libraries/networking/src/ResourceManager.h index 58f4679c97..c010c67f9b 100644 --- a/libraries/networking/src/ResourceManager.h +++ b/libraries/networking/src/ResourceManager.h @@ -14,6 +14,8 @@ #include +#include + #include "ResourceRequest.h" const QString URL_SCHEME_FILE = "file"; @@ -28,6 +30,11 @@ public: static QString normalizeURL(const QString& urlString); static QUrl normalizeURL(const QUrl& url); static ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url); +private: + using PrefixMap = std::map; + + static PrefixMap _prefixMap; + static QMutex _prefixMapLock; }; #endif From b5b4c2153a0bb8053c117192cee4cd4abc5257a3 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 14:00:35 -0700 Subject: [PATCH 4/9] temp fix to get editing working again --- examples/libraries/entitySelectionTool.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index c49408fef6..7b79b654f7 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -2324,9 +2324,11 @@ SelectionDisplay = (function () { } }); - that.checkMove = function() { + that.checkMove = function () { if (SelectionManager.hasSelection()) { - SelectionManager._update(); + + // FIXME - this cause problems with editing in the entity properties window + //SelectionManager._update(); if (!Vec3.equal(Camera.getPosition(), lastCameraPosition) || !Quat.equal(Camera.getOrientation(), lastCameraOrientation)) { From e09fe30f05718fe742b5961488a9d86cfd1d9286 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 14:02:33 -0700 Subject: [PATCH 5/9] damn you visual studio --- examples/libraries/entitySelectionTool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 7b79b654f7..61aa5b0394 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -2324,7 +2324,7 @@ SelectionDisplay = (function () { } }); - that.checkMove = function () { + that.checkMove = function() { if (SelectionManager.hasSelection()) { // FIXME - this cause problems with editing in the entity properties window From 0986f86c349417fc61a2598043bc9fbaf803e8d7 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 14:55:07 -0700 Subject: [PATCH 6/9] implement StandardController and expose it to JS as Controller.Standard.* --- .../scripts/controllerScriptingExamples.js | 9 +++++++-- .../scripting/ControllerScriptingInterface.cpp | 13 +++++++++++++ .../src/input-plugins/UserInputMapper.cpp | 15 +++++++++++++++ .../src/input-plugins/UserInputMapper.h | 14 +++++++++++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/examples/example/scripts/controllerScriptingExamples.js b/examples/example/scripts/controllerScriptingExamples.js index 88c4ae2daa..6db7b38705 100644 --- a/examples/example/scripts/controllerScriptingExamples.js +++ b/examples/example/scripts/controllerScriptingExamples.js @@ -11,14 +11,19 @@ // Assumes you only have the default keyboard connected + +Object.keys(Controller.Standard).forEach(function (input) { + print("Controller.Standard." + input + ":" + Controller.Standard[input]); +}); + Object.keys(Controller.Hardware).forEach(function (deviceName) { Object.keys(Controller.Hardware[deviceName]).forEach(function (input) { - print(deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); + print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); }); }); Object.keys(Controller.Actions).forEach(function (actionName) { - print(actionName + ":" + Controller.Actions[actionName]); + print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]); }); // Resets every device to its default key bindings: diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 4db482b6d4..9bdf8d1a4a 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -391,6 +391,19 @@ QString ControllerScriptingInterface::sanatizeName(const QString& name) { void ControllerScriptingInterface::wireUpControllers(ScriptEngine* engine) { + // Controller.Standard.* + auto standardDevice = DependencyManager::get()->getStandardDevice(); + if (standardDevice) { + auto deviceName = sanatizeName(standardDevice->getName()); + auto deviceInputs = standardDevice->getAvailabeInputs(); + for (const auto& inputMapping : deviceInputs) { + auto input = inputMapping.first; + auto inputName = sanatizeName(inputMapping.second); + QString deviceInputName{ "Controller." + deviceName + "." + inputName }; + engine->registerValue(deviceInputName, input.getID()); + } + } + // Controller.Hardware.* auto devices = DependencyManager::get()->getDevices(); for(const auto& deviceMapping : devices) { diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp index 5c51db9410..82f90fc5dc 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp @@ -10,13 +10,20 @@ // #include "UserInputMapper.h" +#include "StandardController.h" // Default contruct allocate the poutput size with the current hardcoded action channels UserInputMapper::UserInputMapper() { + registerStandardDevice(); assignDefaulActionScales(); createActionNames(); } +UserInputMapper::~UserInputMapper() { + delete _standardController; +} + + bool UserInputMapper::registerDevice(uint16 deviceID, const DeviceProxy::Pointer& proxy){ proxy->_name += " (" + QString::number(deviceID) + ")"; _registeredDevices[deviceID] = proxy; @@ -322,3 +329,11 @@ void UserInputMapper::createActionNames() { _actionNames[CONTEXT_MENU] = "CONTEXT_MENU"; _actionNames[TOGGLE_MUTE] = "TOGGLE_MUTE"; } + +void UserInputMapper::registerStandardDevice() { + _standardController = new StandardController; + _standardController->registerToUserInputMapper(*this); + + //mapper.registerDevice(_deviceID, proxy); + //_standardDevice = proxy; +} \ No newline at end of file diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.h b/libraries/input-plugins/src/input-plugins/UserInputMapper.h index 1ad4294e0c..8995d3544b 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.h +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.h @@ -19,13 +19,16 @@ #include #include #include - + +class StandardController; class UserInputMapper : public QObject, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY Q_ENUMS(Action) public: + ~UserInputMapper(); + typedef unsigned short uint16; typedef unsigned int uint32; @@ -123,6 +126,7 @@ public: // GetFreeDeviceID should be called before registering a device to use an ID not used by a different device. uint16 getFreeDeviceID() { return _nextFreeDeviceID++; } bool registerDevice(uint16 deviceID, const DeviceProxy::Pointer& device); + bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; return true; } DeviceProxy::Pointer getDeviceProxy(const Input& input); QString getDeviceName(uint16 deviceID); QVector getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); } @@ -238,11 +242,19 @@ public: typedef std::map DevicesMap; DevicesMap getDevices() { return _registeredDevices; } + uint16 getStandardDeviceID() const { return _standardDeviceID; } + DeviceProxy::Pointer getStandardDevice() { return _standardDevice; } + signals: void actionEvent(int action, float state); protected: + void registerStandardDevice(); + uint16 _standardDeviceID = 0; + DeviceProxy::Pointer _standardDevice; + StandardController* _standardController = nullptr; + DevicesMap _registeredDevices; uint16 _nextFreeDeviceID = 1; From 9667a103aa6295a36aaafd2bb62889c7732bbc2d Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 15:02:11 -0700 Subject: [PATCH 7/9] actually add new files --- .../src/input-plugins/StandardController.cpp | 156 ++++++++++++++++++ .../src/input-plugins/StandardController.h | 69 ++++++++ 2 files changed, 225 insertions(+) create mode 100644 libraries/input-plugins/src/input-plugins/StandardController.cpp create mode 100644 libraries/input-plugins/src/input-plugins/StandardController.h diff --git a/libraries/input-plugins/src/input-plugins/StandardController.cpp b/libraries/input-plugins/src/input-plugins/StandardController.cpp new file mode 100644 index 0000000000..ba5b5baa19 --- /dev/null +++ b/libraries/input-plugins/src/input-plugins/StandardController.cpp @@ -0,0 +1,156 @@ +// +// StandardController.cpp +// input-plugins/src/input-plugins +// +// Created by Stephen Birarda on 2014-09-23. +// 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 + +#include + +#include "StandardController.h" + +const float CONTROLLER_THRESHOLD = 0.3f; + +const float MAX_AXIS = 32768.0f; + +StandardController::~StandardController() { +} + +void StandardController::update(float deltaTime, bool jointsCaptured) { + for (auto axisState : _axisStateMap) { + if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) { + _axisStateMap[axisState.first] = 0.0f; + } + } +} + +void StandardController::focusOutEvent() { + _axisStateMap.clear(); + _buttonPressedMap.clear(); +}; + +void StandardController::registerToUserInputMapper(UserInputMapper& mapper) { + // Grab the current free device ID + _deviceID = mapper.getStandardDeviceID(); + + auto proxy = std::make_shared(_name); + proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); }; + proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); }; + proxy->getAvailabeInputs = [this] () -> QVector { + QVector availableInputs; + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_A), "Bottom Button")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_B), "Right Button")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_X), "Left Button")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_Y), "Top Button")); + + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_UP), "DPad Up")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_DOWN), "DPad Down")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_LEFT), "DPad Left")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT), "DPad Right")); + + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_LEFTSHOULDER), "L1")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), "R1")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_SHOULDER), "L2")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_SHOULDER), "R2")); + + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_Y_NEG), "Left Stick Up")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_Y_POS), "Left Stick Down")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_X_POS), "Left Stick Right")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_X_NEG), "Left Stick Left")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_Y_NEG), "Right Stick Up")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_Y_POS), "Right Stick Down")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_POS), "Right Stick Right")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_NEG), "Right Stick Left")); + + return availableInputs; + }; + proxy->resetDeviceBindings = [this, &mapper] () -> bool { + mapper.removeAllInputChannelsForDevice(_deviceID); + this->assignDefaultInputMapping(mapper); + return true; + }; + mapper.registerStandardDevice(proxy); +} + +void StandardController::assignDefaultInputMapping(UserInputMapper& mapper) { + const float JOYSTICK_MOVE_SPEED = 1.0f; + const float DPAD_MOVE_SPEED = 0.5f; + const float JOYSTICK_YAW_SPEED = 0.5f; + const float JOYSTICK_PITCH_SPEED = 0.25f; + const float BOOM_SPEED = 0.1f; + + // Y axes are flipped (up is negative) + // Left StandardController: Movement, strafing + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(LEFT_AXIS_Y_NEG), JOYSTICK_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(LEFT_AXIS_Y_POS), JOYSTICK_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(LEFT_AXIS_X_POS), JOYSTICK_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(LEFT_AXIS_X_NEG), JOYSTICK_MOVE_SPEED); + + // Right StandardController: Camera orientation + mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(RIGHT_AXIS_X_POS), JOYSTICK_YAW_SPEED); + mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(RIGHT_AXIS_X_NEG), JOYSTICK_YAW_SPEED); + mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(RIGHT_AXIS_Y_NEG), JOYSTICK_PITCH_SPEED); + mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(RIGHT_AXIS_Y_POS), JOYSTICK_PITCH_SPEED); + + // Dpad movement + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_UP), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_DOWN), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_LEFT), DPAD_MOVE_SPEED); + + // Button controls + mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(STANDARD_CONTROLLER_BUTTON_Y), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(STANDARD_CONTROLLER_BUTTON_X), DPAD_MOVE_SPEED); + + // Zoom + mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), BOOM_SPEED); + mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), BOOM_SPEED); + + + // Hold front right shoulder button for precision controls + // Left StandardController: Movement, strafing + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(LEFT_AXIS_Y_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(LEFT_AXIS_Y_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(LEFT_AXIS_X_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(LEFT_AXIS_X_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + + // Right StandardController: Camera orientation + mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(RIGHT_AXIS_X_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_YAW_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(RIGHT_AXIS_X_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_YAW_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(RIGHT_AXIS_Y_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_PITCH_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(RIGHT_AXIS_Y_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_PITCH_SPEED/2.0f); + + // Dpad movement + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_UP), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_DOWN), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_LEFT), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + + // Button controls + mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(STANDARD_CONTROLLER_BUTTON_Y), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(STANDARD_CONTROLLER_BUTTON_X), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + + // Zoom + mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); + + mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(STANDARD_CONTROLLER_BUTTON_LEFTSHOULDER)); + + mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(STANDARD_CONTROLLER_BUTTON_B)); + mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(STANDARD_CONTROLLER_BUTTON_A)); +} + +UserInputMapper::Input StandardController::makeInput(StandardController::StandardControllerButtonChannel button) { + return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON); +} + +UserInputMapper::Input StandardController::makeInput(StandardController::StandardControllerAxisChannel axis) { + return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS); +} + diff --git a/libraries/input-plugins/src/input-plugins/StandardController.h b/libraries/input-plugins/src/input-plugins/StandardController.h new file mode 100644 index 0000000000..ac89bca581 --- /dev/null +++ b/libraries/input-plugins/src/input-plugins/StandardController.h @@ -0,0 +1,69 @@ +// +// StandardController.h +// input-plugins/src/input-plugins +// +// Created by Stephen Birarda on 2014-09-23. +// 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 +// + +#ifndef hifi_StandardController_h +#define hifi_StandardController_h + +#include +#include + +#include "InputDevice.h" + +class StandardController : public QObject, public InputDevice { + Q_OBJECT + Q_PROPERTY(QString name READ getName) + +public: + enum StandardControllerAxisChannel { + LEFT_AXIS_X_POS = 0, + LEFT_AXIS_X_NEG, + LEFT_AXIS_Y_POS, + LEFT_AXIS_Y_NEG, + RIGHT_AXIS_X_POS, + RIGHT_AXIS_X_NEG, + RIGHT_AXIS_Y_POS, + RIGHT_AXIS_Y_NEG, + RIGHT_SHOULDER, + LEFT_SHOULDER, + }; + enum StandardControllerButtonChannel { + STANDARD_CONTROLLER_BUTTON_A = 0, + STANDARD_CONTROLLER_BUTTON_B, + STANDARD_CONTROLLER_BUTTON_X, + STANDARD_CONTROLLER_BUTTON_Y, + + STANDARD_CONTROLLER_BUTTON_DPAD_UP, + STANDARD_CONTROLLER_BUTTON_DPAD_DOWN, + STANDARD_CONTROLLER_BUTTON_DPAD_LEFT, + STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT, + + STANDARD_CONTROLLER_BUTTON_LEFTSHOULDER, + STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER, + }; + + const QString& getName() const { return _name; } + + // Device functions + virtual void registerToUserInputMapper(UserInputMapper& mapper) override; + virtual void assignDefaultInputMapping(UserInputMapper& mapper) override; + virtual void update(float deltaTime, bool jointsCaptured) override; + virtual void focusOutEvent() override; + + StandardController() : InputDevice("Standard") {} + ~StandardController(); + + UserInputMapper::Input makeInput(StandardController::StandardControllerButtonChannel button); + UserInputMapper::Input makeInput(StandardController::StandardControllerAxisChannel axis); + +private: +}; + +#endif // hifi_StandardController_h From 312bbf6167871c4020e52e5a27cab630df6fc8f0 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 15:15:20 -0700 Subject: [PATCH 8/9] CR feedback --- .../src/input-plugins/StandardController.cpp | 10 ++++++++-- .../src/input-plugins/StandardController.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/StandardController.cpp b/libraries/input-plugins/src/input-plugins/StandardController.cpp index ba5b5baa19..4fb4a23654 100644 --- a/libraries/input-plugins/src/input-plugins/StandardController.cpp +++ b/libraries/input-plugins/src/input-plugins/StandardController.cpp @@ -2,8 +2,8 @@ // StandardController.cpp // input-plugins/src/input-plugins // -// Created by Stephen Birarda on 2014-09-23. -// Copyright 2014 High Fidelity, Inc. +// Created by Brad Hefta-Gaub on 2015-10-11. +// 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 @@ -68,6 +68,9 @@ void StandardController::registerToUserInputMapper(UserInputMapper& mapper) { availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_POS), "Right Stick Right")); availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_NEG), "Right Stick Left")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_HAND), "Left Hand")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_HAND), "Right Hand")); + return availableInputs; }; proxy->resetDeviceBindings = [this, &mapper] () -> bool { @@ -154,3 +157,6 @@ UserInputMapper::Input StandardController::makeInput(StandardController::Standar return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS); } +UserInputMapper::Input StandardController::makeInput(StandardController::StandardControllerPoseChannel pose) { + return UserInputMapper::Input(_deviceID, pose, UserInputMapper::ChannelType::POSE); +} diff --git a/libraries/input-plugins/src/input-plugins/StandardController.h b/libraries/input-plugins/src/input-plugins/StandardController.h index ac89bca581..7f13b61783 100644 --- a/libraries/input-plugins/src/input-plugins/StandardController.h +++ b/libraries/input-plugins/src/input-plugins/StandardController.h @@ -2,8 +2,8 @@ // StandardController.h // input-plugins/src/input-plugins // -// Created by Stephen Birarda on 2014-09-23. -// Copyright 2014 High Fidelity, Inc. +// Created by Brad Hefta-Gaub on 2015-10-11. +// 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 @@ -49,6 +49,11 @@ public: STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER, }; + enum StandardControllerPoseChannel { + LEFT_HAND = 0, + RIGHT_HAND, + }; + const QString& getName() const { return _name; } // Device functions @@ -62,6 +67,7 @@ public: UserInputMapper::Input makeInput(StandardController::StandardControllerButtonChannel button); UserInputMapper::Input makeInput(StandardController::StandardControllerAxisChannel axis); + UserInputMapper::Input makeInput(StandardController::StandardControllerPoseChannel pose); private: }; From 21a473035e2b60d7f854f1abe432cf6e2cd7c586 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 15:37:17 -0700 Subject: [PATCH 9/9] more CR feedback --- .../input-plugins/src/input-plugins/StandardController.h | 2 ++ .../input-plugins/src/input-plugins/UserInputMapper.cpp | 6 +----- libraries/input-plugins/src/input-plugins/UserInputMapper.h | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/StandardController.h b/libraries/input-plugins/src/input-plugins/StandardController.h index 7f13b61783..f7a4215242 100644 --- a/libraries/input-plugins/src/input-plugins/StandardController.h +++ b/libraries/input-plugins/src/input-plugins/StandardController.h @@ -17,6 +17,8 @@ #include "InputDevice.h" +typedef std::shared_ptr StandardControllerPointer; + class StandardController : public QObject, public InputDevice { Q_OBJECT Q_PROPERTY(QString name READ getName) diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp index 82f90fc5dc..fad962345c 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp @@ -20,7 +20,6 @@ UserInputMapper::UserInputMapper() { } UserInputMapper::~UserInputMapper() { - delete _standardController; } @@ -331,9 +330,6 @@ void UserInputMapper::createActionNames() { } void UserInputMapper::registerStandardDevice() { - _standardController = new StandardController; + _standardController = std::make_shared(); _standardController->registerToUserInputMapper(*this); - - //mapper.registerDevice(_deviceID, proxy); - //_standardDevice = proxy; } \ No newline at end of file diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.h b/libraries/input-plugins/src/input-plugins/UserInputMapper.h index 8995d3544b..1d64638ee1 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.h +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.h @@ -21,6 +21,7 @@ #include class StandardController; +typedef std::shared_ptr StandardControllerPointer; class UserInputMapper : public QObject, public Dependency { Q_OBJECT @@ -253,7 +254,7 @@ protected: void registerStandardDevice(); uint16 _standardDeviceID = 0; DeviceProxy::Pointer _standardDevice; - StandardController* _standardController = nullptr; + StandardControllerPointer _standardController; DevicesMap _registeredDevices; uint16 _nextFreeDeviceID = 1;