From ecfc2ff5d0fff615f6b1632e3b328d6c678fbc92 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 11 Sep 2014 23:12:38 +0200 Subject: [PATCH] Add a MyGUI plugin to register OpenMW resources, to use with MyGUI's standalone tools --- CMakeLists.txt | 52 +++++++++----- components/CMakeLists.txt | 6 ++ libs/mygui_resource_plugin/CMakeLists.txt | 24 +++++++ libs/mygui_resource_plugin/plugin.cpp | 75 ++++++++++++++++++++ libs/mygui_resource_plugin/plugin.hpp | 37 ++++++++++ libs/mygui_resource_plugin/plugin_export.cpp | 17 +++++ 6 files changed, 192 insertions(+), 19 deletions(-) create mode 100644 libs/mygui_resource_plugin/CMakeLists.txt create mode 100644 libs/mygui_resource_plugin/plugin.cpp create mode 100644 libs/mygui_resource_plugin/plugin.hpp create mode 100644 libs/mygui_resource_plugin/plugin_export.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 47575e0ce..c6ceaa668 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ option(BUILD_OPENCS "build OpenMW Construction Set" ON) option(BUILD_WITH_CODE_COVERAGE "Enable code coverage with gconv" OFF) option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest ang GMock frameworks" OFF) option(BUILD_NIFTEST "build nif file tester" OFF) +option(BUILD_MYGUI_PLUGIN "build MyGUI plugin for OpenMW resources, to use with MyGUI tools" ON) # OS X deployment option(OPENMW_OSX_DEPLOYMENT OFF) @@ -103,32 +104,32 @@ cmake_minimum_required(VERSION 2.6) # source directory: libs -set(LIBDIR ${CMAKE_SOURCE_DIR}/libs) +set(LIBS_DIR ${CMAKE_SOURCE_DIR}/libs) set(OENGINE_OGRE - ${LIBDIR}/openengine/ogre/renderer.cpp - ${LIBDIR}/openengine/ogre/lights.cpp - ${LIBDIR}/openengine/ogre/selectionbuffer.cpp - ${LIBDIR}/openengine/ogre/imagerotate.cpp + ${LIBS_DIR}/openengine/ogre/renderer.cpp + ${LIBS_DIR}/openengine/ogre/lights.cpp + ${LIBS_DIR}/openengine/ogre/selectionbuffer.cpp + ${LIBS_DIR}/openengine/ogre/imagerotate.cpp ) set(OENGINE_GUI - ${LIBDIR}/openengine/gui/loglistener.cpp - ${LIBDIR}/openengine/gui/manager.cpp - ${LIBDIR}/openengine/gui/layout.hpp + ${LIBS_DIR}/openengine/gui/loglistener.cpp + ${LIBS_DIR}/openengine/gui/manager.cpp + ${LIBS_DIR}/openengine/gui/layout.hpp ) set(OENGINE_BULLET - ${LIBDIR}/openengine/bullet/BtOgre.cpp - ${LIBDIR}/openengine/bullet/BtOgreExtras.h - ${LIBDIR}/openengine/bullet/BtOgreGP.h - ${LIBDIR}/openengine/bullet/BtOgrePG.h - ${LIBDIR}/openengine/bullet/physic.cpp - ${LIBDIR}/openengine/bullet/physic.hpp - ${LIBDIR}/openengine/bullet/BulletShapeLoader.cpp - ${LIBDIR}/openengine/bullet/BulletShapeLoader.h - ${LIBDIR}/openengine/bullet/trace.cpp - ${LIBDIR}/openengine/bullet/trace.h + ${LIBS_DIR}/openengine/bullet/BtOgre.cpp + ${LIBS_DIR}/openengine/bullet/BtOgreExtras.h + ${LIBS_DIR}/openengine/bullet/BtOgreGP.h + ${LIBS_DIR}/openengine/bullet/BtOgrePG.h + ${LIBS_DIR}/openengine/bullet/physic.cpp + ${LIBS_DIR}/openengine/bullet/physic.hpp + ${LIBS_DIR}/openengine/bullet/BulletShapeLoader.cpp + ${LIBS_DIR}/openengine/bullet/BulletShapeLoader.h + ${LIBS_DIR}/openengine/bullet/trace.cpp + ${LIBS_DIR}/openengine/bullet/trace.h ) @@ -261,7 +262,7 @@ include_directories("." ${MYGUI_INCLUDE_DIRS} ${MYGUI_PLATFORM_INCLUDE_DIRS} ${OPENAL_INCLUDE_DIR} - ${LIBDIR} + ${LIBS_DIR} ) link_directories(${SDL2_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR} ${MYGUI_LIB_DIR}) @@ -333,8 +334,10 @@ add_subdirectory(files/mygui) if (APPLE) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${APP_BUNDLE_DIR}/Contents/MacOS") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${APP_BUNDLE_DIR}/Contents/MacOS") else (APPLE) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OpenMW_BINARY_DIR}") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OpenMW_BINARY_DIR}") endif (APPLE) # Other files @@ -379,6 +382,7 @@ IF(NOT WIN32 AND NOT APPLE) # Linux building # Paths SET(BINDIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Where to install binaries") + SET(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Where to install libraries") SET(DATAROOTDIR "${CMAKE_INSTALL_PREFIX}/share" CACHE PATH "Sets the root of data directories to a non-default location") SET(DATADIR "${DATAROOTDIR}/games/openmw" CACHE PATH "Sets the openmw data directories to a non-default location") SET(ICONDIR "${DATAROOTDIR}/pixmaps" CACHE PATH "Set icon dir") @@ -405,6 +409,9 @@ IF(NOT WIN32 AND NOT APPLE) IF(BUILD_NIFTEST) INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/niftest" DESTINATION "${BINDIR}" ) ENDIF(BUILD_NIFTEST) + if(BUILD_MYGUI_PLUGIN) + INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/Plugin_MyGUI_OpenMW_Resources.so" DESTINATION "${LIBDIR}" ) + ENDIF(BUILD_MYGUI_PLUGIN) # Install licenses INSTALL(FILES "docs/license/DejaVu Font License.txt" DESTINATION "${LICDIR}" ) @@ -454,6 +461,9 @@ if(WIN32) INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/Release/opencs.exe" DESTINATION ".") INSTALL(FILES "${OpenMW_BINARY_DIR}/opencs.ini" DESTINATION ".") ENDIF(BUILD_OPENCS) + if(BUILD_MYGUI_PLUGIN) + INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/Release/Plugin_MyGUI_OpenMW_Resources.dll" DESTINATION ".") + ENDIF(BUILD_MYGUI_PLUGIN) INSTALL(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION ".") @@ -521,6 +531,10 @@ add_subdirectory (extern/sdl4ogre) # Components add_subdirectory (components) +if (BUILD_MYGUI_PLUGIN) + add_subdirectory(libs/mygui_resource_plugin) +endif() + #Testing if (BUILD_NIFTEST) add_subdirectory(components/nif/tests/) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 1c3f442c2..beeadadbe 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -112,6 +112,12 @@ if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) QT4_WRAP_CPP(MOC_SRCS ${COMPONENT_MOC_FILES}) endif(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) +if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE) + add_definitions(-fPIC) + endif() +endif () + include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR}) diff --git a/libs/mygui_resource_plugin/CMakeLists.txt b/libs/mygui_resource_plugin/CMakeLists.txt new file mode 100644 index 000000000..7288fd4b6 --- /dev/null +++ b/libs/mygui_resource_plugin/CMakeLists.txt @@ -0,0 +1,24 @@ +set (MYGUI_RESOURCE_PLUGIN_SOURCES + plugin.hpp + plugin.cpp + plugin_export.cpp +) + +set (MYGUI_RESOURCE_PLUGIN_LIBRARY + Plugin_MyGUI_OpenMW_Resources +) + +add_definitions("-D_USRDLL -DMYGUI_BUILD_DLL") + +add_library(${MYGUI_RESOURCE_PLUGIN_LIBRARY} + SHARED + ${MYGUI_RESOURCE_PLUGIN_SOURCES} + ) + +set_target_properties(${MYGUI_RESOURCE_PLUGIN_LIBRARY} PROPERTIES PREFIX "") + +target_link_libraries(${MYGUI_RESOURCE_PLUGIN_LIBRARY} + ${OGRE_LIBRARIES} + ${MYGUI_LIBRARIES} + components +) diff --git a/libs/mygui_resource_plugin/plugin.cpp b/libs/mygui_resource_plugin/plugin.cpp new file mode 100644 index 000000000..24ecf6557 --- /dev/null +++ b/libs/mygui_resource_plugin/plugin.cpp @@ -0,0 +1,75 @@ +#include "plugin.hpp" + +#include + +#include +#include + +namespace MyGUI +{ + + const std::string& ResourcePlugin::getName() const + { + static const std::string name = "OpenMW resource plugin"; + return name; + } + + void ResourcePlugin::install() + { + + } + void ResourcePlugin::uninstall() + { + + } + + void ResourcePlugin::initialize() + { + MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "initialize"); + + boost::program_options::variables_map variables; + + boost::program_options::options_description desc("Allowed options"); + desc.add_options() + ("data", boost::program_options::value()->default_value(Files::PathContainer(), "data")->multitoken()) + ("data-local", boost::program_options::value()->default_value("")) + ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) + ("fallback-archive", boost::program_options::value >()-> + default_value(std::vector(), "fallback-archive")->multitoken()); + + boost::program_options::notify(variables); + + Files::ConfigurationManager cfgManager; + cfgManager.readConfiguration(variables, desc); + + std::vector archives = variables["fallback-archive"].as >(); + bool fsStrict = variables["fs-strict"].as(); + + Files::PathContainer dataDirs, dataLocal; + if (!variables["data"].empty()) { + dataDirs = Files::PathContainer(variables["data"].as()); + } + + std::string local = variables["data-local"].as(); + if (!local.empty()) { + dataLocal.push_back(Files::PathContainer::value_type(local)); + } + + cfgManager.processPaths (dataDirs); + cfgManager.processPaths (dataLocal, true); + + if (!dataLocal.empty()) + dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end()); + + Files::Collections collections (dataDirs, !fsStrict); + + Bsa::registerResources(collections, archives, true, fsStrict); + } + + void ResourcePlugin::shutdown() + { + /// \todo remove resource groups + MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "shutdown"); + } + +} diff --git a/libs/mygui_resource_plugin/plugin.hpp b/libs/mygui_resource_plugin/plugin.hpp new file mode 100644 index 000000000..5203b80ba --- /dev/null +++ b/libs/mygui_resource_plugin/plugin.hpp @@ -0,0 +1,37 @@ +#ifndef OPENMW_MYGUI_RESOURCE_PLUGIN_H +#define OPENMW_MYGUI_RESOURCE_PLUGIN_H + +#include + +namespace MyGUI +{ + + class ResourcePlugin : public MyGUI::IPlugin + { + /*! Get the name of the plugin. + @remarks An implementation must be supplied for this method to uniquely + identify the plugin + */ + virtual const std::string& getName() const; + + /*! Perform the plugin initial installation sequence + */ + virtual void install(); + + /*! Perform any tasks the plugin needs to perform on full system + initialisation. + */ + virtual void initialize(); + + /*! Perform any tasks the plugin needs to perform when the system is shut down + */ + virtual void shutdown(); + + /*! Perform the final plugin uninstallation sequence + */ + virtual void uninstall(); + }; + +} + +#endif diff --git a/libs/mygui_resource_plugin/plugin_export.cpp b/libs/mygui_resource_plugin/plugin_export.cpp new file mode 100644 index 000000000..3ca1152f3 --- /dev/null +++ b/libs/mygui_resource_plugin/plugin_export.cpp @@ -0,0 +1,17 @@ +#include "plugin.hpp" +#include "MyGUI_PluginManager.h" + +MyGUI::ResourcePlugin* plugin_item = nullptr; + +extern "C" MYGUI_EXPORT_DLL void dllStartPlugin(void) +{ + plugin_item = new MyGUI::ResourcePlugin(); + MyGUI::PluginManager::getInstance().installPlugin(plugin_item); +} + +extern "C" MYGUI_EXPORT_DLL void dllStopPlugin(void) +{ + MyGUI::PluginManager::getInstance().uninstallPlugin(plugin_item); + delete plugin_item; + plugin_item = nullptr; +}