From 37e272b3b5e18d1a93a1d69804a96845f8762ba1 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 13 Jan 2012 20:41:38 +0100 Subject: [PATCH 01/45] Issue #178 - workaround for compilation problems with ogre 1.8.0. --- components/bsa/bsa_archive.cpp | 6 ++++++ extern/caelum/src/CaelumPlugin.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 2178be318e..87b46b34c4 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -221,6 +221,12 @@ class BSAArchive : public Archive { BSAFile arc; + FileInfoListPtr findFileInfo(const String&, bool, bool) const + { + static FileInfoListPtr filp(new FileInfoList()); + return filp; + } + public: BSAArchive(const String& name) : Archive(name, "BSA") diff --git a/extern/caelum/src/CaelumPlugin.cpp b/extern/caelum/src/CaelumPlugin.cpp index 288ad9220a..340a26559a 100644 --- a/extern/caelum/src/CaelumPlugin.cpp +++ b/extern/caelum/src/CaelumPlugin.cpp @@ -21,17 +21,17 @@ along with Caelum. If not, see . #include "CaelumPrecompiled.h" #include "CaelumPlugin.h" -template<> Caelum::CaelumPlugin* Ogre::Singleton::ms_Singleton = 0; +template<> Caelum::CaelumPlugin* Ogre::Singleton::msSingleton = 0; namespace Caelum { CaelumPlugin* CaelumPlugin::getSingletonPtr () { - return ms_Singleton; + return msSingleton; } CaelumPlugin& CaelumPlugin::getSingleton () { - assert (ms_Singleton); - return *ms_Singleton; + assert (msSingleton); + return *msSingleton; } extern "C" void CAELUM_EXPORT dllStartPlugin () { From 96ed96d4dd432b3ee78c081575f888d0692c78c5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Mon, 16 Jan 2012 23:09:25 +0100 Subject: [PATCH 02/45] Quick test at getting Morrowinds install path from the registry on windows --- components/files/path.hpp | 2 +- components/files/windowspath.cpp | 37 +++++++++++++++++++++++++++++++- components/files/windowspath.hpp | 7 ++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/components/files/path.hpp b/components/files/path.hpp index 0788cefb15..5a4cf337b6 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -30,7 +30,7 @@ #include namespace Files { typedef LinuxPath TargetPathType; } -#elif defined(__WIN32) || defined(__WINDOWS__) +#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WINDOWS) #include namespace Files { typedef WindowsPath TargetPathType; } diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index f42f149c14..5c87eba92c 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -5,7 +5,10 @@ #include #include -#include +#include +#include + +#pragma comment(lib, "Shlwapi.lib") namespace Files { @@ -67,6 +70,38 @@ boost::filesystem::path WindowsPath::getRuntimeDataPath() const return boost::filesystem::path("./data/"); } +boost::filesystem::path WindowsPath::getInstallPath() const +{ + boost::filesystem::path installPath(""); + + HKEY hKey; + + BOOL f64 = FALSE; + LPCTSTR regkey; + if (IsWow64Process(GetCurrentProcess(), &f64) && f64) + { + regkey = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\Morrowind"; + } + else + { + regkey = "SOFTWARE\\Bethesda Softworks\\Morrowind"; + } + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(regkey), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) + { + //Key existed, let's try to read the install dir + char* data = new char[4096]; + int len = 4096; + + if (RegQueryValueEx(hKey, TEXT("Installed Path"), NULL, NULL, (LPBYTE)data, (LPDWORD)&len) == ERROR_SUCCESS) + { + installPath = data; + } + } + + return installPath; +} + } /* namespace Files */ #endif /* defined(_WIN32) || defined(__WINDOWS__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 47dfc08d8e..4550fc05ff 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -81,6 +81,13 @@ struct WindowsPath * \return boost::filesystem::path */ boost::filesystem::path getRuntimeDataPath() const; + + /** + * \brief Gets the path of the installed Morrowind version if there is one. + * + * \return boost::filesystem::path + */ + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ From 8663177ad175d549ef9d08c26e9e740d10d2b73e Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Mon, 16 Jan 2012 23:21:13 +0100 Subject: [PATCH 03/45] Oops, forgot the delete... --- components/files/windowspath.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 5c87eba92c..d838772325 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -97,6 +97,8 @@ boost::filesystem::path WindowsPath::getInstallPath() const { installPath = data; } + + delete[] data; } return installPath; From b4174b64195ddf6d03ded66dd574d80879c30708 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Tue, 17 Jan 2012 09:02:45 +0100 Subject: [PATCH 04/45] Vector instead of new/delete --- components/files/windowspath.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index d838772325..4fa70980ef 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -90,15 +90,13 @@ boost::filesystem::path WindowsPath::getInstallPath() const if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(regkey), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) { //Key existed, let's try to read the install dir - char* data = new char[4096]; - int len = 4096; + std::vector buf(512); + int len = 512; - if (RegQueryValueEx(hKey, TEXT("Installed Path"), NULL, NULL, (LPBYTE)data, (LPDWORD)&len) == ERROR_SUCCESS) + if (RegQueryValueEx(hKey, TEXT("Installed Path"), NULL, NULL, (LPBYTE)&buf[0], (LPDWORD)&len) == ERROR_SUCCESS) { - installPath = data; + installPath = &buf[0]; } - - delete[] data; } return installPath; From 16c214a17af6c4506d89bad139a4d66e7423f180 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 17 Jan 2012 19:18:17 +0100 Subject: [PATCH 05/45] find InstalledPath in wine registry; mInstalledPath in Files::Path --- components/files/linuxpath.cpp | 70 ++++++++++++++++++++++++++++++++++ components/files/linuxpath.hpp | 8 ++++ components/files/path.hpp | 22 +++++++++++ 3 files changed, 100 insertions(+) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index c485002fdb..b11f273057 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -154,6 +154,76 @@ boost::filesystem::path LinuxPath::getRuntimeDataPath() const return boost::filesystem::path("./data/"); } +boost::filesystem::path LinuxPath::getInstallPath() const +{ + char *homePath = getenv("HOME"); + if(!homePath) + { + return boost::filesystem::path(""); + } + + boost::filesystem::path wineDefaultRegistry(homePath); + wineDefaultRegistry /= ".wine/system.reg"; + + boost::filesystem::path wineDriveC(homePath); + wineDriveC /= ".wine/drive_c"; + + boost::filesystem::file_status fileStatus = boost::filesystem::status(wineDefaultRegistry); + boost::filesystem::file_status dirStatus = boost::filesystem::status(wineDriveC); + if(!boost::filesystem::is_regular_file(fileStatus) || !boost::filesystem::is_directory(dirStatus)) + { + return boost::filesystem::path(""); + } + + + boost::filesystem::ifstream file(wineDefaultRegistry); + bool isRegEntry = false; + std::string line; + int startPos, pos; + + while (std::getline(file, line)) + { + if(line.length() > 0 && line[0] == '[') // we found an entry + { + std::string regkey = line.substr(1, line.find(']')-1); + if( regkey.compare("SOFTWARE\\\\Wow6432Node\\\\Bethesda Softworks\\\\Morrowind") == 0 + || regkey.compare("SOFTWARE\\\\Bethesda Softworks\\\\Morrowind") == 0 ) + { + isRegEntry = true; + } + } + else if(isRegEntry) + { + if(line.length() == 0 || line[0] != '"') // empty line means new registry key + { + break; + } + std::string key = line.substr(1, line.find('"', 1)-1); + if(key.compare("Installed Path") == 0) { + startPos = line.find('=')+2; + std::string installPath = line.substr(startPos, line.find('"', startPos+1)-startPos); + installPath.replace(0, 2, wineDriveC.string()); + + pos = -1; + do + { + pos = static_cast(installPath.find("\\\\", pos+1)); + if(static_cast(pos) == std::string::npos) + { + break; + } + + installPath.replace(pos, 2, "/"); + } while(true); + + return boost::filesystem::path(installPath); + } + } + } + + return boost::filesystem::path(""); +} + } /* namespace Files */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index d6e717fc44..62cf93664f 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -26,6 +26,7 @@ #if defined(__linux__) #include +#include /** * \namespace Files @@ -81,6 +82,13 @@ struct LinuxPath * \return boost::filesystem::path */ boost::filesystem::path getRuntimeDataPath() const; + + /** + * \brief Gets the path of the installed Morrowind version if there is one. + * + * \return boost::filesystem::path + */ + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ diff --git a/components/files/path.hpp b/components/files/path.hpp index 5a4cf337b6..5139d9f78a 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -76,6 +76,7 @@ struct Path , mLocalDataPath(mPath.getLocalDataPath()) , mGlobalDataPath(mPath.getGlobalDataPath()) , mRuntimeDataPath(mPath.getRuntimeDataPath()) + , mInstalledPath(mPath.getInstallPath()) { if (!application_name.empty()) { @@ -209,6 +210,26 @@ struct Path mRuntimeDataPath = path; } + /** + * \brief Return path pointing to the directory where application was started. + * + * \return boost::filesystem::path + */ + const boost::filesystem::path& getInstalledPath() const + { + return mInstalledPath; + } + + /** + * \brief Sets new runtime data directory. + * + * \param [in] path - New path + */ + void setInstalledPath(const boost::filesystem::path& path) + { + mInstalledPath = path; + } + private: PathType mPath; @@ -223,6 +244,7 @@ struct Path boost::filesystem::path mRuntimeDataPath; /**< Runtime path to the configuration files. By default it is a 'data' directory in same directory where application was run */ + boost::filesystem::path mInstalledPath; /**< Runtime path to the configuration files. */ }; From 62eaaab69d607c11ae7eb645fe5df56243505383 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 17 Jan 2012 23:19:17 +0100 Subject: [PATCH 06/45] move include from .hpp to .cpp; line.empty() instead of line.size() > 0; change type of startPos and pos and move to other scope --- components/files/linuxpath.cpp | 12 +++++++----- components/files/linuxpath.hpp | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index b11f273057..5ca0856f1c 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -28,6 +28,7 @@ #include #include #include +#include /** * \namespace Files @@ -179,11 +180,10 @@ boost::filesystem::path LinuxPath::getInstallPath() const boost::filesystem::ifstream file(wineDefaultRegistry); bool isRegEntry = false; std::string line; - int startPos, pos; while (std::getline(file, line)) { - if(line.length() > 0 && line[0] == '[') // we found an entry + if(!line.empty() && line[0] == '[') // we found an entry { std::string regkey = line.substr(1, line.find(']')-1); if( regkey.compare("SOFTWARE\\\\Wow6432Node\\\\Bethesda Softworks\\\\Morrowind") == 0 @@ -194,12 +194,14 @@ boost::filesystem::path LinuxPath::getInstallPath() const } else if(isRegEntry) { - if(line.length() == 0 || line[0] != '"') // empty line means new registry key + if(line.empty() || line[0] != '"') // empty line means new registry key { break; } std::string key = line.substr(1, line.find('"', 1)-1); if(key.compare("Installed Path") == 0) { + std::string::size_type pos, startPos; + startPos = line.find('=')+2; std::string installPath = line.substr(startPos, line.find('"', startPos+1)-startPos); installPath.replace(0, 2, wineDriveC.string()); @@ -207,8 +209,8 @@ boost::filesystem::path LinuxPath::getInstallPath() const pos = -1; do { - pos = static_cast(installPath.find("\\\\", pos+1)); - if(static_cast(pos) == std::string::npos) + pos = installPath.find("\\\\", pos+1); + if(pos == std::string::npos) { break; } diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 62cf93664f..62cc14fff4 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -26,7 +26,6 @@ #if defined(__linux__) #include -#include /** * \namespace Files From 463acb2f75b339d075d08ed9285eaba3ab97044d Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Wed, 28 Sep 2011 03:40:27 +0400 Subject: [PATCH 07/45] Use linuxpath for FreeBSD as well --- components/files/linuxpath.cpp | 4 ++-- components/files/linuxpath.hpp | 4 ++-- components/files/path.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index c485002fdb..27581a1e2f 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -22,7 +22,7 @@ #include "linuxpath.hpp" -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include #include @@ -157,4 +157,4 @@ boost::filesystem::path LinuxPath::getRuntimeDataPath() const } /* namespace Files */ -#endif /* defined(__linux__) */ +#endif /* defined(__linux__) || defined(__FreeBSD__) */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index d6e717fc44..53f7a73b43 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -23,7 +23,7 @@ #ifndef COMPONENTS_FILES_LINUXPATH_H #define COMPONENTS_FILES_LINUXPATH_H -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include @@ -85,6 +85,6 @@ struct LinuxPath } /* namespace Files */ -#endif /* defined(__linux__) */ +#endif /* defined(__linux__) || defined(__FreeBSD__) */ #endif /* COMPONENTS_FILES_LINUXPATH_H */ diff --git a/components/files/path.hpp b/components/files/path.hpp index 0788cefb15..78de9c585b 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -26,7 +26,7 @@ #include #include -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include namespace Files { typedef LinuxPath TargetPathType; } From 6b3242f5141b68b0a2c814fcb47adda814c52dfd Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 21 Jan 2012 01:09:06 +0100 Subject: [PATCH 08/45] Updated .gitignore file Updated .gitignore file - added ignore rules for: *.a, *.o, cmake_install.cmake, moc_*.cxx files. Signed-off-by: Lukasz Gromanowski --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index ada874bb22..e57bcfc62f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ Docs/mainpage.hpp CMakeFiles */CMakeFiles CMakeCache.txt +moc_*.cxx +cmake_install.cmake +*.[ao] + From 7c24ae9ac7f48aa4b1ba3a17db2e9b6cd57b7d41 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 21 Jan 2012 01:14:35 +0100 Subject: [PATCH 09/45] Issue #168 - Configuration cleanup - WIP This is "work in progress" commit, it shall not be merged alone, without succeeding commits (it's not fully functional). Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 12 +- apps/launcher/datafilespage.hpp | 6 +- apps/launcher/graphicspage.cpp | 13 +- apps/launcher/graphicspage.hpp | 7 +- apps/launcher/maindialog.cpp | 10 +- apps/launcher/maindialog.hpp | 4 +- apps/openmw/engine.cpp | 6 +- apps/openmw/engine.hpp | 10 +- apps/openmw/main.cpp | 10 +- components/CMakeLists.txt | 6 +- components/cfg/configurationmanager.cpp | 157 ---------------- components/cfg/configurationmanager.hpp | 62 ------- components/files/configurationmanager.cpp | 177 +++++++++++++++++++ components/files/configurationmanager.hpp | 65 +++++++ components/files/{path.hpp => fixedpath.hpp} | 78 +++----- components/files/linuxpath.cpp | 82 ++------- components/files/linuxpath.hpp | 30 +--- components/files/macospath.cpp | 62 +------ components/files/macospath.hpp | 28 +-- components/files/windowspath.cpp | 37 ++-- components/files/windowspath.hpp | 30 +--- 21 files changed, 354 insertions(+), 538 deletions(-) delete mode 100644 components/cfg/configurationmanager.cpp delete mode 100644 components/cfg/configurationmanager.hpp create mode 100644 components/files/configurationmanager.cpp create mode 100644 components/files/configurationmanager.hpp rename components/files/{path.hpp => fixedpath.hpp} (68%) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index c8311846f5..8b59f1b819 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "datafilespage.hpp" #include "lineedit.hpp" @@ -26,7 +26,9 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2) return index1.row() <= index2.row(); } -DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) +DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent) + : QWidget(parent) + , mCfgMgr(cfg) { mDataFilesModel = new QStandardItemModel(); // Contains all plugins with masters mPluginsModel = new PluginsModel(); // Contains selectable plugins @@ -236,13 +238,11 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) void DataFilesPage::setupConfig() { - Cfg::ConfigurationManager cfg; - - QString config = (cfg.getRuntimeConfigPath() / "launcher.cfg").string().c_str(); + QString config = (mCfgMgr.getLocalPath() / "launcher.cfg").string().c_str(); QFile file(config); if (!file.exists()) { - config = QString::fromStdString((cfg.getLocalConfigPath() / "launcher.cfg").string()); + config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string()); } file.setFileName(config); // Just for displaying information diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 2d0a385a79..db1068abdc 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -19,12 +19,14 @@ class PluginsModel; class PluginsView; class ComboBox; +namespace Files { struct ConfigurationManager; } + class DataFilesPage : public QWidget { Q_OBJECT public: - DataFilesPage(QWidget *parent = 0); + DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); ComboBox *mProfilesComboBox; QSettings *mLauncherConfig; @@ -81,6 +83,8 @@ private: QAction *mCheckAction; QAction *mUncheckAction; + Files::ConfigurationManager& mCfgMgr; + void addPlugins(const QModelIndex &index); void removePlugins(const QModelIndex &index); void uncheckPlugins(); diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 92fbf3350b..d41a333563 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -1,8 +1,11 @@ #include #include "graphicspage.hpp" +#include -GraphicsPage::GraphicsPage(QWidget *parent) : QWidget(parent) +GraphicsPage::GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent) + : QWidget(parent) + , mCfgMgr(cfg) { QGroupBox *rendererGroup = new QGroupBox(tr("Renderer"), this); @@ -147,21 +150,21 @@ void GraphicsPage::createPages() void GraphicsPage::setupConfig() { - QString ogreCfg = mCfg.getOgreConfigPath().string().c_str(); + QString ogreCfg = mCfgMgr.getOgreConfigPath().string().c_str(); QFile file(ogreCfg); mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat); } void GraphicsPage::setupOgre() { - QString pluginCfg = mCfg.getPluginsConfigPath().string().c_str(); + QString pluginCfg = mCfgMgr.getPluginsConfigPath().string().c_str(); QFile file(pluginCfg); // Create a log manager so we can surpress debug text to stdout/stderr Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager; - logMgr->createLog((mCfg.getLogPath().string() + "/launcherOgre.log"), true, false, false); + logMgr->createLog((mCfgMgr.getLogPath().string() + "/launcherOgre.log"), true, false, false); - QString ogreCfg = QString::fromStdString(mCfg.getOgreConfigPath().string()); + QString ogreCfg = QString::fromStdString(mCfgMgr.getOgreConfigPath().string()); file.setFileName(ogreCfg); //we need to check that the path to the configuration file exists before we diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 5d50cfc613..ffd7a41b8c 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -7,19 +7,20 @@ #include #include #include -#include class QComboBox; class QCheckBox; class QStackedWidget; class QSettings; +namespace Files { struct ConfigurationManager; } + class GraphicsPage : public QWidget { Q_OBJECT public: - GraphicsPage(QWidget *parent = 0); + GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); QSettings *mOgreConfig; @@ -29,7 +30,7 @@ public slots: void rendererChanged(const QString &renderer); private: - Cfg::ConfigurationManager mCfg; + Files::ConfigurationManager& mCfgMgr; Ogre::Root *mOgre; Ogre::RenderSystem *mSelectedRenderSystem; Ogre::RenderSystem *mOpenGLRenderSystem; diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 4ec8b309cc..3bef0b6f9b 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -152,20 +152,20 @@ QStringList MainDialog::readConfig(const QString &fileName) void MainDialog::createPages() { mPlayPage = new PlayPage(this); - mGraphicsPage = new GraphicsPage(this); - mDataFilesPage = new DataFilesPage(this); + mGraphicsPage = new GraphicsPage(mCfgMgr, this); + mDataFilesPage = new DataFilesPage(mCfgMgr, this); // Retrieve all data entries from the configs QStringList dataDirs; // Global location - QFile file(QString::fromStdString((mCfg.getGlobalConfigPath()/"openmw.cfg").string())); + QFile file(QString::fromStdString((mCfgMgr.getGlobalPath()/"openmw.cfg").string())); if (file.exists()) { dataDirs = readConfig(file.fileName()); } // User location - file.setFileName(QString::fromStdString((mCfg.getLocalConfigPath()/"openmw.cfg").string())); + file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); if (file.exists()) { dataDirs = readConfig(file.fileName()); } @@ -328,7 +328,7 @@ void MainDialog::writeConfig() dataFiles.append(mDataFilesPage->checkedPlugins()); // Open the config as a QFile - QFile file(QString::fromStdString((mCfg.getLocalConfigPath()/"openmw.cfg").string())); + QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { // File cannot be opened or created diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index 047050902a..718fde4f7f 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -3,7 +3,7 @@ #include -#include +#include class QListWidget; class QListWidgetItem; @@ -47,7 +47,7 @@ private: QStringList mDataDirs; bool mStrict; - Cfg::ConfigurationManager mCfg; + Files::ConfigurationManager mCfgMgr; }; #endif diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 7fa98f8e2c..bbc68b8e23 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -17,7 +17,9 @@ #include #include #include -#include +#include +#include + #include #include "mwinput/inputmanager.hpp" @@ -154,7 +156,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) return true; } -OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager) +OMW::Engine::Engine(Files::ConfigurationManager& configurationManager) : mOgre (0) , mPhysicEngine (0) , mShowFPS (false) diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 443f790a47..97079f5a5e 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -11,7 +11,6 @@ #include #include -#include #include "mwworld/environment.hpp" #include "mwworld/ptr.hpp" @@ -54,6 +53,11 @@ namespace OEngine } } +namespace Files +{ + struct ConfigurationManager; +} + namespace OMW { /// \brief Main engine class, that brings together all the components of OpenMW @@ -104,7 +108,7 @@ namespace OMW virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); public: - Engine(Cfg::ConfigurationManager& configurationManager); + Engine(Files::ConfigurationManager& configurationManager); virtual ~Engine(); /// Enable strict filesystem mode (do not fold case) @@ -159,7 +163,7 @@ namespace OMW void setEncoding(const std::string& encoding); private: - Cfg::ConfigurationManager& mCfgMgr; + Files::ConfigurationManager& mCfgMgr; }; } diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 933d1c48aa..0f66925d38 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -6,9 +6,9 @@ #include #include -#include +#include #include -#include +#include #include "engine.hpp" @@ -46,7 +46,7 @@ using namespace std; * \retval true - Everything goes OK * \retval false - Error */ -bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::ConfigurationManager& cfgMgr) +bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::ConfigurationManager& cfgMgr) { // Create a local alias for brevity namespace bpo = boost::program_options; @@ -166,7 +166,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getLocalDataPath()); + dataDirs.push_back(cfgMgr.getDataPath("local:data?")); } engine.setDataDirs(dataDirs); @@ -220,7 +220,7 @@ int main(int argc, char**argv) try { - Cfg::ConfigurationManager cfgMgr; + Files::ConfigurationManager cfgMgr; OMW::Engine engine(cfgMgr); if (parseOptions(argc, argv, engine, cfgMgr)) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 75b8aff8c7..3f7d6d49af 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -6,10 +6,6 @@ add_component_dir (bsa bsa_archive bsa_file ) -add_component_dir (cfg - configurationmanager - ) - add_component_dir (nif controlled effect nif_types record controller extra node record_ptr data nif_file property ) @@ -47,7 +43,7 @@ add_component_dir (misc ) add_component_dir (files - linuxpath windowspath macospath path multidircollection collections fileops + linuxpath windowspath macospath fixedpath multidircollection collections fileops configurationmanager ) add_component_dir (compiler diff --git a/components/cfg/configurationmanager.cpp b/components/cfg/configurationmanager.cpp deleted file mode 100644 index 0998debeeb..0000000000 --- a/components/cfg/configurationmanager.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "configurationmanager.hpp" - -#include -#include -#include - -namespace Cfg -{ - -static const char* const openmwCfgFile = "openmw.cfg"; -static const char* const ogreCfgFile = "ogre.cfg"; -static const char* const pluginsCfgFile = "plugins.cfg"; - - -ConfigurationManager::ConfigurationManager() - : mPath("openmw") -{ - /** - * According to task #168 plugins.cfg file shall be located in global - * configuration path or in runtime configuration path. - */ - mPluginsCfgPath = mPath.getGlobalConfigPath() / pluginsCfgFile; - if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) - { - mPluginsCfgPath = mPath.getRuntimeConfigPath() / pluginsCfgFile; - if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) - { - std::cerr << "Failed to find " << pluginsCfgFile << " file!" << std::endl; - mPluginsCfgPath.clear(); - } - } - - /** - * According to task #168 ogre.cfg file shall be located only - * in user configuration path. - */ - mOgreCfgPath = mPath.getLocalConfigPath() / ogreCfgFile; - - mLogPath = mPath.getLocalConfigPath(); -} - -ConfigurationManager::~ConfigurationManager() -{ -} - -void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, - boost::program_options::options_description& description) -{ - loadConfig(mPath.getLocalConfigPath(), variables, description); - boost::program_options::notify(variables); - loadConfig(mPath.getRuntimeConfigPath(), variables, description); - boost::program_options::notify(variables); - loadConfig(mPath.getGlobalConfigPath(), variables, description); - boost::program_options::notify(variables); -} - -void ConfigurationManager::loadConfig(const boost::filesystem::path& path, - boost::program_options::variables_map& variables, - boost::program_options::options_description& description) -{ - boost::filesystem::path cfgFile(path); - cfgFile /= std::string(openmwCfgFile); - if (boost::filesystem::is_regular_file(cfgFile)) - { - std::cout << "Loading config file: " << cfgFile.string() << "... "; - - std::ifstream configFileStream(cfgFile.string().c_str()); - if (configFileStream.is_open()) - { - boost::program_options::store(boost::program_options::parse_config_file( - configFileStream, description), variables); - - std::cout << "done." << std::endl; - } - else - { - std::cout << "failed." << std::endl; - } - } -} - -const boost::filesystem::path& ConfigurationManager::getGlobalConfigPath() const -{ - return mPath.getGlobalConfigPath(); -} - -void ConfigurationManager::setGlobalConfigPath(const boost::filesystem::path& newPath) -{ - mPath.setGlobalConfigPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getLocalConfigPath() const -{ - return mPath.getLocalConfigPath(); -} - -void ConfigurationManager::setLocalConfigPath(const boost::filesystem::path& newPath) -{ - mPath.setLocalConfigPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getRuntimeConfigPath() const -{ - return mPath.getRuntimeConfigPath(); -} - -void ConfigurationManager::setRuntimeConfigPath(const boost::filesystem::path& newPath) -{ - mPath.setRuntimeConfigPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const -{ - return mPath.getGlobalDataPath(); -} - -void ConfigurationManager::setGlobalDataPath(const boost::filesystem::path& newPath) -{ - mPath.setGlobalDataPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const -{ - return mPath.getLocalDataPath(); -} - -void ConfigurationManager::setLocalDataPath(const boost::filesystem::path& newPath) -{ - mPath.setLocalDataPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getRuntimeDataPath() const -{ - return mPath.getRuntimeDataPath(); -} - -void ConfigurationManager::setRuntimeDataPath(const boost::filesystem::path& newPath) -{ - mPath.setRuntimeDataPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const -{ - return mOgreCfgPath; -} - -const boost::filesystem::path& ConfigurationManager::getPluginsConfigPath() const -{ - return mPluginsCfgPath; -} - -const boost::filesystem::path& ConfigurationManager::getLogPath() const -{ - return mLogPath; -} - -} /* namespace Cfg */ diff --git a/components/cfg/configurationmanager.hpp b/components/cfg/configurationmanager.hpp deleted file mode 100644 index 7f13d0914c..0000000000 --- a/components/cfg/configurationmanager.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP -#define COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP - -#include -#include - -#include - -/** - * \namespace Cfg - */ -namespace Cfg -{ - -/** - * \struct ConfigurationManager - */ -struct ConfigurationManager -{ - ConfigurationManager(); - virtual ~ConfigurationManager(); - - void readConfiguration(boost::program_options::variables_map& variables, - boost::program_options::options_description& description); - - const boost::filesystem::path& getGlobalConfigPath() const; - void setGlobalConfigPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getLocalConfigPath() const; - void setLocalConfigPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getRuntimeConfigPath() const; - void setRuntimeConfigPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getGlobalDataPath() const; - void setGlobalDataPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getLocalDataPath() const; - void setLocalDataPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getRuntimeDataPath() const; - void setRuntimeDataPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getOgreConfigPath() const; - const boost::filesystem::path& getPluginsConfigPath() const; - const boost::filesystem::path& getLogPath() const; - - private: - void loadConfig(const boost::filesystem::path& path, - boost::program_options::variables_map& variables, - boost::program_options::options_description& description); - - Files::Path<> mPath; - - boost::filesystem::path mOgreCfgPath; - boost::filesystem::path mPluginsCfgPath; - boost::filesystem::path mLogPath; -}; - -} /* namespace Cfg */ - -#endif /* COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP */ diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp new file mode 100644 index 0000000000..224fd26492 --- /dev/null +++ b/components/files/configurationmanager.cpp @@ -0,0 +1,177 @@ +#include "configurationmanager.hpp" + +#include +#include +#include +#include + +namespace Files +{ + +static const char* const openmwCfgFile = "openmw.cfg"; +static const char* const ogreCfgFile = "ogre.cfg"; +static const char* const pluginsCfgFile = "plugins.cfg"; + +static const char* const mwDataToken = "?mw:data?"; +static const char* const localDataToken = "?local:data?"; +static const char* const userDataToken = "?user:data?"; +static const char* const globalDataToken = "?global:data?"; + +ConfigurationManager::ConfigurationManager() + : mFixedPath("openmw") +{ + setupTokensMapping(); + + /** + * According to task #168 plugins.cfg file shall be located in global + * configuration path or in runtime configuration path. + */ + mPluginsCfgPath = mFixedPath.getGlobalPath() / pluginsCfgFile; + if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) + { + mPluginsCfgPath = mFixedPath.getLocalPath() / pluginsCfgFile; + if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) + { + std::cerr << "Failed to find " << pluginsCfgFile << " file!" << std::endl; + mPluginsCfgPath.clear(); + } + } + + /** + * According to task #168 ogre.cfg file shall be located only + * in user configuration path. + */ + mOgreCfgPath = mFixedPath.getUserPath() / ogreCfgFile; + + /** + * FIXME: Logs shoudn't be stored in the same dir where configuration is placed. + */ + mLogPath = mFixedPath.getUserPath(); +} + +ConfigurationManager::~ConfigurationManager() +{ +} + +void ConfigurationManager::setupTokensMapping() +{ + mTokensMapping.insert(std::make_pair(mwDataToken, &ConfigurationManager::getInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &ConfigurationManager::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &ConfigurationManager::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &ConfigurationManager::getGlobalDataPath)); +} + +void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, + boost::program_options::options_description& description) +{ + loadConfig(mFixedPath.getUserPath(), variables, description); + boost::program_options::notify(variables); + loadConfig(mFixedPath.getLocalPath(), variables, description); + boost::program_options::notify(variables); + loadConfig(mFixedPath.getGlobalPath(), variables, description); + boost::program_options::notify(variables); +} + +void ConfigurationManager::loadConfig(const boost::filesystem::path& path, + boost::program_options::variables_map& variables, + boost::program_options::options_description& description) +{ + boost::filesystem::path cfgFile(path); + cfgFile /= std::string(openmwCfgFile); + if (boost::filesystem::is_regular_file(cfgFile)) + { + std::cout << "Loading config file: " << cfgFile.string() << "... "; + + std::ifstream configFileStream(cfgFile.string().c_str()); + if (configFileStream.is_open()) + { + boost::program_options::store(boost::program_options::parse_config_file( + configFileStream, description), variables); + + std::cout << "done." << std::endl; + } + else + { + std::cout << "failed." << std::endl; + } + } +} + +const boost::filesystem::path& ConfigurationManager::getGlobalPath() const +{ + return mFixedPath.getGlobalPath(); +} + +const boost::filesystem::path& ConfigurationManager::getUserPath() const +{ + return mFixedPath.getUserPath(); +} + +const boost::filesystem::path& ConfigurationManager::getLocalPath() const +{ + return mFixedPath.getLocalPath(); +} + +const boost::filesystem::path& ConfigurationManager::getDataPath(const std::string& type) const +{ + TokensMappingContainer::const_iterator it = mTokensMapping.find(type); + if (it != mTokensMapping.end()) + { + return ((this)->*(it->second))(); + } + + return mFixedPath.getLocalDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getInstallPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + + //return mFixedPath.getInstallPath(); +} + +const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + + //return mFixedPath.getGlobalDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getUserDataPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + + //return mFixedPath.getUserDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + //return mFixedPath.getLocalDataPath(); +} + + +const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const +{ + return mOgreCfgPath; +} + +const boost::filesystem::path& ConfigurationManager::getPluginsConfigPath() const +{ + return mPluginsCfgPath; +} + +const boost::filesystem::path& ConfigurationManager::getLogPath() const +{ + return mLogPath; +} + +} /* namespace Cfg */ diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp new file mode 100644 index 0000000000..3004b62819 --- /dev/null +++ b/components/files/configurationmanager.hpp @@ -0,0 +1,65 @@ +#ifndef COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP +#define COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP + +#include + +#include +#include + +#include + +/** + * \namespace Files + */ +namespace Files +{ + +/** + * \struct ConfigurationManager + */ +struct ConfigurationManager +{ + ConfigurationManager(); + virtual ~ConfigurationManager(); + + void readConfiguration(boost::program_options::variables_map& variables, + boost::program_options::options_description& description); + + /**< Fixed paths */ + const boost::filesystem::path& getGlobalPath() const; + const boost::filesystem::path& getUserPath() const; + const boost::filesystem::path& getLocalPath() const ; + + const boost::filesystem::path& getDataPath(const std::string& type) const; + + const boost::filesystem::path& getOgreConfigPath() const; + const boost::filesystem::path& getPluginsConfigPath() const; + const boost::filesystem::path& getLogPath() const; + + private: + typedef const boost::filesystem::path& (ConfigurationManager::*path_type_f)() const; + typedef std::tr1::unordered_map TokensMappingContainer; + + void loadConfig(const boost::filesystem::path& path, + boost::program_options::variables_map& variables, + boost::program_options::options_description& description); + + void setupTokensMapping(); + + const boost::filesystem::path& getInstallPath() const; + const boost::filesystem::path& getGlobalDataPath() const; + const boost::filesystem::path& getUserDataPath() const; + const boost::filesystem::path& getLocalDataPath() const; + + Files::FixedPath<> mFixedPath; + + boost::filesystem::path mOgreCfgPath; + boost::filesystem::path mPluginsCfgPath; + boost::filesystem::path mLogPath; + + TokensMappingContainer mTokensMapping; +}; + +} /* namespace Cfg */ + +#endif /* COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP */ diff --git a/components/files/path.hpp b/components/files/fixedpath.hpp similarity index 68% rename from components/files/path.hpp rename to components/files/fixedpath.hpp index 78de9c585b..4e2b20e3cd 100644 --- a/components/files/path.hpp +++ b/components/files/fixedpath.hpp @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -/** \file components/files/path.hpp */ +/** \file components/files/fixedpath.hpp */ -#ifndef COMPONENTS_FILES_PATH_HPP -#define COMPONENTS_FILES_PATH_HPP +#ifndef COMPONENTS_FILES_FIXEDPATH_HPP +#define COMPONENTS_FILES_FIXEDPATH_HPP #include #include @@ -59,7 +59,7 @@ template < class P = TargetPathType > -struct Path +struct FixedPath { typedef P PathType; @@ -68,21 +68,21 @@ struct Path * * \param [in] application_name - Name of the application */ - Path(const std::string& application_name) + FixedPath(const std::string& application_name) : mPath() - , mLocalConfigPath(mPath.getLocalConfigPath()) - , mGlobalConfigPath(mPath.getGlobalConfigPath()) - , mRuntimeConfigPath(mPath.getRuntimeConfigPath()) - , mLocalDataPath(mPath.getLocalDataPath()) - , mGlobalDataPath(mPath.getGlobalDataPath()) - , mRuntimeDataPath(mPath.getRuntimeDataPath()) + , mUserPath(mPath.getUserPath()) + , mGlobalPath(mPath.getGlobalPath()) + , mLocalPath(mPath.getLocalPath()) + , mLocalDataPath() + , mGlobalDataPath() + , mRuntimeDataPath() { if (!application_name.empty()) { boost::filesystem::path suffix(application_name + std::string("/")); - mLocalConfigPath /= suffix; - mGlobalConfigPath /= suffix; + mUserPath /= suffix; + mGlobalPath /= suffix; mLocalDataPath /= suffix; mGlobalDataPath /= suffix; @@ -94,19 +94,9 @@ struct Path * * \return boost::filesystem::path */ - const boost::filesystem::path& getLocalConfigPath() const + const boost::filesystem::path& getUserPath() const { - return mLocalConfigPath; - } - - /** - * \brief Sets new local configuration path. - * - * \param [in] path - New path - */ - void setLocalConfigPath(const boost::filesystem::path& path) - { - mLocalConfigPath = path; + return mUserPath; } /** @@ -114,19 +104,9 @@ struct Path * * \return boost::filesystem::path */ - const boost::filesystem::path& getGlobalConfigPath() const + const boost::filesystem::path& getGlobalPath() const { - return mGlobalConfigPath; - } - - /** - * \brief Sets new global configuration path. - * - * \param [in] path - New path - */ - void setGlobalConfigPath(const boost::filesystem::path& path) - { - mGlobalConfigPath = path; + return mGlobalPath; } /** @@ -134,19 +114,9 @@ struct Path * * \return boost::filesystem::path */ - const boost::filesystem::path& getRuntimeConfigPath() const + const boost::filesystem::path& getLocalPath() const { - return mRuntimeConfigPath; - } - - /** - * \brief Sets new runtime configuration path. - * - * \param [in] path - New path - */ - void setRuntimeConfigPath(const boost::filesystem::path& path) - { - mRuntimeConfigPath = path; + return mLocalPath; } /** @@ -212,11 +182,9 @@ struct Path private: PathType mPath; - boost::filesystem::path mLocalConfigPath; /**< User local path to the configuration files */ - boost::filesystem::path mGlobalConfigPath; /**< Global path to the configuration files */ - boost::filesystem::path mRuntimeConfigPath; /**< Runtime path to the configuration files. - By default it is the same directory where - application was run */ + boost::filesystem::path mUserPath; /**< User path */ + boost::filesystem::path mGlobalPath; /**< Global path */ + boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */ boost::filesystem::path mLocalDataPath; /**< User local application data path (user plugins / mods / etc.) */ boost::filesystem::path mGlobalDataPath; /**< Global application data path */ @@ -229,4 +197,4 @@ struct Path } /* namespace Files */ -#endif /* COMPONENTS_FILES_PATH_HPP */ +#endif /* COMPONENTS_FILES_FIXEDPATH_HPP */ diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 27581a1e2f..11ddc31048 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -35,9 +35,9 @@ namespace Files { -boost::filesystem::path LinuxPath::getLocalConfigPath() const +boost::filesystem::path LinuxPath::getUserPath() const { - boost::filesystem::path localConfigPath("."); + boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); const char* theDir = getenv("OPENMW_CONFIG"); @@ -63,17 +63,17 @@ boost::filesystem::path LinuxPath::getLocalConfigPath() const } if (theDir != NULL) { - localConfigPath = boost::filesystem::path(theDir); + userPath = boost::filesystem::path(theDir); } - localConfigPath /= suffix; + userPath /= suffix; - return localConfigPath; + return userPath; } -boost::filesystem::path LinuxPath::getGlobalConfigPath() const +boost::filesystem::path LinuxPath::getGlobalPath() const { - boost::filesystem::path globalConfigPath("/etc/xdg/"); + boost::filesystem::path globalPath("/etc/xdg/"); char* theDir = getenv("XDG_CONFIG_DIRS"); if (theDir != NULL) @@ -82,79 +82,19 @@ boost::filesystem::path LinuxPath::getGlobalConfigPath() const char* ptr = strtok(theDir, ":"); if (ptr != NULL) { - globalConfigPath = boost::filesystem::path(ptr); - globalConfigPath /= boost::filesystem::path("/"); + globalPath = boost::filesystem::path(ptr); + globalPath /= boost::filesystem::path("/"); } } - return globalConfigPath; + return globalPath; } -boost::filesystem::path LinuxPath::getRuntimeConfigPath() const +boost::filesystem::path LinuxPath::getLocalPath() const { return boost::filesystem::path("./"); } -boost::filesystem::path LinuxPath::getLocalDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("XDG_DATA_HOME"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/.local/share/"); - } - } - } - - if (theDir != NULL) { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - -boost::filesystem::path LinuxPath::getGlobalDataPath() const -{ - boost::filesystem::path globalDataPath("/usr/local/share/"); - - char* theDir = getenv("XDG_DATA_DIRS"); - if (theDir != NULL) - { - // We take only first path from list - char* ptr = strtok(theDir, ":"); - if (ptr != NULL) - { - globalDataPath = boost::filesystem::path(ptr); - globalDataPath /= boost::filesystem::path("/"); - } - } - - return globalDataPath; -} - -boost::filesystem::path LinuxPath::getRuntimeDataPath() const -{ - return boost::filesystem::path("./data/"); -} - - } /* namespace Files */ #endif /* defined(__linux__) || defined(__FreeBSD__) */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 53f7a73b43..af92326bed 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -39,18 +39,18 @@ namespace Files struct LinuxPath { /** - * \brief Return path to the local configuration directory. + * \brief Return path to the user directory. * * \return boost::filesystem::path */ - boost::filesystem::path getLocalConfigPath() const; + boost::filesystem::path getUserPath() const; /** * \brief Return path to the global (system) configuration directory. * * \return boost::filesystem::path */ - boost::filesystem::path getGlobalConfigPath() const; + boost::filesystem::path getGlobalPath() const; /** * \brief Return path to the runtime configuration directory which is the @@ -58,29 +58,7 @@ struct LinuxPath * * \return boost::filesystem::path */ - boost::filesystem::path getRuntimeConfigPath() const; - - /** - * \brief Return path to the local data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - - /** - * \brief Return path to the global (system) data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getGlobalDataPath() const; - - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getRuntimeDataPath() const; + boost::filesystem::path getLocalPath() const; }; } /* namespace Files */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 46e775030f..1ffb443991 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -34,9 +34,9 @@ namespace Files { -boost::filesystem::path MacOsPath::getLocalConfigPath() const +boost::filesystem::path MacOsPath::getUserPath() const { - boost::filesystem::path localConfigPath("."); + boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); const char* theDir = getenv("HOME"); @@ -50,69 +50,25 @@ boost::filesystem::path MacOsPath::getLocalConfigPath() const } if (theDir != NULL) { - localConfigPath = boost::filesystem::path(theDir) / "Library/Preferences/"; + userPath = boost::filesystem::path(theDir) / "Library/Preferences/"; } - localConfigPath /= suffix; + userPath /= suffix; - return localConfigPath; + return userPath; } -boost::filesystem::path MacOsPath::getGlobalConfigPath() const +boost::filesystem::path MacOsPath::getGlobalPath() const { - boost::filesystem::path globalConfigPath("/Library/Preferences/"); - return globalConfigPath; + boost::filesystem::path globalPath("/Library/Preferences/"); + return globalPath; } -boost::filesystem::path MacOsPath::getRuntimeConfigPath() const +boost::filesystem::path MacOsPath::getLocalPath() const { return boost::filesystem::path("./"); } -boost::filesystem::path MacOsPath::getLocalDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/Library/Application Support/"); - } - } - - if (theDir != NULL) - { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - -boost::filesystem::path MacOsPath::getGlobalDataPath() const -{ - boost::filesystem::path globalDataPath("/Library/Application Support/"); - return globalDataPath; -} - -boost::filesystem::path MacOsPath::getRuntimeDataPath() const -{ - return boost::filesystem::path("./data/"); -} - - } /* namespace Files */ #endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */ diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 26f2c907f7..2087a21c70 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -43,14 +43,14 @@ struct MacOsPath * * \return boost::filesystem::path */ - boost::filesystem::path getLocalConfigPath() const; + boost::filesystem::path getUserPath() const; /** * \brief Return path to the global (system) configuration directory. * * \return boost::filesystem::path */ - boost::filesystem::path getGlobalConfigPath() const; + boost::filesystem::path getGlobalPath() const; /** * \brief Return path to the runtime configuration directory which is the @@ -58,29 +58,7 @@ struct MacOsPath * * \return boost::filesystem::path */ - boost::filesystem::path getRuntimeConfigPath() const; - - /** - * \brief Return path to the local data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - - /** - * \brief Return path to the global (system) data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getGlobalDataPath() const; - - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getRuntimeDataPath() const; + boost::filesystem::path getLocalPath() const; }; } /* namespace Files */ diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index f42f149c14..7a4bab1dfb 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -10,9 +10,9 @@ namespace Files { -boost::filesystem::path WindowsPath::getLocalConfigPath() const +boost::filesystem::path WindowsPath::getUserPath() const { - boost::filesystem::path localConfigPath("."); + boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); TCHAR path[MAX_PATH]; @@ -21,17 +21,17 @@ boost::filesystem::path WindowsPath::getLocalConfigPath() const if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path))) { PathAppend(path, TEXT("My Games")); - localConfigPath = boost::filesystem::path(path); + userPath = boost::filesystem::path(path); } - localConfigPath /= suffix; + userPath /= suffix; - return localConfigPath; + return userPath; } -boost::filesystem::path WindowsPath::getGlobalConfigPath() const +boost::filesystem::path WindowsPath::getGlobalPath() const { - boost::filesystem::path globalConfigPath("."); + boost::filesystem::path globalPath("."); boost::filesystem::path suffix("/"); TCHAR path[MAX_PATH]; @@ -39,34 +39,19 @@ boost::filesystem::path WindowsPath::getGlobalConfigPath() const if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, NULL, 0, path))) { - globalConfigPath = boost::filesystem::path(path); + globalPath = boost::filesystem::path(path); } - globalConfigPath /= suffix; + globalPath /= suffix; - return globalConfigPath; + return globalPath; } -boost::filesystem::path WindowsPath::getRuntimeConfigPath() const +boost::filesystem::path WindowsPath::getLocalPath() const { return boost::filesystem::path("./"); } -boost::filesystem::path WindowsPath::getLocalDataPath() const -{ - return getLocalConfigPath(); -} - -boost::filesystem::path WindowsPath::getGlobalDataPath() const -{ - return getGlobalConfigPath(); -} - -boost::filesystem::path WindowsPath::getRuntimeDataPath() const -{ - return boost::filesystem::path("./data/"); -} - } /* namespace Files */ #endif /* defined(_WIN32) || defined(__WINDOWS__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 47dfc08d8e..78b3981bb0 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -43,44 +43,22 @@ struct WindowsPath * * \return boost::filesystem::path */ - boost::filesystem::path getLocalConfigPath() const; + boost::filesystem::path getUserPath() const; /** * \brief Returns "X:\Program Files\" * * \return boost::filesystem::path */ - boost::filesystem::path getGlobalConfigPath() const; + boost::filesystem::path getGlobalPath() const; /** - * \brief Return runtime configuration path which is a location where + * \brief Return local path which is a location where * an application was started * * \return boost::filesystem::path */ - boost::filesystem::path getRuntimeConfigPath() const; - - /** - * \brief Return same path like getLocalConfigPath - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - - /** - * \brief Return same path like getGlobalConfigPath - * - * \return boost::filesystem::path - */ - boost::filesystem::path getGlobalDataPath() const; - - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getRuntimeDataPath() const; + boost::filesystem::path getLocalPath() const; }; } /* namespace Files */ From 406897aa646b387fd29a65c6911ae1e958d24cc5 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 21 Jan 2012 17:58:49 +0100 Subject: [PATCH 10/45] Issue #168 - Configuration cleanup - WIP Sources update. Signed-off-by: Lukasz Gromanowski --- apps/openmw/main.cpp | 2 +- components/files/configurationmanager.cpp | 54 +++-------------- components/files/configurationmanager.hpp | 17 +++--- components/files/fixedpath.hpp | 70 ++++++----------------- components/files/linuxpath.cpp | 65 +++++++++++++++++++++ components/files/linuxpath.hpp | 23 ++++++++ components/files/macospath.cpp | 48 ++++++++++++++++ components/files/macospath.hpp | 2 + components/files/windowspath.cpp | 29 ++++++++++ components/files/windowspath.hpp | 24 ++++++++ 10 files changed, 229 insertions(+), 105 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 0f66925d38..02fa1d7651 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -166,7 +166,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getDataPath("local:data?")); + dataDirs.push_back(cfgMgr.getDataPath(Files::localDataToken)); } engine.setDataDirs(dataDirs); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 224fd26492..aaa26977c5 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -12,10 +12,10 @@ static const char* const openmwCfgFile = "openmw.cfg"; static const char* const ogreCfgFile = "ogre.cfg"; static const char* const pluginsCfgFile = "plugins.cfg"; -static const char* const mwDataToken = "?mw:data?"; -static const char* const localDataToken = "?local:data?"; -static const char* const userDataToken = "?user:data?"; -static const char* const globalDataToken = "?global:data?"; +const char* const mwDataToken = "?mw:data?"; +const char* const localDataToken = "?local:data?"; +const char* const userDataToken = "?user:data?"; +const char* const globalDataToken = "?global:data?"; ConfigurationManager::ConfigurationManager() : mFixedPath("openmw") @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &ConfigurationManager::getInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &ConfigurationManager::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &ConfigurationManager::getUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &ConfigurationManager::getGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -117,48 +117,12 @@ const boost::filesystem::path& ConfigurationManager::getDataPath(const std::stri TokensMappingContainer::const_iterator it = mTokensMapping.find(type); if (it != mTokensMapping.end()) { - return ((this)->*(it->second))(); + return ((mFixedPath).*(it->second))(); } return mFixedPath.getLocalDataPath(); } -const boost::filesystem::path& ConfigurationManager::getInstallPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - - //return mFixedPath.getInstallPath(); -} - -const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - - //return mFixedPath.getGlobalDataPath(); -} - -const boost::filesystem::path& ConfigurationManager::getUserDataPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - - //return mFixedPath.getUserDataPath(); -} - -const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - //return mFixedPath.getLocalDataPath(); -} - - const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const { return mOgreCfgPath; diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 3004b62819..d1c9999793 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -14,6 +14,12 @@ namespace Files { +extern const char* const mwDataToken; +extern const char* const localDataToken; +extern const char* const userDataToken; +extern const char* const globalDataToken; + + /** * \struct ConfigurationManager */ @@ -37,7 +43,9 @@ struct ConfigurationManager const boost::filesystem::path& getLogPath() const; private: - typedef const boost::filesystem::path& (ConfigurationManager::*path_type_f)() const; + typedef Files::FixedPath<> FixedPathType; + + typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const; typedef std::tr1::unordered_map TokensMappingContainer; void loadConfig(const boost::filesystem::path& path, @@ -46,12 +54,7 @@ struct ConfigurationManager void setupTokensMapping(); - const boost::filesystem::path& getInstallPath() const; - const boost::filesystem::path& getGlobalDataPath() const; - const boost::filesystem::path& getUserDataPath() const; - const boost::filesystem::path& getLocalDataPath() const; - - Files::FixedPath<> mFixedPath; + FixedPathType mFixedPath; boost::filesystem::path mOgreCfgPath; boost::filesystem::path mPluginsCfgPath; diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 4e2b20e3cd..3a27bd21d4 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -73,9 +73,10 @@ struct FixedPath , mUserPath(mPath.getUserPath()) , mGlobalPath(mPath.getGlobalPath()) , mLocalPath(mPath.getLocalPath()) - , mLocalDataPath() - , mGlobalDataPath() - , mRuntimeDataPath() + , mUserDataPath(mPath.getUserDataPath()) + , mGlobalDataPath(mPath.getGlobalDataPath()) + , mLocalDataPath(mPath.getLocalDataPath()) + , mInstallPath(mPath.getInstallPath()) { if (!application_name.empty()) { @@ -119,64 +120,28 @@ struct FixedPath return mLocalPath; } - /** - * \brief Return path pointing to the user local data directory. - * - * \return boost::filesystem::path - */ - const boost::filesystem::path& getLocalDataPath() const + const boost::filesystem::path& getInstallPath() const { - return mLocalDataPath; + // TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + + //return mFixedPath.getInstallPath(); } - /** - * \brief Sets new local data path. - * - * \param [in] path - New path - */ - void setLocalDataPath(const boost::filesystem::path& path) - { - mLocalDataPath = path; - } - - /** - * \brief Return path pointing to the global (system) data directory. - * - * \return boost::filesystem::path - */ const boost::filesystem::path& getGlobalDataPath() const { return mGlobalDataPath; } - /** - * \brief Sets new global (system) data directory. - * - * \param [in] path - New path - */ - void setGlobalDataPath(const boost::filesystem::path& path) + const boost::filesystem::path& getUserDataPath() const { - mGlobalDataPath = path; + return mUserDataPath; } - /** - * \brief Return path pointing to the directory where application was started. - * - * \return boost::filesystem::path - */ - const boost::filesystem::path& getRuntimeDataPath() const + const boost::filesystem::path& getLocalDataPath() const { - return mRuntimeDataPath; - } - - /** - * \brief Sets new runtime data directory. - * - * \param [in] path - New path - */ - void setRuntimeDataPath(const boost::filesystem::path& path) - { - mRuntimeDataPath = path; + return mLocalDataPath; } private: @@ -186,11 +151,12 @@ struct FixedPath boost::filesystem::path mGlobalPath; /**< Global path */ boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */ - boost::filesystem::path mLocalDataPath; /**< User local application data path (user plugins / mods / etc.) */ - boost::filesystem::path mGlobalDataPath; /**< Global application data path */ - boost::filesystem::path mRuntimeDataPath; /**< Runtime path to the configuration files. + boost::filesystem::path mUserDataPath; /**< User data path */ + boost::filesystem::path mGlobalDataPath; /**< Global application data path */ + boost::filesystem::path mLocalDataPath; /**< Local path to the configuration files. By default it is a 'data' directory in same directory where application was run */ + boost::filesystem::path mInstallPath; }; diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 11ddc31048..8466f0222e 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -95,6 +95,71 @@ boost::filesystem::path LinuxPath::getLocalPath() const return boost::filesystem::path("./"); } +boost::filesystem::path LinuxPath::getUserDataPath() const +{ + boost::filesystem::path localDataPath("."); + boost::filesystem::path suffix("/"); + + const char* theDir = getenv("OPENMW_DATA"); + if (theDir == NULL) + { + theDir = getenv("XDG_DATA_HOME"); + if (theDir == NULL) + { + theDir = getenv("HOME"); + if (theDir == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + theDir = pwd->pw_dir; + } + } + if (theDir != NULL) + { + suffix = boost::filesystem::path("/.local/share/"); + } + } + } + + if (theDir != NULL) { + localDataPath = boost::filesystem::path(theDir); + } + + localDataPath /= suffix; + return localDataPath; +} + +boost::filesystem::path LinuxPath::getGlobalDataPath() const +{ + boost::filesystem::path globalDataPath("/usr/local/share/"); + + char* theDir = getenv("XDG_DATA_DIRS"); + if (theDir != NULL) + { + // We take only first path from list + char* ptr = strtok(theDir, ":"); + if (ptr != NULL) + { + globalDataPath = boost::filesystem::path(ptr); + globalDataPath /= boost::filesystem::path("/"); + } + } + + return globalDataPath; +} + +boost::filesystem::path LinuxPath::getLocalDataPath() const +{ + return boost::filesystem::path("./data/"); +} + + +boost::filesystem::path LinuxPath::getInstallPath() const +{ + return boost::filesystem::path("./"); +} + } /* namespace Files */ #endif /* defined(__linux__) || defined(__FreeBSD__) */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index af92326bed..51be6242cc 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -59,6 +59,29 @@ struct LinuxPath * \return boost::filesystem::path */ boost::filesystem::path getLocalPath() const; + + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getUserDataPath() const; + + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getGlobalDataPath() const; + + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getLocalDataPath() const; + + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 1ffb443991..87ac422020 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -69,6 +69,54 @@ boost::filesystem::path MacOsPath::getLocalPath() const return boost::filesystem::path("./"); } +boost::filesystem::path MacOsPath::getUserDataPath() const +{ + boost::filesystem::path localDataPath("."); + boost::filesystem::path suffix("/"); + + const char* theDir = getenv("OPENMW_DATA"); + if (theDir == NULL) + { + theDir = getenv("HOME"); + if (theDir == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + theDir = pwd->pw_dir; + } + } + if (theDir != NULL) + { + suffix = boost::filesystem::path("/Library/Application Support/"); + } + } + + if (theDir != NULL) + { + localDataPath = boost::filesystem::path(theDir); + } + + localDataPath /= suffix; + return localDataPath; +} + +boost::filesystem::path MacOsPath::getGlobalDataPath() const +{ + boost::filesystem::path globalDataPath("/Library/Application Support/"); + return globalDataPath; +} + +boost::filesystem::path MacOsPath::getLocalDataPath() const +{ + return boost::filesystem::path("./data/"); +} + +boost::filesystem::path MacOsPath::getInstallPath() const; +{ + return boost::filesystem::path("./"); +} + } /* namespace Files */ #endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */ diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 2087a21c70..2194dbb94a 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -59,6 +59,8 @@ struct MacOsPath * \return boost::filesystem::path */ boost::filesystem::path getLocalPath() const; + + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 7a4bab1dfb..a54f800d40 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -52,6 +52,35 @@ boost::filesystem::path WindowsPath::getLocalPath() const return boost::filesystem::path("./"); } +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ +boost::filesystem::path WindowsPath::getUserDataPath() const +{ + return getUserConfigPath(); +} + +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ +boost::filesystem::path WindowsPath::getGlobalDataPath() const +{ + return getGlobalConfigPath(); +} + +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ +boost::filesystem::path WindowsPath::getLocalDataPath() const +{ + return boost::filesystem::path("./data/"); +} + +boost::filesystem::path WindowsPath::getInstallPath() const; +{ + return boost::filesystem::path("./"); +} + } /* namespace Files */ #endif /* defined(_WIN32) || defined(__WINDOWS__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 78b3981bb0..95af3ea902 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -59,6 +59,30 @@ struct WindowsPath * \return boost::filesystem::path */ boost::filesystem::path getLocalPath() const; + + /** + * \brief Return same path like getUserConfigPath + * + * \return boost::filesystem::path + */ + boost::filesystem::path getUserDataPath() const; + + /** + * \brief Return same path like getGlobalConfigPath + * + * \return boost::filesystem::path + */ + boost::filesystem::path getGlobalDataPath() const; + + /** + * \brief Return runtime data path which is a location where + * an application was started with 'data' suffix. + * + * \return boost::filesystem::path + */ + boost::filesystem::path getLocalDataPath() const; + + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ From 6de0847b86e0b9cea6e272f32ae3e6540a9191b5 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 25 Jan 2012 01:21:30 -0500 Subject: [PATCH 11/45] Slightly better performance on animation --- apps/openmw/mwrender/animation.cpp | 145 ++++----------------- apps/openmw/mwrender/animation.hpp | 1 + apps/openmw/mwrender/creatureanimation.cpp | 1 + apps/openmw/mwrender/npcanimation.cpp | 26 +--- apps/openmw/mwrender/renderingmanager.cpp | 18 ++- components/nifogre/ogre_nif_loader.cpp | 1 + 6 files changed, 48 insertions(+), 144 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3bd160e6da..3ae1a0fa72 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -101,7 +101,7 @@ namespace MWRender{ } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ - bool useHandles = skel == creaturemodel->getSkeleton(); + bool useHandles = false; shapeNumber = 0; std::vector::iterator allshapesiter; @@ -186,62 +186,56 @@ namespace MWRender{ Ogre::Vector3 currentVertex = (*allvertices)[verIndex]; Nif::NiSkinData::BoneInfoCopy* boneinfocopy = &(allshapesiter->boneinfo[inds[0].boneinfocopyindex]); Ogre::Bone *bonePtr = 0; - if(useHandles) - { - bonePtr = skel->getBone(boneinfocopy->bonehandle); - } - else + + + + Ogre::Vector3 vecPos; //= bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; + Ogre::Quaternion vecRot; //= bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; + std::map::iterator result = vecRotPos.find(boneinfocopy); + + if(result == vecRotPos.end()){ bonePtr = skel->getBone(boneinfocopy->bonename); - - Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; - Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - - - /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ + vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - if(useHandles){ + PosAndRot both; both.vecPos = vecPos; both.vecRot = vecRot; - vecPosRot[boneinfocopy->bonehandle] = both; - } + vecRotPos[boneinfocopy] = both; + } else{ - PosAndRot both = vecPosRot[boneinfocopy->bonehandle]; + PosAndRot both = result->second; vecPos = both.vecPos; vecRot = both.vecRot; - }*/ + } Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight; for(int i = 1; i < inds.size(); i++){ boneinfocopy = &(allshapesiter->boneinfo[inds[i].boneinfocopyindex]); - if(useHandles) - bonePtr = skel->getBone(boneinfocopy->bonehandle); - else - bonePtr = skel->getBone(boneinfocopy->bonename); - vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; - vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; + result = vecRotPos.find(boneinfocopy); + - /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ + if(result == vecRotPos.end()){ + bonePtr = skel->getBone(boneinfocopy->bonename); vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - if(useHandles){ PosAndRot both; both.vecPos = vecPos; both.vecRot = vecRot; - vecPosRot[boneinfocopy->bonehandle] = both; - } + vecRotPos[boneinfocopy] = both; + } else{ - PosAndRot both = vecPosRot[boneinfocopy->bonehandle]; + PosAndRot both = result->second; vecPos = both.vecPos; vecRot = both.vecRot; - }*/ + } absVertPos += (vecPos + vecRot * currentVertex) * inds[i].weight; @@ -253,76 +247,9 @@ namespace MWRender{ *(addr+2) = absVertPos.z; } - /*for (unsigned int i = 0; i < boneinfovector.size(); i++) - { - Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[i]; - if(skel->hasBone(boneinfo.bonename)){ - Ogre::Bone *bonePtr = skel->getBone(boneinfo.bonename); - Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans; - Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation; - - for (unsigned int j=0; j < boneinfo.weights.size(); j++) - { - unsigned int verIndex = boneinfo.weights[j].vertex; - if(vertices.find(verIndex) == vertices.end()) - { - Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex]; - absVertPos = absVertPos * boneinfo.weights[j].weight; - vertices.insert(verIndex); - Ogre::Real* addr = (pReal + 3 * verIndex); - *addr = absVertPos.x; - *(addr+1) = absVertPos.y; - *(addr+2) = absVertPos.z; - - - } - else - { - - Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex]; - absVertPos = absVertPos * boneinfo.weights[j].weight; - Ogre::Vector3 old = Ogre::Vector3(pReal + 3 * verIndex); - absVertPos = absVertPos + old; - Ogre::Real* addr = (pReal + 3 * verIndex); - *addr = absVertPos.x; - *(addr+1) = absVertPos.y; - *(addr+2) = absVertPos.z; - - //std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n"; - - } - - /*if(normals.find(verIndex) == normals.end()) - { - Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; - absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; - normals.insert(verIndex); - Ogre::Real* addr = (pRealNormal + 3 * verIndex); - *addr = absNormalsPos.x; - *(addr+1) = absNormalsPos.y; - *(addr+2) = absNormalsPos.z; - } - else - { - Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; - absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; - Ogre::Vector3 old = Ogre::Vector3(pRealNormal + 3 * verIndex); - absNormalsPos = absNormalsPos + old; - - Ogre::Real* addr = (pRealNormal + 3 * verIndex); - *addr = absNormalsPos.x; - *(addr+1) = absNormalsPos.y; - *(addr+2) = absNormalsPos.z; - - }*/ - - //} - //} - - //} //Comment out - ; + } else { @@ -469,20 +396,19 @@ namespace MWRender{ //base->_updateAnimation(); base->_notifyMoved(); - for(unsigned int i = 0; i < entityparts.size(); i++){ + for(unsigned int i = 0; i < entityparts.size(); i++){ Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick skel->_updateTransforms(); - // skel->_notifyManualBonesDirty(); entityparts[i]->getAllAnimationStates()->_notifyDirty(); - //entityparts[i]->_updateAnimation(); entityparts[i]->_notifyMoved(); } + std::vector::iterator iter; int slot = 0; if(transformations){ @@ -490,7 +416,7 @@ namespace MWRender{ if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) { slot++; - //iter++; + continue; } @@ -546,22 +472,7 @@ namespace MWRender{ //base->_updateAnimation(); base->_notifyMoved(); } - for(int i = 0; i < entityparts.size(); i++){ - skel = entityparts[i]->getSkeleton(); - if(skel->hasBone(iter->getBonename())){ - Ogre::Bone* bone = skel->getBone(iter->getBonename()); - if(bTrans) - bone->setPosition(t); - if(bQuats) - bone->setOrientation(r); - - skel->_updateTransforms(); - //skel->_notifyManualBonesDirty(); - entityparts[i]->getAllAnimationStates()->_notifyDirty(); - // entityparts[i]->_updateAnimation(); - entityparts[i]->_notifyMoved(); - } - } + slot++; } } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 15c25707c8..bad7eca15e 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -26,6 +26,7 @@ class Animation{ Ogre::SceneNode* insert; OEngine::Render::OgreRenderer &mRend; MWWorld::Environment& mEnvironment; + std::map vecRotPos; static std::map mUniqueIDs; diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index c2b95186b8..ffcfdcea90 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -38,6 +38,7 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme } void CreatureAnimation::runAnimation(float timepassed){ + vecRotPos.clear(); if(animate > 0){ //Add the amount of time passed to time diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 063ecbc841..4776dc1107 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -250,6 +250,7 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf void NpcAnimation::runAnimation(float timepassed){ + //1. Add the amount of time passed to time //2. Handle the animation transforms dependent on time @@ -270,36 +271,19 @@ void NpcAnimation::runAnimation(float timepassed){ handleAnimationTransforms(); Ogre::Vector3 current = insert->_getWorldAABB().getCenter(); - //This is the attempt at npc physics - //mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), current); - - - - /*if(base->hasSkeleton()) - { - - Ogre::Quaternion boneQuat = rotate; - Ogre::Vector3 boneTrans = trans; - mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), boneTrans + insert->getPosition()); - //mEnvironment.mWorld->setObjectPhysicsRotation(insert->getName(), boneQuat * insert->getOrientation()); - - }*/ + std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); while(shapepartsiter != shapeparts.end()) { + vecRotPos.clear(); std::vector* shapes = *shapepartsiter; Ogre::Entity* theentity = *entitypartsiter; - /* - Pass* pass = theentity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); - if (pass->hasVertexProgram() && pass->getVertexProgram()->isSkeletalAnimationIncluded()) - std::cout << "It's hardware\n"; - else - std::cout << "It's software\n";*/ + - handleShapes(shapes, theentity, theentity->getSkeleton()); + handleShapes(shapes, theentity, base->getSkeleton()); shapepartsiter++; entitypartsiter++; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index fff1412631..a4b51b0824 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -25,6 +25,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const :mRendering(_rend), mObjects(mRendering), mDebugging(engine), mActors(mRendering, environment) { mRendering.createScene("PlayerCam", 55, 5); + //mSkyManager = 0; mSkyManager = MWRender::SkyManager::create(mRendering.getWindow(), mRendering.getCamera(), resDir); // Set default mipmap level (NB some APIs ignore this) @@ -126,27 +127,32 @@ void RenderingManager::update (float duration){ void RenderingManager::skyEnable () { + if(mSkyManager) mSkyManager->enable(); } void RenderingManager::skyDisable () { - mSkyManager->disable(); + if(mSkyManager) + mSkyManager->disable(); } void RenderingManager::skySetHour (double hour) { - mSkyManager->setHour(hour); + if(mSkyManager) + mSkyManager->setHour(hour); } void RenderingManager::skySetDate (int day, int month) { - mSkyManager->setDate(day, month); + if(mSkyManager) + mSkyManager->setDate(day, month); } int RenderingManager::skyGetMasserPhase() const { + return mSkyManager->getMasserPhase(); } @@ -155,9 +161,9 @@ int RenderingManager::skyGetSecundaPhase() const return mSkyManager->getSecundaPhase(); } -void RenderingManager::skySetMoonColour (bool red) -{ - mSkyManager->setMoonColour(red); +void RenderingManager::skySetMoonColour (bool red){ + if(mSkyManager) + mSkyManager->setMoonColour(red); } bool RenderingManager::toggleRenderMode(int mode){ return mDebugging.toggleRenderMode(mode); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 4c28656429..d836a27a48 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -424,6 +424,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std bind->setBinding(nextBuf++, vbuf); } + // Vertex colors if (data->colors.length) { From 1d96b99532f069bd50dd6cc7d1ef3a552e4c3e7f Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 25 Jan 2012 23:55:43 +0100 Subject: [PATCH 12/45] Issue #168 - Configuration cleanup Added tokens processing, modified getInstallPath for linux so we could use ~/.wine/dosdevices symlinks. Signed-off-by: Lukasz Gromanowski --- apps/openmw/main.cpp | 3 +- components/files/configurationmanager.cpp | 77 ++++++++++++--- components/files/configurationmanager.hpp | 17 ++-- components/files/fixedpath.hpp | 24 ++++- components/files/linuxpath.cpp | 112 +++++++++++----------- components/files/macospath.cpp | 76 ++++++++++++++- 6 files changed, 226 insertions(+), 83 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 02fa1d7651..9f70fac15e 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -157,6 +157,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.enableFSStrict(variables["fs-strict"].as()); Files::PathContainer dataDirs(variables["data"].as()); + cfgMgr.processPaths(dataDirs); std::string local(variables["data-local"].as()); if (!local.empty()) @@ -166,7 +167,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getDataPath(Files::localDataToken)); + dataDirs.push_back(cfgMgr.getLocalDataPath()); } engine.setDataDirs(dataDirs); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index aaa26977c5..e1bf48a6fc 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace Files { @@ -24,7 +24,7 @@ ConfigurationManager::ConfigurationManager() /** * According to task #168 plugins.cfg file shall be located in global - * configuration path or in runtime configuration path. + * configuration path or in local configuration path. */ mPluginsCfgPath = mFixedPath.getGlobalPath() / pluginsCfgFile; if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::setInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::setLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::setUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::setGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -66,10 +66,54 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m { loadConfig(mFixedPath.getUserPath(), variables, description); boost::program_options::notify(variables); + loadConfig(mFixedPath.getLocalPath(), variables, description); boost::program_options::notify(variables); loadConfig(mFixedPath.getGlobalPath(), variables, description); boost::program_options::notify(variables); + +} + +struct EmptyPath : public std::unary_function +{ + bool operator()(const boost::filesystem::path& path) const + { + return path.empty(); + } +}; + +void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) +{ + for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) + { + const std::string& path = it->string(); + if (!path.empty() && path[0] == '?') + { + std::string::size_type pos = path.find('?', 1); + if (pos != std::string::npos) + { + ++pos; + TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos)); + + if (tokenIt != mTokensMapping.end()) + { + boost::filesystem::path tempPath(path.substr(pos, path.length() - pos)); + + if (boost::filesystem::is_directory(tempPath)) + { + ((mFixedPath).*(tokenIt->second))(tempPath); + (*it) = tempPath; + } + else + { + (*it).clear(); + } + } + } + } + } + + dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), EmptyPath()), dataDirs.end()); } void ConfigurationManager::loadConfig(const boost::filesystem::path& path, @@ -112,17 +156,26 @@ const boost::filesystem::path& ConfigurationManager::getLocalPath() const return mFixedPath.getLocalPath(); } -const boost::filesystem::path& ConfigurationManager::getDataPath(const std::string& type) const +const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const { - TokensMappingContainer::const_iterator it = mTokensMapping.find(type); - if (it != mTokensMapping.end()) - { - return ((mFixedPath).*(it->second))(); - } + return mFixedPath.getGlobalDataPath(); +} +const boost::filesystem::path& ConfigurationManager::getUserDataPath() const +{ + return mFixedPath.getUserDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const +{ return mFixedPath.getLocalDataPath(); } +const boost::filesystem::path& ConfigurationManager::getInstallPath() const +{ + return mFixedPath.getInstallPath(); +} + const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const { return mOgreCfgPath; diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index d1c9999793..dce56ea5d5 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -7,6 +7,7 @@ #include #include +#include /** * \namespace Files @@ -14,12 +15,6 @@ namespace Files { -extern const char* const mwDataToken; -extern const char* const localDataToken; -extern const char* const userDataToken; -extern const char* const globalDataToken; - - /** * \struct ConfigurationManager */ @@ -30,13 +25,17 @@ struct ConfigurationManager void readConfiguration(boost::program_options::variables_map& variables, boost::program_options::options_description& description); + void processPaths(Files::PathContainer& dataDirs); /**< Fixed paths */ const boost::filesystem::path& getGlobalPath() const; const boost::filesystem::path& getUserPath() const; - const boost::filesystem::path& getLocalPath() const ; + const boost::filesystem::path& getLocalPath() const; - const boost::filesystem::path& getDataPath(const std::string& type) const; + const boost::filesystem::path& getGlobalDataPath() const; + const boost::filesystem::path& getUserDataPath() const; + const boost::filesystem::path& getLocalDataPath() const; + const boost::filesystem::path& getInstallPath() const; const boost::filesystem::path& getOgreConfigPath() const; const boost::filesystem::path& getPluginsConfigPath() const; @@ -45,7 +44,7 @@ struct ConfigurationManager private: typedef Files::FixedPath<> FixedPathType; - typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const; + typedef void (FixedPathType::*path_type_f)(const boost::filesystem::path&); typedef std::tr1::unordered_map TokensMappingContainer; void loadConfig(const boost::filesystem::path& path, diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 3a27bd21d4..3db409b2c2 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -122,11 +122,12 @@ struct FixedPath const boost::filesystem::path& getInstallPath() const { - // TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; + return mInstallPath; + } - //return mFixedPath.getInstallPath(); + void setInstallPath(const boost::filesystem::path& path) + { + mInstallPath = path; } const boost::filesystem::path& getGlobalDataPath() const @@ -134,16 +135,31 @@ struct FixedPath return mGlobalDataPath; } + void setGlobalDataPath(const boost::filesystem::path& path) + { + mGlobalDataPath = path; + } + const boost::filesystem::path& getUserDataPath() const { return mUserDataPath; } + void setUserDataPath(const boost::filesystem::path& path) + { + mUserDataPath = path; + } + const boost::filesystem::path& getLocalDataPath() const { return mLocalDataPath; } + void setLocalDataPath(const boost::filesystem::path& path) + { + mLocalDataPath = path; + } + private: PathType mPath; diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index a1d1168d9a..41891661ef 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -157,73 +157,75 @@ boost::filesystem::path LinuxPath::getLocalDataPath() const boost::filesystem::path LinuxPath::getInstallPath() const { - char *homePath = getenv("HOME"); - if(!homePath) - { - return boost::filesystem::path(""); - } - - boost::filesystem::path wineDefaultRegistry(homePath); - wineDefaultRegistry /= ".wine/system.reg"; - - boost::filesystem::path wineDriveC(homePath); - wineDriveC /= ".wine/drive_c"; + boost::filesystem::path installPath; - boost::filesystem::file_status fileStatus = boost::filesystem::status(wineDefaultRegistry); - boost::filesystem::file_status dirStatus = boost::filesystem::status(wineDriveC); - if(!boost::filesystem::is_regular_file(fileStatus) || !boost::filesystem::is_directory(dirStatus)) + char *homePath = getenv("HOME"); + if (homePath == NULL) { - return boost::filesystem::path(""); - } - - - boost::filesystem::ifstream file(wineDefaultRegistry); - bool isRegEntry = false; - std::string line; - - while (std::getline(file, line)) - { - if(!line.empty() && line[0] == '[') // we found an entry + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) { - std::string regkey = line.substr(1, line.find(']')-1); - if( regkey.compare("SOFTWARE\\\\Wow6432Node\\\\Bethesda Softworks\\\\Morrowind") == 0 - || regkey.compare("SOFTWARE\\\\Bethesda Softworks\\\\Morrowind") == 0 ) - { - isRegEntry = true; - } + homePath = pwd->pw_dir; } - else if(isRegEntry) + } + + if (homePath != NULL) + { + boost::filesystem::path wineDefaultRegistry(homePath); + wineDefaultRegistry /= ".wine/system.reg"; + + if (boost::filesystem::is_regular_file(wineDefaultRegistry)) { - if(line.empty() || line[0] != '"') // empty line means new registry key + boost::filesystem::ifstream file(wineDefaultRegistry); + bool isRegEntry = false; + std::string line; + std::string mwpath; + + while (std::getline(file, line) && !line.empty()) { - break; - } - std::string key = line.substr(1, line.find('"', 1)-1); - if(key.compare("Installed Path") == 0) { - std::string::size_type pos, startPos; - - startPos = line.find('=')+2; - std::string installPath = line.substr(startPos, line.find('"', startPos+1)-startPos); - installPath.replace(0, 2, wineDriveC.string()); - - pos = -1; - do + if (line[0] == '[') // we found an entry { - pos = installPath.find("\\\\", pos+1); - if(pos == std::string::npos) + isRegEntry = (line.find("Softworks\\Morrowind]") != std::string::npos); + } + else if (isRegEntry) + { + if (line[0] == '"') // empty line means new registry key { - break; + std::string key = line.substr(1, line.find('"', 1) - 1); + if (strcasecmp(key.c_str(), "Installed Path") == 0) + { + std::string::size_type valuePos = line.find('=') + 2; + mwpath = line.substr(valuePos, line.rfind('"') - valuePos); + + std::string::size_type pos = mwpath.find("\\"); + while (pos != std::string::npos) + { + mwpath.replace(pos, 2, "/"); + pos = mwpath.find("\\", pos + 1); + } + break; + } } - - installPath.replace(pos, 2, "/"); - } while(true); - - return boost::filesystem::path(installPath); + } + } + + if (!mwpath.empty()) + { + // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks + mwpath[0] = tolower(mwpath[0]); + installPath /= homePath; + installPath /= ".wine/dosdevices/"; + installPath /= mwpath; + + if (!boost::filesystem::is_directory(installPath)) + { + installPath.clear(); + } } } } - - return boost::filesystem::path(""); + + return installPath; } } /* namespace Files */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 87ac422020..789c877099 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -112,11 +112,83 @@ boost::filesystem::path MacOsPath::getLocalDataPath() const return boost::filesystem::path("./data/"); } -boost::filesystem::path MacOsPath::getInstallPath() const; +/** + * FIXME: This should be verified on MacOS system! + */ +boost::filesystem::path MacOsPath::getInstallPath() const { - return boost::filesystem::path("./"); + boost::filesystem::path installPath; + + char *homePath = getenv("HOME"); + if (homePath == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + homePath = pwd->pw_dir; + } + } + + if (homePath != NULL) + { + boost::filesystem::path wineDefaultRegistry(homePath); + wineDefaultRegistry /= ".wine/system.reg"; + + if (boost::filesystem::is_regular_file(wineDefaultRegistry)) + { + boost::filesystem::ifstream file(wineDefaultRegistry); + bool isRegEntry = false; + std::string line; + std::string mwpath; + + while (std::getline(file, line) && !line.empty()) + { + if (line[0] == '[') // we found an entry + { + isRegEntry = (line.find("Softworks\\Morrowind]") != std::string::npos); + } + else if (isRegEntry) + { + if (line[0] == '"') // empty line means new registry key + { + std::string key = line.substr(1, line.find('"', 1) - 1); + if (strcasecmp(key.c_str(), "Installed Path") == 0) + { + std::string::size_type valuePos = line.find('=') + 2; + mwpath = line.substr(valuePos, line.rfind('"') - valuePos); + + std::string::size_type pos = mwpath.find("\\"); + while (pos != std::string::npos) + { + mwpath.replace(pos, 2, "/"); + pos = mwpath.find("\\", pos + 1); + } + break; + } + } + } + } + + if (!mwpath.empty()) + { + // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks + mwpath[0] = tolower(mwpath[0]); + installPath /= homePath; + installPath /= ".wine/dosdevices/"; + installPath /= mwpath; + + if (!boost::filesystem::is_directory(installPath)) + { + installPath.clear(); + } + } + } + } + + return installPath; } + } /* namespace Files */ #endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */ From f4b6caac5961e869b531a63d1113e2a00d89080c Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Thu, 26 Jan 2012 00:14:03 +0100 Subject: [PATCH 13/45] Revert "Issue #178 - workaround for compilation problems with ogre 1.8.0." This reverts commit 37e272b3b5e18d1a93a1d69804a96845f8762ba1. It shouldn't be commited and pushed to config branch. --- components/bsa/bsa_archive.cpp | 6 ------ extern/caelum/src/CaelumPlugin.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 87b46b34c4..2178be318e 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -221,12 +221,6 @@ class BSAArchive : public Archive { BSAFile arc; - FileInfoListPtr findFileInfo(const String&, bool, bool) const - { - static FileInfoListPtr filp(new FileInfoList()); - return filp; - } - public: BSAArchive(const String& name) : Archive(name, "BSA") diff --git a/extern/caelum/src/CaelumPlugin.cpp b/extern/caelum/src/CaelumPlugin.cpp index 340a26559a..288ad9220a 100644 --- a/extern/caelum/src/CaelumPlugin.cpp +++ b/extern/caelum/src/CaelumPlugin.cpp @@ -21,17 +21,17 @@ along with Caelum. If not, see . #include "CaelumPrecompiled.h" #include "CaelumPlugin.h" -template<> Caelum::CaelumPlugin* Ogre::Singleton::msSingleton = 0; +template<> Caelum::CaelumPlugin* Ogre::Singleton::ms_Singleton = 0; namespace Caelum { CaelumPlugin* CaelumPlugin::getSingletonPtr () { - return msSingleton; + return ms_Singleton; } CaelumPlugin& CaelumPlugin::getSingleton () { - assert (msSingleton); - return *msSingleton; + assert (ms_Singleton); + return *ms_Singleton; } extern "C" void CAELUM_EXPORT dllStartPlugin () { From c5dee2c4fb792ea31f24c0aad13dbe23df66941a Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 28 Jan 2012 09:49:09 +0100 Subject: [PATCH 14/45] Issue #168 - Configuration cleanup Corrected tokens processing. If directory exist then tokens shall be replaced by correct path, otherwise they are silently removed from path container. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 37 ++++++++++------------- components/files/configurationmanager.hpp | 2 +- components/files/fixedpath.hpp | 20 ------------ 3 files changed, 17 insertions(+), 42 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index e1bf48a6fc..91e2790517 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::setInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::setLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::setUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::setGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -87,27 +87,22 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) { const std::string& path = it->string(); - if (!path.empty() && path[0] == '?') + + // Check if path contains a token + if (!path.empty() && *path.begin() == '?' && *path.rbegin() == '?') { - std::string::size_type pos = path.find('?', 1); - if (pos != std::string::npos) + TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path); + if (tokenIt != mTokensMapping.end()) { - ++pos; - TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos)); + boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))()); - if (tokenIt != mTokensMapping.end()) + if (boost::filesystem::is_directory(tempPath)) { - boost::filesystem::path tempPath(path.substr(pos, path.length() - pos)); - - if (boost::filesystem::is_directory(tempPath)) - { - ((mFixedPath).*(tokenIt->second))(tempPath); - (*it) = tempPath; - } - else - { - (*it).clear(); - } + (*it) = tempPath; + } + else + { + (*it).clear(); } } } diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index dce56ea5d5..7d77df9c00 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -44,7 +44,7 @@ struct ConfigurationManager private: typedef Files::FixedPath<> FixedPathType; - typedef void (FixedPathType::*path_type_f)(const boost::filesystem::path&); + typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const; typedef std::tr1::unordered_map TokensMappingContainer; void loadConfig(const boost::filesystem::path& path, diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 3db409b2c2..1bf582ab9c 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -125,41 +125,21 @@ struct FixedPath return mInstallPath; } - void setInstallPath(const boost::filesystem::path& path) - { - mInstallPath = path; - } - const boost::filesystem::path& getGlobalDataPath() const { return mGlobalDataPath; } - void setGlobalDataPath(const boost::filesystem::path& path) - { - mGlobalDataPath = path; - } - const boost::filesystem::path& getUserDataPath() const { return mUserDataPath; } - void setUserDataPath(const boost::filesystem::path& path) - { - mUserDataPath = path; - } - const boost::filesystem::path& getLocalDataPath() const { return mLocalDataPath; } - void setLocalDataPath(const boost::filesystem::path& path) - { - mLocalDataPath = path; - } - private: PathType mPath; From 86f88bedae4a7bca9ae3e8645825388eefb579fc Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 28 Jan 2012 11:59:08 +0100 Subject: [PATCH 15/45] Issue #168 - Configuration cleanup Removed 'data' part from token names, added token cleaning when invalid or unknown token is passed as commandline parameter. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 91e2790517..28d49a50c2 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -12,10 +12,10 @@ static const char* const openmwCfgFile = "openmw.cfg"; static const char* const ogreCfgFile = "ogre.cfg"; static const char* const pluginsCfgFile = "plugins.cfg"; -const char* const mwDataToken = "?mw:data?"; -const char* const localDataToken = "?local:data?"; -const char* const userDataToken = "?user:data?"; -const char* const globalDataToken = "?global:data?"; +const char* const mwToken = "?mw?"; +const char* const localToken = "?local?"; +const char* const userToken = "?user?"; +const char* const globalToken = "?global?"; ConfigurationManager::ConfigurationManager() : mFixedPath("openmw") @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwToken, &FixedPath<>::getInstallPath)); + mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -105,6 +105,11 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) (*it).clear(); } } + else + { + // Clean invalid / unknown token, it will be removed outside the loop + (*it).clear(); + } } } From 1da519a91496e7e72a4de22f645bfa249a7d4db7 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 29 Jan 2012 00:42:55 -0500 Subject: [PATCH 16/45] Some cleanup --- apps/openmw/mwrender/animation.cpp | 30 +++++++++++--------------- apps/openmw/mwrender/npcanimation.cpp | 16 +++++--------- components/nifogre/ogre_nif_loader.cpp | 19 +++++++++------- components/nifogre/ogre_nif_loader.hpp | 2 -- 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3ae1a0fa72..96d65e00da 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -124,8 +124,7 @@ namespace MWRender{ //std::cout << "Name " << copy.sname << "\n"; Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); Ogre::Real* pReal = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); - //Ogre::HardwareVertexBufferSharedPtr vbufNormal = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(1); - // Ogre::Real* pRealNormal = static_cast(vbufNormal->lock(Ogre::HardwareBuffer::HBL_NORMAL)); + std::vector initialVertices = copy.morph.getInitialVertices(); //Each shape has multiple indices @@ -184,13 +183,14 @@ namespace MWRender{ std::vector inds = iter->second; int verIndex = iter->first; Ogre::Vector3 currentVertex = (*allvertices)[verIndex]; + Ogre::Vector3 currentNormal = (*allnormals)[verIndex]; Nif::NiSkinData::BoneInfoCopy* boneinfocopy = &(allshapesiter->boneinfo[inds[0].boneinfocopyindex]); Ogre::Bone *bonePtr = 0; - Ogre::Vector3 vecPos; //= bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; - Ogre::Quaternion vecRot; //= bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; + Ogre::Vector3 vecPos; + Ogre::Quaternion vecRot; std::map::iterator result = vecRotPos.find(boneinfocopy); if(result == vecRotPos.end()){ @@ -213,6 +213,7 @@ namespace MWRender{ } Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight; + for(int i = 1; i < inds.size(); i++){ @@ -239,12 +240,14 @@ namespace MWRender{ absVertPos += (vecPos + vecRot * currentVertex) * inds[i].weight; + } Ogre::Real* addr = (pReal + 3 * verIndex); *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; + } @@ -321,7 +324,7 @@ namespace MWRender{ } vbuf->unlock(); - //vbufNormal->unlock(); + } } @@ -394,18 +397,15 @@ namespace MWRender{ base->getAllAnimationStates()->_notifyDirty(); //base->_updateAnimation(); - base->_notifyMoved(); + //base->_notifyMoved(); for(unsigned int i = 0; i < entityparts.size(); i++){ - Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); + //Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick - - skel->_updateTransforms(); entityparts[i]->getAllAnimationStates()->_notifyDirty(); - entityparts[i]->_notifyMoved(); } @@ -416,9 +416,7 @@ namespace MWRender{ if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) { slot++; - - continue; - + continue; } float x; @@ -439,7 +437,6 @@ namespace MWRender{ timeIndex(time, ttime, tindexI[slot], tindexJ, x); - //std::cout << "X: " << x << " X2: " << x2 << "\n"; Ogre::Vector3 t; Ogre::Quaternion r; @@ -454,7 +451,6 @@ namespace MWRender{ bool bQuats = quats.size() > 0; if(bQuats){ r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); - //bone->setOrientation(r); } skel = base->getSkeleton(); if(skel->hasBone(iter->getBonename())){ @@ -467,10 +463,8 @@ namespace MWRender{ skel->_updateTransforms(); - //skel->_notifyManualBonesDirty(); base->getAllAnimationStates()->_notifyDirty(); - //base->_updateAnimation(); - base->_notifyMoved(); + } slot++; diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 4776dc1107..40db0006c0 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -43,14 +43,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); bool female = tolower(secondtolast) == 'f'; bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - /*std::cout << "Race: " << ref->base->race ; - if(female){ - std::cout << " Sex: Female" << " Height: " << race->data.height.female << "\n"; - } - else{ - std::cout << " Sex: Male" << " Height: " << race->data.height.male << "\n"; - }*/ - + std::string smodel = "meshes\\base_anim.nif"; @@ -65,7 +58,6 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O base = mRend.getScene()->createEntity(smodel); base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones //stay in the same place when we skipanim, or open a gui window - if(transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel)){ @@ -116,7 +108,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O const ESM::BodyPart* wristr = wristl; const ESM::BodyPart* armr = arml; - + if(upperleg){ insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg"); insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg"); @@ -178,7 +170,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(clavicler) insertBoundedPart("meshes\\" + clavicler->model , "Right Clavicle", base);*/ - + if(neck) { insertBoundedPart("meshes\\" + neck->model, "Neck"); @@ -187,6 +179,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertBoundedPart("meshes\\" + head->model, "Head"); if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); + if (chest){ insertFreePart("meshes\\" + chest->model, ">\"", insert); @@ -214,6 +207,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O } Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ + NIFLoader::load(mesh); Entity* ent = mRend.getScene()->createEntity(mesh); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index d836a27a48..4e3864a674 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -220,14 +220,14 @@ void NIFLoader::createMaterial(const String &name, //Hardware Skinning code, textures may be the wrong color if enabled - /* if(!mSkel.isNull()){ - material->removeAllTechniques(); + + /*material->removeAllTechniques(); Ogre::Technique* tech = material->createTechnique(); //tech->setSchemeName("blahblah"); Pass* pass = tech->createPass(); - pass->setVertexProgram("Ogre/HardwareSkinningFourWeights"); - }*/ + pass->setVertexProgram("Ogre/BasicVertexPrograms/AmbientOneTexture");*/ + // This assigns the texture to this material. If the texture name is // a file name, and this file exists (in a resource directory), it @@ -888,6 +888,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou boneIndex++; } + } else @@ -1154,6 +1155,10 @@ void NIFLoader::loadResource(Resource *resource) bool hasAnim = false; bool baddin = false; bNiTri = true; + if(name == "meshes\\base_anim.nif" || name == "meshes\\base_animkna.nif") + { + bNiTri = false; + } if(suffix == '*') { @@ -1304,15 +1309,13 @@ void NIFLoader::loadResource(Resource *resource) mesh->_setBounds(mBoundingBox, false); } - if (!mSkel.isNull()) + if (!mSkel.isNull() ) { mesh->_notifySkeleton(mSkel); } } -void NIFLoader::addInMesh(Ogre::Mesh* input){ - addin.push_back(input); -} + diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index fd16208227..b1e0943f5d 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -111,7 +111,6 @@ class NIFLoader : Ogre::ManualResourceLoader std::vector* getAnim(std::string name); std::vector* getShapes(std::string name); std::map* getTextIndices(std::string name); - void addInMesh(Ogre::Mesh* input); Ogre::Vector3 convertVector3(const Nif::Vector& vec); @@ -188,7 +187,6 @@ class NIFLoader : Ogre::ManualResourceLoader std::map,ciLessBoost> alltextmappings; std::map,ciLessBoost> allanimmap; std::map,ciLessBoost> allshapesmap; - std::vector addin; std::vector mAnim; std::vector mS; From b004e2479c335a40d61ea944f69403cf0176bff8 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 29 Jan 2012 20:27:03 +0100 Subject: [PATCH 17/45] Issue #133 Handle resources across multiple data directories - WIP Work In Progress - added support for multiple paths in SoundManager. Signed-off-by: Lukasz Gromanowski --- apps/openmw/engine.cpp | 12 +- apps/openmw/engine.hpp | 2 +- apps/openmw/mwsound/soundmanager.cpp | 169 +++++++++++++----------- apps/openmw/mwsound/soundmanager.hpp | 11 +- components/file_finder/file_finder.hpp | 89 ++++++++++++- components/file_finder/search.cpp | 28 ++-- components/files/multidircollection.hpp | 2 +- 7 files changed, 200 insertions(+), 113 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index bbc68b8e23..31c9470548 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -200,12 +200,12 @@ void OMW::Engine::loadBSA() for (Files::MultiDirCollection::TIter iter (bsa.begin()); iter!=bsa.end(); ++iter) { - std::cout << "Adding " << iter->second.string() << std::endl; - Bsa::addBSA (iter->second.string()); + std::cout << "Adding " << iter->second.string() << std::endl; + Bsa::addBSA (iter->second.string()); } - std::cout << "Data dir " << mDataDir.string() << std::endl; - Bsa::addDir(mDataDir.string(), mFSStrict); + //std::cout << "Data dir " << mDataDir.string() << std::endl; + //Bsa::addDir(mDataDir.string(), mFSStrict); } // add resources directory @@ -228,7 +228,7 @@ void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs) { /// \todo remove mDataDir, once resources system can handle multiple directories assert (!dataDirs.empty()); - mDataDir = dataDirs.back(); + mDataDirs = dataDirs; mFileCollections = Files::Collections (dataDirs, !mFSStrict); } @@ -339,7 +339,7 @@ void OMW::Engine::go() mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre->getRoot(), mOgre->getCamera(), mEnvironment.mWorld->getStore(), - (mDataDir), + mDataDirs, mUseSound, mFSStrict, mEnvironment); // Create script system diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 97079f5a5e..40bf73c6d2 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -64,7 +64,7 @@ namespace OMW class Engine : private Ogre::FrameListener { std::string mEncoding; - boost::filesystem::path mDataDir; + Files::PathContainer mDataDirs; boost::filesystem::path mResDir; OEngine::Render::OgreRenderer *mOgre; OEngine::Physic::PhysicEngine* mPhysicEngine; diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 7390e4c5ca..76ef23bc2a 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -4,8 +4,6 @@ #include #include -using namespace std; - #include #include @@ -15,6 +13,7 @@ using namespace std; #include #include + #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" #include "../mwworld/player.hpp" @@ -90,24 +89,28 @@ namespace MWSound // relative to the sound dir, and translates them into full paths // of existing files in the filesystem, if they exist. bool FSstrict; - FileFinder::FileFinder files; - FileFinder::FileFinderStrict strict; - FileFinder::FileFinder musicpath; - FileFinder::FileFinderStrict musicpathStrict; + FileFinder::LessTreeFileFinder files; + FileFinder::StrictTreeFileFinder strict; + FileFinder::LessTreeFileFinder musicpath; + FileFinder::StrictTreeFileFinder musicpathStrict; - SoundImpl(Ogre::Root *root, Ogre::Camera *camera, - const ESMS::ESMStore &str, - const std::string &soundDir, const std::string &musicDir, bool fsstrict) + SoundImpl(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &str, + const Files::PathContainer& soundDir, + const Files::PathContainer& musicDir, + bool fsstrict) : mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY))) , updater(mgr) , cameraTracker(mgr) , store(str) - , files(soundDir), strict(soundDir) - ,musicpath(musicDir), musicpathStrict(musicDir) + , FSstrict(fsstrict) + , files(soundDir) + , strict(soundDir) + , musicpath(musicDir) + , musicpathStrict(musicDir) { - FSstrict = fsstrict; - cout << "Sound output: " << SOUND_OUT << endl; - cout << "Sound decoder: " << SOUND_IN << endl; + + std::cout << "Sound output: " << SOUND_OUT << std::endl; + std::cout << "Sound decoder: " << SOUND_IN << std::endl; // Attach the camera to the camera tracker cameraTracker.followCamera(camera); @@ -136,36 +139,49 @@ namespace MWSound bool hasFile(const std::string &str, bool music = false) { - if(FSstrict == false) + bool found = false; + if(!FSstrict) { if(music) { - if(musicpath.has(str)) return true; - + found = musicpath.has(str); // Not found? Try with .mp3 - return musicpath.has(toMp3(str)); + if (!found) + { + found = musicpath.has(toMp3(str)); + } } else { - if(files.has(str)) return true; - return files.has(toMp3(str)); + found = files.has(str); + if (!found) + { + found = files.has(toMp3(str)); + } } } else { if(music) { - if(musicpathStrict.has(str)) return true; - + found = musicpathStrict.has(str); // Not found? Try with .mp3 - return musicpathStrict.has(toMp3(str)); + if (!found) + { + found = musicpathStrict.has(toMp3(str)); + } } else { - if(strict.has(str)) return true; - return strict.has(toMp3(str)); + found = strict.has(str); + if (!found) + { + found = strict.has(toMp3(str)); + } } } + + return found; } // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path @@ -258,13 +274,13 @@ namespace MWSound } catch(...) { - cout << "Error loading " << file << ", skipping.\n"; + std::cout << "Error loading " << file << ", skipping.\n"; } } // Clears all the sub-elements of a given iterator, and then // removes it from 'sounds'. - void clearAll(PtrMap::iterator it) + void clearAll(PtrMap::iterator& it) { IDMap::iterator sit = it->second.begin(); @@ -362,9 +378,9 @@ namespace MWSound } } } - }; + }; /* SoundImpl */ - void SoundManager::streamMusicFull (const std::string& filename) + void SoundManager::streamMusicFull(const std::string& filename) { if(!mData) return; @@ -381,20 +397,24 @@ namespace MWSound } SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, - const ESMS::ESMStore &store, - boost::filesystem::path dataDir, - bool useSound, bool fsstrict, MWWorld::Environment& environment) - : mData(NULL), fsStrict (fsstrict), mEnvironment (environment) + const ESMS::ESMStore &store, const Files::PathContainer& dataDirs, + bool useSound, bool fsstrict, MWWorld::Environment& environment) + : mData(NULL) + , fsStrict(fsstrict) + , mEnvironment(environment) { - MP3Lookup(dataDir / "Music/Explore/"); - if(useSound) - mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict); + for (Files::PathContainer::const_iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) + { + MP3Lookup((*it) / "Music/Explore/"); + } + if(useSound) + { + mData = new SoundImpl(root, camera, store, dataDirs /* Sound */, dataDirs /* Music */, fsstrict); + } test.name = ""; total = 0; - - } SoundManager::~SoundManager() @@ -407,14 +427,12 @@ namespace MWSound { if(mData->hasFile(filename, true)) { - std::string fullpath = mData->convertPath(filename, true); - streamMusicFull(fullpath); + streamMusicFull(mData->convertPath(filename, true)); } } - - void SoundManager::MP3Lookup(boost::filesystem::path dir) -{ + void SoundManager::MP3Lookup(const boost::filesystem::path& dir) + { boost::filesystem::directory_iterator dir_iter(dir), dir_end; std::string mp3extension = ".mp3"; @@ -425,35 +443,30 @@ namespace MWSound files.push_back(*dir_iter); } } -} + } void SoundManager::startRandomTitle() -{ - std::vector::iterator fileIter; - - if(files.size() > 0) + { + if(!files.empty()) { - fileIter = files.begin(); - srand ( time(NULL) ); + Files::PathContainer::iterator fileIter = files.begin(); + srand( time(NULL) ); int r = rand() % files.size() + 1; //old random code - for(int i = 1; i < r; i++) - { - fileIter++; - } + std::advance(fileIter, r - 1); std::string music = fileIter->string(); + std::cout << "Playing " << music << "\n"; + try { - std::cout << "Playing " << music << "\n"; streamMusicFull(music); } - catch(std::exception &e) + catch (std::exception &e) { std::cout << " Music Error: " << e.what() << "\n"; } } -} - + } bool SoundManager::isMusicPlaying() { @@ -465,14 +478,12 @@ namespace MWSound return test; } - SoundManager::SoundImpl SoundManager::getMData() + SoundManager::SoundImpl SoundManager::getMData() { // bool test = mData->music->isPlaying(); return *mData; } - - void SoundManager::say (MWWorld::Ptr ptr, const std::string& filename) { // The range values are not tested @@ -480,7 +491,7 @@ namespace MWSound if(mData->hasFile(filename)) mData->add(mData->convertPath(filename), ptr, "_say_sound", 1, 1, 100, 20000, false); else - cout << "Sound file " << filename << " not found, skipping.\n"; + std::cout << "Sound file " << filename << " not found, skipping.\n"; } bool SoundManager::sayDone (MWWorld::Ptr ptr) const @@ -490,20 +501,20 @@ namespace MWSound } - void SoundManager::playSound (const std::string& soundId, float volume, float pitch) + void SoundManager::playSound(const std::string& soundId, float volume, float pitch) { if(!mData) return; // Play and forget float min, max; const std::string &file = mData->lookup(soundId, volume, min, max); - if(file != "") - { + if (file != "") + { SoundPtr snd = mData->mgr->load(file); snd->setVolume(volume); snd->setRange(min,max); snd->setPitch(pitch); snd->play(); - } + } } void SoundManager::playSound3D (MWWorld::Ptr ptr, const std::string& soundId, @@ -514,7 +525,7 @@ namespace MWSound // Look up the sound in the ESM data float min, max; const std::string &file = mData->lookup(soundId, volume, min, max); - if(file != "") + if (file != "") mData->add(file, ptr, soundId, volume, pitch, min, max, loop); } @@ -541,18 +552,19 @@ namespace MWSound void SoundManager::updateObject(MWWorld::Ptr ptr) { - if(!mData) return; - mData->updatePositions(ptr); + if (mData != NULL) + { + mData->updatePositions(ptr); + } } void SoundManager::update (float duration) { - std::string effect; - MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); //If the region has changed - if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){ + if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10) + { timer.restart(); if (test.name != current->cell->region) { @@ -564,11 +576,12 @@ namespace MWSound { std::vector::iterator soundIter = test.soundList.begin(); //mEnvironment.mSoundManager - if(total == 0){ - while (!(soundIter == test.soundList.end())) + if(total == 0) + { + while (soundIter != test.soundList.end()) { - ESM::NAME32 go = soundIter->sound; int chance = (int) soundIter->chance; + //ESM::NAME32 go = soundIter->sound; //std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; soundIter++; total += chance; @@ -578,7 +591,7 @@ namespace MWSound int r = rand() % total; //old random code int pos = 0; soundIter = test.soundList.begin(); - while (!(soundIter == test.soundList.end())) + while (soundIter != test.soundList.end()) { const ESM::NAME32 go = soundIter->sound; int chance = (int) soundIter->chance; @@ -586,13 +599,11 @@ namespace MWSound soundIter++; if( r - pos < chance) { - effect = go.name; //play sound std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; - mEnvironment.mSoundManager->playSound(effect, 20.0, 1.0); + mEnvironment.mSoundManager->playSound(go.name, 20.0, 1.0); break; - } pos += chance; } diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 7dff16c761..5c3f473f2e 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -2,14 +2,15 @@ #define GAME_SOUND_SOUNDMANAGER_H #include -#include #include +#include + #include "../mwworld/ptr.hpp" #include +#include -#include namespace Ogre { @@ -37,7 +38,7 @@ namespace MWSound struct SoundImpl; SoundImpl *mData; - std::vector files; + Files::PathContainer files; bool fsStrict; MWWorld::Environment& mEnvironment; @@ -52,7 +53,7 @@ namespace MWSound public: SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, - boost::filesystem::path dataDir, bool useSound, bool fsstrict, + const Files::PathContainer& dataDir, bool useSound, bool fsstrict, MWWorld::Environment& environment); ~SoundManager(); @@ -61,7 +62,7 @@ namespace MWSound /// \param filename name of a sound file in "Music/" in the data directory. void startRandomTitle(); - void MP3Lookup(boost::filesystem::path dir); + void MP3Lookup(const boost::filesystem::path& dir); bool isMusicPlaying(); diff --git a/components/file_finder/file_finder.hpp b/components/file_finder/file_finder.hpp index 0e1e072263..8a15af73af 100644 --- a/components/file_finder/file_finder.hpp +++ b/components/file_finder/file_finder.hpp @@ -1,9 +1,11 @@ #ifndef FILE_FINDER_MAIN_H #define FILE_FINDER_MAIN_H +#include + #include "search.hpp" #include "filename_less.hpp" -#include +#include namespace FileFinder { @@ -11,7 +13,8 @@ namespace FileFinder template class FileFinderT { - std::map table; + typedef std::map TableContainer; + TableContainer table; struct Inserter : ReturnPath { @@ -35,12 +38,12 @@ public: // Remember the original path length, so we can cut it away from // the relative paths used as keys - std::string pstring = path.string(); + const std::string& pstring = path.string(); inserter.cut = pstring.size(); // If the path does not end in a slash, then boost will add one // later, which means one more character we have to remove. - char last = pstring[pstring.size()-1]; + char last = *pstring.rbegin(); if(last != '\\' && last != '/') inserter.cut++; @@ -56,12 +59,84 @@ public: // Find the full path from a relative path. const std::string &lookup(const std::string& file) const { - return table.find(file)->second; + static std::string empty; + typename TableContainer::const_iterator it = table.find(file); + return (it != table.end()) ? it->second : empty; } }; +template +< + class LESS +> +struct TreeFileFinder +{ + typedef TreeFileFinder finder_t; + + TreeFileFinder(const Files::PathContainer& paths, bool recurse = true) + { + struct : ReturnPath + { + finder_t *owner; + int cut; + + void add(const boost::filesystem::path &pth) + { + std::string file = pth.string(); + std::string key = file.substr(cut); + owner->mTable[key] = file; + } + } inserter; + + inserter.owner = this; + + for (Files::PathContainer::const_iterator it = paths.begin(); it != paths.end(); ++it) + { + + // Remember the original path length, so we can cut it away from + // the relative paths used as keys + const std::string& pstring = it->string(); + inserter.cut = pstring.size(); + + // If the path does not end in a slash, then boost will add one + // later, which means one more character we have to remove. + char last = *pstring.rbegin(); + if (last != '\\' && last != '/') + { + inserter.cut++; + } + + // Fill the map + find(*it, inserter, recurse); + } + } + + bool has(const std::string& file) const + { + return mTable.find(file) != mTable.end(); + } + + const std::string& lookup(const std::string& file) const + { + static std::string empty; + typename TableContainer::const_iterator it = mTable.find(file); + return (it != mTable.end()) ? it->second : empty; + } + + private: + typedef std::map TableContainer; + TableContainer mTable; + +// Inserter inserter; +}; + + // The default is to use path_less for equality checks typedef FileFinderT FileFinder; typedef FileFinderT FileFinderStrict; -} -#endif + +typedef TreeFileFinder LessTreeFileFinder; +typedef TreeFileFinder StrictTreeFileFinder; + +} /* namespace FileFinder */ +#endif /* FILE_FINDER_MAIN_H */ diff --git a/components/file_finder/search.cpp b/components/file_finder/search.cpp index b05b30e835..eb4392abc5 100644 --- a/components/file_finder/search.cpp +++ b/components/file_finder/search.cpp @@ -2,27 +2,27 @@ #include -using namespace std; -using namespace boost::filesystem; - -void FileFinder::find(const path & dir_path, ReturnPath &ret, bool recurse) +void FileFinder::find(const boost::filesystem::path & dir_path, ReturnPath &ret, bool recurse) { - if ( !exists( dir_path ) ) + if ( !boost::filesystem::exists( dir_path ) ) { - cout << "Path " << dir_path << " not found\n"; + std::cout << "Path " << dir_path << " not found" << std::endl; return; } - directory_iterator end_itr; // default construction yields past-the-end - for ( directory_iterator itr(dir_path); - itr != end_itr; - ++itr ) + boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end + for (boost::filesystem::directory_iterator itr(dir_path); itr != end_itr; ++itr) { - if ( is_directory( *itr ) ) + if (boost::filesystem::is_directory( *itr )) { - if(recurse) find(*itr, ret); + if (recurse) + { + find(*itr, ret); + } + } + else + { + ret.add(*itr); } - else - ret.add(*itr); } } diff --git a/components/files/multidircollection.hpp b/components/files/multidircollection.hpp index 391f8b6a4e..e8abeb45dc 100644 --- a/components/files/multidircollection.hpp +++ b/components/files/multidircollection.hpp @@ -68,7 +68,7 @@ namespace Files /// \param foldCase Ignore filename case boost::filesystem::path getPath (const std::string& file) const; - ///< Return full path (including filename) of \æ file. + ///< Return full path (including filename) of \a file. /// /// If the file does not exist, an exception is thrown. \a file must include /// the extension. From 9c73fa6b6d61ca1632b129423a28b9c523d2be82 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 29 Jan 2012 17:50:51 -0500 Subject: [PATCH 18/45] Physics sort of fixed --- apps/openmw/mwworld/scene.cpp | 16 +++++++++------- apps/openmw/mwworld/world.cpp | 7 +++++++ apps/openmw/mwworld/world.hpp | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index b08a52aac6..624c65d579 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -60,12 +60,12 @@ namespace MWWorld std::cout << "Unloading cell\n"; ListHandles functor; - MWWorld::Ptr::CellStore* active = *iter; + - active->forEach(functor); + (*iter)->forEach(functor); { @@ -77,12 +77,13 @@ namespace MWWorld mPhysics->removeObject (node->getName()); } } - mRendering.removeCell(active); + mRendering.removeCell(*iter); //mPhysics->removeObject("Unnamed_43"); - mWorld->getLocalScripts().clearCell (active); - mEnvironment.mMechanicsManager->dropActors (active); - mEnvironment.mSoundManager->stopSound (active); - mActiveCells.erase(active); + mWorld->getLocalScripts().clearCell (*iter); + mEnvironment.mMechanicsManager->dropActors (*iter); + mEnvironment.mSoundManager->stopSound (*iter); + mActiveCells.erase(*iter); + } @@ -108,6 +109,7 @@ namespace MWWorld void Scene::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos) { + mWorld->makeNewPlayer(); if (adjustPlayerPos) mWorld->getPlayer().setPos (position.pos[0], position.pos[1], position.pos[2]); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 2232e8a1d4..f655b6143f 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -182,6 +182,13 @@ namespace MWWorld } + void World::makeNewPlayer(){ + MWRender::Player* play = &(mRendering.getPlayer()); + delete mPlayer; + mPlayer = new MWWorld::Player (play, mStore.npcs.find ("player"), *this); + mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); + } + World::~World() { delete mWorldScene; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 235d203a60..71231998a6 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -220,6 +220,7 @@ namespace MWWorld /// references that are currently not in the rendered scene should be ignored. void setObjectPhysicsRotation(const std::string& handle,Ogre::Quaternion quat); void setObjectPhysicsPosition(const std::string& handle,Ogre::Vector3 vector); + void makeNewPlayer(); }; } From d2b3c1dbac91c68d00455ca8cb20c5b9988506a8 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 29 Jan 2012 18:13:43 -0500 Subject: [PATCH 19/45] Collision may be working correctly --- apps/openmw/mwworld/world.cpp | 10 ++++++++-- apps/openmw/mwworld/world.hpp | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index f655b6143f..4439d4c666 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -148,7 +148,7 @@ namespace MWWorld const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) : mRendering (renderer,resDir, physEng, environment),mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), - mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) + mSky (false), bCollision(false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { mPhysEngine = physEng; @@ -183,10 +183,15 @@ namespace MWWorld } void World::makeNewPlayer(){ + bool initialCollision = bCollision; + if(bCollision) + toggleCollisionMode(); MWRender::Player* play = &(mRendering.getPlayer()); delete mPlayer; mPlayer = new MWWorld::Player (play, mStore.npcs.find ("player"), *this); mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); + if(initialCollision) + toggleCollisionMode(); } World::~World() @@ -619,7 +624,8 @@ namespace MWWorld bool World::toggleCollisionMode() { - return mPhysics->toggleCollisionMode(); + bCollision = mPhysics->toggleCollisionMode(); + return bCollision; } bool World::toggleRenderMode (RenderMode mode) diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 71231998a6..eef2f8da3f 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -77,6 +77,7 @@ namespace MWWorld bool mSky; Environment& mEnvironment; int mNextDynamicRecord; + bool bCollision; Cells mCells; From 2d0e83a2cf55da1f4830bd587d5f6505a96228cb Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 30 Jan 2012 00:06:29 -0500 Subject: [PATCH 20/45] Reversing changes --- apps/openmw/mwworld/scene.cpp | 1 - apps/openmw/mwworld/world.cpp | 11 ----------- apps/openmw/mwworld/world.hpp | 2 +- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 624c65d579..1b86ce4faa 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -109,7 +109,6 @@ namespace MWWorld void Scene::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos) { - mWorld->makeNewPlayer(); if (adjustPlayerPos) mWorld->getPlayer().setPos (position.pos[0], position.pos[1], position.pos[2]); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 4439d4c666..a5fcfe093c 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -182,17 +182,6 @@ namespace MWWorld } - void World::makeNewPlayer(){ - bool initialCollision = bCollision; - if(bCollision) - toggleCollisionMode(); - MWRender::Player* play = &(mRendering.getPlayer()); - delete mPlayer; - mPlayer = new MWWorld::Player (play, mStore.npcs.find ("player"), *this); - mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); - if(initialCollision) - toggleCollisionMode(); - } World::~World() { diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index eef2f8da3f..db5b0b9cc9 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -221,7 +221,7 @@ namespace MWWorld /// references that are currently not in the rendered scene should be ignored. void setObjectPhysicsRotation(const std::string& handle,Ogre::Quaternion quat); void setObjectPhysicsPosition(const std::string& handle,Ogre::Vector3 vector); - void makeNewPlayer(); + }; } From eea8773be1c752d92e53ea3e07dd07828b4b5210 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Fri, 10 Feb 2012 21:45:46 +0100 Subject: [PATCH 21/45] Changed the order of preference for the configuration files --- apps/launcher/maindialog.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 3bef0b6f9b..dd9f0d653c 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -164,15 +164,15 @@ void MainDialog::createPages() dataDirs = readConfig(file.fileName()); } - // User location - file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); + // Local location + file.setFileName("./openmw.cfg"); + if (file.exists()) { dataDirs = readConfig(file.fileName()); } - // Local location - file.setFileName("./openmw.cfg"); - + // User location + file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); if (file.exists()) { dataDirs = readConfig(file.fileName()); } From bcc4d7a7c98cf03231de39c6d5f185f8c90887a5 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 12 Feb 2012 13:31:19 +0100 Subject: [PATCH 22/45] Issue #133 Handle resources across multiple data directories Signed-off-by: Lukasz Gromanowski --- apps/openmw/engine.cpp | 13 +++++++------ components/file_finder/search.cpp | 32 +++++++++++++++++++------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 31c9470548..2a0c23e51a 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -197,15 +197,16 @@ OMW::Engine::~Engine() void OMW::Engine::loadBSA() { const Files::MultiDirCollection& bsa = mFileCollections.getCollection (".bsa"); - - for (Files::MultiDirCollection::TIter iter (bsa.begin()); iter!=bsa.end(); ++iter) + std::string dataDirectory; + for (Files::MultiDirCollection::TIter iter(bsa.begin()); iter!=bsa.end(); ++iter) { std::cout << "Adding " << iter->second.string() << std::endl; - Bsa::addBSA (iter->second.string()); - } + Bsa::addBSA(iter->second.string()); - //std::cout << "Data dir " << mDataDir.string() << std::endl; - //Bsa::addDir(mDataDir.string(), mFSStrict); + dataDirectory = iter->second.parent_path().string(); + std::cout << "Data dir " << dataDirectory << std::endl; + Bsa::addDir(dataDirectory, mFSStrict); + } } // add resources directory diff --git a/components/file_finder/search.cpp b/components/file_finder/search.cpp index eb4392abc5..06deaf83a6 100644 --- a/components/file_finder/search.cpp +++ b/components/file_finder/search.cpp @@ -4,25 +4,33 @@ void FileFinder::find(const boost::filesystem::path & dir_path, ReturnPath &ret, bool recurse) { - if ( !boost::filesystem::exists( dir_path ) ) + if (boost::filesystem::exists(dir_path)) { - std::cout << "Path " << dir_path << " not found" << std::endl; - return; - } - - boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end - for (boost::filesystem::directory_iterator itr(dir_path); itr != end_itr; ++itr) - { - if (boost::filesystem::is_directory( *itr )) + if (!recurse) { - if (recurse) + boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end + for (boost::filesystem::directory_iterator itr(dir_path); itr != end_itr; ++itr) { - find(*itr, ret); + if (!boost::filesystem::is_directory( *itr )) + { + ret.add(*itr); + } } } else { - ret.add(*itr); + boost::filesystem::recursive_directory_iterator end_itr; // default construction yields past-the-end + for (boost::filesystem::recursive_directory_iterator itr(dir_path); itr != end_itr; ++itr) + { + if (!boost::filesystem::is_directory(*itr)) + { + ret.add(*itr); + } + } } } + else + { + std::cout << "Path " << dir_path << " not found" << std::endl; + } } From 77201d05bc64a052b1a52cd1d92d802c73f0018c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 13 Feb 2012 16:42:01 +0100 Subject: [PATCH 23/45] post-merge fix --- apps/openmw/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 892e7a1881..9e04d1ad00 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -470,7 +470,7 @@ void OMW::Engine::screenshot() // Count screenshots. int shotCount = 0; - const std::string screenshotPath = mCfgMgr.getLocalConfigPath().string(); + const std::string screenshotPath = mCfgMgr.getLocalPath().string(); // Find the first unused filename with a do-while std::ostringstream stream; From 9af08ff18de5403289f053d5da572309d2e5ef03 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 13 Feb 2012 18:34:21 +0100 Subject: [PATCH 24/45] store screenshots in user directory instead of local directory --- apps/openmw/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 9e04d1ad00..2e4beb65f3 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -470,7 +470,7 @@ void OMW::Engine::screenshot() // Count screenshots. int shotCount = 0; - const std::string screenshotPath = mCfgMgr.getLocalPath().string(); + const std::string screenshotPath = mCfgMgr.getUserPath().string(); // Find the first unused filename with a do-while std::ostringstream stream; From e1defd359548b071c92fe6ad9b518d7a186d0eac Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 14 Feb 2012 09:25:12 +0100 Subject: [PATCH 25/45] adjusted the globally installed openmw.cfg file --- files/openmw.cfg | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/files/openmw.cfg b/files/openmw.cfg index f5322ae8c8..f76524b33f 100644 --- a/files/openmw.cfg +++ b/files/openmw.cfg @@ -1,3 +1,5 @@ -data=${MORROWIND_DATA_FILES} +data=?mw?Data Files +data=?global?data +data=?local?data +data-local=?user?data resources=${MORROWIND_RESOURCE_FILES} - From 8277df04b124cbb8d61e13978f24fe796bd2eeec Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 14 Feb 2012 09:26:06 +0100 Subject: [PATCH 26/45] bumping version number --- CMakeLists.txt | 8 ++++---- readme.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d556ae147c..75d26645ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,8 @@ include (OpenMWMacros) # Version set (OPENMW_VERSION_MAJOR 0) -set (OPENMW_VERSION_MINOR 11) -set (OPENMW_VERSION_RELEASE 1) +set (OPENMW_VERSION_MINOR 12) +set (OPENMW_VERSION_RELEASE 0) set (OPENMW_VERSION "${OPENMW_VERSION_MAJOR}.${OPENMW_VERSION_MINOR}.${OPENMW_VERSION_RELEASE}") @@ -451,7 +451,7 @@ if (APPLE) # some library already has be "fixed up", i.e. its id name contains @executable_path, # but library is not embedded in bundle. For example, it's Ogre.framework from Ogre SDK. # Current implementation of GetPrerequsities/BundleUtilities doesn't handle that case. - # + # # Current limitations: # 1. Handles only frameworks, not simple libs INSTALL(CODE " @@ -492,4 +492,4 @@ include(CPack) set(CMAKE_EXE_LINKER_FLAGS "-arch i386") set(CMAKE_CXX_FLAGS "-arch i386") -endif (APPLE) \ No newline at end of file +endif (APPLE) diff --git a/readme.txt b/readme.txt index cfddd9a1fa..a02374b9b1 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ OpenMW: A reimplementation of The Elder Scrolls III: Morrowind OpenMW is an attempt at recreating the engine for the popular role-playing game Morrowind by Bethesda Softworks. You need to own and install the original game for OpenMW to work. -Version: 0.11.1 +Version: 0.12.0 License: GPL (see GPL3.txt for more information) Website: http://www.openmw.org From 7b457c05bc13b93e96e04b37796d712d6fe2f4c7 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 14 Feb 2012 09:39:58 +0100 Subject: [PATCH 27/45] updated readme --- readme.txt | 109 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 10 deletions(-) diff --git a/readme.txt b/readme.txt index a02374b9b1..47dd6d3fd4 100644 --- a/readme.txt +++ b/readme.txt @@ -14,7 +14,7 @@ THIS IS A WORK IN PROGRESS INSTALLATION Windows: -Just unpack to a location of your choice. Currently there is no installer. +Run the installer. Linux: Ubuntu (and most others) @@ -35,25 +35,87 @@ TODO add description here THE DATA PATH -After the installation OpenMW needs to be told where to find the Morrowind data directory. Create a text file named openmw.cfg (location depends on platform) and enter the following line: +The data path tells OpenMW where to find your Morrowind files. From 0.12.0 on OpenMW should be able to +pick up the location of these files on its own, if both Morrowind and OpenMW are installed properly +(installing Morrowind under WINE is considered a proper install). + +If that does not work for you, please check if you have any leftover openmw.cfg files from versions earlier than 0.12.0. These can interfere with the configuration process, so try to remove then. + +If you are running OpenMW without installing it, you still need to manually adjust the data path. Create a text file named openmw.cfg in the location of the binary and enter the following line: data=path to your data directory (where you replace "path to your data directory" with the actual location of your data directory) -On Windows a suitable location for the cfg file is alongside the binary. Currently the binary release comes with such a file pre-generated, but you still need to adjust the data setting. - -On Linux and Mac the default location will be ~/.config/openmw/openmw.cfg. - COMMAND LINE OPTIONS -TODO add description of command line options + +Syntax: openmw +Allowed options: + --help print help message + --version print version information and quit + --data arg (=data) set data directories (later directories have + higher priority) + --data-local arg set local data directory (highest priority) + --resources arg (=resources) set resources directory + --start arg (=Beshara) set initial cell + --master arg master file(s) + --plugin arg plugin file(s) + --fps [=arg(=1)] (=0) fps counter detail (0 = off, 1 = fps counter + , 2 = full detail) + --anim-verbose [=arg(=1)] (=0) output animation indices files + --debug [=arg(=1)] (=0) debug mode + --nosound [=arg(=1)] (=0) disable all sounds + --script-verbose [=arg(=1)] (=0) verbose script output + --new-game [=arg(=1)] (=0) activate char gen/new game mechanics + --script-all [=arg(=1)] (=0) compile all scripts (excluding dialogue scri + pts) at startup + --fs-strict [=arg(=1)] (=0) strict file system handling (no case folding + ) + --encoding arg (=win1252) Character encoding used in OpenMW game messa + ges: + + win1250 - Central and Eastern European such + as Polish, Czech, Slovak, Hungarian, Slovene + , Bosnian, Croatian, Serbian (Latin script), + Romanian and Albanian languages + + win1251 - Cyrillic alphabet such as Russian, + Bulgarian, Serbian Cyrillic and other langua + ges + + win1252 - Western European (Latin) alphabet, + used by default + --report-focus [=arg(=1)] (=0) write name of focussed object to cout CREDITS -Developers: -TODO add list of developers +Current Developers: +Alexander “Ace” Olofsson +athile +Cris “Mirceam” Mihalache +gugus / gus +Jacob “Yacoby” Essex +Jason “jhooks” Hooks +Lukasz “lgro” Gromanowski +Marc “Zini” Zinnschlag +Nikolay “corristo” Kasyanov +Pieter “pvdk” van der Kloet +Sebastian “swick” Wick + +Retired Developers: +Ardekantur +Armin Preiml +Diggory Hardy +Jan Borsodi +Jan-Peter “peppe” Nilsson +Josua Grawitter +Karl-Felix “k1ll” Glatzer +Nicolay Korslund +sergoz +Star-Demon +Yuri Krupenin OpenMW: Thanks to DokterDume for kindly providing us with the Moon and Star logo used as the application icon and project logo. @@ -64,6 +126,33 @@ Thanks to Kevin Ryan for kindly providing us with the icon used for the Data Fil CHANGELOG +0.12.0 + +Bug #154: FPS Drop +Bug #169: Local scripts continue running if associated object is deleted +Bug #174: OpenMW fails to start if the config directory doesn't exist +Bug #187: Missing lighting +Bug #188: Lights without a mesh are not rendered +Bug #191: Taking screenshot causes crash when running installed +Feature #28: Sort out the cell load problem +Feature #31: Allow the player to move away from pre-defined cells +Feature #35: Use alternate storage location for modified object position +Feature #45: NPC animations +Feature #46: Creature Animation +Feature #89: Basic Journal Window +Feature #110: Automatically pick up the path of existing MW-installations +Feature #133: Handle resources across multiple data directories +Feature #134: Generate a suitable default-value for --data-local +Feature #183: More FPS display settings +Task #19: Refactor engine class +Task #109/Feature #162: Automate Packaging +Task #112: Catch exceptions thrown in input handling functions +Task #128/#168: Cleanup Configuration File Handling +Task #131: NPC Activation doesn't work properly +Task #144: MWRender cleanup +Task #155: cmake cleanup + + 0.11.1 Bug #2: Resources loading doesn't work outside of bsa files @@ -90,4 +179,4 @@ Task #14: Replace tabs with 4 spaces Task #18: Move components from global namespace into their own namespace Task #123: refactor header files in components/esm -TODO add old changelog (take pre 0.11.0 changelog from wiki) +TODO add old changelog (take pre 0.11.1 changelog from wiki) From 57a4b198806ba305822e3404cad9bd387918b654 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Wed, 15 Feb 2012 11:27:51 +0400 Subject: [PATCH 28/45] Feature #162 - Need to create app bundle using CMake, not by hand. Almost complete --- CMakeLists.txt | 14 +++++--------- apps/launcher/CMakeLists.txt | 32 +++++++++++++++++--------------- apps/launcher/main.cpp | 9 +++++++++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef31dae076..fb58b01248 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,9 +384,6 @@ endif() if (APPLE) set(INSTALL_SUBDIR OpenMW) - #install(FILES ${MISC_FILES} DESTINATION ../MacOS) - #install(DIRECTORY "${APP_BUNDLE_DIR}/Contents/Plugins" DESTINATION ..) - #install(DIRECTORY "${APP_BUNDLE_DIR}/Contents/Resources/resources" DESTINATION ../Resources) install(DIRECTORY "${APP_BUNDLE_DIR}" USE_SOURCE_PERMISSIONS DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" RENAME "openmw.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) @@ -394,9 +391,6 @@ if (APPLE) install(FILES "${OpenMW_BINARY_DIR}/plugins.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(FILES "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) set(CPACK_GENERATOR "DragNDrop") - # set(CPACK_BUNDLE_PLIST "${CMAKE_SOURCE_DIR}/files/mac/Info.plist") - # set(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/files/mac/openmw.icns") - # set(CPACK_BUNDLE_NAME "OpenMW") set(CPACK_PACKAGE_VERSION ${OPENMW_VERSION}) set(CPACK_PACKAGE_VERSION_MAJOR ${OPENMW_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${OPENMW_VERSION_MINO}) @@ -406,11 +400,13 @@ if (APPLE) set(PLUGINS "") # Scan Plugins dir for *.dylibs - file(GLOB ALL_PLUGINS "${APP_BUNDLE_DIR}/Contents/Plugins/*.dylib") + set(PLUGIN_SEARCH_ROOT "${APP_BUNDLE_DIR}/Contents/Plugins") + file(GLOB_RECURSE ALL_PLUGINS "${PLUGIN_SEARCH_ROOT}/*.dylib") + set(PLUGIN_INSTALL_BASE "\${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR}/${APP_BUNDLE_NAME}/Contents/Plugins") foreach(PLUGIN ${ALL_PLUGINS}) - get_filename_component(PLUGIN_FILENAME ${PLUGIN} NAME) - set(PLUGINS ${PLUGINS} "\${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR}/${APP_BUNDLE_NAME}/Contents/Plugins/${PLUGIN_FILENAME}") + string(REPLACE "${PLUGIN_SEARCH_ROOT}/" "" PLUGIN_RELATIVE "${PLUGIN}") + set(PLUGINS ${PLUGINS} "${PLUGIN_INSTALL_BASE}/${PLUGIN_RELATIVE}") endforeach() #For now, search unresolved dependencies only in default system paths, so if you put unresolveable (i.e. with @executable_path in id name) lib or framework somewhere else, it would fail diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index e46a062055..2879539a75 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -41,8 +41,10 @@ source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER} ${LAUNCHER_HEADER_MOC find_package(Qt4 REQUIRED) set(QT_USE_QTGUI 1) -#find_package(PNG REQUIRED) -#include_directories(${PNG_INCLUDE_DIR}) +if (NOT APPLE) # this dependency can be completely removed, but now it only tested on OS X + find_package(PNG REQUIRED) + include_directories(${PNG_INCLUDE_DIR}) +endif() QT4_ADD_RESOURCES(RCC_SRCS resources.qrc) QT4_WRAP_CPP(MOC_SRCS ${LAUNCHER_HEADER_MOC}) @@ -51,14 +53,14 @@ include(${QT_USE_FILE}) # list here plugins that can't be detected statically, but loaded in runtime # it needed for packaging automatisation -#set(USED_QT_PLUGINS imageformats/libqgif -# imageformats/libqico -# imageformats/libqjpeg -# imageformats/libqmng -# imageformats/libqsvg -# imageformats/libqtga -# imageformats/libqtiff) -# It seems that launcher works without this plugins, but it loads them into memory if they exists +set(USED_QT_PLUGINS imageformats/libqgif + imageformats/libqico + imageformats/libqjpeg + imageformats/libqmng + imageformats/libqsvg + imageformats/libqtga + imageformats/libqtiff) +# It seems that launcher works without this plugins, but it loads them if they exists # Main executable add_executable(omwlauncher @@ -71,7 +73,7 @@ target_link_libraries(omwlauncher ${Boost_LIBRARIES} ${OGRE_LIBRARIES} ${QT_LIBRARIES} -# ${PNG_LIBRARY} + ${PNG_LIBRARY} components ) @@ -86,10 +88,10 @@ if (APPLE) "${APP_BUNDLE_DIR}/../launcher.cfg") # copy used QT plugins into ${APP_BUNDLE_DIR}/Contents/Plugins - #foreach(PLUGIN ${USED_QT_PLUGINS}) - # get_filename_component(PLUGIN_FILENAME ${PLUGIN} NAME) - # configure_file("${QT_PLUGINS_DIR}/${PLUGIN}.dylib" "${APP_BUNDLE_DIR}/Contents/Plugins/${PLUGIN_FILENAME}.dylib" COPYONLY) - #endforeach() + foreach(PLUGIN ${USED_QT_PLUGINS}) + get_filename_component(PLUGIN_FILENAME ${PLUGIN} NAME) + configure_file("${QT_PLUGINS_DIR}/${PLUGIN}.dylib" "${APP_BUNDLE_DIR}/Contents/Plugins/${PLUGIN}.dylib" COPYONLY) + endforeach() else() configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 4e438a4db1..93d23371e1 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "maindialog.hpp" @@ -17,6 +18,14 @@ int main(int argc, char *argv[]) dir.cdUp(); dir.cdUp(); } + + QDir pluginsPath(QCoreApplication::applicationDirPath()); + pluginsPath.cdUp(); + pluginsPath.cd("Plugins"); + + QStringList libraryPaths; + libraryPaths << pluginsPath.path() << QCoreApplication::applicationDirPath(); + app.setLibraryPaths(libraryPaths); #endif QDir::setCurrent(dir.absolutePath()); From 2020d916ec482ae592b195fec18db4f6c0745589 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Wed, 15 Feb 2012 11:30:35 +0400 Subject: [PATCH 29/45] added missing comment --- apps/launcher/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 93d23371e1..f108882a3f 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -19,6 +19,7 @@ int main(int argc, char *argv[]) dir.cdUp(); } + // force Qt to load only LOCAL plugins, don't touch system Qt installation QDir pluginsPath(QCoreApplication::applicationDirPath()); pluginsPath.cdUp(); pluginsPath.cd("Plugins"); From 80008ed09f516aed4f68efbf253ab6f716c13820 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 15 Feb 2012 22:34:51 +0100 Subject: [PATCH 30/45] Issue #168 - Configuration cleanup Fixed bug with configuration tokens parsing - when something appear after token it should be appended to replaced path. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 34 +++++++++++++++-------- components/files/fixedpath.hpp | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 28d49a50c2..46cd0e053b 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -89,27 +89,37 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) const std::string& path = it->string(); // Check if path contains a token - if (!path.empty() && *path.begin() == '?' && *path.rbegin() == '?') + if (!path.empty() && *path.begin() == '?') { - TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path); - if (tokenIt != mTokensMapping.end()) + std::string::size_type pos = path.find('?', 1); + if (pos != std::string::npos && pos != 0) { - boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))()); - - if (boost::filesystem::is_directory(tempPath)) + TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos + 1)); + if (tokenIt != mTokensMapping.end()) { - (*it) = tempPath; + boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))()); + if (pos < path.length() - 1) + { + // There is something after the token, so we should + // append it to the path + tempPath /= path.substr(pos + 1, path.length() - pos); + } + + if (boost::filesystem::is_directory(tempPath)) + { + (*it) = tempPath; + } + else + { + (*it).clear(); + } } else { + // Clean invalid / unknown token, it will be removed outside the loop (*it).clear(); } } - else - { - // Clean invalid / unknown token, it will be removed outside the loop - (*it).clear(); - } } } diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 1bf582ab9c..0e052fd248 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -86,6 +86,7 @@ struct FixedPath mGlobalPath /= suffix; mLocalDataPath /= suffix; + mUserDataPath /= suffix; mGlobalDataPath /= suffix; } } From 6a71cf21b0faf400db173b8dea3983f3e265fca2 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Thu, 16 Feb 2012 08:52:26 +0100 Subject: [PATCH 31/45] Added OpenAL redistributable to OpenMW installer --- CMakeLists.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d556ae147c..9c702be2ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,10 +348,18 @@ if(WIN32) SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.openmw.org") SET(CPACK_NSIS_INSTALLED_ICON_NAME "omwlauncher.exe") - if(EXISTS "${OpenMW_BINARY_DIR}/vcredist_x86.exe") - INSTALL(FILES "${OpenMW_BINARY_DIR}/vcredist_x86.exe" DESTINATION "redist") + SET(VCREDIST "${OpenMW_BINARY_DIR}/vcredist_x86.exe") + if(EXISTS ${VCREDIST}) + INSTALL(FILES ${VCREDIST} DESTINATION "redist") SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '\\\"$INSTDIR\\\\redist\\\\vcredist_x86.exe\\\" /q'" ) - endif(EXISTS "${OpenMW_BINARY_DIR}/vcredist_x86.exe") + endif(EXISTS ${VCREDIST}) + + SET(OALREDIST "${OpenMW_BINARY_DIR}/oalinst.exe") + if(EXISTS ${OALREDIST}) + INSTALL(FILES ${OALREDIST} DESTINATION "redist") + SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS} + ExecWait '\\\"$INSTDIR\\\\redist\\\\oalinst.exe\\\" /s'" ) + endif(EXISTS ${OALREDIST}) include(CPack) endif(WIN32) From 8244ed58605fc91ac920f1436f3e6c77b340c91e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 16 Feb 2012 09:26:27 +0100 Subject: [PATCH 32/45] workaround for space in paths problem --- files/openmw.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/openmw.cfg b/files/openmw.cfg index f76524b33f..950332cc1c 100644 --- a/files/openmw.cfg +++ b/files/openmw.cfg @@ -1,5 +1,5 @@ -data=?mw?Data Files -data=?global?data -data=?local?data -data-local=?user?data +data="?mw?Data Files" +data="?global?data" +data="?local?data" +data-"local=?user?data" resources=${MORROWIND_RESOURCE_FILES} From 850501e9221daf1a55d31b72c4389da158b338e6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 16 Feb 2012 13:14:16 +0100 Subject: [PATCH 33/45] workaround for the configuration problems --- components/files/configurationmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 46cd0e053b..c6e5534180 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -56,9 +56,9 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { mTokensMapping.insert(std::make_pair(mwToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserDataPath)); - mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalDataPath)); + mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserPath)); + mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, From 8186445de9e2bcb6966c5ef86583493c4225a3b6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 16 Feb 2012 21:06:25 +0100 Subject: [PATCH 34/45] fix for a very silly bug --- files/openmw.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/openmw.cfg b/files/openmw.cfg index 950332cc1c..585b735f30 100644 --- a/files/openmw.cfg +++ b/files/openmw.cfg @@ -1,5 +1,5 @@ data="?mw?Data Files" data="?global?data" data="?local?data" -data-"local=?user?data" +data-local="?user?data" resources=${MORROWIND_RESOURCE_FILES} From 2217847c5753be314a51b1b9263ecc7bdffbec76 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 18 Feb 2012 15:29:40 -0500 Subject: [PATCH 35/45] Fixing a crash --- components/nifogre/ogre_nif_loader.cpp | 23 +++++++++++++++++++++-- components/nifogre/ogre_nif_loader.hpp | 4 +++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 4e3864a674..2ac05f2c83 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -531,6 +531,8 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std { sub->addBoneAssignment(*it); } + if(mSkel.isNull()) + needBoneAssignments.push_back(sub); } // Helper math functions. Reinventing linear algebra for the win! @@ -945,7 +947,8 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { // Add this vertex set to the bounding box bounds.add(optr, numVerts); - shapes.push_back(copy); + if(addShapes) + shapes.push_back(copy); // Create the submesh createOgreSubMesh(shape, material, vertexBoneAssignments); @@ -1066,9 +1069,11 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { - + addShapes = true; mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); } + else if (!mSkel.isNull() && !parentBone) + addShapes = false; if (!mSkel.isNull()) //if there is a skeleton { @@ -1143,8 +1148,11 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, void NIFLoader::loadResource(Resource *resource) { + addShapes = false; allanim.clear(); shapes.clear(); + needBoneAssignments.clear(); + // needBoneAssignments.clear(); mBoundingBox.setNull(); mesh = 0; mSkel.setNull(); @@ -1311,6 +1319,17 @@ void NIFLoader::loadResource(Resource *resource) if (!mSkel.isNull() ) { + for(std::vector::iterator iter = needBoneAssignments.begin(); iter != needBoneAssignments.end(); iter++) + { + int boneIndex = mSkel->getNumBones() - 1; + VertexBoneAssignment vba; + vba.boneIndex = boneIndex; + vba.vertexIndex = 0; + vba.weight = 1; + + + (*iter)->addBoneAssignment(vba); + } mesh->_notifySkeleton(mSkel); } } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index b1e0943f5d..1361ffaca9 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -121,7 +121,7 @@ class NIFLoader : Ogre::ManualResourceLoader private: NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), - mFlipVertexWinding(false), mOutputAnimFiles(false) {} + mFlipVertexWinding(false), mOutputAnimFiles(false), addShapes(false) {} NIFLoader(NIFLoader& n) {} void calculateTransform(); @@ -189,6 +189,8 @@ class NIFLoader : Ogre::ManualResourceLoader std::map,ciLessBoost> allshapesmap; std::vector mAnim; std::vector mS; + std::vector needBoneAssignments; + bool addShapes; }; From e58f2f5363ec8f6f6b3c960335bdc8544f958b8a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 19 Feb 2012 02:01:15 -0500 Subject: [PATCH 36/45] Eliminating unnecessary data from skeletons and shape saving --- apps/openmw/class2/activator.cpp | 66 ++++++ apps/openmw/class2/activator.hpp | 28 +++ apps/openmw/class2/apparatus.cpp | 81 ++++++++ apps/openmw/class2/apparatus.hpp | 37 ++++ apps/openmw/class2/armor.cpp | 93 +++++++++ apps/openmw/class2/armor.hpp | 43 ++++ apps/openmw/class2/book.cpp | 83 ++++++++ apps/openmw/class2/book.hpp | 37 ++++ apps/openmw/class2/classes.cpp | 50 +++++ apps/openmw/class2/classes.hpp | 10 + apps/openmw/class2/clothing.cpp | 81 ++++++++ apps/openmw/class2/clothing.hpp | 37 ++++ apps/openmw/class2/container.cpp | 80 +++++++ apps/openmw/class2/container.hpp | 33 +++ apps/openmw/class2/containerutil.hpp | 28 +++ apps/openmw/class2/creature.cpp | 138 +++++++++++++ apps/openmw/class2/creature.hpp | 51 +++++ apps/openmw/class2/creaturelevlist.cpp | 19 ++ apps/openmw/class2/creaturelevlist.hpp | 20 ++ apps/openmw/class2/door.cpp | 129 ++++++++++++ apps/openmw/class2/door.hpp | 39 ++++ apps/openmw/class2/ingredient.cpp | 82 ++++++++ apps/openmw/class2/ingredient.hpp | 37 ++++ apps/openmw/class2/itemlevlist.cpp | 19 ++ apps/openmw/class2/itemlevlist.hpp | 20 ++ apps/openmw/class2/light.cpp | 110 ++++++++++ apps/openmw/class2/light.hpp | 42 ++++ apps/openmw/class2/lockpick.cpp | 81 ++++++++ apps/openmw/class2/lockpick.hpp | 37 ++++ apps/openmw/class2/misc.cpp | 80 +++++++ apps/openmw/class2/misc.hpp | 37 ++++ apps/openmw/class2/npc.cpp | 276 +++++++++++++++++++++++++ apps/openmw/class2/npc.hpp | 72 +++++++ apps/openmw/class2/potion.cpp | 81 ++++++++ apps/openmw/class2/potion.hpp | 37 ++++ apps/openmw/class2/probe.cpp | 81 ++++++++ apps/openmw/class2/probe.hpp | 37 ++++ apps/openmw/class2/repair.cpp | 80 +++++++ apps/openmw/class2/repair.hpp | 37 ++++ apps/openmw/class2/static.cpp | 52 +++++ apps/openmw/class2/static.hpp | 26 +++ apps/openmw/class2/weapon.cpp | 94 +++++++++ apps/openmw/class2/weapon.hpp | 43 ++++ apps/openmw/mwrender/animation.cpp | 7 +- components/nifogre/ogre_nif_loader.cpp | 19 +- components/nifogre/ogre_nif_loader.hpp | 4 +- 46 files changed, 2661 insertions(+), 13 deletions(-) create mode 100644 apps/openmw/class2/activator.cpp create mode 100644 apps/openmw/class2/activator.hpp create mode 100644 apps/openmw/class2/apparatus.cpp create mode 100644 apps/openmw/class2/apparatus.hpp create mode 100644 apps/openmw/class2/armor.cpp create mode 100644 apps/openmw/class2/armor.hpp create mode 100644 apps/openmw/class2/book.cpp create mode 100644 apps/openmw/class2/book.hpp create mode 100644 apps/openmw/class2/classes.cpp create mode 100644 apps/openmw/class2/classes.hpp create mode 100644 apps/openmw/class2/clothing.cpp create mode 100644 apps/openmw/class2/clothing.hpp create mode 100644 apps/openmw/class2/container.cpp create mode 100644 apps/openmw/class2/container.hpp create mode 100644 apps/openmw/class2/containerutil.hpp create mode 100644 apps/openmw/class2/creature.cpp create mode 100644 apps/openmw/class2/creature.hpp create mode 100644 apps/openmw/class2/creaturelevlist.cpp create mode 100644 apps/openmw/class2/creaturelevlist.hpp create mode 100644 apps/openmw/class2/door.cpp create mode 100644 apps/openmw/class2/door.hpp create mode 100644 apps/openmw/class2/ingredient.cpp create mode 100644 apps/openmw/class2/ingredient.hpp create mode 100644 apps/openmw/class2/itemlevlist.cpp create mode 100644 apps/openmw/class2/itemlevlist.hpp create mode 100644 apps/openmw/class2/light.cpp create mode 100644 apps/openmw/class2/light.hpp create mode 100644 apps/openmw/class2/lockpick.cpp create mode 100644 apps/openmw/class2/lockpick.hpp create mode 100644 apps/openmw/class2/misc.cpp create mode 100644 apps/openmw/class2/misc.hpp create mode 100644 apps/openmw/class2/npc.cpp create mode 100644 apps/openmw/class2/npc.hpp create mode 100644 apps/openmw/class2/potion.cpp create mode 100644 apps/openmw/class2/potion.hpp create mode 100644 apps/openmw/class2/probe.cpp create mode 100644 apps/openmw/class2/probe.hpp create mode 100644 apps/openmw/class2/repair.cpp create mode 100644 apps/openmw/class2/repair.hpp create mode 100644 apps/openmw/class2/static.cpp create mode 100644 apps/openmw/class2/static.hpp create mode 100644 apps/openmw/class2/weapon.cpp create mode 100644 apps/openmw/class2/weapon.hpp diff --git a/apps/openmw/class2/activator.cpp b/apps/openmw/class2/activator.cpp new file mode 100644 index 0000000000..086cb433dd --- /dev/null +++ b/apps/openmw/class2/activator.cpp @@ -0,0 +1,66 @@ + +#include "activator.hpp" +#include "../mwrender/objects.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + + +namespace MWClass +{ + void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Activator::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + std::string Activator::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Activator::registerSelf() + { + boost::shared_ptr instance (new Activator); + + registerClass (typeid (ESM::Activator).name(), instance); + } +} diff --git a/apps/openmw/class2/activator.hpp b/apps/openmw/class2/activator.hpp new file mode 100644 index 0000000000..08be8a5ff1 --- /dev/null +++ b/apps/openmw/class2/activator.hpp @@ -0,0 +1,28 @@ +#ifndef GAME_MWCLASS_ACTIVATOR_H +#define GAME_MWCLASS_ACTIVATOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Activator : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/apparatus.cpp b/apps/openmw/class2/apparatus.cpp new file mode 100644 index 0000000000..4c5ba07219 --- /dev/null +++ b/apps/openmw/class2/apparatus.cpp @@ -0,0 +1,81 @@ + +#include "apparatus.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Apparatus::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Apparatus::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Apparatus::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Apparatus::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.appas); + } + + std::string Apparatus::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Apparatus::registerSelf() + { + boost::shared_ptr instance (new Apparatus); + + registerClass (typeid (ESM::Apparatus).name(), instance); + } +} diff --git a/apps/openmw/class2/apparatus.hpp b/apps/openmw/class2/apparatus.hpp new file mode 100644 index 0000000000..4c8a2c0e2d --- /dev/null +++ b/apps/openmw/class2/apparatus.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_APPARATUS_H +#define GAME_MWCLASS_APPARATUS_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Apparatus : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/armor.cpp b/apps/openmw/class2/armor.cpp new file mode 100644 index 0000000000..2ad1dbfa25 --- /dev/null +++ b/apps/openmw/class2/armor.cpp @@ -0,0 +1,93 @@ + +#include "armor.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Armor::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Armor::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + bool Armor::hasItemHealth (const MWWorld::Ptr& ptr) const + { + return true; + } + + int Armor::getItemMaxHealth (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->data.health; + } + + void Armor::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.armors); + } + + std::string Armor::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Armor::registerSelf() + { + boost::shared_ptr instance (new Armor); + + registerClass (typeid (ESM::Armor).name(), instance); + } +} diff --git a/apps/openmw/class2/armor.hpp b/apps/openmw/class2/armor.hpp new file mode 100644 index 0000000000..c5f9812b79 --- /dev/null +++ b/apps/openmw/class2/armor.hpp @@ -0,0 +1,43 @@ +#ifndef GAME_MWCLASS_ARMOR_H +#define GAME_MWCLASS_ARMOR_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Armor : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; + ///< \return Item health data available? + + virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; + ///< Return item max health or throw an exception, if class does not have item health + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/book.cpp b/apps/openmw/class2/book.cpp new file mode 100644 index 0000000000..5c0d8767a0 --- /dev/null +++ b/apps/openmw/class2/book.cpp @@ -0,0 +1,83 @@ + +#include "book.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Book::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Book::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Book::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Book::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + // TODO implement reading + + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Book::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.books); + } + + std::string Book::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Book::registerSelf() + { + boost::shared_ptr instance (new Book); + + registerClass (typeid (ESM::Book).name(), instance); + } +} diff --git a/apps/openmw/class2/book.hpp b/apps/openmw/class2/book.hpp new file mode 100644 index 0000000000..f0e38cceba --- /dev/null +++ b/apps/openmw/class2/book.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_BOOK_H +#define GAME_MWCLASS_BOOK_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Book : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/classes.cpp b/apps/openmw/class2/classes.cpp new file mode 100644 index 0000000000..e9538a6cb4 --- /dev/null +++ b/apps/openmw/class2/classes.cpp @@ -0,0 +1,50 @@ + +#include "classes.hpp" + +#include "activator.hpp" +#include "creature.hpp" +#include "npc.hpp" +#include "weapon.hpp" +#include "armor.hpp" +#include "potion.hpp" +#include "apparatus.hpp" +#include "book.hpp" +#include "clothing.hpp" +#include "container.hpp" +#include "door.hpp" +#include "ingredient.hpp" +#include "creaturelevlist.hpp" +#include "itemlevlist.hpp" +#include "light.hpp" +#include "lockpick.hpp" +#include "misc.hpp" +#include "probe.hpp" +#include "repair.hpp" +#include "static.hpp" + +namespace MWClass +{ + void registerClasses() + { + Activator::registerSelf(); + Creature::registerSelf(); + Npc::registerSelf(); + Weapon::registerSelf(); + Armor::registerSelf(); + Potion::registerSelf(); + Apparatus::registerSelf(); + Book::registerSelf(); + Clothing::registerSelf(); + Container::registerSelf(); + Door::registerSelf(); + Ingredient::registerSelf(); + CreatureLevList::registerSelf(); + ItemLevList::registerSelf(); + Light::registerSelf(); + Lockpick::registerSelf(); + Miscellaneous::registerSelf(); + Probe::registerSelf(); + Repair::registerSelf(); + Static::registerSelf(); + } +} diff --git a/apps/openmw/class2/classes.hpp b/apps/openmw/class2/classes.hpp new file mode 100644 index 0000000000..0ab90b677b --- /dev/null +++ b/apps/openmw/class2/classes.hpp @@ -0,0 +1,10 @@ +#ifndef GAME_MWCLASS_CLASSES_H +#define GAME_MWCLASS_CLASSES_H + +namespace MWClass +{ + void registerClasses(); + ///< register all known classes +} + +#endif diff --git a/apps/openmw/class2/clothing.cpp b/apps/openmw/class2/clothing.cpp new file mode 100644 index 0000000000..b81a181f4b --- /dev/null +++ b/apps/openmw/class2/clothing.cpp @@ -0,0 +1,81 @@ + +#include "clothing.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Clothing::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Clothing::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Clothing::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Clothing::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Clothing::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.clothes); + } + + std::string Clothing::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Clothing::registerSelf() + { + boost::shared_ptr instance (new Clothing); + + registerClass (typeid (ESM::Clothing).name(), instance); + } +} diff --git a/apps/openmw/class2/clothing.hpp b/apps/openmw/class2/clothing.hpp new file mode 100644 index 0000000000..76c2c4a3e4 --- /dev/null +++ b/apps/openmw/class2/clothing.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_CLOTHING_H +#define GAME_MWCLASS_CLOTHING_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Clothing : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/container.cpp b/apps/openmw/class2/container.cpp new file mode 100644 index 0000000000..fff3a9bda7 --- /dev/null +++ b/apps/openmw/class2/container.cpp @@ -0,0 +1,80 @@ + +#include "container.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + +namespace MWClass +{ + void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Container::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Container::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + MWWorld::ContainerStore& Container::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + + std::string Container::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Container::registerSelf() + { + boost::shared_ptr instance (new Container); + + registerClass (typeid (ESM::Container).name(), instance); + } +} diff --git a/apps/openmw/class2/container.hpp b/apps/openmw/class2/container.hpp new file mode 100644 index 0000000000..01763870ad --- /dev/null +++ b/apps/openmw/class2/container.hpp @@ -0,0 +1,33 @@ +#ifndef GAME_MWCLASS_CONTAINER_H +#define GAME_MWCLASS_CONTAINER_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Container : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/containerutil.hpp b/apps/openmw/class2/containerutil.hpp new file mode 100644 index 0000000000..76bdf02361 --- /dev/null +++ b/apps/openmw/class2/containerutil.hpp @@ -0,0 +1,28 @@ +#ifndef GAME_MWCLASS_CONTAINERUTIL_H +#define GAME_MWCLASS_CONTAINERUTIL_H + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/containerstore.hpp" + +namespace MWClass +{ + template + void insertIntoContainerStore (const MWWorld::Ptr& ptr, + ESMS::CellRefList& containerStore) + { + if (!ptr.isEmpty()) + { + // TODO check stacking + + ESMS::LiveCellRef cellRef(ptr.getCellRef(), ptr.get()->base); + cellRef.mData = ptr.getRefData(); + + containerStore.list.push_back (cellRef); + + } + } +} + +#endif diff --git a/apps/openmw/class2/creature.cpp b/apps/openmw/class2/creature.cpp new file mode 100644 index 0000000000..5aa203a49a --- /dev/null +++ b/apps/openmw/class2/creature.cpp @@ -0,0 +1,138 @@ + +#include "creature.hpp" + +#include + +#include "../mwmechanics/creaturestats.hpp" + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontalk.hpp" +#include "../mwworld/environment.hpp" + + +#include "../mwmechanics/mechanicsmanager.hpp" + +namespace MWClass +{ + std::string Creature::getId (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->mId; + } + + void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + + /*ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + {*/ + MWRender::Actors& actors = renderingInterface.getActors(); + actors.insertCreature(ptr); + + } + + void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertActorPhysics(ptr, "meshes\\" + model); + } + + } + + void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->addActor (ptr); + } + + void Creature::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->removeActor (ptr); + } + + std::string Creature::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + MWMechanics::CreatureStats& Creature::getCreatureStats (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getCreatureStats().get()) + { + boost::shared_ptr stats ( + new MWMechanics::CreatureStats); + + ESMS::LiveCellRef *ref = ptr.get(); + + stats->mAttributes[0].set (ref->base->data.strength); + stats->mAttributes[1].set (ref->base->data.intelligence); + stats->mAttributes[2].set (ref->base->data.willpower); + stats->mAttributes[3].set (ref->base->data.agility); + stats->mAttributes[4].set (ref->base->data.speed); + stats->mAttributes[5].set (ref->base->data.endurance); + stats->mAttributes[6].set (ref->base->data.personality); + stats->mAttributes[7].set (ref->base->data.luck); + stats->mDynamic[0].set (ref->base->data.health); + stats->mDynamic[1].set (ref->base->data.mana); + stats->mDynamic[2].set (ref->base->data.fatigue); + + stats->mLevel = ref->base->data.level; + + ptr.getRefData().getCreatureStats() = stats; + } + + return *ptr.getRefData().getCreatureStats(); + } + + boost::shared_ptr Creature::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr (new MWWorld::ActionTalk (ptr)); + } + + MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + + std::string Creature::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Creature::registerSelf() + { + boost::shared_ptr instance (new Creature); + + registerClass (typeid (ESM::Creature).name(), instance); + } +} diff --git a/apps/openmw/class2/creature.hpp b/apps/openmw/class2/creature.hpp new file mode 100644 index 0000000000..b7b654bc01 --- /dev/null +++ b/apps/openmw/class2/creature.hpp @@ -0,0 +1,51 @@ +#ifndef GAME_MWCLASS_CREATURE_H +#define GAME_MWCLASS_CREATURE_H + +#include "../mwworld/class.hpp" +#include "../mwrender/renderinginterface.hpp" +#include "../mwrender/actors.hpp" + + +namespace MWClass +{ + class Creature : public MWWorld::Class + { + public: + + virtual std::string getId (const MWWorld::Ptr& ptr) const; + ///< Return ID of \a ptr + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; + ///< Return creature stats + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/creaturelevlist.cpp b/apps/openmw/class2/creaturelevlist.cpp new file mode 100644 index 0000000000..53dd34bb48 --- /dev/null +++ b/apps/openmw/class2/creaturelevlist.cpp @@ -0,0 +1,19 @@ + +#include "creaturelevlist.hpp" + +#include + +namespace MWClass +{ + std::string CreatureLevList::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + + void CreatureLevList::registerSelf() + { + boost::shared_ptr instance (new CreatureLevList); + + registerClass (typeid (ESM::CreatureLevList).name(), instance); + } +} diff --git a/apps/openmw/class2/creaturelevlist.hpp b/apps/openmw/class2/creaturelevlist.hpp new file mode 100644 index 0000000000..81965efd58 --- /dev/null +++ b/apps/openmw/class2/creaturelevlist.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_CREATURELEVLIST_H +#define GAME_MWCLASS_CREATURELEVLIST_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class CreatureLevList : public MWWorld::Class + { + public: + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/door.cpp b/apps/openmw/class2/door.cpp new file mode 100644 index 0000000000..baced8a9cc --- /dev/null +++ b/apps/openmw/class2/door.cpp @@ -0,0 +1,129 @@ + +#include "door.hpp" + +#include + +#include + +#include "../mwworld/player.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/nullaction.hpp" +#include "../mwworld/actionteleport.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "../mwrender/objects.hpp" + +#include + +namespace MWClass +{ + void Door::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Door::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (ref->ref.teleport && !ref->ref.destCell.empty()) // TODO doors that lead to exteriors + return ref->ref.destCell; + + return ref->base->name; + } + + boost::shared_ptr Door::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (ptr.getCellRef().lockLevel>0) + { + // TODO check for key + // TODO report failure to player (message, sound?). Look up behaviour of original MW. + std::cout << "Locked!" << std::endl; + return boost::shared_ptr (new MWWorld::NullAction); + } + + // TODO check trap + + if (ref->ref.teleport) + { + // teleport door + if (environment.mWorld->getPlayer().getPlayer()==actor) + { + // the player is using the door + return boost::shared_ptr ( + new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest)); + } + else + { + // another NPC or a create is using the door + // TODO return action for teleporting other NPC/creature + return boost::shared_ptr (new MWWorld::NullAction); + } + } + else + { + // animated door + // TODO return action for rotating the door + return boost::shared_ptr (new MWWorld::NullAction); + } + } + + void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const + { + if (lockLevel<0) + lockLevel = 0; + + ptr.getCellRef().lockLevel = lockLevel; + } + + void Door::unlock (const MWWorld::Ptr& ptr) const + { + ptr.getCellRef().lockLevel = 0; + } + + std::string Door::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Door::registerSelf() + { + boost::shared_ptr instance (new Door); + + registerClass (typeid (ESM::Door).name(), instance); + } +} diff --git a/apps/openmw/class2/door.hpp b/apps/openmw/class2/door.hpp new file mode 100644 index 0000000000..c230cf3576 --- /dev/null +++ b/apps/openmw/class2/door.hpp @@ -0,0 +1,39 @@ +#ifndef GAME_MWCLASS_DOOR_H +#define GAME_MWCLASS_DOOR_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Door : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void lock (const MWWorld::Ptr& ptr, int lockLevel) const; + ///< Lock object + + virtual void unlock (const MWWorld::Ptr& ptr) const; + ///< Unlock object + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/ingredient.cpp b/apps/openmw/class2/ingredient.cpp new file mode 100644 index 0000000000..42e3d11e49 --- /dev/null +++ b/apps/openmw/class2/ingredient.cpp @@ -0,0 +1,82 @@ + +#include "ingredient.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Ingredient::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Ingredient::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Ingredient::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Ingredient::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.ingreds); + } + + std::string Ingredient::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Ingredient::registerSelf() + { + boost::shared_ptr instance (new Ingredient); + + registerClass (typeid (ESM::Ingredient).name(), instance); + } +} diff --git a/apps/openmw/class2/ingredient.hpp b/apps/openmw/class2/ingredient.hpp new file mode 100644 index 0000000000..47bd1a9e5c --- /dev/null +++ b/apps/openmw/class2/ingredient.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_INGREDIENT_H +#define GAME_MWCLASS_INGREDIENT_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Ingredient : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/itemlevlist.cpp b/apps/openmw/class2/itemlevlist.cpp new file mode 100644 index 0000000000..6ed9ab2e53 --- /dev/null +++ b/apps/openmw/class2/itemlevlist.cpp @@ -0,0 +1,19 @@ + +#include "itemlevlist.hpp" + +#include + +namespace MWClass +{ + std::string ItemLevList::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + + void ItemLevList::registerSelf() + { + boost::shared_ptr instance (new ItemLevList); + + registerClass (typeid (ESM::ItemLevList).name(), instance); + } +} diff --git a/apps/openmw/class2/itemlevlist.hpp b/apps/openmw/class2/itemlevlist.hpp new file mode 100644 index 0000000000..0b71b072c8 --- /dev/null +++ b/apps/openmw/class2/itemlevlist.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_ITEMLEVLIST_H +#define GAME_MWCLASS_ITEMLEVLIST_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class ItemLevList : public MWWorld::Class + { + public: + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/light.cpp b/apps/openmw/class2/light.cpp new file mode 100644 index 0000000000..a3ceea4a68 --- /dev/null +++ b/apps/openmw/class2/light.cpp @@ -0,0 +1,110 @@ + +#include "light.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" +#include "../mwworld/nullaction.hpp" +#include "../mwworld/environment.hpp" + +#include "../mwsound/soundmanager.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Light::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + const int color = ref->base->data.color; + const float r = ((color >> 0) & 0xFF) / 255.0f; + const float g = ((color >> 8) & 0xFF) / 255.0f; + const float b = ((color >> 16) & 0xFF) / 255.0f; + const float radius = float (ref->base->data.radius); + objects.insertLight (ptr, r, g, b, radius); + } + } + + void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + void Light::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (!ref->base->sound.empty()) + { + environment.mSoundManager->playSound3D (ptr, ref->base->sound, 1.0, 1.0, true); + } + } + + std::string Light::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (ref->base->model.empty()) + return ""; + + return ref->base->name; + } + + boost::shared_ptr Light::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (!(ref->base->data.flags & ESM::Light::Carry)) + return boost::shared_ptr (new MWWorld::NullAction); + + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Light::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.lights); + } + + std::string Light::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Light::registerSelf() + { + boost::shared_ptr instance (new Light); + + registerClass (typeid (ESM::Light).name(), instance); + } +} diff --git a/apps/openmw/class2/light.hpp b/apps/openmw/class2/light.hpp new file mode 100644 index 0000000000..34421ff513 --- /dev/null +++ b/apps/openmw/class2/light.hpp @@ -0,0 +1,42 @@ +#ifndef GAME_MWCLASS_LIGHT_H +#define GAME_MWCLASS_LIGHT_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Light : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + /// \attention This is not the same as the script instruction with the same name. References + /// should only be enabled while in an active cell. + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/lockpick.cpp b/apps/openmw/class2/lockpick.cpp new file mode 100644 index 0000000000..c07d5592c7 --- /dev/null +++ b/apps/openmw/class2/lockpick.cpp @@ -0,0 +1,81 @@ + +#include "lockpick.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Lockpick::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + + std::string Lockpick::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Lockpick::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Lockpick::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.lockpicks); + } + + std::string Lockpick::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Lockpick::registerSelf() + { + boost::shared_ptr instance (new Lockpick); + + registerClass (typeid (ESM::Tool).name(), instance); + } +} diff --git a/apps/openmw/class2/lockpick.hpp b/apps/openmw/class2/lockpick.hpp new file mode 100644 index 0000000000..c5f1539b4c --- /dev/null +++ b/apps/openmw/class2/lockpick.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_LOCKPICK_H +#define GAME_MWCLASS_LOCKPICK_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Lockpick : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/misc.cpp b/apps/openmw/class2/misc.cpp new file mode 100644 index 0000000000..a58142905c --- /dev/null +++ b/apps/openmw/class2/misc.cpp @@ -0,0 +1,80 @@ + +#include "misc.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Miscellaneous::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Miscellaneous::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Miscellaneous::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Miscellaneous::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Miscellaneous::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.miscItems); + } + + std::string Miscellaneous::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Miscellaneous::registerSelf() + { + boost::shared_ptr instance (new Miscellaneous); + + registerClass (typeid (ESM::Miscellaneous).name(), instance); + } +} diff --git a/apps/openmw/class2/misc.hpp b/apps/openmw/class2/misc.hpp new file mode 100644 index 0000000000..36ee2c1b26 --- /dev/null +++ b/apps/openmw/class2/misc.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_MISC_H +#define GAME_MWCLASS_MISC_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Miscellaneous : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/npc.cpp b/apps/openmw/class2/npc.cpp new file mode 100644 index 0000000000..acb0a5a351 --- /dev/null +++ b/apps/openmw/class2/npc.cpp @@ -0,0 +1,276 @@ + +#include "npc.hpp" + +#include + +#include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/npcstats.hpp" + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontalk.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "../mwmechanics/mechanicsmanager.hpp" +#include + +namespace +{ + const Ogre::Radian kOgrePi (Ogre::Math::PI); + const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0)); +} + +namespace MWClass +{ + std::string Npc::getId (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->mId; + } + + void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + renderingInterface.getActors().insertNPC(ptr); + } + + void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + + + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + std::string headID = ref->base->head; + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); + bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; + + + std::string smodel = "meshes\\base_anim.nif"; + if(beast) + smodel = "meshes\\base_animkna.nif"; + physics.insertActorPhysics(ptr, smodel); + + + } + + void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->addActor (ptr); + } + + void Npc::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->removeActor (ptr); + } + + std::string Npc::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getCreatureStats().get()) + { + boost::shared_ptr stats ( + new MWMechanics::CreatureStats); + + ESMS::LiveCellRef *ref = ptr.get(); + + stats->mAttributes[0].set (ref->base->npdt52.strength); + stats->mAttributes[1].set (ref->base->npdt52.intelligence); + stats->mAttributes[2].set (ref->base->npdt52.willpower); + stats->mAttributes[3].set (ref->base->npdt52.agility); + stats->mAttributes[4].set (ref->base->npdt52.speed); + stats->mAttributes[5].set (ref->base->npdt52.endurance); + stats->mAttributes[6].set (ref->base->npdt52.personality); + stats->mAttributes[7].set (ref->base->npdt52.luck); + stats->mDynamic[0].set (ref->base->npdt52.health); + stats->mDynamic[1].set (ref->base->npdt52.mana); + stats->mDynamic[2].set (ref->base->npdt52.fatigue); + + stats->mLevel = ref->base->npdt52.level; + + ptr.getRefData().getCreatureStats() = stats; + } + + return *ptr.getRefData().getCreatureStats(); + } + + MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getNpcStats().get()) + { + boost::shared_ptr stats ( + new MWMechanics::NpcStats); + + ESMS::LiveCellRef *ref = ptr.get(); + + if (!ref->base->faction.empty()) + { + // TODO research how initial rank is stored. The information in loadnpc.hpp are at + // best very unclear. + stats->mFactionRank[ref->base->faction] = 0; + } + + for (int i=0; i<27; ++i) + stats->mSkill[i].setBase (ref->base->npdt52.skills[i]); + + ptr.getRefData().getNpcStats() = stats; + } + + return *ptr.getRefData().getNpcStats(); + } + + boost::shared_ptr Npc::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr (new MWWorld::ActionTalk (ptr)); + } + + MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + + std::string Npc::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Npc::setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const + { + MWMechanics::NpcStats& stats = getNpcStats (ptr); + + switch (stance) + { + case Run: + + stats.mForceRun = force; + break; + + case Sneak: + + stats.mForceSneak = force; + break; + + case Combat: + + throw std::runtime_error ("combat stance not enforcable for NPCs"); + } + } + + void Npc::setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const + { + MWMechanics::NpcStats& stats = getNpcStats (ptr); + + switch (stance) + { + case Run: + + stats.mRun = set; + break; + + case Sneak: + + stats.mSneak = set; + break; + + case Combat: + + stats.mCombat = set; + break; + } + } + + bool Npc::getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce) const + { + MWMechanics::NpcStats& stats = getNpcStats (ptr); + + switch (stance) + { + case Run: + + if (!ignoreForce && stats.mForceRun) + return true; + + return stats.mRun; + + case Sneak: + + if (!ignoreForce && stats.mForceSneak) + return true; + + return stats.mSneak; + + case Combat: + + return stats.mCombat; + } + + return false; + } + + float Npc::getSpeed (const MWWorld::Ptr& ptr) const + { + return getStance (ptr, Run) ? 600 : 300; // TODO calculate these values from stats + } + + MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getMovement().get()) + { + boost::shared_ptr movement ( + new MWMechanics::Movement); + + ptr.getRefData().getMovement() = movement; + } + + return *ptr.getRefData().getMovement(); + } + + Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const + { + Ogre::Vector3 vector (0, 0, 0); + + if (ptr.getRefData().getMovement().get()) + { + vector.x = - ptr.getRefData().getMovement()->mLeftRight * 200; + vector.y = ptr.getRefData().getMovement()->mForwardBackward * 200; + + if (getStance (ptr, Run, false)) + vector *= 2; + } + + return vector; + } + + void Npc::registerSelf() + { + boost::shared_ptr instance (new Npc); + + registerClass (typeid (ESM::NPC).name(), instance); + } +} diff --git a/apps/openmw/class2/npc.hpp b/apps/openmw/class2/npc.hpp new file mode 100644 index 0000000000..cc9dbef7fa --- /dev/null +++ b/apps/openmw/class2/npc.hpp @@ -0,0 +1,72 @@ +#ifndef GAME_MWCLASS_NPC_H +#define GAME_MWCLASS_NPC_H + +#include "../mwworld/class.hpp" + + +namespace MWClass +{ + class Npc : public MWWorld::Class + { + public: + + virtual std::string getId (const MWWorld::Ptr& ptr) const; + ///< Return ID of \a ptr + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; + ///< Return creature stats + + virtual MWMechanics::NpcStats& getNpcStats (const MWWorld::Ptr& ptr) const; + ///< Return NPC stats + + virtual MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + virtual void setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const; + ///< Force or unforce a stance. + + virtual void setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const; + ///< Set or unset a stance. + + virtual bool getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce = false) + const; + ////< Check if a stance is active or not. + + virtual float getSpeed (const MWWorld::Ptr& ptr) const; + ///< Return movement speed. + + virtual MWMechanics::Movement& getMovementSettings (const MWWorld::Ptr& ptr) const; + ///< Return desired movement. + + virtual Ogre::Vector3 getMovementVector (const MWWorld::Ptr& ptr) const; + ///< Return desired movement vector (determined based on movement settings, + /// stance and stats). + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/potion.cpp b/apps/openmw/class2/potion.cpp new file mode 100644 index 0000000000..0ab1c7aad6 --- /dev/null +++ b/apps/openmw/class2/potion.cpp @@ -0,0 +1,81 @@ + +#include "potion.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Potion::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Potion::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Potion::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.potions); + } + + std::string Potion::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Potion::registerSelf() + { + boost::shared_ptr instance (new Potion); + + registerClass (typeid (ESM::Potion).name(), instance); + } +} diff --git a/apps/openmw/class2/potion.hpp b/apps/openmw/class2/potion.hpp new file mode 100644 index 0000000000..85678121fb --- /dev/null +++ b/apps/openmw/class2/potion.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_POTION_H +#define GAME_MWCLASS_POTION_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Potion : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/probe.cpp b/apps/openmw/class2/probe.cpp new file mode 100644 index 0000000000..83c0e1ef47 --- /dev/null +++ b/apps/openmw/class2/probe.cpp @@ -0,0 +1,81 @@ + +#include "probe.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + void Probe::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Probe::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + + std::string Probe::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + boost::shared_ptr Probe::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Probe::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.probes); + } + + std::string Probe::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Probe::registerSelf() + { + boost::shared_ptr instance (new Probe); + + registerClass (typeid (ESM::Probe).name(), instance); + } +} diff --git a/apps/openmw/class2/probe.hpp b/apps/openmw/class2/probe.hpp new file mode 100644 index 0000000000..d7b9df7385 --- /dev/null +++ b/apps/openmw/class2/probe.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_PROBE_H +#define GAME_MWCLASS_PROBE_H + +#include "../mwworld/class.hpp" + + +namespace MWClass +{ + class Probe : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/repair.cpp b/apps/openmw/class2/repair.cpp new file mode 100644 index 0000000000..feee7e988b --- /dev/null +++ b/apps/openmw/class2/repair.cpp @@ -0,0 +1,80 @@ + +#include "repair.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Repair::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Repair::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Repair::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Repair::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Repair::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.repairs); + } + + std::string Repair::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Repair::registerSelf() + { + boost::shared_ptr instance (new Repair); + + registerClass (typeid (ESM::Repair).name(), instance); + } +} diff --git a/apps/openmw/class2/repair.hpp b/apps/openmw/class2/repair.hpp new file mode 100644 index 0000000000..1e0ea51785 --- /dev/null +++ b/apps/openmw/class2/repair.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_REPAIR_H +#define GAME_MWCLASS_REPAIR_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Repair : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/static.cpp b/apps/openmw/class2/static.cpp new file mode 100644 index 0000000000..af14bb3069 --- /dev/null +++ b/apps/openmw/class2/static.cpp @@ -0,0 +1,52 @@ + +#include "static.hpp" + +#include + +#include "../mwworld/ptr.hpp" + + +namespace MWClass +{ + void Static::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Static::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Static::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + + void Static::registerSelf() + { + boost::shared_ptr instance (new Static); + + registerClass (typeid (ESM::Static).name(), instance); + } +} diff --git a/apps/openmw/class2/static.hpp b/apps/openmw/class2/static.hpp new file mode 100644 index 0000000000..be3fdb1804 --- /dev/null +++ b/apps/openmw/class2/static.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_MWCLASS_STATIC_H +#define GAME_MWCLASS_STATIC_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Static : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/weapon.cpp b/apps/openmw/class2/weapon.cpp new file mode 100644 index 0000000000..d5f7e68536 --- /dev/null +++ b/apps/openmw/class2/weapon.cpp @@ -0,0 +1,94 @@ + +#include "weapon.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Weapon::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(),true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Weapon::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Weapon::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Weapon::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + bool Weapon::hasItemHealth (const MWWorld::Ptr& ptr) const + { + return true; + } + + int Weapon::getItemMaxHealth (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->data.health; + } + + void Weapon::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.weapons); + } + + std::string Weapon::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Weapon::registerSelf() + { + boost::shared_ptr instance (new Weapon); + + registerClass (typeid (ESM::Weapon).name(), instance); + } +} diff --git a/apps/openmw/class2/weapon.hpp b/apps/openmw/class2/weapon.hpp new file mode 100644 index 0000000000..79bc4d4dec --- /dev/null +++ b/apps/openmw/class2/weapon.hpp @@ -0,0 +1,43 @@ +#ifndef GAME_MWCLASS_WEAPON_H +#define GAME_MWCLASS_WEAPON_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Weapon : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; + ///< \return Item health data available? + + virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; + ///< Return item max health or throw an exception, if class does not have item health + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 96d65e00da..4013d69fec 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -261,11 +261,13 @@ namespace MWRender{ Ogre::Vector3 shapetrans = copy.trafo.trans; float shapescale = copy.trafo.scale; std::vector boneSequence = copy.boneSequence; - std::vector::iterator boneSequenceIter = boneSequence.begin(); + Ogre::Vector3 transmult; Ogre::Quaternion rotmult; float scale; - if(skel->hasBone(*boneSequenceIter)){ + if(boneSequence.size() > 0){ + std::vector::iterator boneSequenceIter = boneSequence.begin(); + if(skel->hasBone(*boneSequenceIter)){ Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); @@ -292,6 +294,7 @@ namespace MWRender{ //std::cout << "Position: " << transmult << "Rotation: " << rotmult << "\n"; } + } else { transmult = shapetrans; diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 2ac05f2c83..68cd532e9f 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -583,6 +583,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { assert(shape != NULL); + bool saveTheShape = inTheSkeletonTree; // Interpret flags bool hidden = (flags & 0x01) != 0; // Not displayed bool collide = (flags & 0x02) != 0; // Use mesh for collision @@ -741,6 +742,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou std::list vertexBoneAssignments; Nif::NiTriShapeCopy copy = shape->clone(); + if(!shape->controller.empty()) { Nif::Controller* cont = shape->controller.getPtr(); @@ -750,6 +752,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou copy.morph = morph->data.get(); copy.morph.setStartTime(morph->timeStart); copy.morph.setStopTime(morph->timeStop); + saveTheShape = true; } } @@ -928,10 +931,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou } if(!mSkel.isNull() ){ int boneIndex; - Ogre::Bone *parentBone = mSkel->getBone(boneSequence[boneSequence.size() - 1]); - if(parentBone) - boneIndex = parentBone->getHandle(); - else + boneIndex = mSkel->getNumBones() - 1; for(int i = 0; i < numVerts; i++){ VertexBoneAssignment vba; @@ -947,7 +947,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { // Add this vertex set to the bounding box bounds.add(optr, numVerts); - if(addShapes) + if(saveTheShape) shapes.push_back(copy); // Create the submesh @@ -1069,21 +1069,22 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { - addShapes = true; + inTheSkeletonTree = true; mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); } else if (!mSkel.isNull() && !parentBone) - addShapes = false; + inTheSkeletonTree = false; if (!mSkel.isNull()) //if there is a skeleton { std::string name = node->name.toString(); - boneSequence.push_back(name); + // Quick-n-dirty workaround for the fact that several // bones may have the same name. if(!mSkel->hasBone(name)) { + boneSequence.push_back(name); bone = mSkel->createBone(name); if (parentBone) @@ -1148,7 +1149,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, void NIFLoader::loadResource(Resource *resource) { - addShapes = false; + inTheSkeletonTree = false; allanim.clear(); shapes.clear(); needBoneAssignments.clear(); diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index 1361ffaca9..b43d2992ce 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -121,7 +121,7 @@ class NIFLoader : Ogre::ManualResourceLoader private: NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), - mFlipVertexWinding(false), mOutputAnimFiles(false), addShapes(false) {} + mFlipVertexWinding(false), mOutputAnimFiles(false), inTheSkeletonTree(false) {} NIFLoader(NIFLoader& n) {} void calculateTransform(); @@ -190,7 +190,7 @@ class NIFLoader : Ogre::ManualResourceLoader std::vector mAnim; std::vector mS; std::vector needBoneAssignments; - bool addShapes; + bool inTheSkeletonTree; }; From e330c22d68ab8f850a00e1b8a3a299595ccce775 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 19 Feb 2012 02:04:47 -0500 Subject: [PATCH 37/45] Removing unneeded files --- apps/openmw/class2/activator.cpp | 66 ------ apps/openmw/class2/activator.hpp | 28 --- apps/openmw/class2/apparatus.cpp | 81 -------- apps/openmw/class2/apparatus.hpp | 37 ---- apps/openmw/class2/armor.cpp | 93 --------- apps/openmw/class2/armor.hpp | 43 ---- apps/openmw/class2/book.cpp | 83 -------- apps/openmw/class2/book.hpp | 37 ---- apps/openmw/class2/classes.cpp | 50 ----- apps/openmw/class2/classes.hpp | 10 - apps/openmw/class2/clothing.cpp | 81 -------- apps/openmw/class2/clothing.hpp | 37 ---- apps/openmw/class2/container.cpp | 80 ------- apps/openmw/class2/container.hpp | 33 --- apps/openmw/class2/containerutil.hpp | 28 --- apps/openmw/class2/creature.cpp | 138 ------------- apps/openmw/class2/creature.hpp | 51 ----- apps/openmw/class2/creaturelevlist.cpp | 19 -- apps/openmw/class2/creaturelevlist.hpp | 20 -- apps/openmw/class2/door.cpp | 129 ------------ apps/openmw/class2/door.hpp | 39 ---- apps/openmw/class2/ingredient.cpp | 82 -------- apps/openmw/class2/ingredient.hpp | 37 ---- apps/openmw/class2/itemlevlist.cpp | 19 -- apps/openmw/class2/itemlevlist.hpp | 20 -- apps/openmw/class2/light.cpp | 110 ---------- apps/openmw/class2/light.hpp | 42 ---- apps/openmw/class2/lockpick.cpp | 81 -------- apps/openmw/class2/lockpick.hpp | 37 ---- apps/openmw/class2/misc.cpp | 80 ------- apps/openmw/class2/misc.hpp | 37 ---- apps/openmw/class2/npc.cpp | 276 ------------------------- apps/openmw/class2/npc.hpp | 72 ------- apps/openmw/class2/potion.cpp | 81 -------- apps/openmw/class2/potion.hpp | 37 ---- apps/openmw/class2/probe.cpp | 81 -------- apps/openmw/class2/probe.hpp | 37 ---- apps/openmw/class2/repair.cpp | 80 ------- apps/openmw/class2/repair.hpp | 37 ---- apps/openmw/class2/static.cpp | 52 ----- apps/openmw/class2/static.hpp | 26 --- apps/openmw/class2/weapon.cpp | 94 --------- apps/openmw/class2/weapon.hpp | 43 ---- 43 files changed, 2644 deletions(-) delete mode 100644 apps/openmw/class2/activator.cpp delete mode 100644 apps/openmw/class2/activator.hpp delete mode 100644 apps/openmw/class2/apparatus.cpp delete mode 100644 apps/openmw/class2/apparatus.hpp delete mode 100644 apps/openmw/class2/armor.cpp delete mode 100644 apps/openmw/class2/armor.hpp delete mode 100644 apps/openmw/class2/book.cpp delete mode 100644 apps/openmw/class2/book.hpp delete mode 100644 apps/openmw/class2/classes.cpp delete mode 100644 apps/openmw/class2/classes.hpp delete mode 100644 apps/openmw/class2/clothing.cpp delete mode 100644 apps/openmw/class2/clothing.hpp delete mode 100644 apps/openmw/class2/container.cpp delete mode 100644 apps/openmw/class2/container.hpp delete mode 100644 apps/openmw/class2/containerutil.hpp delete mode 100644 apps/openmw/class2/creature.cpp delete mode 100644 apps/openmw/class2/creature.hpp delete mode 100644 apps/openmw/class2/creaturelevlist.cpp delete mode 100644 apps/openmw/class2/creaturelevlist.hpp delete mode 100644 apps/openmw/class2/door.cpp delete mode 100644 apps/openmw/class2/door.hpp delete mode 100644 apps/openmw/class2/ingredient.cpp delete mode 100644 apps/openmw/class2/ingredient.hpp delete mode 100644 apps/openmw/class2/itemlevlist.cpp delete mode 100644 apps/openmw/class2/itemlevlist.hpp delete mode 100644 apps/openmw/class2/light.cpp delete mode 100644 apps/openmw/class2/light.hpp delete mode 100644 apps/openmw/class2/lockpick.cpp delete mode 100644 apps/openmw/class2/lockpick.hpp delete mode 100644 apps/openmw/class2/misc.cpp delete mode 100644 apps/openmw/class2/misc.hpp delete mode 100644 apps/openmw/class2/npc.cpp delete mode 100644 apps/openmw/class2/npc.hpp delete mode 100644 apps/openmw/class2/potion.cpp delete mode 100644 apps/openmw/class2/potion.hpp delete mode 100644 apps/openmw/class2/probe.cpp delete mode 100644 apps/openmw/class2/probe.hpp delete mode 100644 apps/openmw/class2/repair.cpp delete mode 100644 apps/openmw/class2/repair.hpp delete mode 100644 apps/openmw/class2/static.cpp delete mode 100644 apps/openmw/class2/static.hpp delete mode 100644 apps/openmw/class2/weapon.cpp delete mode 100644 apps/openmw/class2/weapon.hpp diff --git a/apps/openmw/class2/activator.cpp b/apps/openmw/class2/activator.cpp deleted file mode 100644 index 086cb433dd..0000000000 --- a/apps/openmw/class2/activator.cpp +++ /dev/null @@ -1,66 +0,0 @@ - -#include "activator.hpp" -#include "../mwrender/objects.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" - - -namespace MWClass -{ - void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Activator::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - std::string Activator::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Activator::registerSelf() - { - boost::shared_ptr instance (new Activator); - - registerClass (typeid (ESM::Activator).name(), instance); - } -} diff --git a/apps/openmw/class2/activator.hpp b/apps/openmw/class2/activator.hpp deleted file mode 100644 index 08be8a5ff1..0000000000 --- a/apps/openmw/class2/activator.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GAME_MWCLASS_ACTIVATOR_H -#define GAME_MWCLASS_ACTIVATOR_H - -#include "../mwworld/class.hpp" - -namespace MWClass -{ - class Activator : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/apparatus.cpp b/apps/openmw/class2/apparatus.cpp deleted file mode 100644 index 4c5ba07219..0000000000 --- a/apps/openmw/class2/apparatus.cpp +++ /dev/null @@ -1,81 +0,0 @@ - -#include "apparatus.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - - -#include "containerutil.hpp" - -namespace MWClass -{ - void Apparatus::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Apparatus::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Apparatus::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Apparatus::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.appas); - } - - std::string Apparatus::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Apparatus::registerSelf() - { - boost::shared_ptr instance (new Apparatus); - - registerClass (typeid (ESM::Apparatus).name(), instance); - } -} diff --git a/apps/openmw/class2/apparatus.hpp b/apps/openmw/class2/apparatus.hpp deleted file mode 100644 index 4c8a2c0e2d..0000000000 --- a/apps/openmw/class2/apparatus.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_APPARATUS_H -#define GAME_MWCLASS_APPARATUS_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Apparatus : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/armor.cpp b/apps/openmw/class2/armor.cpp deleted file mode 100644 index 2ad1dbfa25..0000000000 --- a/apps/openmw/class2/armor.cpp +++ /dev/null @@ -1,93 +0,0 @@ - -#include "armor.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - - -#include "containerutil.hpp" - -namespace MWClass -{ - void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Armor::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Armor::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - bool Armor::hasItemHealth (const MWWorld::Ptr& ptr) const - { - return true; - } - - int Armor::getItemMaxHealth (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->data.health; - } - - void Armor::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.armors); - } - - std::string Armor::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Armor::registerSelf() - { - boost::shared_ptr instance (new Armor); - - registerClass (typeid (ESM::Armor).name(), instance); - } -} diff --git a/apps/openmw/class2/armor.hpp b/apps/openmw/class2/armor.hpp deleted file mode 100644 index c5f9812b79..0000000000 --- a/apps/openmw/class2/armor.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef GAME_MWCLASS_ARMOR_H -#define GAME_MWCLASS_ARMOR_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Armor : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; - ///< \return Item health data available? - - virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; - ///< Return item max health or throw an exception, if class does not have item health - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/book.cpp b/apps/openmw/class2/book.cpp deleted file mode 100644 index 5c0d8767a0..0000000000 --- a/apps/openmw/class2/book.cpp +++ /dev/null @@ -1,83 +0,0 @@ - -#include "book.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - - -#include "containerutil.hpp" - -namespace MWClass -{ - void Book::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Book::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Book::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Book::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - // TODO implement reading - - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Book::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.books); - } - - std::string Book::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Book::registerSelf() - { - boost::shared_ptr instance (new Book); - - registerClass (typeid (ESM::Book).name(), instance); - } -} diff --git a/apps/openmw/class2/book.hpp b/apps/openmw/class2/book.hpp deleted file mode 100644 index f0e38cceba..0000000000 --- a/apps/openmw/class2/book.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_BOOK_H -#define GAME_MWCLASS_BOOK_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Book : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/classes.cpp b/apps/openmw/class2/classes.cpp deleted file mode 100644 index e9538a6cb4..0000000000 --- a/apps/openmw/class2/classes.cpp +++ /dev/null @@ -1,50 +0,0 @@ - -#include "classes.hpp" - -#include "activator.hpp" -#include "creature.hpp" -#include "npc.hpp" -#include "weapon.hpp" -#include "armor.hpp" -#include "potion.hpp" -#include "apparatus.hpp" -#include "book.hpp" -#include "clothing.hpp" -#include "container.hpp" -#include "door.hpp" -#include "ingredient.hpp" -#include "creaturelevlist.hpp" -#include "itemlevlist.hpp" -#include "light.hpp" -#include "lockpick.hpp" -#include "misc.hpp" -#include "probe.hpp" -#include "repair.hpp" -#include "static.hpp" - -namespace MWClass -{ - void registerClasses() - { - Activator::registerSelf(); - Creature::registerSelf(); - Npc::registerSelf(); - Weapon::registerSelf(); - Armor::registerSelf(); - Potion::registerSelf(); - Apparatus::registerSelf(); - Book::registerSelf(); - Clothing::registerSelf(); - Container::registerSelf(); - Door::registerSelf(); - Ingredient::registerSelf(); - CreatureLevList::registerSelf(); - ItemLevList::registerSelf(); - Light::registerSelf(); - Lockpick::registerSelf(); - Miscellaneous::registerSelf(); - Probe::registerSelf(); - Repair::registerSelf(); - Static::registerSelf(); - } -} diff --git a/apps/openmw/class2/classes.hpp b/apps/openmw/class2/classes.hpp deleted file mode 100644 index 0ab90b677b..0000000000 --- a/apps/openmw/class2/classes.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef GAME_MWCLASS_CLASSES_H -#define GAME_MWCLASS_CLASSES_H - -namespace MWClass -{ - void registerClasses(); - ///< register all known classes -} - -#endif diff --git a/apps/openmw/class2/clothing.cpp b/apps/openmw/class2/clothing.cpp deleted file mode 100644 index b81a181f4b..0000000000 --- a/apps/openmw/class2/clothing.cpp +++ /dev/null @@ -1,81 +0,0 @@ - -#include "clothing.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - - -#include "containerutil.hpp" - -namespace MWClass -{ - void Clothing::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Clothing::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Clothing::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Clothing::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Clothing::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.clothes); - } - - std::string Clothing::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Clothing::registerSelf() - { - boost::shared_ptr instance (new Clothing); - - registerClass (typeid (ESM::Clothing).name(), instance); - } -} diff --git a/apps/openmw/class2/clothing.hpp b/apps/openmw/class2/clothing.hpp deleted file mode 100644 index 76c2c4a3e4..0000000000 --- a/apps/openmw/class2/clothing.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_CLOTHING_H -#define GAME_MWCLASS_CLOTHING_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Clothing : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/container.cpp b/apps/openmw/class2/container.cpp deleted file mode 100644 index fff3a9bda7..0000000000 --- a/apps/openmw/class2/container.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -#include "container.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" - -namespace MWClass -{ - void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Container::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Container::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - MWWorld::ContainerStore& Container::getContainerStore (const MWWorld::Ptr& ptr) - const - { - if (!ptr.getRefData().getContainerStore().get()) - { - boost::shared_ptr > store ( - new MWWorld::ContainerStore); - - // TODO add initial content - - ptr.getRefData().getContainerStore() = store; - } - - return *ptr.getRefData().getContainerStore(); - } - - std::string Container::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Container::registerSelf() - { - boost::shared_ptr instance (new Container); - - registerClass (typeid (ESM::Container).name(), instance); - } -} diff --git a/apps/openmw/class2/container.hpp b/apps/openmw/class2/container.hpp deleted file mode 100644 index 01763870ad..0000000000 --- a/apps/openmw/class2/container.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef GAME_MWCLASS_CONTAINER_H -#define GAME_MWCLASS_CONTAINER_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Container : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual MWWorld::ContainerStore& getContainerStore ( - const MWWorld::Ptr& ptr) const; - ///< Return container store - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/containerutil.hpp b/apps/openmw/class2/containerutil.hpp deleted file mode 100644 index 76bdf02361..0000000000 --- a/apps/openmw/class2/containerutil.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GAME_MWCLASS_CONTAINERUTIL_H -#define GAME_MWCLASS_CONTAINERUTIL_H - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/containerstore.hpp" - -namespace MWClass -{ - template - void insertIntoContainerStore (const MWWorld::Ptr& ptr, - ESMS::CellRefList& containerStore) - { - if (!ptr.isEmpty()) - { - // TODO check stacking - - ESMS::LiveCellRef cellRef(ptr.getCellRef(), ptr.get()->base); - cellRef.mData = ptr.getRefData(); - - containerStore.list.push_back (cellRef); - - } - } -} - -#endif diff --git a/apps/openmw/class2/creature.cpp b/apps/openmw/class2/creature.cpp deleted file mode 100644 index 5aa203a49a..0000000000 --- a/apps/openmw/class2/creature.cpp +++ /dev/null @@ -1,138 +0,0 @@ - -#include "creature.hpp" - -#include - -#include "../mwmechanics/creaturestats.hpp" - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontalk.hpp" -#include "../mwworld/environment.hpp" - - -#include "../mwmechanics/mechanicsmanager.hpp" - -namespace MWClass -{ - std::string Creature::getId (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->mId; - } - - void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - - /*ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - {*/ - MWRender::Actors& actors = renderingInterface.getActors(); - actors.insertCreature(ptr); - - } - - void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertActorPhysics(ptr, "meshes\\" + model); - } - - } - - void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const - { - environment.mMechanicsManager->addActor (ptr); - } - - void Creature::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const - { - environment.mMechanicsManager->removeActor (ptr); - } - - std::string Creature::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - MWMechanics::CreatureStats& Creature::getCreatureStats (const MWWorld::Ptr& ptr) const - { - if (!ptr.getRefData().getCreatureStats().get()) - { - boost::shared_ptr stats ( - new MWMechanics::CreatureStats); - - ESMS::LiveCellRef *ref = ptr.get(); - - stats->mAttributes[0].set (ref->base->data.strength); - stats->mAttributes[1].set (ref->base->data.intelligence); - stats->mAttributes[2].set (ref->base->data.willpower); - stats->mAttributes[3].set (ref->base->data.agility); - stats->mAttributes[4].set (ref->base->data.speed); - stats->mAttributes[5].set (ref->base->data.endurance); - stats->mAttributes[6].set (ref->base->data.personality); - stats->mAttributes[7].set (ref->base->data.luck); - stats->mDynamic[0].set (ref->base->data.health); - stats->mDynamic[1].set (ref->base->data.mana); - stats->mDynamic[2].set (ref->base->data.fatigue); - - stats->mLevel = ref->base->data.level; - - ptr.getRefData().getCreatureStats() = stats; - } - - return *ptr.getRefData().getCreatureStats(); - } - - boost::shared_ptr Creature::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr (new MWWorld::ActionTalk (ptr)); - } - - MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr) - const - { - if (!ptr.getRefData().getContainerStore().get()) - { - boost::shared_ptr > store ( - new MWWorld::ContainerStore); - - // TODO add initial content - - ptr.getRefData().getContainerStore() = store; - } - - return *ptr.getRefData().getContainerStore(); - } - - std::string Creature::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Creature::registerSelf() - { - boost::shared_ptr instance (new Creature); - - registerClass (typeid (ESM::Creature).name(), instance); - } -} diff --git a/apps/openmw/class2/creature.hpp b/apps/openmw/class2/creature.hpp deleted file mode 100644 index b7b654bc01..0000000000 --- a/apps/openmw/class2/creature.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef GAME_MWCLASS_CREATURE_H -#define GAME_MWCLASS_CREATURE_H - -#include "../mwworld/class.hpp" -#include "../mwrender/renderinginterface.hpp" -#include "../mwrender/actors.hpp" - - -namespace MWClass -{ - class Creature : public MWWorld::Class - { - public: - - virtual std::string getId (const MWWorld::Ptr& ptr) const; - ///< Return ID of \a ptr - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; - ///< Enable reference; only does the non-rendering part - - virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; - ///< Enable reference; only does the non-rendering part - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; - ///< Return creature stats - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual MWWorld::ContainerStore& getContainerStore ( - const MWWorld::Ptr& ptr) const; - ///< Return container store - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/creaturelevlist.cpp b/apps/openmw/class2/creaturelevlist.cpp deleted file mode 100644 index 53dd34bb48..0000000000 --- a/apps/openmw/class2/creaturelevlist.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include "creaturelevlist.hpp" - -#include - -namespace MWClass -{ - std::string CreatureLevList::getName (const MWWorld::Ptr& ptr) const - { - return ""; - } - - void CreatureLevList::registerSelf() - { - boost::shared_ptr instance (new CreatureLevList); - - registerClass (typeid (ESM::CreatureLevList).name(), instance); - } -} diff --git a/apps/openmw/class2/creaturelevlist.hpp b/apps/openmw/class2/creaturelevlist.hpp deleted file mode 100644 index 81965efd58..0000000000 --- a/apps/openmw/class2/creaturelevlist.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef GAME_MWCLASS_CREATURELEVLIST_H -#define GAME_MWCLASS_CREATURELEVLIST_H - -#include "../mwworld/class.hpp" - -namespace MWClass -{ - class CreatureLevList : public MWWorld::Class - { - public: - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/door.cpp b/apps/openmw/class2/door.cpp deleted file mode 100644 index baced8a9cc..0000000000 --- a/apps/openmw/class2/door.cpp +++ /dev/null @@ -1,129 +0,0 @@ - -#include "door.hpp" - -#include - -#include - -#include "../mwworld/player.hpp" -#include "../mwworld/ptr.hpp" -#include "../mwworld/nullaction.hpp" -#include "../mwworld/actionteleport.hpp" -#include "../mwworld/environment.hpp" -#include "../mwworld/world.hpp" - -#include "../mwrender/objects.hpp" - -#include - -namespace MWClass -{ - void Door::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Door::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - if (ref->ref.teleport && !ref->ref.destCell.empty()) // TODO doors that lead to exteriors - return ref->ref.destCell; - - return ref->base->name; - } - - boost::shared_ptr Door::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - if (ptr.getCellRef().lockLevel>0) - { - // TODO check for key - // TODO report failure to player (message, sound?). Look up behaviour of original MW. - std::cout << "Locked!" << std::endl; - return boost::shared_ptr (new MWWorld::NullAction); - } - - // TODO check trap - - if (ref->ref.teleport) - { - // teleport door - if (environment.mWorld->getPlayer().getPlayer()==actor) - { - // the player is using the door - return boost::shared_ptr ( - new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest)); - } - else - { - // another NPC or a create is using the door - // TODO return action for teleporting other NPC/creature - return boost::shared_ptr (new MWWorld::NullAction); - } - } - else - { - // animated door - // TODO return action for rotating the door - return boost::shared_ptr (new MWWorld::NullAction); - } - } - - void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const - { - if (lockLevel<0) - lockLevel = 0; - - ptr.getCellRef().lockLevel = lockLevel; - } - - void Door::unlock (const MWWorld::Ptr& ptr) const - { - ptr.getCellRef().lockLevel = 0; - } - - std::string Door::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Door::registerSelf() - { - boost::shared_ptr instance (new Door); - - registerClass (typeid (ESM::Door).name(), instance); - } -} diff --git a/apps/openmw/class2/door.hpp b/apps/openmw/class2/door.hpp deleted file mode 100644 index c230cf3576..0000000000 --- a/apps/openmw/class2/door.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef GAME_MWCLASS_DOOR_H -#define GAME_MWCLASS_DOOR_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Door : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void lock (const MWWorld::Ptr& ptr, int lockLevel) const; - ///< Lock object - - virtual void unlock (const MWWorld::Ptr& ptr) const; - ///< Unlock object - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/ingredient.cpp b/apps/openmw/class2/ingredient.cpp deleted file mode 100644 index 42e3d11e49..0000000000 --- a/apps/openmw/class2/ingredient.cpp +++ /dev/null @@ -1,82 +0,0 @@ - -#include "ingredient.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - - -#include "containerutil.hpp" - -namespace MWClass -{ - void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Ingredient::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Ingredient::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Ingredient::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Ingredient::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.ingreds); - } - - std::string Ingredient::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Ingredient::registerSelf() - { - boost::shared_ptr instance (new Ingredient); - - registerClass (typeid (ESM::Ingredient).name(), instance); - } -} diff --git a/apps/openmw/class2/ingredient.hpp b/apps/openmw/class2/ingredient.hpp deleted file mode 100644 index 47bd1a9e5c..0000000000 --- a/apps/openmw/class2/ingredient.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_INGREDIENT_H -#define GAME_MWCLASS_INGREDIENT_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Ingredient : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/itemlevlist.cpp b/apps/openmw/class2/itemlevlist.cpp deleted file mode 100644 index 6ed9ab2e53..0000000000 --- a/apps/openmw/class2/itemlevlist.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include "itemlevlist.hpp" - -#include - -namespace MWClass -{ - std::string ItemLevList::getName (const MWWorld::Ptr& ptr) const - { - return ""; - } - - void ItemLevList::registerSelf() - { - boost::shared_ptr instance (new ItemLevList); - - registerClass (typeid (ESM::ItemLevList).name(), instance); - } -} diff --git a/apps/openmw/class2/itemlevlist.hpp b/apps/openmw/class2/itemlevlist.hpp deleted file mode 100644 index 0b71b072c8..0000000000 --- a/apps/openmw/class2/itemlevlist.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef GAME_MWCLASS_ITEMLEVLIST_H -#define GAME_MWCLASS_ITEMLEVLIST_H - -#include "../mwworld/class.hpp" - -namespace MWClass -{ - class ItemLevList : public MWWorld::Class - { - public: - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/light.cpp b/apps/openmw/class2/light.cpp deleted file mode 100644 index a3ceea4a68..0000000000 --- a/apps/openmw/class2/light.cpp +++ /dev/null @@ -1,110 +0,0 @@ - -#include "light.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" -#include "../mwworld/nullaction.hpp" -#include "../mwworld/environment.hpp" - -#include "../mwsound/soundmanager.hpp" - -#include "containerutil.hpp" - -namespace MWClass -{ - void Light::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - const int color = ref->base->data.color; - const float r = ((color >> 0) & 0xFF) / 255.0f; - const float g = ((color >> 8) & 0xFF) / 255.0f; - const float b = ((color >> 16) & 0xFF) / 255.0f; - const float radius = float (ref->base->data.radius); - objects.insertLight (ptr, r, g, b, radius); - } - } - - void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - void Light::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - if (!ref->base->sound.empty()) - { - environment.mSoundManager->playSound3D (ptr, ref->base->sound, 1.0, 1.0, true); - } - } - - std::string Light::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - if (ref->base->model.empty()) - return ""; - - return ref->base->name; - } - - boost::shared_ptr Light::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - if (!(ref->base->data.flags & ESM::Light::Carry)) - return boost::shared_ptr (new MWWorld::NullAction); - - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Light::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.lights); - } - - std::string Light::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Light::registerSelf() - { - boost::shared_ptr instance (new Light); - - registerClass (typeid (ESM::Light).name(), instance); - } -} diff --git a/apps/openmw/class2/light.hpp b/apps/openmw/class2/light.hpp deleted file mode 100644 index 34421ff513..0000000000 --- a/apps/openmw/class2/light.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef GAME_MWCLASS_LIGHT_H -#define GAME_MWCLASS_LIGHT_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Light : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; - ///< Enable reference; only does the non-rendering part - /// \attention This is not the same as the script instruction with the same name. References - /// should only be enabled while in an active cell. - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/lockpick.cpp b/apps/openmw/class2/lockpick.cpp deleted file mode 100644 index c07d5592c7..0000000000 --- a/apps/openmw/class2/lockpick.cpp +++ /dev/null @@ -1,81 +0,0 @@ - -#include "lockpick.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - -#include "containerutil.hpp" - -namespace MWClass -{ - void Lockpick::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - - std::string Lockpick::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Lockpick::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Lockpick::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.lockpicks); - } - - std::string Lockpick::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Lockpick::registerSelf() - { - boost::shared_ptr instance (new Lockpick); - - registerClass (typeid (ESM::Tool).name(), instance); - } -} diff --git a/apps/openmw/class2/lockpick.hpp b/apps/openmw/class2/lockpick.hpp deleted file mode 100644 index c5f1539b4c..0000000000 --- a/apps/openmw/class2/lockpick.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_LOCKPICK_H -#define GAME_MWCLASS_LOCKPICK_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Lockpick : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/misc.cpp b/apps/openmw/class2/misc.cpp deleted file mode 100644 index a58142905c..0000000000 --- a/apps/openmw/class2/misc.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -#include "misc.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - -#include "containerutil.hpp" - -namespace MWClass -{ - void Miscellaneous::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Miscellaneous::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Miscellaneous::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Miscellaneous::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Miscellaneous::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.miscItems); - } - - std::string Miscellaneous::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Miscellaneous::registerSelf() - { - boost::shared_ptr instance (new Miscellaneous); - - registerClass (typeid (ESM::Miscellaneous).name(), instance); - } -} diff --git a/apps/openmw/class2/misc.hpp b/apps/openmw/class2/misc.hpp deleted file mode 100644 index 36ee2c1b26..0000000000 --- a/apps/openmw/class2/misc.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_MISC_H -#define GAME_MWCLASS_MISC_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Miscellaneous : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/npc.cpp b/apps/openmw/class2/npc.cpp deleted file mode 100644 index acb0a5a351..0000000000 --- a/apps/openmw/class2/npc.cpp +++ /dev/null @@ -1,276 +0,0 @@ - -#include "npc.hpp" - -#include - -#include "../mwmechanics/creaturestats.hpp" -#include "../mwmechanics/npcstats.hpp" - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontalk.hpp" -#include "../mwworld/environment.hpp" -#include "../mwworld/world.hpp" - -#include "../mwmechanics/mechanicsmanager.hpp" -#include - -namespace -{ - const Ogre::Radian kOgrePi (Ogre::Math::PI); - const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0)); -} - -namespace MWClass -{ - std::string Npc::getId (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->mId; - } - - void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - renderingInterface.getActors().insertNPC(ptr); - } - - void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - - - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - std::string headID = ref->base->head; - std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); - bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - - - std::string smodel = "meshes\\base_anim.nif"; - if(beast) - smodel = "meshes\\base_animkna.nif"; - physics.insertActorPhysics(ptr, smodel); - - - } - - void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const - { - environment.mMechanicsManager->addActor (ptr); - } - - void Npc::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const - { - environment.mMechanicsManager->removeActor (ptr); - } - - std::string Npc::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const - { - if (!ptr.getRefData().getCreatureStats().get()) - { - boost::shared_ptr stats ( - new MWMechanics::CreatureStats); - - ESMS::LiveCellRef *ref = ptr.get(); - - stats->mAttributes[0].set (ref->base->npdt52.strength); - stats->mAttributes[1].set (ref->base->npdt52.intelligence); - stats->mAttributes[2].set (ref->base->npdt52.willpower); - stats->mAttributes[3].set (ref->base->npdt52.agility); - stats->mAttributes[4].set (ref->base->npdt52.speed); - stats->mAttributes[5].set (ref->base->npdt52.endurance); - stats->mAttributes[6].set (ref->base->npdt52.personality); - stats->mAttributes[7].set (ref->base->npdt52.luck); - stats->mDynamic[0].set (ref->base->npdt52.health); - stats->mDynamic[1].set (ref->base->npdt52.mana); - stats->mDynamic[2].set (ref->base->npdt52.fatigue); - - stats->mLevel = ref->base->npdt52.level; - - ptr.getRefData().getCreatureStats() = stats; - } - - return *ptr.getRefData().getCreatureStats(); - } - - MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const - { - if (!ptr.getRefData().getNpcStats().get()) - { - boost::shared_ptr stats ( - new MWMechanics::NpcStats); - - ESMS::LiveCellRef *ref = ptr.get(); - - if (!ref->base->faction.empty()) - { - // TODO research how initial rank is stored. The information in loadnpc.hpp are at - // best very unclear. - stats->mFactionRank[ref->base->faction] = 0; - } - - for (int i=0; i<27; ++i) - stats->mSkill[i].setBase (ref->base->npdt52.skills[i]); - - ptr.getRefData().getNpcStats() = stats; - } - - return *ptr.getRefData().getNpcStats(); - } - - boost::shared_ptr Npc::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr (new MWWorld::ActionTalk (ptr)); - } - - MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr) - const - { - if (!ptr.getRefData().getContainerStore().get()) - { - boost::shared_ptr > store ( - new MWWorld::ContainerStore); - - // TODO add initial content - - ptr.getRefData().getContainerStore() = store; - } - - return *ptr.getRefData().getContainerStore(); - } - - std::string Npc::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Npc::setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const - { - MWMechanics::NpcStats& stats = getNpcStats (ptr); - - switch (stance) - { - case Run: - - stats.mForceRun = force; - break; - - case Sneak: - - stats.mForceSneak = force; - break; - - case Combat: - - throw std::runtime_error ("combat stance not enforcable for NPCs"); - } - } - - void Npc::setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const - { - MWMechanics::NpcStats& stats = getNpcStats (ptr); - - switch (stance) - { - case Run: - - stats.mRun = set; - break; - - case Sneak: - - stats.mSneak = set; - break; - - case Combat: - - stats.mCombat = set; - break; - } - } - - bool Npc::getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce) const - { - MWMechanics::NpcStats& stats = getNpcStats (ptr); - - switch (stance) - { - case Run: - - if (!ignoreForce && stats.mForceRun) - return true; - - return stats.mRun; - - case Sneak: - - if (!ignoreForce && stats.mForceSneak) - return true; - - return stats.mSneak; - - case Combat: - - return stats.mCombat; - } - - return false; - } - - float Npc::getSpeed (const MWWorld::Ptr& ptr) const - { - return getStance (ptr, Run) ? 600 : 300; // TODO calculate these values from stats - } - - MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const - { - if (!ptr.getRefData().getMovement().get()) - { - boost::shared_ptr movement ( - new MWMechanics::Movement); - - ptr.getRefData().getMovement() = movement; - } - - return *ptr.getRefData().getMovement(); - } - - Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const - { - Ogre::Vector3 vector (0, 0, 0); - - if (ptr.getRefData().getMovement().get()) - { - vector.x = - ptr.getRefData().getMovement()->mLeftRight * 200; - vector.y = ptr.getRefData().getMovement()->mForwardBackward * 200; - - if (getStance (ptr, Run, false)) - vector *= 2; - } - - return vector; - } - - void Npc::registerSelf() - { - boost::shared_ptr instance (new Npc); - - registerClass (typeid (ESM::NPC).name(), instance); - } -} diff --git a/apps/openmw/class2/npc.hpp b/apps/openmw/class2/npc.hpp deleted file mode 100644 index cc9dbef7fa..0000000000 --- a/apps/openmw/class2/npc.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef GAME_MWCLASS_NPC_H -#define GAME_MWCLASS_NPC_H - -#include "../mwworld/class.hpp" - - -namespace MWClass -{ - class Npc : public MWWorld::Class - { - public: - - virtual std::string getId (const MWWorld::Ptr& ptr) const; - ///< Return ID of \a ptr - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; - ///< Enable reference; only does the non-rendering part - - virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; - ///< Enable reference; only does the non-rendering part - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; - ///< Return creature stats - - virtual MWMechanics::NpcStats& getNpcStats (const MWWorld::Ptr& ptr) const; - ///< Return NPC stats - - virtual MWWorld::ContainerStore& getContainerStore ( - const MWWorld::Ptr& ptr) const; - ///< Return container store - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - virtual void setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const; - ///< Force or unforce a stance. - - virtual void setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const; - ///< Set or unset a stance. - - virtual bool getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce = false) - const; - ////< Check if a stance is active or not. - - virtual float getSpeed (const MWWorld::Ptr& ptr) const; - ///< Return movement speed. - - virtual MWMechanics::Movement& getMovementSettings (const MWWorld::Ptr& ptr) const; - ///< Return desired movement. - - virtual Ogre::Vector3 getMovementVector (const MWWorld::Ptr& ptr) const; - ///< Return desired movement vector (determined based on movement settings, - /// stance and stats). - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/potion.cpp b/apps/openmw/class2/potion.cpp deleted file mode 100644 index 0ab1c7aad6..0000000000 --- a/apps/openmw/class2/potion.cpp +++ /dev/null @@ -1,81 +0,0 @@ - -#include "potion.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - - -#include "containerutil.hpp" - -namespace MWClass -{ - void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Potion::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Potion::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Potion::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.potions); - } - - std::string Potion::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Potion::registerSelf() - { - boost::shared_ptr instance (new Potion); - - registerClass (typeid (ESM::Potion).name(), instance); - } -} diff --git a/apps/openmw/class2/potion.hpp b/apps/openmw/class2/potion.hpp deleted file mode 100644 index 85678121fb..0000000000 --- a/apps/openmw/class2/potion.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_POTION_H -#define GAME_MWCLASS_POTION_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Potion : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/probe.cpp b/apps/openmw/class2/probe.cpp deleted file mode 100644 index 83c0e1ef47..0000000000 --- a/apps/openmw/class2/probe.cpp +++ /dev/null @@ -1,81 +0,0 @@ - -#include "probe.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - -#include "containerutil.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - void Probe::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Probe::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - - std::string Probe::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - boost::shared_ptr Probe::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Probe::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.probes); - } - - std::string Probe::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Probe::registerSelf() - { - boost::shared_ptr instance (new Probe); - - registerClass (typeid (ESM::Probe).name(), instance); - } -} diff --git a/apps/openmw/class2/probe.hpp b/apps/openmw/class2/probe.hpp deleted file mode 100644 index d7b9df7385..0000000000 --- a/apps/openmw/class2/probe.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_PROBE_H -#define GAME_MWCLASS_PROBE_H - -#include "../mwworld/class.hpp" - - -namespace MWClass -{ - class Probe : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/repair.cpp b/apps/openmw/class2/repair.cpp deleted file mode 100644 index feee7e988b..0000000000 --- a/apps/openmw/class2/repair.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -#include "repair.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - -#include "containerutil.hpp" - -namespace MWClass -{ - void Repair::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Repair::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Repair::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Repair::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - void Repair::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.repairs); - } - - std::string Repair::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Repair::registerSelf() - { - boost::shared_ptr instance (new Repair); - - registerClass (typeid (ESM::Repair).name(), instance); - } -} diff --git a/apps/openmw/class2/repair.hpp b/apps/openmw/class2/repair.hpp deleted file mode 100644 index 1e0ea51785..0000000000 --- a/apps/openmw/class2/repair.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_MWCLASS_REPAIR_H -#define GAME_MWCLASS_REPAIR_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Repair : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/static.cpp b/apps/openmw/class2/static.cpp deleted file mode 100644 index af14bb3069..0000000000 --- a/apps/openmw/class2/static.cpp +++ /dev/null @@ -1,52 +0,0 @@ - -#include "static.hpp" - -#include - -#include "../mwworld/ptr.hpp" - - -namespace MWClass -{ - void Static::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Static::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Static::getName (const MWWorld::Ptr& ptr) const - { - return ""; - } - - void Static::registerSelf() - { - boost::shared_ptr instance (new Static); - - registerClass (typeid (ESM::Static).name(), instance); - } -} diff --git a/apps/openmw/class2/static.hpp b/apps/openmw/class2/static.hpp deleted file mode 100644 index be3fdb1804..0000000000 --- a/apps/openmw/class2/static.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef GAME_MWCLASS_STATIC_H -#define GAME_MWCLASS_STATIC_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Static : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/class2/weapon.cpp b/apps/openmw/class2/weapon.cpp deleted file mode 100644 index d5f7e68536..0000000000 --- a/apps/openmw/class2/weapon.cpp +++ /dev/null @@ -1,94 +0,0 @@ - -#include "weapon.hpp" - -#include - -#include - -#include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" - - -#include "containerutil.hpp" - -namespace MWClass -{ - void Weapon::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Objects& objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(),true); - objects.insertMesh(ptr, "meshes\\" + model); - } - } - - void Weapon::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - - const std::string &model = ref->base->model; - assert (ref->base != NULL); - if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - - } - - std::string Weapon::getName (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->name; - } - - boost::shared_ptr Weapon::activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const - { - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); - } - - bool Weapon::hasItemHealth (const MWWorld::Ptr& ptr) const - { - return true; - } - - int Weapon::getItemMaxHealth (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->data.health; - } - - void Weapon::insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const - { - insertIntoContainerStore (ptr, containerStore.weapons); - } - - std::string Weapon::getScript (const MWWorld::Ptr& ptr) const - { - ESMS::LiveCellRef *ref = - ptr.get(); - - return ref->base->script; - } - - void Weapon::registerSelf() - { - boost::shared_ptr instance (new Weapon); - - registerClass (typeid (ESM::Weapon).name(), instance); - } -} diff --git a/apps/openmw/class2/weapon.hpp b/apps/openmw/class2/weapon.hpp deleted file mode 100644 index 79bc4d4dec..0000000000 --- a/apps/openmw/class2/weapon.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef GAME_MWCLASS_WEAPON_H -#define GAME_MWCLASS_WEAPON_H - -#include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" - -namespace MWClass -{ - class Weapon : public MWWorld::Class - { - public: - - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - - virtual std::string getName (const MWWorld::Ptr& ptr) const; - ///< \return name (the one that is to be presented to the user; not the internal one); - /// can return an empty string. - - virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, - const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; - ///< Generate action for activation - - virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; - ///< \return Item health data available? - - virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; - ///< Return item max health or throw an exception, if class does not have item health - - virtual void insertIntoContainer (const MWWorld::Ptr& ptr, - MWWorld::ContainerStore& containerStore) const; - ///< Insert into a containe - - virtual std::string getScript (const MWWorld::Ptr& ptr) const; - ///< Return name of the script attached to ptr - - static void registerSelf(); - }; -} - -#endif From 7e1e746201cb60546b950860140f0b94b8966f17 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 19 Feb 2012 17:59:50 -0500 Subject: [PATCH 38/45] More changes --- apps/openmw/mwrender/animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 4013d69fec..c9078cb9c4 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -216,7 +216,7 @@ namespace MWRender{ - for(int i = 1; i < inds.size(); i++){ + for(std::size_t i = 1; i < inds.size(); i++){ boneinfocopy = &(allshapesiter->boneinfo[inds[i].boneinfocopyindex]); result = vecRotPos.find(boneinfocopy); From 0c0b5940908c2ea385a9564fd02431d27792bd85 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 19 Feb 2012 23:39:37 +0100 Subject: [PATCH 39/45] Issue #168 - Configuration cleanup Removed unnecessary path methods - according to forum disscusion: http://openmw.org/forum/viewtopic.php?f=6&t=448 Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 2 + apps/openmw/main.cpp | 2 +- components/files/configurationmanager.cpp | 56 ++++--------- components/files/fixedpath.hpp | 20 +---- components/files/linuxpath.cpp | 97 +++-------------------- components/files/linuxpath.hpp | 14 ---- components/files/macospath.cpp | 44 +--------- components/files/macospath.hpp | 7 ++ components/files/windowspath.cpp | 26 ++---- components/files/windowspath.hpp | 18 +---- 10 files changed, 50 insertions(+), 236 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 8b59f1b819..6eb4590373 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -135,6 +135,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) dataDirs.push_back(boost::filesystem::path(currentPath.toStdString())); } + mCfgMgr.processPaths(dataDirs); + // Create a file collection for the dataDirs Files::Collections mFileCollections(dataDirs, strict); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 9f70fac15e..6bdfdd91f0 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -167,7 +167,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getLocalDataPath()); + dataDirs.push_back(cfgMgr.getLocalPath()); } engine.setDataDirs(dataDirs); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 46cd0e053b..c5561d6527 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -5,6 +5,11 @@ #include #include +#include + +/** + * \namespace Files + */ namespace Files { @@ -22,10 +27,6 @@ ConfigurationManager::ConfigurationManager() { setupTokensMapping(); - /** - * According to task #168 plugins.cfg file shall be located in global - * configuration path or in local configuration path. - */ mPluginsCfgPath = mFixedPath.getGlobalPath() / pluginsCfgFile; if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) { @@ -37,15 +38,7 @@ ConfigurationManager::ConfigurationManager() } } - /** - * According to task #168 ogre.cfg file shall be located only - * in user configuration path. - */ mOgreCfgPath = mFixedPath.getUserPath() / ogreCfgFile; - - /** - * FIXME: Logs shoudn't be stored in the same dir where configuration is placed. - */ mLogPath = mFixedPath.getUserPath(); } @@ -56,8 +49,8 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { mTokensMapping.insert(std::make_pair(mwToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserPath)); mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalDataPath)); } @@ -74,14 +67,6 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m } -struct EmptyPath : public std::unary_function -{ - bool operator()(const boost::filesystem::path& path) const - { - return path.empty(); - } -}; - void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) { for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) @@ -105,14 +90,7 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) tempPath /= path.substr(pos + 1, path.length() - pos); } - if (boost::filesystem::is_directory(tempPath)) - { - (*it) = tempPath; - } - else - { - (*it).clear(); - } + *it = tempPath; } else { @@ -121,9 +99,15 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) } } } + + if (!boost::filesystem::is_directory(*it)) + { + (*it).clear(); + } } - dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), EmptyPath()), dataDirs.end()); + dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), + boost::bind(&boost::filesystem::path::empty, _1)), dataDirs.end()); } void ConfigurationManager::loadConfig(const boost::filesystem::path& path, @@ -171,16 +155,6 @@ const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const return mFixedPath.getGlobalDataPath(); } -const boost::filesystem::path& ConfigurationManager::getUserDataPath() const -{ - return mFixedPath.getUserDataPath(); -} - -const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const -{ - return mFixedPath.getLocalDataPath(); -} - const boost::filesystem::path& ConfigurationManager::getInstallPath() const { return mFixedPath.getInstallPath(); diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 0e052fd248..4e054b17ff 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -73,9 +73,7 @@ struct FixedPath , mUserPath(mPath.getUserPath()) , mGlobalPath(mPath.getGlobalPath()) , mLocalPath(mPath.getLocalPath()) - , mUserDataPath(mPath.getUserDataPath()) , mGlobalDataPath(mPath.getGlobalDataPath()) - , mLocalDataPath(mPath.getLocalDataPath()) , mInstallPath(mPath.getInstallPath()) { if (!application_name.empty()) @@ -84,9 +82,6 @@ struct FixedPath mUserPath /= suffix; mGlobalPath /= suffix; - - mLocalDataPath /= suffix; - mUserDataPath /= suffix; mGlobalDataPath /= suffix; } } @@ -131,16 +126,6 @@ struct FixedPath return mGlobalDataPath; } - const boost::filesystem::path& getUserDataPath() const - { - return mUserDataPath; - } - - const boost::filesystem::path& getLocalDataPath() const - { - return mLocalDataPath; - } - private: PathType mPath; @@ -148,11 +133,8 @@ struct FixedPath boost::filesystem::path mGlobalPath; /**< Global path */ boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */ - boost::filesystem::path mUserDataPath; /**< User data path */ boost::filesystem::path mGlobalDataPath; /**< Global application data path */ - boost::filesystem::path mLocalDataPath; /**< Local path to the configuration files. - By default it is a 'data' directory in same - directory where application was run */ + boost::filesystem::path mInstallPath; }; diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 41891661ef..0b315ccfb2 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -41,29 +41,19 @@ boost::filesystem::path LinuxPath::getUserPath() const boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); - const char* theDir = getenv("OPENMW_CONFIG"); + const char* theDir = getenv("HOME"); if (theDir == NULL) { - theDir = getenv("XDG_CONFIG_HOME"); - if (theDir == NULL) + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/.config/"); - } + theDir = pwd->pw_dir; } } - if (theDir != NULL) { + if (theDir != NULL) + { + suffix = boost::filesystem::path("/.config/"); userPath = boost::filesystem::path(theDir); } @@ -74,20 +64,7 @@ boost::filesystem::path LinuxPath::getUserPath() const boost::filesystem::path LinuxPath::getGlobalPath() const { - boost::filesystem::path globalPath("/etc/xdg/"); - - char* theDir = getenv("XDG_CONFIG_DIRS"); - if (theDir != NULL) - { - // We take only first path from list - char* ptr = strtok(theDir, ":"); - if (ptr != NULL) - { - globalPath = boost::filesystem::path(ptr); - globalPath /= boost::filesystem::path("/"); - } - } - + boost::filesystem::path globalPath("/etc/"); return globalPath; } @@ -96,65 +73,12 @@ boost::filesystem::path LinuxPath::getLocalPath() const return boost::filesystem::path("./"); } -boost::filesystem::path LinuxPath::getUserDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("XDG_DATA_HOME"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/.local/share/"); - } - } - } - - if (theDir != NULL) { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - boost::filesystem::path LinuxPath::getGlobalDataPath() const { - boost::filesystem::path globalDataPath("/usr/local/share/"); - - char* theDir = getenv("XDG_DATA_DIRS"); - if (theDir != NULL) - { - // We take only first path from list - char* ptr = strtok(theDir, ":"); - if (ptr != NULL) - { - globalDataPath = boost::filesystem::path(ptr); - globalDataPath /= boost::filesystem::path("/"); - } - } - + boost::filesystem::path globalDataPath("/usr/share/games/"); return globalDataPath; } -boost::filesystem::path LinuxPath::getLocalDataPath() const -{ - return boost::filesystem::path("./data/"); -} - boost::filesystem::path LinuxPath::getInstallPath() const { boost::filesystem::path installPath; @@ -211,7 +135,8 @@ boost::filesystem::path LinuxPath::getInstallPath() const if (!mwpath.empty()) { - // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks + // Change drive letter to lowercase, so we could use + // ~/.wine/dosdevices symlinks mwpath[0] = tolower(mwpath[0]); installPath /= homePath; installPath /= ".wine/dosdevices/"; diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 71f45ae32b..873f8801de 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -60,13 +60,6 @@ struct LinuxPath */ boost::filesystem::path getLocalPath() const; - /** - * \brief - * - * \return boost::filesystem::path - */ - boost::filesystem::path getUserDataPath() const; - /** * \brief * @@ -74,13 +67,6 @@ struct LinuxPath */ boost::filesystem::path getGlobalDataPath() const; - /** - * \brief - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - /** * \brief Gets the path of the installed Morrowind version if there is one. * diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 789c877099..6225fc01f4 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -28,6 +28,10 @@ #include #include +/** + * FIXME: Someone with MacOS system should check this and correct if necessary + */ + /** * \namespace Files */ @@ -69,52 +73,12 @@ boost::filesystem::path MacOsPath::getLocalPath() const return boost::filesystem::path("./"); } -boost::filesystem::path MacOsPath::getUserDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/Library/Application Support/"); - } - } - - if (theDir != NULL) - { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - boost::filesystem::path MacOsPath::getGlobalDataPath() const { boost::filesystem::path globalDataPath("/Library/Application Support/"); return globalDataPath; } -boost::filesystem::path MacOsPath::getLocalDataPath() const -{ - return boost::filesystem::path("./data/"); -} - -/** - * FIXME: This should be verified on MacOS system! - */ boost::filesystem::path MacOsPath::getInstallPath() const { boost::filesystem::path installPath; diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 2194dbb94a..7656538c19 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -60,6 +60,13 @@ struct MacOsPath */ boost::filesystem::path getLocalPath() const; + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getGlobalDataPath() const; + boost::filesystem::path getInstallPath() const; }; diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 9bb66a3cb3..e810412720 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -10,6 +10,13 @@ #pragma comment(lib, "Shlwapi.lib") +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ + +/** + * \namespace Files + */ namespace Files { @@ -55,30 +62,11 @@ boost::filesystem::path WindowsPath::getLocalPath() const return boost::filesystem::path("./"); } -/** - * FIXME: Someone with Windows system should check this and correct if necessary - */ -boost::filesystem::path WindowsPath::getUserDataPath() const -{ - return getUserConfigPath(); -} - -/** - * FIXME: Someone with Windows system should check this and correct if necessary - */ boost::filesystem::path WindowsPath::getGlobalDataPath() const { return getGlobalConfigPath(); } -/** - * FIXME: Someone with Windows system should check this and correct if necessary - */ -boost::filesystem::path WindowsPath::getLocalDataPath() const -{ - return boost::filesystem::path("./data/"); -} - boost::filesystem::path WindowsPath::getInstallPath() const { boost::filesystem::path installPath(""); diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 0240de257f..919d087f11 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -39,7 +39,8 @@ namespace Files struct WindowsPath { /** - * \brief Returns "X:\Documents And Settings\\My Documents\My Games\" + * \brief Returns user path i.e.: + * "X:\Documents And Settings\\My Documents\My Games\" * * \return boost::filesystem::path */ @@ -60,13 +61,6 @@ struct WindowsPath */ boost::filesystem::path getLocalPath() const; - /** - * \brief Return same path like getUserConfigPath - * - * \return boost::filesystem::path - */ - boost::filesystem::path getUserDataPath() const; - /** * \brief Return same path like getGlobalConfigPath * @@ -74,14 +68,6 @@ struct WindowsPath */ boost::filesystem::path getGlobalDataPath() const; - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - /** * \brief Gets the path of the installed Morrowind version if there is one. * From 7eae24bb45b5d595e98fcf3ef16be421103b149c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 20 Feb 2012 14:02:24 +0100 Subject: [PATCH 40/45] some fixes --- apps/openmw/mwrender/animation.cpp | 133 ++++++++++++++--------------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index c9078cb9c4..63855f3b81 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -18,7 +18,7 @@ namespace MWRender{ mUniqueIDs[copy] = mUniqueIDs[copy] + 1; counter = mUniqueIDs[copy]; } - + std::stringstream out; if(counter > 99 && counter < 1000) out << "0"; @@ -38,7 +38,7 @@ namespace MWRender{ time = startTime; } else if(textmappings){ - + std::string startName = groupname + ": loop start"; std::string stopName = groupname + ": loop stop"; @@ -49,7 +49,7 @@ namespace MWRender{ stopName = groupname + ": loop stop"; for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ - + std::string current = iter->first.substr(0, startName.size()); std::transform(current.begin(), current.end(), current.begin(), ::tolower); std::string current2 = iter->first.substr(0, stopName.size()); @@ -71,9 +71,9 @@ namespace MWRender{ if(!first){ startName = groupname + ": start"; stopName = groupname + ": stop"; - + for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ - + std::string current = iter->first.substr(0, startName.size()); std::transform(current.begin(), current.end(), current.begin(), ::tolower); std::string current2 = iter->first.substr(0, stopName.size()); @@ -92,24 +92,23 @@ namespace MWRender{ } } } - + } - + } void Animation::stopScript(){ animate = 0; } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ - bool useHandles = false; shapeNumber = 0; - + std::vector::iterator allshapesiter; for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) - + { //std::map vecPosRot; - + Nif::NiTriShapeCopy& copy = *allshapesiter; std::vector* allvertices = ©.vertices; std::vector* allnormals = ©.normals; @@ -119,12 +118,12 @@ namespace MWRender{ //std::set vertices; //std::set normals; //std::vector boneinfovector = copy.boneinfo; - std::map>* verticesToChange = ©.vertsToWeights; - + std::map >* verticesToChange = ©.vertsToWeights; + //std::cout << "Name " << copy.sname << "\n"; Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); Ogre::Real* pReal = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); - + std::vector initialVertices = copy.morph.getInitialVertices(); //Each shape has multiple indices @@ -134,7 +133,7 @@ namespace MWRender{ if(copy.vertices.size() == initialVertices.size()) { //Create if it doesn't already exist - if(shapeIndexI.size() == shapeNumber) + if(shapeIndexI.size() == static_cast (shapeNumber)) { std::vector vec; shapeIndexI.push_back(vec); @@ -164,10 +163,10 @@ namespace MWRender{ } - + } - + allvertices = &initialVertices; } shapeNumber++; @@ -176,8 +175,8 @@ namespace MWRender{ if(verticesToChange->size() > 0){ - - for(std::map>::iterator iter = verticesToChange->begin(); + + for(std::map >::iterator iter = verticesToChange->begin(); iter != verticesToChange->end(); iter++) { std::vector inds = iter->second; @@ -186,25 +185,25 @@ namespace MWRender{ Ogre::Vector3 currentNormal = (*allnormals)[verIndex]; Nif::NiSkinData::BoneInfoCopy* boneinfocopy = &(allshapesiter->boneinfo[inds[0].boneinfocopyindex]); Ogre::Bone *bonePtr = 0; - - - + + + Ogre::Vector3 vecPos; - Ogre::Quaternion vecRot; + Ogre::Quaternion vecRot; std::map::iterator result = vecRotPos.find(boneinfocopy); - + if(result == vecRotPos.end()){ bonePtr = skel->getBone(boneinfocopy->bonename); - + vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - - + + PosAndRot both; both.vecPos = vecPos; both.vecRot = vecRot; vecRotPos[boneinfocopy] = both; - + } else{ PosAndRot both = result->second; @@ -213,24 +212,24 @@ namespace MWRender{ } Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight; - - + + for(std::size_t i = 1; i < inds.size(); i++){ boneinfocopy = &(allshapesiter->boneinfo[inds[i].boneinfocopyindex]); result = vecRotPos.find(boneinfocopy); - + if(result == vecRotPos.end()){ bonePtr = skel->getBone(boneinfocopy->bonename); vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - + PosAndRot both; both.vecPos = vecPos; both.vecRot = vecRot; vecRotPos[boneinfocopy] = both; - + } else{ PosAndRot both = result->second; @@ -238,22 +237,22 @@ namespace MWRender{ vecRot = both.vecRot; } - + absVertPos += (vecPos + vecRot * currentVertex) * inds[i].weight; - - + + } Ogre::Real* addr = (pReal + 3 * verIndex); *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; - + } - - - - - } + + + + + } else { //Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(copy.bonename); @@ -261,7 +260,7 @@ namespace MWRender{ Ogre::Vector3 shapetrans = copy.trafo.trans; float shapescale = copy.trafo.scale; std::vector boneSequence = copy.boneSequence; - + Ogre::Vector3 transmult; Ogre::Quaternion rotmult; float scale; @@ -269,9 +268,9 @@ namespace MWRender{ std::vector::iterator boneSequenceIter = boneSequence.begin(); if(skel->hasBone(*boneSequenceIter)){ Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); - - - + + + transmult = bonePtr->getPosition(); rotmult = bonePtr->getOrientation(); @@ -301,13 +300,13 @@ namespace MWRender{ rotmult = shaperot; scale = shapescale; } - - - + + + // Computes C = B + AxC*scale // final_vector = old_vector + old_rotation*new_vector*old_scale/ - + for(unsigned int i = 0; i < allvertices->size(); i++){ Ogre::Vector3 current = transmult + rotmult * (*allvertices)[i]; Ogre::Real* addr = pReal + i * 3; @@ -327,7 +326,7 @@ namespace MWRender{ } vbuf->unlock(); - + } } @@ -347,10 +346,10 @@ namespace MWRender{ x = 0.0; return true; } - + if ( i < 0 || i >= count ) i = 0; - + float tI = times[i]; if ( time > tI ) { @@ -390,11 +389,11 @@ namespace MWRender{ void Animation::handleAnimationTransforms(){ Ogre::SkeletonInstance* skel = base->getSkeleton(); - + Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3)); //This is a trick - + skel->_updateTransforms(); //skel->_notifyManualBonesDirty(); @@ -419,17 +418,17 @@ namespace MWRender{ if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) { slot++; - continue; + continue; } float x; float x2; - + std::vector quats = iter->getQuat(); std::vector ttime = iter->gettTime(); std::vector::iterator ttimeiter = ttime.begin(); - + std::vector rtime = iter->getrTime(); int rindexJ = 0; timeIndex(time, rtime, rindexI[slot], rindexJ, x2); @@ -442,15 +441,15 @@ namespace MWRender{ Ogre::Vector3 t; Ogre::Quaternion r; - + bool bTrans = translist1.size() > 0; if(bTrans){ Ogre::Vector3 v1 = translist1[tindexI[slot]]; Ogre::Vector3 v2 = translist1[tindexJ]; t = (v1 + (v2 - v1) * x); - + } - + bool bQuats = quats.size() > 0; if(bQuats){ r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); @@ -463,16 +462,16 @@ namespace MWRender{ if(bQuats) bone->setOrientation(r); - - + + skel->_updateTransforms(); base->getAllAnimationStates()->_notifyDirty(); - - } - + + } + slot++; } } } -} \ No newline at end of file +} From 781b16a00e9e1571fd955c50eda070e2dfa4eb39 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 20 Feb 2012 14:07:16 +0100 Subject: [PATCH 41/45] removed bCollision variable from World --- apps/openmw/mwworld/world.cpp | 5 ++--- apps/openmw/mwworld/world.hpp | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 73439ff649..c9e1775665 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -148,7 +148,7 @@ namespace MWWorld const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) : mRendering (renderer,resDir, physEng, environment),mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), - mSky (false), bCollision(false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) + mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { mPhysEngine = physEng; @@ -612,8 +612,7 @@ namespace MWWorld bool World::toggleCollisionMode() { - bCollision = mPhysics->toggleCollisionMode(); - return bCollision; + return mPhysics->toggleCollisionMode();; } bool World::toggleRenderMode (RenderMode mode) diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index b4c61eebb5..59cddb1c15 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -77,7 +77,6 @@ namespace MWWorld bool mSky; Environment& mEnvironment; int mNextDynamicRecord; - bool bCollision; Cells mCells; From 971ae94fbf0dc5d4ebab96a2e25b5f731c2f5ca8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 21 Feb 2012 11:50:04 +0100 Subject: [PATCH 42/45] Revert "workaround for the configuration problems" This reverts commit 850501e9221daf1a55d31b72c4389da158b338e6. --- components/files/configurationmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index c6e5534180..46cd0e053b 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -56,9 +56,9 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { mTokensMapping.insert(std::make_pair(mwToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalPath)); - mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserPath)); - mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalPath)); + mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, From 280babc7194bf01dfe5f9c79b4b3d45fecab51df Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Wed, 22 Feb 2012 08:34:47 +0100 Subject: [PATCH 43/45] Fixed stylesheet and configuration problems with the launcher and code cleanup --- CMakeLists.txt | 2 +- apps/launcher/datafilespage.cpp | 195 ++++++++++++++------- apps/launcher/datafilespage.hpp | 18 +- apps/launcher/graphicspage.cpp | 2 +- apps/launcher/graphicspage.hpp | 9 +- apps/launcher/main.cpp | 7 - apps/launcher/maindialog.cpp | 197 +++------------------- apps/launcher/maindialog.hpp | 7 - components/files/configurationmanager.cpp | 2 +- 9 files changed, 169 insertions(+), 270 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a83ca1c0b..41da79a055 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,7 +329,7 @@ if(WIN32) FILE(GLOB files "${OpenMW_BINARY_DIR}/Release/*.*") INSTALL(FILES ${files} DESTINATION ".") INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "." RENAME "openmw.cfg") - INSTALL(FILES "${OpenMW_BINARY_DIR}/launcher.cfg" "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION ".") + INSTALL(FILES "${OpenMW_BINARY_DIR}/launcher.qss" "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION ".") INSTALL(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION ".") SET(CPACK_GENERATOR "NSIS") diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 6eb4590373..fb8631f731 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -26,7 +26,7 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2) return index1.row() <= index2.row(); } -DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent) +DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent) : QWidget(parent) , mCfgMgr(cfg) { @@ -123,25 +123,89 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent) setupConfig(); + setupDataFiles(); createActions(); } -void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) +void DataFilesPage::setupConfig() { - // Put the paths in a boost::filesystem vector to use with Files::Collections - Files::PathContainer dataDirs; + QString config = QString::fromStdString((mCfgMgr.getLocalPath() / "launcher.cfg").string()); + QFile file(config); - foreach (const QString ¤tPath, paths) { - dataDirs.push_back(boost::filesystem::path(currentPath.toStdString())); + if (!file.exists()) { + config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string()); } + // Open our config file + mLauncherConfig = new QSettings(config, QSettings::IniFormat); + mLauncherConfig->sync(); + + + // Make sure we have no groups open + while (!mLauncherConfig->group().isEmpty()) { + mLauncherConfig->endGroup(); + } + + mLauncherConfig->beginGroup("Profiles"); + QStringList profiles = mLauncherConfig->childGroups(); + + if (profiles.isEmpty()) { + // Add a default profile + profiles.append("Default"); + } + + mProfilesComboBox->addItems(profiles); + + QString currentProfile = mLauncherConfig->value("CurrentProfile").toString(); + + if (currentProfile.isEmpty()) { + // No current profile selected + currentProfile = "Default"; + } + mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile)); + + mLauncherConfig->endGroup(); + + // Now we connect the combobox to do something if the profile changes + // This prevents strange behaviour while reading and appending the profiles + connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&))); +} + + +void DataFilesPage::setupDataFiles() +{ + // We use the Configuration Manager to retrieve the configuration values + boost::program_options::variables_map variables; + boost::program_options::options_description desc; + + 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)) + ("encoding", boost::program_options::value()->default_value("win1252")); + + mCfgMgr.readConfiguration(variables, desc); + + // Put the paths in a boost::filesystem vector to use with Files::Collections + Files::PathContainer dataDirs(variables["data"].as()); mCfgMgr.processPaths(dataDirs); + std::string local(variables["data-local"].as()); + if (!local.empty()) + { + dataDirs.push_back(Files::PathContainer::value_type(local)); + } + + if (dataDirs.empty()) + { + dataDirs.push_back(mCfgMgr.getLocalPath()); + } + // Create a file collection for the dataDirs - Files::Collections mFileCollections(dataDirs, strict); + Files::Collections fileCollections(dataDirs, !variables["fs-strict"].as()); // First we add all the master files - const Files::MultiDirCollection &esm = mFileCollections.getCollection(".esm"); + const Files::MultiDirCollection &esm = fileCollections.getCollection(".esm"); unsigned int i = 0; // Row number for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter) @@ -161,14 +225,14 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) } // Now on to the plugins - const Files::MultiDirCollection &esp = mFileCollections.getCollection(".esp"); + const Files::MultiDirCollection &esp = fileCollections.getCollection(".esp"); for (Files::MultiDirCollection::TIter iter(esp.begin()); iter!=esp.end(); ++iter) { ESMReader fileReader; QStringList availableMasters; // Will contain all found masters - fileReader.setEncoding("win1252"); // FIXME: This should be configurable! + fileReader.setEncoding(variables["encoding"].as()); fileReader.open(iter->second.string()); // First we fill the availableMasters and the mMastersWidget @@ -238,52 +302,6 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) readConfig(); } -void DataFilesPage::setupConfig() -{ - QString config = (mCfgMgr.getLocalPath() / "launcher.cfg").string().c_str(); - QFile file(config); - - if (!file.exists()) { - config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string()); - } - - file.setFileName(config); // Just for displaying information - - // Open our config file - mLauncherConfig = new QSettings(config, QSettings::IniFormat); - mLauncherConfig->sync(); - - - // Make sure we have no groups open - while (!mLauncherConfig->group().isEmpty()) { - mLauncherConfig->endGroup(); - } - - mLauncherConfig->beginGroup("Profiles"); - QStringList profiles = mLauncherConfig->childGroups(); - - if (profiles.isEmpty()) { - // Add a default profile - profiles.append("Default"); - } - - mProfilesComboBox->addItems(profiles); - - QString currentProfile = mLauncherConfig->value("CurrentProfile").toString(); - - if (currentProfile.isEmpty()) { - // No current profile selected - currentProfile = "Default"; - } - mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile)); - - mLauncherConfig->endGroup(); - - // Now we connect the combobox to do something if the profile changes - // This prevents strange behaviour while reading and appending the profiles - connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&))); -} - void DataFilesPage::createActions() { // Refresh the plugins @@ -983,6 +1001,53 @@ void DataFilesPage::writeConfig(QString profile) return; } + // Prepare the OpenMW config + + // Open the config as a QFile + QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); + + if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { + // File cannot be opened or created + QMessageBox msgBox; + msgBox.setWindowTitle("Error writing OpenMW configuration file"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
Could not open or create %0

\ + Please make sure you have the right permissions and try again.
").arg(file.fileName())); + msgBox.exec(); + + QApplication::exit(1); + } + + QTextStream in(&file); + QByteArray buffer; + + // Remove all previous master/plugin entries from config + while (!in.atEnd()) { + QString line = in.readLine(); + if (!line.contains("master") && !line.contains("plugin")) { + buffer += line += "\n"; + } + } + + file.close(); + + // Now we write back the other config entries + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { + QMessageBox msgBox; + msgBox.setWindowTitle("Error writing OpenMW configuration file"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
Could not write to %0

\ + Please make sure you have the right permissions and try again.
").arg(file.fileName())); + msgBox.exec(); + + QApplication::exit(1); + } + + file.write(buffer); + QTextStream gameConfig(&file); + // Make sure we have no groups open while (!mLauncherConfig->group().isEmpty()) { mLauncherConfig->endGroup(); @@ -995,13 +1060,16 @@ void DataFilesPage::writeConfig(QString profile) mLauncherConfig->beginGroup(profile); mLauncherConfig->remove(""); // Clear the subgroup - // First write the masters to the config - const QStringList masterList = selectedMasters(); + // First write the masters to the configs + const QStringList masters = selectedMasters(); // We don't use foreach because we need i - for (int i = 0; i < masterList.size(); ++i) { - const QString master = masterList.at(i); - mLauncherConfig->setValue(QString("Master%0").arg(i), master); + for (int i = 0; i < masters.size(); ++i) { + const QString currentMaster = masters.at(i); + + mLauncherConfig->setValue(QString("Master%0").arg(i), currentMaster); + gameConfig << "master=" << currentMaster << endl; + } // Now write all checked plugins @@ -1009,9 +1077,12 @@ void DataFilesPage::writeConfig(QString profile) for (int i = 0; i < plugins.size(); ++i) { - mLauncherConfig->setValue(QString("Plugin%1").arg(i), plugins.at(i)); + const QString currentPlugin = plugins.at(i); + mLauncherConfig->setValue(QString("Plugin%1").arg(i), currentPlugin); + gameConfig << "plugin=" << currentPlugin << endl; } + file.close(); mLauncherConfig->endGroup(); mLauncherConfig->endGroup(); diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index db1068abdc..a454fa871b 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -29,16 +29,9 @@ public: DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); ComboBox *mProfilesComboBox; - QSettings *mLauncherConfig; - const QStringList checkedPlugins(); - const QStringList selectedMasters(); - void setupConfig(); - void readConfig(); void writeConfig(QString profile = QString()); - void setupDataFiles(const QStringList &paths, bool strict); - public slots: void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void setCheckState(QModelIndex index); @@ -83,13 +76,20 @@ private: QAction *mCheckAction; QAction *mUncheckAction; - Files::ConfigurationManager& mCfgMgr; + Files::ConfigurationManager &mCfgMgr; + + QSettings *mLauncherConfig; + + const QStringList checkedPlugins(); + const QStringList selectedMasters(); void addPlugins(const QModelIndex &index); void removePlugins(const QModelIndex &index); void uncheckPlugins(); void createActions(); - + void setupDataFiles(); + void setupConfig(); + void readConfig(); void scrollToSelection(); }; diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index d41a333563..c9dca18793 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -3,7 +3,7 @@ #include "graphicspage.hpp" #include -GraphicsPage::GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent) +GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) : QWidget(parent) , mCfgMgr(cfg) { diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index ffd7a41b8c..bdfd4f038d 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -20,9 +20,7 @@ class GraphicsPage : public QWidget Q_OBJECT public: - GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); - - QSettings *mOgreConfig; + GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent = 0); void writeConfig(); @@ -30,7 +28,6 @@ public slots: void rendererChanged(const QString &renderer); private: - Files::ConfigurationManager& mCfgMgr; Ogre::Root *mOgre; Ogre::RenderSystem *mSelectedRenderSystem; Ogre::RenderSystem *mOpenGLRenderSystem; @@ -60,6 +57,10 @@ private: QCheckBox *mD3DVSyncCheckBox; QCheckBox *mD3DFullScreenCheckBox; + QSettings *mOgreConfig; + + Files::ConfigurationManager &mCfgMgr; + QString getConfigValue(const QString &key, Ogre::RenderSystem *renderer); QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer); diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index f108882a3f..bd29e2bcac 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -31,13 +31,6 @@ int main(int argc, char *argv[]) QDir::setCurrent(dir.absolutePath()); - // Load the stylesheet - QFile file("./launcher.qss"); - - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - app.setStyleSheet(styleSheet); - MainDialog dialog; return dialog.exec(); diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index dd9f0d653c..14f452fa3f 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -45,6 +45,20 @@ MainDialog::MainDialog() setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); setMinimumSize(QSize(575, 575)); + // Load the stylesheet + QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "launcher.qss").string()); + QFile file(config); + + if (!file.exists()) { + file.setFileName(QString::fromStdString((mCfgMgr.getLocalPath() / "launcher.qss").string())); + } + + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + qApp->setStyleSheet(styleSheet); + file.close(); + + connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(play())); @@ -85,116 +99,13 @@ void MainDialog::createIcons() } -QStringList MainDialog::readConfig(const QString &fileName) -{ - // We can't use QSettings directly because it - // does not support multiple keys with the same name - QFile file(fileName); - - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QMessageBox msgBox; - msgBox.setWindowTitle("Error opening OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - - QApplication::exit(); // File cannot be opened or created - } - - QTextStream in(&file); - QStringList dataDirs; - QString dataLocal; - - // Read the config line by line - while (!in.atEnd()) { - QString line = in.readLine(); - - if (line.startsWith("data=")) { - dataDirs.append(line.remove("data=")); - } - - // Read the data-local key, if more than one are found only the last is used - if (line.startsWith("data-local=")) { - dataLocal = line.remove("data-local="); - } - - // Read fs-strict key - if (line.startsWith("fs-strict=")) { - QString value = line.remove("fs-strict="); - - (value.toLower() == QLatin1String("true")) - ? mStrict = true - : mStrict = false; - - } - - } - - // Add the data-local= key to the end of the dataDirs for priority reasons - if (!dataLocal.isEmpty()) { - dataDirs.append(dataLocal); - } - - if (!dataDirs.isEmpty()) - { - // Reset the global datadirs to the newly read entries - // Else return the previous dataDirs because nothing was found in this file; - mDataDirs = dataDirs; - } - - file.close(); - - return mDataDirs; -} - void MainDialog::createPages() { mPlayPage = new PlayPage(this); mGraphicsPage = new GraphicsPage(mCfgMgr, this); mDataFilesPage = new DataFilesPage(mCfgMgr, this); - // Retrieve all data entries from the configs - QStringList dataDirs; - - // Global location - QFile file(QString::fromStdString((mCfgMgr.getGlobalPath()/"openmw.cfg").string())); - if (file.exists()) { - dataDirs = readConfig(file.fileName()); - } - - // Local location - file.setFileName("./openmw.cfg"); - - if (file.exists()) { - dataDirs = readConfig(file.fileName()); - } - - // User location - file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); - if (file.exists()) { - dataDirs = readConfig(file.fileName()); - } - - file.close(); - - if (!dataDirs.isEmpty()) { - // Now pass the datadirs on to the DataFilesPage - mDataFilesPage->setupDataFiles(dataDirs, mStrict); - } else { - QMessageBox msgBox; - msgBox.setWindowTitle("Error reading OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not read the location of the data files

\ - Please make sure OpenMW is correctly configured and try again.
")); - msgBox.exec(); - - QApplication::exit(); // No data or data-local entries in openmw.cfg - } - - // Set the combobox of the play page to imitate the comobox on the datafilespage + // Set the combobox of the play page to imitate the combobox on the datafilespage mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model()); mPlayPage->mProfilesComboBox->setCurrentIndex(mDataFilesPage->mProfilesComboBox->currentIndex()); @@ -246,14 +157,16 @@ void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) void MainDialog::closeEvent(QCloseEvent *event) { // Now write all config files - writeConfig(); + mDataFilesPage->writeConfig(); + mGraphicsPage->writeConfig(); event->accept(); } void MainDialog::play() { // First do a write of all the configs, just to be sure - writeConfig(); + mDataFilesPage->writeConfig(); + mGraphicsPage->writeConfig(); #ifdef Q_WS_WIN QString game = "./openmw.exe"; @@ -313,75 +226,3 @@ void MainDialog::play() close(); } } - -void MainDialog::writeConfig() -{ - // Write the profiles - mDataFilesPage->writeConfig(); - mDataFilesPage->mLauncherConfig->sync(); - - // Write the graphics settings - mGraphicsPage->writeConfig(); - mGraphicsPage->mOgreConfig->sync(); - - QStringList dataFiles = mDataFilesPage->selectedMasters(); - dataFiles.append(mDataFilesPage->checkedPlugins()); - - // Open the config as a QFile - QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); - - if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { - // File cannot be opened or created - QMessageBox msgBox; - msgBox.setWindowTitle("Error writing OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open or create %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - - QApplication::exit(1); - } - - QTextStream in(&file); - QByteArray buffer; - - // Remove all previous master/plugin entries from config - while (!in.atEnd()) { - QString line = in.readLine(); - if (!line.contains("master") && !line.contains("plugin")) { - buffer += line += "\n"; - } - } - - file.close(); - - // Now we write back the other config entries - if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { - QMessageBox msgBox; - msgBox.setWindowTitle("Error writing OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not write to %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - - QApplication::exit(1); - } - - file.write(buffer); - - QTextStream out(&file); - - // Write the list of game files to the config - foreach (const QString ¤tFile, dataFiles) { - - if (currentFile.endsWith(QString(".esm"), Qt::CaseInsensitive)) { - out << "master=" << currentFile << endl; - } else if (currentFile.endsWith(QString(".esp"), Qt::CaseInsensitive)) { - out << "plugin=" << currentFile << endl; - } - } - - file.close(); -} diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index 718fde4f7f..d6d0e9974e 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -28,15 +28,11 @@ public slots: void play(); void profileChanged(int index); - private: void createIcons(); void createPages(); - void writeConfig(); void closeEvent(QCloseEvent *event); - QStringList readConfig(const QString &fileName); - QListWidget *mIconWidget; QStackedWidget *mPagesWidget; @@ -44,9 +40,6 @@ private: GraphicsPage *mGraphicsPage; DataFilesPage *mDataFilesPage; - QStringList mDataDirs; - bool mStrict; - Files::ConfigurationManager mCfgMgr; }; diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index c5561d6527..5cf2952c74 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -124,7 +124,7 @@ void ConfigurationManager::loadConfig(const boost::filesystem::path& path, if (configFileStream.is_open()) { boost::program_options::store(boost::program_options::parse_config_file( - configFileStream, description), variables); + configFileStream, description, true), variables); std::cout << "done." << std::endl; } From e0206edc44d13dfe8c78826f827f20963e684d3c Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 22 Feb 2012 20:00:17 +0100 Subject: [PATCH 44/45] Fixed stupid bug in getGlobalDataPath. Signed-off-by: Lukasz Gromanowski --- components/files/windowspath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index e810412720..cf73b37289 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -64,7 +64,7 @@ boost::filesystem::path WindowsPath::getLocalPath() const boost::filesystem::path WindowsPath::getGlobalDataPath() const { - return getGlobalConfigPath(); + return getGlobalPath(); } boost::filesystem::path WindowsPath::getInstallPath() const From d5f1d7eed7517eb4a9df03abea61060ed2c3187b Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 22 Feb 2012 23:56:07 +0100 Subject: [PATCH 45/45] Fix for processing tokens inside data-local config option. Signed-off-by: Lukasz Gromanowski --- apps/openmw/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index dd7a1e7805..ec1775ac83 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -160,7 +160,6 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.enableFSStrict(variables["fs-strict"].as()); Files::PathContainer dataDirs(variables["data"].as()); - cfgMgr.processPaths(dataDirs); std::string local(variables["data-local"].as()); if (!local.empty()) @@ -173,6 +172,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat dataDirs.push_back(cfgMgr.getLocalPath()); } + cfgMgr.processPaths(dataDirs); + engine.setDataDirs(dataDirs); engine.setResourceDir(variables["resources"].as());