mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
commit
2c27d18922
7 changed files with 76 additions and 32 deletions
|
@ -18,12 +18,19 @@ macro(COPY_DLLS_BESIDE_WINDOWS_EXECUTABLE)
|
||||||
@ONLY
|
@ONLY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (APPLE)
|
||||||
|
set(PLUGIN_PATH "interface.app/Contents/MacOS/plugins")
|
||||||
|
else()
|
||||||
|
set(PLUGIN_PATH "plugins")
|
||||||
|
endif()
|
||||||
|
|
||||||
# add a post-build command to copy DLLs beside the executable
|
# add a post-build command to copy DLLs beside the executable
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ${TARGET_NAME}
|
TARGET ${TARGET_NAME}
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DBUNDLE_EXECUTABLE=$<TARGET_FILE:${TARGET_NAME}>
|
-DBUNDLE_EXECUTABLE=$<TARGET_FILE:${TARGET_NAME}>
|
||||||
|
-DBUNDLE_PLUGIN_DIR=$<TARGET_FILE_DIR:${TARGET_NAME}>/${PLUGIN_PATH}
|
||||||
-P ${CMAKE_CURRENT_BINARY_DIR}/FixupBundlePostBuild.cmake
|
-P ${CMAKE_CURRENT_BINARY_DIR}/FixupBundlePostBuild.cmake
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -41,4 +41,16 @@ function(copy_resolved_item_into_bundle resolved_item resolved_embedded_item)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
message(STATUS "FIXUP_LIBS for fixup_bundle called for bundle ${BUNDLE_EXECUTABLE} are @FIXUP_LIBS@")
|
message(STATUS "FIXUP_LIBS for fixup_bundle called for bundle ${BUNDLE_EXECUTABLE} are @FIXUP_LIBS@")
|
||||||
fixup_bundle("${BUNDLE_EXECUTABLE}" "" "@FIXUP_LIBS@")
|
|
||||||
|
message(STATUS "Scanning for plugins from ${BUNDLE_PLUGIN_DIR}")
|
||||||
|
|
||||||
|
if (APPLE)
|
||||||
|
set(PLUGIN_EXTENSION "dylib")
|
||||||
|
elseif (WIN32)
|
||||||
|
set(PLUGIN_EXTENSION "dll")
|
||||||
|
else()
|
||||||
|
set(PLUGIN_EXTENSION "so")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(GLOB RUNTIME_PLUGINS "${BUNDLE_PLUGIN_DIR}/*.${PLUGIN_EXTENSION}")
|
||||||
|
fixup_bundle("${BUNDLE_EXECUTABLE}" "${RUNTIME_PLUGINS}" "@FIXUP_LIBS@")
|
|
@ -44,22 +44,11 @@
|
||||||
|
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
|
||||||
Menu* Menu::_instance = NULL;
|
static const char* const MENU_PROPERTY_NAME = "com.highfidelity.Menu";
|
||||||
|
|
||||||
Menu* Menu::getInstance() {
|
Menu* Menu::getInstance() {
|
||||||
static QMutex menuInstanceMutex;
|
static Menu* instance = globalInstance<Menu>(MENU_PROPERTY_NAME);
|
||||||
|
return instance;
|
||||||
// lock the menu instance mutex to make sure we don't race and create two menus and crash
|
|
||||||
menuInstanceMutex.lock();
|
|
||||||
|
|
||||||
if (!_instance) {
|
|
||||||
qCDebug(interfaceapp, "First call to Menu::getInstance() - initing menu.");
|
|
||||||
_instance = new Menu();
|
|
||||||
}
|
|
||||||
|
|
||||||
menuInstanceMutex.unlock();
|
|
||||||
|
|
||||||
return _instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::Menu() {
|
Menu::Menu() {
|
||||||
|
|
|
@ -57,6 +57,7 @@ private:
|
||||||
class Menu : public QMenuBar {
|
class Menu : public QMenuBar {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
Menu();
|
||||||
static Menu* getInstance();
|
static Menu* getInstance();
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
|
@ -103,9 +104,6 @@ public slots:
|
||||||
void setIsOptionChecked(const QString& menuOption, bool isChecked);
|
void setIsOptionChecked(const QString& menuOption, bool isChecked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Menu* _instance;
|
|
||||||
Menu();
|
|
||||||
|
|
||||||
typedef void(*settingsAction)(Settings&, QAction&);
|
typedef void(*settingsAction)(Settings&, QAction&);
|
||||||
static void loadAction(Settings& settings, QAction& action);
|
static void loadAction(Settings& settings, QAction& action);
|
||||||
static void saveAction(Settings& settings, QAction& action);
|
static void saveAction(Settings& settings, QAction& action);
|
||||||
|
|
|
@ -11,8 +11,16 @@
|
||||||
|
|
||||||
#include "DependencyManager.h"
|
#include "DependencyManager.h"
|
||||||
|
|
||||||
DependencyManager DependencyManager::_manager;
|
#include "SharedUtil.h"
|
||||||
|
#include "Finally.h"
|
||||||
|
|
||||||
|
static const char* const DEPENDENCY_PROPERTY_NAME = "com.highfidelity.DependencyMananger";
|
||||||
|
|
||||||
|
DependencyManager& DependencyManager::manager() {
|
||||||
|
static DependencyManager* instance = globalInstance<DependencyManager>(DEPENDENCY_PROPERTY_NAME);
|
||||||
|
return *instance;
|
||||||
|
}
|
||||||
|
|
||||||
QSharedPointer<Dependency>& DependencyManager::safeGet(size_t hashCode) {
|
QSharedPointer<Dependency>& DependencyManager::safeGet(size_t hashCode) {
|
||||||
return _instanceHash[hashCode];
|
return _instanceHash[hashCode];
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,8 @@ public:
|
||||||
static void registerInheritance();
|
static void registerInheritance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static DependencyManager _manager;
|
static DependencyManager& manager();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
size_t getHashCode();
|
size_t getHashCode();
|
||||||
|
|
||||||
|
@ -75,11 +75,11 @@ private:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QSharedPointer<T> DependencyManager::get() {
|
QSharedPointer<T> DependencyManager::get() {
|
||||||
static size_t hashCode = _manager.getHashCode<T>();
|
static size_t hashCode = manager().getHashCode<T>();
|
||||||
static QWeakPointer<T> instance;
|
static QWeakPointer<T> instance;
|
||||||
|
|
||||||
if (instance.isNull()) {
|
if (instance.isNull()) {
|
||||||
instance = qSharedPointerCast<T>(_manager.safeGet(hashCode));
|
instance = qSharedPointerCast<T>(manager().safeGet(hashCode));
|
||||||
|
|
||||||
if (instance.isNull()) {
|
if (instance.isNull()) {
|
||||||
qWarning() << "DependencyManager::get(): No instance available for" << typeid(T).name();
|
qWarning() << "DependencyManager::get(): No instance available for" << typeid(T).name();
|
||||||
|
@ -91,9 +91,9 @@ QSharedPointer<T> DependencyManager::get() {
|
||||||
|
|
||||||
template <typename T, typename ...Args>
|
template <typename T, typename ...Args>
|
||||||
QSharedPointer<T> DependencyManager::set(Args&&... args) {
|
QSharedPointer<T> DependencyManager::set(Args&&... args) {
|
||||||
static size_t hashCode = _manager.getHashCode<T>();
|
static size_t hashCode = manager().getHashCode<T>();
|
||||||
|
|
||||||
QSharedPointer<Dependency>& instance = _manager.safeGet(hashCode);
|
QSharedPointer<Dependency>& instance = manager().safeGet(hashCode);
|
||||||
instance.clear(); // Clear instance before creation of new one to avoid edge cases
|
instance.clear(); // Clear instance before creation of new one to avoid edge cases
|
||||||
QSharedPointer<T> newInstance(new T(args...), &T::customDeleter);
|
QSharedPointer<T> newInstance(new T(args...), &T::customDeleter);
|
||||||
QSharedPointer<Dependency> storedInstance = qSharedPointerCast<Dependency>(newInstance);
|
QSharedPointer<Dependency> storedInstance = qSharedPointerCast<Dependency>(newInstance);
|
||||||
|
@ -104,9 +104,9 @@ QSharedPointer<T> DependencyManager::set(Args&&... args) {
|
||||||
|
|
||||||
template <typename T, typename I, typename ...Args>
|
template <typename T, typename I, typename ...Args>
|
||||||
QSharedPointer<T> DependencyManager::set(Args&&... args) {
|
QSharedPointer<T> DependencyManager::set(Args&&... args) {
|
||||||
static size_t hashCode = _manager.getHashCode<T>();
|
static size_t hashCode = manager().getHashCode<T>();
|
||||||
|
|
||||||
QSharedPointer<Dependency>& instance = _manager.safeGet(hashCode);
|
QSharedPointer<Dependency>& instance = manager().safeGet(hashCode);
|
||||||
instance.clear(); // Clear instance before creation of new one to avoid edge cases
|
instance.clear(); // Clear instance before creation of new one to avoid edge cases
|
||||||
QSharedPointer<T> newInstance(new I(args...), &I::customDeleter);
|
QSharedPointer<T> newInstance(new I(args...), &I::customDeleter);
|
||||||
QSharedPointer<Dependency> storedInstance = qSharedPointerCast<Dependency>(newInstance);
|
QSharedPointer<Dependency> storedInstance = qSharedPointerCast<Dependency>(newInstance);
|
||||||
|
@ -117,15 +117,15 @@ QSharedPointer<T> DependencyManager::set(Args&&... args) {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void DependencyManager::destroy() {
|
void DependencyManager::destroy() {
|
||||||
static size_t hashCode = _manager.getHashCode<T>();
|
static size_t hashCode = manager().getHashCode<T>();
|
||||||
_manager.safeGet(hashCode).clear();
|
manager().safeGet(hashCode).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Base, typename Derived>
|
template<typename Base, typename Derived>
|
||||||
void DependencyManager::registerInheritance() {
|
void DependencyManager::registerInheritance() {
|
||||||
size_t baseHashCode = typeid(Base).hash_code();
|
size_t baseHashCode = typeid(Base).hash_code();
|
||||||
size_t derivedHashCode = typeid(Derived).hash_code();
|
size_t derivedHashCode = typeid(Derived).hash_code();
|
||||||
_manager._inheritanceHash.insert(baseHashCode, derivedHashCode);
|
manager()._inheritanceHash.insert(baseHashCode, derivedHashCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define hifi_SharedUtil_h
|
#define hifi_SharedUtil_h
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -20,7 +21,36 @@
|
||||||
#include <unistd.h> // not on windows, not needed for mac or windows
|
#include <unistd.h> // not on windows, not needed for mac or windows
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
|
// Provides efficient access to a named global type. By storing the value
|
||||||
|
// in the QApplication by name we can implement the singleton pattern and
|
||||||
|
// have the single instance function across DLL boundaries.
|
||||||
|
template <typename T, typename... Args>
|
||||||
|
T* globalInstance(const char* propertyName, Args&&... args) {
|
||||||
|
static std::unique_ptr<T> instancePtr;
|
||||||
|
static T* resultInstance { nullptr };
|
||||||
|
static std::mutex mutex;
|
||||||
|
if (!resultInstance) {
|
||||||
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
|
if (!resultInstance) {
|
||||||
|
auto variant = qApp->property(propertyName);
|
||||||
|
if (variant.isNull()) {
|
||||||
|
// Since we're building the object, store it in a shared_ptr so it's
|
||||||
|
// destroyed by the destructor of the static instancePtr
|
||||||
|
instancePtr = std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||||
|
|
||||||
|
void* voidInstance = &(*instancePtr);
|
||||||
|
variant = QVariant::fromValue(voidInstance);
|
||||||
|
qApp->setProperty(propertyName, variant);
|
||||||
|
}
|
||||||
|
void* returnedVoidInstance = variant.value<void*>();
|
||||||
|
resultInstance = static_cast<T*>(returnedVoidInstance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultInstance;
|
||||||
|
}
|
||||||
|
|
||||||
const int BYTES_PER_COLOR = 3;
|
const int BYTES_PER_COLOR = 3;
|
||||||
const int BYTES_PER_FLAGS = 1;
|
const int BYTES_PER_FLAGS = 1;
|
||||||
|
|
Loading…
Reference in a new issue