diff --git a/.gitignore b/.gitignore index b3bb8d82d..26ba80e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ cmake_install.cmake Makefile makefile data +*.kdev4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 84cef306e..9cc741c67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,14 @@ set (OPENMW_VERSION_RELEASE 0) set (OPENMW_VERSION "${OPENMW_VERSION_MAJOR}.${OPENMW_VERSION_MINOR}.${OPENMW_VERSION_RELEASE}") +# Debug suffix for plugins +set(DEBUG_SUFFIX "") +if (DEFINED CMAKE_BUILD_TYPE) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(DEBUG_SUFFIX "_d") + endif() +endif() + # doxygen main page configure_file ("${OpenMW_SOURCE_DIR}/Docs/mainpage.hpp.cmake" "${OpenMW_SOURCE_DIR}/Docs/mainpage.hpp") @@ -93,9 +101,8 @@ ENDIF() set(LIBDIR ${CMAKE_SOURCE_DIR}/libs) -set(MANGLE_VFS ${LIBDIR}/mangle/vfs/servers/ogre_vfs.cpp) set(MANGLE_INPUT ${LIBDIR}/mangle/input/servers/ois_driver.cpp) -set(MANGLE_ALL ${MANGLE_VFS} ${MANGLE_INPUT}) +set(MANGLE_ALL ${MANGLE_INPUT}) source_group(libs\\mangle FILES ${MANGLE_ALL}) set(OENGINE_OGRE diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index bb3f76f3c..cf331e7dd 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -39,7 +39,7 @@ add_openmw_dir (mwscript locals scriptmanager compilercontext interpretercontext cellextensions miscextensions guiextensions soundextensions skyextensions statsextensions containerextensions aiextensions controlextensions extensions globalscripts ref dialogueextensions - animationextensions + animationextensions transformationextensions ) add_openmw_dir (mwsound @@ -79,7 +79,6 @@ ENDIF(WIN32) ENDIF(OGRE_STATIC) add_executable(openmw ${OPENMW_LIBS} ${OPENMW_LIBS_HEADER} - ${COMPONENT_FILES} ${OPENMW_FILES} ${GAME} ${GAME_HEADER} ${APPLE_BUNDLE_RESOURCES} diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 45b4ab514..7966639a6 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -1,25 +1,13 @@ #include "engine.hpp" #include "components/esm/loadcell.hpp" -#include - -#include -#include - #include #include #include -#include -#include - -#include #include -#include -#include #include -#include #include #include @@ -31,16 +19,12 @@ #include "mwgui/cursorreplace.hpp" #include "mwscript/scriptmanager.hpp" -#include "mwscript/compilercontext.hpp" -#include "mwscript/interpretercontext.hpp" #include "mwscript/extensions.hpp" -#include "mwscript/globalscripts.hpp" #include "mwsound/soundmanager.hpp" #include "mwworld/class.hpp" #include "mwworld/player.hpp" -#include "mwworld/cellstore.hpp" #include "mwworld/worldimp.hpp" #include "mwclass/classes.hpp" @@ -50,9 +34,6 @@ #include "mwmechanics/mechanicsmanager.hpp" -#include "mwbase/environment.hpp" -#include "mwbase/world.hpp" - void OMW::Engine::executeLocalScripts() { diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index cf1ef3b9c..031cae551 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -1,10 +1,6 @@ #ifndef ENGINE_H #define ENGINE_H -#include - -#include - #include #include diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 68aa12fb3..993ec6623 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -1,13 +1,5 @@ #include -#include -#include - -#include - -#include -#include -#include #include #include "engine.hpp" @@ -16,15 +8,10 @@ #include #include -# if !defined(_DEBUG) -# include -# include -# endif - // For OutputDebugString #include // makes __argc and __argv available on windows -#include +#include #endif @@ -52,8 +39,6 @@ inline boost::filesystem::path lexical_cast mMap; }; diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index b2c19ab35..6937cbf3b 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -1,8 +1,6 @@ #ifndef GAME_MWBASE_WORLD_H #define GAME_MWBASE_WORLD_H -#include -#include #include #include @@ -178,6 +176,10 @@ namespace MWBase virtual void moveObject (const MWWorld::Ptr& ptr, float x, float y, float z) = 0; + virtual void scaleObject (const MWWorld::Ptr& ptr, float scale) = 0; + + virtual void rotateObject(const MWWorld::Ptr& ptr,float x,float y,float z) = 0; + virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const = 0; ///< Convert cell numbers to position. diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 237f54e82..1274be09a 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -1,7 +1,6 @@ #ifndef GAME_MWCLASS_CREATURE_H #define GAME_MWCLASS_CREATURE_H -#include "../mwworld/class.hpp" #include "../mwrender/renderinginterface.hpp" #include "../mwrender/actors.hpp" diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index 46b5b9662..da5f0df96 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -9,7 +9,7 @@ namespace MWClass { public: - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + 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) const; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 2570408f7..ffe7dec61 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -125,10 +125,14 @@ namespace MWClass void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { + MWWorld::LiveCellRef *ref = ptr.get(); 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_"; @@ -136,7 +140,8 @@ namespace MWClass std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertActorPhysics(ptr, smodel); + physics.insertActorPhysics(ptr, smodel); + MWBase::Environment::get().getMechanicsManager()->addActor (ptr); } @@ -365,4 +370,10 @@ namespace MWClass stats.useSkill (skill, *class_, usageType); } + + void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const + { + y = 0; + x = 0; + } } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 74a80c085..b32a162a1 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -48,7 +48,7 @@ namespace MWClass 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; + 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; @@ -85,6 +85,8 @@ namespace MWClass virtual void skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType) const; ///< Inform actor \a ptr that a skill use has succeeded. + virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const; + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index ac5d85f23..101f4cefa 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -9,7 +9,7 @@ namespace MWClass { public: - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + 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) const; diff --git a/apps/openmw/mwclass/static.hpp b/apps/openmw/mwclass/static.hpp index cd1626c19..c223df1ac 100644 --- a/apps/openmw/mwclass/static.hpp +++ b/apps/openmw/mwclass/static.hpp @@ -9,7 +9,7 @@ namespace MWClass { public: - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + 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) const; diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index b1d94f11e..6f3f0c901 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -591,7 +591,7 @@ namespace MWDialogue mIsInChoice = false; mCompilerContext.setExtensions (&extensions); mDialogueMap.clear(); - actorKnownTopics.clear(); + mActorKnownTopics.clear(); ESMS::RecListCaseT::MapType dialogueList = MWBase::Environment::get().getWorld()->getStore().dialogs.list; for(ESMS::RecListCaseT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) { @@ -601,24 +601,24 @@ namespace MWDialogue void DialogueManager::addTopic(std::string topic) { - knownTopics[toLower(topic)] = true; + mKnownTopics[toLower(topic)] = true; } void DialogueManager::parseText(std::string text) { std::list::iterator it; - for(it = actorKnownTopics.begin();it != actorKnownTopics.end();++it) + for(it = mActorKnownTopics.begin();it != mActorKnownTopics.end();++it) { size_t pos = find_str_ci(text,*it,0); if(pos !=std::string::npos) { if(pos==0) { - knownTopics[*it] = true; + mKnownTopics[*it] = true; } else if(text.substr(pos -1,1) == " ") { - knownTopics[*it] = true; + mKnownTopics[*it] = true; } } } @@ -632,7 +632,7 @@ namespace MWDialogue mActor = actor; - actorKnownTopics.clear(); + mActorKnownTopics.clear(); //initialise the GUI MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Dialogue); @@ -742,7 +742,7 @@ namespace MWDialogue std::list keywordList; int choice = mChoice; mChoice = -1; - actorKnownTopics.clear(); + mActorKnownTopics.clear(); MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow(); ESMS::RecListCaseT::MapType dialogueList = MWBase::Environment::get().getWorld()->getStore().dialogs.list; for(ESMS::RecListCaseT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) @@ -755,9 +755,9 @@ namespace MWDialogue { if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,true)) { - actorKnownTopics.push_back(toLower(it->first)); + mActorKnownTopics.push_back(toLower(it->first)); //does the player know the topic? - if(knownTopics.find(toLower(it->first)) != knownTopics.end()) + if(mKnownTopics.find(toLower(it->first)) != mKnownTopics.end()) { keywordList.push_back(it->first); break; diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index 992175c0c..d139ddc01 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -26,8 +26,8 @@ namespace MWDialogue void updateTopics(); std::map mDialogueMap; - std::map knownTopics;// Those are the topics the player knows. - std::list actorKnownTopics; + std::map mKnownTopics;// Those are the topics the player knows. + std::list mActorKnownTopics; MWScript::CompilerContext mCompilerContext; std::ostream mErrorStream; diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index 69056759d..0f1a04c27 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -15,15 +15,15 @@ BirthDialog::BirthDialog(WindowManager& parWindowManager) // Centre dialog center(); - getWidget(spellArea, "SpellArea"); + getWidget(mSpellArea, "SpellArea"); - getWidget(birthImage, "BirthsignImage"); + getWidget(mBirthImage, "BirthsignImage"); - getWidget(birthList, "BirthsignList"); - birthList->setScrollVisible(true); - birthList->eventListSelectAccept += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); - birthList->eventListMouseItemActivate += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); - birthList->eventListChangePosition += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); + getWidget(mBirthList, "BirthsignList"); + mBirthList->setScrollVisible(true); + mBirthList->eventListSelectAccept += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); + mBirthList->eventListMouseItemActivate += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); + mBirthList->eventListChangePosition += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); @@ -68,14 +68,14 @@ void BirthDialog::open() void BirthDialog::setBirthId(const std::string &birthId) { - currentBirthId = birthId; - birthList->setIndexSelected(MyGUI::ITEM_NONE); - size_t count = birthList->getItemCount(); + mCurrentBirthId = birthId; + mBirthList->setIndexSelected(MyGUI::ITEM_NONE); + size_t count = mBirthList->getItemCount(); for (size_t i = 0; i < count; ++i) { - if (boost::iequals(*birthList->getItemDataAt(i), birthId)) + if (boost::iequals(*mBirthList->getItemDataAt(i), birthId)) { - birthList->setIndexSelected(i); + mBirthList->setIndexSelected(i); break; } } @@ -100,11 +100,11 @@ void BirthDialog::onSelectBirth(MyGUI::ListBox* _sender, size_t _index) if (_index == MyGUI::ITEM_NONE) return; - const std::string *birthId = birthList->getItemDataAt(_index); - if (boost::iequals(currentBirthId, *birthId)) + const std::string *birthId = mBirthList->getItemDataAt(_index); + if (boost::iequals(mCurrentBirthId, *birthId)) return; - currentBirthId = *birthId; + mCurrentBirthId = *birthId; updateSpells(); } @@ -112,7 +112,7 @@ void BirthDialog::onSelectBirth(MyGUI::ListBox* _sender, size_t _index) void BirthDialog::updateBirths() { - birthList->removeAllItems(); + mBirthList->removeAllItems(); const ESMS::ESMStore &store = mWindowManager.getStore(); @@ -122,34 +122,34 @@ void BirthDialog::updateBirths() for (; it != end; ++it) { const ESM::BirthSign &birth = it->second; - birthList->addItem(birth.name, it->first); - if (boost::iequals(it->first, currentBirthId)) - birthList->setIndexSelected(index); + mBirthList->addItem(birth.name, it->first); + if (boost::iequals(it->first, mCurrentBirthId)) + mBirthList->setIndexSelected(index); ++index; } } void BirthDialog::updateSpells() { - for (std::vector::iterator it = spellItems.begin(); it != spellItems.end(); ++it) + for (std::vector::iterator it = mSpellItems.begin(); it != mSpellItems.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } - spellItems.clear(); + mSpellItems.clear(); - if (currentBirthId.empty()) + if (mCurrentBirthId.empty()) return; MWSpellPtr spellWidget; const int lineHeight = 18; - MyGUI::IntCoord coord(0, 0, spellArea->getWidth(), 18); + MyGUI::IntCoord coord(0, 0, mSpellArea->getWidth(), 18); const ESMS::ESMStore &store = mWindowManager.getStore(); - const ESM::BirthSign *birth = store.birthSigns.find(currentBirthId); + const ESM::BirthSign *birth = store.birthSigns.find(mCurrentBirthId); std::string texturePath = std::string("textures\\") + birth->texture; fixTexturePath(texturePath); - birthImage->setImageTexture(texturePath); + mBirthImage->setImageTexture(texturePath); std::vector abilities, powers, spells; @@ -183,25 +183,25 @@ void BirthDialog::updateSpells() { if (!categories[category].spells.empty()) { - MyGUI::TextBox* label = spellArea->createWidget("SandBrightText", coord, MyGUI::Align::Default, std::string("Label")); + MyGUI::TextBox* label = mSpellArea->createWidget("SandBrightText", coord, MyGUI::Align::Default, std::string("Label")); label->setCaption(mWindowManager.getGameSettingString(categories[category].label, "")); - spellItems.push_back(label); + mSpellItems.push_back(label); coord.top += lineHeight; std::vector::const_iterator end = categories[category].spells.end(); for (std::vector::const_iterator it = categories[category].spells.begin(); it != end; ++it) { const std::string &spellId = *it; - spellWidget = spellArea->createWidget("MW_StatName", coord, MyGUI::Align::Default, std::string("Spell") + boost::lexical_cast(i)); + spellWidget = mSpellArea->createWidget("MW_StatName", coord, MyGUI::Align::Default, std::string("Spell") + boost::lexical_cast(i)); spellWidget->setWindowManager(&mWindowManager); spellWidget->setSpellId(spellId); - spellItems.push_back(spellWidget); + mSpellItems.push_back(spellWidget); coord.top += lineHeight; MyGUI::IntCoord spellCoord = coord; spellCoord.height = 24; // TODO: This should be fetched from the skin somehow, or perhaps a widget in the layout as a template? - spellWidget->createEffectWidgets(spellItems, spellArea, spellCoord, (category == 0) ? MWEffectList::EF_Constant : 0); + spellWidget->createEffectWidgets(mSpellItems, mSpellArea, spellCoord, (category == 0) ? MWEffectList::EF_Constant : 0); coord.top = spellCoord.top; ++i; diff --git a/apps/openmw/mwgui/birth.hpp b/apps/openmw/mwgui/birth.hpp index e61be736a..770e4ba36 100644 --- a/apps/openmw/mwgui/birth.hpp +++ b/apps/openmw/mwgui/birth.hpp @@ -25,7 +25,7 @@ namespace MWGui GM_Female }; - const std::string &getBirthId() const { return currentBirthId; } + const std::string &getBirthId() const { return mCurrentBirthId; } void setBirthId(const std::string &raceId); void setNextButtonShow(bool shown); @@ -49,12 +49,12 @@ namespace MWGui void updateBirths(); void updateSpells(); - MyGUI::ListBox* birthList; - MyGUI::WidgetPtr spellArea; - MyGUI::ImageBox* birthImage; - std::vector spellItems; + MyGUI::ListBox* mBirthList; + MyGUI::WidgetPtr mSpellArea; + MyGUI::ImageBox* mBirthImage; + std::vector mSpellItems; - std::string currentBirthId; + std::string mCurrentBirthId; }; } #endif diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index d0f21f945..48e01eb1e 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -1,6 +1,5 @@ #include "class.hpp" -#include #include #include @@ -26,8 +25,8 @@ GenerateClassResultDialog::GenerateClassResultDialog(WindowManager& parWindowMan setText("ReflectT", mWindowManager.getGameSettingString("sMessageQuestionAnswer1", "")); - getWidget(classImage, "ClassImage"); - getWidget(className, "ClassName"); + getWidget(mClassImage, "ClassImage"); + getWidget(mClassName, "ClassName"); MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); @@ -51,15 +50,15 @@ void GenerateClassResultDialog::open() std::string GenerateClassResultDialog::getClassId() const { - return className->getCaption(); + return mClassName->getCaption(); } void GenerateClassResultDialog::setClassId(const std::string &classId) { - currentClassId = classId; - classImage->setImageTexture(std::string("textures\\levelup\\") + currentClassId + ".dds"); + mCurrentClassId = classId; + mClassImage->setImageTexture(std::string("textures\\levelup\\") + mCurrentClassId + ".dds"); const ESMS::ESMStore &store = mWindowManager.getStore(); - className->setCaption(store.classes.find(currentClassId)->name); + mClassName->setCaption(store.classes.find(mCurrentClassId)->name); } // widget controls @@ -82,29 +81,29 @@ PickClassDialog::PickClassDialog(WindowManager& parWindowManager) // Centre dialog center(); - getWidget(specializationName, "SpecializationName"); + getWidget(mSpecializationName, "SpecializationName"); - getWidget(favoriteAttribute[0], "FavoriteAttribute0"); - getWidget(favoriteAttribute[1], "FavoriteAttribute1"); - favoriteAttribute[0]->setWindowManager(&mWindowManager); - favoriteAttribute[1]->setWindowManager(&mWindowManager); + getWidget(mFavoriteAttribute[0], "FavoriteAttribute0"); + getWidget(mFavoriteAttribute[1], "FavoriteAttribute1"); + mFavoriteAttribute[0]->setWindowManager(&mWindowManager); + mFavoriteAttribute[1]->setWindowManager(&mWindowManager); for(int i = 0; i < 5; i++) { char theIndex = '0'+i; - getWidget(majorSkill[i], std::string("MajorSkill").append(1, theIndex)); - getWidget(minorSkill[i], std::string("MinorSkill").append(1, theIndex)); - majorSkill[i]->setWindowManager(&mWindowManager); - minorSkill[i]->setWindowManager(&mWindowManager); + getWidget(mMajorSkill[i], std::string("MajorSkill").append(1, theIndex)); + getWidget(mMinorSkill[i], std::string("MinorSkill").append(1, theIndex)); + mMajorSkill[i]->setWindowManager(&mWindowManager); + mMinorSkill[i]->setWindowManager(&mWindowManager); } - getWidget(classList, "ClassList"); - classList->setScrollVisible(true); - classList->eventListSelectAccept += MyGUI::newDelegate(this, &PickClassDialog::onSelectClass); - classList->eventListMouseItemActivate += MyGUI::newDelegate(this, &PickClassDialog::onSelectClass); - classList->eventListChangePosition += MyGUI::newDelegate(this, &PickClassDialog::onSelectClass); + getWidget(mClassList, "ClassList"); + mClassList->setScrollVisible(true); + mClassList->eventListSelectAccept += MyGUI::newDelegate(this, &PickClassDialog::onSelectClass); + mClassList->eventListMouseItemActivate += MyGUI::newDelegate(this, &PickClassDialog::onSelectClass); + mClassList->eventListChangePosition += MyGUI::newDelegate(this, &PickClassDialog::onSelectClass); - getWidget(classImage, "ClassImage"); + getWidget(mClassImage, "ClassImage"); MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); @@ -148,14 +147,14 @@ void PickClassDialog::open() void PickClassDialog::setClassId(const std::string &classId) { - currentClassId = classId; - classList->setIndexSelected(MyGUI::ITEM_NONE); - size_t count = classList->getItemCount(); + mCurrentClassId = classId; + mClassList->setIndexSelected(MyGUI::ITEM_NONE); + size_t count = mClassList->getItemCount(); for (size_t i = 0; i < count; ++i) { - if (boost::iequals(*classList->getItemDataAt(i), classId)) + if (boost::iequals(*mClassList->getItemDataAt(i), classId)) { - classList->setIndexSelected(i); + mClassList->setIndexSelected(i); break; } } @@ -180,11 +179,11 @@ void PickClassDialog::onSelectClass(MyGUI::ListBox* _sender, size_t _index) if (_index == MyGUI::ITEM_NONE) return; - const std::string *classId = classList->getItemDataAt(_index); - if (boost::iequals(currentClassId, *classId)) + const std::string *classId = mClassList->getItemDataAt(_index); + if (boost::iequals(mCurrentClassId, *classId)) return; - currentClassId = *classId; + mCurrentClassId = *classId; updateStats(); } @@ -192,7 +191,7 @@ void PickClassDialog::onSelectClass(MyGUI::ListBox* _sender, size_t _index) void PickClassDialog::updateClasses() { - classList->removeAllItems(); + mClassList->removeAllItems(); const ESMS::ESMStore &store = mWindowManager.getStore(); @@ -207,19 +206,19 @@ void PickClassDialog::updateClasses() continue; const std::string &id = it->first; - classList->addItem(klass.name, id); - if (boost::iequals(id, currentClassId)) - classList->setIndexSelected(index); + mClassList->addItem(klass.name, id); + if (boost::iequals(id, mCurrentClassId)) + mClassList->setIndexSelected(index); ++index; } } void PickClassDialog::updateStats() { - if (currentClassId.empty()) + if (mCurrentClassId.empty()) return; const ESMS::ESMStore &store = mWindowManager.getStore(); - const ESM::Class *klass = store.classes.search(currentClassId); + const ESM::Class *klass = store.classes.search(mCurrentClassId); if (!klass) return; @@ -231,23 +230,23 @@ void PickClassDialog::updateStats() "sSpecializationStealth" }; std::string specName = mWindowManager.getGameSettingString(specIds[specialization], specIds[specialization]); - specializationName->setCaption(specName); - ToolTips::createSpecializationToolTip(specializationName, specName, specialization); + mSpecializationName->setCaption(specName); + ToolTips::createSpecializationToolTip(mSpecializationName, specName, specialization); - favoriteAttribute[0]->setAttributeId(klass->data.attribute[0]); - favoriteAttribute[1]->setAttributeId(klass->data.attribute[1]); - ToolTips::createAttributeToolTip(favoriteAttribute[0], favoriteAttribute[0]->getAttributeId()); - ToolTips::createAttributeToolTip(favoriteAttribute[1], favoriteAttribute[1]->getAttributeId()); + mFavoriteAttribute[0]->setAttributeId(klass->data.attribute[0]); + mFavoriteAttribute[1]->setAttributeId(klass->data.attribute[1]); + ToolTips::createAttributeToolTip(mFavoriteAttribute[0], mFavoriteAttribute[0]->getAttributeId()); + ToolTips::createAttributeToolTip(mFavoriteAttribute[1], mFavoriteAttribute[1]->getAttributeId()); for (int i = 0; i < 5; ++i) { - minorSkill[i]->setSkillNumber(klass->data.skills[i][0]); - majorSkill[i]->setSkillNumber(klass->data.skills[i][1]); - ToolTips::createSkillToolTip(minorSkill[i], klass->data.skills[i][0]); - ToolTips::createSkillToolTip(majorSkill[i], klass->data.skills[i][1]); + mMinorSkill[i]->setSkillNumber(klass->data.skills[i][0]); + mMajorSkill[i]->setSkillNumber(klass->data.skills[i][1]); + ToolTips::createSkillToolTip(mMinorSkill[i], klass->data.skills[i][0]); + ToolTips::createSkillToolTip(mMajorSkill[i], klass->data.skills[i][1]); } - classImage->setImageTexture(std::string("textures\\levelup\\") + currentClassId + ".dds"); + mClassImage->setImageTexture(std::string("textures\\levelup\\") + mCurrentClassId + ".dds"); } /* InfoBoxDialog */ @@ -284,59 +283,59 @@ void InfoBoxDialog::layoutVertically(MyGUI::WidgetPtr widget, int margin) InfoBoxDialog::InfoBoxDialog(WindowManager& parWindowManager) : WindowBase("openmw_infobox.layout", parWindowManager) - , currentButton(-1) + , mCurrentButton(-1) { - getWidget(textBox, "TextBox"); - getWidget(text, "Text"); - text->getSubWidgetText()->setWordWrap(true); - getWidget(buttonBar, "ButtonBar"); + getWidget(mTextBox, "TextBox"); + getWidget(mText, "Text"); + mText->getSubWidgetText()->setWordWrap(true); + getWidget(mButtonBar, "ButtonBar"); center(); } void InfoBoxDialog::setText(const std::string &str) { - text->setCaption(str); - textBox->setVisible(!str.empty()); - fitToText(text); + mText->setCaption(str); + mTextBox->setVisible(!str.empty()); + fitToText(mText); } std::string InfoBoxDialog::getText() const { - return text->getCaption(); + return mText->getCaption(); } void InfoBoxDialog::setButtons(ButtonList &buttons) { - for (std::vector::iterator it = this->buttons.begin(); it != this->buttons.end(); ++it) + for (std::vector::iterator it = this->mButtons.begin(); it != this->mButtons.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } - this->buttons.clear(); - currentButton = -1; + this->mButtons.clear(); + mCurrentButton = -1; // TODO: The buttons should be generated from a template in the layout file, ie. cloning an existing widget MyGUI::ButtonPtr button; - MyGUI::IntCoord coord = MyGUI::IntCoord(0, 0, buttonBar->getWidth(), 10); + MyGUI::IntCoord coord = MyGUI::IntCoord(0, 0, mButtonBar->getWidth(), 10); ButtonList::const_iterator end = buttons.end(); for (ButtonList::const_iterator it = buttons.begin(); it != end; ++it) { const std::string &text = *it; - button = buttonBar->createWidget("MW_Button", coord, MyGUI::Align::Top | MyGUI::Align::HCenter, ""); + button = mButtonBar->createWidget("MW_Button", coord, MyGUI::Align::Top | MyGUI::Align::HCenter, ""); button->getSubWidgetText()->setWordWrap(true); button->setCaption(text); fitToText(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &InfoBoxDialog::onButtonClicked); coord.top += button->getHeight(); - this->buttons.push_back(button); + this->mButtons.push_back(button); } } void InfoBoxDialog::open() { // Fix layout - layoutVertically(textBox, 4); - layoutVertically(buttonBar, 6); + layoutVertically(mTextBox, 4); + layoutVertically(mButtonBar, 6); layoutVertically(mMainWidget, 4 + 6); center(); @@ -345,18 +344,18 @@ void InfoBoxDialog::open() int InfoBoxDialog::getChosenButton() const { - return currentButton; + return mCurrentButton; } void InfoBoxDialog::onButtonClicked(MyGUI::WidgetPtr _sender) { - std::vector::const_iterator end = buttons.end(); + std::vector::const_iterator end = mButtons.end(); int i = 0; - for (std::vector::const_iterator it = buttons.begin(); it != end; ++it) + for (std::vector::const_iterator it = mButtons.begin(); it != end; ++it) { if (*it == _sender) { - currentButton = i; + mCurrentButton = i; eventButtonSelected(i); return; } @@ -382,49 +381,49 @@ ClassChoiceDialog::ClassChoiceDialog(WindowManager& parWindowManager) CreateClassDialog::CreateClassDialog(WindowManager& parWindowManager) : WindowBase("openmw_chargen_create_class.layout", parWindowManager) - , specDialog(nullptr) - , attribDialog(nullptr) - , skillDialog(nullptr) - , descDialog(nullptr) + , mSpecDialog(nullptr) + , mAttribDialog(nullptr) + , mSkillDialog(nullptr) + , mDescDialog(nullptr) { // Centre dialog center(); setText("SpecializationT", mWindowManager.getGameSettingString("sChooseClassMenu1", "Specialization")); - getWidget(specializationName, "SpecializationName"); - specializationName->eventMouseButtonClick += MyGUI::newDelegate(this, &CreateClassDialog::onSpecializationClicked); + getWidget(mSpecializationName, "SpecializationName"); + mSpecializationName->eventMouseButtonClick += MyGUI::newDelegate(this, &CreateClassDialog::onSpecializationClicked); setText("FavoriteAttributesT", mWindowManager.getGameSettingString("sChooseClassMenu2", "Favorite Attributes:")); - getWidget(favoriteAttribute0, "FavoriteAttribute0"); - getWidget(favoriteAttribute1, "FavoriteAttribute1"); - favoriteAttribute0->setWindowManager(&mWindowManager); - favoriteAttribute1->setWindowManager(&mWindowManager); - favoriteAttribute0->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeClicked); - favoriteAttribute1->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeClicked); + getWidget(mFavoriteAttribute0, "FavoriteAttribute0"); + getWidget(mFavoriteAttribute1, "FavoriteAttribute1"); + mFavoriteAttribute0->setWindowManager(&mWindowManager); + mFavoriteAttribute1->setWindowManager(&mWindowManager); + mFavoriteAttribute0->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeClicked); + mFavoriteAttribute1->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeClicked); setText("MajorSkillT", mWindowManager.getGameSettingString("sSkillClassMajor", "")); setText("MinorSkillT", mWindowManager.getGameSettingString("sSkillClassMinor", "")); for(int i = 0; i < 5; i++) { char theIndex = '0'+i; - getWidget(majorSkill[i], std::string("MajorSkill").append(1, theIndex)); - getWidget(minorSkill[i], std::string("MinorSkill").append(1, theIndex)); - skills.push_back(majorSkill[i]); - skills.push_back(minorSkill[i]); + getWidget(mMajorSkill[i], std::string("MajorSkill").append(1, theIndex)); + getWidget(mMinorSkill[i], std::string("MinorSkill").append(1, theIndex)); + mSkills.push_back(mMajorSkill[i]); + mSkills.push_back(mMinorSkill[i]); } - std::vector::const_iterator end = skills.end(); - for (std::vector::const_iterator it = skills.begin(); it != end; ++it) + std::vector::const_iterator end = mSkills.end(); + for (std::vector::const_iterator it = mSkills.begin(); it != end; ++it) { (*it)->setWindowManager(&mWindowManager); (*it)->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onSkillClicked); } setText("LabelT", mWindowManager.getGameSettingString("sName", "")); - getWidget(editName, "EditName"); + getWidget(mEditName, "EditName"); // Make sure the edit box has focus - MyGUI::InputManager::getInstance().setKeyFocusWidget(editName); + MyGUI::InputManager::getInstance().setKeyFocusWidget(mEditName); MyGUI::ButtonPtr descriptionButton; getWidget(descriptionButton, "DescriptionButton"); @@ -441,20 +440,20 @@ CreateClassDialog::CreateClassDialog(WindowManager& parWindowManager) // Set default skills, attributes - favoriteAttribute0->setAttributeId(ESM::Attribute::Strength); - favoriteAttribute1->setAttributeId(ESM::Attribute::Agility); + mFavoriteAttribute0->setAttributeId(ESM::Attribute::Strength); + mFavoriteAttribute1->setAttributeId(ESM::Attribute::Agility); - majorSkill[0]->setSkillId(ESM::Skill::Block); - majorSkill[1]->setSkillId(ESM::Skill::Armorer); - majorSkill[2]->setSkillId(ESM::Skill::MediumArmor); - majorSkill[3]->setSkillId(ESM::Skill::HeavyArmor); - majorSkill[4]->setSkillId(ESM::Skill::BluntWeapon); + mMajorSkill[0]->setSkillId(ESM::Skill::Block); + mMajorSkill[1]->setSkillId(ESM::Skill::Armorer); + mMajorSkill[2]->setSkillId(ESM::Skill::MediumArmor); + mMajorSkill[3]->setSkillId(ESM::Skill::HeavyArmor); + mMajorSkill[4]->setSkillId(ESM::Skill::BluntWeapon); - minorSkill[0]->setSkillId(ESM::Skill::LongBlade); - minorSkill[1]->setSkillId(ESM::Skill::Axe); - minorSkill[2]->setSkillId(ESM::Skill::Spear); - minorSkill[3]->setSkillId(ESM::Skill::Athletics); - minorSkill[4]->setSkillId(ESM::Skill::Enchant); + mMinorSkill[0]->setSkillId(ESM::Skill::LongBlade); + mMinorSkill[1]->setSkillId(ESM::Skill::Axe); + mMinorSkill[2]->setSkillId(ESM::Skill::Spear); + mMinorSkill[3]->setSkillId(ESM::Skill::Athletics); + mMinorSkill[4]->setSkillId(ESM::Skill::Enchant); setSpecialization(0); update(); @@ -462,44 +461,44 @@ CreateClassDialog::CreateClassDialog(WindowManager& parWindowManager) CreateClassDialog::~CreateClassDialog() { - delete specDialog; - delete attribDialog; - delete skillDialog; - delete descDialog; + delete mSpecDialog; + delete mAttribDialog; + delete mSkillDialog; + delete mDescDialog; } void CreateClassDialog::update() { for (int i = 0; i < 5; ++i) { - ToolTips::createSkillToolTip(majorSkill[i], majorSkill[i]->getSkillId()); - ToolTips::createSkillToolTip(minorSkill[i], minorSkill[i]->getSkillId()); + ToolTips::createSkillToolTip(mMajorSkill[i], mMajorSkill[i]->getSkillId()); + ToolTips::createSkillToolTip(mMinorSkill[i], mMinorSkill[i]->getSkillId()); } - ToolTips::createAttributeToolTip(favoriteAttribute0, favoriteAttribute0->getAttributeId()); - ToolTips::createAttributeToolTip(favoriteAttribute1, favoriteAttribute1->getAttributeId()); + ToolTips::createAttributeToolTip(mFavoriteAttribute0, mFavoriteAttribute0->getAttributeId()); + ToolTips::createAttributeToolTip(mFavoriteAttribute1, mFavoriteAttribute1->getAttributeId()); } std::string CreateClassDialog::getName() const { - return editName->getOnlyText(); + return mEditName->getOnlyText(); } std::string CreateClassDialog::getDescription() const { - return description; + return mDescription; } ESM::Class::Specialization CreateClassDialog::getSpecializationId() const { - return specializationId; + return mSpecializationId; } std::vector CreateClassDialog::getFavoriteAttributes() const { std::vector v; - v.push_back(favoriteAttribute0->getAttributeId()); - v.push_back(favoriteAttribute1->getAttributeId()); + v.push_back(mFavoriteAttribute0->getAttributeId()); + v.push_back(mFavoriteAttribute1->getAttributeId()); return v; } @@ -508,7 +507,7 @@ std::vector CreateClassDialog::getMajorSkills() const std::vector v; for(int i = 0; i < 5; i++) { - v.push_back(majorSkill[i]->getSkillId()); + v.push_back(mMajorSkill[i]->getSkillId()); } return v; } @@ -518,7 +517,7 @@ std::vector CreateClassDialog::getMinorSkills() const std::vector v; for(int i=0; i < 5; i++) { - v.push_back(minorSkill[i]->getSkillId()); + v.push_back(mMinorSkill[i]->getSkillId()); } return v; } @@ -557,108 +556,108 @@ void CreateClassDialog::open() void CreateClassDialog::onDialogCancel() { - if (specDialog) + if (mSpecDialog) { - mWindowManager.removeDialog(specDialog); - specDialog = 0; + mWindowManager.removeDialog(mSpecDialog); + mSpecDialog = 0; } - if (attribDialog) + if (mAttribDialog) { - mWindowManager.removeDialog(attribDialog); - attribDialog = 0; + mWindowManager.removeDialog(mAttribDialog); + mAttribDialog = 0; } - if (skillDialog) + if (mSkillDialog) { - mWindowManager.removeDialog(skillDialog); - skillDialog = 0; + mWindowManager.removeDialog(mSkillDialog); + mSkillDialog = 0; } - if (descDialog) + if (mDescDialog) { - mWindowManager.removeDialog(descDialog); - descDialog = 0; + mWindowManager.removeDialog(mDescDialog); + mDescDialog = 0; } } void CreateClassDialog::onSpecializationClicked(MyGUI::WidgetPtr _sender) { - delete specDialog; - specDialog = new SelectSpecializationDialog(mWindowManager); - specDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); - specDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSpecializationSelected); - specDialog->setVisible(true); + delete mSpecDialog; + mSpecDialog = new SelectSpecializationDialog(mWindowManager); + mSpecDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); + mSpecDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSpecializationSelected); + mSpecDialog->setVisible(true); } void CreateClassDialog::onSpecializationSelected() { - specializationId = specDialog->getSpecializationId(); - setSpecialization(specializationId); + mSpecializationId = mSpecDialog->getSpecializationId(); + setSpecialization(mSpecializationId); - mWindowManager.removeDialog(specDialog); - specDialog = 0; + mWindowManager.removeDialog(mSpecDialog); + mSpecDialog = 0; } void CreateClassDialog::setSpecialization(int id) { - specializationId = (ESM::Class::Specialization) id; + mSpecializationId = (ESM::Class::Specialization) id; static const char *specIds[3] = { "sSpecializationCombat", "sSpecializationMagic", "sSpecializationStealth" }; - std::string specName = mWindowManager.getGameSettingString(specIds[specializationId], specIds[specializationId]); - specializationName->setCaption(specName); - ToolTips::createSpecializationToolTip(specializationName, specName, specializationId); + std::string specName = mWindowManager.getGameSettingString(specIds[mSpecializationId], specIds[mSpecializationId]); + mSpecializationName->setCaption(specName); + ToolTips::createSpecializationToolTip(mSpecializationName, specName, mSpecializationId); } void CreateClassDialog::onAttributeClicked(Widgets::MWAttributePtr _sender) { - delete attribDialog; - attribDialog = new SelectAttributeDialog(mWindowManager); - attribDialog->setAffectedWidget(_sender); - attribDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); - attribDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeSelected); - attribDialog->setVisible(true); + delete mAttribDialog; + mAttribDialog = new SelectAttributeDialog(mWindowManager); + mAttribDialog->setAffectedWidget(_sender); + mAttribDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); + mAttribDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeSelected); + mAttribDialog->setVisible(true); } void CreateClassDialog::onAttributeSelected() { - ESM::Attribute::AttributeID id = attribDialog->getAttributeId(); - Widgets::MWAttributePtr attribute = attribDialog->getAffectedWidget(); - if (attribute == favoriteAttribute0) + ESM::Attribute::AttributeID id = mAttribDialog->getAttributeId(); + Widgets::MWAttributePtr attribute = mAttribDialog->getAffectedWidget(); + if (attribute == mFavoriteAttribute0) { - if (favoriteAttribute1->getAttributeId() == id) - favoriteAttribute1->setAttributeId(favoriteAttribute0->getAttributeId()); + if (mFavoriteAttribute1->getAttributeId() == id) + mFavoriteAttribute1->setAttributeId(mFavoriteAttribute0->getAttributeId()); } - else if (attribute == favoriteAttribute1) + else if (attribute == mFavoriteAttribute1) { - if (favoriteAttribute0->getAttributeId() == id) - favoriteAttribute0->setAttributeId(favoriteAttribute1->getAttributeId()); + if (mFavoriteAttribute0->getAttributeId() == id) + mFavoriteAttribute0->setAttributeId(mFavoriteAttribute1->getAttributeId()); } attribute->setAttributeId(id); - mWindowManager.removeDialog(attribDialog); - attribDialog = 0; + mWindowManager.removeDialog(mAttribDialog); + mAttribDialog = 0; update(); } void CreateClassDialog::onSkillClicked(Widgets::MWSkillPtr _sender) { - delete skillDialog; - skillDialog = new SelectSkillDialog(mWindowManager); - skillDialog->setAffectedWidget(_sender); - skillDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); - skillDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSkillSelected); - skillDialog->setVisible(true); + delete mSkillDialog; + mSkillDialog = new SelectSkillDialog(mWindowManager); + mSkillDialog->setAffectedWidget(_sender); + mSkillDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel); + mSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSkillSelected); + mSkillDialog->setVisible(true); } void CreateClassDialog::onSkillSelected() { - ESM::Skill::SkillEnum id = skillDialog->getSkillId(); - Widgets::MWSkillPtr skill = skillDialog->getAffectedWidget(); + ESM::Skill::SkillEnum id = mSkillDialog->getSkillId(); + Widgets::MWSkillPtr skill = mSkillDialog->getAffectedWidget(); // Avoid duplicate skills by swapping any skill field that matches the selected one - std::vector::const_iterator end = skills.end(); - for (std::vector::const_iterator it = skills.begin(); it != end; ++it) + std::vector::const_iterator end = mSkills.end(); + for (std::vector::const_iterator it = mSkills.begin(); it != end; ++it) { if (*it == skill) continue; @@ -669,25 +668,25 @@ void CreateClassDialog::onSkillSelected() } } - skill->setSkillId(skillDialog->getSkillId()); - mWindowManager.removeDialog(skillDialog); - skillDialog = 0; + skill->setSkillId(mSkillDialog->getSkillId()); + mWindowManager.removeDialog(mSkillDialog); + mSkillDialog = 0; update(); } void CreateClassDialog::onDescriptionClicked(MyGUI::Widget* _sender) { - descDialog = new DescriptionDialog(mWindowManager); - descDialog->setTextInput(description); - descDialog->eventDone += MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionEntered); - descDialog->setVisible(true); + mDescDialog = new DescriptionDialog(mWindowManager); + mDescDialog->setTextInput(mDescription); + mDescDialog->eventDone += MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionEntered); + mDescDialog->setVisible(true); } void CreateClassDialog::onDescriptionEntered(WindowBase* parWindow) { - description = descDialog->getTextInput(); - mWindowManager.removeDialog(descDialog); - descDialog = 0; + mDescription = mDescDialog->getTextInput(); + mWindowManager.removeDialog(mDescDialog); + mDescDialog = 0; } void CreateClassDialog::onOkClicked(MyGUI::Widget* _sender) @@ -710,24 +709,24 @@ SelectSpecializationDialog::SelectSpecializationDialog(WindowManager& parWindowM setText("LabelT", mWindowManager.getGameSettingString("sSpecializationMenu1", "")); - getWidget(specialization0, "Specialization0"); - getWidget(specialization1, "Specialization1"); - getWidget(specialization2, "Specialization2"); + getWidget(mSpecialization0, "Specialization0"); + getWidget(mSpecialization1, "Specialization1"); + getWidget(mSpecialization2, "Specialization2"); std::string combat = mWindowManager.getGameSettingString(ESM::Class::gmstSpecializationIds[ESM::Class::Combat], ""); std::string magic = mWindowManager.getGameSettingString(ESM::Class::gmstSpecializationIds[ESM::Class::Magic], ""); std::string stealth = mWindowManager.getGameSettingString(ESM::Class::gmstSpecializationIds[ESM::Class::Stealth], ""); - specialization0->setCaption(combat); - specialization0->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked); - specialization1->setCaption(magic); - specialization1->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked); - specialization2->setCaption(stealth); - specialization2->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked); - specializationId = ESM::Class::Combat; + mSpecialization0->setCaption(combat); + mSpecialization0->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked); + mSpecialization1->setCaption(magic); + mSpecialization1->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked); + mSpecialization2->setCaption(stealth); + mSpecialization2->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked); + mSpecializationId = ESM::Class::Combat; - ToolTips::createSpecializationToolTip(specialization0, combat, ESM::Class::Combat); - ToolTips::createSpecializationToolTip(specialization1, magic, ESM::Class::Magic); - ToolTips::createSpecializationToolTip(specialization2, stealth, ESM::Class::Stealth); + ToolTips::createSpecializationToolTip(mSpecialization0, combat, ESM::Class::Combat); + ToolTips::createSpecializationToolTip(mSpecialization1, magic, ESM::Class::Magic); + ToolTips::createSpecializationToolTip(mSpecialization2, stealth, ESM::Class::Stealth); MyGUI::ButtonPtr cancelButton; getWidget(cancelButton, "CancelButton"); @@ -748,12 +747,12 @@ SelectSpecializationDialog::~SelectSpecializationDialog() void SelectSpecializationDialog::onSpecializationClicked(MyGUI::WidgetPtr _sender) { - if (_sender == specialization0) - specializationId = ESM::Class::Combat; - else if (_sender == specialization1) - specializationId = ESM::Class::Magic; - else if (_sender == specialization2) - specializationId = ESM::Class::Stealth; + if (_sender == mSpecialization0) + mSpecializationId = ESM::Class::Combat; + else if (_sender == mSpecialization1) + mSpecializationId = ESM::Class::Magic; + else if (_sender == mSpecialization2) + mSpecializationId = ESM::Class::Stealth; else return; @@ -807,7 +806,7 @@ SelectAttributeDialog::~SelectAttributeDialog() void SelectAttributeDialog::onAttributeClicked(Widgets::MWAttributePtr _sender) { // TODO: Change MWAttribute to set and get AttributeID enum instead of int - attributeId = static_cast(_sender->getAttributeId()); + mAttributeId = static_cast(_sender->getAttributeId()); eventItemSelected(); } @@ -833,44 +832,44 @@ SelectSkillDialog::SelectSkillDialog(WindowManager& parWindowManager) for(int i = 0; i < 9; i++) { char theIndex = '0'+i; - getWidget(combatSkill[i], std::string("CombatSkill").append(1, theIndex)); - getWidget(magicSkill[i], std::string("MagicSkill").append(1, theIndex)); - getWidget(stealthSkill[i], std::string("StealthSkill").append(1, theIndex)); + getWidget(mCombatSkill[i], std::string("CombatSkill").append(1, theIndex)); + getWidget(mMagicSkill[i], std::string("MagicSkill").append(1, theIndex)); + getWidget(mStealthSkill[i], std::string("StealthSkill").append(1, theIndex)); } - struct {Widgets::MWSkillPtr widget; ESM::Skill::SkillEnum skillId;} skills[3][9] = { + struct {Widgets::MWSkillPtr widget; ESM::Skill::SkillEnum skillId;} mSkills[3][9] = { { - {combatSkill[0], ESM::Skill::Block}, - {combatSkill[1], ESM::Skill::Armorer}, - {combatSkill[2], ESM::Skill::MediumArmor}, - {combatSkill[3], ESM::Skill::HeavyArmor}, - {combatSkill[4], ESM::Skill::BluntWeapon}, - {combatSkill[5], ESM::Skill::LongBlade}, - {combatSkill[6], ESM::Skill::Axe}, - {combatSkill[7], ESM::Skill::Spear}, - {combatSkill[8], ESM::Skill::Athletics} + {mCombatSkill[0], ESM::Skill::Block}, + {mCombatSkill[1], ESM::Skill::Armorer}, + {mCombatSkill[2], ESM::Skill::MediumArmor}, + {mCombatSkill[3], ESM::Skill::HeavyArmor}, + {mCombatSkill[4], ESM::Skill::BluntWeapon}, + {mCombatSkill[5], ESM::Skill::LongBlade}, + {mCombatSkill[6], ESM::Skill::Axe}, + {mCombatSkill[7], ESM::Skill::Spear}, + {mCombatSkill[8], ESM::Skill::Athletics} }, { - {magicSkill[0], ESM::Skill::Enchant}, - {magicSkill[1], ESM::Skill::Destruction}, - {magicSkill[2], ESM::Skill::Alteration}, - {magicSkill[3], ESM::Skill::Illusion}, - {magicSkill[4], ESM::Skill::Conjuration}, - {magicSkill[5], ESM::Skill::Mysticism}, - {magicSkill[6], ESM::Skill::Restoration}, - {magicSkill[7], ESM::Skill::Alchemy}, - {magicSkill[8], ESM::Skill::Unarmored} + {mMagicSkill[0], ESM::Skill::Enchant}, + {mMagicSkill[1], ESM::Skill::Destruction}, + {mMagicSkill[2], ESM::Skill::Alteration}, + {mMagicSkill[3], ESM::Skill::Illusion}, + {mMagicSkill[4], ESM::Skill::Conjuration}, + {mMagicSkill[5], ESM::Skill::Mysticism}, + {mMagicSkill[6], ESM::Skill::Restoration}, + {mMagicSkill[7], ESM::Skill::Alchemy}, + {mMagicSkill[8], ESM::Skill::Unarmored} }, { - {stealthSkill[0], ESM::Skill::Security}, - {stealthSkill[1], ESM::Skill::Sneak}, - {stealthSkill[2], ESM::Skill::Acrobatics}, - {stealthSkill[3], ESM::Skill::LightArmor}, - {stealthSkill[4], ESM::Skill::ShortBlade}, - {stealthSkill[5] ,ESM::Skill::Marksman}, - {stealthSkill[6] ,ESM::Skill::Mercantile}, - {stealthSkill[7] ,ESM::Skill::Speechcraft}, - {stealthSkill[8] ,ESM::Skill::HandToHand} + {mStealthSkill[0], ESM::Skill::Security}, + {mStealthSkill[1], ESM::Skill::Sneak}, + {mStealthSkill[2], ESM::Skill::Acrobatics}, + {mStealthSkill[3], ESM::Skill::LightArmor}, + {mStealthSkill[4], ESM::Skill::ShortBlade}, + {mStealthSkill[5] ,ESM::Skill::Marksman}, + {mStealthSkill[6] ,ESM::Skill::Mercantile}, + {mStealthSkill[7] ,ESM::Skill::Speechcraft}, + {mStealthSkill[8] ,ESM::Skill::HandToHand} } }; @@ -878,10 +877,10 @@ SelectSkillDialog::SelectSkillDialog(WindowManager& parWindowManager) { for (int i = 0; i < 9; ++i) { - skills[spec][i].widget->setWindowManager(&mWindowManager); - skills[spec][i].widget->setSkillId(skills[spec][i].skillId); - skills[spec][i].widget->eventClicked += MyGUI::newDelegate(this, &SelectSkillDialog::onSkillClicked); - ToolTips::createSkillToolTip(skills[spec][i].widget, skills[spec][i].widget->getSkillId()); + mSkills[spec][i].widget->setWindowManager(&mWindowManager); + mSkills[spec][i].widget->setSkillId(mSkills[spec][i].skillId); + mSkills[spec][i].widget->eventClicked += MyGUI::newDelegate(this, &SelectSkillDialog::onSkillClicked); + ToolTips::createSkillToolTip(mSkills[spec][i].widget, mSkills[spec][i].widget->getSkillId()); } } @@ -904,7 +903,7 @@ SelectSkillDialog::~SelectSkillDialog() void SelectSkillDialog::onSkillClicked(Widgets::MWSkillPtr _sender) { - skillId = _sender->getSkillId(); + mSkillId = _sender->getSkillId(); eventItemSelected(); } @@ -921,7 +920,7 @@ DescriptionDialog::DescriptionDialog(WindowManager& parWindowManager) // Centre dialog center(); - getWidget(textEdit, "TextEdit"); + getWidget(mTextEdit, "TextEdit"); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); @@ -931,7 +930,7 @@ DescriptionDialog::DescriptionDialog(WindowManager& parWindowManager) okButton->setCoord(234 - buttonWidth, 214, buttonWidth, 24); // Make sure the edit box has focus - MyGUI::InputManager::getInstance().setKeyFocusWidget(textEdit); + MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); } diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index c9e7aef7b..4d8d9fa23 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -45,11 +45,11 @@ namespace MWGui void fitToText(MyGUI::TextBox* widget); void layoutVertically(MyGUI::WidgetPtr widget, int margin); - int currentButton; - MyGUI::WidgetPtr textBox; - MyGUI::TextBox* text; - MyGUI::WidgetPtr buttonBar; - std::vector buttons; + int mCurrentButton; + MyGUI::WidgetPtr mTextBox; + MyGUI::TextBox* mText; + MyGUI::WidgetPtr mButtonBar; + std::vector mButtons; }; // Lets the player choose between 3 ways of creating a class @@ -90,10 +90,10 @@ namespace MWGui void onBackClicked(MyGUI::Widget* _sender); private: - MyGUI::ImageBox* classImage; - MyGUI::TextBox* className; + MyGUI::ImageBox* mClassImage; + MyGUI::TextBox* mClassName; - std::string currentClassId; + std::string mCurrentClassId; }; class PickClassDialog : public WindowBase @@ -101,7 +101,7 @@ namespace MWGui public: PickClassDialog(WindowManager& parWindowManager); - const std::string &getClassId() const { return currentClassId; } + const std::string &getClassId() const { return mCurrentClassId; } void setClassId(const std::string &classId); void setNextButtonShow(bool shown); @@ -125,14 +125,14 @@ namespace MWGui void updateClasses(); void updateStats(); - MyGUI::ImageBox* classImage; - MyGUI::ListBox* classList; - MyGUI::TextBox* specializationName; - Widgets::MWAttributePtr favoriteAttribute[2]; - Widgets::MWSkillPtr majorSkill[5]; - Widgets::MWSkillPtr minorSkill[5]; + MyGUI::ImageBox* mClassImage; + MyGUI::ListBox* mClassList; + MyGUI::TextBox* mSpecializationName; + Widgets::MWAttributePtr mFavoriteAttribute[2]; + Widgets::MWSkillPtr mMajorSkill[5]; + Widgets::MWSkillPtr mMinorSkill[5]; - std::string currentClassId; + std::string mCurrentClassId; }; class SelectSpecializationDialog : public WindowBase @@ -141,7 +141,7 @@ namespace MWGui SelectSpecializationDialog(WindowManager& parWindowManager); ~SelectSpecializationDialog(); - ESM::Class::Specialization getSpecializationId() const { return specializationId; } + ESM::Class::Specialization getSpecializationId() const { return mSpecializationId; } // Events typedef delegates::CMultiDelegate0 EventHandle_Void; @@ -161,9 +161,9 @@ namespace MWGui void onCancelClicked(MyGUI::Widget* _sender); private: - MyGUI::TextBox *specialization0, *specialization1, *specialization2; + MyGUI::TextBox *mSpecialization0, *mSpecialization1, *mSpecialization2; - ESM::Class::Specialization specializationId; + ESM::Class::Specialization mSpecializationId; }; class SelectAttributeDialog : public WindowBase @@ -172,9 +172,9 @@ namespace MWGui SelectAttributeDialog(WindowManager& parWindowManager); ~SelectAttributeDialog(); - ESM::Attribute::AttributeID getAttributeId() const { return attributeId; } - Widgets::MWAttributePtr getAffectedWidget() const { return affectedWidget; } - void setAffectedWidget(Widgets::MWAttributePtr widget) { affectedWidget = widget; } + ESM::Attribute::AttributeID getAttributeId() const { return mAttributeId; } + Widgets::MWAttributePtr getAffectedWidget() const { return mAffectedWidget; } + void setAffectedWidget(Widgets::MWAttributePtr widget) { mAffectedWidget = widget; } // Events typedef delegates::CMultiDelegate0 EventHandle_Void; @@ -194,9 +194,9 @@ namespace MWGui void onCancelClicked(MyGUI::Widget* _sender); private: - Widgets::MWAttributePtr affectedWidget; + Widgets::MWAttributePtr mAffectedWidget; - ESM::Attribute::AttributeID attributeId; + ESM::Attribute::AttributeID mAttributeId; }; class SelectSkillDialog : public WindowBase @@ -205,9 +205,9 @@ namespace MWGui SelectSkillDialog(WindowManager& parWindowManager); ~SelectSkillDialog(); - ESM::Skill::SkillEnum getSkillId() const { return skillId; } - Widgets::MWSkillPtr getAffectedWidget() const { return affectedWidget; } - void setAffectedWidget(Widgets::MWSkillPtr widget) { affectedWidget = widget; } + ESM::Skill::SkillEnum getSkillId() const { return mSkillId; } + Widgets::MWSkillPtr getAffectedWidget() const { return mAffectedWidget; } + void setAffectedWidget(Widgets::MWSkillPtr widget) { mAffectedWidget = widget; } // Events typedef delegates::CMultiDelegate0 EventHandle_Void; @@ -227,12 +227,12 @@ namespace MWGui void onCancelClicked(MyGUI::Widget* _sender); private: - Widgets::MWSkillPtr combatSkill[9]; - Widgets::MWSkillPtr magicSkill[9]; - Widgets::MWSkillPtr stealthSkill[9]; - Widgets::MWSkillPtr affectedWidget; + Widgets::MWSkillPtr mCombatSkill[9]; + Widgets::MWSkillPtr mMagicSkill[9]; + Widgets::MWSkillPtr mStealthSkill[9]; + Widgets::MWSkillPtr mAffectedWidget; - ESM::Skill::SkillEnum skillId; + ESM::Skill::SkillEnum mSkillId; }; class DescriptionDialog : public WindowBase @@ -241,14 +241,14 @@ namespace MWGui DescriptionDialog(WindowManager& parWindowManager); ~DescriptionDialog(); - std::string getTextInput() const { return textEdit ? textEdit->getOnlyText() : ""; } - void setTextInput(const std::string &text) { if (textEdit) textEdit->setOnlyText(text); } + std::string getTextInput() const { return mTextEdit ? mTextEdit->getOnlyText() : ""; } + void setTextInput(const std::string &text) { if (mTextEdit) mTextEdit->setOnlyText(text); } protected: void onOkClicked(MyGUI::Widget* _sender); private: - MyGUI::EditPtr textEdit; + MyGUI::EditPtr mTextEdit; }; class CreateClassDialog : public WindowBase @@ -294,20 +294,20 @@ namespace MWGui void update(); private: - MyGUI::EditPtr editName; - MyGUI::TextBox* specializationName; - Widgets::MWAttributePtr favoriteAttribute0, favoriteAttribute1; - Widgets::MWSkillPtr majorSkill[5]; - Widgets::MWSkillPtr minorSkill[5]; - std::vector skills; - std::string description; - - SelectSpecializationDialog *specDialog; - SelectAttributeDialog *attribDialog; - SelectSkillDialog *skillDialog; - DescriptionDialog *descDialog; - - ESM::Class::Specialization specializationId; + MyGUI::EditPtr mEditName; + MyGUI::TextBox* mSpecializationName; + Widgets::MWAttributePtr mFavoriteAttribute0, mFavoriteAttribute1; + Widgets::MWSkillPtr mMajorSkill[5]; + Widgets::MWSkillPtr mMinorSkill[5]; + std::vector mSkills; + std::string mDescription; + + SelectSpecializationDialog *mSpecDialog; + SelectAttributeDialog *mAttribDialog; + SelectSkillDialog *mSkillDialog; + DescriptionDialog *mDescDialog; + + ESM::Class::Specialization mSpecializationId; }; } #endif diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index acf0bf130..760c89f49 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -1,6 +1,5 @@ #include "dialogue.hpp" -#include #include #include @@ -51,9 +50,9 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager) center(); //History view - getWidget(history, "History"); - history->setOverflowToTheLeft(true); - history->setMaxTextLength(1000000); + getWidget(mHistory, "History"); + mHistory->setOverflowToTheLeft(true); + mHistory->setMaxTextLength(1000000); Widget* eventbox; //An EditBox cannot receive mouse click events, so we use an @@ -63,36 +62,36 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager) eventbox->eventMouseWheel += MyGUI::newDelegate(this, &DialogueWindow::onMouseWheel); //Topics list - getWidget(topicsList, "TopicsList"); - topicsList->eventItemSelected += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); + getWidget(mTopicsList, "TopicsList"); + mTopicsList->eventItemSelected += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); MyGUI::ButtonPtr byeButton; getWidget(byeButton, "ByeButton"); byeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &DialogueWindow::onByeClicked); - getWidget(pDispositionBar, "Disposition"); - getWidget(pDispositionText,"DispositionText"); + getWidget(mDispositionBar, "Disposition"); + getWidget(mDispositionText,"DispositionText"); static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize); } void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) { - ISubWidgetText* t = history->getClient()->getSubWidgetText(); + ISubWidgetText* t = mHistory->getClient()->getSubWidgetText(); if(t == nullptr) return; const IntPoint& lastPressed = InputManager::getInstance().getLastPressedPosition(MyGUI::MouseButton::Left); size_t cursorPosition = t->getCursorPosition(lastPressed); - MyGUI::UString color = history->getColorAtPos(cursorPosition); + MyGUI::UString color = mHistory->getColorAtPos(cursorPosition); if (!mEnabled && color == "#572D21") MWBase::Environment::get().getDialogueManager()->goodbyeSelected(); if(color != "#B29154") { - UString key = history->getColorTextAt(cursorPosition); + UString key = mHistory->getColorTextAt(cursorPosition); if(color == "#686EBA") MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(key)); if(color == "#572D21") MWBase::Environment::get().getDialogueManager()->questionAnswered(lower_string(key)); @@ -101,15 +100,15 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) void DialogueWindow::onWindowResize(MyGUI::Window* _sender) { - topicsList->adjustSize(); + mTopicsList->adjustSize(); } void DialogueWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) { - if (history->getVScrollPosition() - _rel*0.3 < 0) - history->setVScrollPosition(0); + if (mHistory->getVScrollPosition() - _rel*0.3 < 0) + mHistory->setVScrollPosition(0); else - history->setVScrollPosition(history->getVScrollPosition() - _rel*0.3); + mHistory->setVScrollPosition(mHistory->getVScrollPosition() - _rel*0.3); } void DialogueWindow::onByeClicked(MyGUI::Widget* _sender) @@ -136,40 +135,40 @@ void DialogueWindow::startDialogue(MWWorld::Ptr actor, std::string npcName) { mEnabled = true; mPtr = actor; - topicsList->setEnabled(true); + mTopicsList->setEnabled(true); setTitle(npcName); - topicsList->clear(); - history->eraseText(0,history->getTextLength()); + mTopicsList->clear(); + mHistory->eraseText(0,mHistory->getTextLength()); updateOptions(); } void DialogueWindow::setKeywords(std::list keyWords) { - topicsList->clear(); + mTopicsList->clear(); bool anyService = mShowTrade; if (mShowTrade) - topicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarter")->str); + mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarter")->str); if (anyService) - topicsList->addSeparator(); + mTopicsList->addSeparator(); for(std::list::iterator it = keyWords.begin(); it != keyWords.end(); ++it) { - topicsList->addItem(*it); + mTopicsList->addItem(*it); } - topicsList->adjustSize(); + mTopicsList->adjustSize(); } void DialogueWindow::removeKeyword(std::string keyWord) { - if(topicsList->hasItem(keyWord)) + if(mTopicsList->hasItem(keyWord)) { - topicsList->removeItem(keyWord); + mTopicsList->removeItem(keyWord); } - topicsList->adjustSize(); + mTopicsList->adjustSize(); } void addColorInString(std::string& str, const std::string& keyword,std::string color1, std::string color2) @@ -206,9 +205,9 @@ void addColorInString(std::string& str, const std::string& keyword,std::string c std::string DialogueWindow::parseText(std::string text) { bool separatorReached = false; // only parse topics that are below the separator (this prevents actions like "Barter" that are not topics from getting blue-colored) - for(unsigned int i = 0;igetItemCount();i++) + for(unsigned int i = 0;igetItemCount();i++) { - std::string keyWord = topicsList->getItemNameAt(i); + std::string keyWord = mTopicsList->getItemNameAt(i); if (separatorReached && keyWord != "") addColorInString(text,keyWord,"#686EBA","#B29154"); else @@ -219,7 +218,7 @@ std::string DialogueWindow::parseText(std::string text) void DialogueWindow::addText(std::string text) { - history->addDialogText("#B29154"+parseText(text)+"#B29154"); + mHistory->addDialogText("#B29154"+parseText(text)+"#B29154"); } void DialogueWindow::addTitle(std::string text) @@ -227,37 +226,37 @@ void DialogueWindow::addTitle(std::string text) // This is called from the dialogue manager, so text is // case-smashed - thus we have to retrieve the correct case // of the text through the topic list. - for (size_t i=0; igetItemCount(); ++i) + for (size_t i=0; igetItemCount(); ++i) { - std::string item = topicsList->getItemNameAt(i); + std::string item = mTopicsList->getItemNameAt(i); if (lower_string(item) == text) text = item; } - history->addDialogHeading(text); + mHistory->addDialogHeading(text); } void DialogueWindow::askQuestion(std::string question) { - history->addDialogText("#572D21"+question+"#B29154"+" "); + mHistory->addDialogText("#572D21"+question+"#B29154"+" "); } void DialogueWindow::updateOptions() { //Clear the list of topics - topicsList->clear(); - history->eraseText(0,history->getTextLength()); + mTopicsList->clear(); + mHistory->eraseText(0, mHistory->getTextLength()); - pDispositionBar->setProgressRange(100); - pDispositionBar->setProgressPosition(40); - pDispositionText->eraseText(0,pDispositionText->getTextLength()); - pDispositionText->addText("#B29154"+std::string("40/100")+"#B29154"); + mDispositionBar->setProgressRange(100); + mDispositionBar->setProgressPosition(40); + mDispositionText->eraseText(0, mDispositionText->getTextLength()); + mDispositionText->addText("#B29154"+std::string("40/100")+"#B29154"); } void DialogueWindow::goodbye() { - history->addDialogText("\n#572D21" + MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGoodbye")->str); - topicsList->setEnabled(false); + mHistory->addDialogText("\n#572D21" + MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGoodbye")->str); + mTopicsList->setEnabled(false); mEnabled = false; } diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index 5d808b5a7..e2824bead 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -73,10 +73,10 @@ namespace MWGui bool mEnabled; - DialogueHistory* history; - Widgets::MWList* topicsList; - MyGUI::ProgressPtr pDispositionBar; - MyGUI::EditPtr pDispositionText; + DialogueHistory* mHistory; + Widgets::MWList* mTopicsList; + MyGUI::ProgressPtr mDispositionBar; + MyGUI::EditPtr mDispositionText; }; } #endif diff --git a/apps/openmw/mwgui/dialogue_history.cpp b/apps/openmw/mwgui/dialogue_history.cpp index cd34ee119..009f42044 100644 --- a/apps/openmw/mwgui/dialogue_history.cpp +++ b/apps/openmw/mwgui/dialogue_history.cpp @@ -3,7 +3,6 @@ #include "widgets.hpp" #include "components/esm_store/store.hpp" -#include #include #include diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 78eefa338..d2eef26ac 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -28,24 +28,24 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) , health(NULL) , magicka(NULL) , stamina(NULL) - , weapImage(NULL) - , spellImage(NULL) - , weapStatus(NULL) - , spellStatus(NULL) - , effectBox(NULL) - , effect1(NULL) - , minimap(NULL) - , compass(NULL) - , crosshair(NULL) + , mWeapImage(NULL) + , mSpellImage(NULL) + , mWeapStatus(NULL) + , mSpellStatus(NULL) + , mEffectBox(NULL) + , mEffect1(NULL) + , mMinimap(NULL) + , mCompass(NULL) + , mCrosshair(NULL) , fpsbox(NULL) , fpscounter(NULL) , trianglecounter(NULL) , batchcounter(NULL) - , hmsBaseLeft(0) - , weapBoxBaseLeft(0) - , spellBoxBaseLeft(0) - , effectBoxBaseRight(0) - , minimapBoxBaseRight(0) + , mHealthManaStaminaBaseLeft(0) + , mWeapBoxBaseLeft(0) + , mSpellBoxBaseLeft(0) + , mEffectBoxBaseRight(0) + , mMinimapBoxBaseRight(0) , mDragAndDrop(dragAndDrop) , mCellNameTimer(0.0f) , mCellNameBox(NULL) @@ -62,7 +62,7 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) getWidget(magicka, "Magicka"); getWidget(stamina, "Stamina"); - hmsBaseLeft = mHealthFrame->getLeft(); + mHealthManaStaminaBaseLeft = mHealthFrame->getLeft(); MyGUI::Widget *healthFrame, *magickaFrame, *fatigueFrame; getWidget(healthFrame, "HealthFrame"); @@ -75,33 +75,33 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize(); // Item and spell images and status bars - getWidget(weapBox, "WeapBox"); - getWidget(weapImage, "WeapImage"); - getWidget(weapStatus, "WeapStatus"); - weapBoxBaseLeft = weapBox->getLeft(); - weapBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWeaponClicked); - - getWidget(spellBox, "SpellBox"); - getWidget(spellImage, "SpellImage"); - getWidget(spellStatus, "SpellStatus"); - spellBoxBaseLeft = spellBox->getLeft(); - spellBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMagicClicked); - - getWidget(effectBox, "EffectBox"); - getWidget(effect1, "Effect1"); - effectBoxBaseRight = viewSize.width - effectBox->getRight(); - effectBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMagicClicked); - - getWidget(minimapBox, "MiniMapBox"); - minimapBoxBaseRight = viewSize.width - minimapBox->getRight(); - minimapBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMapClicked); - getWidget(minimap, "MiniMap"); - getWidget(compass, "Compass"); + getWidget(mWeapBox, "WeapBox"); + getWidget(mWeapImage, "WeapImage"); + getWidget(mWeapStatus, "WeapStatus"); + mWeapBoxBaseLeft = mWeapBox->getLeft(); + mWeapBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWeaponClicked); + + getWidget(mSpellBox, "SpellBox"); + getWidget(mSpellImage, "SpellImage"); + getWidget(mSpellStatus, "SpellStatus"); + mSpellBoxBaseLeft = mSpellBox->getLeft(); + mSpellBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMagicClicked); + + getWidget(mEffectBox, "EffectBox"); + getWidget(mEffect1, "Effect1"); + mEffectBoxBaseRight = viewSize.width - mEffectBox->getRight(); + mEffectBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMagicClicked); + + getWidget(mMinimapBox, "MiniMapBox"); + mMinimapBoxBaseRight = viewSize.width - mMinimapBox->getRight(); + mMinimapBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMapClicked); + getWidget(mMinimap, "MiniMap"); + getWidget(mCompass, "Compass"); getWidget(mCellNameBox, "CellName"); getWidget(mWeaponSpellBox, "WeaponSpellName"); - getWidget(crosshair, "Crosshair"); + getWidget(mCrosshair, "Crosshair"); setFpsLevel(fpsLevel); @@ -110,7 +110,7 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) setEffect("icons\\s\\tx_s_chameleon.dds"); - LocalMapBase::init(minimap, compass, this); + LocalMapBase::init(mMinimap, mCompass, this); mMainWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWorldClicked); mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver); @@ -159,7 +159,7 @@ void HUD::setBatchCount(unsigned int count) void HUD::setEffect(const char *img) { - effect1->setImageTexture(img); + mEffect1->setImageTexture(img); } void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat& value) @@ -202,10 +202,10 @@ void HUD::setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellV { int weapDx = 0, spellDx = 0; if (!hmsVisible) - spellDx = weapDx = weapBoxBaseLeft - hmsBaseLeft; + spellDx = weapDx = mWeapBoxBaseLeft - mHealthManaStaminaBaseLeft; if (!weapVisible) - spellDx += spellBoxBaseLeft - weapBoxBaseLeft; + spellDx += mSpellBoxBaseLeft - mWeapBoxBaseLeft; mWeaponVisible = weapVisible; mSpellVisible = spellVisible; @@ -215,10 +215,10 @@ void HUD::setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellV health->setVisible(hmsVisible); stamina->setVisible(hmsVisible); magicka->setVisible(hmsVisible); - weapBox->setPosition(weapBoxBaseLeft - weapDx, weapBox->getTop()); - weapBox->setVisible(weapVisible); - spellBox->setPosition(spellBoxBaseLeft - spellDx, spellBox->getTop()); - spellBox->setVisible(spellVisible); + mWeapBox->setPosition(mWeapBoxBaseLeft - weapDx, mWeapBox->getTop()); + mWeapBox->setVisible(weapVisible); + mSpellBox->setPosition(mSpellBoxBaseLeft - spellDx, mSpellBox->getTop()); + mSpellBox->setVisible(spellVisible); } void HUD::setBottomRightVisibility(bool effectBoxVisible, bool minimapBoxVisible) @@ -228,12 +228,12 @@ void HUD::setBottomRightVisibility(bool effectBoxVisible, bool minimapBoxVisible // effect box can have variable width -> variable left coordinate int effectsDx = 0; if (!minimapBoxVisible) - effectsDx = (viewSize.width - minimapBoxBaseRight) - (viewSize.width - effectBoxBaseRight); + effectsDx = (viewSize.width - mMinimapBoxBaseRight) - (viewSize.width - mEffectBoxBaseRight); mMapVisible = minimapBoxVisible; - minimapBox->setVisible(minimapBoxVisible); - effectBox->setPosition((viewSize.width - effectBoxBaseRight) - effectBox->getWidth() + effectsDx, effectBox->getTop()); - effectBox->setVisible(effectBoxVisible); + mMinimapBox->setVisible(minimapBoxVisible); + mEffectBox->setPosition((viewSize.width - mEffectBoxBaseRight) - mEffectBox->getWidth() + effectsDx, mEffectBox->getTop()); + mEffectBox->setVisible(effectBoxVisible); } void HUD::onWorldClicked(MyGUI::Widget* _sender) @@ -395,14 +395,14 @@ void HUD::setSelectedSpell(const std::string& spellId, int successChancePercent) mWeaponSpellBox->setVisible(true); } - spellStatus->setProgressRange(100); - spellStatus->setProgressPosition(successChancePercent); + mSpellStatus->setProgressRange(100); + mSpellStatus->setProgressPosition(successChancePercent); - if (spellImage->getChildCount()) - MyGUI::Gui::getInstance().destroyWidget(spellImage->getChildAt(0)); + if (mSpellImage->getChildCount()) + MyGUI::Gui::getInstance().destroyWidget(mSpellImage->getChildAt(0)); - spellBox->setUserString("ToolTipType", "Spell"); - spellBox->setUserString("Spell", spellId); + mSpellBox->setUserString("ToolTipType", "Spell"); + mSpellBox->setUserString("Spell", spellId); // use the icon of the first effect const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().magicEffects.find(spell->effects.list.front().effectID); @@ -411,7 +411,7 @@ void HUD::setSelectedSpell(const std::string& spellId, int successChancePercent) icon.insert(slashPos+1, "b_"); icon = std::string("icons\\") + icon; Widgets::fixTexturePath(icon); - spellImage->setImageTexture(icon); + mSpellImage->setImageTexture(icon); } void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) @@ -425,17 +425,17 @@ void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) mWeaponSpellBox->setVisible(true); } - spellStatus->setProgressRange(100); - spellStatus->setProgressPosition(chargePercent); + mSpellStatus->setProgressRange(100); + mSpellStatus->setProgressPosition(chargePercent); - if (spellImage->getChildCount()) - MyGUI::Gui::getInstance().destroyWidget(spellImage->getChildAt(0)); + if (mSpellImage->getChildCount()) + MyGUI::Gui::getInstance().destroyWidget(mSpellImage->getChildAt(0)); - spellBox->setUserString("ToolTipType", "ItemPtr"); - spellBox->setUserData(item); + mSpellBox->setUserString("ToolTipType", "ItemPtr"); + mSpellBox->setUserData(item); - spellImage->setImageTexture("textures\\menu_icon_magic_mini.dds"); - MyGUI::ImageBox* itemBox = spellImage->createWidgetReal("ImageBox", MyGUI::FloatCoord(0,0,1,1) + mSpellImage->setImageTexture("textures\\menu_icon_magic_mini.dds"); + MyGUI::ImageBox* itemBox = mSpellImage->createWidgetReal("ImageBox", MyGUI::FloatCoord(0,0,1,1) , MyGUI::Align::Stretch); std::string path = std::string("icons\\"); @@ -456,14 +456,14 @@ void HUD::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent) mWeaponSpellBox->setVisible(true); } - weapBox->setUserString("ToolTipType", "ItemPtr"); - weapBox->setUserData(item); + mWeapBox->setUserString("ToolTipType", "ItemPtr"); + mWeapBox->setUserData(item); - weapStatus->setProgressRange(100); - weapStatus->setProgressPosition(durabilityPercent); + mWeapStatus->setProgressRange(100); + mWeapStatus->setProgressPosition(durabilityPercent); - if (weapImage->getChildCount()) - MyGUI::Gui::getInstance().destroyWidget(weapImage->getChildAt(0)); + if (mWeapImage->getChildCount()) + MyGUI::Gui::getInstance().destroyWidget(mWeapImage->getChildAt(0)); std::string path = std::string("icons\\"); path+=MWWorld::Class::get(item).getInventoryIcon(item); @@ -471,14 +471,14 @@ void HUD::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent) if (MWWorld::Class::get(item).getEnchantment(item) != "") { - weapImage->setImageTexture("textures\\menu_icon_magic_mini.dds"); - MyGUI::ImageBox* itemBox = weapImage->createWidgetReal("ImageBox", MyGUI::FloatCoord(0,0,1,1) + mWeapImage->setImageTexture("textures\\menu_icon_magic_mini.dds"); + MyGUI::ImageBox* itemBox = mWeapImage->createWidgetReal("ImageBox", MyGUI::FloatCoord(0,0,1,1) , MyGUI::Align::Stretch); itemBox->setImageTexture(path); itemBox->setNeedMouseFocus(false); } else - weapImage->setImageTexture(path); + mWeapImage->setImageTexture(path); } void HUD::unsetSelectedSpell() @@ -492,12 +492,12 @@ void HUD::unsetSelectedSpell() mWeaponSpellBox->setVisible(true); } - if (spellImage->getChildCount()) - MyGUI::Gui::getInstance().destroyWidget(spellImage->getChildAt(0)); - spellStatus->setProgressRange(100); - spellStatus->setProgressPosition(0); - spellImage->setImageTexture(""); - spellBox->clearUserStrings(); + if (mSpellImage->getChildCount()) + MyGUI::Gui::getInstance().destroyWidget(mSpellImage->getChildAt(0)); + mSpellStatus->setProgressRange(100); + mSpellStatus->setProgressPosition(0); + mSpellImage->setImageTexture(""); + mSpellBox->clearUserStrings(); } void HUD::unsetSelectedWeapon() @@ -511,10 +511,10 @@ void HUD::unsetSelectedWeapon() mWeaponSpellBox->setVisible(true); } - if (weapImage->getChildCount()) - MyGUI::Gui::getInstance().destroyWidget(weapImage->getChildAt(0)); - weapStatus->setProgressRange(100); - weapStatus->setProgressPosition(0); - weapImage->setImageTexture("icons\\k\\stealth_handtohand.dds"); - weapBox->clearUserStrings(); + if (mWeapImage->getChildCount()) + MyGUI::Gui::getInstance().destroyWidget(mWeapImage->getChildAt(0)); + mWeapStatus->setProgressRange(100); + mWeapStatus->setProgressPosition(0); + mWeapImage->setImageTexture("icons\\k\\stealth_handtohand.dds"); + mWeapBox->clearUserStrings(); } diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index c6bcdd4e9..485c788fc 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -37,14 +37,14 @@ namespace MWGui MyGUI::ProgressPtr health, magicka, stamina; MyGUI::Widget* mHealthFrame; - MyGUI::Widget *weapBox, *spellBox; - MyGUI::ImageBox *weapImage, *spellImage; - MyGUI::ProgressPtr weapStatus, spellStatus; - MyGUI::Widget *effectBox, *minimapBox; - MyGUI::ImageBox* effect1; - MyGUI::ScrollView* minimap; - MyGUI::ImageBox* compass; - MyGUI::ImageBox* crosshair; + MyGUI::Widget *mWeapBox, *mSpellBox; + MyGUI::ImageBox *mWeapImage, *mSpellImage; + MyGUI::ProgressPtr mWeapStatus, mSpellStatus; + MyGUI::Widget *mEffectBox, *mMinimapBox; + MyGUI::ImageBox* mEffect1; + MyGUI::ScrollView* mMinimap; + MyGUI::ImageBox* mCompass; + MyGUI::ImageBox* mCrosshair; MyGUI::TextBox* mCellNameBox; MyGUI::TextBox* mWeaponSpellBox; @@ -55,9 +55,9 @@ namespace MWGui private: // bottom left elements - int hmsBaseLeft, weapBoxBaseLeft, spellBoxBaseLeft; + int mHealthManaStaminaBaseLeft, mWeapBoxBaseLeft, mSpellBoxBaseLeft; // bottom right elements - int minimapBoxBaseRight, effectBoxBaseRight; + int mMinimapBoxBaseRight, mEffectBoxBaseRight; DragAndDrop* mDragAndDrop; diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index 75b546c7b..8b50c9ef1 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -84,7 +84,7 @@ book formatText(std::string text,book mBook,int maxLine, int lineSize) MWGui::JournalWindow::JournalWindow (WindowManager& parWindowManager) : WindowBase("openmw_journal.layout", parWindowManager) - , lastPos(0) + , mLastPos(0) , mVisible(false) { //setCoord(0,0,498, 342); @@ -148,19 +148,19 @@ void MWGui::JournalWindow::open() { if(left) { - leftPages.push_back(*it); + mLeftPages.push_back(*it); } else { - rightPages.push_back(*it); + mRightPages.push_back(*it); } left = !left; } - if(!left) rightPages.push_back(""); + if(!left) mRightPages.push_back(""); - mPageNumber = leftPages.size()-1; - displayLeftText(leftPages[mPageNumber]); - displayRightText(rightPages[mPageNumber]); + mPageNumber = mLeftPages.size()-1; + displayLeftText(mLeftPages[mPageNumber]); + displayRightText(mRightPages[mPageNumber]); } else @@ -184,13 +184,13 @@ void MWGui::JournalWindow::displayRightText(std::string text) void MWGui::JournalWindow::notifyNextPage(MyGUI::WidgetPtr _sender) { - if(mPageNumber < int(leftPages.size())-1) + if(mPageNumber < int(mLeftPages.size())-1) { std::string nextSound = "book page2"; MWBase::Environment::get().getSoundManager()->playSound (nextSound, 1.0, 1.0); mPageNumber = mPageNumber + 1; - displayLeftText(leftPages[mPageNumber]); - displayRightText(rightPages[mPageNumber]); + displayLeftText(mLeftPages[mPageNumber]); + displayRightText(mRightPages[mPageNumber]); } } @@ -201,7 +201,7 @@ void MWGui::JournalWindow::notifyPrevPage(MyGUI::WidgetPtr _sender) std::string prevSound = "book page"; MWBase::Environment::get().getSoundManager()->playSound (prevSound, 1.0, 1.0); mPageNumber = mPageNumber - 1; - displayLeftText(leftPages[mPageNumber]); - displayRightText(rightPages[mPageNumber]); + displayLeftText(mLeftPages[mPageNumber]); + displayRightText(mRightPages[mPageNumber]); } } diff --git a/apps/openmw/mwgui/journalwindow.hpp b/apps/openmw/mwgui/journalwindow.hpp index cacdb9414..0c85ebf08 100644 --- a/apps/openmw/mwgui/journalwindow.hpp +++ b/apps/openmw/mwgui/journalwindow.hpp @@ -31,17 +31,17 @@ namespace MWGui void notifyNextPage(MyGUI::WidgetPtr _sender); void notifyPrevPage(MyGUI::WidgetPtr _sender); - static const int lineHeight; + static const int sLineHeight; - MyGUI::WidgetPtr skillAreaWidget, skillClientWidget; - MyGUI::ScrollBar* skillScrollerWidget; - int lastPos, clientHeight; + MyGUI::WidgetPtr mSkillAreaWidget, mSkillClientWidget; + MyGUI::ScrollBar* mSkillScrollerWidget; + int mLastPos, mClientHeight; MyGUI::EditPtr mLeftTextWidget; MyGUI::EditPtr mRightTextWidget; MyGUI::ButtonPtr mPrevBtn; MyGUI::ButtonPtr mNextBtn; - std::vector leftPages; - std::vector rightPages; + std::vector mLeftPages; + std::vector mRightPages; int mPageNumber; //store the number of the current left page bool mVisible; }; diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 68326a3c3..2b00ca05c 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -149,7 +149,7 @@ int MessageBoxManager::readPressedButton () MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message) : Layout("openmw_messagebox.layout") , mMessageBoxManager(parMessageBoxManager) - , cMessage(message) + , mMessage(message) { // defines mFixedWidth = 300; @@ -160,7 +160,7 @@ MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::strin getWidget(mMessageWidget, "message"); mMessageWidget->setOverflowToTheLeft(true); - mMessageWidget->setCaptionWithReplacing(cMessage); + mMessageWidget->setCaptionWithReplacing(mMessage); MyGUI::IntSize size; size.width = mFixedWidth; diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 33155b2a0..75393ec94 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -59,7 +59,7 @@ namespace MWGui protected: MessageBoxManager& mMessageBoxManager; int mHeight; - const std::string& cMessage; + const std::string& mMessage; MyGUI::EditPtr mMessageWidget; int mFixedWidth; int mBottomPadding; diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 9ae453016..f90a9edde 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -1,6 +1,5 @@ #include "race.hpp" -#include #include #include @@ -18,11 +17,11 @@ using namespace Widgets; RaceDialog::RaceDialog(WindowManager& parWindowManager) : WindowBase("openmw_chargen_race.layout", parWindowManager) - , genderIndex(0) - , faceIndex(0) - , hairIndex(0) - , faceCount(10) - , hairCount(14) + , mGenderIndex(0) + , mFaceIndex(0) + , mHairIndex(0) + , mFaceCount(10) + , mHairCount(14) { // Centre dialog center(); @@ -31,13 +30,13 @@ RaceDialog::RaceDialog(WindowManager& parWindowManager) // real calls from outside the class later. setText("AppearanceT", mWindowManager.getGameSettingString("sRaceMenu1", "Appearance")); - getWidget(appearanceBox, "AppearanceBox"); + getWidget(mAppearanceBox, "AppearanceBox"); - getWidget(headRotate, "HeadRotate"); - headRotate->setScrollRange(50); - headRotate->setScrollPosition(20); - headRotate->setScrollViewPage(10); - headRotate->eventScrollChangePosition += MyGUI::newDelegate(this, &RaceDialog::onHeadRotate); + getWidget(mHeadRotate, "HeadRotate"); + mHeadRotate->setScrollRange(50); + mHeadRotate->setScrollPosition(20); + mHeadRotate->setScrollViewPage(10); + mHeadRotate->eventScrollChangePosition += MyGUI::newDelegate(this, &RaceDialog::onHeadRotate); // Set up next/previous buttons MyGUI::ButtonPtr prevButton, nextButton; @@ -61,16 +60,16 @@ RaceDialog::RaceDialog(WindowManager& parWindowManager) nextButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectNextHair); setText("RaceT", mWindowManager.getGameSettingString("sRaceMenu4", "Race")); - getWidget(raceList, "RaceList"); - raceList->setScrollVisible(true); - raceList->eventListSelectAccept += MyGUI::newDelegate(this, &RaceDialog::onSelectRace); - raceList->eventListMouseItemActivate += MyGUI::newDelegate(this, &RaceDialog::onSelectRace); - raceList->eventListChangePosition += MyGUI::newDelegate(this, &RaceDialog::onSelectRace); + getWidget(mRaceList, "RaceList"); + mRaceList->setScrollVisible(true); + mRaceList->eventListSelectAccept += MyGUI::newDelegate(this, &RaceDialog::onSelectRace); + mRaceList->eventListMouseItemActivate += MyGUI::newDelegate(this, &RaceDialog::onSelectRace); + mRaceList->eventListChangePosition += MyGUI::newDelegate(this, &RaceDialog::onSelectRace); setText("SkillsT", mWindowManager.getGameSettingString("sBonusSkillTitle", "Skill Bonus")); - getWidget(skillList, "SkillList"); + getWidget(mSkillList, "SkillList"); setText("SpellPowerT", mWindowManager.getGameSettingString("sRaceMenu7", "Specials")); - getWidget(spellPowerList, "SpellPowerList"); + getWidget(mSpellPowerList, "SpellPowerList"); MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); @@ -117,14 +116,14 @@ void RaceDialog::open() void RaceDialog::setRaceId(const std::string &raceId) { - currentRaceId = raceId; - raceList->setIndexSelected(MyGUI::ITEM_NONE); - size_t count = raceList->getItemCount(); + mCurrentRaceId = raceId; + mRaceList->setIndexSelected(MyGUI::ITEM_NONE); + size_t count = mRaceList->getItemCount(); for (size_t i = 0; i < count; ++i) { - if (boost::iequals(*raceList->getItemDataAt(i), raceId)) + if (boost::iequals(*mRaceList->getItemDataAt(i), raceId)) { - raceList->setIndexSelected(i); + mRaceList->setIndexSelected(i); break; } } @@ -162,32 +161,32 @@ void RaceDialog::onHeadRotate(MyGUI::ScrollBar*, size_t _position) void RaceDialog::onSelectPreviousGender(MyGUI::Widget*) { - genderIndex = wrap(genderIndex - 1, 2); + mGenderIndex = wrap(mGenderIndex - 1, 2); } void RaceDialog::onSelectNextGender(MyGUI::Widget*) { - genderIndex = wrap(genderIndex + 1, 2); + mGenderIndex = wrap(mGenderIndex + 1, 2); } void RaceDialog::onSelectPreviousFace(MyGUI::Widget*) { - faceIndex = wrap(faceIndex - 1, faceCount); + mFaceIndex = wrap(mFaceIndex - 1, mFaceCount); } void RaceDialog::onSelectNextFace(MyGUI::Widget*) { - faceIndex = wrap(faceIndex + 1, faceCount); + mFaceIndex = wrap(mFaceIndex + 1, mFaceCount); } void RaceDialog::onSelectPreviousHair(MyGUI::Widget*) { - hairIndex = wrap(hairIndex - 1, hairCount); + mHairIndex = wrap(mHairIndex - 1, mHairCount); } void RaceDialog::onSelectNextHair(MyGUI::Widget*) { - hairIndex = wrap(hairIndex - 1, hairCount); + mHairIndex = wrap(mHairIndex - 1, mHairCount); } void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) @@ -195,11 +194,11 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) if (_index == MyGUI::ITEM_NONE) return; - const std::string *raceId = raceList->getItemDataAt(_index); - if (boost::iequals(currentRaceId, *raceId)) + const std::string *raceId = mRaceList->getItemDataAt(_index); + if (boost::iequals(mCurrentRaceId, *raceId)) return; - currentRaceId = *raceId; + mCurrentRaceId = *raceId; updateSkills(); updateSpellPowers(); } @@ -208,7 +207,7 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) void RaceDialog::updateRaces() { - raceList->removeAllItems(); + mRaceList->removeAllItems(); const ESMS::ESMStore &store = mWindowManager.getStore(); @@ -222,30 +221,30 @@ void RaceDialog::updateRaces() if (!playable) // Only display playable races continue; - raceList->addItem(race.name, it->first); - if (boost::iequals(it->first, currentRaceId)) - raceList->setIndexSelected(index); + mRaceList->addItem(race.name, it->first); + if (boost::iequals(it->first, mCurrentRaceId)) + mRaceList->setIndexSelected(index); ++index; } } void RaceDialog::updateSkills() { - for (std::vector::iterator it = skillItems.begin(); it != skillItems.end(); ++it) + for (std::vector::iterator it = mSkillItems.begin(); it != mSkillItems.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } - skillItems.clear(); + mSkillItems.clear(); - if (currentRaceId.empty()) + if (mCurrentRaceId.empty()) return; MWSkillPtr skillWidget; const int lineHeight = 18; - MyGUI::IntCoord coord1(0, 0, skillList->getWidth(), 18); + MyGUI::IntCoord coord1(0, 0, mSkillList->getWidth(), 18); const ESMS::ESMStore &store = mWindowManager.getStore(); - const ESM::Race *race = store.races.find(currentRaceId); + const ESM::Race *race = store.races.find(mCurrentRaceId); int count = sizeof(race->data.bonus)/sizeof(race->data.bonus[0]); // TODO: Find a portable macro for this ARRAYSIZE? for (int i = 0; i < count; ++i) { @@ -253,7 +252,7 @@ void RaceDialog::updateSkills() if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes continue; - skillWidget = skillList->createWidget("MW_StatNameValue", coord1, MyGUI::Align::Default, + skillWidget = mSkillList->createWidget("MW_StatNameValue", coord1, MyGUI::Align::Default, std::string("Skill") + boost::lexical_cast(i)); skillWidget->setWindowManager(&mWindowManager); skillWidget->setSkillNumber(skillId); @@ -261,7 +260,7 @@ void RaceDialog::updateSkills() ToolTips::createSkillToolTip(skillWidget, skillId); - skillItems.push_back(skillWidget); + mSkillItems.push_back(skillWidget); coord1.top += lineHeight; } @@ -269,34 +268,34 @@ void RaceDialog::updateSkills() void RaceDialog::updateSpellPowers() { - for (std::vector::iterator it = spellPowerItems.begin(); it != spellPowerItems.end(); ++it) + for (std::vector::iterator it = mSpellPowerItems.begin(); it != mSpellPowerItems.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } - spellPowerItems.clear(); + mSpellPowerItems.clear(); - if (currentRaceId.empty()) + if (mCurrentRaceId.empty()) return; MWSpellPtr spellPowerWidget; const int lineHeight = 18; - MyGUI::IntCoord coord(0, 0, spellPowerList->getWidth(), 18); + MyGUI::IntCoord coord(0, 0, mSpellPowerList->getWidth(), 18); const ESMS::ESMStore &store = mWindowManager.getStore(); - const ESM::Race *race = store.races.find(currentRaceId); + const ESM::Race *race = store.races.find(mCurrentRaceId); std::vector::const_iterator it = race->powers.list.begin(); std::vector::const_iterator end = race->powers.list.end(); for (int i = 0; it != end; ++it) { const std::string &spellpower = *it; - spellPowerWidget = spellPowerList->createWidget("MW_StatName", coord, MyGUI::Align::Default, std::string("SpellPower") + boost::lexical_cast(i)); + spellPowerWidget = mSpellPowerList->createWidget("MW_StatName", coord, MyGUI::Align::Default, std::string("SpellPower") + boost::lexical_cast(i)); spellPowerWidget->setWindowManager(&mWindowManager); spellPowerWidget->setSpellId(spellpower); spellPowerWidget->setUserString("ToolTipType", "Spell"); spellPowerWidget->setUserString("Spell", spellpower); - spellPowerItems.push_back(spellPowerWidget); + mSpellPowerItems.push_back(spellPowerWidget); coord.top += lineHeight; ++i; diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index 217ce15aa..b523b8690 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -32,13 +32,13 @@ namespace MWGui GM_Female }; - const std::string &getRaceId() const { return currentRaceId; } - Gender getGender() const { return genderIndex == 0 ? GM_Male : GM_Female; } + const std::string &getRaceId() const { return mCurrentRaceId; } + Gender getGender() const { return mGenderIndex == 0 ? GM_Male : GM_Female; } // getFace() // getHair() void setRaceId(const std::string &raceId); - void setGender(Gender gender) { genderIndex = gender == GM_Male ? 0 : 1; } + void setGender(Gender gender) { mGenderIndex = gender == GM_Male ? 0 : 1; } // setFace() // setHair() @@ -75,20 +75,20 @@ namespace MWGui void updateSkills(); void updateSpellPowers(); - MyGUI::CanvasPtr appearanceBox; - MyGUI::ListBox* raceList; - MyGUI::ScrollBar* headRotate; + MyGUI::CanvasPtr mAppearanceBox; + MyGUI::ListBox* mRaceList; + MyGUI::ScrollBar* mHeadRotate; - MyGUI::WidgetPtr skillList; - std::vector skillItems; + MyGUI::WidgetPtr mSkillList; + std::vector mSkillItems; - MyGUI::WidgetPtr spellPowerList; - std::vector spellPowerItems; + MyGUI::WidgetPtr mSpellPowerList; + std::vector mSpellPowerItems; - int genderIndex, faceIndex, hairIndex; - int faceCount, hairCount; + int mGenderIndex, mFaceIndex, mHairIndex; + int mFaceCount, mHairCount; - std::string currentRaceId; + std::string mCurrentRaceId; }; } #endif diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index f9792ea34..7061f65c1 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -17,49 +17,49 @@ using namespace MWGui; using namespace Widgets; -const int ReviewDialog::lineHeight = 18; +const int ReviewDialog::sLineHeight = 18; ReviewDialog::ReviewDialog(WindowManager& parWindowManager) : WindowBase("openmw_chargen_review.layout", parWindowManager) - , lastPos(0) + , mLastPos(0) { // Centre dialog center(); // Setup static stats ButtonPtr button; - getWidget(nameWidget, "NameText"); + getWidget(mNameWidget, "NameText"); getWidget(button, "NameButton"); adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onNameClicked);; - getWidget(raceWidget, "RaceText"); + getWidget(mRaceWidget, "RaceText"); getWidget(button, "RaceButton"); adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onRaceClicked);; - getWidget(classWidget, "ClassText"); + getWidget(mClassWidget, "ClassText"); getWidget(button, "ClassButton"); adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onClassClicked);; - getWidget(birthSignWidget, "SignText"); + getWidget(mBirthSignWidget, "SignText"); getWidget(button, "SignButton"); adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onBirthSignClicked);; // Setup dynamic stats - getWidget(health, "Health"); - health->setTitle(mWindowManager.getGameSettingString("sHealth", "")); - health->setValue(45, 45); + getWidget(mHealth, "Health"); + mHealth->setTitle(mWindowManager.getGameSettingString("sHealth", "")); + mHealth->setValue(45, 45); - getWidget(magicka, "Magicka"); - magicka->setTitle(mWindowManager.getGameSettingString("sMagic", "")); - magicka->setValue(50, 50); + getWidget(mMagicka, "Magicka"); + mMagicka->setTitle(mWindowManager.getGameSettingString("sMagic", "")); + mMagicka->setValue(50, 50); - getWidget(fatigue, "Fatigue"); - fatigue->setTitle(mWindowManager.getGameSettingString("sFatigue", "")); - fatigue->setValue(160, 160); + getWidget(mFatigue, "Fatigue"); + mFatigue->setTitle(mWindowManager.getGameSettingString("sFatigue", "")); + mFatigue->setValue(160, 160); // Setup attributes @@ -67,24 +67,24 @@ ReviewDialog::ReviewDialog(WindowManager& parWindowManager) for (int idx = 0; idx < ESM::Attribute::Length; ++idx) { getWidget(attribute, std::string("Attribute") + boost::lexical_cast(idx)); - attributeWidgets.insert(std::make_pair(static_cast(ESM::Attribute::attributeIds[idx]), attribute)); + mAttributeWidgets.insert(std::make_pair(static_cast(ESM::Attribute::attributeIds[idx]), attribute)); attribute->setWindowManager(&mWindowManager); attribute->setAttributeId(ESM::Attribute::attributeIds[idx]); attribute->setAttributeValue(MWAttribute::AttributeValue(0, 0)); } // Setup skills - getWidget(skillAreaWidget, "Skills"); - getWidget(skillClientWidget, "SkillClient"); - getWidget(skillScrollerWidget, "SkillScroller"); - skillClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); - skillScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &ReviewDialog::onScrollChangePosition); + getWidget(mSkillAreaWidget, "Skills"); + getWidget(mSkillClientWidget, "SkillClient"); + getWidget(mSkillScrollerWidget, "SkillScroller"); + mSkillClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); + mSkillScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &ReviewDialog::onScrollChangePosition); updateScroller(); for (int i = 0; i < ESM::Skill::Length; ++i) { - skillValues.insert(std::make_pair(i, MWMechanics::Stat())); - skillWidgetMap.insert(std::make_pair(i, static_cast (0))); + mSkillValues.insert(std::make_pair(i, MWMechanics::Stat())); + mSkillWidgetMap.insert(std::make_pair(i, static_cast (0))); } static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ReviewDialog::onWindowResize); @@ -112,14 +112,14 @@ void ReviewDialog::open() void ReviewDialog::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) { - int diff = lastPos - pos; + int diff = mLastPos - pos; // Adjust position of all widget according to difference if (diff == 0) return; - lastPos = pos; + mLastPos = pos; - std::vector::const_iterator end = skillWidgets.end(); - for (std::vector::const_iterator it = skillWidgets.begin(); it != end; ++it) + std::vector::const_iterator end = mSkillWidgets.end(); + for (std::vector::const_iterator it = mSkillWidgets.begin(); it != end; ++it) { (*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff)); } @@ -132,63 +132,63 @@ void ReviewDialog::onWindowResize(MyGUI::Window* window) void ReviewDialog::setPlayerName(const std::string &name) { - nameWidget->setCaption(name); + mNameWidget->setCaption(name); } -void ReviewDialog::setRace(const std::string &raceId_) +void ReviewDialog::setRace(const std::string &raceId) { - raceId = raceId_; - const ESM::Race *race = mWindowManager.getStore().races.search(raceId); + mRaceId = raceId; + const ESM::Race *race = mWindowManager.getStore().races.search(mRaceId); if (race) { - ToolTips::createRaceToolTip(raceWidget, race); - raceWidget->setCaption(race->name); + ToolTips::createRaceToolTip(mRaceWidget, race); + mRaceWidget->setCaption(race->name); } } void ReviewDialog::setClass(const ESM::Class& class_) { - klass = class_; - classWidget->setCaption(klass.name); - ToolTips::createClassToolTip(classWidget, klass); + mKlass = class_; + mClassWidget->setCaption(mKlass.name); + ToolTips::createClassToolTip(mClassWidget, mKlass); } void ReviewDialog::setBirthSign(const std::string& signId) { - birthSignId = signId; - const ESM::BirthSign *sign = mWindowManager.getStore().birthSigns.search(birthSignId); + mBirthSignId = signId; + const ESM::BirthSign *sign = mWindowManager.getStore().birthSigns.search(mBirthSignId); if (sign) { - birthSignWidget->setCaption(sign->name); - ToolTips::createBirthsignToolTip(birthSignWidget, birthSignId); + mBirthSignWidget->setCaption(sign->name); + ToolTips::createBirthsignToolTip(mBirthSignWidget, mBirthSignId); } } void ReviewDialog::setHealth(const MWMechanics::DynamicStat& value) { - health->setValue(value.getCurrent(), value.getModified()); + mHealth->setValue(value.getCurrent(), value.getModified()); std::string valStr = boost::lexical_cast(value.getCurrent()) + "/" + boost::lexical_cast(value.getModified()); - health->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr); + mHealth->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr); } void ReviewDialog::setMagicka(const MWMechanics::DynamicStat& value) { - magicka->setValue(value.getCurrent(), value.getModified()); + mMagicka->setValue(value.getCurrent(), value.getModified()); std::string valStr = boost::lexical_cast(value.getCurrent()) + "/" + boost::lexical_cast(value.getModified()); - magicka->setUserString("Caption_HealthDescription", "#{sIntDesc}\n" + valStr); + mMagicka->setUserString("Caption_HealthDescription", "#{sIntDesc}\n" + valStr); } void ReviewDialog::setFatigue(const MWMechanics::DynamicStat& value) { - fatigue->setValue(value.getCurrent(), value.getModified()); + mFatigue->setValue(value.getCurrent(), value.getModified()); std::string valStr = boost::lexical_cast(value.getCurrent()) + "/" + boost::lexical_cast(value.getModified()); - fatigue->setUserString("Caption_HealthDescription", "#{sFatDesc}\n" + valStr); + mFatigue->setUserString("Caption_HealthDescription", "#{sFatDesc}\n" + valStr); } void ReviewDialog::setAttribute(ESM::Attribute::AttributeID attributeId, const MWMechanics::Stat& value) { - std::map::iterator attr = attributeWidgets.find(static_cast(attributeId)); - if (attr == attributeWidgets.end()) + std::map::iterator attr = mAttributeWidgets.find(static_cast(attributeId)); + if (attr == mAttributeWidgets.end()) return; attr->second->setAttributeValue(value); @@ -196,8 +196,8 @@ void ReviewDialog::setAttribute(ESM::Attribute::AttributeID attributeId, const M void ReviewDialog::setSkillValue(ESM::Skill::SkillEnum skillId, const MWMechanics::Stat& value) { - skillValues[skillId] = value; - MyGUI::TextBox* widget = skillWidgetMap[skillId]; + mSkillValues[skillId] = value; + MyGUI::TextBox* widget = mSkillWidgetMap[skillId]; if (widget) { float modified = value.getModified(), base = value.getBase(); @@ -216,20 +216,20 @@ void ReviewDialog::setSkillValue(ESM::Skill::SkillEnum skillId, const MWMechanic void ReviewDialog::configureSkills(const std::vector& major, const std::vector& minor) { - majorSkills = major; - minorSkills = minor; + mMajorSkills = major; + mMinorSkills = minor; // Update misc skills with the remaining skills not in major or minor std::set skillSet; std::copy(major.begin(), major.end(), std::inserter(skillSet, skillSet.begin())); std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin())); boost::array::const_iterator end = ESM::Skill::skillIds.end(); - miscSkills.clear(); + mMiscSkills.clear(); for (boost::array::const_iterator it = ESM::Skill::skillIds.begin(); it != end; ++it) { int skill = *it; if (skillSet.find(skill) == skillSet.end()) - miscSkills.push_back(skill); + mMiscSkills.push_back(skill); } updateSkillArea(); @@ -237,10 +237,10 @@ void ReviewDialog::configureSkills(const std::vector& major, const std::vec void ReviewDialog::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { - MyGUI::ImageBox* separator = skillClientWidget->createWidget("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Default); + MyGUI::ImageBox* separator = mSkillClientWidget->createWidget("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Default); separator->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); - skillWidgets.push_back(separator); + mSkillWidgets.push_back(separator); coord1.top += separator->getHeight(); coord2.top += separator->getHeight(); @@ -248,13 +248,13 @@ void ReviewDialog::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2 void ReviewDialog::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { - MyGUI::TextBox* groupWidget = skillClientWidget->createWidget("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default); + MyGUI::TextBox* groupWidget = mSkillClientWidget->createWidget("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default); groupWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); groupWidget->setCaption(label); - skillWidgets.push_back(groupWidget); + mSkillWidgets.push_back(groupWidget); - coord1.top += lineHeight; - coord2.top += lineHeight; + coord1.top += sLineHeight; + coord2.top += sLineHeight; } MyGUI::TextBox* ReviewDialog::addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) @@ -262,20 +262,20 @@ MyGUI::TextBox* ReviewDialog::addValueItem(const std::string& text, const std::s MyGUI::TextBox* skillNameWidget; MyGUI::TextBox* skillValueWidget; - skillNameWidget = skillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Default); + skillNameWidget = mSkillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Default); skillNameWidget->setCaption(text); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); - skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Top | MyGUI::Align::Right); + skillValueWidget = mSkillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Top | MyGUI::Align::Right); skillValueWidget->setCaption(value); skillValueWidget->_setWidgetState(state); skillValueWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); - skillWidgets.push_back(skillNameWidget); - skillWidgets.push_back(skillValueWidget); + mSkillWidgets.push_back(skillNameWidget); + mSkillWidgets.push_back(skillValueWidget); - coord1.top += lineHeight; - coord2.top += lineHeight; + coord1.top += sLineHeight; + coord2.top += sLineHeight; return skillValueWidget; } @@ -284,20 +284,20 @@ void ReviewDialog::addItem(const std::string& text, MyGUI::IntCoord &coord1, MyG { MyGUI::TextBox* skillNameWidget; - skillNameWidget = skillClientWidget->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); + skillNameWidget = mSkillClientWidget->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); skillNameWidget->setCaption(text); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); - skillWidgets.push_back(skillNameWidget); + mSkillWidgets.push_back(skillNameWidget); - coord1.top += lineHeight; - coord2.top += lineHeight; + coord1.top += sLineHeight; + coord2.top += sLineHeight; } void ReviewDialog::addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { // Add a line separator if there are items above - if (!skillWidgets.empty()) + if (!mSkillWidgets.empty()) { addSeparator(coord1, coord2); } @@ -312,7 +312,7 @@ void ReviewDialog::addSkills(const SkillList &skills, const std::string &titleId continue; assert(skillId >= 0 && skillId < ESM::Skill::Length); const std::string &skillNameId = ESMS::Skill::sSkillNameIds[skillId]; - const MWMechanics::Stat &stat = skillValues.find(skillId)->second; + const MWMechanics::Stat &stat = mSkillValues.find(skillId)->second; float base = stat.getBase(); float modified = stat.getModified(); @@ -325,44 +325,44 @@ void ReviewDialog::addSkills(const SkillList &skills, const std::string &titleId for (int i=0; i<2; ++i) { - ToolTips::createSkillToolTip(skillWidgets[skillWidgets.size()-1-i], skillId); + ToolTips::createSkillToolTip(mSkillWidgets[mSkillWidgets.size()-1-i], skillId); } - skillWidgetMap[skillId] = widget; + mSkillWidgetMap[skillId] = widget; } } void ReviewDialog::updateSkillArea() { - for (std::vector::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it) + for (std::vector::iterator it = mSkillWidgets.begin(); it != mSkillWidgets.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } - skillWidgets.clear(); + mSkillWidgets.clear(); const int valueSize = 40; - MyGUI::IntCoord coord1(10, 0, skillClientWidget->getWidth() - (10 + valueSize), 18); + MyGUI::IntCoord coord1(10, 0, mSkillClientWidget->getWidth() - (10 + valueSize), 18); MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); - if (!majorSkills.empty()) - addSkills(majorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2); + if (!mMajorSkills.empty()) + addSkills(mMajorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2); - if (!minorSkills.empty()) - addSkills(minorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2); + if (!mMinorSkills.empty()) + addSkills(mMinorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2); - if (!miscSkills.empty()) - addSkills(miscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); + if (!mMiscSkills.empty()) + addSkills(mMiscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); - clientHeight = coord1.top; + mClientHeight = coord1.top; updateScroller(); } void ReviewDialog::updateScroller() { - skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0)); - skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0)); - if (clientHeight != 0) - skillScrollerWidget->setTrackSize( (skillAreaWidget->getHeight() / float(clientHeight)) * skillScrollerWidget->getLineSize() ); + mSkillScrollerWidget->setScrollRange(std::max(mClientHeight - mSkillClientWidget->getHeight(), 0)); + mSkillScrollerWidget->setScrollPage(std::max(mSkillClientWidget->getHeight() - sLineHeight, 0)); + if (mClientHeight != 0) + mSkillScrollerWidget->setTrackSize( (mSkillAreaWidget->getHeight() / float(mClientHeight)) * mSkillScrollerWidget->getLineSize() ); } // widget controls @@ -399,12 +399,12 @@ void ReviewDialog::onBirthSignClicked(MyGUI::Widget* _sender) void ReviewDialog::onMouseWheel(MyGUI::Widget* _sender, int _rel) { - if (skillScrollerWidget->getScrollPosition() - _rel*0.3 < 0) - skillScrollerWidget->setScrollPosition(0); - else if (skillScrollerWidget->getScrollPosition() - _rel*0.3 > skillScrollerWidget->getScrollRange()-1) - skillScrollerWidget->setScrollPosition(skillScrollerWidget->getScrollRange()-1); + if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 < 0) + mSkillScrollerWidget->setScrollPosition(0); + else if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 > mSkillScrollerWidget->getScrollRange()-1) + mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollRange()-1); else - skillScrollerWidget->setScrollPosition(skillScrollerWidget->getScrollPosition() - _rel*0.3); + mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollPosition() - _rel*0.3); - onScrollChangePosition(skillScrollerWidget, skillScrollerWidget->getScrollPosition()); + onScrollChangePosition(mSkillScrollerWidget, mSkillScrollerWidget->getScrollPosition()); } diff --git a/apps/openmw/mwgui/review.hpp b/apps/openmw/mwgui/review.hpp index 454a6c5a5..27b167033 100644 --- a/apps/openmw/mwgui/review.hpp +++ b/apps/openmw/mwgui/review.hpp @@ -82,23 +82,23 @@ namespace MWGui void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onWindowResize(MyGUI::Window* window); - static const int lineHeight; + static const int sLineHeight; - MyGUI::TextBox *nameWidget, *raceWidget, *classWidget, *birthSignWidget; - MyGUI::WidgetPtr skillAreaWidget, skillClientWidget; - MyGUI::ScrollBar* skillScrollerWidget; - int lastPos, clientHeight; + MyGUI::TextBox *mNameWidget, *mRaceWidget, *mClassWidget, *mBirthSignWidget; + MyGUI::WidgetPtr mSkillAreaWidget, mSkillClientWidget; + MyGUI::ScrollBar* mSkillScrollerWidget; + int mLastPos, mClientHeight; - Widgets::MWDynamicStatPtr health, magicka, fatigue; + Widgets::MWDynamicStatPtr mHealth, mMagicka, mFatigue; - std::map attributeWidgets; + std::map mAttributeWidgets; - SkillList majorSkills, minorSkills, miscSkills; - std::map > skillValues; - std::map skillWidgetMap; - std::string name, raceId, birthSignId; - ESM::Class klass; - std::vector skillWidgets; //< Skills and other information + SkillList mMajorSkills, mMinorSkills, mMiscSkills; + std::map > mSkillValues; + std::map mSkillWidgetMap; + std::string mName, mRaceId, mBirthSignId; + ESM::Class mKlass; + std::vector mSkillWidgets; //< Skills and other information }; } #endif diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index be99982d9..190d19594 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -19,26 +19,26 @@ using namespace MWGui; -const int StatsWindow::lineHeight = 18; +const int StatsWindow::sLineHeight = 18; StatsWindow::StatsWindow (WindowManager& parWindowManager) : WindowPinnableBase("openmw_stats_window.layout", parWindowManager) - , skillAreaWidget(NULL) - , skillClientWidget(NULL) - , skillScrollerWidget(NULL) - , lastPos(0) - , clientHeight(0) - , majorSkills() - , minorSkills() - , miscSkills() - , skillValues() - , skillWidgetMap() - , factionWidgetMap() + , mSkillAreaWidget(NULL) + , mSkillClientWidget(NULL) + , mSkillScrollerWidget(NULL) + , mLastPos(0) + , mClientHeight(0) + , mMajorSkills() + , mMinorSkills() + , mMiscSkills() + , mSkillValues() + , mSkillWidgetMap() + , mFactionWidgetMap() , mFactions() - , birthSignId() - , reputation(0) - , bounty(0) - , skillWidgets() + , mBirthSignId() + , mReputation(0) + , mBounty(0) + , mSkillWidgets() , mChanged(true) { setCoord(0,0,498, 342); @@ -62,21 +62,21 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager) setText (names[i][0], store.gameSettings.find (names[i][1])->str); } - getWidget(skillAreaWidget, "Skills"); - getWidget(skillClientWidget, "SkillClient"); - getWidget(skillScrollerWidget, "SkillScroller"); + getWidget(mSkillAreaWidget, "Skills"); + getWidget(mSkillClientWidget, "SkillClient"); + getWidget(mSkillScrollerWidget, "SkillScroller"); getWidget(mLeftPane, "LeftPane"); getWidget(mRightPane, "RightPane"); - skillClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); + mSkillClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - skillScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &StatsWindow::onScrollChangePosition); + mSkillScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &StatsWindow::onScrollChangePosition); updateScroller(); for (int i = 0; i < ESM::Skill::Length; ++i) { - skillValues.insert(std::pair >(i, MWMechanics::Stat())); - skillWidgetMap.insert(std::pair(i, nullptr)); + mSkillValues.insert(std::pair >(i, MWMechanics::Stat())); + mSkillWidgetMap.insert(std::pair(i, nullptr)); } MyGUI::WindowPtr t = static_cast(mMainWidget); @@ -85,14 +85,14 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager) void StatsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) { - int diff = lastPos - pos; + int diff = mLastPos - pos; // Adjust position of all widget according to difference if (diff == 0) return; - lastPos = pos; + mLastPos = pos; - std::vector::const_iterator end = skillWidgets.end(); - for (std::vector::const_iterator it = skillWidgets.begin(); it != end; ++it) + std::vector::const_iterator end = mSkillWidgets.end(); + for (std::vector::const_iterator it = mSkillWidgets.begin(); it != end; ++it) { (*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff)); } @@ -100,14 +100,14 @@ void StatsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) void StatsWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) { - if (skillScrollerWidget->getScrollPosition() - _rel*0.3 < 0) - skillScrollerWidget->setScrollPosition(0); - else if (skillScrollerWidget->getScrollPosition() - _rel*0.3 > skillScrollerWidget->getScrollRange()-1) - skillScrollerWidget->setScrollPosition(skillScrollerWidget->getScrollRange()-1); + if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 < 0) + mSkillScrollerWidget->setScrollPosition(0); + else if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 > mSkillScrollerWidget->getScrollRange()-1) + mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollRange()-1); else - skillScrollerWidget->setScrollPosition(skillScrollerWidget->getScrollPosition() - _rel*0.3); + mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollPosition() - _rel*0.3); - onScrollChangePosition(skillScrollerWidget, skillScrollerWidget->getScrollPosition()); + onScrollChangePosition(mSkillScrollerWidget, mSkillScrollerWidget->getScrollPosition()); } void StatsWindow::onWindowResize(MyGUI::Window* window) @@ -224,8 +224,8 @@ void StatsWindow::setValue (const std::string& id, int value) void StatsWindow::setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat& value) { - skillValues[parSkill] = value; - MyGUI::TextBox* widget = skillWidgetMap[(int)parSkill]; + mSkillValues[parSkill] = value; + MyGUI::TextBox* widget = mSkillWidgetMap[(int)parSkill]; if (widget) { float modified = value.getModified(), base = value.getBase(); @@ -243,20 +243,20 @@ void StatsWindow::setValue(const ESM::Skill::SkillEnum parSkill, const MWMechani void StatsWindow::configureSkills (const std::vector& major, const std::vector& minor) { - majorSkills = major; - minorSkills = minor; + mMajorSkills = major; + mMinorSkills = minor; // Update misc skills with the remaining skills not in major or minor std::set skillSet; std::copy(major.begin(), major.end(), std::inserter(skillSet, skillSet.begin())); std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin())); boost::array::const_iterator end = ESM::Skill::skillIds.end(); - miscSkills.clear(); + mMiscSkills.clear(); for (boost::array::const_iterator it = ESM::Skill::skillIds.begin(); it != end; ++it) { int skill = *it; if (skillSet.find(skill) == skillSet.end()) - miscSkills.push_back(skill); + mMiscSkills.push_back(skill); } updateSkillArea(); @@ -289,20 +289,20 @@ void StatsWindow::setFactions (const FactionList& factions) void StatsWindow::setBirthSign (const std::string& signId) { - if (signId != birthSignId) + if (signId != mBirthSignId) { - birthSignId = signId; + mBirthSignId = signId; mChanged = true; } } void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { - MyGUI::ImageBox* separator = skillClientWidget->createWidget("MW_HLine", + MyGUI::ImageBox* separator = mSkillClientWidget->createWidget("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); separator->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - skillWidgets.push_back(separator); + mSkillWidgets.push_back(separator); coord1.top += separator->getHeight(); coord2.top += separator->getHeight(); @@ -310,35 +310,35 @@ void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { - MyGUI::TextBox* groupWidget = skillClientWidget->createWidget("SandBrightText", + MyGUI::TextBox* groupWidget = mSkillClientWidget->createWidget("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); groupWidget->setCaption(label); groupWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - skillWidgets.push_back(groupWidget); + mSkillWidgets.push_back(groupWidget); - coord1.top += lineHeight; - coord2.top += lineHeight; + coord1.top += sLineHeight; + coord2.top += sLineHeight; } MyGUI::TextBox* StatsWindow::addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { MyGUI::TextBox *skillNameWidget, *skillValueWidget; - skillNameWidget = skillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); + skillNameWidget = mSkillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); skillNameWidget->setCaption(text); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top); + skillValueWidget = mSkillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top); skillValueWidget->setCaption(value); skillValueWidget->_setWidgetState(state); skillValueWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - skillWidgets.push_back(skillNameWidget); - skillWidgets.push_back(skillValueWidget); + mSkillWidgets.push_back(skillNameWidget); + mSkillWidgets.push_back(skillValueWidget); - coord1.top += lineHeight; - coord2.top += lineHeight; + coord1.top += sLineHeight; + coord2.top += sLineHeight; return skillValueWidget; } @@ -347,14 +347,14 @@ MyGUI::Widget* StatsWindow::addItem(const std::string& text, MyGUI::IntCoord &co { MyGUI::TextBox* skillNameWidget; - skillNameWidget = skillClientWidget->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); + skillNameWidget = mSkillClientWidget->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); skillNameWidget->setCaption(text); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - skillWidgets.push_back(skillNameWidget); + mSkillWidgets.push_back(skillNameWidget); - coord1.top += lineHeight; - coord2.top += lineHeight; + coord1.top += sLineHeight; + coord2.top += sLineHeight; return skillNameWidget; } @@ -362,7 +362,7 @@ MyGUI::Widget* StatsWindow::addItem(const std::string& text, MyGUI::IntCoord &co void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { // Add a line separator if there are items above - if (!skillWidgets.empty()) + if (!mSkillWidgets.empty()) { addSeparator(coord1, coord2); } @@ -377,7 +377,7 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, continue; assert(skillId >= 0 && skillId < ESM::Skill::Length); const std::string &skillNameId = ESMS::Skill::sSkillNameIds[skillId]; - const MWMechanics::Stat &stat = skillValues.find(skillId)->second; + const MWMechanics::Stat &stat = mSkillValues.find(skillId)->second; float base = stat.getBase(); float modified = stat.getModified(); int progressPercent = (modified - float(static_cast(modified))) * 100; @@ -400,18 +400,18 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, for (int i=0; i<2; ++i) { - skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipLayout", "SkillToolTip"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillName", "#{"+skillNameId+"}"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillDescription", skill->description); - skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillAttribute", "#{sGoverningAttribute}: #{" + attr->name + "}"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("ImageTexture_SkillImage", icon); - skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillProgressText", boost::lexical_cast(progressPercent)+"/100"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("Range_SkillProgress", "100"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("RangePosition_SkillProgress", boost::lexical_cast(progressPercent)); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("ToolTipLayout", "SkillToolTip"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("Caption_SkillName", "#{"+skillNameId+"}"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("Caption_SkillDescription", skill->description); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("Caption_SkillAttribute", "#{sGoverningAttribute}: #{" + attr->name + "}"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("ImageTexture_SkillImage", icon); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("Caption_SkillProgressText", boost::lexical_cast(progressPercent)+"/100"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("Range_SkillProgress", "100"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("RangePosition_SkillProgress", boost::lexical_cast(progressPercent)); } - skillWidgetMap[skillId] = widget; + mSkillWidgetMap[skillId] = widget; } } @@ -419,28 +419,28 @@ void StatsWindow::updateSkillArea() { mChanged = false; - for (std::vector::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it) + for (std::vector::iterator it = mSkillWidgets.begin(); it != mSkillWidgets.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } - skillWidgets.clear(); + mSkillWidgets.clear(); - skillScrollerWidget->setScrollPosition(0); - onScrollChangePosition(skillScrollerWidget, 0); - clientHeight = 0; + mSkillScrollerWidget->setScrollPosition(0); + onScrollChangePosition(mSkillScrollerWidget, 0); + mClientHeight = 0; const int valueSize = 40; - MyGUI::IntCoord coord1(10, 0, skillClientWidget->getWidth() - (10 + valueSize), 18); + MyGUI::IntCoord coord1(10, 0, mSkillClientWidget->getWidth() - (10 + valueSize), 18); MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); - if (!majorSkills.empty()) - addSkills(majorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2); + if (!mMajorSkills.empty()) + addSkills(mMajorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2); - if (!minorSkills.empty()) - addSkills(minorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2); + if (!mMinorSkills.empty()) + addSkills(mMinorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2); - if (!miscSkills.empty()) - addSkills(miscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); + if (!mMiscSkills.empty()) + addSkills(mMiscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); const ESMS::ESMStore &store = mWindowManager.getStore(); @@ -463,7 +463,7 @@ void StatsWindow::updateSkillArea() if (!mFactions.empty()) { // Add a line separator if there are items above - if (!skillWidgets.empty()) + if (!mSkillWidgets.empty()) addSeparator(coord1, coord2); addGroup(mWindowManager.getGameSettingString("sFaction", "Faction"), coord1, coord2); @@ -516,53 +516,53 @@ void StatsWindow::updateSkillArea() } } - if (!birthSignId.empty()) + if (!mBirthSignId.empty()) { // Add a line separator if there are items above - if (!skillWidgets.empty()) + if (!mSkillWidgets.empty()) addSeparator(coord1, coord2); addGroup(mWindowManager.getGameSettingString("sBirthSign", "Sign"), coord1, coord2); - const ESM::BirthSign *sign = store.birthSigns.find(birthSignId); + const ESM::BirthSign *sign = store.birthSigns.find(mBirthSignId); MyGUI::Widget* w = addItem(sign->name, coord1, coord2); - ToolTips::createBirthsignToolTip(w, birthSignId); + ToolTips::createBirthsignToolTip(w, mBirthSignId); } // Add a line separator if there are items above - if (!skillWidgets.empty()) + if (!mSkillWidgets.empty()) addSeparator(coord1, coord2); addValueItem(mWindowManager.getGameSettingString("sReputation", "Reputation"), - boost::lexical_cast(static_cast(reputation)), "normal", coord1, coord2); + boost::lexical_cast(static_cast(mReputation)), "normal", coord1, coord2); for (int i=0; i<2; ++i) { - skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipLayout", "TextToolTip"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_Text", "#{sSkillsMenuReputationHelp}"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("ToolTipLayout", "TextToolTip"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("Caption_Text", "#{sSkillsMenuReputationHelp}"); } addValueItem(mWindowManager.getGameSettingString("sBounty", "Bounty"), - boost::lexical_cast(static_cast(bounty)), "normal", coord1, coord2); + boost::lexical_cast(static_cast(mBounty)), "normal", coord1, coord2); for (int i=0; i<2; ++i) { - skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipLayout", "TextToolTip"); - skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_Text", "#{sCrimeHelp}"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("ToolTipLayout", "TextToolTip"); + mSkillWidgets[mSkillWidgets.size()-1-i]->setUserString("Caption_Text", "#{sCrimeHelp}"); } - clientHeight = coord1.top; + mClientHeight = coord1.top; updateScroller(); } void StatsWindow::updateScroller() { - skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0)); - skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0)); - if (clientHeight != 0) - skillScrollerWidget->setTrackSize( (skillAreaWidget->getHeight() / float(clientHeight)) * skillScrollerWidget->getLineSize() ); + mSkillScrollerWidget->setScrollRange(std::max(mClientHeight - mSkillClientWidget->getHeight(), 0)); + mSkillScrollerWidget->setScrollPage(std::max(mSkillClientWidget->getHeight() - sLineHeight, 0)); + if (mClientHeight != 0) + mSkillScrollerWidget->setTrackSize( (mSkillAreaWidget->getHeight() / float(mClientHeight)) * mSkillScrollerWidget->getLineSize() ); } void StatsWindow::onPinToggled() diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 10b794cc0..2469c12e9 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -38,8 +38,8 @@ namespace MWGui void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat& value); void configureSkills (const SkillList& major, const SkillList& minor); - void setReputation (int reputation) { this->reputation = reputation; } - void setBounty (int bounty) { this->bounty = bounty; } + void setReputation (int reputation) { this->mReputation = reputation; } + void setBounty (int bounty) { this->mBounty = bounty; } void updateSkillArea(); private: @@ -57,23 +57,23 @@ namespace MWGui void onWindowResize(MyGUI::Window* window); void onMouseWheel(MyGUI::Widget* _sender, int _rel); - static const int lineHeight; + static const int sLineHeight; MyGUI::Widget* mLeftPane; MyGUI::Widget* mRightPane; - MyGUI::WidgetPtr skillAreaWidget, skillClientWidget; - MyGUI::ScrollBar* skillScrollerWidget; - int lastPos, clientHeight; + MyGUI::WidgetPtr mSkillAreaWidget, mSkillClientWidget; + MyGUI::ScrollBar* mSkillScrollerWidget; + int mLastPos, mClientHeight; - SkillList majorSkills, minorSkills, miscSkills; - std::map > skillValues; - std::map skillWidgetMap; - std::map factionWidgetMap; + SkillList mMajorSkills, mMinorSkills, mMiscSkills; + std::map > mSkillValues; + std::map mSkillWidgetMap; + std::map mFactionWidgetMap; FactionList mFactions; ///< Stores a list of factions and the current rank - std::string birthSignId; - int reputation, bounty; - std::vector skillWidgets; //< Skills and other information + std::string mBirthSignId; + int mReputation, mBounty; + std::vector mSkillWidgets; //< Skills and other information bool mChanged; diff --git a/apps/openmw/mwgui/text_input.cpp b/apps/openmw/mwgui/text_input.cpp index 17852ba5a..7d5b0cc6d 100644 --- a/apps/openmw/mwgui/text_input.cpp +++ b/apps/openmw/mwgui/text_input.cpp @@ -9,15 +9,15 @@ TextInputDialog::TextInputDialog(WindowManager& parWindowManager) // Centre dialog center(); - getWidget(textEdit, "TextEdit"); - textEdit->eventEditSelectAccept += newDelegate(this, &TextInputDialog::onTextAccepted); + getWidget(mTextEdit, "TextEdit"); + mTextEdit->eventEditSelectAccept += newDelegate(this, &TextInputDialog::onTextAccepted); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked); // Make sure the edit box has focus - MyGUI::InputManager::getInstance().setKeyFocusWidget(textEdit); + MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); } void TextInputDialog::setNextButtonShow(bool shown) @@ -43,7 +43,7 @@ void TextInputDialog::setTextLabel(const std::string &label) void TextInputDialog::open() { // Make sure the edit box has focus - MyGUI::InputManager::getInstance().setKeyFocusWidget(textEdit); + MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); setVisible(true); } diff --git a/apps/openmw/mwgui/text_input.hpp b/apps/openmw/mwgui/text_input.hpp index fe355655f..835d5deaa 100644 --- a/apps/openmw/mwgui/text_input.hpp +++ b/apps/openmw/mwgui/text_input.hpp @@ -20,8 +20,8 @@ namespace MWGui public: TextInputDialog(WindowManager& parWindowManager); - std::string getTextInput() const { return textEdit ? textEdit->getOnlyText() : ""; } - void setTextInput(const std::string &text) { if (textEdit) textEdit->setOnlyText(text); } + std::string getTextInput() const { return mTextEdit ? mTextEdit->getOnlyText() : ""; } + void setTextInput(const std::string &text) { if (mTextEdit) mTextEdit->setOnlyText(text); } void setNextButtonShow(bool shown); void setTextLabel(const std::string &label); @@ -32,7 +32,7 @@ namespace MWGui void onTextAccepted(MyGUI::Edit* _sender); private: - MyGUI::EditPtr textEdit; + MyGUI::EditPtr mTextEdit; }; } #endif diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 65de7ce0a..c54ac6e38 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -27,16 +27,16 @@ void MWGui::Widgets::fixTexturePath(std::string &path) /* MWSkill */ MWSkill::MWSkill() - : manager(nullptr) - , skillId(ESM::Skill::Length) - , skillNameWidget(nullptr) - , skillValueWidget(nullptr) + : mManager(nullptr) + , mSkillId(ESM::Skill::Length) + , mSkillNameWidget(nullptr) + , mSkillValueWidget(nullptr) { } void MWSkill::setSkillId(ESM::Skill::SkillEnum skill) { - skillId = skill; + mSkillId = skill; updateWidgets(); } @@ -50,36 +50,36 @@ void MWSkill::setSkillNumber(int skill) throw new std::runtime_error("Skill number out of range"); } -void MWSkill::setSkillValue(const SkillValue& value_) +void MWSkill::setSkillValue(const SkillValue& value) { - value = value_; + mValue = value; updateWidgets(); } void MWSkill::updateWidgets() { - if (skillNameWidget && manager) + if (mSkillNameWidget && mManager) { - if (skillId == ESM::Skill::Length) + if (mSkillId == ESM::Skill::Length) { - static_cast(skillNameWidget)->setCaption(""); + static_cast(mSkillNameWidget)->setCaption(""); } else { - const std::string &name = manager->getGameSettingString(ESM::Skill::sSkillNameIds[skillId], ""); - static_cast(skillNameWidget)->setCaption(name); + const std::string &name = mManager->getGameSettingString(ESM::Skill::sSkillNameIds[mSkillId], ""); + static_cast(mSkillNameWidget)->setCaption(name); } } - if (skillValueWidget) + if (mSkillValueWidget) { - SkillValue::Type modified = value.getModified(), base = value.getBase(); - static_cast(skillValueWidget)->setCaption(boost::lexical_cast(modified)); + SkillValue::Type modified = mValue.getModified(), base = mValue.getBase(); + static_cast(mSkillValueWidget)->setCaption(boost::lexical_cast(modified)); if (modified > base) - skillValueWidget->_setWidgetState("increased"); + mSkillValueWidget->_setWidgetState("increased"); else if (modified < base) - skillValueWidget->_setWidgetState("decreased"); + mSkillValueWidget->_setWidgetState("decreased"); else - skillValueWidget->_setWidgetState("normal"); + mSkillValueWidget->_setWidgetState("normal"); } } @@ -96,14 +96,14 @@ void MWSkill::initialiseOverride() { Base::initialiseOverride(); - assignWidget(skillNameWidget, "StatName"); - assignWidget(skillValueWidget, "StatValue"); + assignWidget(mSkillNameWidget, "StatName"); + assignWidget(mSkillValueWidget, "StatValue"); MyGUI::ButtonPtr button; assignWidget(button, "StatNameButton"); if (button) { - skillNameWidget = button; + mSkillNameWidget = button; button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWSkill::onClicked); } @@ -111,7 +111,7 @@ void MWSkill::initialiseOverride() assignWidget(button, "StatValueButton"); if (button) { - skillNameWidget = button; + mSkillNameWidget = button; button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWSkill::onClicked); } } @@ -119,22 +119,22 @@ void MWSkill::initialiseOverride() /* MWAttribute */ MWAttribute::MWAttribute() - : manager(nullptr) - , id(-1) - , attributeNameWidget(nullptr) - , attributeValueWidget(nullptr) + : mManager(nullptr) + , mId(-1) + , mAttributeNameWidget(nullptr) + , mAttributeValueWidget(nullptr) { } void MWAttribute::setAttributeId(int attributeId) { - id = attributeId; + mId = attributeId; updateWidgets(); } -void MWAttribute::setAttributeValue(const AttributeValue& value_) +void MWAttribute::setAttributeValue(const AttributeValue& value) { - value = value_; + mValue = value; updateWidgets(); } @@ -145,11 +145,11 @@ void MWAttribute::onClicked(MyGUI::Widget* _sender) void MWAttribute::updateWidgets() { - if (attributeNameWidget && manager) + if (mAttributeNameWidget && mManager) { - if (id < 0 || id >= 8) + if (mId < 0 || mId >= 8) { - static_cast(attributeNameWidget)->setCaption(""); + static_cast(mAttributeNameWidget)->setCaption(""); } else { @@ -163,20 +163,20 @@ void MWAttribute::updateWidgets() "sAttributePersonality", "sAttributeLuck" }; - const std::string &name = manager->getGameSettingString(attributes[id], ""); - static_cast(attributeNameWidget)->setCaption(name); + const std::string &name = mManager->getGameSettingString(attributes[mId], ""); + static_cast(mAttributeNameWidget)->setCaption(name); } } - if (attributeValueWidget) + if (mAttributeValueWidget) { - AttributeValue::Type modified = value.getModified(), base = value.getBase(); - static_cast(attributeValueWidget)->setCaption(boost::lexical_cast(modified)); + AttributeValue::Type modified = mValue.getModified(), base = mValue.getBase(); + static_cast(mAttributeValueWidget)->setCaption(boost::lexical_cast(modified)); if (modified > base) - attributeValueWidget->_setWidgetState("increased"); + mAttributeValueWidget->_setWidgetState("increased"); else if (modified < base) - attributeValueWidget->_setWidgetState("decreased"); + mAttributeValueWidget->_setWidgetState("decreased"); else - attributeValueWidget->_setWidgetState("normal"); + mAttributeValueWidget->_setWidgetState("normal"); } } @@ -188,14 +188,14 @@ void MWAttribute::initialiseOverride() { Base::initialiseOverride(); - assignWidget(attributeNameWidget, "StatName"); - assignWidget(attributeValueWidget, "StatValue"); + assignWidget(mAttributeNameWidget, "StatName"); + assignWidget(mAttributeValueWidget, "StatValue"); MyGUI::ButtonPtr button; assignWidget(button, "StatNameButton"); if (button) { - attributeNameWidget = button; + mAttributeNameWidget = button; button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWAttribute::onClicked); } @@ -203,7 +203,7 @@ void MWAttribute::initialiseOverride() assignWidget(button, "StatValueButton"); if (button) { - attributeValueWidget = button; + mAttributeValueWidget = button; button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWAttribute::onClicked); } } @@ -212,21 +212,21 @@ void MWAttribute::initialiseOverride() MWSpell::MWSpell() : mWindowManager(nullptr) - , spellNameWidget(nullptr) + , mSpellNameWidget(nullptr) { } void MWSpell::setSpellId(const std::string &spellId) { - id = spellId; + mId = spellId; updateWidgets(); } void MWSpell::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, int flags) { const ESMS::ESMStore &store = mWindowManager->getStore(); - const ESM::Spell *spell = store.spells.search(id); - MYGUI_ASSERT(spell, "spell with id '" << id << "' not found"); + const ESM::Spell *spell = store.spells.search(mId); + MYGUI_ASSERT(spell, "spell with id '" << mId << "' not found"); MWSpellEffectPtr effect = nullptr; std::vector::const_iterator end = spell->effects.list.end(); @@ -253,14 +253,14 @@ void MWSpell::createEffectWidgets(std::vector &effects, MyGUI: void MWSpell::updateWidgets() { - if (spellNameWidget && mWindowManager) + if (mSpellNameWidget && mWindowManager) { const ESMS::ESMStore &store = mWindowManager->getStore(); - const ESM::Spell *spell = store.spells.search(id); + const ESM::Spell *spell = store.spells.search(mId); if (spell) - static_cast(spellNameWidget)->setCaption(spell->name); + static_cast(mSpellNameWidget)->setCaption(spell->name); else - static_cast(spellNameWidget)->setCaption(""); + static_cast(mSpellNameWidget)->setCaption(""); } } @@ -268,7 +268,7 @@ void MWSpell::initialiseOverride() { Base::initialiseOverride(); - assignWidget(spellNameWidget, "StatName"); + assignWidget(mSpellNameWidget, "StatName"); } MWSpell::~MWSpell() @@ -367,8 +367,8 @@ SpellEffectList MWEffectList::effectListFromESM(const ESM::EffectList* effects) MWSpellEffect::MWSpellEffect() : mWindowManager(nullptr) - , imageWidget(nullptr) - , textWidget(nullptr) + , mImageWidget(nullptr) + , mTextWidget(nullptr) , mRequestedWidth(0) { } @@ -388,7 +388,7 @@ void MWSpellEffect::updateWidgets() const ESM::MagicEffect *magicEffect = store.magicEffects.search(mEffectParams.mEffectID); if (!magicEffect) return; - if (textWidget) + if (mTextWidget) { std::string pt = mWindowManager->getGameSettingString("spoint", ""); std::string pts = mWindowManager->getGameSettingString("spoints", ""); @@ -448,14 +448,14 @@ void MWSpellEffect::updateWidgets() } } - static_cast(textWidget)->setCaption(spellLine); - mRequestedWidth = textWidget->getTextSize().width + 24; + static_cast(mTextWidget)->setCaption(spellLine); + mRequestedWidth = mTextWidget->getTextSize().width + 24; } - if (imageWidget) + if (mImageWidget) { std::string path = std::string("icons\\") + magicEffect->icon; fixTexturePath(path); - imageWidget->setImageTexture(path); + mImageWidget->setImageTexture(path); } } @@ -728,49 +728,49 @@ void MWSpellEffect::initialiseOverride() { Base::initialiseOverride(); - assignWidget(textWidget, "Text"); - assignWidget(imageWidget, "Image"); + assignWidget(mTextWidget, "Text"); + assignWidget(mImageWidget, "Image"); } /* MWDynamicStat */ MWDynamicStat::MWDynamicStat() -: value(0) -, max(1) -, textWidget(nullptr) -, barWidget(nullptr) -, barTextWidget(nullptr) +: mValue(0) +, mMax(1) +, mTextWidget(nullptr) +, mBarWidget(nullptr) +, mBarTextWidget(nullptr) { } -void MWDynamicStat::setValue(int cur, int max_) +void MWDynamicStat::setValue(int cur, int max) { - value = cur; - max = max_; + mValue = cur; + mMax = max; - if (barWidget) + if (mBarWidget) { - barWidget->setProgressRange(max); - barWidget->setProgressPosition(value); + mBarWidget->setProgressRange(mMax); + mBarWidget->setProgressPosition(mValue); } - if (barTextWidget) + if (mBarTextWidget) { - if (value >= 0 && max > 0) + if (mValue >= 0 && mMax > 0) { std::stringstream out; - out << value << "/" << max; - static_cast(barTextWidget)->setCaption(out.str().c_str()); + out << mValue << "/" << mMax; + static_cast(mBarTextWidget)->setCaption(out.str().c_str()); } else - static_cast(barTextWidget)->setCaption(""); + static_cast(mBarTextWidget)->setCaption(""); } } void MWDynamicStat::setTitle(const std::string& text) { - if (textWidget) - static_cast(textWidget)->setCaption(text); + if (mTextWidget) + static_cast(mTextWidget)->setCaption(text); } MWDynamicStat::~MWDynamicStat() @@ -781,7 +781,7 @@ void MWDynamicStat::initialiseOverride() { Base::initialiseOverride(); - assignWidget(textWidget, "Text"); - assignWidget(barWidget, "Bar"); - assignWidget(barTextWidget, "BarText"); + assignWidget(mTextWidget, "Text"); + assignWidget(mBarWidget, "Bar"); + assignWidget(mBarTextWidget, "BarText"); } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 5d00baf87..d4947895b 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -73,7 +73,7 @@ namespace MWGui typedef std::vector SpellEffectList; - class MYGUI_EXPORT MWSkill : public Widget + class MYGUI_EXPORT MWSkill : public MyGUI::Widget { MYGUI_RTTI_DERIVED( MWSkill ); public: @@ -81,14 +81,14 @@ namespace MWGui typedef MWMechanics::Stat SkillValue; - void setWindowManager(WindowManager *m) { manager = m; } + void setWindowManager(WindowManager *m) { mManager = m; } void setSkillId(ESM::Skill::SkillEnum skillId); void setSkillNumber(int skillId); void setSkillValue(const SkillValue& value); - WindowManager *getWindowManager() const { return manager; } - ESM::Skill::SkillEnum getSkillId() const { return skillId; } - const SkillValue& getSkillValue() const { return value; } + WindowManager *getWindowManager() const { return mManager; } + ESM::Skill::SkillEnum getSkillId() const { return mSkillId; } + const SkillValue& getSkillValue() const { return mValue; } // Events typedef delegates::CMultiDelegate1 EventHandle_SkillVoid; @@ -109,14 +109,14 @@ namespace MWGui void updateWidgets(); - WindowManager *manager; - ESM::Skill::SkillEnum skillId; - SkillValue value; - MyGUI::WidgetPtr skillNameWidget, skillValueWidget; + WindowManager *mManager; + ESM::Skill::SkillEnum mSkillId; + SkillValue mValue; + MyGUI::WidgetPtr mSkillNameWidget, mSkillValueWidget; }; typedef MWSkill* MWSkillPtr; - class MYGUI_EXPORT MWAttribute : public Widget + class MYGUI_EXPORT MWAttribute : public MyGUI::Widget { MYGUI_RTTI_DERIVED( MWAttribute ); public: @@ -124,13 +124,13 @@ namespace MWGui typedef MWMechanics::Stat AttributeValue; - void setWindowManager(WindowManager *m) { manager = m; } + void setWindowManager(WindowManager *m) { mManager = m; } void setAttributeId(int attributeId); void setAttributeValue(const AttributeValue& value); - WindowManager *getWindowManager() const { return manager; } - int getAttributeId() const { return id; } - const AttributeValue& getAttributeValue() const { return value; } + WindowManager *getWindowManager() const { return mManager; } + int getAttributeId() const { return mId; } + const AttributeValue& getAttributeValue() const { return mValue; } // Events typedef delegates::CMultiDelegate1 EventHandle_AttributeVoid; @@ -151,10 +151,10 @@ namespace MWGui void updateWidgets(); - WindowManager *manager; - int id; - AttributeValue value; - MyGUI::WidgetPtr attributeNameWidget, attributeValueWidget; + WindowManager *mManager; + int mId; + AttributeValue mValue; + MyGUI::WidgetPtr mAttributeNameWidget, mAttributeValueWidget; }; typedef MWAttribute* MWAttributePtr; @@ -162,7 +162,7 @@ namespace MWGui * @todo remove this class and use MWEffectList instead */ class MWSpellEffect; - class MYGUI_EXPORT MWSpell : public Widget + class MYGUI_EXPORT MWSpell : public MyGUI::Widget { MYGUI_RTTI_DERIVED( MWSpell ); public: @@ -182,7 +182,7 @@ namespace MWGui */ void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, int flags); - const std::string &getSpellId() const { return id; } + const std::string &getSpellId() const { return mId; } protected: virtual ~MWSpell(); @@ -193,12 +193,12 @@ namespace MWGui void updateWidgets(); WindowManager* mWindowManager; - std::string id; - MyGUI::TextBox* spellNameWidget; + std::string mId; + MyGUI::TextBox* mSpellNameWidget; }; typedef MWSpell* MWSpellPtr; - class MYGUI_EXPORT MWEffectList : public Widget + class MYGUI_EXPORT MWEffectList : public MyGUI::Widget { MYGUI_RTTI_DERIVED( MWEffectList ); public: @@ -239,7 +239,7 @@ namespace MWGui }; typedef MWEffectList* MWEffectListPtr; - class MYGUI_EXPORT MWSpellEffect : public Widget + class MYGUI_EXPORT MWSpellEffect : public MyGUI::Widget { MYGUI_RTTI_DERIVED( MWSpellEffect ); public: @@ -269,13 +269,13 @@ namespace MWGui WindowManager* mWindowManager; SpellEffectParams mEffectParams; - MyGUI::ImageBox* imageWidget; - MyGUI::TextBox* textWidget; + MyGUI::ImageBox* mImageWidget; + MyGUI::TextBox* mTextWidget; int mRequestedWidth; }; typedef MWSpellEffect* MWSpellEffectPtr; - class MYGUI_EXPORT MWDynamicStat : public Widget + class MYGUI_EXPORT MWDynamicStat : public MyGUI::Widget { MYGUI_RTTI_DERIVED( MWDynamicStat ); public: @@ -284,8 +284,8 @@ namespace MWGui void setValue(int value, int max); void setTitle(const std::string& text); - int getValue() const { return value; } - int getMax() const { return max; } + int getValue() const { return mValue; } + int getMax() const { return mMax; } protected: virtual ~MWDynamicStat(); @@ -294,10 +294,10 @@ namespace MWGui private: - int value, max; - MyGUI::TextBox* textWidget; - MyGUI::ProgressPtr barWidget; - MyGUI::TextBox* barTextWidget; + int mValue, mMax; + MyGUI::TextBox* mTextWidget; + MyGUI::ProgressPtr mBarWidget; + MyGUI::TextBox* mBarTextWidget; }; typedef MWDynamicStat* MWDynamicStatPtr; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 62207d7d7..aa0595b85 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -43,13 +43,13 @@ using namespace MWGui; WindowManager::WindowManager( const Compiler::Extensions& extensions, int fpsLevel, bool newGame, OEngine::Render::OgreRenderer *mOgre, const std::string& logpath) : mGuiManager(NULL) - , hud(NULL) - , map(NULL) - , menu(NULL) + , mHud(NULL) + , mMap(NULL) + , mMenu(NULL) , mStatsWindow(NULL) , mToolTips(NULL) , mMessageBoxManager(NULL) - , console(NULL) + , mConsole(NULL) , mJournal(NULL) , mDialogueWindow(NULL) , mBookWindow(NULL) @@ -61,21 +61,21 @@ WindowManager::WindowManager( , mAlchemyWindow(NULL) , mSpellWindow(NULL) , mCharGen(NULL) - , playerClass() - , playerName() - , playerRaceId() - , playerAttributes() - , playerMajorSkills() - , playerMinorSkills() - , playerSkillValues() - , playerHealth() - , playerMagicka() - , playerFatigue() - , gui(NULL) - , garbageDialogs() - , shown(GW_ALL) - , allowed(newGame ? GW_None : GW_ALL) - , showFPSLevel(fpsLevel) + , mPlayerClass() + , mPlayerName() + , mPlayerRaceId() + , mPlayerAttributes() + , mPlayerMajorSkills() + , mPlayerMinorSkills() + , mPlayerSkillValues() + , mPlayerHealth() + , mPlayerMagicka() + , mPlayerFatigue() + , mGui(NULL) + , mGarbageDialogs() + , mShown(GW_ALL) + , mAllowed(newGame ? GW_None : GW_ALL) + , mShowFPSLevel(fpsLevel) , mFPS(0.0f) , mTriangleCount(0) , mBatchCount(0) @@ -83,7 +83,7 @@ WindowManager::WindowManager( // Set up the GUI system mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, logpath); - gui = mGuiManager->getGui(); + mGui = mGuiManager->getGui(); //Register own widgets with MyGUI MyGUI::FactoryManager::getInstance().registerFactory("Widget"); @@ -98,11 +98,11 @@ WindowManager::WindowManager( MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag); // Get size info from the Gui object - assert(gui); + assert(mGui); int w = MyGUI::RenderManager::getInstance().getViewSize().width; int h = MyGUI::RenderManager::getInstance().getViewSize().height; - MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); + MyGUI::Widget* dragAndDropWidget = mGui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); dragAndDropWidget->setVisible(false); mDragAndDrop = new DragAndDrop(); @@ -110,17 +110,17 @@ WindowManager::WindowManager( mDragAndDrop->mDraggedWidget = 0; mDragAndDrop->mDragAndDropWidget = dragAndDropWidget; - menu = new MainMenu(w,h); - map = new MapWindow(*this); + mMenu = new MainMenu(w,h); + mMap = new MapWindow(*this); mStatsWindow = new StatsWindow(*this); - console = new Console(w,h, extensions); + mConsole = new Console(w,h, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mTradeWindow = new TradeWindow(*this); mDialogueWindow = new DialogueWindow(*this); mContainerWindow = new ContainerWindow(*this,mDragAndDrop); - hud = new HUD(w,h, showFPSLevel, mDragAndDrop); + mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop); mToolTips = new ToolTips(this); mScrollWindow = new ScrollWindow(*this); mBookWindow = new BookWindow(*this); @@ -131,19 +131,19 @@ WindowManager::WindowManager( mSpellWindow = new SpellWindow(*this); // The HUD is always on - hud->setVisible(true); + mHud->setVisible(true); mCharGen = new CharacterCreation(this); // Setup player stats for (int i = 0; i < ESM::Attribute::Length; ++i) { - playerAttributes.insert(std::make_pair(ESM::Attribute::attributeIds[i], MWMechanics::Stat())); + mPlayerAttributes.insert(std::make_pair(ESM::Attribute::attributeIds[i], MWMechanics::Stat())); } for (int i = 0; i < ESM::Skill::Length; ++i) { - playerSkillValues.insert(std::make_pair(ESM::Skill::skillIds[i], MWMechanics::Stat())); + mPlayerSkillValues.insert(std::make_pair(ESM::Skill::skillIds[i], MWMechanics::Stat())); } unsetSelectedSpell(); @@ -156,11 +156,11 @@ WindowManager::WindowManager( WindowManager::~WindowManager() { delete mGuiManager; - delete console; + delete mConsole; delete mMessageBoxManager; - delete hud; - delete map; - delete menu; + delete mHud; + delete mMap; + delete mMenu; delete mStatsWindow; delete mJournal; delete mDialogueWindow; @@ -183,13 +183,13 @@ WindowManager::~WindowManager() void WindowManager::cleanupGarbage() { // Delete any dialogs which are no longer in use - if (!garbageDialogs.empty()) + if (!mGarbageDialogs.empty()) { - for (std::vector::iterator it = garbageDialogs.begin(); it != garbageDialogs.end(); ++it) + for (std::vector::iterator it = mGarbageDialogs.begin(); it != mGarbageDialogs.end(); ++it) { delete *it; } - garbageDialogs.clear(); + mGarbageDialogs.clear(); } } @@ -197,18 +197,18 @@ void WindowManager::update() { cleanupGarbage(); - hud->setFPS(mFPS); - hud->setTriangleCount(mTriangleCount); - hud->setBatchCount(mBatchCount); + mHud->setFPS(mFPS); + mHud->setTriangleCount(mTriangleCount); + mHud->setBatchCount(mBatchCount); } void WindowManager::updateVisible() { // Start out by hiding everything except the HUD - map->setVisible(false); - menu->setVisible(false); + mMap->setVisible(false); + mMenu->setVisible(false); mStatsWindow->setVisible(false); - console->disable(); + mConsole->disable(); mJournal->setVisible(false); mDialogueWindow->setVisible(false); mContainerWindow->setVisible(false); @@ -230,10 +230,10 @@ void WindowManager::updateVisible() else mToolTips->enterGuiMode(); - setMinimapVisibility((allowed & GW_Map) && !map->pinned()); - setWeaponVisibility((allowed & GW_Inventory) && !mInventoryWindow->pinned()); - setSpellVisibility((allowed & GW_Magic) && !mSpellWindow->pinned()); - setHMSVisibility((allowed & GW_Stats) && !mStatsWindow->pinned()); + setMinimapVisibility((mAllowed & GW_Map) && !mMap->pinned()); + setWeaponVisibility((mAllowed & GW_Inventory) && !mInventoryWindow->pinned()); + setSpellVisibility((mAllowed & GW_Magic) && !mSpellWindow->pinned()); + setHMSVisibility((mAllowed & GW_Stats) && !mStatsWindow->pinned()); // If in game mode, don't show anything. if (gameMode) @@ -243,13 +243,13 @@ void WindowManager::updateVisible() switch(mode) { case GM_MainMenu: - menu->setVisible(true); + mMenu->setVisible(true); break; case GM_Settings: mSettingsWindow->setVisible(true); break; case GM_Console: - console->enable(); + mConsole->enable(); break; case GM_Scroll: mScrollWindow->setVisible(true); @@ -276,13 +276,13 @@ void WindowManager::updateVisible() // This is controlled both by what windows the // user has opened/closed (the 'shown' variable) and by what // windows we are allowed to show (the 'allowed' var.) - int eff = shown & allowed; + int eff = mShown & mAllowed; // Show the windows we want - map -> setVisible(eff & GW_Map); - mStatsWindow -> setVisible(eff & GW_Stats); + mMap ->setVisible(eff & GW_Map); + mStatsWindow ->setVisible(eff & GW_Stats); mInventoryWindow->setVisible(eff & GW_Inventory); - mSpellWindow->setVisible(eff & GW_Magic); + mSpellWindow ->setVisible(eff & GW_Magic); break; } case GM_Container: @@ -333,7 +333,7 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::StatsetValue(parSkill, value); mCharGen->setValue(parSkill, value); - playerSkillValues[parSkill] = value; + mPlayerSkillValues[parSkill] = value; } void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat& value) { mStatsWindow->setValue (id, value); - hud->setValue (id, value); + mHud->setValue (id, value); mCharGen->setValue(id, value); if (id == "HBar") { - playerHealth = value; + mPlayerHealth = value; mCharGen->setPlayerHealth (value); } else if (id == "MBar") { - playerMagicka = value; + mPlayerMagicka = value; mCharGen->setPlayerMagicka (value); } else if (id == "FBar") { - playerFatigue = value; + mPlayerFatigue = value; mCharGen->setPlayerFatigue (value); } } @@ -372,11 +372,11 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicS MWMechanics::DynamicStat WindowManager::getValue(const std::string& id) { if(id == "HBar") - return playerHealth; + return layerHealth; else if (id == "MBar") - return playerMagicka; + return mPlayerMagicka; else if (id == "FBar") - return playerFatigue; + return mPlayerFatigue; } #endif @@ -384,9 +384,9 @@ void WindowManager::setValue (const std::string& id, const std::string& value) { mStatsWindow->setValue (id, value); if (id=="name") - playerName = value; + mPlayerName = value; else if (id=="race") - playerRaceId = value; + mPlayerRaceId = value; } void WindowManager::setValue (const std::string& id, int value) @@ -396,16 +396,16 @@ void WindowManager::setValue (const std::string& id, int value) void WindowManager::setPlayerClass (const ESM::Class &class_) { - playerClass = class_; - mStatsWindow->setValue("class", playerClass.name); + mPlayerClass = class_; + mStatsWindow->setValue("class", mPlayerClass.name); } void WindowManager::configureSkills (const SkillList& major, const SkillList& minor) { mStatsWindow->configureSkills (major, minor); mCharGen->configureSkills(major, minor); - playerMajorSkills = major; - playerMinorSkills = minor; + mPlayerMajorSkills = major; + mPlayerMinorSkills = minor; } void WindowManager::setReputation (int reputation) @@ -429,7 +429,7 @@ void WindowManager::removeDialog(OEngine::GUI::Layout*dialog) if (!dialog) return; dialog->setVisible(false); - garbageDialogs.push_back(dialog); + mGarbageDialogs.push_back(dialog); } void WindowManager::messageBox (const std::string& message, const std::vector& buttons) @@ -484,12 +484,12 @@ void WindowManager::onFrame (float frameDuration) mStatsWindow->onFrame(); - hud->onFrame(frameDuration); + mHud->onFrame(frameDuration); mDialogueWindow->checkReferenceAvailable(); mTradeWindow->checkReferenceAvailable(); mContainerWindow->checkReferenceAvailable(); - console->checkReferenceAvailable(); + mConsole->checkReferenceAvailable(); } const ESMS::ESMStore& WindowManager::getStore() const @@ -513,56 +513,56 @@ void WindowManager::changeCell(MWWorld::Ptr::CellStore* cell) name = getGameSettingString("sDefaultCellname", "Wilderness"); } - map->setCellName( name ); - hud->setCellName( name ); + mMap->setCellName( name ); + mHud->setCellName( name ); - map->setCellPrefix("Cell"); - hud->setCellPrefix("Cell"); - map->setActiveCell( cell->cell->data.gridX, cell->cell->data.gridY ); - hud->setActiveCell( cell->cell->data.gridX, cell->cell->data.gridY ); + mMap->setCellPrefix("Cell"); + mHud->setCellPrefix("Cell"); + mMap->setActiveCell( cell->cell->data.gridX, cell->cell->data.gridY ); + mHud->setActiveCell( cell->cell->data.gridX, cell->cell->data.gridY ); } else { - map->setCellName( cell->cell->name ); - hud->setCellName( cell->cell->name ); - map->setCellPrefix( cell->cell->name ); - hud->setCellPrefix( cell->cell->name ); + mMap->setCellName( cell->cell->name ); + mHud->setCellName( cell->cell->name ); + mMap->setCellPrefix( cell->cell->name ); + mHud->setCellPrefix( cell->cell->name ); } } void WindowManager::setInteriorMapTexture(const int x, const int y) { - map->setActiveCell(x,y, true); - hud->setActiveCell(x,y, true); + mMap->setActiveCell(x,y, true); + mHud->setActiveCell(x,y, true); } void WindowManager::setPlayerPos(const float x, const float y) { - map->setPlayerPos(x,y); - hud->setPlayerPos(x,y); + mMap->setPlayerPos(x,y); + mHud->setPlayerPos(x,y); } void WindowManager::setPlayerDir(const float x, const float y) { - map->setPlayerDir(x,y); - hud->setPlayerDir(x,y); + mMap->setPlayerDir(x,y); + mHud->setPlayerDir(x,y); } void WindowManager::setHMSVisibility(bool visible) { - hud->setBottomLeftVisibility(visible, hud->weapBox->getVisible(), hud->spellBox->getVisible()); + mHud->setBottomLeftVisibility(visible, mHud->mWeapBox->getVisible(), mHud->mSpellBox->getVisible()); } void WindowManager::setMinimapVisibility(bool visible) { - hud->setBottomRightVisibility(hud->effectBox->getVisible(), visible); + mHud->setBottomRightVisibility(mHud->mEffectBox->getVisible(), visible); } void WindowManager::toggleFogOfWar() { - map->toggleFogOfWar(); - hud->toggleFogOfWar(); + mMap->toggleFogOfWar(); + mHud->toggleFogOfWar(); } void WindowManager::setFocusObject(const MWWorld::Ptr& focus) @@ -587,13 +587,13 @@ bool WindowManager::getFullHelp() const void WindowManager::setWeaponVisibility(bool visible) { - hud->setBottomLeftVisibility(hud->health->getVisible(), visible, hud->spellBox->getVisible()); + mHud->setBottomLeftVisibility(mHud->health->getVisible(), visible, mHud->mSpellBox->getVisible()); } void WindowManager::setSpellVisibility(bool visible) { - hud->setBottomLeftVisibility(hud->health->getVisible(), hud->weapBox->getVisible(), visible); - hud->setBottomRightVisibility(visible, hud->minimapBox->getVisible()); + mHud->setBottomLeftVisibility(mHud->health->getVisible(), mHud->mWeapBox->getVisible(), visible); + mHud->setBottomRightVisibility(visible, mHud->mMinimapBox->getVisible()); } void WindowManager::setMouseVisible(bool visible) @@ -618,7 +618,7 @@ void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _r void WindowManager::processChangedSettings(const Settings::CategorySettingVector& changed) { - hud->setFpsLevel(Settings::Manager::getInt("fps", "HUD")); + mHud->setFpsLevel(Settings::Manager::getInt("fps", "HUD")); mToolTips->setDelay(Settings::Manager::getFloat("tooltip delay", "GUI")); bool changeRes = false; @@ -637,8 +637,8 @@ void WindowManager::processChangedSettings(const Settings::CategorySettingVector { int x = Settings::Manager::getInt("resolution x", "Video"); int y = Settings::Manager::getInt("resolution y", "Video"); - hud->onResChange(x, y); - console->onResChange(x, y); + mHud->onResChange(x, y); + mConsole->onResChange(x, y); mSettingsWindow->center(); mAlchemyWindow->center(); mScrollWindow->center(); @@ -649,7 +649,7 @@ void WindowManager::processChangedSettings(const Settings::CategorySettingVector void WindowManager::pushGuiMode(GuiMode mode) { - if (mode==GM_Inventory && allowed==GW_None) + if (mode==GM_Inventory && mAllowed==GW_None) return; mGuiModes.push_back(mode); @@ -690,32 +690,32 @@ void WindowManager::removeGuiMode(GuiMode mode) void WindowManager::setSelectedSpell(const std::string& spellId, int successChancePercent) { - hud->setSelectedSpell(spellId, successChancePercent); + mHud->setSelectedSpell(spellId, successChancePercent); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellId); mSpellWindow->setTitle(spell->name); } void WindowManager::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) { - hud->setSelectedEnchantItem(item, chargePercent); + mHud->setSelectedEnchantItem(item, chargePercent); mSpellWindow->setTitle(MWWorld::Class::get(item).getName(item)); } void WindowManager::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent) { - hud->setSelectedWeapon(item, durabilityPercent); + mHud->setSelectedWeapon(item, durabilityPercent); mInventoryWindow->setTitle(MWWorld::Class::get(item).getName(item)); } void WindowManager::unsetSelectedSpell() { - hud->unsetSelectedSpell(); + mHud->unsetSelectedSpell(); mSpellWindow->setTitle("#{sNone}"); } void WindowManager::unsetSelectedWeapon() { - hud->unsetSelectedWeapon(); + mHud->unsetSelectedWeapon(); mInventoryWindow->setTitle("#{sSkillHandtohand}"); } @@ -738,5 +738,5 @@ void WindowManager::getMousePosition(float &x, float &y) bool WindowManager::getWorldMouseOver() { - return hud->getWorldMouseOver(); + return mHud->getWorldMouseOver(); } diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 03ffa6b59..adab79942 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -10,10 +10,6 @@ this class. **/ -#include -#include -#include - #include "MyGUI_UString.h" #include @@ -123,27 +119,27 @@ namespace MWGui void toggleVisible(GuiWindow wnd) { - shown = (shown & wnd) ? (GuiWindow) (shown & ~wnd) : (GuiWindow) (shown | wnd); + mShown = (mShown & wnd) ? (GuiWindow) (mShown & ~wnd) : (GuiWindow) (mShown | wnd); updateVisible(); } // Disallow all inventory mode windows void disallowAll() { - allowed = GW_None; + mAllowed = GW_None; updateVisible(); } // Allow one or more windows void allow(GuiWindow wnd) { - allowed = (GuiWindow)(allowed | wnd); + mAllowed = (GuiWindow)(mAllowed | wnd); updateVisible(); } bool isAllowed(GuiWindow wnd) const { - return allowed & wnd; + return mAllowed & wnd; } MWGui::DialogueWindow* getDialogueWindow() {return mDialogueWindow;} @@ -155,9 +151,9 @@ namespace MWGui MWGui::ConfirmationDialog* getConfirmationDialog() {return mConfirmationDialog;} MWGui::TradeWindow* getTradeWindow() {return mTradeWindow;} MWGui::SpellWindow* getSpellWindow() {return mSpellWindow;} - MWGui::Console* getConsole() {return console;} + MWGui::Console* getConsole() {return mConsole;} - MyGUI::Gui* getGui() const { return gui; } + MyGUI::Gui* getGui() const { return mGui; } void wmUpdateFps(float fps, unsigned int triangleCount, unsigned int batchCount) { @@ -223,10 +219,10 @@ namespace MWGui void onFrame (float frameDuration); - std::map > getPlayerSkillValues() { return playerSkillValues; } - std::map > getPlayerAttributeValues() { return playerAttributes; } - SkillList getPlayerMinorSkills() { return playerMinorSkills; } - SkillList getPlayerMajorSkills() { return playerMajorSkills; } + std::map > getPlayerSkillValues() { return mPlayerSkillValues; } + std::map > getPlayerAttributeValues() { return mPlayerAttributes; } + SkillList getPlayerMinorSkills() { return mPlayerMinorSkills; } + SkillList getPlayerMajorSkills() { return mPlayerMajorSkills; } /** * Fetches a GMST string from the store, if there is no setting with the given @@ -243,13 +239,13 @@ namespace MWGui private: OEngine::GUI::MyGUIManager *mGuiManager; - HUD *hud; - MapWindow *map; - MainMenu *menu; + HUD *mHud; + MapWindow *mMap; + MainMenu *mMenu; ToolTips *mToolTips; StatsWindow *mStatsWindow; MessageBoxManager *mMessageBoxManager; - Console *console; + Console *mConsole; JournalWindow* mJournal; DialogueWindow *mDialogueWindow; ContainerWindow *mContainerWindow; @@ -267,33 +263,33 @@ namespace MWGui CharacterCreation* mCharGen; // Various stats about player as needed by window manager - ESM::Class playerClass; - std::string playerName; - std::string playerRaceId; - std::map > playerAttributes; - SkillList playerMajorSkills, playerMinorSkills; - std::map > playerSkillValues; - MWMechanics::DynamicStat playerHealth, playerMagicka, playerFatigue; + ESM::Class mPlayerClass; + std::string mPlayerName; + std::string mPlayerRaceId; + std::map > mPlayerAttributes; + SkillList mPlayerMajorSkills, mPlayerMinorSkills; + std::map > mPlayerSkillValues; + MWMechanics::DynamicStat mPlayerHealth, mPlayerMagicka, mPlayerFatigue; - MyGUI::Gui *gui; // Gui + MyGUI::Gui *mGui; // Gui std::vector mGuiModes; - std::vector garbageDialogs; + std::vector mGarbageDialogs; void cleanupGarbage(); - GuiWindow shown; // Currently shown windows in inventory mode + GuiWindow mShown; // Currently shown windows in inventory mode /* Currently ALLOWED windows in inventory mode. This is used at the start of the game, when windows are enabled one by one through script commands. You can manipulate this through using allow() and disableAll(). */ - GuiWindow allowed; + GuiWindow mAllowed; void updateVisible(); // Update visibility of all windows based on mode, shown and allowed settings - int showFPSLevel; + int mShowFPSLevel; float mFPS; unsigned int mTriangleCount; unsigned int mBatchCount; diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 63cd3baa1..4b0b2e572 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -1,18 +1,8 @@ #ifndef _GAME_RENDER_ACTORS_H #define _GAME_RENDER_ACTORS_H -#include -#include - -#include -#include "components/nifogre/ogre_nif_loader.hpp" - -#include "../mwworld/refdata.hpp" -#include "../mwworld/actiontalk.hpp" - #include "npcanimation.hpp" #include "creatureanimation.hpp" -#include namespace MWWorld { diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index f0a6ab683..549dbf6b2 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -6,25 +6,26 @@ #include #include -namespace MWRender{ - std::map Animation::mUniqueIDs; +namespace MWRender +{ + std::map Animation::sUniqueIDs; Animation::Animation(OEngine::Render::OgreRenderer& _rend) - : insert(NULL) + : mInsert(NULL) , mRend(_rend) - , vecRotPos() - , time(0.0f) - , startTime(0.0f) - , stopTime(0.0f) - , animate(0) - , rindexI() - , tindexI() - , shapeNumber(0) - , shapeIndexI() - , shapes(NULL) - , transformations(NULL) - , textmappings(NULL) - , base(NULL) + , mVecRotPos() + , mTime(0.0f) + , mStartTime(0.0f) + , mStopTime(0.0f) + , mAnimate(0) + , mRindexI() + , mTindexI() + , mShapeNumber(0) + , mShapeIndexI() + , mShapes(NULL) + , mTransformations(NULL) + , mTextmappings(NULL) + , mBase(NULL) { } @@ -32,178 +33,191 @@ namespace MWRender{ { } - std::string Animation::getUniqueID(std::string mesh){ - int counter; - std::string copy = mesh; - std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower); - if(mUniqueIDs.find(copy) == mUniqueIDs.end()){ - counter = mUniqueIDs[copy] = 0; - } - else{ - mUniqueIDs[copy] = mUniqueIDs[copy] + 1; - counter = mUniqueIDs[copy]; - } + std::string Animation::getUniqueID(std::string mesh) + { + int counter; + std::string copy = mesh; + std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower); + + if(sUniqueIDs.find(copy) == sUniqueIDs.end()) + { + counter = sUniqueIDs[copy] = 0; + } + else + { + sUniqueIDs[copy] = sUniqueIDs[copy] + 1; + counter = sUniqueIDs[copy]; + } - std::stringstream out; - if(counter > 99 && counter < 1000) - out << "0"; - else if(counter > 9) - out << "00"; - else - out << "000"; - out << counter; - return out.str(); -} - void Animation::startScript(std::string groupname, int mode, int loops){ - //If groupname is recognized set animate to true - //Set the start time and stop time - //How many times to loop - if(groupname == "all"){ - animate = loops; - time = startTime; + std::stringstream out; + + if(counter > 99 && counter < 1000) + out << "0"; + else if(counter > 9) + out << "00"; + else + out << "000"; + out << counter; + + return out.str(); + } + + void Animation::startScript(std::string groupname, int mode, int loops) + { + //If groupname is recognized set animate to true + //Set the start time and stop time + //How many times to loop + if(groupname == "all") + { + mAnimate = loops; + mTime = mStartTime; } - else if(textmappings){ + else if(mTextmappings) + { std::string startName = groupname + ": loop start"; std::string stopName = groupname + ": loop stop"; bool first = false; - if(loops > 1){ + if(loops > 1) + { startName = groupname + ": loop start"; 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()); - std::transform(current2.begin(), current2.end(), current2.begin(), ::tolower); + for(std::map::iterator iter = mTextmappings->begin(); iter != mTextmappings->end(); iter++) + { - if(current == startName){ - startTime = iter->second; - animate = loops; - time = startTime; - first = true; - } - if(current2 == stopName){ - stopTime = iter->second; - if(first) - break; - } + 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()); + std::transform(current2.begin(), current2.end(), current2.begin(), ::tolower); + + if(current == startName) + { + mStartTime = iter->second; + mAnimate = loops; + mTime = mStartTime; + first = true; + } + if(current2 == stopName) + { + mStopTime = iter->second; + if(first) + break; + } } } - if(!first){ + 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()); - std::transform(current2.begin(), current2.end(), current2.begin(), ::tolower); + for(std::map::iterator iter = mTextmappings->begin(); iter != mTextmappings->end(); iter++) + { - if(current == startName){ - startTime = iter->second; - animate = loops; - time = startTime; - first = true; - } - if(current2 == stopName){ - stopTime = iter->second; - if(first) - break; + 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()); + std::transform(current2.begin(), current2.end(), current2.begin(), ::tolower); + + if(current == startName) + { + mStartTime = iter->second; + mAnimate = loops; + mTime = mStartTime; + first = true; + } + if(current2 == stopName) + { + mStopTime = iter->second; + if(first) + break; + } } } - } - } - - } - void Animation::stopScript(){ - animate = 0; } - - void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ - shapeNumber = 0; + + void Animation::stopScript() + { + mAnimate = 0; + } + + void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel) + { + mShapeNumber = 0; if (allshapes == NULL || creaturemodel == NULL || skel == NULL) - { return; - } std::vector::iterator allshapesiter; - for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) + for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) + { + //std::map vecPosRot; - { - //std::map vecPosRot; + Nif::NiTriShapeCopy& copy = *allshapesiter; + std::vector* allvertices = ©.vertices; - Nif::NiTriShapeCopy& copy = *allshapesiter; - std::vector* allvertices = ©.vertices; + //std::set vertices; + //std::set normals; + //std::vector boneinfovector = copy.boneinfo; + 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::set vertices; - //std::set normals; - //std::vector boneinfovector = copy.boneinfo; - std::map >* verticesToChange = ©.vertsToWeights; + std::vector initialVertices = copy.morph.getInitialVertices(); + //Each shape has multiple indices + if(initialVertices.size() ) + { + if(copy.vertices.size() == initialVertices.size()) + { + //Create if it doesn't already exist + if(mShapeIndexI.size() == static_cast (mShapeNumber)) + { + std::vector vec; + mShapeIndexI.push_back(vec); + } + if(mTime >= copy.morph.getStartTime() && mTime <= copy.morph.getStopTime()) + { + float x; + for (unsigned int i = 0; i < copy.morph.getAdditionalVertices().size(); i++) + { + int j = 0; + if(mShapeIndexI[mShapeNumber].size() <= i) + mShapeIndexI[mShapeNumber].push_back(0); + + if(timeIndex(mTime,copy.morph.getRelevantTimes()[i],(mShapeIndexI[mShapeNumber])[i], j, x)) + { + int indexI = (mShapeIndexI[mShapeNumber])[i]; + std::vector relevantData = (copy.morph.getRelevantData()[i]); + float v1 = relevantData[indexI].x; + float v2 = relevantData[j].x; + float t = v1 + (v2 - v1) * x; + + if ( t < 0 ) + t = 0; + if ( t > 1 ) + t = 1; + if( t != 0 && initialVertices.size() == copy.morph.getAdditionalVertices()[i].size()) + for (unsigned int v = 0; v < initialVertices.size(); v++) + initialVertices[v] += ((copy.morph.getAdditionalVertices()[i])[v]) * t; + } - //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 - if(initialVertices.size() ) - { - - if(copy.vertices.size() == initialVertices.size()) - { - //Create if it doesn't already exist - if(shapeIndexI.size() == static_cast (shapeNumber)) - { - std::vector vec; - shapeIndexI.push_back(vec); - } - if(time >= copy.morph.getStartTime() && time <= copy.morph.getStopTime()){ - float x; - for (unsigned int i = 0; i < copy.morph.getAdditionalVertices().size(); i++){ - int j = 0; - if(shapeIndexI[shapeNumber].size() <= i) - shapeIndexI[shapeNumber].push_back(0); - - - if(timeIndex(time,copy.morph.getRelevantTimes()[i],(shapeIndexI[shapeNumber])[i], j, x)){ - int indexI = (shapeIndexI[shapeNumber])[i]; - std::vector relevantData = (copy.morph.getRelevantData()[i]); - float v1 = relevantData[indexI].x; - float v2 = relevantData[j].x; - float t = v1 + (v2 - v1) * x; - if ( t < 0 ) t = 0; - if ( t > 1 ) t = 1; - if( t != 0 && initialVertices.size() == copy.morph.getAdditionalVertices()[i].size()) - { - for (unsigned int v = 0; v < initialVertices.size(); v++){ - initialVertices[v] += ((copy.morph.getAdditionalVertices()[i])[v]) * t; - } - } - - } - - - - } - - allvertices = &initialVertices; } - shapeNumber++; - } - } + + allvertices = &initialVertices; + } + mShapeNumber++; + } + } - if(verticesToChange->size() > 0){ + if(verticesToChange->size() > 0) + { for(std::map >::iterator iter = verticesToChange->begin(); iter != verticesToChange->end(); iter++) @@ -214,26 +228,25 @@ namespace MWRender{ Nif::NiSkinData::BoneInfoCopy* boneinfocopy = &(allshapesiter->boneinfo[inds[0].boneinfocopyindex]); Ogre::Bone *bonePtr = 0; - - Ogre::Vector3 vecPos; Ogre::Quaternion vecRot; - std::map::iterator result = vecRotPos.find(boneinfocopy); + std::map::iterator result = mVecRotPos.find(boneinfocopy); - if(result == vecRotPos.end()){ + if(result == mVecRotPos.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; + PosAndRot both; + both.vecPos = vecPos; + both.vecRot = vecRot; + mVecRotPos[boneinfocopy] = both; } - else{ + else + { PosAndRot both = result->second; vecPos = both.vecPos; vecRot = both.vecRot; @@ -241,263 +254,249 @@ namespace MWRender{ Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight; - - - for(std::size_t 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); + result = mVecRotPos.find(boneinfocopy); - - if(result == vecRotPos.end()){ + if(result == mVecRotPos.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; + PosAndRot both; + both.vecPos = vecPos; + both.vecRot = vecRot; + mVecRotPos[boneinfocopy] = both; } - else{ - PosAndRot both = result->second; - vecPos = both.vecPos; - vecRot = both.vecRot; + else + { + PosAndRot both = result->second; + vecPos = both.vecPos; + 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; + 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); + Ogre::Quaternion shaperot = copy.trafo.rotation; + Ogre::Vector3 shapetrans = copy.trafo.trans; + float shapescale = copy.trafo.scale; + std::vector boneSequence = copy.boneSequence; + + Ogre::Vector3 transmult; + Ogre::Quaternion rotmult; + float scale; + if(boneSequence.size() > 0) + { + std::vector::iterator boneSequenceIter = boneSequence.begin(); + if(skel->hasBone(*boneSequenceIter)) + { + Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); + + transmult = bonePtr->getPosition(); + rotmult = bonePtr->getOrientation(); + scale = bonePtr->getScale().x; + boneSequenceIter++; + + for(; boneSequenceIter != boneSequence.end(); boneSequenceIter++) + { + if(skel->hasBone(*boneSequenceIter)) + { + Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); + // Computes C = B + AxC*scale + transmult = transmult + rotmult * bonePtr->getPosition(); + rotmult = rotmult * bonePtr->getOrientation(); + scale = scale * bonePtr->getScale().x; + } + //std::cout << "Bone:" << *boneSequenceIter << " "; + } + transmult = transmult + rotmult * shapetrans; + rotmult = rotmult * shaperot; + scale = shapescale * scale; - - - - } - else - { - //Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(copy.bonename); - Ogre::Quaternion shaperot = copy.trafo.rotation; - Ogre::Vector3 shapetrans = copy.trafo.trans; - float shapescale = copy.trafo.scale; - std::vector boneSequence = copy.boneSequence; - - Ogre::Vector3 transmult; - Ogre::Quaternion rotmult; - float scale; - if(boneSequence.size() > 0){ - std::vector::iterator boneSequenceIter = boneSequence.begin(); - if(skel->hasBone(*boneSequenceIter)){ - Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); - - - - - transmult = bonePtr->getPosition(); - rotmult = bonePtr->getOrientation(); - scale = bonePtr->getScale().x; - boneSequenceIter++; - - for(; boneSequenceIter != boneSequence.end(); boneSequenceIter++) - { - if(skel->hasBone(*boneSequenceIter)){ - Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); - // Computes C = B + AxC*scale - transmult = transmult + rotmult * bonePtr->getPosition(); - rotmult = rotmult * bonePtr->getOrientation(); - scale = scale * bonePtr->getScale().x; - } - //std::cout << "Bone:" << *boneSequenceIter << " "; - } - transmult = transmult + rotmult * shapetrans; - rotmult = rotmult * shaperot; - scale = shapescale * scale; - - //std::cout << "Position: " << transmult << "Rotation: " << rotmult << "\n"; - } + //std::cout << "Position: " << transmult << "Rotation: " << rotmult << "\n"; } - else - { - transmult = shapetrans; - 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; - *addr = current.x; - *(addr+1) = current.y; - *(addr + 2) = current.z; - - }/* - for(int i = 0; i < allnormals.size(); i++){ - Ogre::Vector3 current =rotmult * allnormals[i]; - Ogre::Real* addr = pRealNormal + i * 3; - *addr = current.x; - *(addr+1) = current.y; - *(addr + 2) = current.z; - - }*/ + } + else + { + transmult = shapetrans; + rotmult = shaperot; + scale = shapescale; + } - } - vbuf->unlock(); + // 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; + *addr = current.x; + *(addr+1) = current.y; + *(addr + 2) = current.z; + + }/* + for(int i = 0; i < allnormals.size(); i++){ + Ogre::Vector3 current =rotmult * allnormals[i]; + Ogre::Real* addr = pRealNormal + i * 3; + *addr = current.x; + *(addr+1) = current.y; + *(addr + 2) = current.z; + + }*/ + } + vbuf->unlock(); + } + } - bool Animation::timeIndex( float time, const std::vector & times, int & i, int & j, float & x ){ - int count; - if ( (count = times.size()) > 0 ) - { - if ( time <= times[0] ) - { - i = j = 0; - x = 0.0; - return true; - } - if ( time >= times[count - 1] ) - { - i = j = count - 1; - x = 0.0; - return true; - } - - if ( i < 0 || i >= count ) - i = 0; - - float tI = times[i]; - if ( time > tI ) - { - j = i + 1; - float tJ; - while ( time >= ( tJ = times[j]) ) - { - i = j++; - tI = tJ; - } - x = ( time - tI ) / ( tJ - tI ); - return true; - } - else if ( time < tI ) - { - j = i - 1; - float tJ; - while ( time <= ( tJ = times[j] ) ) - { - i = j--; - tI = tJ; - } - x = ( time - tI ) / ( tJ - tI ); - return true; - } - else - { - j = i; - x = 0.0; - return true; - } - } - else - return false; - -} + + bool Animation::timeIndex( float time, const std::vector & times, int & i, int & j, float & x ) + { + int count; + if ( (count = times.size()) > 0 ) + { + if ( time <= times[0] ) + { + i = j = 0; + x = 0.0; + return true; + } + if ( time >= times[count - 1] ) + { + i = j = count - 1; + x = 0.0; + return true; + } - void Animation::handleAnimationTransforms(){ + if ( i < 0 || i >= count ) + i = 0; + float tI = times[i]; + if ( time > tI ) + { + j = i + 1; + float tJ; + while ( time >= ( tJ = times[j]) ) + { + i = j++; + tI = tJ; + } + x = ( time - tI ) / ( tJ - tI ); + return true; + } + else if ( time < tI ) + { + j = i - 1; + float tJ; + while ( time <= ( tJ = times[j] ) ) + { + i = j--; + tI = tJ; + } + x = ( time - tI ) / ( tJ - tI ); + return true; + } + else + { + j = i; + x = 0.0; + return true; + } + } + else + return false; - Ogre::SkeletonInstance* skel = base->getSkeleton(); + } + void Animation::handleAnimationTransforms() + { + Ogre::SkeletonInstance* skel = mBase->getSkeleton(); - Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3)); //This is a trick + 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(); - - base->getAllAnimationStates()->_notifyDirty(); - //base->_updateAnimation(); - //base->_notifyMoved(); - - - - - std::vector::iterator iter; - int slot = 0; - if(transformations){ - for(iter = transformations->begin(); iter != transformations->end(); iter++){ - if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) - { - slot++; - continue; - } - - float x; - float x2; - - const std::vector & quats = iter->getQuat(); - - const std::vector & ttime = iter->gettTime(); - + //skel->_notifyManualBonesDirty(); - const std::vector & rtime = iter->getrTime(); - int rindexJ = rindexI[slot]; + mBase->getAllAnimationStates()->_notifyDirty(); + //mBase->_updateAnimation(); + //mBase->_notifyMoved(); - timeIndex(time, rtime, rindexI[slot], rindexJ, x2); - int tindexJ = tindexI[slot]; - - - const std::vector & translist1 = iter->getTranslist1(); - - timeIndex(time, ttime, tindexI[slot], tindexJ, x); + std::vector::iterator iter; + int slot = 0; + if(mTransformations) + { + for(iter = mTransformations->begin(); iter != mTransformations->end(); iter++) + { + if(mTime < iter->getStartTime() || mTime < mStartTime || mTime > iter->getStopTime()) + { + slot++; + continue; + } - Ogre::Vector3 t; - Ogre::Quaternion r; + float x; + float x2; - bool bTrans = translist1.size() > 0; + const std::vector & quats = iter->getQuat(); + const std::vector & ttime = iter->gettTime(); + const std::vector & rtime = iter->getrTime(); + int rindexJ = mRindexI[slot]; - bool bQuats = quats.size() > 0; + timeIndex(mTime, rtime, mRindexI[slot], rindexJ, x2); + int tindexJ = mTindexI[slot]; - if(skel->hasBone(iter->getBonename())){ - Ogre::Bone* bone = skel->getBone(iter->getBonename()); - if(bTrans){ - Ogre::Vector3 v1 = translist1[tindexI[slot]]; - Ogre::Vector3 v2 = translist1[tindexJ]; - t = (v1 + (v2 - v1) * x); - bone->setPosition(t); + const std::vector & translist1 = iter->getTranslist1(); - } - if(bQuats){ - r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); - bone->setOrientation(r); - } + timeIndex(mTime, ttime, mTindexI[slot], tindexJ, x); + Ogre::Vector3 t; + Ogre::Quaternion r; + bool bTrans = translist1.size() > 0; + bool bQuats = quats.size() > 0; + if(skel->hasBone(iter->getBonename())) + { + Ogre::Bone* bone = skel->getBone(iter->getBonename()); + + if(bTrans) + { + Ogre::Vector3 v1 = translist1[mTindexI[slot]]; + Ogre::Vector3 v2 = translist1[tindexJ]; + t = (v1 + (v2 - v1) * x); + bone->setPosition(t); - } + } + + if(bQuats) + { + r = Ogre::Quaternion::Slerp(x2, quats[mRindexI[slot]], quats[rindexJ], true); + bone->setOrientation(r); + } + } - slot++; + slot++; + } + skel->_updateTransforms(); + mBase->getAllAnimationStates()->_notifyDirty(); + } } - skel->_updateTransforms(); - base->getAllAnimationStates()->_notifyDirty(); -} -} } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 4ab60cff4..30f8acb64 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -1,17 +1,13 @@ #ifndef _GAME_RENDER_ANIMATION_H #define _GAME_RENDER_ANIMATION_H -#include + #include -#include "../mwworld/refdata.hpp" -#include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" #include -#include #include - namespace MWRender{ struct PosAndRot{ @@ -22,36 +18,30 @@ struct PosAndRot{ class Animation{ protected: - Ogre::SceneNode* insert; + Ogre::SceneNode* mInsert; OEngine::Render::OgreRenderer &mRend; - std::map vecRotPos; - static std::map mUniqueIDs; - - - - - - float time; - float startTime; - float stopTime; - int animate; - //Represents a rotation index for each bone - std::vectorrindexI; + std::map mVecRotPos; + static std::map sUniqueIDs; + + float mTime; + float mStartTime; + float mStopTime; + int mAnimate; + //Represents a rotation index for each bone + std::vectormRindexI; //Represents a translation index for each bone - std::vectortindexI; - - //Only shapes with morphing data will use a shape number - int shapeNumber; - std::vector > shapeIndexI; + std::vectormTindexI; - //Ogre::SkeletonInstance* skel; - std::vector* shapes; //All the NiTriShapeData for a creature + //Only shapes with morphing data will use a shape number + int mShapeNumber; + std::vector > mShapeIndexI; + //Ogre::SkeletonInstance* skel; + std::vector* mShapes; //All the NiTriShapeData for a creature - - std::vector* transformations; - std::map* textmappings; - Ogre::Entity* base; + std::vector* mTransformations; + std::map* mTextmappings; + Ogre::Entity* mBase; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); void handleAnimationTransforms(); bool timeIndex( float time, const std::vector & times, int & i, int & j, float & x ); @@ -63,7 +53,6 @@ class Animation{ void startScript(std::string groupname, int mode, int loops); void stopScript(); - virtual ~Animation(); }; diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index e1fa7868c..20037a773 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -12,26 +12,28 @@ using namespace Ogre; using namespace NifOgre; namespace MWRender{ -CreatureAnimation::~CreatureAnimation(){ +CreatureAnimation::~CreatureAnimation() +{ +} -} -CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend): Animation(_rend){ - insert = ptr.getRefData().getBaseNode(); - MWWorld::LiveCellRef *ref = - ptr.get(); +CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend): Animation(_rend) +{ + mInsert = ptr.getRefData().getBaseNode(); + MWWorld::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); - if(!ref->base->model.empty()){ + if(!ref->base->model.empty()) + { const std::string &mesh = "meshes\\" + ref->base->model; std::string meshNumbered = mesh + getUniqueID(mesh) + ">|"; NifOgre::NIFLoader::load(meshNumbered); - base = mRend.getScene()->createEntity(meshNumbered); - base->setVisibilityFlags(RV_Actors); + mBase = mRend.getScene()->createEntity(meshNumbered); + mBase->setVisibilityFlags(RV_Actors); bool transparent = false; - for (unsigned int i=0; igetNumSubEntities(); ++i) + for (unsigned int i=0; i < mBase->getNumSubEntities(); ++i) { - Ogre::MaterialPtr mat = base->getSubEntity(i)->getMaterial(); + Ogre::MaterialPtr mat = mBase->getSubEntity(i)->getMaterial(); Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator(); while (techIt.hasMoreElements()) { @@ -46,46 +48,51 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::O } } } - base->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main); + mBase->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main); std::string meshZero = mesh + "0000>|"; - if((transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero))){ - - for(std::size_t init = 0; init < transformations->size(); init++){ - rindexI.push_back(0); - tindexI.push_back(0); - } - stopTime = transformations->begin()->getStopTime(); - startTime = transformations->begin()->getStartTime(); - shapes = (NIFLoader::getSingletonPtr())->getShapes(meshZero); + if((mTransformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero))) + { + for(std::size_t init = 0; init < mTransformations->size(); init++) + { + mRindexI.push_back(0); + mTindexI.push_back(0); + } + mStopTime = mTransformations->begin()->getStopTime(); + mStartTime = mTransformations->begin()->getStartTime(); + mShapes = (NIFLoader::getSingletonPtr())->getShapes(meshZero); } - textmappings = NIFLoader::getSingletonPtr()->getTextIndices(meshZero); - insert->attachObject(base); + mTextmappings = NIFLoader::getSingletonPtr()->getTextIndices(meshZero); + mInsert->attachObject(mBase); } } -void CreatureAnimation::runAnimation(float timepassed){ - vecRotPos.clear(); - if(animate > 0){ - //Add the amount of time passed to time +void CreatureAnimation::runAnimation(float timepassed) +{ + mVecRotPos.clear(); + if(mAnimate > 0) + { + //Add the amount of time passed to time - //Handle the animation transforms dependent on time + //Handle the animation transforms dependent on time - //Handle the shapes dependent on animation transforms - time += timepassed; - if(time >= stopTime){ - animate--; + //Handle the shapes dependent on animation transforms + mTime += timepassed; + if(mTime >= mStopTime) + { + mAnimate--; //std::cout << "Stopping the animation\n"; - if(animate == 0) - time = stopTime; + if(mAnimate == 0) + mTime = mStopTime; else - time = startTime + (time - stopTime); + mTime = mStartTime + (mTime - mStopTime); } handleAnimationTransforms(); - handleShapes(shapes, base, base->getSkeleton()); + handleShapes(mShapes, mBase, mBase->getSkeleton()); - } + } } + } diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index f50b7904b..b3c9d3ddd 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -2,11 +2,7 @@ #define _GAME_RENDER_CREATUREANIMATION_H #include "animation.hpp" -#include - -#include "../mwworld/refdata.hpp" -#include "../mwworld/ptr.hpp" #include "components/nifogre/ogre_nif_loader.hpp" @@ -17,8 +13,7 @@ class CreatureAnimation: public Animation{ public: virtual ~CreatureAnimation(); CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend); - virtual void runAnimation(float timepassed); - + virtual void runAnimation(float timepassed); }; } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index fa88b7277..ef075b12b 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -14,118 +14,117 @@ using namespace Ogre; using namespace NifOgre; namespace MWRender{ -NpcAnimation::~NpcAnimation(){ - +NpcAnimation::~NpcAnimation() +{ } -NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend, MWWorld::InventoryStore& _inv): Animation(_rend), mStateID(-1), inv(_inv), timeToChange(0), - robe(inv.end()), helmet(inv.end()), shirt(inv.end()), - cuirass(inv.end()), greaves(inv.end()), - leftpauldron(inv.end()), rightpauldron(inv.end()), - boots(inv.end()), - leftglove(inv.end()), rightglove(inv.end()), skirtiter(inv.end()), - pants(inv.end()), +NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend, MWWorld::InventoryStore& _inv): Animation(_rend), mStateID(-1), mInv(_inv), timeToChange(0), + robe(mInv.end()), helmet(mInv.end()), shirt(mInv.end()), + cuirass(mInv.end()), greaves(mInv.end()), + leftpauldron(mInv.end()), rightpauldron(mInv.end()), + boots(mInv.end()), + leftglove(mInv.end()), rightglove(mInv.end()), skirtiter(mInv.end()), + pants(mInv.end()), lclavicle(0), - rclavicle(0), - rupperArm(0), - lupperArm(0), - rUpperLeg(0), - lUpperLeg(0), - lForearm(0), - rForearm(0), - lWrist(0), - rWrist(0), - rKnee(0), - lKnee(0), - neck(0), - rAnkle(0), - lAnkle(0), - groin(0), - lfoot(0), - rfoot(0) - { - MWWorld::LiveCellRef *ref = - ptr.get(); - Ogre::Entity* blank = 0; - std::vector* blankshape = 0; - zero = std::make_pair(blank, blankshape); - chest = std::make_pair(blank, blankshape); - tail = std::make_pair(blank, blankshape); - lFreeFoot = std::make_pair(blank, blankshape); - rFreeFoot = std::make_pair(blank, blankshape); - rhand = std::make_pair(blank, blankshape); - lhand = std::make_pair(blank, blankshape); - skirt = std::make_pair(blank, blankshape); - for (int init = 0; init < 27; init++){ - partslots[init] = -1; //each slot is empty - partpriorities[init] = 0; - } - - - //Part selection on last character of the file string - // " Tri Chest - // * Tri Tail - // : Tri Left Foot - // < Tri Right Foot - // > Tri Left Hand - // ? Tri Right Hand - // | Normal - - //Mirroring Parts on second to last character - //suffix == '*' - // vector = Ogre::Vector3(-1,1,1); - // suffix == '?' - // vector = Ogre::Vector3(1,-1,1); - // suffix == '<' - // vector = Ogre::Vector3(1,1,-1); - - - std::string hairID = ref->base->hair; - std::string headID = ref->base->head; - headModel = "meshes\\" + - MWBase::Environment::get().getWorld()->getStore().bodyParts.find(headID)->model; - - hairModel = "meshes\\" + - MWBase::Environment::get().getWorld()->getStore().bodyParts.find(hairID)->model; - npcName = ref->base->name; - - //ESMStore::Races r = - const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().races.find(ref->base->race); - - - bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); - char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); - isFemale = tolower(secondtolast) == 'f'; - std::transform(bodyRaceID.begin(), bodyRaceID.end(), bodyRaceID.begin(), ::tolower); - isBeast = 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"; - if(isBeast) - smodel = "meshes\\base_animkna.nif"; - - insert = ptr.getRefData().getBaseNode(); - assert(insert); - - NifOgre::NIFLoader::load(smodel); - - base = mRend.getScene()->createEntity(smodel); - - base->setVisibilityFlags(RV_Actors); + rclavicle(0), + rupperArm(0), + lupperArm(0), + rUpperLeg(0), + lUpperLeg(0), + lForearm(0), + rForearm(0), + lWrist(0), + rWrist(0), + rKnee(0), + lKnee(0), + neck(0), + rAnkle(0), + lAnkle(0), + groin(0), + lfoot(0), + rfoot(0) +{ + MWWorld::LiveCellRef *ref = ptr.get(); + Ogre::Entity* blank = 0; + std::vector* blankshape = 0; + mZero = std::make_pair(blank, blankshape); + mChest = std::make_pair(blank, blankshape); + mTail = std::make_pair(blank, blankshape); + mLFreeFoot = std::make_pair(blank, blankshape); + mRFreeFoot = std::make_pair(blank, blankshape); + mRhand = std::make_pair(blank, blankshape); + mLhand = std::make_pair(blank, blankshape); + mSkirt = std::make_pair(blank, blankshape); + for (int init = 0; init < 27; init++) + { + mPartslots[init] = -1; //each slot is empty + mPartPriorities[init] = 0; + } + + + //Part selection on last character of the file string + // " Tri Chest + // * Tri Tail + // : Tri Left Foot + // < Tri Right Foot + // > Tri Left Hand + // ? Tri Right Hand + // | Normal + + //Mirroring Parts on second to last character + //suffix == '*' + // vector = Ogre::Vector3(-1,1,1); + // suffix == '?' + // vector = Ogre::Vector3(1,-1,1); + // suffix == '<' + // vector = Ogre::Vector3(1,1,-1); + + + std::string hairID = ref->base->hair; + std::string headID = ref->base->head; + headModel = "meshes\\" + + MWBase::Environment::get().getWorld()->getStore().bodyParts.find(headID)->model; + + hairModel = "meshes\\" + + MWBase::Environment::get().getWorld()->getStore().bodyParts.find(hairID)->model; + npcName = ref->base->name; + + //ESMStore::Races r = + const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().races.find(ref->base->race); + + + bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); + char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); + isFemale = tolower(secondtolast) == 'f'; + std::transform(bodyRaceID.begin(), bodyRaceID.end(), bodyRaceID.begin(), ::tolower); + isBeast = 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"; + if(isBeast) + smodel = "meshes\\base_animkna.nif"; + + mInsert = ptr.getRefData().getBaseNode(); + assert(mInsert); + + NifOgre::NIFLoader::load(smodel); + + mBase = mRend.getScene()->createEntity(smodel); + + mBase->setVisibilityFlags(RV_Actors); bool transparent = false; - for (unsigned int i=0; igetNumSubEntities(); ++i) + for (unsigned int i=0; igetNumSubEntities(); ++i) { - Ogre::MaterialPtr mat = base->getSubEntity(i)->getMaterial(); + Ogre::MaterialPtr mat = mBase->getSubEntity(i)->getMaterial(); Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator(); while (techIt.hasMoreElements()) { @@ -140,625 +139,694 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRendere } } } - base->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main); + mBase->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main); - base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones + mBase->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones //stay in the same place when we skipanim, or open a gui window + if((mTransformations = (NIFLoader::getSingletonPtr())->getAnim(smodel))) + { - if((transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel))){ - - for(unsigned int init = 0; init < transformations->size(); init++){ - rindexI.push_back(0); - tindexI.push_back(0); - } + for(unsigned int init = 0; init < mTransformations->size(); init++) + { + mRindexI.push_back(0); + mTindexI.push_back(0); + } - stopTime = transformations->begin()->getStopTime(); - startTime = transformations->begin()->getStartTime(); + mStopTime = mTransformations->begin()->getStopTime(); + mStartTime = mTransformations->begin()->getStartTime(); } - textmappings = NIFLoader::getSingletonPtr()->getTextIndices(smodel); - insert->attachObject(base); + mTextmappings = NIFLoader::getSingletonPtr()->getTextIndices(smodel); + mInsert->attachObject(mBase); - if(isFemale) - insert->scale(race->data.height.female, race->data.height.female, race->data.height.female); - else - insert->scale(race->data.height.male, race->data.height.male, race->data.height.male); - updateParts(); + if(isFemale) + mInsert->scale(race->data.height.female, race->data.height.female, race->data.height.female); + else + mInsert->scale(race->data.height.male, race->data.height.male, race->data.height.male); + updateParts(); } -void NpcAnimation::updateParts(){ +void NpcAnimation::updateParts() +{ + + bool apparelChanged = false; - bool apparelChanged = false; + //mInv.getSlot(MWWorld::InventoryStore::Slot_Robe); + if(robe != mInv.getSlot(MWWorld::InventoryStore::Slot_Robe)) + { + //A robe was added or removed + removePartGroup(MWWorld::InventoryStore::Slot_Robe); + robe = mInv.getSlot(MWWorld::InventoryStore::Slot_Robe); + apparelChanged = true; + } + if(skirtiter != mInv.getSlot(MWWorld::InventoryStore::Slot_Skirt)) + { + //A robe was added or removed + removePartGroup(MWWorld::InventoryStore::Slot_Skirt); + skirtiter = mInv.getSlot(MWWorld::InventoryStore::Slot_Skirt); + apparelChanged = true; + } + if(helmet != mInv.getSlot(MWWorld::InventoryStore::Slot_Helmet)) + { + apparelChanged = true; + helmet = mInv.getSlot(MWWorld::InventoryStore::Slot_Helmet); + removePartGroup(MWWorld::InventoryStore::Slot_Helmet); + + } + if(cuirass != mInv.getSlot(MWWorld::InventoryStore::Slot_Cuirass)) + { + cuirass = mInv.getSlot(MWWorld::InventoryStore::Slot_Cuirass); + removePartGroup(MWWorld::InventoryStore::Slot_Cuirass); + apparelChanged = true; - //inv.getSlot(MWWorld::InventoryStore::Slot_Robe); - if(robe != inv.getSlot(MWWorld::InventoryStore::Slot_Robe)){ - //A robe was added or removed - removePartGroup(MWWorld::InventoryStore::Slot_Robe); - robe = inv.getSlot(MWWorld::InventoryStore::Slot_Robe); - apparelChanged = true; - } - if(skirtiter != inv.getSlot(MWWorld::InventoryStore::Slot_Skirt)){ - //A robe was added or removed - removePartGroup(MWWorld::InventoryStore::Slot_Skirt); - skirtiter = inv.getSlot(MWWorld::InventoryStore::Slot_Skirt); - apparelChanged = true; - } - if(helmet != inv.getSlot(MWWorld::InventoryStore::Slot_Helmet)){ - apparelChanged = true; - helmet = inv.getSlot(MWWorld::InventoryStore::Slot_Helmet); - removePartGroup(MWWorld::InventoryStore::Slot_Helmet); + } + if(greaves != mInv.getSlot(MWWorld::InventoryStore::Slot_Greaves)) + { + greaves = mInv.getSlot(MWWorld::InventoryStore::Slot_Greaves); + removePartGroup(MWWorld::InventoryStore::Slot_Greaves); + apparelChanged = true; + } + if(leftpauldron != mInv.getSlot(MWWorld::InventoryStore::Slot_LeftPauldron)) + { + leftpauldron = mInv.getSlot(MWWorld::InventoryStore::Slot_LeftPauldron); + removePartGroup(MWWorld::InventoryStore::Slot_LeftPauldron); + apparelChanged = true; - } - if(cuirass != inv.getSlot(MWWorld::InventoryStore::Slot_Cuirass)){ - cuirass = inv.getSlot(MWWorld::InventoryStore::Slot_Cuirass); - removePartGroup(MWWorld::InventoryStore::Slot_Cuirass); - apparelChanged = true; + } + if(rightpauldron != mInv.getSlot(MWWorld::InventoryStore::Slot_RightPauldron)) + { + rightpauldron = mInv.getSlot(MWWorld::InventoryStore::Slot_RightPauldron); + removePartGroup(MWWorld::InventoryStore::Slot_RightPauldron); + apparelChanged = true; - } - if(greaves != inv.getSlot(MWWorld::InventoryStore::Slot_Greaves)){ - greaves = inv.getSlot(MWWorld::InventoryStore::Slot_Greaves); - removePartGroup(MWWorld::InventoryStore::Slot_Greaves); - apparelChanged = true; - } - if(leftpauldron != inv.getSlot(MWWorld::InventoryStore::Slot_LeftPauldron)){ - leftpauldron = inv.getSlot(MWWorld::InventoryStore::Slot_LeftPauldron); - removePartGroup(MWWorld::InventoryStore::Slot_LeftPauldron); - apparelChanged = true; + } + if(!isBeast && boots != mInv.getSlot(MWWorld::InventoryStore::Slot_Boots)) + { + boots = mInv.getSlot(MWWorld::InventoryStore::Slot_Boots); + removePartGroup(MWWorld::InventoryStore::Slot_Boots); + apparelChanged = true; - } - if(rightpauldron != inv.getSlot(MWWorld::InventoryStore::Slot_RightPauldron)){ - rightpauldron = inv.getSlot(MWWorld::InventoryStore::Slot_RightPauldron); - removePartGroup(MWWorld::InventoryStore::Slot_RightPauldron); - apparelChanged = true; + } + if(leftglove != mInv.getSlot(MWWorld::InventoryStore::Slot_LeftGauntlet)) + { + leftglove = mInv.getSlot(MWWorld::InventoryStore::Slot_LeftGauntlet); + removePartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet); + apparelChanged = true; - } - if(!isBeast && boots != inv.getSlot(MWWorld::InventoryStore::Slot_Boots)){ - boots = inv.getSlot(MWWorld::InventoryStore::Slot_Boots); - removePartGroup(MWWorld::InventoryStore::Slot_Boots); - apparelChanged = true; + } + if(rightglove != mInv.getSlot(MWWorld::InventoryStore::Slot_RightGauntlet)) + { + rightglove = mInv.getSlot(MWWorld::InventoryStore::Slot_RightGauntlet); + removePartGroup(MWWorld::InventoryStore::Slot_RightGauntlet); + apparelChanged = true; - } - if(leftglove != inv.getSlot(MWWorld::InventoryStore::Slot_LeftGauntlet)){ - leftglove = inv.getSlot(MWWorld::InventoryStore::Slot_LeftGauntlet); - removePartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet); - apparelChanged = true; + } + if(shirt != mInv.getSlot(MWWorld::InventoryStore::Slot_Shirt)) + { + shirt = mInv.getSlot(MWWorld::InventoryStore::Slot_Shirt); + removePartGroup(MWWorld::InventoryStore::Slot_Shirt); + apparelChanged = true; - } - if(rightglove != inv.getSlot(MWWorld::InventoryStore::Slot_RightGauntlet)){ - rightglove = inv.getSlot(MWWorld::InventoryStore::Slot_RightGauntlet); - removePartGroup(MWWorld::InventoryStore::Slot_RightGauntlet); - apparelChanged = true; + } + if(pants != mInv.getSlot(MWWorld::InventoryStore::Slot_Pants)) + { + pants = mInv.getSlot(MWWorld::InventoryStore::Slot_Pants); + removePartGroup(MWWorld::InventoryStore::Slot_Pants); + apparelChanged = true; + } + if(apparelChanged) + { + + if(robe != mInv.end()) + { + MWWorld::Ptr ptr = *robe; + + const ESM::Clothing *clothes = (ptr.get())->base; + std::vector parts = clothes->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_Robe, 5, parts); + reserveIndividualPart(ESM::PRT_Groin, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_Skirt, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_RLeg, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_RUpperarm, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_LUpperarm, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_RKnee, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_LKnee, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_RForearm, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_LForearm, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_RPauldron, MWWorld::InventoryStore::Slot_Robe, 5); + reserveIndividualPart(ESM::PRT_LPauldron, MWWorld::InventoryStore::Slot_Robe, 5); + } + if(skirtiter != mInv.end()) + { + MWWorld::Ptr ptr = *skirtiter; + + const ESM::Clothing *clothes = (ptr.get())->base; + std::vector parts = clothes->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_Skirt, 4, parts); + reserveIndividualPart(ESM::PRT_Groin, MWWorld::InventoryStore::Slot_Skirt, 4); + reserveIndividualPart(ESM::PRT_RLeg, MWWorld::InventoryStore::Slot_Skirt, 4); + reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Skirt, 4); } - if(shirt != inv.getSlot(MWWorld::InventoryStore::Slot_Shirt)){ - shirt = inv.getSlot(MWWorld::InventoryStore::Slot_Shirt); - removePartGroup(MWWorld::InventoryStore::Slot_Shirt); - apparelChanged = true; + + if(helmet != mInv.end()) + { + removeIndividualPart(ESM::PRT_Hair); + const ESM::Armor *armor = (helmet->get())->base; + std::vector parts = armor->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_Helmet, 3, parts); } - if(pants != inv.getSlot(MWWorld::InventoryStore::Slot_Pants)){ - pants = inv.getSlot(MWWorld::InventoryStore::Slot_Pants); - removePartGroup(MWWorld::InventoryStore::Slot_Pants); - apparelChanged = true; + if(cuirass != mInv.end()) + { + const ESM::Armor *armor = (cuirass->get())->base; + std::vector parts = armor->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_Cuirass, 3, parts); } + if(greaves != mInv.end()) + { + const ESM::Armor *armor = (greaves->get())->base; + std::vector parts = armor->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_Greaves, 3, parts); + } - if(apparelChanged){ + if(leftpauldron != mInv.end()) + { + const ESM::Armor *armor = (leftpauldron->get())->base; + std::vector parts = armor->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_LeftPauldron, 3, parts); - if(robe != inv.end()) - { - MWWorld::Ptr ptr = *robe; + } + if(rightpauldron != mInv.end()) + { + const ESM::Armor *armor = (rightpauldron->get())->base; + std::vector parts = armor->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_RightPauldron, 3, parts); - const ESM::Clothing *clothes = (ptr.get())->base; - std::vector parts = clothes->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Robe, 5, parts); - reserveIndividualPart(ESM::PRT_Groin, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_Skirt, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_RLeg, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_RUpperarm, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_LUpperarm, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_RKnee, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_LKnee, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_RForearm, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_LForearm, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_RPauldron, MWWorld::InventoryStore::Slot_Robe, 5); - reserveIndividualPart(ESM::PRT_LPauldron, MWWorld::InventoryStore::Slot_Robe, 5); - } - if(skirtiter != inv.end()) + } + if(!isBeast && boots != mInv.end()) + { + if(boots->getTypeName() == typeid(ESM::Clothing).name()) { - MWWorld::Ptr ptr = *skirtiter; - - const ESM::Clothing *clothes = (ptr.get())->base; + const ESM::Clothing *clothes = (boots->get())->base; std::vector parts = clothes->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Skirt, 4, parts); - reserveIndividualPart(ESM::PRT_Groin, MWWorld::InventoryStore::Slot_Skirt, 4); - reserveIndividualPart(ESM::PRT_RLeg, MWWorld::InventoryStore::Slot_Skirt, 4); - reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Skirt, 4); + addPartGroup(MWWorld::InventoryStore::Slot_Boots, 2, parts); } - - if(helmet != inv.end()){ - removeIndividualPart(ESM::PRT_Hair); - const ESM::Armor *armor = (helmet->get())->base; + else if(boots->getTypeName() == typeid(ESM::Armor).name()) + { + const ESM::Armor *armor = (boots->get())->base; std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Helmet, 3, parts); - + addPartGroup(MWWorld::InventoryStore::Slot_Boots, 3, parts); } - if(cuirass != inv.end()){ - const ESM::Armor *armor = (cuirass->get())->base; - std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Cuirass, 3, parts); + } + if(leftglove != mInv.end()){ + if(leftglove->getTypeName() == typeid(ESM::Clothing).name()) + { + const ESM::Clothing *clothes = (leftglove->get())->base; + std::vector parts = clothes->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 2, parts); } - if(greaves != inv.end()){ - const ESM::Armor *armor = (greaves->get())->base; + else + { + const ESM::Armor *armor = (leftglove->get())->base; std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Greaves, 3, parts); - + addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 3, parts); } - if(leftpauldron != inv.end()){ - const ESM::Armor *armor = (leftpauldron->get())->base; - std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_LeftPauldron, 3, parts); - + } + if(rightglove != mInv.end()){ + if(rightglove->getTypeName() == typeid(ESM::Clothing).name()) + { + const ESM::Clothing *clothes = (rightglove->get())->base; + std::vector parts = clothes->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 2, parts); } - if(rightpauldron != inv.end()){ - const ESM::Armor *armor = (rightpauldron->get())->base; + else + { + const ESM::Armor *armor = (rightglove->get())->base; std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_RightPauldron, 3, parts); - + addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 3, parts); } - if(!isBeast && boots != inv.end()){ - if(boots->getTypeName() == typeid(ESM::Clothing).name()){ - const ESM::Clothing *clothes = (boots->get())->base; - std::vector parts = clothes->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Boots, 2, parts); - } - else if(boots->getTypeName() == typeid(ESM::Armor).name()) - { - const ESM::Armor *armor = (boots->get())->base; - std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Boots, 3, parts); - } - } - if(leftglove != inv.end()){ - if(leftglove->getTypeName() == typeid(ESM::Clothing).name()){ - const ESM::Clothing *clothes = (leftglove->get())->base; - std::vector parts = clothes->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 2, parts); - } - else - { - const ESM::Armor *armor = (leftglove->get())->base; - std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 3, parts); - } - - } - if(rightglove != inv.end()){ - if(rightglove->getTypeName() == typeid(ESM::Clothing).name()){ - const ESM::Clothing *clothes = (rightglove->get())->base; - std::vector parts = clothes->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 2, parts); - } - else - { - const ESM::Armor *armor = (rightglove->get())->base; - std::vector parts = armor->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 3, parts); - } - - } - - if(shirt != inv.end()){ - const ESM::Clothing *clothes = (shirt->get())->base; - std::vector parts = clothes->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Shirt, 2, parts); - } - if(pants != inv.end()){ - const ESM::Clothing *clothes = (pants->get())->base; - std::vector parts = clothes->parts.parts; - addPartGroup(MWWorld::InventoryStore::Slot_Pants, 2, parts); - } } - if(partpriorities[ESM::PRT_Head] < 1){ - addOrReplaceIndividualPart(ESM::PRT_Head, -1,1,headModel); - } - if(partpriorities[ESM::PRT_Hair] < 1 && partpriorities[ESM::PRT_Head] <= 1){ - addOrReplaceIndividualPart(ESM::PRT_Hair, -1,1,hairModel); - } - if(partpriorities[ESM::PRT_Neck] < 1){ - const ESM::BodyPart *neckPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "neck"); - if(neckPart) - addOrReplaceIndividualPart(ESM::PRT_Neck, -1,1,"meshes\\" + neckPart->model); - } - if(partpriorities[ESM::PRT_Cuirass] < 1){ - const ESM::BodyPart *chestPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "chest"); - if(chestPart) - addOrReplaceIndividualPart(ESM::PRT_Cuirass, -1,1,"meshes\\" + chestPart->model); - } - - if(partpriorities[ESM::PRT_Groin] < 1){ - const ESM::BodyPart *groinPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "groin"); - if(groinPart) - addOrReplaceIndividualPart(ESM::PRT_Groin, -1,1,"meshes\\" + groinPart->model); - } - if(partpriorities[ESM::PRT_RHand] < 1){ - const ESM::BodyPart *handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hand"); - if(!handPart) - handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hands"); - if(handPart) - addOrReplaceIndividualPart(ESM::PRT_RHand, -1,1,"meshes\\" + handPart->model); - } - if(partpriorities[ESM::PRT_LHand] < 1){ - const ESM::BodyPart *handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hand"); - if(!handPart) - handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hands"); - if(handPart) - addOrReplaceIndividualPart(ESM::PRT_LHand, -1,1,"meshes\\" + handPart->model); - } - - if(partpriorities[ESM::PRT_RWrist] < 1){ - const ESM::BodyPart *wristPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "wrist"); - if(wristPart) - addOrReplaceIndividualPart(ESM::PRT_RWrist, -1,1,"meshes\\" + wristPart->model); - } - if(partpriorities[ESM::PRT_LWrist] < 1){ - const ESM::BodyPart *wristPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "wrist"); - if(wristPart) - addOrReplaceIndividualPart(ESM::PRT_LWrist, -1,1,"meshes\\" + wristPart->model); - } - if(partpriorities[ESM::PRT_RForearm] < 1){ - const ESM::BodyPart *forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "forearm"); - if(bodyRaceID == "b_n_argonian_f_") - forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search ("b_n_argonian_m_forearm"); - if(forearmPart) - addOrReplaceIndividualPart(ESM::PRT_RForearm, -1,1,"meshes\\" + forearmPart->model); - } - if(partpriorities[ESM::PRT_LForearm] < 1){ - const ESM::BodyPart *forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "forearm"); - if(bodyRaceID == "b_n_argonian_f_") - forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search ("b_n_argonian_m_forearm"); - if(forearmPart) - addOrReplaceIndividualPart(ESM::PRT_LForearm, -1,1,"meshes\\" + forearmPart->model); - } - if(partpriorities[ESM::PRT_RUpperarm] < 1){ - const ESM::BodyPart *armPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper arm"); - if(armPart) - addOrReplaceIndividualPart(ESM::PRT_RUpperarm, -1,1,"meshes\\" + armPart->model); - } - if(partpriorities[ESM::PRT_LUpperarm] < 1){ - const ESM::BodyPart *armPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper arm"); - if(armPart) - addOrReplaceIndividualPart(ESM::PRT_LUpperarm, -1,1,"meshes\\" + armPart->model); - } - if(partpriorities[ESM::PRT_RFoot] < 1){ - const ESM::BodyPart *footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "foot"); - if(isBeast && !footPart) - footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "feet"); - if(footPart) - addOrReplaceIndividualPart(ESM::PRT_RFoot, -1,1,"meshes\\" + footPart->model); - } - if(partpriorities[ESM::PRT_LFoot] < 1){ - const ESM::BodyPart *footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "foot"); - if(isBeast && !footPart) - footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "feet"); - if(footPart) - addOrReplaceIndividualPart(ESM::PRT_LFoot, -1,1,"meshes\\" + footPart->model); - } - if(partpriorities[ESM::PRT_RAnkle] < 1){ - const ESM::BodyPart *anklePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "ankle"); - if(anklePart) - addOrReplaceIndividualPart(ESM::PRT_RAnkle, -1,1,"meshes\\" + anklePart->model); - } - if(partpriorities[ESM::PRT_LAnkle] < 1){ - const ESM::BodyPart *anklePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "ankle"); - if(anklePart) - addOrReplaceIndividualPart(ESM::PRT_LAnkle, -1,1,"meshes\\" + anklePart->model); - } - if(partpriorities[ESM::PRT_RKnee] < 1){ - const ESM::BodyPart *kneePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "knee"); - if(kneePart) - addOrReplaceIndividualPart(ESM::PRT_RKnee, -1,1,"meshes\\" + kneePart->model); - } - if(partpriorities[ESM::PRT_LKnee] < 1){ - const ESM::BodyPart *kneePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "knee"); - if(kneePart) - addOrReplaceIndividualPart(ESM::PRT_LKnee, -1,1,"meshes\\" + kneePart->model); - } - if(partpriorities[ESM::PRT_RLeg] < 1){ - const ESM::BodyPart *legPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper leg"); - if(legPart) - addOrReplaceIndividualPart(ESM::PRT_RLeg, -1,1,"meshes\\" + legPart->model); - } - if(partpriorities[ESM::PRT_LLeg] < 1){ - const ESM::BodyPart *legPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper leg"); - if(legPart) - addOrReplaceIndividualPart(ESM::PRT_LLeg, -1,1,"meshes\\" + legPart->model); - } - if(partpriorities[ESM::PRT_Tail] < 1){ - const ESM::BodyPart *tailPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "tail"); - if(tailPart) - addOrReplaceIndividualPart(ESM::PRT_Tail, -1,1,"meshes\\" + tailPart->model); - } - - - - + if(shirt != mInv.end()) + { + const ESM::Clothing *clothes = (shirt->get())->base; + std::vector parts = clothes->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_Shirt, 2, parts); + } + if(pants != mInv.end()) + { + const ESM::Clothing *clothes = (pants->get())->base; + std::vector parts = clothes->parts.parts; + addPartGroup(MWWorld::InventoryStore::Slot_Pants, 2, parts); + } + } + if(mPartPriorities[ESM::PRT_Head] < 1) + { + addOrReplaceIndividualPart(ESM::PRT_Head, -1,1,headModel); + } + if(mPartPriorities[ESM::PRT_Hair] < 1 && mPartPriorities[ESM::PRT_Head] <= 1) + { + addOrReplaceIndividualPart(ESM::PRT_Hair, -1,1,hairModel); + } + if(mPartPriorities[ESM::PRT_Neck] < 1) + { + const ESM::BodyPart *neckPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "neck"); + if(neckPart) + addOrReplaceIndividualPart(ESM::PRT_Neck, -1,1,"meshes\\" + neckPart->model); + } + if(mPartPriorities[ESM::PRT_Cuirass] < 1) + { + const ESM::BodyPart *chestPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "chest"); + if(chestPart) + addOrReplaceIndividualPart(ESM::PRT_Cuirass, -1,1,"meshes\\" + chestPart->model); + } + if(mPartPriorities[ESM::PRT_Groin] < 1) + { + const ESM::BodyPart *groinPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "groin"); + if(groinPart) + addOrReplaceIndividualPart(ESM::PRT_Groin, -1,1,"meshes\\" + groinPart->model); + } + if(mPartPriorities[ESM::PRT_RHand] < 1) + { + const ESM::BodyPart *handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hand"); + if(!handPart) + handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hands"); + if(handPart) + addOrReplaceIndividualPart(ESM::PRT_RHand, -1,1,"meshes\\" + handPart->model); + } + if(mPartPriorities[ESM::PRT_LHand] < 1) + { + const ESM::BodyPart *handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hand"); + if(!handPart) + handPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "hands"); + if(handPart) + addOrReplaceIndividualPart(ESM::PRT_LHand, -1,1,"meshes\\" + handPart->model); + } + if(mPartPriorities[ESM::PRT_RWrist] < 1) + { + const ESM::BodyPart *wristPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "wrist"); + if(wristPart) + addOrReplaceIndividualPart(ESM::PRT_RWrist, -1,1,"meshes\\" + wristPart->model); + } + if(mPartPriorities[ESM::PRT_LWrist] < 1) + { + const ESM::BodyPart *wristPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "wrist"); + if(wristPart) + addOrReplaceIndividualPart(ESM::PRT_LWrist, -1,1,"meshes\\" + wristPart->model); + } + if(mPartPriorities[ESM::PRT_RForearm] < 1) + { + const ESM::BodyPart *forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "forearm"); + if(bodyRaceID == "b_n_argonian_f_") + forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search ("b_n_argonian_m_forearm"); + if(forearmPart) + addOrReplaceIndividualPart(ESM::PRT_RForearm, -1,1,"meshes\\" + forearmPart->model); + } + if(mPartPriorities[ESM::PRT_LForearm] < 1) + { + const ESM::BodyPart *forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "forearm"); + if(bodyRaceID == "b_n_argonian_f_") + forearmPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search ("b_n_argonian_m_forearm"); + if(forearmPart) + addOrReplaceIndividualPart(ESM::PRT_LForearm, -1,1,"meshes\\" + forearmPart->model); + } + if(mPartPriorities[ESM::PRT_RUpperarm] < 1) + { + const ESM::BodyPart *armPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper arm"); + if(armPart) + addOrReplaceIndividualPart(ESM::PRT_RUpperarm, -1,1,"meshes\\" + armPart->model); + } + if(mPartPriorities[ESM::PRT_LUpperarm] < 1) + { + const ESM::BodyPart *armPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper arm"); + if(armPart) + addOrReplaceIndividualPart(ESM::PRT_LUpperarm, -1,1,"meshes\\" + armPart->model); + } + if(mPartPriorities[ESM::PRT_RFoot] < 1) + { + const ESM::BodyPart *footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "foot"); + if(isBeast && !footPart) + footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "feet"); + if(footPart) + addOrReplaceIndividualPart(ESM::PRT_RFoot, -1,1,"meshes\\" + footPart->model); + } + if(mPartPriorities[ESM::PRT_LFoot] < 1) + { + const ESM::BodyPart *footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "foot"); + if(isBeast && !footPart) + footPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "feet"); + if(footPart) + addOrReplaceIndividualPart(ESM::PRT_LFoot, -1,1,"meshes\\" + footPart->model); + } + if(mPartPriorities[ESM::PRT_RAnkle] < 1) + { + const ESM::BodyPart *anklePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "ankle"); + if(anklePart) + addOrReplaceIndividualPart(ESM::PRT_RAnkle, -1,1,"meshes\\" + anklePart->model); + } + if(mPartPriorities[ESM::PRT_LAnkle] < 1) + { + const ESM::BodyPart *anklePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "ankle"); + if(anklePart) + addOrReplaceIndividualPart(ESM::PRT_LAnkle, -1,1,"meshes\\" + anklePart->model); + } + if(mPartPriorities[ESM::PRT_RKnee] < 1) + { + const ESM::BodyPart *kneePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "knee"); + if(kneePart) + addOrReplaceIndividualPart(ESM::PRT_RKnee, -1,1,"meshes\\" + kneePart->model); + } + if(mPartPriorities[ESM::PRT_LKnee] < 1) + { + const ESM::BodyPart *kneePart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "knee"); + if(kneePart) + addOrReplaceIndividualPart(ESM::PRT_LKnee, -1,1,"meshes\\" + kneePart->model); + } + if(mPartPriorities[ESM::PRT_RLeg] < 1) + { + const ESM::BodyPart *legPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper leg"); + if(legPart) + addOrReplaceIndividualPart(ESM::PRT_RLeg, -1,1,"meshes\\" + legPart->model); + } + if(mPartPriorities[ESM::PRT_LLeg] < 1) + { + const ESM::BodyPart *legPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "upper leg"); + if(legPart) + addOrReplaceIndividualPart(ESM::PRT_LLeg, -1,1,"meshes\\" + legPart->model); + } + if(mPartPriorities[ESM::PRT_Tail] < 1) + { + const ESM::BodyPart *tailPart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (bodyRaceID + "tail"); + if(tailPart) + addOrReplaceIndividualPart(ESM::PRT_Tail, -1,1,"meshes\\" + tailPart->model); + } } -Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ - +Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename) +{ NIFLoader::load(mesh); Ogre::Entity* part = mRend.getScene()->createEntity(mesh); part->setVisibilityFlags(RV_Actors); - base->attachObjectToBone(bonename, part); + mBase->attachObjectToBone(bonename, part); return part; } -void NpcAnimation::insertFootPart(int type, const std::string &mesh){ +void NpcAnimation::insertFootPart(int type, const std::string &mesh) +{ std::string meshAndSuffix = mesh; if(type == ESM::PRT_LFoot) meshAndSuffix += "*|"; NIFLoader::load(meshAndSuffix); Ogre::Entity* part = mRend.getScene()->createEntity(meshAndSuffix); std::vector* shape = ((NIFLoader::getSingletonPtr())->getShapes(meshAndSuffix)); - if(shape == 0){ - if(type == ESM::PRT_LFoot){ - base->attachObjectToBone("Left Foot", part); + if(shape == 0) + { + if(type == ESM::PRT_LFoot) + { + mBase->attachObjectToBone("Left Foot", part); lfoot = part; } - else if (type == ESM::PRT_RFoot){ - base->attachObjectToBone("Right Foot", part); + else if (type == ESM::PRT_RFoot) + { + mBase->attachObjectToBone("Right Foot", part); rfoot = part; } } - else{ + else + { if(type == ESM::PRT_LFoot) - lFreeFoot = insertFreePart(mesh, "::"); + mLFreeFoot = insertFreePart(mesh, "::"); else if (type == ESM::PRT_RFoot) - rFreeFoot = insertFreePart(mesh, ":<"); + mRFreeFoot = insertFreePart(mesh, ":<"); } - - } -std::pair*> NpcAnimation::insertFreePart(const std::string &mesh, const std::string& suffix){ +std::pair*> NpcAnimation::insertFreePart(const std::string &mesh, const std::string& suffix) +{ std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; NIFLoader::load(meshNumbered); Ogre::Entity* part = mRend.getScene()->createEntity(meshNumbered); part->setVisibilityFlags(RV_Actors); - insert->attachObject(part); + mInsert->attachObject(part); std::vector* shape = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix)); - if(shape){ - handleShapes(shape, part, base->getSkeleton()); - } - std::pair*> pair = std::make_pair(part, shape); - return pair; + if(shape) + handleShapes(shape, part, mBase->getSkeleton()); + std::pair*> pair = std::make_pair(part, shape); + return pair; } +void NpcAnimation::runAnimation(float timepassed) +{ + if(timeToChange > .2){ + timeToChange = 0; + updateParts(); + } - -void NpcAnimation::runAnimation(float timepassed){ - - if(timeToChange > .2){ - - timeToChange = 0; - - updateParts(); - } - - timeToChange += timepassed; + timeToChange += timepassed; //1. Add the amount of time passed to time - //2. Handle the animation transforms dependent on time + //2. Handle the animation transforms dependent on time - //3. Handle the shapes dependent on animation transforms - if(animate > 0){ - time += timepassed; + //3. Handle the shapes dependent on animation transforms + if(mAnimate > 0) + { + mTime += timepassed; - if(time > stopTime){ - animate--; + if(mTime > mStopTime) + { + mAnimate--; - if(animate == 0) - time = stopTime; + if(mAnimate == 0) + mTime = mStopTime; else - time = startTime + (time - stopTime); + mTime = mStartTime + (mTime - mStopTime); } - handleAnimationTransforms(); + handleAnimationTransforms(); + mVecRotPos.clear(); - vecRotPos.clear(); + if(mLFreeFoot.first) + handleShapes(mLFreeFoot.second, mLFreeFoot.first, mBase->getSkeleton()); + if(mRFreeFoot.first) + handleShapes(mRFreeFoot.second, mRFreeFoot.first, mBase->getSkeleton()); + if(mChest.first) + handleShapes(mChest.second, mChest.first, mBase->getSkeleton()); + if(mTail.first) + handleShapes(mTail.second, mTail.first, mBase->getSkeleton()); + if(mSkirt.first) + handleShapes(mSkirt.second, mSkirt.first, mBase->getSkeleton()); + if(mLhand.first) + handleShapes(mLhand.second, mLhand.first, mBase->getSkeleton()); + if(mRhand.first) + handleShapes(mRhand.second, mRhand.first, mBase->getSkeleton()); - if(lFreeFoot.first) - handleShapes(lFreeFoot.second, lFreeFoot.first, base->getSkeleton()); - if(rFreeFoot.first) - handleShapes(rFreeFoot.second, rFreeFoot.first, base->getSkeleton()); - - if(chest.first) - handleShapes(chest.second, chest.first, base->getSkeleton()); - if(tail.first) - handleShapes(tail.second, tail.first, base->getSkeleton()); - if(skirt.first){ - handleShapes(skirt.second, skirt.first, base->getSkeleton()); - } - if(lhand.first) - handleShapes(lhand.second, lhand.first, base->getSkeleton()); - if(rhand.first) - handleShapes(rhand.second, rhand.first, base->getSkeleton()); - -} + } } void NpcAnimation::removeIndividualPart(int type){ - partpriorities[type] = 0; - partslots[type] = -1; + mPartPriorities[type] = 0; + mPartslots[type] = -1; - if(type == ESM::PRT_Head && head){ //0 - base->detachObjectFromBone(head); + if(type == ESM::PRT_Head && head) //0 + { + mBase->detachObjectFromBone(head); head = 0; } - else if(type == ESM::PRT_Hair && hair){//1 - base->detachObjectFromBone(hair); + else if(type == ESM::PRT_Hair && hair) //1 + { + mBase->detachObjectFromBone(hair); hair = 0; } - else if(type == ESM::PRT_Neck && neck){//2 - base->detachObjectFromBone(neck); + else if(type == ESM::PRT_Neck && neck) //2 + { + mBase->detachObjectFromBone(neck); neck = 0; } - else if(type == ESM::PRT_Cuirass && chest.first){//3 - insert->detachObject(chest.first); - chest = zero; + else if(type == ESM::PRT_Cuirass && mChest.first) //3 + { + mInsert->detachObject(mChest.first); + mChest = mZero; } - else if(type == ESM::PRT_Groin && groin){//4 - base->detachObjectFromBone(groin); + else if(type == ESM::PRT_Groin && groin) //4 + { + mBase->detachObjectFromBone(groin); groin = 0; } - else if(type == ESM::PRT_Skirt && skirt.first){//5 - insert->detachObject(skirt.first); - skirt = zero; + else if(type == ESM::PRT_Skirt && mSkirt.first) //5 + { + mInsert->detachObject(mSkirt.first); + mSkirt = mZero; } - else if(type == ESM::PRT_RHand && rhand.first){//6 - insert->detachObject(rhand.first); - rhand = zero; + else if(type == ESM::PRT_RHand && mRhand.first) //6 + { + mInsert->detachObject(mRhand.first); + mRhand = mZero; } - else if(type == ESM::PRT_LHand && lhand.first){//7 - insert->detachObject(lhand.first); - lhand = zero; + else if(type == ESM::PRT_LHand && mLhand.first) //7 + { + mInsert->detachObject(mLhand.first); + mLhand = mZero; } - else if(type == ESM::PRT_RWrist && rWrist){//8 - base->detachObjectFromBone(rWrist); + else if(type == ESM::PRT_RWrist && rWrist) //8 + { + mBase->detachObjectFromBone(rWrist); rWrist = 0; } - else if(type == ESM::PRT_LWrist && lWrist){//9 - base->detachObjectFromBone(lWrist); + else if(type == ESM::PRT_LWrist && lWrist) //9 + { + mBase->detachObjectFromBone(lWrist); lWrist = 0; } - else if(type == ESM::PRT_Shield){//10 + else if(type == ESM::PRT_Shield) //10 + { } - else if(type == ESM::PRT_RForearm && rForearm){//11 - base->detachObjectFromBone(rForearm); + else if(type == ESM::PRT_RForearm && rForearm) //11 + { + mBase->detachObjectFromBone(rForearm); rForearm = 0; } - else if(type == ESM::PRT_LForearm && lForearm){//12 - base->detachObjectFromBone(lForearm); + else if(type == ESM::PRT_LForearm && lForearm) //12 + { + mBase->detachObjectFromBone(lForearm); lForearm = 0; } - else if(type == ESM::PRT_RUpperarm && rupperArm){//13 - base->detachObjectFromBone(rupperArm); + else if(type == ESM::PRT_RUpperarm && rupperArm) //13 + { + mBase->detachObjectFromBone(rupperArm); rupperArm = 0; } - else if(type == ESM::PRT_LUpperarm && lupperArm){//14 - base->detachObjectFromBone(lupperArm); + else if(type == ESM::PRT_LUpperarm && lupperArm) //14 + { + mBase->detachObjectFromBone(lupperArm); lupperArm = 0; } - else if(type == ESM::PRT_RFoot){ //15 - if(rfoot){ - base->detachObjectFromBone(rfoot); + else if(type == ESM::PRT_RFoot) //15 + { + if(rfoot) + { + mBase->detachObjectFromBone(rfoot); rfoot = 0; } - else if(rFreeFoot.first){ - insert->detachObject(rFreeFoot.first); - rFreeFoot = zero; + else if(mRFreeFoot.first) + { + mInsert->detachObject(mRFreeFoot.first); + mRFreeFoot = mZero; } } - else if(type == ESM::PRT_LFoot){ //16 - if(lfoot){ - base->detachObjectFromBone(lfoot); + else if(type == ESM::PRT_LFoot) //16 + { + if(lfoot) + { + mBase->detachObjectFromBone(lfoot); lfoot = 0; } - else if(lFreeFoot.first){ - insert->detachObject(lFreeFoot.first); - lFreeFoot = zero; + else if(mLFreeFoot.first) + { + mInsert->detachObject(mLFreeFoot.first); + mLFreeFoot = mZero; } } - else if(type == ESM::PRT_RAnkle && rAnkle){ //17 - base->detachObjectFromBone(rAnkle); + else if(type == ESM::PRT_RAnkle && rAnkle) //17 + { + mBase->detachObjectFromBone(rAnkle); rAnkle = 0; } - else if(type == ESM::PRT_LAnkle && lAnkle){ //18 - base->detachObjectFromBone(lAnkle); + else if(type == ESM::PRT_LAnkle && lAnkle) //18 + { + mBase->detachObjectFromBone(lAnkle); lAnkle = 0; } - else if(type == ESM::PRT_RKnee && rKnee){ //19 - base->detachObjectFromBone(rKnee); + else if(type == ESM::PRT_RKnee && rKnee) //19 + { + mBase->detachObjectFromBone(rKnee); rKnee = 0; } - else if(type == ESM::PRT_LKnee && lKnee){ //20 - base->detachObjectFromBone(lKnee); + else if(type == ESM::PRT_LKnee && lKnee) //20 + { + mBase->detachObjectFromBone(lKnee); lKnee = 0; } - else if(type == ESM::PRT_RLeg && rUpperLeg){ //21 - base->detachObjectFromBone(rUpperLeg); + else if(type == ESM::PRT_RLeg && rUpperLeg) //21 + { + mBase->detachObjectFromBone(rUpperLeg); rUpperLeg = 0; } - else if(type == ESM::PRT_LLeg && lUpperLeg){ //22 - base->detachObjectFromBone(lUpperLeg); + else if(type == ESM::PRT_LLeg && lUpperLeg) //22 + { + mBase->detachObjectFromBone(lUpperLeg); lUpperLeg = 0; } - else if(type == ESM::PRT_RPauldron && rclavicle){ //23 - base->detachObjectFromBone(rclavicle); + else if(type == ESM::PRT_RPauldron && rclavicle) //23 + { + mBase->detachObjectFromBone(rclavicle); rclavicle = 0; } - else if(type == ESM::PRT_LPauldron && lclavicle){ //24 - base->detachObjectFromBone(lclavicle); + else if(type == ESM::PRT_LPauldron && lclavicle) //24 + { + mBase->detachObjectFromBone(lclavicle); lclavicle = 0; } - else if(type == ESM::PRT_Weapon){ //25 + else if(type == ESM::PRT_Weapon) //25 + { } - else if(type == ESM::PRT_Tail && tail.first){ //26 - insert->detachObject(tail.first); - tail = zero; + else if(type == ESM::PRT_Tail && mTail.first) //26 + { + mInsert->detachObject(mTail.first); + mTail = mZero; } - - - } - void NpcAnimation::reserveIndividualPart(int type, int group, int priority){ - if(priority > partpriorities[type]){ + void NpcAnimation::reserveIndividualPart(int type, int group, int priority) + { + if(priority > mPartPriorities[type]) + { removeIndividualPart(type); - partpriorities[type] = priority; - partslots[type] = group; + mPartPriorities[type] = priority; + mPartslots[type] = group; } } - void NpcAnimation::removePartGroup(int group){ - for(int i = 0; i < 27; i++){ - if(partslots[i] == group){ + void NpcAnimation::removePartGroup(int group) + { + for(int i = 0; i < 27; i++) + if(mPartslots[i] == group) removeIndividualPart(i); - } - } } - bool NpcAnimation::addOrReplaceIndividualPart(int type, int group, int priority, const std::string &mesh){ - if(priority > partpriorities[type]){ + bool NpcAnimation::addOrReplaceIndividualPart(int type, int group, int priority, const std::string &mesh) + { + if(priority > mPartPriorities[type]) + { removeIndividualPart(type); - partslots[type] = group; - partpriorities[type] = priority; - switch(type){ + mPartslots[type] = group; + mPartPriorities[type] = priority; + switch(type) + { case ESM::PRT_Head: //0 head = insertBoundedPart(mesh, "Head"); break; @@ -769,19 +837,19 @@ void NpcAnimation::removeIndividualPart(int type){ neck = insertBoundedPart(mesh, "Neck"); break; case ESM::PRT_Cuirass: //3 - chest = insertFreePart(mesh, ":\""); + mChest = insertFreePart(mesh, ":\""); break; case ESM::PRT_Groin: //4 groin = insertBoundedPart(mesh, "Groin"); break; case ESM::PRT_Skirt: //5 - skirt = insertFreePart(mesh, ":|"); + mSkirt = insertFreePart(mesh, ":|"); break; case ESM::PRT_RHand: //6 - rhand = insertFreePart(mesh, ":?"); + mRhand = insertFreePart(mesh, ":?"); break; case ESM::PRT_LHand: //7 - lhand = insertFreePart(mesh, ":>"); + mLhand = insertFreePart(mesh, ":>"); break; case ESM::PRT_RWrist: //8 rWrist = insertBoundedPart(mesh, "Right Wrist"); @@ -836,33 +904,30 @@ void NpcAnimation::removeIndividualPart(int type){ case ESM::PRT_Weapon: //25 break; case ESM::PRT_Tail: //26 - tail = insertFreePart(mesh, ":*"); + mTail = insertFreePart(mesh, ":*"); break; - - } return true; } return false; } - void NpcAnimation::addPartGroup(int group, int priority, std::vector& parts){ + void NpcAnimation::addPartGroup(int group, int priority, std::vector& parts) + { for(std::size_t i = 0; i < parts.size(); i++) - { - ESM::PartReference part = parts[i]; - - const ESM::BodyPart *bodypart = 0; - - if(isFemale) - bodypart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (part.female); - if(!bodypart) - bodypart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (part.male); - if(bodypart){ - addOrReplaceIndividualPart(part.part, group,priority,"meshes\\" + bodypart->model); - } - else - reserveIndividualPart(part.part, group, priority); - - } + { + ESM::PartReference part = parts[i]; + + const ESM::BodyPart *bodypart = 0; + + if(isFemale) + bodypart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (part.female); + if(!bodypart) + bodypart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search (part.male); + if(bodypart) + addOrReplaceIndividualPart(part.part, group,priority,"meshes\\" + bodypart->model); + else + reserveIndividualPart(part.part, group, priority); + } } } diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 8f4f8181d..2f8cb97da 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -1,73 +1,63 @@ #ifndef _GAME_RENDER_NPCANIMATION_H #define _GAME_RENDER_NPCANIMATION_H + #include "animation.hpp" -#include -#include -#include -#include -#include -#include -#include "../mwworld/refdata.hpp" -#include "../mwworld/ptr.hpp" #include "components/nifogre/ogre_nif_loader.hpp" #include "../mwworld/inventorystore.hpp" #include "../mwclass/npc.hpp" #include "../mwworld/containerstore.hpp" -#include "components/esm/loadarmo.hpp" namespace MWRender{ class NpcAnimation: public Animation{ private: - MWWorld::InventoryStore& inv; - int mStateID; - //Free Parts - std::pair*> chest; - std::pair*> skirt; - std::pair*> lhand; - std::pair*> rhand; - std::pair*> tail; - std::pair*> lFreeFoot; - std::pair*> rFreeFoot; - - int partslots[27]; //Each part slot is taken by clothing, armor, or is empty - int partpriorities[27]; - std::pair*> zero; + MWWorld::InventoryStore& mInv; + int mStateID; + //Free Parts + std::pair*> mChest; + std::pair*> mSkirt; + std::pair*> mLhand; + std::pair*> mRhand; + std::pair*> mTail; + std::pair*> mLFreeFoot; + std::pair*> mRFreeFoot; + int mPartslots[27]; //Each part slot is taken by clothing, armor, or is empty + int mPartPriorities[27]; + std::pair*> mZero; + //Bounded Parts + Ogre::Entity* lclavicle; + Ogre::Entity* rclavicle; + Ogre::Entity* rupperArm; + Ogre::Entity* lupperArm; + Ogre::Entity* rUpperLeg; + Ogre::Entity* lUpperLeg; + Ogre::Entity* lForearm; + Ogre::Entity* rForearm; + Ogre::Entity* lWrist; + Ogre::Entity* rWrist; + Ogre::Entity* rKnee; + Ogre::Entity* lKnee; + Ogre::Entity* neck; + Ogre::Entity* rAnkle; + Ogre::Entity* lAnkle; + Ogre::Entity* groin; + Ogre::Entity* lfoot; + Ogre::Entity* rfoot; + Ogre::Entity* hair; + Ogre::Entity* head; - //Bounded Parts - Ogre::Entity* lclavicle; - Ogre::Entity* rclavicle; - Ogre::Entity* rupperArm; - Ogre::Entity* lupperArm; - Ogre::Entity* rUpperLeg; - Ogre::Entity* lUpperLeg; - Ogre::Entity* lForearm; - Ogre::Entity* rForearm; - Ogre::Entity* lWrist; - Ogre::Entity* rWrist; - Ogre::Entity* rKnee; - Ogre::Entity* lKnee; - Ogre::Entity* neck; - Ogre::Entity* rAnkle; - Ogre::Entity* lAnkle; - Ogre::Entity* groin; - Ogre::Entity* lfoot; - Ogre::Entity* rfoot; - Ogre::Entity* hair; - Ogre::Entity* head; - - Ogre::SceneNode* insert; + Ogre::SceneNode* insert; bool isBeast; bool isFemale; - std::string headModel; - std::string hairModel; - std::string npcName; - std::string bodyRaceID; - float timeToChange; - MWWorld::ContainerStoreIterator robe; + std::string headModel; + std::string hairModel; + std::string npcName; + std::string bodyRaceID; + float timeToChange; + MWWorld::ContainerStoreIterator robe; MWWorld::ContainerStoreIterator helmet; MWWorld::ContainerStoreIterator shirt; MWWorld::ContainerStoreIterator cuirass; @@ -80,22 +70,21 @@ private: MWWorld::ContainerStoreIterator rightglove; MWWorld::ContainerStoreIterator skirtiter; - public: - NpcAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend, MWWorld::InventoryStore& _inv); - virtual ~NpcAnimation(); +public: + NpcAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend, MWWorld::InventoryStore& _inv); + virtual ~NpcAnimation(); Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename); - std::pair*> insertFreePart(const std::string &mesh, const std::string& suffix); - void insertFootPart(int type, const std::string &mesh); - virtual void runAnimation(float timepassed); - void updateParts(); + std::pair*> insertFreePart(const std::string &mesh, const std::string& suffix); + void insertFootPart(int type, const std::string &mesh); + virtual void runAnimation(float timepassed); + void updateParts(); void removeIndividualPart(int type); void reserveIndividualPart(int type, int group, int priority); bool addOrReplaceIndividualPart(int type, int group, int priority, const std::string &mesh); - void removePartGroup(int group); + void removePartGroup(int group); void addPartGroup(int group, int priority, std::vector& parts); - }; } #endif diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 9aaba3803..c30f52979 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -1,25 +1,14 @@ #ifndef _GAME_RENDERING_MANAGER_H #define _GAME_RENDERING_MANAGER_H - #include "sky.hpp" #include "terrain.hpp" #include "debugging.hpp" -#include "../mwworld/class.hpp" - -#include - -#include -#include #include -#include #include -#include -#include - #include #include "renderinginterface.hpp" @@ -45,7 +34,6 @@ namespace MWWorld namespace MWRender { - class Shadows; class ShaderHelper; class LocalMap; diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 8a166eff3..b979420dd 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -165,4 +165,9 @@ op 0x2000160: SetFlee op 0x2000161: SetFlee, explicit reference op 0x2000162: SetAlarm op 0x2000163: SetAlarm, explicit reference -opcodes 0x2000164-0x3ffffff unused +op 0x2000164: SetScale +op 0x2000165: SetScale, explicit reference +op 0x2000166: SetAngle +op 0x2000167: SetAngle, explicit reference +opcodes 0x2000168-0x3ffffff unused + diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp index 197494146..b7425aca0 100644 --- a/apps/openmw/mwscript/extensions.cpp +++ b/apps/openmw/mwscript/extensions.cpp @@ -15,6 +15,7 @@ #include "controlextensions.hpp" #include "dialogueextensions.hpp" #include "animationextensions.hpp" +#include "transformationextensions.hpp" namespace MWScript { @@ -31,6 +32,7 @@ namespace MWScript Control::registerExtensions (extensions); Dialogue::registerExtensions (extensions); Animation::registerExtensions (extensions); + Transformation::registerExtensions (extensions); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -47,5 +49,6 @@ namespace MWScript Control::installOpcodes (interpreter); Dialogue::installOpcodes (interpreter); Animation::installOpcodes (interpreter); + Transformation::installOpcodes (interpreter); } } diff --git a/apps/openmw/mwscript/scriptmanager.hpp b/apps/openmw/mwscript/scriptmanager.hpp index 34cc0defe..a466f903d 100644 --- a/apps/openmw/mwscript/scriptmanager.hpp +++ b/apps/openmw/mwscript/scriptmanager.hpp @@ -2,7 +2,6 @@ #define GAME_SCRIPT_SCRIPTMANAGER_H #include -#include #include #include diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 33f086c6f..2edd7925e 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -536,6 +536,7 @@ namespace MWScript } }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp new file mode 100644 index 000000000..2ea80c0d8 --- /dev/null +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -0,0 +1,140 @@ +#include + +#include + +#include + +#include +#include +#include + +#include "../mwbase/environment.hpp" + +#include "../mwworld/class.hpp" + +#include "interpretercontext.hpp" +#include "ref.hpp" +#include "OgreSceneNode.h" + +namespace MWScript +{ + namespace Transformation + { + template + class OpSetScale : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + Interpreter::Type_Float scale = runtime[0].mFloat; + runtime.pop(); + + MWBase::Environment::get().getWorld()->scaleObject(ptr,scale); + } + }; + + template + class OpGetScale : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + runtime.push(ptr.getCellRef().scale); + } + }; + + template + class OpSetAngle : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + Interpreter::Type_Float angle = runtime[0].mFloat; + runtime.pop(); + + float ax = Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees(); + float ay = Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees(); + float az = Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees(); + + if(axis == "X") + { + MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,ay,az); + } + if(axis == "Y") + { + MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,angle,az); + } + if(axis == "Z") + { + MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,angle); + } + } + }; + + template + class OpGetAngle : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + if(axis == "X") + { + runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees()); + } + if(axis == "Y") + { + runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees()); + } + if(axis == "Z") + { + runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees()); + } + } + }; + + const int opcodeSetScale = 0x2000164; + const int opcodeSetScaleExplicit = 0x2000165; + const int opcodeSetAngle = 0x2000166; + const int opcodeSetAngleExplicit = 0x2000167; + const int opcodeGetScale = 0x2000168; + const int opcodeGetScaleExplicit = 0x2000169; + const int opcodeGetAngle = 0x200016a; + const int opcodeGetAngleExplicit = 0x200016b; + + void registerExtensions (Compiler::Extensions& extensions) + { + extensions.registerInstruction("setscale","f",opcodeSetScale,opcodeSetScaleExplicit); + extensions.registerFunction("getscale",'f',"",opcodeGetScale,opcodeGetScaleExplicit); + extensions.registerInstruction("setangle","Sf",opcodeSetAngle,opcodeSetAngleExplicit); + extensions.registerFunction("getangle",'f',"S",opcodeGetAngle,opcodeGetAngleExplicit); + } + + void installOpcodes (Interpreter::Interpreter& interpreter) + { + interpreter.installSegment5(opcodeSetScale,new OpSetScale); + interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale); + interpreter.installSegment5(opcodeSetAngle,new OpSetAngle); + interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle); + interpreter.installSegment5(opcodeGetScale,new OpGetScale); + interpreter.installSegment5(opcodeGetScaleExplicit,new OpGetScale); + interpreter.installSegment5(opcodeGetAngle,new OpGetAngle); + interpreter.installSegment5(opcodeGetAngleExplicit,new OpGetAngle); + } + } +} diff --git a/apps/openmw/mwscript/transformationextensions.hpp b/apps/openmw/mwscript/transformationextensions.hpp new file mode 100644 index 000000000..6ee1db1b8 --- /dev/null +++ b/apps/openmw/mwscript/transformationextensions.hpp @@ -0,0 +1,25 @@ +#ifndef GAME_SCRIPT_TRANSFORMATIONEXTENSIONS_H +#define GAME_SCRIPT_TRANSFORMATIONEXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace Interpreter +{ + class Interpreter; +} + +namespace MWScript +{ + /// \brief stats-related script functionality (creatures and NPCs) + namespace Transformation + { + void registerExtensions (Compiler::Extensions& extensions); + + void installOpcodes (Interpreter::Interpreter& interpreter); + } +} + +#endif \ No newline at end of file diff --git a/apps/openmw/mwsound/sound.hpp b/apps/openmw/mwsound/sound.hpp index a33892548..0cba6abca 100644 --- a/apps/openmw/mwsound/sound.hpp +++ b/apps/openmw/mwsound/sound.hpp @@ -3,6 +3,8 @@ #include +#include "soundmanager.hpp" + namespace MWSound { class Sound diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index ff360122b..83195390c 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index cd7ebf79a..cffaf70ea 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -1,9 +1,5 @@ #include "cells.hpp" -#include - -#include - #include #include "../mwbase/environment.hpp" diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 8253f3f0b..de3ac12ae 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -4,9 +4,6 @@ #include #include -#include -#include -#include #include #include "refdata.hpp" diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 356eef9a9..65fa91666 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -204,4 +204,12 @@ namespace MWWorld { return ""; } + + void Class::adjustScale(const MWWorld::Ptr& ptr,float& scale) const + { + } + + void Class::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const + { + } } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 352c7bda1..3d3ed71ec 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -200,6 +200,10 @@ namespace MWWorld virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string /// (default implementation: return empty string) + + virtual void adjustScale(const MWWorld::Ptr& ptr,float& scale) const; + + virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const; }; } diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index f71b493bd..ae27fad3d 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -3,8 +3,6 @@ #include -#include "cellstore.hpp" -#include "refdata.hpp" #include "ptr.hpp" namespace ESM diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 4d16a6d1c..105995aca 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -165,9 +165,6 @@ namespace MWWorld for (std::vector >::const_iterator iter (actors.begin()); iter!=actors.end(); ++iter) { - OEngine::Physic::PhysicActor* act = mEngine->getCharacter(iter->first); - //if(iter->first == "player") - // std::cout << "This is player\n"; //dirty stuff to get the camera orientation. Must be changed! Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first); @@ -177,46 +174,28 @@ namespace MWWorld Ogre::Quaternion yawQuat = yawNode->getOrientation(); Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); - // unused - //Ogre::Quaternion both = yawQuat * pitchQuat; - playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); - playerphysics->ps.viewangles.z = 0; - playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90; - - if(mFreeFly) - { - Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - pm_ref.rightmove = -dir1.x; - pm_ref.forwardmove = dir1.z; - pm_ref.upmove = dir1.y; + playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); + playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90; - //std::cout << "Current angle" << yawQuat.getYaw().valueDegrees() - 90<< "\n"; - //playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); - //std::cout << "Pitch: " << yawQuat.getPitch() << "Yaw:" << yawQuat.getYaw() << "Roll: " << yawQuat.getRoll() << "\n"; - dir = 0.07*(yawQuat*pitchQuat*dir1); - } - else - { Ogre::Quaternion quat = yawNode->getOrientation(); Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - pm_ref.rightmove = -dir1.x; - pm_ref.forwardmove = dir1.z; - pm_ref.upmove = dir1.y; + pm_ref.rightmove = -iter->second.x; + pm_ref.forwardmove = -iter->second.y; + pm_ref.upmove = iter->second.z; - dir = 0.025*(quat*dir1); } - //set the walk direction - act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y)); - } + + + mEngine->stepSimulation(dt); } @@ -234,10 +213,6 @@ namespace MWWorld if(it->first == "player"){ coord = playerphysics->ps.origin; - //std::cout << "ZCoord: " << coord.z << "\n"; - //std::cout << "Coord" << coord << "\n"; - //coord = Ogre::Vector3(coord.x, coord.z, coord.y); //x, z, -y - } @@ -262,6 +237,7 @@ namespace MWWorld void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh, const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position) { + handleToMesh[handle] = mesh; OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle,scale); mEngine->addRigidBody(body); btTransform tr; @@ -314,17 +290,27 @@ namespace MWWorld void PhysicsSystem::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation) { - if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) + if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 act->setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); } + if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) + { + body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); + } } void PhysicsSystem::scaleObject (const std::string& handle, float scale) { + if(handleToMesh.find(handle) != handleToMesh.end()) + { + btTransform transform = mEngine->getRigidBody(handle)->getWorldTransform(); + removeObject(handle); + Ogre::Quaternion quat = Ogre::Quaternion(transform.getRotation().getW(), transform.getRotation().getX(), transform.getRotation().getY(), transform.getRotation().getZ()); + Ogre::Vector3 vec = Ogre::Vector3(transform.getOrigin().getX(), transform.getOrigin().getY(), transform.getOrigin().getZ()); + addObject(handle, handleToMesh[handle], quat, scale, vec); + } } bool PhysicsSystem::toggleCollisionMode() diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 1a8bd87ae..a6b679833 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -1,9 +1,7 @@ #ifndef GAME_MWWORLD_PHYSICSSYSTEM_H #define GAME_MWWORLD_PHYSICSSYSTEM_H -#include #include -#include #include "ptr.hpp" #include @@ -72,6 +70,7 @@ namespace MWWorld OEngine::Physic::PhysicEngine* mEngine; bool mFreeFly; playerMove* playerphysics; + std::map handleToMesh; PhysicsSystem (const PhysicsSystem&); PhysicsSystem& operator= (const PhysicsSystem&); diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index b7469b8f5..f74fdd3ef 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -1,12 +1,8 @@ #ifndef GAME_MWWORLD_PTR_H #define GAME_MWWORLD_PTR_H -#include - #include -#include - #include "cellstore.hpp" namespace MWWorld diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 41521e47a..3a6e0fc9f 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -1,8 +1,6 @@ #ifndef GAME_MWWORLD_REFDATA_H #define GAME_MWWORLD_REFDATA_H -#include - #include #include "../mwscript/locals.hpp" diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 39496def3..33c67aad8 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -11,9 +11,7 @@ #include "../mwworld/manualref.hpp" /// FIXME -#include "ptr.hpp" #include "player.hpp" -#include "class.hpp" #include "localscripts.hpp" #include "cellfunctors.hpp" diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 64a8c9f8e..c0b93796a 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -1,15 +1,7 @@ #ifndef GAME_MWWORLD_SCENE_H #define GAME_MWWORLD_SCENE_H -#include -#include - -#include - -#include - #include "../mwrender/renderingmanager.hpp" -#include "../mwrender/renderinginterface.hpp" #include "physicssystem.hpp" #include "globals.hpp" diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 6f9f9936c..a68f08e34 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1,8 +1,5 @@ #include "worldimp.hpp" -#include -#include - #include #include @@ -17,16 +14,10 @@ #include "../mwgui/window_manager.hpp" -#include "ptr.hpp" -#include "class.hpp" #include "player.hpp" -#include "weather.hpp" #include "manualref.hpp" -#include "refdata.hpp" -#include "globals.hpp" #include "cellfunctors.hpp" -#include using namespace Ogre; namespace @@ -597,6 +588,31 @@ namespace MWWorld mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z)); } + void World::scaleObject (const Ptr& ptr, float scale) + { + MWWorld::Class::get(ptr).adjustScale(ptr,scale); + + ptr.getCellRef().scale = scale; + //scale = scale/ptr.getRefData().getBaseNode()->getScale().x; + ptr.getRefData().getBaseNode()->setScale(scale,scale,scale); + mPhysics->scaleObject( ptr.getRefData().getHandle(), scale ); + } + + void World::rotateObject (const Ptr& ptr,float x,float y,float z) + { + MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); + + ptr.getRefData().getPosition().rot[0] = Ogre::Degree(x).valueRadians(); + ptr.getRefData().getPosition().rot[1] = Ogre::Degree(y).valueRadians(); + ptr.getRefData().getPosition().rot[2] = Ogre::Degree(z).valueRadians(); + + Ogre::Quaternion rotx(Ogre::Degree(x),Ogre::Vector3::UNIT_X); + Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y); + Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z); + ptr.getRefData().getBaseNode()->setOrientation(rotz*roty*rotx); + mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation()); + } + void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const { const int cellSize = 8192; diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 62a24000e..43b178fe3 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -1,32 +1,17 @@ #ifndef GAME_MWWORLD_WORLDIMP_H #define GAME_MWWORLD_WORLDIMP_H -#include -#include - -#include - #include -#include - #include "../mwrender/debugging.hpp" -#include "../mwrender/renderingmanager.hpp" -#include "refdata.hpp" #include "ptr.hpp" -#include "globals.hpp" #include "scene.hpp" #include "physicssystem.hpp" #include "cells.hpp" #include "localscripts.hpp" #include "timestamp.hpp" -#include -#include - -#include - #include "../mwbase/world.hpp" namespace Ogre @@ -219,6 +204,10 @@ namespace MWWorld virtual void moveObject (const Ptr& ptr, float x, float y, float z); + virtual void scaleObject (const Ptr& ptr, float scale); + + virtual void rotateObject (const Ptr& ptr,float x,float y,float z); + virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; ///< Convert cell numbers to position. diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 284ca3cce..efeb69cae 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -72,5 +72,11 @@ add_library(components STATIC ${COMPONENT_FILES}) target_link_libraries(components ${Boost_LIBRARIES} ${OGRE_LIBRARIES}) +# Fix for not visible pthreads functions for linker with glibc 2.15 +if (UNIX AND NOT APPLE) +target_link_libraries(components ${CMAKE_THREAD_LIBS_INIT}) +endif() + + # Make the variable accessible for other subdirectories set(COMPONENT_FILES ${COMPONENT_FILES} PARENT_SCOPE) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index d3b75d4ae..07921da69 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -28,13 +28,11 @@ #include #include #include "bsa_file.hpp" -#include namespace { using namespace Ogre; -using namespace Mangle::Stream; using namespace Bsa; struct ciLessBoost : std::binary_function @@ -73,14 +71,16 @@ class DirArchive: public Ogre::FileSystemArchive { { String passed = filename; - if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') + passed = filename.substr(0, filename.length() - 6); + else if(filename.at(filename.length() - 2) == '"') + passed = filename.substr(0, filename.length() - 9); + else if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' || filename.at(filename.length() - 1) == '|') - { passed = filename.substr(0, filename.length() - 2); - } - if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') - passed = filename.substr(0, filename.length() - 6); + + copy = passed; } @@ -226,19 +226,18 @@ public: BSAFile *narc = (BSAFile*)&arc; String passed = filename; - if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') + passed = filename.substr(0, filename.length() - 6); + else if(filename.at(filename.length() - 2) == '"') + passed = filename.substr(0, filename.length() - 9); + else if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' || filename.at(filename.length() - 1) == '|') - { passed = filename.substr(0, filename.length() - 2); - } - if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') - passed = filename.substr(0, filename.length() - 6); + + // Open the file - StreamPtr strm = narc->getFile(passed.c_str()); - - // Wrap it into an Ogre::DataStream. - return DataStreamPtr(new Mangle2OgreStream(strm)); + return narc->getFile(passed.c_str()); } bool exists(const String& filename) { @@ -248,14 +247,16 @@ bool exists(const String& filename) { // Check if the file exists. bool cexists(const String& filename) const { String passed = filename; - if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') + passed = filename.substr(0, filename.length() - 6); + else if(filename.at(filename.length() - 2) == '"') + passed = filename.substr(0, filename.length() - 9); + else if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' || filename.at(filename.length() - 1) == '|') - { passed = filename.substr(0, filename.length() - 2); - } - if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') - passed = filename.substr(0, filename.length() - 6); + + return arc.exists(passed.c_str()); } diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp index f19606703..053191c9b 100644 --- a/components/bsa/bsa_file.cpp +++ b/components/bsa/bsa_file.cpp @@ -23,171 +23,235 @@ #include "bsa_file.hpp" -#include -#include - #include -#include -#include +#include +#include + +#include using namespace std; -using namespace Mangle::Stream; using namespace Bsa; +class ConstrainedDataStream : public Ogre::DataStream { + std::ifstream mStream; + const size_t mStart; + size_t mPos; + bool mIsEOF; + +public: + ConstrainedDataStream(const Ogre::String &fname, size_t start, size_t length) + : mStream(fname.c_str(), std::ios_base::binary), mStart(start), mPos(0), mIsEOF(false) + { + mSize = length; + if(!mStream.seekg(mStart, std::ios_base::beg)) + throw std::runtime_error("Error seeking to start of BSA entry"); + } + + ConstrainedDataStream(const Ogre::String &name, const Ogre::String &fname, + size_t start, size_t length) + : Ogre::DataStream(name), mStream(fname.c_str(), std::ios_base::binary), + mStart(start), mPos(0), mIsEOF(false) + { + mSize = length; + if(!mStream.seekg(mStart, std::ios_base::beg)) + throw std::runtime_error("Error seeking to start of BSA entry"); + } + + + virtual size_t read(void *buf, size_t count) + { + mStream.clear(); + + if(count > mSize-mPos) + { + count = mSize-mPos; + mIsEOF = true; + } + mStream.read(reinterpret_cast(buf), count); + + count = mStream.gcount(); + mPos += count; + return count; + } + + virtual void skip(long count) + { + if((count >= 0 && (size_t)count <= mSize-mPos) || + (count < 0 && (size_t)-count <= mPos)) + { + mStream.clear(); + if(mStream.seekg(count, std::ios_base::cur)) + { + mPos += count; + mIsEOF = false; + } + } + } + + virtual void seek(size_t pos) + { + if(pos < mSize) + { + mStream.clear(); + if(mStream.seekg(pos+mStart, std::ios_base::beg)) + { + mPos = pos; + mIsEOF = false; + } + } + } + + virtual size_t tell() const + { return mPos; } + + virtual bool eof() const + { return mIsEOF; } + + virtual void close() + { mStream.close(); } +}; + + /// Error handling void BSAFile::fail(const string &msg) { - throw std::runtime_error("BSA Error: " + msg + "\nArchive: " + filename); + throw std::runtime_error("BSA Error: " + msg + "\nArchive: " + filename); } /// Read header information from the input source void BSAFile::readHeader() { - /* - * The layout of a BSA archive is as follows: - * - * - 12 bytes header, contains 3 ints: - * id number - equal to 0x100 - * dirsize - size of the directory block (see below) - * numfiles - number of files - * - * ---------- start of directory block ----------- - * - * - 8 bytes*numfiles, each record contains: - * fileSize - * offset into data buffer (see below) - * - * - 4 bytes*numfiles, each record is an offset into the following name buffer - * - * - name buffer, indexed by the previous table, each string is - * null-terminated. Size is (dirsize - 12*numfiles). - * - * ---------- end of directory block ------------- - * - * - 8*filenum - hash table block, we currently ignore this - * - * ----------- start of data buffer -------------- - * - * - The rest of the archive is file data, indexed by the - * offsets in the directory block. The offsets start at 0 at - * the beginning of this buffer. - * - */ - assert(!isLoaded); - assert(input); - assert(input->hasSize); - assert(input->hasPosition); - assert(input->isSeekable); - - // Total archive size - size_t fsize = input->size(); - - if( fsize < 12 ) - fail("File too small to be a valid BSA archive"); - - // Get essential header numbers - size_t dirsize, filenum; - - { - // First 12 bytes - uint32_t head[3]; - - input->read(head, 12); - - if(head[0] != 0x100) - fail("Unrecognized BSA header"); - - // Total number of bytes used in size/offset-table + filename - // sections. - dirsize = head[1]; - - // Number of files - filenum = head[2]; - } - - // Each file must take up at least 21 bytes of data in the bsa. So - // if files*21 overflows the file size then we are guaranteed that - // the archive is corrupt. - if( (filenum*21 > fsize -12) || - (dirsize+8*filenum > fsize -12) ) - fail("Directory information larger than entire archive"); - - // Read the offset info into a temporary buffer - vector offsets(3*filenum); - input->read(&offsets[0], 12*filenum); - - // Read the string table - stringBuf.resize(dirsize-12*filenum); - input->read(&stringBuf[0], stringBuf.size()); - - // Check our position - assert(input->tell() == 12+dirsize); - - // Calculate the offset of the data buffer. All file offsets are - // relative to this. 12 header bytes + directory + hash table - // (skipped) - size_t fileDataOffset = 12 + dirsize + 8*filenum; - - // Set up the the FileStruct table - files.resize(filenum); - for(size_t i=0;i(head), 12); + + if(head[0] != 0x100) + fail("Unrecognized BSA header"); + + // Total number of bytes used in size/offset-table + filename + // sections. + dirsize = head[1]; + + // Number of files + filenum = head[2]; + } + + // Each file must take up at least 21 bytes of data in the bsa. So + // if files*21 overflows the file size then we are guaranteed that + // the archive is corrupt. + if((filenum*21 > fsize -12) || (dirsize+8*filenum > fsize -12) ) + fail("Directory information larger than entire archive"); + + // Read the offset info into a temporary buffer + vector offsets(3*filenum); + input.read(reinterpret_cast(&offsets[0]), 12*filenum); - if(fs.offset + fs.fileSize > fsize) - fail("Archive contains offsets outside itself"); + // Read the string table + stringBuf.resize(dirsize-12*filenum); + input.read(&stringBuf[0], stringBuf.size()); - // Add the file name to the lookup - lookup[fs.name] = i; + // Check our position + assert(input.tellg() == static_cast (12+dirsize)); + + // Calculate the offset of the data buffer. All file offsets are + // relative to this. 12 header bytes + directory + hash table + // (skipped) + size_t fileDataOffset = 12 + dirsize + 8*filenum; + + // Set up the the FileStruct table + files.resize(filenum); + for(size_t i=0;i fsize) + fail("Archive contains offsets outside itself"); + + // Add the file name to the lookup + lookup[fs.name] = i; } - isLoaded = true; + isLoaded = true; } /// Get the index of a given file name, or -1 if not found int BSAFile::getIndex(const char *str) const { - Lookup::const_iterator it; - it = lookup.find(str); + Lookup::const_iterator it = lookup.find(str); + if(it == lookup.end()) + return -1; - if(it == lookup.end()) return -1; - else - { - int res = it->second; - assert(res >= 0 && res < static_cast (files.size())); - return res; - } + int res = it->second; + assert(res >= 0 && (size_t)res < files.size()); + return res; } /// Open an archive file. void BSAFile::open(const string &file) { - filename = file; - input = StreamPtr(new FileStream(file)); - readHeader(); + filename = file; + readHeader(); } -/** Open an archive from a generic stream. The 'name' parameter is - used for error messages. -*/ -void BSAFile::open(StreamPtr inp, const string &name) +Ogre::DataStreamPtr BSAFile::getFile(const char *file) { - filename = name; - input = inp; - readHeader(); -} - -StreamPtr BSAFile::getFile(const char *file) -{ - assert(file); - int i = getIndex(file); - if(i == -1) - fail("File not found: " + string(file)); - - FileStruct &fs = files[i]; + assert(file); + int i = getIndex(file); + if(i == -1) + fail("File not found: " + string(file)); - return StreamPtr(new SliceStream(input, fs.offset, fs.fileSize)); + const FileStruct &fs = files[i]; + return Ogre::DataStreamPtr(new ConstrainedDataStream(filename, fs.offset, fs.fileSize)); } diff --git a/components/bsa/bsa_file.hpp b/components/bsa/bsa_file.hpp index 95fac0f4d..6f3ab3bce 100644 --- a/components/bsa/bsa_file.hpp +++ b/components/bsa/bsa_file.hpp @@ -24,13 +24,15 @@ #ifndef BSA_BSA_FILE_H #define BSA_BSA_FILE_H -#include #include #include #include #include #include +#include + + namespace Bsa { @@ -39,98 +41,85 @@ namespace Bsa */ class BSAFile { - public: - - /// Represents one file entry in the archive - struct FileStruct - { - // File size and offset in file. We store the offset from the - // beginning of the file, not the offset into the data buffer - // (which is what is stored in the archive.) - uint32_t fileSize, offset; - - // Zero-terminated file name - char* name; - }; - - typedef std::vector FileList; - - private: - - /// The archive source - Mangle::Stream::StreamPtr input; - - /// Table of files in this archive - FileList files; - - /// Filename string buffer - std::vector stringBuf; - - /// True when an archive has been loaded - bool isLoaded; - - /// Used for error messages - std::string filename; - - /// Case insensitive string comparison - struct iltstr - { - bool operator()(const char *s1, const char *s2) const - { return strcasecmp(s1,s2) < 0; } - }; - - /** A map used for fast file name lookup. The value is the index into - the files[] vector above. The iltstr ensures that file name - checks are case insensitive. - */ - typedef std::map Lookup; - Lookup lookup; - - /// Error handling - void fail(const std::string &msg); - - /// Read header information from the input source - void readHeader(); - - /// Get the index of a given file name, or -1 if not found - int getIndex(const char *str) const; - - public: - - /* ----------------------------------- - * BSA management methods - * ----------------------------------- - */ - - BSAFile() - : input(), isLoaded(false) {} - - /// Open an archive file. - void open(const std::string &file); - - /** Open an archive from a generic stream. The 'name' parameter is - used for error messages. - */ - void open(Mangle::Stream::StreamPtr inp, const std::string &name); - - /* ----------------------------------- - * Archive file routines - * ----------------------------------- - */ - - /// Check if a file exists - bool exists(const char *file) const { return getIndex(file) != -1; } - - /** Open a file contained in the archive. Throws an exception if the - file doesn't exist. - - NOTE: All files opened from one archive will share a common file - handle. This is NOT thread safe. - */ - Mangle::Stream::StreamPtr getFile(const char *file); - - /// Get a list of all files - const FileList &getList() const +public: + /// Represents one file entry in the archive + struct FileStruct + { + // File size and offset in file. We store the offset from the + // beginning of the file, not the offset into the data buffer + // (which is what is stored in the archive.) + uint32_t fileSize, offset; + + // Zero-terminated file name + const char *name; + }; + typedef std::vector FileList; + +private: + /// Table of files in this archive + FileList files; + + /// Filename string buffer + std::vector stringBuf; + + /// True when an archive has been loaded + bool isLoaded; + + /// Used for error messages + std::string filename; + + /// Case insensitive string comparison + struct iltstr + { + bool operator()(const char *s1, const char *s2) const + { return strcasecmp(s1,s2) < 0; } + }; + + /** A map used for fast file name lookup. The value is the index into + the files[] vector above. The iltstr ensures that file name + checks are case insensitive. + */ + typedef std::map Lookup; + Lookup lookup; + + /// Error handling + void fail(const std::string &msg); + + /// Read header information from the input source + void readHeader(); + + /// Get the index of a given file name, or -1 if not found + int getIndex(const char *str) const; + +public: + /* ----------------------------------- + * BSA management methods + * ----------------------------------- + */ + + BSAFile() + : isLoaded(false) + { } + + /// Open an archive file. + void open(const std::string &file); + + /* ----------------------------------- + * Archive file routines + * ----------------------------------- + */ + + /// Check if a file exists + bool exists(const char *file) const + { return getIndex(file) != -1; } + + /** Open a file contained in the archive. Throws an exception if the + file doesn't exist. + */ + Ogre::DataStreamPtr getFile(const char *file); + + /// Get a list of all files + const FileList &getList() const { return files; } }; diff --git a/components/bsa/tests/bsatool_cmd.c b/components/bsa/tests/bsatool_cmd.c index f6e10d793..caa8cd720 100644 --- a/components/bsa/tests/bsatool_cmd.c +++ b/components/bsa/tests/bsatool_cmd.c @@ -13,8 +13,8 @@ #include "config.h" #endif -#include -#include +#include +#include #include #ifndef FIX_UNUSED diff --git a/components/bsa/tests/bsatool_cmd.h b/components/bsa/tests/bsatool_cmd.h index 65ebc3e96..98fe2633f 100644 --- a/components/bsa/tests/bsatool_cmd.h +++ b/components/bsa/tests/bsatool_cmd.h @@ -13,7 +13,7 @@ #include "config.h" #endif -#include /* for FILE */ +#include /* for FILE */ #ifdef __cplusplus extern "C" { diff --git a/components/compiler/streamerrorhandler.cpp b/components/compiler/streamerrorhandler.cpp index a1d12b708..8a74ad086 100644 --- a/components/compiler/streamerrorhandler.cpp +++ b/components/compiler/streamerrorhandler.cpp @@ -35,4 +35,5 @@ namespace Compiler << " " << message << std::endl; } - StreamErrorHandler::StreamErrorHandler (std::ostream& ErrorStream) : mStream (ErrorStream) {}} + StreamErrorHandler::StreamErrorHandler (std::ostream& ErrorStream) : mStream (ErrorStream) {} +} diff --git a/components/esm/esm_reader.cpp b/components/esm/esm_reader.cpp index e9bfcf5ee..a2cf69ddc 100644 --- a/components/esm/esm_reader.cpp +++ b/components/esm/esm_reader.cpp @@ -27,7 +27,7 @@ void ESMReader::restoreContext(const ESM_Context &rc) void ESMReader::close() { - mEsm.reset(); + mEsm.setNull(); mCtx.filename.clear(); mCtx.leftFile = 0; mCtx.leftRec = 0; @@ -37,7 +37,7 @@ void ESMReader::close() mCtx.subName.val = 0; } -void ESMReader::openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name) +void ESMReader::openRaw(Ogre::DataStreamPtr _esm, const std::string &name) { close(); mEsm = _esm; @@ -57,7 +57,7 @@ void ESMReader::openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name) mSpf = SF_Other; } -void ESMReader::open(Mangle::Stream::StreamPtr _esm, const std::string &name) +void ESMReader::open(Ogre::DataStreamPtr _esm, const std::string &name) { openRaw(_esm, name); @@ -107,14 +107,16 @@ void ESMReader::open(Mangle::Stream::StreamPtr _esm, const std::string &name) void ESMReader::open(const std::string &file) { - using namespace Mangle::Stream; - open(StreamPtr(new FileStream(file)), file); + std::ifstream *stream = OGRE_NEW_T(std::ifstream, Ogre::MEMCATEGORY_GENERAL)(file.c_str(), std::ios_base::binary); + // Ogre will delete the stream for us + open(Ogre::DataStreamPtr(new Ogre::FileStreamDataStream(stream)), file); } void ESMReader::openRaw(const std::string &file) { - using namespace Mangle::Stream; - openRaw(StreamPtr(new FileStream(file)), file); + std::ifstream *stream = OGRE_NEW_T(std::ifstream, Ogre::MEMCATEGORY_GENERAL)(file.c_str(), std::ios_base::binary); + // Ogre will delete the stream for us + openRaw(Ogre::DataStreamPtr(new Ogre::FileStreamDataStream(stream)), file); } int64_t ESMReader::getHNLong(const char *name) @@ -339,7 +341,7 @@ void ESMReader::fail(const std::string &msg) ss << "\n File: " << mCtx.filename; ss << "\n Record: " << mCtx.recName.toString(); ss << "\n Subrecord: " << mCtx.subName.toString(); - if (mEsm != NULL) + if (!mEsm.isNull()) ss << "\n Offset: 0x" << hex << mEsm->tell(); throw std::runtime_error(ss.str()); } diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp index 340482891..13f1f4a01 100644 --- a/components/esm/esm_reader.hpp +++ b/components/esm/esm_reader.hpp @@ -1,18 +1,14 @@ #ifndef _ESM_READER_H #define _ESM_READER_H -#include - -#include #include #include -#include +#include #include #include -#include -#include -#include +#include + #include #include @@ -183,11 +179,11 @@ public: /// Raw opening. Opens the file and sets everything up but doesn't /// parse the header. - void openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name); + void openRaw(Ogre::DataStreamPtr _esm, const std::string &name); /// Load ES file from a new stream, parses the header. Closes the /// currently open file first, if any. - void open(Mangle::Stream::StreamPtr _esm, const std::string &name); + void open(Ogre::DataStreamPtr _esm, const std::string &name); void open(const std::string &file); @@ -354,7 +350,7 @@ public: void setEncoding(const std::string& encoding); private: - Mangle::Stream::StreamPtr mEsm; + Ogre::DataStreamPtr mEsm; ESM_Context mCtx; diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 48bf050cd..ffecfc8de 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/components/files/collections.hpp b/components/files/collections.hpp index 70aaec55e..ed4aafa13 100644 --- a/components/files/collections.hpp +++ b/components/files/collections.hpp @@ -1,8 +1,6 @@ #ifndef COMPONENTS_FILES_COLLECTION_HPP #define COMPONENTS_FILES_COLLECTION_HPP -#include -#include #include #include "multidircollection.hpp" diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index af9d02b91..0c22c6f7d 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -8,7 +8,6 @@ #endif #include -#include #include #include diff --git a/components/misc/tests/slice_test.cpp b/components/misc/tests/slice_test.cpp index a0ea55311..0d9d7b4ab 100644 --- a/components/misc/tests/slice_test.cpp +++ b/components/misc/tests/slice_test.cpp @@ -2,8 +2,6 @@ using namespace std; -#include - #include "../slice_array.hpp" int main() diff --git a/components/misc/tests/strops_test.cpp b/components/misc/tests/strops_test.cpp index 2a1fdd77d..24ab8a298 100644 --- a/components/misc/tests/strops_test.cpp +++ b/components/misc/tests/strops_test.cpp @@ -1,4 +1,4 @@ -#include +#include #include "../stringops.hpp" diff --git a/components/nif/controlled.hpp b/components/nif/controlled.hpp index d59950132..b9d84b58a 100644 --- a/components/nif/controlled.hpp +++ b/components/nif/controlled.hpp @@ -25,6 +25,7 @@ #define _NIF_CONTROLLED_H_ #include "extra.hpp" +#include "controller.hpp" namespace Nif { @@ -33,92 +34,104 @@ namespace Nif class Controlled : public Extra { public: - ControllerPtr controller; - - void read(NIFFile *nif) - { - Extra::read(nif); - controller.read(nif); - } + ControllerPtr controller; + + void read(NIFFile *nif) + { + Extra::read(nif); + controller.read(nif); + } + + void post(NIFFile *nif) + { + Extra::post(nif); + controller.post(nif); + } }; /// Has name, extra-data and controller class Named : public Controlled { public: - Misc::SString name; + std::string name; - void read(NIFFile *nif) - { - name = nif->getString(); - Controlled::read(nif); - } + void read(NIFFile *nif) + { + name = nif->getString(); + Controlled::read(nif); + } }; typedef Named NiSequenceStreamHelper; class NiParticleGrowFade : public Controlled { public: - void read(NIFFile *nif) - { - Controlled::read(nif); + void read(NIFFile *nif) + { + Controlled::read(nif); - // Two floats. - nif->skip(8); - } + // Two floats. + nif->skip(8); + } }; class NiParticleColorModifier : public Controlled { public: - NiColorDataPtr data; - - void read(NIFFile *nif) - { - Controlled::read(nif); - data.read(nif); - } + NiColorDataPtr data; + + void read(NIFFile *nif) + { + Controlled::read(nif); + data.read(nif); + } + + void post(NIFFile *nif) + { + Controlled::post(nif); + data.post(nif); + } }; class NiGravity : public Controlled { public: - void read(NIFFile *nif) - { - Controlled::read(nif); + void read(NIFFile *nif) + { + Controlled::read(nif); - // two floats, one int, six floats - nif->skip(9*4); - } + // two floats, one int, six floats + nif->skip(9*4); + } }; // NiPinaColada class NiPlanarCollider : public Controlled { public: - void read(NIFFile *nif) - { - Controlled::read(nif); + void read(NIFFile *nif) + { + Controlled::read(nif); - // (I think) 4 floats + 4 vectors - nif->skip(4*16); - } + // (I think) 4 floats + 4 vectors + nif->skip(4*16); + } }; class NiParticleRotation : public Controlled { public: - void read(NIFFile *nif) - { - Controlled::read(nif); - - /* - byte (0 or 1) - float (1) - float*3 - */ - nif->skip(17); - } + void read(NIFFile *nif) + { + Controlled::read(nif); + + /* + byte (0 or 1) + float (1) + float*3 + */ + nif->skip(17); + } }; } // Namespace diff --git a/components/nif/controller.hpp b/components/nif/controller.hpp index d6fb22255..cbc19cd8f 100644 --- a/components/nif/controller.hpp +++ b/components/nif/controller.hpp @@ -34,136 +34,187 @@ namespace Nif class Controller : public Record { public: - ControllerPtr next; - int flags; - float frequency, phase; - float timeStart, timeStop; - ControlledPtr target; - - void read(NIFFile *nif) - { - next.read(nif); - - flags = nif->getShort(); - - frequency = nif->getFloat(); - phase = nif->getFloat(); - timeStart = nif->getFloat(); - timeStop = nif->getFloat(); - - target.read(nif); - } + ControllerPtr next; + int flags; + float frequency, phase; + float timeStart, timeStop; + ControlledPtr target; + + void read(NIFFile *nif) + { + next.read(nif); + + flags = nif->getUShort(); + + frequency = nif->getFloat(); + phase = nif->getFloat(); + timeStart = nif->getFloat(); + timeStop = nif->getFloat(); + + target.read(nif); + } + + void post(NIFFile *nif) + { + Record::post(nif); + next.post(nif); + target.post(nif); + } }; class NiBSPArrayController : public Controller { public: - void read(NIFFile *nif) - { - Controller::read(nif); - - // At the moment, just skip it all - nif->skip(111); - int s = nif->getShort(); - nif->skip(15 + s*40); - } + void read(NIFFile *nif) + { + Controller::read(nif); + + // At the moment, just skip it all + nif->skip(111); + int s = nif->getUShort(); + nif->skip(15 + s*40); + } }; typedef NiBSPArrayController NiParticleSystemController; class NiMaterialColorController : public Controller { public: - NiPosDataPtr data; - - void read(NIFFile *nif) - { - Controller::read(nif); - data.read(nif); - } + NiPosDataPtr data; + + void read(NIFFile *nif) + { + Controller::read(nif); + data.read(nif); + } + + void post(NIFFile *nif) + { + Controller::post(nif); + data.post(nif); + } }; class NiPathController : public Controller { public: - NiPosDataPtr posData; - NiFloatDataPtr floatData; - - void read(NIFFile *nif) - { - Controller::read(nif); - - /* - int = 1 - 2xfloat - short = 0 or 1 - */ - nif->skip(14); - posData.read(nif); - floatData.read(nif); - } + NiPosDataPtr posData; + NiFloatDataPtr floatData; + + void read(NIFFile *nif) + { + Controller::read(nif); + + /* + int = 1 + 2xfloat + short = 0 or 1 + */ + nif->skip(14); + posData.read(nif); + floatData.read(nif); + } + + void post(NIFFile *nif) + { + Controller::post(nif); + + posData.post(nif); + floatData.post(nif); + } }; class NiUVController : public Controller { public: - NiUVDataPtr data; + NiUVDataPtr data; - void read(NIFFile *nif) - { - Controller::read(nif); + void read(NIFFile *nif) + { + Controller::read(nif); - nif->getShort(); // always 0 - data.read(nif); - } + nif->getUShort(); // always 0 + data.read(nif); + } + + void post(NIFFile *nif) + { + Controller::post(nif); + data.post(nif); + } }; class NiKeyframeController : public Controller { public: - NiKeyframeDataPtr data; - - void read(NIFFile *nif) - { - Controller::read(nif); - data.read(nif); - } + NiKeyframeDataPtr data; + + void read(NIFFile *nif) + { + Controller::read(nif); + data.read(nif); + } + + void post(NIFFile *nif) + { + Controller::post(nif); + data.post(nif); + } }; class NiAlphaController : public Controller { public: - NiFloatDataPtr data; - - void read(NIFFile *nif) - { - Controller::read(nif); - data.read(nif); - } + NiFloatDataPtr data; + + void read(NIFFile *nif) + { + Controller::read(nif); + data.read(nif); + } + + void post(NIFFile *nif) + { + Controller::post(nif); + data.post(nif); + } }; class NiGeomMorpherController : public Controller { public: - NiMorphDataPtr data; - - void read(NIFFile *nif) - { - Controller::read(nif); - data.read(nif); - nif->getByte(); // always 0 - } + NiMorphDataPtr data; + + void read(NIFFile *nif) + { + Controller::read(nif); + data.read(nif); + nif->getChar(); // always 0 + } + + void post(NIFFile *nif) + { + Controller::post(nif); + data.post(nif); + } }; class NiVisController : public Controller { public: - NiVisDataPtr data; - - void read(NIFFile *nif) - { - Controller::read(nif); - data.read(nif); - } + NiVisDataPtr data; + + void read(NIFFile *nif) + { + Controller::read(nif); + data.read(nif); + } + + void post(NIFFile *nif) + { + Controller::post(nif); + data.post(nif); + } }; } // Namespace diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 10337d2c9..ad670bc5e 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -35,794 +35,771 @@ namespace Nif class NiSourceTexture : public Named { public: + // Is this an external (references a separate texture file) or + // internal (data is inside the nif itself) texture? + bool external; + + std::string filename; // In case of external textures + NiPixelDataPtr data; // In case of internal textures + + /* Pixel layout + 0 - Palettised + 1 - High color 16 + 2 - True color 32 + 3 - Compressed + 4 - Bumpmap + 5 - Default */ + int pixel; + + /* Mipmap format + 0 - no + 1 - yes + 2 - default */ + int mipmap; + + /* Alpha + 0 - none + 1 - binary + 2 - smooth + 3 - default (use material alpha, or multiply material with texture if present) + */ + int alpha; + + void read(NIFFile *nif) + { + Named::read(nif); - // Is this an external (references a separate texture file) or - // internal (data is inside the nif itself) texture? - bool external; - - Misc::SString filename; // In case of external textures - NiPixelDataPtr data; // In case of internal textures - - /* Pixel layout - 0 - Palettised - 1 - High color 16 - 2 - True color 32 - 3 - Compressed - 4 - Bumpmap - 5 - Default */ - int pixel; - - /* Mipmap format - 0 - no - 1 - yes - 2 - default */ - int mipmap; - - /* Alpha - 0 - none - 1 - binary - 2 - smooth - 3 - default (use material alpha, or multiply material with texture if present) - */ - int alpha; - - void read(NIFFile *nif) - { - Named::read(nif); - - external = !!nif->getByte(); - - if(external) filename = nif->getString(); - else - { - nif->getByte(); // always 1 - data.read(nif); - } + external = !!nif->getChar(); + if(external) + filename = nif->getString(); + else + { + nif->getChar(); // always 1 + data.read(nif); + } - pixel = nif->getInt(); - mipmap = nif->getInt(); - alpha = nif->getInt(); + pixel = nif->getInt(); + mipmap = nif->getInt(); + alpha = nif->getInt(); - nif->getByte(); // always 1 - } + nif->getChar(); // always 1 + } + + void post(NIFFile *nif) + { + Named::post(nif); + data.post(nif); + } }; // Common ancestor for several data classes class ShapeData : public Record { public: - Misc::FloatArray vertices, normals, colors, uvlist; - const Vector *center; - float radius; + std::vector vertices, normals, colors, uvlist; + Ogre::Vector3 center; + float radius; - void read(NIFFile *nif) - { - int verts = nif->getShort(); - - if(nif->getInt()) - vertices = nif->getFloatLen(verts*3); + void read(NIFFile *nif) + { + int verts = nif->getUShort(); - if(nif->getInt()) - normals = nif->getFloatLen(verts*3); + if(nif->getInt()) + nif->getFloats(vertices, verts*3); - center = nif->getVector(); - radius = nif->getFloat(); + if(nif->getInt()) + nif->getFloats(normals, verts*3); - if(nif->getInt()) - colors = nif->getFloatLen(verts*4); + center = nif->getVector3(); + radius = nif->getFloat(); - int uvs = nif->getShort(); + if(nif->getInt()) + nif->getFloats(colors, verts*4); - // Only the first 6 bits are used as a count. I think the rest are - // flags of some sort. - uvs &= 0x3f; + // Only the first 6 bits are used as a count. I think the rest are + // flags of some sort. + int uvs = nif->getUShort(); + uvs &= 0x3f; - if(nif->getInt()) - uvlist = nif->getFloatLen(uvs*verts*2); - } + if(nif->getInt()) + nif->getFloats(uvlist, uvs*verts*2); + } }; class NiTriShapeData : public ShapeData { public: - // Triangles, three vertex indices per triangle - Misc::SliceArray triangles; - - void read(NIFFile *nif) - { - ShapeData::read(nif); - - int tris = nif->getShort(); - if(tris) - { - // We have three times as many vertices as triangles, so this - // is always equal to tris*3. - int cnt = nif->getInt(); - triangles = nif->getArrayLen(cnt); - } - - // Read the match list, which lists the vertices that are equal to - // vertices. We don't actually need need this for anything, so - // just skip it. - int verts = nif->getShort(); - if(verts) - { + // Triangles, three vertex indices per triangle + std::vector triangles; + + void read(NIFFile *nif) + { + ShapeData::read(nif); + + int tris = nif->getUShort(); + if(tris) + { + // We have three times as many vertices as triangles, so this + // is always equal to tris*3. + int cnt = nif->getInt(); + nif->getShorts(triangles, cnt); + } + + // Read the match list, which lists the vertices that are equal to + // vertices. We don't actually need need this for anything, so + // just skip it. + int verts = nif->getUShort(); for(int i=0;igetShort(); - nif->skip(num*sizeof(short)); - } - } - } + int num = nif->getUShort(); + nif->skip(num * sizeof(short)); + } + } }; class NiAutoNormalParticlesData : public ShapeData { public: - int activeCount; + int activeCount; - void read(NIFFile *nif) - { - ShapeData::read(nif); + void read(NIFFile *nif) + { + ShapeData::read(nif); - // Should always match the number of vertices - activeCount = nif->getShort(); + // Should always match the number of vertices + activeCount = nif->getUShort(); - // Skip all the info, we don't support particles yet - nif->getFloat(); // Active radius ? - nif->getShort(); // Number of valid entries in the following arrays ? + // Skip all the info, we don't support particles yet + nif->getFloat(); // Active radius ? + nif->getUShort(); // Number of valid entries in the following arrays ? - if(nif->getInt()) - // Particle sizes - nif->getFloatLen(activeCount); - } + if(nif->getInt()) + { + // Particle sizes + nif->skip(activeCount * sizeof(float)); + } + } }; class NiRotatingParticlesData : public NiAutoNormalParticlesData { public: - void read(NIFFile *nif) - { - NiAutoNormalParticlesData::read(nif); - - if(nif->getInt()) - // Rotation quaternions. I THINK activeCount is correct here, - // but verts (vertex number) might also be correct, if there is - // any case where the two don't match. - nif->getArrayLen(activeCount); - } + void read(NIFFile *nif) + { + NiAutoNormalParticlesData::read(nif); + + if(nif->getInt()) + { + // Rotation quaternions. I THINK activeCount is correct here, + // but verts (vertex number) might also be correct, if there is + // any case where the two don't match. + nif->skip(activeCount * 4*sizeof(float)); + } + } }; class NiPosData : public Record { public: - void read(NIFFile *nif) - { - int count = nif->getInt(); - int type = nif->getInt(); - if(type != 1 && type != 2) - nif->fail("Cannot handle NiPosData type"); - - // TODO: Could make structs of these. Seems to be identical to - // translation in NiKeyframeData. - for(int i=0; igetFloat(); - nif->getVector(); // This isn't really shared between type 1 - // and type 2, most likely - if(type == 2) - { - nif->getVector(); - nif->getVector(); - } - } - } + void read(NIFFile *nif) + { + int count = nif->getInt(); + int type = nif->getInt(); + if(type != 1 && type != 2) + nif->fail("Cannot handle NiPosData type"); + + // TODO: Could make structs of these. Seems to be identical to + // translation in NiKeyframeData. + for(int i=0; igetFloat(); + nif->getVector3(); // This isn't really shared between type 1 + // and type 2, most likely + if(type == 2) + { + nif->getVector3(); + nif->getVector3(); + } + } + } }; class NiUVData : public Record { public: - void read(NIFFile *nif) - { - // TODO: This is claimed to be a "float animation key", which is - // also used in FloatData and KeyframeData. We could probably - // reuse and refactor a lot of this if we actually use it at some - // point. - - for(int i=0; i<2; i++) - { - int count = nif->getInt(); - - if(count) - { - nif->getInt(); // always 2 - nif->getArrayLen(count); // Really one time float + one vector - } - } - // Always 0 - nif->getInt(); - nif->getInt(); - } + void read(NIFFile *nif) + { + // TODO: This is claimed to be a "float animation key", which is + // also used in FloatData and KeyframeData. We could probably + // reuse and refactor a lot of this if we actually use it at some + // point. + for(int i=0; i<2; i++) + { + int count = nif->getInt(); + if(count) + { + nif->getInt(); // always 2 + nif->skip(count * (sizeof(float) + 3*sizeof(float))); // Really one time float + one vector + } + } + // Always 0 + nif->getInt(); + nif->getInt(); + } }; class NiFloatData : public Record { public: - void read(NIFFile *nif) - { - int count = nif->getInt(); - nif->getInt(); // always 2 - nif->getArrayLen(count); // Really one time float + one vector - } + void read(NIFFile *nif) + { + int count = nif->getInt(); + nif->getInt(); // always 2 + nif->skip(count * (sizeof(float) + 3*sizeof(float))); // Really one time float + one vector + } }; class NiPixelData : public Record { public: - unsigned int rmask, gmask, bmask, amask; - int bpp, mips; + unsigned int rmask, gmask, bmask, amask; + int bpp, mips; - void read(NIFFile *nif) - { - nif->getInt(); // always 0 or 1 + void read(NIFFile *nif) + { + nif->getInt(); // always 0 or 1 - rmask = nif->getInt(); // usually 0xff - gmask = nif->getInt(); // usually 0xff00 - bmask = nif->getInt(); // usually 0xff0000 - amask = nif->getInt(); // usually 0xff000000 or zero + rmask = nif->getInt(); // usually 0xff + gmask = nif->getInt(); // usually 0xff00 + bmask = nif->getInt(); // usually 0xff0000 + amask = nif->getInt(); // usually 0xff000000 or zero - bpp = nif->getInt(); + bpp = nif->getInt(); - // Unknown - nif->skip(12); + // Unknown + nif->skip(12); - mips = nif->getInt(); + mips = nif->getInt(); - // Bytes per pixel, should be bpp * 8 - /*int bytes =*/ nif->getInt(); + // Bytes per pixel, should be bpp * 8 + /*int bytes =*/ nif->getInt(); - for(int i=0; igetInt(); - /*int y =*/ nif->getInt(); - /*int offset =*/ nif->getInt(); - } + for(int i=0; igetInt(); + /*int y =*/ nif->getInt(); + /*int offset =*/ nif->getInt(); + } - // Skip the data - unsigned int dataSize = nif->getInt(); - nif->skip(dataSize); - } + // Skip the data + unsigned int dataSize = nif->getInt(); + nif->skip(dataSize); + } }; class NiColorData : public Record { public: - struct ColorData - { - float time; - Vector4 rgba; - }; - - void read(NIFFile *nif) - { - int count = nif->getInt(); - nif->getInt(); // always 1 - - // Skip the data - assert(sizeof(ColorData) == 4*5); - nif->skip(sizeof(ColorData) * count); - } + struct ColorData + { + float time; + Ogre::Vector4 rgba; + }; + + void read(NIFFile *nif) + { + int count = nif->getInt(); + nif->getInt(); // always 1 + + // Skip the data + nif->skip(count * 5*sizeof(float)); + } }; class NiVisData : public Record { public: - void read(NIFFile *nif) - { - int count = nif->getInt(); - /* - Each VisData consists of: + struct VisData { float time; - byte isSet; + char isSet; + }; - If you implement this, make sure you use a packed struct - (sizeof==5), or read each element individually. - */ - nif->skip(count*5); - } + void read(NIFFile *nif) + { + int count = nif->getInt(); + + /* Skip VisData */ + nif->skip(count*5); + } }; class NiSkinInstance : public Record { public: - NiSkinDataPtr data; - NodePtr root; - NodeList bones; - - void read(NIFFile *nif) - { - data.read(nif); - root.read(nif); - bones.read(nif); + NiSkinDataPtr data; + NodePtr root; + NodeList bones; - if(data.empty() || root.empty()) - nif->fail("NiSkinInstance missing root or data"); - } + void read(NIFFile *nif) + { + data.read(nif); + root.read(nif); + bones.read(nif); + } - void post(NIFFile *nif); + void post(NIFFile *nif); }; class NiSkinData : public Record { public: - // This is to make sure the structs are packed, ie. that the - // compiler doesn't mess them up with extra alignment bytes. -#pragma pack(push) -#pragma pack(1) - - struct BoneTrafo - { - Matrix rotation; // Rotation offset from bone? - Vector trans; // Translation - float scale; // Probably scale (always 1) - }; - struct BoneTrafoCopy - { - Ogre::Quaternion rotation; - Ogre::Vector3 trans; - float scale; - }; - - struct VertWeight - { - short vertex; - float weight; - }; -#pragma pack(pop) - - struct BoneInfo - { - const BoneTrafo *trafo; - const Vector4 *unknown; - Misc::SliceArray weights; - }; - struct BoneInfoCopy - { - std::string bonename; - unsigned short bonehandle; - BoneTrafoCopy trafo; - Vector4 unknown; - //std::vector weights; - }; - struct IndividualWeight - { - float weight; - unsigned int boneinfocopyindex; - }; - - const BoneTrafo *trafo; - std::vector bones; - - void read(NIFFile *nif) - { - assert(sizeof(BoneTrafo) == 4*(9+3+1)); - assert(sizeof(VertWeight) == 6); - - trafo = nif->getPtr(); + struct BoneTrafo + { + Ogre::Matrix3 rotation; // Rotation offset from bone? + Ogre::Vector3 trans; // Translation + float scale; // Probably scale (always 1) + }; + struct BoneTrafoCopy + { + Ogre::Quaternion rotation; + Ogre::Vector3 trans; + float scale; + }; - int boneNum = nif->getInt(); - nif->getInt(); // -1 + struct VertWeight + { + short vertex; + float weight; + }; - bones.resize(boneNum); - for(int i=0;i weights; + }; + struct BoneInfoCopy + { + std::string bonename; + unsigned short bonehandle; + BoneTrafoCopy trafo; + Ogre::Vector4 unknown; + //std::vector weights; + }; + struct IndividualWeight + { + float weight; + unsigned int boneinfocopyindex; + }; - bi.trafo = nif->getPtr(); - bi.unknown = nif->getVector4(); + BoneTrafo trafo; + std::vector bones; - // Number of vertex weights - int count = nif->getShort(); - bi.weights = nif->getArrayLen(count); - } - } + void read(NIFFile *nif) + { + trafo.rotation = nif->getMatrix3(); + trafo.trans = nif->getVector3(); + trafo.scale = nif->getFloat(); + + int boneNum = nif->getInt(); + nif->getInt(); // -1 + + bones.resize(boneNum); + for(int i=0;igetMatrix3(); + bi.trafo.trans = nif->getVector3(); + bi.trafo.scale = nif->getFloat(); + bi.unknown = nif->getVector4(); + + // Number of vertex weights + bi.weights.resize(nif->getUShort()); + for(size_t j = 0;j < bi.weights.size();j++) + { + bi.weights[j].vertex = nif->getUShort(); + bi.weights[j].weight = nif->getFloat(); + } + } + } }; class NiMorphData : public Record { - float startTime; - float stopTime; - std::vector initialVertices; - std::vector > relevantTimes; - std::vector > relevantData; - std::vector > additionalVertices; - + float startTime; + float stopTime; + std::vector initialVertices; + std::vector > relevantTimes; + std::vector > relevantData; + std::vector > additionalVertices; public: - float getStartTime(){ - return startTime; - } - float getStopTime(){ - return stopTime; - } - void setStartTime(float time){ - startTime = time; - } - - void setStopTime(float time){ - stopTime = time; - } - std::vector getInitialVertices(){ - return initialVertices; - } - std::vector > getRelevantData(){ - return relevantData; - } - std::vector > getRelevantTimes(){ - return relevantTimes; - } - std::vector > getAdditionalVertices(){ - return additionalVertices; - } - -void read(NIFFile *nif) - { - int morphCount = nif->getInt(); - int vertCount = nif->getInt(); - nif->getByte(); - int magic = nif->getInt(); - /*int type =*/ nif->getInt(); - for(int i = 0; i < vertCount; i++){ - - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - initialVertices.push_back(Ogre::Vector3(x, y, z)); - } - - for(int i=1; i& getInitialVertices() const + { return initialVertices; } + const std::vector >& getRelevantData() const + { return relevantData; } + const std::vector >& getRelevantTimes() const + { return relevantTimes; } + const std::vector >& getAdditionalVertices() const + { return additionalVertices; } + + void read(NIFFile *nif) { - magic = nif->getInt(); - /*type =*/ nif->getInt(); - std::vector current; - std::vector currentTime; - for(int i = 0; i < magic; i++){ - // Time, data, forward, backward tangents - float time = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - current.push_back(Ogre::Vector3(x,y,z)); - currentTime.push_back(time); - //nif->getFloatLen(4*magic); - } - if(magic){ - relevantData.push_back(current); - relevantTimes.push_back(currentTime); - } - std::vector verts; - for(int i = 0; i < vertCount; i++){ - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - verts.push_back(Ogre::Vector3(x, y, z)); - } - additionalVertices.push_back(verts); - } - } + int morphCount = nif->getInt(); + int vertCount = nif->getInt(); + nif->getChar(); + int magic = nif->getInt(); + /*int type =*/ nif->getInt(); + + for(int i = 0; i < vertCount; i++) + { + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + initialVertices.push_back(Ogre::Vector3(x, y, z)); + } + + for(int i=1; igetInt(); + /*type =*/ nif->getInt(); + std::vector current; + std::vector currentTime; + for(int i = 0; i < magic; i++) + { + // Time, data, forward, backward tangents + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + current.push_back(Ogre::Vector3(x,y,z)); + currentTime.push_back(time); + //nif->getFloatLen(4*magic); + } + + if(magic) + { + relevantData.push_back(current); + relevantTimes.push_back(currentTime); + } + + std::vector verts; + for(int i = 0; i < vertCount; i++) + { + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + verts.push_back(Ogre::Vector3(x, y, z)); + } + additionalVertices.push_back(verts); + } + } }; class NiKeyframeData : public Record { - std::string bonename; - //Rotations - std::vector quats; - std::vector tbc; - std::vector rottime; - float startTime; - float stopTime; - int rtype; - - //Translations - std::vector translist1; - std::vector translist2; - std::vector translist3; - std::vector transtbc; - std::vector transtime; - int ttype; - - //Scalings - - std::vector scalefactor; - std::vector scaletime; - std::vector forwards; - std::vector backwards; - std::vector tbcscale; - int stype; - - + std::string bonename; + //Rotations + std::vector quats; + std::vector tbc; + std::vector rottime; + float startTime; + float stopTime; + int rtype; + + //Translations + std::vector translist1; + std::vector translist2; + std::vector translist3; + std::vector transtbc; + std::vector transtime; + int ttype; + + //Scalings + std::vector scalefactor; + std::vector scaletime; + std::vector forwards; + std::vector backwards; + std::vector tbcscale; + int stype; public: - void clone(NiKeyframeData c) - { - quats = c.getQuat(); - tbc = c.getrTbc(); - rottime = c.getrTime(); + void clone(const NiKeyframeData &c) + { + quats = c.getQuat(); + tbc = c.getrTbc(); + rottime = c.getrTime(); - //types - ttype = c.getTtype(); - rtype = c.getRtype(); - stype = c.getStype(); + //types + ttype = c.getTtype(); + rtype = c.getRtype(); + stype = c.getStype(); - translist1 = c.getTranslist1(); - translist2 = c.getTranslist2(); + translist1 = c.getTranslist1(); + translist2 = c.getTranslist2(); translist3 = c.getTranslist3(); - transtime = c.gettTime(); - - bonename = c.getBonename(); - - - } - - void setBonename(std::string bone) - { - bonename = bone; - } - void setStartTime(float start) - { - startTime = start; - } - void setStopTime(float end) - { - stopTime = end; - } - void read(NIFFile *nif) - { - // Rotations first - int count = nif->getInt(); - //std::vector quat(count); - //std::vector rottime(count); - if(count) - { - - //TYPE1 LINEAR_KEY - //TYPE2 QUADRATIC_KEY - //TYPE3 TBC_KEY - //TYPE4 XYZ_ROTATION_KEY - //TYPE5 UNKNOWN_KEY - rtype = nif->getInt(); - //std::cout << "Count: " << count << "Type: " << type << "\n"; - - if(rtype == 1) - { - //We need to actually read in these values instead of skipping them - //nif->skip(count*4*5); // time + quaternion - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float w = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); - quats.push_back(quat); - rottime.push_back(time); - //if(time == 0.0 || time > 355.5) - // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; - } - } - else if(rtype == 3) - { //Example - node 116 in base_anim.nif - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float w = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - - float tbcx = nif->getFloat(); - float tbcy = nif->getFloat(); - float tbcz = nif->getFloat(); - Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); - Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); - quats.push_back(quat); - rottime.push_back(time); - tbc.push_back(vec); - //if(time == 0.0 || time > 355.5) - // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; - } - - //nif->skip(count*4*8); // rot1 + tension+bias+continuity - } - else if(rtype == 4) - { - for(int j=0;jgetFloat(); // time - for(int i=0; i<3; i++) - { - int cnt = nif->getInt(); - int type = nif->getInt(); - if(type == 1) - nif->skip(cnt*4*2); // time + unknown - else if(type == 2) - nif->skip(cnt*4*4); // time + unknown vector - else nif->fail("Unknown sub-rotation type"); - } - } - } - else nif->fail("Unknown rotation type in NiKeyframeData"); - } - //first = false; - - // Then translation - count = nif->getInt(); - - if(count) - { - ttype = nif->getInt(); - - //std::cout << "TransCount:" << count << " Type: " << type << "\n"; - if(ttype == 1) { - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - Ogre::Vector3 trans = Ogre::Vector3(x, y, z); - translist1.push_back(trans); - transtime.push_back(time); - } - //nif->getFloatLen(count*4); // time + translation - } - else if(ttype == 2) - { //Example - node 116 in base_anim.nif - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - float x2 = nif->getFloat(); - float y2 = nif->getFloat(); - float z2 = nif->getFloat(); - float x3 = nif->getFloat(); - float y3 = nif->getFloat(); - float z3 = nif->getFloat(); - Ogre::Vector3 trans = Ogre::Vector3(x, y, z); - Ogre::Vector3 trans2 = Ogre::Vector3(x2, y2, z2); - Ogre::Vector3 trans3 = Ogre::Vector3(x3, y3, z3); - transtime.push_back(time); - translist1.push_back(trans); - translist2.push_back(trans2); - translist3.push_back(trans3); - } - - //nif->getFloatLen(count*10); // trans1 + forward + backward - } - else if(ttype == 3){ - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - float t = nif->getFloat(); - float b = nif->getFloat(); - float c = nif->getFloat(); - Ogre::Vector3 trans = Ogre::Vector3(x, y, z); - Ogre::Vector3 tbc = Ogre::Vector3(t, b, c); - translist1.push_back(trans); - transtbc.push_back(tbc); - transtime.push_back(time); - } - //nif->getFloatLen(count*7); // trans1 + tension,bias,continuity - } - else nif->fail("Unknown translation type"); - } - - // Finally, scalings - count = nif->getInt(); - if(count) - { - stype = nif->getInt(); - - - for(int i = 0; i < count; i++){ - - - //int size = 0; - if(stype >= 1 && stype < 4) - { - float time = nif->getFloat(); - float scale = nif->getFloat(); - scaletime.push_back(time); - scalefactor.push_back(scale); - //size = 2; // time+scale - } - else nif->fail("Unknown scaling type"); - if(stype == 2){ - //size = 4; // 1 + forward + backward (floats) - float forward = nif->getFloat(); - float backward = nif->getFloat(); - forwards.push_back(forward); - backwards.push_back(backward); - } - else if(stype == 3){ - float tbcx = nif->getFloat(); - float tbcy = nif->getFloat(); - float tbcz = nif->getFloat(); - Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); - tbcscale.push_back(vec); - - //size = 5; // 1 + tbc - } - - } - } - else - stype = 0; - } - int getRtype(){ - return rtype; - } - int getStype(){ - return stype; - } - int getTtype(){ - return ttype; - } - float getStartTime(){ - return startTime; - } - float getStopTime(){ - return stopTime; - } - std::vector getQuat(){ - return quats; - } - std::vector getrTbc(){ - return tbc; - } - std::vector getrTime(){ - return rottime; - } - - std::vector getTranslist1(){ - return translist1; - } - std::vector getTranslist2(){ - return translist2; - } - std::vector getTranslist3(){ - return translist3; - } - std::vector gettTime(){ - return transtime; - } - std::vector getScalefactor(){ - return scalefactor; - } - std::vector getForwards(){ - return forwards; - } - std::vector getBackwards(){ - return backwards; - } - std::vector getScaleTbc(){ - return tbcscale; - } - - std::vector getsTime(){ - return scaletime; - } - std::string getBonename(){ return bonename; - } + transtime = c.gettTime(); + bonename = c.getBonename(); + } + void setBonename(std::string bone) + { bonename = bone; } + void setStartTime(float start) + { startTime = start; } + void setStopTime(float end) + { stopTime = end; } + + void read(NIFFile *nif) + { + // Rotations first + int count = nif->getInt(); + //std::vector quat(count); + //std::vector rottime(count); + if(count) + { + //TYPE1 LINEAR_KEY + //TYPE2 QUADRATIC_KEY + //TYPE3 TBC_KEY + //TYPE4 XYZ_ROTATION_KEY + //TYPE5 UNKNOWN_KEY + rtype = nif->getInt(); + //std::cout << "Count: " << count << "Type: " << type << "\n"; + + if(rtype == 1) + { + //We need to actually read in these values instead of skipping them + //nif->skip(count*4*5); // time + quaternion + for (int i = 0; i < count; i++) + { + float time = nif->getFloat(); + float w = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); + quats.push_back(quat); + rottime.push_back(time); + //if(time == 0.0 || time > 355.5) + // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; + } + } + else if(rtype == 3) + { + //Example - node 116 in base_anim.nif + for (int i = 0; i < count; i++) + { + float time = nif->getFloat(); + float w = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + + float tbcx = nif->getFloat(); + float tbcy = nif->getFloat(); + float tbcz = nif->getFloat(); + + Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); + Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); + quats.push_back(quat); + rottime.push_back(time); + tbc.push_back(vec); + //if(time == 0.0 || time > 355.5) + // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; + } + } + else if(rtype == 4) + { + for(int j=0;jgetFloat(); // time + for(int i=0; i<3; i++) + { + int cnt = nif->getInt(); + int type = nif->getInt(); + if(type == 1) + nif->skip(cnt*4*2); // time + unknown + else if(type == 2) + nif->skip(cnt*4*4); // time + unknown vector + else + nif->fail("Unknown sub-rotation type"); + } + } + } + else + nif->fail("Unknown rotation type in NiKeyframeData"); + } + //first = false; + + // Then translation + count = nif->getInt(); + if(count) + { + ttype = nif->getInt(); + + //std::cout << "TransCount:" << count << " Type: " << type << "\n"; + if(ttype == 1) + { + for(int i = 0; i < count; i++) + { + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + + Ogre::Vector3 trans = Ogre::Vector3(x, y, z); + translist1.push_back(trans); + transtime.push_back(time); + } + //nif->getFloatLen(count*4); // time + translation + } + else if(ttype == 2) + { + //Example - node 116 in base_anim.nif + for(int i = 0; i < count; i++) + { + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + float x2 = nif->getFloat(); + float y2 = nif->getFloat(); + float z2 = nif->getFloat(); + float x3 = nif->getFloat(); + float y3 = nif->getFloat(); + float z3 = nif->getFloat(); + + Ogre::Vector3 trans = Ogre::Vector3(x, y, z); + Ogre::Vector3 trans2 = Ogre::Vector3(x2, y2, z2); + Ogre::Vector3 trans3 = Ogre::Vector3(x3, y3, z3); + transtime.push_back(time); + translist1.push_back(trans); + translist2.push_back(trans2); + translist3.push_back(trans3); + } + + //nif->getFloatLen(count*10); // trans1 + forward + backward + } + else if(ttype == 3) + { + for(int i = 0; i < count; i++) + { + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + float t = nif->getFloat(); + float b = nif->getFloat(); + float c = nif->getFloat(); + Ogre::Vector3 trans = Ogre::Vector3(x, y, z); + Ogre::Vector3 tbc = Ogre::Vector3(t, b, c); + translist1.push_back(trans); + transtbc.push_back(tbc); + transtime.push_back(time); + } + //nif->getFloatLen(count*7); // trans1 + tension,bias,continuity + } + else nif->fail("Unknown translation type"); + } + + // Finally, scalings + count = nif->getInt(); + if(count) + { + stype = nif->getInt(); + + for(int i = 0; i < count; i++) + { + //int size = 0; + if(stype >= 1 && stype < 4) + { + float time = nif->getFloat(); + float scale = nif->getFloat(); + scaletime.push_back(time); + scalefactor.push_back(scale); + //size = 2; // time+scale + } + else + nif->fail("Unknown scaling type"); + + if(stype == 2) + { + //size = 4; // 1 + forward + backward (floats) + float forward = nif->getFloat(); + float backward = nif->getFloat(); + forwards.push_back(forward); + backwards.push_back(backward); + } + else if(stype == 3) + { + //size = 5; // 1 + tbc + float tbcx = nif->getFloat(); + float tbcy = nif->getFloat(); + float tbcz = nif->getFloat(); + Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); + tbcscale.push_back(vec); + } + } + } + else + stype = 0; + } + + int getRtype() const + { return rtype; } + int getStype() const + { return stype; } + int getTtype() const + { return ttype; } + float getStartTime() const + { return startTime; } + float getStopTime() const + { return stopTime; } + const std::vector& getQuat() const + { return quats; } + const std::vector& getrTbc() const + { return tbc; } + const std::vector& getrTime() const + { return rottime; } + + const std::vector& getTranslist1() const + { return translist1; } + const std::vector& getTranslist2() const + { return translist2; } + const std::vector& getTranslist3() const + { return translist3; } + const std::vector& gettTime() const + { return transtime; } + const std::vector& getScalefactor() const + { return scalefactor; } + const std::vector& getForwards() const + { return forwards; } + const std::vector& getBackwards() const + { return backwards; } + const std::vector& getScaleTbc() const + { return tbcscale; } + + const std::vector& getsTime() const + { return scaletime; } + const std::string& getBonename() const + { return bonename; } }; } // Namespace diff --git a/components/nif/effect.hpp b/components/nif/effect.hpp index b0cc64228..850415dad 100644 --- a/components/nif/effect.hpp +++ b/components/nif/effect.hpp @@ -35,57 +35,70 @@ typedef Node Effect; // NiPointLight and NiSpotLight? struct NiLight : Effect { - struct SLight - { - float dimmer; - Vector ambient; - Vector diffuse; - Vector specular; - }; - - const SLight *light; - - void read(NIFFile *nif) - { - Effect::read(nif); - - nif->getInt(); // 1 - nif->getInt(); // 1? - light = nif->getPtr(); - } + struct SLight + { + float dimmer; + Ogre::Vector3 ambient; + Ogre::Vector3 diffuse; + Ogre::Vector3 specular; + + void read(NIFFile *nif) + { + dimmer = nif->getFloat(); + ambient = nif->getVector3(); + diffuse = nif->getVector3(); + specular = nif->getVector3(); + } + }; + SLight light; + + void read(NIFFile *nif) + { + Effect::read(nif); + + nif->getInt(); // 1 + nif->getInt(); // 1? + light.read(nif); + } }; struct NiTextureEffect : Effect { - NiSourceTexturePtr texture; - - void read(NIFFile *nif) - { - Effect::read(nif); - - int tmp = nif->getInt(); - if(tmp) nif->getInt(); // always 1? - - /* - 3 x Vector4 = [1,0,0,0] - int = 2 - int = 0 or 3 - int = 2 - int = 2 - */ - nif->skip(16*4); - - texture.read(nif); - - /* - byte = 0 - vector4 = [1,0,0,0] - short = 0 - short = -75 - short = 0 - */ - nif->skip(23); - } + NiSourceTexturePtr texture; + + void read(NIFFile *nif) + { + Effect::read(nif); + + int tmp = nif->getInt(); + if(tmp) nif->getInt(); // always 1? + + /* + 3 x Vector4 = [1,0,0,0] + int = 2 + int = 0 or 3 + int = 2 + int = 2 + */ + nif->skip(16*4); + + texture.read(nif); + + /* + byte = 0 + vector4 = [1,0,0,0] + short = 0 + short = -75 + short = 0 + */ + nif->skip(23); + } + + void post(NIFFile *nif) + { + Effect::post(nif); + texture.post(nif); + } }; } // Namespace diff --git a/components/nif/extra.hpp b/components/nif/extra.hpp index eec1aa7b4..35781dbf5 100644 --- a/components/nif/extra.hpp +++ b/components/nif/extra.hpp @@ -38,70 +38,70 @@ namespace Nif class Extra : public Record { public: - ExtraPtr extra; + ExtraPtr extra; - void read(NIFFile *nif) { extra.read(nif); } + void read(NIFFile *nif) { extra.read(nif); } + void post(NIFFile *nif) { extra.post(nif); } }; class NiVertWeightsExtraData : public Extra { public: - void read(NIFFile *nif) - { - Extra::read(nif); + void read(NIFFile *nif) + { + Extra::read(nif); - // We should have s*4+2 == i, for some reason. Might simply be the - // size of the rest of the record, unhelpful as that may be. - /*int i =*/ nif->getInt(); - int s = nif->getShort(); // number of vertices + // We should have s*4+2 == i, for some reason. Might simply be the + // size of the rest of the record, unhelpful as that may be. + /*int i =*/ nif->getInt(); + int s = nif->getUShort(); - nif->getFloatLen(s); // vertex weights I guess - } + nif->skip(s * sizeof(float)); // vertex weights I guess + } }; class NiTextKeyExtraData : public Extra { public: - struct TextKey - { - float time; - Misc::SString text; - }; - - std::vector list; - - void read(NIFFile *nif) - { - Extra::read(nif); - - nif->getInt(); // 0 - - int keynum = nif->getInt(); - list.resize(keynum); - for(int i=0; igetFloat(); - list[i].text = nif->getString(); - } - } + struct TextKey + { + float time; + std::string text; + }; + std::vector list; + + void read(NIFFile *nif) + { + Extra::read(nif); + + nif->getInt(); // 0 + + int keynum = nif->getInt(); + list.resize(keynum); + for(int i=0; igetFloat(); + list[i].text = nif->getString(); + } + } }; class NiStringExtraData : public Extra { public: - /* Two known meanings: - "MRK" - marker, only visible in the editor, not rendered in-game - "NCO" - no collision - */ - Misc::SString string; - - void read(NIFFile *nif) - { - Extra::read(nif); - - nif->getInt(); // size of string + 4. Really useful... - string = nif->getString(); - } + /* Two known meanings: + "MRK" - marker, only visible in the editor, not rendered in-game + "NCO" - no collision + */ + std::string string; + + void read(NIFFile *nif) + { + Extra::read(nif); + + nif->getInt(); // size of string + 4. Really useful... + string = nif->getString(); + } }; } // Namespace diff --git a/components/nif/nif_file.cpp b/components/nif/nif_file.cpp index 80ea7a0b7..36badbf0d 100644 --- a/components/nif/nif_file.cpp +++ b/components/nif/nif_file.cpp @@ -46,8 +46,8 @@ using namespace Misc; void NIFFile::parse() { // Check the header string - const char* head = getString(40); - if(!begins(head, "NetImmerse File Format")) + std::string head = getString(40); + if(head.compare(0, 22, "NetImmerse File Format") != 0) fail("Invalid NIF header"); // Get BCD version @@ -70,7 +70,7 @@ void NIFFile::parse() for(int i=0;irecType != RC_MISSING); @@ -190,17 +190,23 @@ void NIFFile::parse() void NiSkinInstance::post(NIFFile *nif) { - int bnum = bones.length(); - if(bnum != static_cast (data->bones.size())) - nif->fail("Mismatch in NiSkinData bone count"); + data.post(nif); + root.post(nif); + bones.post(nif); - root->makeRootBone(data->trafo); + if(data.empty() || root.empty()) + nif->fail("NiSkinInstance missing root or data"); - for(int i=0; ifail("Oops: Missing bone! Don't know how to handle this."); + size_t bnum = bones.length(); + if(bnum != data->bones.size()) + nif->fail("Mismatch in NiSkinData bone count"); + + root->makeRootBone(&data->trafo); - bones[i].makeBone(i, data->bones[i]); + for(size_t i=0; ifail("Oops: Missing bone! Don't know how to handle this."); + bones[i].makeBone(i, data->bones[i]); } } diff --git a/components/nif/nif_file.hpp b/components/nif/nif_file.hpp index 951ae1f75..4072b4307 100644 --- a/components/nif/nif_file.hpp +++ b/components/nif/nif_file.hpp @@ -24,133 +24,175 @@ #ifndef _NIF_FILE_H_ #define _NIF_FILE_H_ -#include -#include -#include +#include +#include +#include +#include +#include #include #include -#include -#include +#include #include "record.hpp" #include "nif_types.hpp" -using namespace Mangle::Stream; - namespace Nif { class NIFFile { - enum NIFVersion - { - VER_MW = 0x04000002 // Morrowind NIFs + enum NIFVersion { + VER_MW = 0x04000002 // Morrowind NIFs }; - /// Nif file version - int ver; + /// Nif file version + int ver; - /// Input stream - StreamPtr inp; + /// Input stream + Ogre::DataStreamPtr inp; - /// File name, used for error messages - std::string filename; + /// File name, used for error messages + std::string filename; - /// Record list - std::vector records; + /// Record list + std::vector records; - /// Parse the file - void parse(); + /// Parse the file + void parse(); - public: - /// Used for error handling - void fail(const std::string &msg) + uint8_t read_byte() { - std::string err = "NIFFile Error: " + msg; - err += "\nFile: " + filename; - throw std::runtime_error(err); + uint8_t byte; + if(inp->read(&byte, 1) != 1) return 0; + return byte; } - - /// Open a NIF stream. The name is used for error messages. - NIFFile(StreamPtr nif, const std::string &name) - : filename(name) + uint16_t read_le16() { - /* Load the entire file into memory. This allows us to use - direct pointers to the data arrays in the NIF, instead of - individually allocating and copying each one. - - The NIF data is only stored temporarily in memory, since once - the mesh data is loaded it is siphoned into OGRE and - deleted. For that reason, we might improve this further and - use a shared region/pool based allocation scheme in the - future, especially since only one NIFFile will ever be loaded - at any given time. - */ - inp = StreamPtr(new BufferStream(nif)); + uint8_t buffer[2]; + if(inp->read(buffer, 2) != 2) return 0; + return buffer[0] | (buffer[1]<<8); + } + uint32_t read_le32() + { + uint8_t buffer[4]; + if(inp->read(buffer, 4) != 4) return 0; + return buffer[0] | (buffer[1]<<8) | (buffer[2]<<16) | (buffer[3]<<24); + } + float read_le32f() + { + union { + uint32_t i; + float f; + } u = { read_le32() }; + return u.f; + } - parse(); +public: + /// Used for error handling + void fail(const std::string &msg) + { + std::string err = "NIFFile Error: " + msg; + err += "\nFile: " + filename; + throw std::runtime_error(err); } - ~NIFFile() + /// Open a NIF stream. The name is used for error messages. + NIFFile(const std::string &name) + : filename(name) { - for(std::size_t i=0; i= 0 && index < static_cast (records.size())); - Record *res = records[index]; - assert(res != NULL); - return res; - } + ~NIFFile() + { + for(std::size_t i=0; igetPtr(size); } - - template const X* getPtr() { return (const X*)inp->getPtr(sizeof(X)); } - template X getType() { return *getPtr(); } - unsigned short getShort() { return getType(); } - int getInt() { return getType(); } - float getFloat() { return getType(); } - char getByte() { return getType(); } - - template - Misc::SliceArray getArrayLen(int num) - { return Misc::SliceArray((const X*)inp->getPtr(num*sizeof(X)),num); } + void skip(size_t size) { inp->skip(size); } - template - Misc::SliceArray getArray() + char getChar() { return read_byte(); } + short getShort() { return read_le16(); } + unsigned short getUShort() { return read_le16(); } + int getInt() { return read_le32(); } + float getFloat() { return read_le32f(); } + Ogre::Vector3 getVector3() { - int len = getInt(); - return getArrayLen(len); + float a[3]; + for(size_t i = 0;i < 3;i++) + a[i] = getFloat(); + return Ogre::Vector3(a); + } + Ogre::Vector4 getVector4() + { + float a[4]; + for(size_t i = 0;i < 4;i++) + a[i] = getFloat(); + return Ogre::Vector4(a); + } + Ogre::Matrix3 getMatrix3() + { + Ogre::Real a[3][3]; + for(size_t i = 0;i < 3;i++) + { + for(size_t j = 0;j < 3;j++) + a[i][j] = Ogre::Real(getFloat()); + } + return Ogre::Matrix3(a); + } + Transformation getTrafo() + { + Transformation t; + t.pos = getVector3(); + t.rotation = getMatrix3(); + t.scale = getFloat(); + t.velocity = getVector3(); + return t; } - Misc::SString getString() { return getArray(); } - - const Vector *getVector() { return getPtr(); } - const Matrix *getMatrix() { return getPtr(); } - const Transformation *getTrafo() { return getPtr(); } - const Vector4 *getVector4() { return getPtr(); } - - Misc::FloatArray getFloatLen(int num) - { return getArrayLen(num); } + std::string getString(size_t length) + { + std::string str; + str.resize(length); + if(inp->read(&str[0], length) != length) + return std::string(); + return str.substr(0, str.find('\0')); + } + std::string getString() + { + size_t size = read_le32(); + return getString(size); + } - // For fixed-size strings where you already know the size - const char *getString(int size) - { return (const char*)inp->getPtr(size); } + void getShorts(std::vector &vec, size_t size) + { + vec.resize(size); + for(size_t i = 0;i < vec.size();i++) + vec[i] = getShort(); + } + void getFloats(std::vector &vec, size_t size) + { + vec.resize(size); + for(size_t i = 0;i < vec.size();i++) + vec[i] = getFloat(); + } }; } // Namespace diff --git a/components/nif/nif_types.hpp b/components/nif/nif_types.hpp index ee796cc99..705ed5994 100644 --- a/components/nif/nif_types.hpp +++ b/components/nif/nif_types.hpp @@ -24,59 +24,37 @@ #ifndef _NIF_TYPES_H_ #define _NIF_TYPES_H_ +#include +#include + // Common types used in NIF files namespace Nif { -/* These packing #pragmas aren't really necessary on 32 bit - machines. I haven't tested on 64 bit yet. In any case it doesn't - hurt to include them. We can't allow any compiler-generated padding - in any of these structs, since they are used to interface directly - with raw data from the NIF files. -*/ -#pragma pack(push) -#pragma pack(1) - -struct Vector -{ - float array[3]; -}; - -struct Vector4 -{ - float array[4]; -}; - -struct Matrix -{ - Vector v[3]; -}; - struct Transformation { - Vector pos; - Matrix rotation; + Ogre::Vector3 pos; + Ogre::Matrix3 rotation; float scale; - Vector velocity; + Ogre::Vector3 velocity; - static const Transformation* getIdentity() + static const Transformation& getIdentity() { static Transformation identity; static bool iset = false; if (!iset) { identity.scale = 1.0f; - identity.rotation.v[0].array[0] = 1.0f; - identity.rotation.v[1].array[1] = 1.0f; - identity.rotation.v[2].array[2] = 1.0f; + identity.rotation[0][0] = 1.0f; + identity.rotation[1][1] = 1.0f; + identity.rotation[2][2] = 1.0f; iset = true; } - return &identity; + return identity; } }; -#pragma pack(pop) } // Namespace #endif diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 080042746..64ef1e3e9 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -26,10 +26,13 @@ #include "controlled.hpp" #include "data.hpp" +#include "property.hpp" namespace Nif { +class NiNode; + /** A Node is an object that's part of the main NIF tree. It has parent node (unless it's the root), and transformation (location and rotation) relative to it's parent. @@ -37,191 +40,250 @@ namespace Nif class Node : public Named { public: - // Node flags. Interpretation depends somewhat on the type of node. - int flags; - const Transformation *trafo; - PropertyList props; - - // Bounding box info - bool hasBounds; - const Vector *boundPos; - const Matrix *boundRot; - const Vector *boundXYZ; // Box size - - void read(NIFFile *nif) - { - Named::read(nif); - - flags = nif->getShort(); - trafo = nif->getTrafo(); - props.read(nif); - - hasBounds = !!nif->getInt(); - if(hasBounds) - { - nif->getInt(); // always 1 - boundPos = nif->getVector(); - boundRot = nif->getMatrix(); - boundXYZ = nif->getVector(); - } - - boneTrafo = NULL; - boneIndex = -1; - } - - // Bone transformation. If set, node is a part of a skeleton. - const NiSkinData::BoneTrafo *boneTrafo; - - // Bone weight info, from NiSkinData - const NiSkinData::BoneInfo *boneInfo; - - // Bone index. If -1, this node is either not a bone, or if - // boneTrafo is set it is the root bone in the skeleton. - short boneIndex; - - void makeRootBone(const NiSkinData::BoneTrafo *tr) - { - boneTrafo = tr; - boneIndex = -1; - } - - void makeBone(short ind, const NiSkinData::BoneInfo &bi) - { - boneInfo = &bi; - boneTrafo = bi.trafo; - boneIndex = ind; - } + // Node flags. Interpretation depends somewhat on the type of node. + int flags; + Transformation trafo; + PropertyList props; + + // Bounding box info + bool hasBounds; + Ogre::Vector3 boundPos; + Ogre::Matrix3 boundRot; + Ogre::Vector3 boundXYZ; // Box size + + void read(NIFFile *nif) + { + Named::read(nif); + + flags = nif->getUShort(); + trafo = nif->getTrafo(); + props.read(nif); + + hasBounds = !!nif->getInt(); + if(hasBounds) + { + nif->getInt(); // always 1 + boundPos = nif->getVector3(); + boundRot = nif->getMatrix3(); + boundXYZ = nif->getVector3(); + } + + parent = NULL; + + boneTrafo = NULL; + boneIndex = -1; + } + + void post(NIFFile *nif) + { + Named::post(nif); + props.post(nif); + } + + // Parent node, or NULL for the root node. As far as I'm aware, only + // NiNodes (or types derived from NiNodes) can be parents. + NiNode *parent; + + // Bone transformation. If set, node is a part of a skeleton. + const NiSkinData::BoneTrafo *boneTrafo; + + // Bone weight info, from NiSkinData + const NiSkinData::BoneInfo *boneInfo; + + // Bone index. If -1, this node is either not a bone, or if + // boneTrafo is set it is the root bone in the skeleton. + short boneIndex; + + void makeRootBone(const NiSkinData::BoneTrafo *tr) + { + boneTrafo = tr; + boneIndex = -1; + } + + void makeBone(short ind, const NiSkinData::BoneInfo &bi) + { + boneInfo = &bi; + boneTrafo = &bi.trafo; + boneIndex = ind; + } }; struct NiTriShapeCopy { - std::string sname; - std::vector boneSequence; - Nif::NiSkinData::BoneTrafoCopy trafo; - //Ogre::Quaternion initialBoneRotation; - //Ogre::Vector3 initialBoneTranslation; - std::vector vertices; - std::vector normals; - std::vector boneinfo; - std::map > vertsToWeights; - Nif::NiMorphData morph; + std::string sname; + std::vector boneSequence; + Nif::NiSkinData::BoneTrafoCopy trafo; + //Ogre::Quaternion initialBoneRotation; + //Ogre::Vector3 initialBoneTranslation; + std::vector vertices; + std::vector normals; + std::vector boneinfo; + std::map > vertsToWeights; + Nif::NiMorphData morph; }; struct NiNode : Node { - NodeList children; - NodeList effects; - - /* Known NiNode flags: - - 0x01 hidden - 0x02 use mesh for collision - 0x04 use bounding box for collision (?) - 0x08 unknown, but common - 0x20, 0x40, 0x80 unknown - */ - - void read(NIFFile *nif) - { - Node::read(nif); - children.read(nif); - effects.read(nif); - } + NodeList children; + NodeList effects; + + /* Known NiNode flags: + 0x01 hidden + 0x02 use mesh for collision + 0x04 use bounding box for collision (?) + 0x08 unknown, but common + 0x20, 0x40, 0x80 unknown + */ + + void read(NIFFile *nif) + { + Node::read(nif); + children.read(nif); + effects.read(nif); + } + + void post(NIFFile *nif) + { + Node::post(nif); + children.post(nif); + effects.post(nif); + + for(size_t i = 0;i < children.length();i++) + { + // Why would a unique list of children contain empty refs? + if(children.has(i)) + children[i].parent = this; + } + } }; struct NiTriShape : Node { - /* Possible flags: - 0x40 - mesh has no vertex normals ? - - Only flags included in 0x47 (ie. 0x01, 0x02, 0x04 and 0x40) have - been observed so far. - */ - - NiTriShapeDataPtr data; - NiSkinInstancePtr skin; - - void read(NIFFile *nif) - { - Node::read(nif); - data.read(nif); - skin.read(nif); - } - - NiTriShapeCopy clone(){ - NiTriShapeCopy copy; - copy.sname = name.toString(); - float *ptr = (float*)data->vertices.ptr; - float *ptrNormals = (float*)data->normals.ptr; - int numVerts = data->vertices.length / 3; - for(int i = 0; i < numVerts; i++) - { - float *current = (float*) (ptr + i * 3); - copy.vertices.push_back(Ogre::Vector3(*current, *(current + 1), *(current + 2))); - - if(ptrNormals){ - float *currentNormals = (float*) (ptrNormals + i * 3); - copy.normals.push_back(Ogre::Vector3(*currentNormals, *(currentNormals + 1), *(currentNormals + 2))); - } - } - - - return copy; - } + /* Possible flags: + 0x40 - mesh has no vertex normals ? + + Only flags included in 0x47 (ie. 0x01, 0x02, 0x04 and 0x40) have + been observed so far. + */ + + NiTriShapeDataPtr data; + NiSkinInstancePtr skin; + + void read(NIFFile *nif) + { + Node::read(nif); + data.read(nif); + skin.read(nif); + } + + void post(NIFFile *nif) + { + Node::post(nif); + data.post(nif); + skin.post(nif); + } + + NiTriShapeCopy clone() + { + NiTriShapeCopy copy; + copy.sname = name; + float *ptr = (float*)&data->vertices[0]; + float *ptrNormals = (float*)&data->normals[0]; + int numVerts = data->vertices.size() / 3; + for(int i = 0; i < numVerts; i++) + { + float *current = (float*) (ptr + i * 3); + copy.vertices.push_back(Ogre::Vector3(*current, *(current + 1), *(current + 2))); + + if(ptrNormals) + { + float *currentNormals = (float*) (ptrNormals + i * 3); + copy.normals.push_back(Ogre::Vector3(*currentNormals, *(currentNormals + 1), *(currentNormals + 2))); + } + } + + return copy; + } }; struct NiCamera : Node { - struct Camera - { - // Camera frustrum - float left, right, top, bottom, nearDist, farDist; - - // Viewport - float vleft, vright, vtop, vbottom; - - // Level of detail modifier - float LOD; - }; - - const Camera *cam; - - void read(NIFFile *nif) - { - Node::read(nif); - - nif->getPtr(); - - nif->getInt(); // -1 - nif->getInt(); // 0 - } + struct Camera + { + // Camera frustrum + float left, right, top, bottom, nearDist, farDist; + + // Viewport + float vleft, vright, vtop, vbottom; + + // Level of detail modifier + float LOD; + + void read(NIFFile *nif) + { + left = nif->getFloat(); + right = nif->getFloat(); + top = nif->getFloat(); + bottom = nif->getFloat(); + nearDist = nif->getFloat(); + farDist = nif->getFloat(); + + vleft = nif->getFloat(); + vright = nif->getFloat(); + vtop = nif->getFloat(); + vbottom = nif->getFloat(); + + LOD = nif->getFloat(); + } + }; + Camera cam; + + void read(NIFFile *nif) + { + Node::read(nif); + + cam.read(nif); + + nif->getInt(); // -1 + nif->getInt(); // 0 + } }; struct NiAutoNormalParticles : Node { - NiAutoNormalParticlesDataPtr data; - - void read(NIFFile *nif) - { - Node::read(nif); - data.read(nif); - nif->getInt(); // -1 - } + NiAutoNormalParticlesDataPtr data; + + void read(NIFFile *nif) + { + Node::read(nif); + data.read(nif); + nif->getInt(); // -1 + } + + void post(NIFFile *nif) + { + Node::post(nif); + data.post(nif); + } }; struct NiRotatingParticles : Node { - NiRotatingParticlesDataPtr data; - - void read(NIFFile *nif) - { - Node::read(nif); - data.read(nif); - nif->getInt(); // -1 - } + NiRotatingParticlesDataPtr data; + + void read(NIFFile *nif) + { + Node::read(nif); + data.read(nif); + nif->getInt(); // -1 + } + + void post(NIFFile *nif) + { + Node::post(nif); + data.post(nif); + } }; - - } // Namespace #endif diff --git a/components/nif/property.hpp b/components/nif/property.hpp index 1a16854af..b24e49b47 100644 --- a/components/nif/property.hpp +++ b/components/nif/property.hpp @@ -32,104 +32,116 @@ namespace Nif class Property : public Named { public: - // The meaning of these depends on the actual property type. - int flags; - - void read(NIFFile *nif) - { - Named::read(nif); - flags = nif->getShort(); - } + // The meaning of these depends on the actual property type. + int flags; + + void read(NIFFile *nif) + { + Named::read(nif); + flags = nif->getUShort(); + } }; class NiTexturingProperty : public Property { public: - // A sub-texture - struct Texture - { - /* Clamp mode - 0 - clampS clampT - 1 - clampS wrapT - 2 - wrapS clampT - 3 - wrapS wrapT - */ - - /* Filter: - 0 - nearest - 1 - bilinear - 2 - trilinear - 3, 4, 5 - who knows + // A sub-texture + struct Texture + { + /* Clamp mode + 0 - clampS clampT + 1 - clampS wrapT + 2 - wrapS clampT + 3 - wrapS wrapT + */ + + /* Filter: + 0 - nearest + 1 - bilinear + 2 - trilinear + 3, 4, 5 - who knows + */ + bool inUse; + NiSourceTexturePtr texture; + + int clamp, set, filter; + short unknown2; + + void read(NIFFile *nif) + { + inUse = !!nif->getInt(); + if(!inUse) return; + + texture.read(nif); + clamp = nif->getInt(); + filter = nif->getInt(); + set = nif->getInt(); + + // I have no idea, but I think these are actually two + // PS2-specific shorts (ps2L and ps2K), followed by an unknown + // short. + nif->skip(6); + } + + void post(NIFFile *nif) + { + texture.post(nif); + } + }; + + /* Apply mode: + 0 - replace + 1 - decal + 2 - modulate + 3 - hilight // These two are for PS2 only? + 4 - hilight2 */ - bool inUse; - NiSourceTexturePtr texture; - - int clamp, set, filter; - short unknown2; + int apply; + + /* + * The textures in this list are as follows: + * + * 0 - Base texture + * 1 - Dark texture + * 2 - Detail texture + * 3 - Gloss texture (never used?) + * 4 - Glow texture + * 5 - Bump map texture + * 6 - Decal texture + */ + Texture textures[7]; void read(NIFFile *nif) { - inUse = !!nif->getInt(); - if(!inUse) return; - - texture.read(nif); - clamp = nif->getInt(); - filter = nif->getInt(); - set = nif->getInt(); - - // I have no idea, but I think these are actually two - // PS2-specific shorts (ps2L and ps2K), followed by an unknown - // short. - nif->skip(6); + Property::read(nif); + apply = nif->getInt(); + + // Unknown, always 7. Probably the number of textures to read + // below + nif->getInt(); + + textures[0].read(nif); // Base + textures[1].read(nif); // Dark + textures[2].read(nif); // Detail + textures[3].read(nif); // Gloss (never present) + textures[4].read(nif); // Glow + textures[5].read(nif); // Bump map + if(textures[5].inUse) + { + // Ignore these at the moment + /*float lumaScale =*/ nif->getFloat(); + /*float lumaOffset =*/ nif->getFloat(); + /*const Vector4 *lumaMatrix =*/ nif->getVector4(); + } + textures[6].read(nif); // Decal + } + + void post(NIFFile *nif) + { + Property::post(nif); + for(int i = 0;i < 7;i++) + textures[i].post(nif); } - }; - - /* Apply mode: - 0 - replace - 1 - decal - 2 - modulate - 3 - hilight // These two are for PS2 only? - 4 - hilight2 - */ - int apply; - - /* - * The textures in this list are as follows: - * - * 0 - Base texture - * 1 - Dark texture - * 2 - Detail texture - * 3 - Gloss texture (never used?) - * 4 - Glow texture - * 5 - Bump map texture - * 6 - Decal texture - */ - Texture textures[7]; - - void read(NIFFile *nif) - { - Property::read(nif); - apply = nif->getInt(); - - // Unknown, always 7. Probably the number of textures to read - // below - nif->getInt(); - - textures[0].read(nif); // Base - textures[1].read(nif); // Dark - textures[2].read(nif); // Detail - textures[3].read(nif); // Gloss (never present) - textures[4].read(nif); // Glow - textures[5].read(nif); // Bump map - if(textures[5].inUse) - { - // Ignore these at the moment - /*float lumaScale =*/ nif->getFloat(); - /*float lumaOffset =*/ nif->getFloat(); - /*const Vector4 *lumaMatrix =*/ nif->getVector4(); - } - textures[6].read(nif); // Decal - } }; // These contain no other data than the 'flags' field in Property @@ -140,88 +152,109 @@ typedef Property NiSpecularProperty; typedef Property NiWireframeProperty; // The rest are all struct-based -template +template struct StructPropT : Property { - const Struct* data; + T data; - void read(NIFFile *nif) - { - Property::read(nif); - data = nif->getPtr(); - } + void read(NIFFile *nif) + { + Property::read(nif); + data.read(nif); + } }; struct S_MaterialProperty { - // The vector components are R,G,B - Vector ambient, diffuse, specular, emissive; - float glossiness, alpha; + // The vector components are R,G,B + Ogre::Vector3 ambient, diffuse, specular, emissive; + float glossiness, alpha; + + void read(NIFFile *nif) + { + ambient = nif->getVector3(); + diffuse = nif->getVector3(); + specular = nif->getVector3(); + emissive = nif->getVector3(); + glossiness = nif->getFloat(); + alpha = nif->getFloat(); + } }; struct S_VertexColorProperty { - /* Vertex mode: - 0 - source ignore - 1 - source emmisive - 2 - source amb diff - - Lighting mode - 0 - lighting emmisive - 1 - lighting emmisive ambient/diffuse - */ - int vertmode, lightmode; + /* Vertex mode: + 0 - source ignore + 1 - source emmisive + 2 - source amb diff + + Lighting mode + 0 - lighting emmisive + 1 - lighting emmisive ambient/diffuse + */ + int vertmode, lightmode; + + void read(NIFFile *nif) + { + vertmode = nif->getInt(); + lightmode = nif->getInt(); + } }; struct S_AlphaProperty { - /* - In NiAlphaProperty, the flags have the following meaning: - - Bit 0 : alpha blending enable - Bits 1-4 : source blend mode - Bits 5-8 : destination blend mode - Bit 9 : alpha test enable - Bit 10-12 : alpha test mode - Bit 13 : no sorter flag ( disables triangle sorting ) - - blend modes (glBlendFunc): - 0000 GL_ONE - 0001 GL_ZERO - 0010 GL_SRC_COLOR - 0011 GL_ONE_MINUS_SRC_COLOR - 0100 GL_DST_COLOR - 0101 GL_ONE_MINUS_DST_COLOR - 0110 GL_SRC_ALPHA - 0111 GL_ONE_MINUS_SRC_ALPHA - 1000 GL_DST_ALPHA - 1001 GL_ONE_MINUS_DST_ALPHA - 1010 GL_SRC_ALPHA_SATURATE - - test modes (glAlphaFunc): - 000 GL_ALWAYS - 001 GL_LESS - 010 GL_EQUAL - 011 GL_LEQUAL - 100 GL_GREATER - 101 GL_NOTEQUAL - 110 GL_GEQUAL - 111 GL_NEVER - - Taken from: - http://niftools.sourceforge.net/doc/nif/NiAlphaProperty.html - - Right now we only use standard alpha blending (see the Ogre code - that sets it up) and it appears that this is the only blending - used in the original game. Bloodmoon (along with several mods) do - however use other settings, such as discarding pixel values with - alpha < 1.0. This is faster because we don't have to mess with the - depth stuff like we did for blending. And OGRE has settings for - this too. - */ - - // Tested against when certain flags are set (see above.) - unsigned char threshold; + /* + In NiAlphaProperty, the flags have the following meaning: + + Bit 0 : alpha blending enable + Bits 1-4 : source blend mode + Bits 5-8 : destination blend mode + Bit 9 : alpha test enable + Bit 10-12 : alpha test mode + Bit 13 : no sorter flag ( disables triangle sorting ) + + blend modes (glBlendFunc): + 0000 GL_ONE + 0001 GL_ZERO + 0010 GL_SRC_COLOR + 0011 GL_ONE_MINUS_SRC_COLOR + 0100 GL_DST_COLOR + 0101 GL_ONE_MINUS_DST_COLOR + 0110 GL_SRC_ALPHA + 0111 GL_ONE_MINUS_SRC_ALPHA + 1000 GL_DST_ALPHA + 1001 GL_ONE_MINUS_DST_ALPHA + 1010 GL_SRC_ALPHA_SATURATE + + test modes (glAlphaFunc): + 000 GL_ALWAYS + 001 GL_LESS + 010 GL_EQUAL + 011 GL_LEQUAL + 100 GL_GREATER + 101 GL_NOTEQUAL + 110 GL_GEQUAL + 111 GL_NEVER + + Taken from: + http://niftools.sourceforge.net/doc/nif/NiAlphaProperty.html + + Right now we only use standard alpha blending (see the Ogre code + that sets it up) and it appears that this is the only blending + used in the original game. Bloodmoon (along with several mods) do + however use other settings, such as discarding pixel values with + alpha < 1.0. This is faster because we don't have to mess with the + depth stuff like we did for blending. And OGRE has settings for + this too. + */ + + // Tested against when certain flags are set (see above.) + unsigned char threshold; + + void read(NIFFile *nif) + { + threshold = nif->getChar(); + } }; typedef StructPropT NiAlphaProperty; diff --git a/components/nif/record.hpp b/components/nif/record.hpp index 40f91f84f..84f253eb8 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -88,26 +88,25 @@ enum RecordType /// Base class for all records struct Record { - // Record type and type name - int recType; - Misc::SString recName; + // Record type and type name + int recType; + std::string recName; - Record() : recType(RC_MISSING) {} + Record() : recType(RC_MISSING) {} - /// Parses the record from file - virtual void read(NIFFile *nif) = 0; + /// Parses the record from file + virtual void read(NIFFile *nif) = 0; - /// Does post-processing, after the entire tree is loaded - virtual void post(NIFFile *nif) {} + /// Does post-processing, after the entire tree is loaded + virtual void post(NIFFile *nif) {} virtual ~Record() {} - /* - Use these later if you want custom allocation of all NIF objects - - static void* operator new(size_t size); - static void operator delete(void *p); - */ + /* + Use these later if you want custom allocation of all NIF objects + static void* operator new(size_t size); + static void operator delete(void *p); + */ }; } // Namespace diff --git a/components/nif/record_ptr.hpp b/components/nif/record_ptr.hpp index c5618941e..755094147 100644 --- a/components/nif/record_ptr.hpp +++ b/components/nif/record_ptr.hpp @@ -37,61 +37,52 @@ namespace Nif template class RecordPtrT { - int index; - X* ptr; - NIFFile *nif; - - public: - - RecordPtrT() : index(-2), ptr(NULL) {} - - /// Read the index from the nif - void read(NIFFile *_nif) - { - // Can only read the index once - assert(index == -2); - - // Store the NIFFile pointer for later - nif = _nif; - - // And the index, of course - index = nif->getInt(); - } - - /** Set the pointer explicitly. May be used when you are pointing to - records in another file, eg. when you have a .nif / .kf pair. - */ - void set(X *p) - { - ptr = p; - index = -1; - } - - /// Look up the actual object from the index - X* getPtr() - { - // Have we found the pointer already? - if(ptr == NULL) - { - // Get the record - assert(index >= 0); - Record *r = nif->getRecord(index); - - // And cast it - ptr = dynamic_cast(r); - assert(ptr != NULL); - } - return ptr; - } + union { + intptr_t index; + X* ptr; + }; - /// Syntactic sugar - X* operator->() { return getPtr(); } - X& get() { return *getPtr(); } +public: + RecordPtrT() : index(-2) {} - /// Pointers are allowed to be empty - bool empty() { return index == -1 && ptr == NULL; } + /// Read the index from the nif + void read(NIFFile *nif) + { + // Can only read the index once + assert(index == -2); - int getIndex() { return index; } + // Store the index for later + index = nif->getInt(); + assert(index >= -1); + } + + /// Resolve index to pointer + void post(NIFFile *nif) + { + if(index < 0) + ptr = NULL; + else + { + Record *r = nif->getRecord(index); + // And cast it + ptr = dynamic_cast(r); + assert(ptr != NULL); + } + } + + /// Look up the actual object from the index + X* getPtr() + { + assert(ptr != NULL); + return ptr; + } + X& get() { return *getPtr(); } + + /// Syntactic sugar + X* operator->() { return getPtr(); } + + /// Pointers are allowed to be empty + bool empty() { return ptr == NULL; } }; /** A list of references to other records. These are read as a list, @@ -101,40 +92,37 @@ class RecordPtrT template class RecordListT { - typedef RecordPtrT Ptr; - std::vector list; - - public: + typedef RecordPtrT Ptr; + std::vector list; - void read(NIFFile *nif) - { - int len = nif->getInt(); - list.resize(len); +public: + void read(NIFFile *nif) + { + int len = nif->getInt(); + list.resize(len); - assert(len >= 0 && len < 1000); - for(int i=0;i= 0 && index < static_cast (list.size())); - return list[index].get(); + for(size_t i=0;i < list.size();i++) + list[i].post(nif); } - bool has(int index) - { - assert(index >= 0 && index < static_cast (list.size())); - return !list[index].empty(); - } + X& operator[](size_t index) + { + return list.at(index).get(); + } - int getIndex(int index) + bool has(size_t index) { - if(has(index)) return list[index].getIndex(); - else return -1; + return !list.at(index).empty(); } - int length() { return list.size(); } + size_t length() + { return list.size(); } }; diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 30cb4562d..ea94e7758 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -1,4 +1,4 @@ -/* + /* OpenMW - The completely unofficial reimplementation of Morrowind Copyright (C) 2008-2010 Nicolay Korslund Email: < korslund@gmail.com > @@ -23,9 +23,8 @@ http://www.gnu.org/licenses/ . #include "bullet_nif_loader.hpp" #include -#include +#include -#include #include "../nif/nif_file.hpp" #include "../nif/node.hpp" #include "../nif/data.hpp" @@ -44,32 +43,15 @@ http://www.gnu.org/licenses/ . typedef unsigned char ubyte; -using namespace std; -using namespace Ogre; -using namespace Nif; -using namespace Mangle::VFS; - using namespace NifBullet; + ManualBulletShapeLoader::~ManualBulletShapeLoader() { - delete vfs; } -Ogre::Matrix3 ManualBulletShapeLoader::getMatrix(Nif::Transformation* tr) -{ - Ogre::Matrix3 rot(tr->rotation.v[0].array[0],tr->rotation.v[0].array[1],tr->rotation.v[0].array[2], - tr->rotation.v[1].array[0],tr->rotation.v[1].array[1],tr->rotation.v[1].array[2], - tr->rotation.v[2].array[0],tr->rotation.v[2].array[1],tr->rotation.v[2].array[2]); - return rot; -} -Ogre::Vector3 ManualBulletShapeLoader::getVector(Nif::Transformation* tr) -{ - Ogre::Vector3 vect3(tr->pos.array[0],tr->pos.array[1],tr->pos.array[2]); - return vect3; -} -btQuaternion ManualBulletShapeLoader::getbtQuat(Ogre::Matrix3 m) +btQuaternion ManualBulletShapeLoader::getbtQuat(Ogre::Matrix3 &m) { Ogre::Quaternion oquat(m); btQuaternion quat; @@ -80,10 +62,9 @@ btQuaternion ManualBulletShapeLoader::getbtQuat(Ogre::Matrix3 m) return quat; } -btVector3 ManualBulletShapeLoader::getbtVector(Nif::Vector v) +btVector3 ManualBulletShapeLoader::getbtVector(Ogre::Vector3 &v) { - btVector3 a(v.array[0],v.array[1],v.array[2]); - return a; + return btVector3(v[0], v[1], v[2]); } void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) @@ -94,20 +75,11 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) mTriMesh = new btTriangleMesh(); - if (!vfs) vfs = new OgreVFS(resourceGroup); - - if (!vfs->isFile(resourceName)) - { - warn("File not found."); - return; - } - // Load the NIF. TODO: Wrap this in a try-catch block once we're out // of the early stages of development. Right now we WANT to catch // every error as early and intrusively as possible, as it's most // likely a sign of incomplete code rather than faulty input. - Nif::NIFFile nif(vfs->open(resourceName), resourceName); - + Nif::NIFFile nif(resourceName); if (nif.numRecords() < 1) { warn("Found no records in NIF."); @@ -120,26 +92,25 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) assert(r != NULL); Nif::Node *node = dynamic_cast(r); - if (node == NULL) { warn("First record in file was not a node, but a " + - r->recName.toString() + ". Skipping file."); + r->recName + ". Skipping file."); return; } bool hasCollisionNode = hasRootCollisionNode(node); //do a first pass - handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,false); + handleNode(node,0,NULL,hasCollisionNode,false,false); //if collide = false, then it does a second pass which create a shape for raycasting. if(cShape->collide == false) { - handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true); + handleNode(node,0,NULL,hasCollisionNode,false,true); } - cShape->collide = hasCollisionNode&&cShape->collide; + //cShape->collide = hasCollisionNode&&cShape->collide; struct TriangleMeshShape : public btBvhTriangleMeshShape { @@ -186,8 +157,9 @@ bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node) } void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, - Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly) + const Nif::Transformation *trafo,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly) { + // Accumulate the flags from all the child nodes. This works for all // the flags we currently use, at least. flags |= node->flags; @@ -221,18 +193,26 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, } } - //transfo of parents node + curent node - Ogre::Matrix3 finalRot; - Ogre::Vector3 finalPos; - float finalScale; - Nif::Transformation &final = *((Nif::Transformation*)node->trafo); - Ogre::Vector3 nodePos = getVector(&final); - Ogre::Matrix3 nodeRot = getMatrix(&final); + if (trafo) + { + + // Get a non-const reference to the node's data, since we're + // overwriting it. TODO: Is this necessary? + Nif::Transformation &final = node->trafo; + + // For both position and rotation we have that: + // final_vector = old_vector + old_rotation*new_vector*old_scale + final.pos = trafo->pos + trafo->rotation*final.pos*trafo->scale; + final.velocity = trafo->velocity + trafo->rotation*final.velocity*trafo->scale; + + // Merge the rotations together + final.rotation = trafo->rotation * final.rotation; - finalPos = nodePos + parentPos; - finalRot = parentRot*nodeRot; - finalScale = final.scale*parentScale; + // Scale + final.scale *= trafo->scale; + + } // For NiNodes, loop through children @@ -244,14 +224,14 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, { if (list.has(i)) { - handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,isCollisionNode,raycastingOnly); + handleNode(&list[i], flags,&node->trafo,hasCollisionNode,isCollisionNode,raycastingOnly); } } } - else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode)) + else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode)) { cShape->collide = true; - handleNiTriShape(dynamic_cast(node), flags,finalRot,finalPos,parentScale,raycastingOnly); + handleNiTriShape(dynamic_cast(node), flags,node->trafo.rotation,node->trafo.pos,node->trafo.scale,raycastingOnly); } else if(node->recType == Nif::RC_RootCollisionNode) { @@ -260,7 +240,7 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, for (int i=0; itrafo, hasCollisionNode,true,raycastingOnly); } } } @@ -292,17 +272,19 @@ void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags Nif::NiTriShapeData *data = shape->data.getPtr(); - float* vertices = (float*)data->vertices.ptr; - unsigned short* triangles = (unsigned short*)data->triangles.ptr; - - for(unsigned int i=0; i < data->triangles.length; i = i+3) + float* vertices = &data->vertices[0]; + short* triangles = &data->triangles[0]; + const Ogre::Matrix3 &rot = shape->trafo.rotation; + const Ogre::Vector3 &pos = shape->trafo.pos; + float scale = shape->trafo.scale; + for(unsigned int i=0; i < data->triangles.size(); i = i+3) { Ogre::Vector3 b1(vertices[triangles[i+0]*3]*parentScale,vertices[triangles[i+0]*3+1]*parentScale,vertices[triangles[i+0]*3+2]*parentScale); Ogre::Vector3 b2(vertices[triangles[i+1]*3]*parentScale,vertices[triangles[i+1]*3+1]*parentScale,vertices[triangles[i+1]*3+2]*parentScale); Ogre::Vector3 b3(vertices[triangles[i+2]*3]*parentScale,vertices[triangles[i+2]*3+1]*parentScale,vertices[triangles[i+2]*3+2]*parentScale); - b1 = parentRot * b1 + parentPos; - b2 = parentRot * b2 + parentPos; - b3 = parentRot * b3 + parentPos; + b1 = pos + rot*b1*scale; + b2 = pos + rot*b2*scale; + b3 = pos + rot*b3*scale; mTriMesh->addTriangle(btVector3(b1.x,b1.y,b1.z),btVector3(b2.x,b2.y,b2.z),btVector3(b3.x,b3.y,b3.z)); } } diff --git a/components/nifbullet/bullet_nif_loader.hpp b/components/nifbullet/bullet_nif_loader.hpp index ed3aceac4..88e1ab189 100644 --- a/components/nifbullet/bullet_nif_loader.hpp +++ b/components/nifbullet/bullet_nif_loader.hpp @@ -25,37 +25,21 @@ #define _BULLET_NIF_LOADER_H_ #include -#include +#include #include #include #include #include -#include #include "openengine/bullet/BulletShapeLoader.h" -#include -#include // For warning messages #include -// float infinity -#include - namespace Nif { class Node; class Transformation; class NiTriShape; - class Vector; - class Matrix; -} - -namespace Mangle -{ - namespace VFS - { - class OgreVFS; - } } namespace NifBullet @@ -68,7 +52,7 @@ class ManualBulletShapeLoader : public BulletShapeLoader { public: - ManualBulletShapeLoader():resourceGroup("General"){vfs = 0;} + ManualBulletShapeLoader():resourceGroup("General"){} virtual ~ManualBulletShapeLoader(); void warn(std::string msg) @@ -95,22 +79,18 @@ public: void load(const std::string &name,const std::string &group); private: - Ogre::Matrix3 getMatrix(Nif::Transformation* tr); - - Ogre::Vector3 getVector(Nif::Transformation* tr); + btQuaternion getbtQuat(Ogre::Matrix3 &m); - btQuaternion getbtQuat(Ogre::Matrix3 m); - - btVector3 getbtVector(Nif::Vector v); + btVector3 getbtVector(Ogre::Vector3 &v); /** *Parse a node. */ void handleNode(Nif::Node *node, int flags, - Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly); + const Nif::Transformation *trafo, bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly); /** - *Helpler function + *Helper function */ bool hasRootCollisionNode(Nif::Node* node); @@ -119,8 +99,6 @@ private: */ void handleNiTriShape(Nif::NiTriShape *shape, int flags,Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScales,bool raycastingOnly); - Mangle::VFS::OgreVFS *vfs; - std::string resourceName; std::string resourceGroup; diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 895c51a0d..aca1966b9 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -39,9 +39,7 @@ typedef unsigned char ubyte; using namespace std; -using namespace Ogre; using namespace Nif; -using namespace Mangle::VFS; using namespace Misc; using namespace NifOgre; @@ -67,21 +65,6 @@ void NIFLoader::fail(string msg) assert(1); } -Vector3 NIFLoader::convertVector3(const Nif::Vector& vec) -{ - return Ogre::Vector3(vec.array); -} - -Quaternion NIFLoader::convertRotation(const Nif::Matrix& rot) -{ - Real matrix[3][3]; - - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - matrix[i][j] = rot.v[i].array[j]; - - return Quaternion(Matrix3(matrix)); -} // Helper class that computes the bounding box and of a mesh class BoundsFinder @@ -217,16 +200,16 @@ void NIFLoader::setOutputAnimFiles(bool output){ void NIFLoader::setVerbosePath(std::string path){ verbosePath = path; } -void NIFLoader::createMaterial(const String &name, - const Vector &ambient, - const Vector &diffuse, - const Vector &specular, - const Vector &emissive, +void NIFLoader::createMaterial(const Ogre::String &name, + const Ogre::Vector3 &ambient, + const Ogre::Vector3 &diffuse, + const Ogre::Vector3 &specular, + const Ogre::Vector3 &emissive, float glossiness, float alpha, int alphaFlags, float alphaTest, - const String &texName) + const Ogre::String &texName) { - MaterialPtr material = MaterialManager::getSingleton().create(name, resourceGroup); + Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(name, resourceGroup); //Hardware Skinning code, textures may be the wrong color if enabled @@ -249,11 +232,11 @@ void NIFLoader::createMaterial(const String &name, if (!texName.empty()) { - Pass *pass = material->getTechnique(0)->getPass(0); + Ogre::Pass *pass = material->getTechnique(0)->getPass(0); /*TextureUnitState *txt =*/ pass->createTextureUnitState(texName); - pass->setVertexColourTracking(TVC_DIFFUSE); + pass->setVertexColourTracking(Ogre::TVC_DIFFUSE); // As of yet UNTESTED code from Chris: /*pass->setTextureFiltering(Ogre::TFO_ANISOTROPIC); @@ -294,13 +277,13 @@ void NIFLoader::createMaterial(const String &name, NifOverrides::TransparencyResult result = NifOverrides::Overrides::getTransparencyOverride(texName); if (result.first) { - pass->setAlphaRejectFunction(CMPF_GREATER_EQUAL); + pass->setAlphaRejectFunction(Ogre::CMPF_GREATER_EQUAL); pass->setAlphaRejectValue(result.second); } else { // Enable transparency - pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); + pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); //pass->setDepthCheckEnabled(false); pass->setDepthWriteEnabled(false); @@ -322,11 +305,11 @@ void NIFLoader::createMaterial(const String &name, const int numsplits = 3; for (int i = 0; i < (split ? numsplits : 1); ++i) { - TextureUnitState* tu = material->getTechnique(0)->getPass(0)->createTextureUnitState(); - tu->setName("shadowMap" + StringConverter::toString(i)); - tu->setContentType(TextureUnitState::CONTENT_SHADOW); - tu->setTextureAddressingMode(TextureUnitState::TAM_BORDER); - tu->setTextureBorderColour(ColourValue::White); + Ogre::TextureUnitState* tu = material->getTechnique(0)->getPass(0)->createTextureUnitState(); + tu->setName("shadowMap" + Ogre::StringConverter::toString(i)); + tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW); + tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER); + tu->setTextureBorderColour(Ogre::ColourValue::White); } } @@ -339,11 +322,11 @@ void NIFLoader::createMaterial(const String &name, } // Create a fallback technique without shadows and without mrt - Technique* tech2 = material->createTechnique(); + Ogre::Technique* tech2 = material->createTechnique(); tech2->setSchemeName("Fallback"); - Pass* pass2 = tech2->createPass(); + Ogre::Pass* pass2 = tech2->createPass(); pass2->createTextureUnitState(texName); - pass2->setVertexColourTracking(TVC_DIFFUSE); + pass2->setVertexColourTracking(Ogre::TVC_DIFFUSE); if (Settings::Manager::getBool("shaders", "Objects")) { pass2->setVertexProgram("main_fallback_vp"); @@ -352,16 +335,16 @@ void NIFLoader::createMaterial(const String &name, } // Add material bells and whistles - material->setAmbient(ambient.array[0], ambient.array[1], ambient.array[2]); - material->setDiffuse(diffuse.array[0], diffuse.array[1], diffuse.array[2], alpha); - material->setSpecular(specular.array[0], specular.array[1], specular.array[2], alpha); - material->setSelfIllumination(emissive.array[0], emissive.array[1], emissive.array[2]); + material->setAmbient(ambient[0], ambient[1], ambient[2]); + material->setDiffuse(diffuse[0], diffuse[1], diffuse[2], alpha); + material->setSpecular(specular[0], specular[1], specular[2], alpha); + material->setSelfIllumination(emissive[0], emissive[1], emissive[2]); material->setShininess(glossiness); } // Takes a name and adds a unique part to it. This is just used to // make sure that all materials are given unique names. -String NIFLoader::getUniqueName(const String &input) +Ogre::String NIFLoader::getUniqueName(const Ogre::String &input) { static int addon = 0; static char buf[8]; @@ -377,29 +360,25 @@ String NIFLoader::getUniqueName(const String &input) // does not, change the string IN PLACE to say .dds instead and try // that. The texture may still not exist, but no information of value // is lost in that case. -void NIFLoader::findRealTexture(String &texName) +void NIFLoader::findRealTexture(Ogre::String &texName) { - assert(vfs); - if (vfs->isFile(texName)) return; - - int len = texName.size(); - if (len < 4) return; + if(Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(texName)) + return; // Change texture extension to .dds - texName[len-3] = 'd'; - texName[len-2] = 'd'; - texName[len-1] = 's'; + Ogre::String::size_type pos = texName.rfind('.'); + texName.replace(pos, texName.length(), ".dds"); } //Handle node at top // Convert Nif::NiTriShape to Ogre::SubMesh, attached to the given // mesh. -void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std::list &vertexBoneAssignments) +void NIFLoader::createOgreSubMesh(NiTriShape *shape, const Ogre::String &material, std::list &vertexBoneAssignments) { // cout << "s:" << shape << "\n"; NiTriShapeData *data = shape->data.getPtr(); - SubMesh *sub = mesh->createSubMesh(shape->name.toString()); + Ogre::SubMesh *sub = mesh->createSubMesh(shape->name); int nextBuf = 0; @@ -407,27 +386,27 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std // great. // Add vertices - int numVerts = data->vertices.length / 3; - sub->vertexData = new VertexData(); + int numVerts = data->vertices.size() / 3; + sub->vertexData = new Ogre::VertexData(); sub->vertexData->vertexCount = numVerts; sub->useSharedVertices = false; - VertexDeclaration *decl = sub->vertexData->vertexDeclaration; - decl->addElement(nextBuf, 0, VET_FLOAT3, VES_POSITION); + Ogre::VertexDeclaration *decl = sub->vertexData->vertexDeclaration; + decl->addElement(nextBuf, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION); - HardwareVertexBufferSharedPtr vbuf = - HardwareBufferManager::getSingleton().createVertexBuffer( - VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, false); + Ogre::HardwareVertexBufferSharedPtr vbuf = + Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( + Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3), + numVerts, Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, false); if(flip) { - float *datamod = new float[data->vertices.length]; + float *datamod = new float[data->vertices.size()]; //std::cout << "Shape" << shape->name.toString() << "\n"; for(int i = 0; i < numVerts; i++) { int index = i * 3; - const float *pos = data->vertices.ptr + index; + const float *pos = &data->vertices[index]; Ogre::Vector3 original = Ogre::Vector3(*pos ,*(pos+1), *(pos+2)); original = mTransform * original; mBoundingBox.merge(original); @@ -440,30 +419,30 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std } else { - vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, false); + vbuf->writeData(0, vbuf->getSizeInBytes(), &data->vertices[0], false); } - VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; + Ogre::VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; bind->setBinding(nextBuf++, vbuf); - if (data->normals.length) + if (data->normals.size()) { - decl->addElement(nextBuf, 0, VET_FLOAT3, VES_NORMAL); - vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( - VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); + decl->addElement(nextBuf, 0, Ogre::VET_FLOAT3, Ogre::VES_NORMAL); + vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( + Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3), + numVerts, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); if(flip) { - Quaternion rotation = mTransform.extractQuaternion(); + Ogre::Quaternion rotation = mTransform.extractQuaternion(); rotation.normalise(); - float *datamod = new float[data->normals.length]; + float *datamod = new float[data->normals.size()]; for(int i = 0; i < numVerts; i++) { int index = i * 3; - const float *pos = data->normals.ptr + index; + const float *pos = &data->normals[index]; Ogre::Vector3 original = Ogre::Vector3(*pos ,*(pos+1), *(pos+2)); original = rotation * original; if (mNormaliseNormals) @@ -481,49 +460,49 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std } else { - vbuf->writeData(0, vbuf->getSizeInBytes(), data->normals.ptr, false); + vbuf->writeData(0, vbuf->getSizeInBytes(), &data->normals[0], false); } bind->setBinding(nextBuf++, vbuf); } // Vertex colors - if (data->colors.length) + if (data->colors.size()) { - const float *colors = data->colors.ptr; - RenderSystem* rs = Root::getSingleton().getRenderSystem(); - std::vector colorsRGB(numVerts); - RGBA *pColour = &colorsRGB.front(); + const float *colors = &data->colors[0]; + Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem(); + std::vector colorsRGB(numVerts); + Ogre::RGBA *pColour = &colorsRGB.front(); for (int i=0; iconvertColourValue(ColourValue(colors[0],colors[1],colors[2], - colors[3]),pColour++); + rs->convertColourValue(Ogre::ColourValue(colors[0],colors[1],colors[2], + colors[3]),pColour++); colors += 4; } - decl->addElement(nextBuf, 0, VET_COLOUR, VES_DIFFUSE); - vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( - VertexElement::getTypeSize(VET_COLOUR), - numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY); + decl->addElement(nextBuf, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE); + vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( + Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR), + numVerts, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY); vbuf->writeData(0, vbuf->getSizeInBytes(), &colorsRGB.front(), true); bind->setBinding(nextBuf++, vbuf); } - if (data->uvlist.length) + if (data->uvlist.size()) { - decl->addElement(nextBuf, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES); - vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( - VertexElement::getTypeSize(VET_FLOAT2), - numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY,false); + decl->addElement(nextBuf, 0, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES); + vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( + Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2), + numVerts, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY,false); if(flip) { - float *datamod = new float[data->uvlist.length]; + float *datamod = new float[data->uvlist.size()]; - for(unsigned int i = 0; i < data->uvlist.length; i+=2){ - float x = *(data->uvlist.ptr + i); + for(unsigned int i = 0; i < data->uvlist.size(); i+=2){ + float x = data->uvlist[i]; - float y = *(data->uvlist.ptr + i + 1); + float y = data->uvlist[i + 1]; datamod[i] =x; datamod[i + 1] =y; @@ -532,36 +511,34 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std delete [] datamod; } else - vbuf->writeData(0, vbuf->getSizeInBytes(), data->uvlist.ptr, false); + vbuf->writeData(0, vbuf->getSizeInBytes(), &data->uvlist[0], false); bind->setBinding(nextBuf++, vbuf); } // Triangle faces - The total number of triangle points - int numFaces = data->triangles.length; - + int numFaces = data->triangles.size(); if (numFaces) { sub->indexData->indexCount = numFaces; sub->indexData->indexStart = 0; - HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton(). - createIndexBuffer(HardwareIndexBuffer::IT_16BIT, - numFaces, - HardwareBuffer::HBU_STATIC_WRITE_ONLY, true); + Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton(). + createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, numFaces, + Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, true); if(flip && mFlipVertexWinding && sub->indexData->indexCount % 3 == 0){ sub->indexData->indexBuffer = ibuf; - uint16 *datamod = new uint16[numFaces]; + uint16_t *datamod = new uint16_t[numFaces]; int index = 0; for (size_t i = 0; i < sub->indexData->indexCount; i+=3) { - const short *pos = data->triangles.ptr + index; - uint16 i0 = (uint16) *(pos+0); - uint16 i1 = (uint16) *(pos+1); - uint16 i2 = (uint16) *(pos+2); + const short *pos = &data->triangles[index]; + uint16_t i0 = (uint16_t) *(pos+0); + uint16_t i1 = (uint16_t) *(pos+1); + uint16_t i2 = (uint16_t) *(pos+2); //std::cout << "i0: " << i0 << "i1: " << i1 << "i2: " << i2 << "\n"; @@ -578,7 +555,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std } else - ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, false); + ibuf->writeData(0, ibuf->getSizeInBytes(), &data->triangles[0], false); sub->indexData->indexBuffer = ibuf; } @@ -587,7 +564,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std //add vertex bone assignments - for (std::list::iterator it = vertexBoneAssignments.begin(); + for (std::list::iterator it = vertexBoneAssignments.begin(); it != vertexBoneAssignments.end(); it++) { sub->addBoneAssignment(*it); @@ -598,23 +575,8 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std // Helper math functions. Reinventing linear algebra for the win! -// Computes B = AxB (matrix*matrix) -static void matrixMul(const Matrix &A, Matrix &B) -{ - for (int i=0;i<3;i++) - { - float a = B.v[0].array[i]; - float b = B.v[1].array[i]; - float c = B.v[2].array[i]; - - B.v[0].array[i] = a*A.v[0].array[0] + b*A.v[0].array[1] + c*A.v[0].array[2]; - B.v[1].array[i] = a*A.v[1].array[0] + b*A.v[1].array[1] + c*A.v[1].array[2]; - B.v[2].array[i] = a*A.v[2].array[0] + b*A.v[2].array[1] + c*A.v[2].array[2]; - } -} - // Computes C = B + AxC*scale -static void vectorMulAdd(const Matrix &A, const Vector &B, float *C, float scale) +static void vectorMulAdd(const Ogre::Matrix3 &A, const Ogre::Vector3 &B, float *C, float scale) { // Keep the original values float a = C[0]; @@ -623,11 +585,11 @@ static void vectorMulAdd(const Matrix &A, const Vector &B, float *C, float scale // Perform matrix multiplication, scaling and addition for (int i=0;i<3;i++) - C[i] = B.array[i] + (a*A.v[i].array[0] + b*A.v[i].array[1] + c*A.v[i].array[2])*scale; + C[i] = B[i] + (a*A[i][0] + b*A[i][1] + c*A[i][2])*scale; } // Computes B = AxB (matrix*vector) -static void vectorMul(const Matrix &A, float *C) +static void vectorMul(const Ogre::Matrix3 &A, float *C) { // Keep the original values float a = C[0]; @@ -636,7 +598,7 @@ static void vectorMul(const Matrix &A, float *C) // Perform matrix multiplication, scaling and addition for (int i=0;i<3;i++) - C[i] = a*A.v[i].array[0] + b*A.v[i].array[1] + c*A.v[i].array[2]; + C[i] = a*A[i][0] + b*A[i][1] + c*A[i][2]; } @@ -671,7 +633,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou return; // Material name for this submesh, if any - String material; + Ogre::String material; // Skip the entire material phase for hidden nodes if (!hidden) @@ -700,14 +662,12 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou } // Texture - String texName; + Ogre::String texName; if (t && t->textures[0].inUse) { NiSourceTexture *st = t->textures[0].texture.getPtr(); if (st->external) { - SString tname = st->filename; - /* findRealTexture checks if the file actually exists. If it doesn't, and the name ends in .tga, it will try replacing the extension with .dds instead @@ -721,7 +681,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou problem since all the nif data is stored in a local throwaway buffer. */ - texName = "textures\\" + tname.toString(); + texName = "textures\\" + st->filename; findRealTexture(texName); } else warn("Found internal texture, ignoring."); @@ -733,7 +693,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou if (a) { alphaFlags = a->flags; - alphaTest = a->data->threshold; + alphaTest = a->data.threshold; } // Material @@ -748,7 +708,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou if (m) { // Use NiMaterialProperty data to create the data - const S_MaterialProperty *d = m->data; + const S_MaterialProperty *d = &m->data; std::multimap::iterator itr = MaterialMap.find(texName); std::multimap::iterator lastElement; @@ -775,14 +735,8 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { // We only have a texture name. Create a default // material for it. - Vector zero, one; - for (int i=0; i<3;i++) - { - zero.array[i] = 0.0; - one.array[i] = 1.0; - } - - createMaterial(material, one, one, zero, zero, 0.0, 1.0, + const Ogre::Vector3 zero(0.0f), one(1.0f); + createMaterial(material, one, one, zero, zero, 0.0f, 1.0f, alphaFlags, alphaTest, texName); } } @@ -795,12 +749,12 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou level. */ NiTriShapeData *data = shape->data.getPtr(); - int numVerts = data->vertices.length / 3; + int numVerts = data->vertices.size() / 3; - float *ptr = (float*)data->vertices.ptr; + float *ptr = (float*)&data->vertices[0]; float *optr = ptr; - std::list vertexBoneAssignments; + std::list vertexBoneAssignments; Nif::NiTriShapeCopy copy = shape->clone(); @@ -828,14 +782,14 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou std::vector vertexPosOriginal(numVerts, Ogre::Vector3::ZERO); std::vector vertexNormalOriginal(numVerts, Ogre::Vector3::ZERO); - float *ptrNormals = (float*)data->normals.ptr; + float *ptrNormals = (float*)&data->normals[0]; //the bone from skin->bones[boneIndex] is linked to skin->data->bones[boneIndex] //the first one contains a link to the bone, the second vertex transformation //relative to the bone int boneIndex = 0; - Bone *bonePtr; - Vector3 vecPos; - Quaternion vecRot; + Ogre::Bone *bonePtr; + Ogre::Vector3 vecPos; + Ogre::Quaternion vecRot; std::vector boneList = shape->skin->data->bones; @@ -849,33 +803,33 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { if(mSkel.isNull()) { - std::cout << "No skeleton for :" << shape->skin->bones[boneIndex].name.toString() << std::endl; + std::cout << "No skeleton for :" << shape->skin->bones[boneIndex].name << std::endl; break; } //get the bone from bones array of skindata - if(!mSkel->hasBone(shape->skin->bones[boneIndex].name.toString())) + if(!mSkel->hasBone(shape->skin->bones[boneIndex].name)) std::cout << "We don't have this bone"; - bonePtr = mSkel->getBone(shape->skin->bones[boneIndex].name.toString()); + bonePtr = mSkel->getBone(shape->skin->bones[boneIndex].name); // final_vector = old_vector + old_rotation*new_vector*old_scale Nif::NiSkinData::BoneInfoCopy boneinfocopy; - boneinfocopy.trafo.rotation = convertRotation(it->trafo->rotation); - boneinfocopy.trafo.trans = convertVector3(it->trafo->trans); - boneinfocopy.bonename = shape->skin->bones[boneIndex].name.toString(); + boneinfocopy.trafo.rotation = it->trafo.rotation; + boneinfocopy.trafo.trans = it->trafo.trans; + boneinfocopy.bonename = shape->skin->bones[boneIndex].name; boneinfocopy.bonehandle = bonePtr->getHandle(); copy.boneinfo.push_back(boneinfocopy); - for (unsigned int i=0; iweights.length; i++) + for (unsigned int i=0; iweights.size(); i++) { vecPos = bonePtr->_getDerivedPosition() + - bonePtr->_getDerivedOrientation() * convertVector3(it->trafo->trans); + bonePtr->_getDerivedOrientation() * it->trafo.trans; - vecRot = bonePtr->_getDerivedOrientation() * convertRotation(it->trafo->rotation); - unsigned int verIndex = (it->weights.ptr + i)->vertex; + vecRot = bonePtr->_getDerivedOrientation() * it->trafo.rotation; + unsigned int verIndex = it->weights[i].vertex; //boneinfo.weights.push_back(*(it->weights.ptr + i)); Nif::NiSkinData::IndividualWeight ind; - ind.weight = (it->weights.ptr + i)->weight; + ind.weight = it->weights[i].weight; ind.boneinfocopyindex = copy.boneinfo.size() - 1; if(copy.vertsToWeights.find(verIndex) == copy.vertsToWeights.end()) { @@ -892,9 +846,9 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou if (vertexPosAbsolut[verIndex] == false) { //apply transformation to the vertices - Vector3 absVertPos = vecPos + vecRot * Vector3(ptr + verIndex *3); - absVertPos = absVertPos * (it->weights.ptr + i)->weight; - vertexPosOriginal[verIndex] = Vector3(ptr + verIndex *3); + Ogre::Vector3 absVertPos = vecPos + vecRot * Ogre::Vector3(ptr + verIndex *3); + absVertPos = absVertPos * it->weights[i].weight; + vertexPosOriginal[verIndex] = Ogre::Vector3(ptr + verIndex *3); mBoundingBox.merge(absVertPos); //convert it back to float * @@ -903,11 +857,11 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou //apply rotation to the normals (not every vertex has a normal) //FIXME: I guessed that vertex[i] = normal[i], is that true? - if (verIndex < data->normals.length) + if (verIndex < data->normals.size()) { - Vector3 absNormalsPos = vecRot * Vector3(ptrNormals + verIndex *3); - absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; - vertexNormalOriginal[verIndex] = Vector3(ptrNormals + verIndex *3); + Ogre::Vector3 absNormalsPos = vecRot * Ogre::Vector3(ptrNormals + verIndex *3); + absNormalsPos = absNormalsPos * it->weights[i].weight; + vertexNormalOriginal[verIndex] = Ogre::Vector3(ptrNormals + verIndex *3); for (int j=0; j<3; j++) (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; @@ -917,9 +871,9 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou } else { - Vector3 absVertPos = vecPos + vecRot * vertexPosOriginal[verIndex]; - absVertPos = absVertPos * (it->weights.ptr + i)->weight; - Vector3 old = Vector3(ptr + verIndex *3); + Ogre::Vector3 absVertPos = vecPos + vecRot * vertexPosOriginal[verIndex]; + absVertPos = absVertPos * it->weights[i].weight; + Ogre::Vector3 old = Ogre::Vector3(ptr + verIndex *3); absVertPos = absVertPos + old; mBoundingBox.merge(absVertPos); @@ -929,11 +883,11 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou //apply rotation to the normals (not every vertex has a normal) //FIXME: I guessed that vertex[i] = normal[i], is that true? - if (verIndex < data->normals.length) + if (verIndex < data->normals.size()) { - Vector3 absNormalsPos = vecRot * vertexNormalOriginal[verIndex]; - absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; - Vector3 oldNormal = Vector3(ptrNormals + verIndex *3); + Ogre::Vector3 absNormalsPos = vecRot * vertexNormalOriginal[verIndex]; + absNormalsPos = absNormalsPos * it->weights[i].weight; + Ogre::Vector3 oldNormal = Ogre::Vector3(ptrNormals + verIndex *3); absNormalsPos = absNormalsPos + oldNormal; for (int j=0; j<3; j++) @@ -942,10 +896,10 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou } - VertexBoneAssignment vba; + Ogre::VertexBoneAssignment vba; vba.boneIndex = bonePtr->getHandle(); vba.vertexIndex = verIndex; - vba.weight = (it->weights.ptr + i)->weight; + vba.weight = it->weights[i].weight; vertexBoneAssignments.push_back(vba); @@ -962,12 +916,12 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou copy.boneSequence = boneSequence; // Rotate, scale and translate all the vertices, - const Matrix &rot = shape->trafo->rotation; - const Vector &pos = shape->trafo->pos; - float scale = shape->trafo->scale; + const Ogre::Matrix3 &rot = shape->trafo.rotation; + const Ogre::Vector3 &pos = shape->trafo.pos; + float scale = shape->trafo.scale; - copy.trafo.trans = convertVector3(original.pos); - copy.trafo.rotation = convertRotation(original.rotation); + copy.trafo.trans = original.pos; + copy.trafo.rotation = original.rotation; copy.trafo.scale = original.scale; //We don't use velocity for anything yet, so it does not need to be saved @@ -975,15 +929,15 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou for (int i=0; inormals.length) + if (data->normals.size()) { - ptr = (float*)data->normals.ptr; + ptr = (float*)&data->normals[0]; for (int i=0; igetNumBones() - 1; for(int i = 0; i < numVerts; i++){ - VertexBoneAssignment vba; + Ogre::VertexBoneAssignment vba; vba.boneIndex = boneIndex; vba.vertexIndex = i; vba.weight = 1; @@ -1019,15 +973,15 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou void NIFLoader::calculateTransform() { // Calculate transform - Matrix4 transform = Matrix4::IDENTITY; - transform = Matrix4::getScale(vector) * transform; + Ogre::Matrix4 transform = Ogre::Matrix4::IDENTITY; + transform = Ogre::Matrix4::getScale(vector) * transform; // Check whether we have to flip vertex winding. // We do have to, if we changed our right hand base. // We can test it by using the cross product from X and Y and see, if it is a non-negative // projection on Z. Actually it should be exactly Z, as we don't do non-uniform scaling yet, // but the test is cheap either way. - Matrix3 m3; + Ogre::Matrix3 m3; transform.extract3x3Matrix(m3); if (m3.GetColumn(0).crossProduct(m3.GetColumn(1)).dotProduct(m3.GetColumn(2)) < 0) @@ -1090,7 +1044,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) { - std::string text = textiter->text.toString(); + std::string text = textiter->text; replace(text.begin(), text.end(), '\n', '/'); @@ -1121,7 +1075,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, } } - Bone *bone = 0; + Ogre::Bone *bone = 0; // create skeleton or add bones if (node->recType == RC_NiNode) @@ -1131,14 +1085,14 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { inTheSkeletonTree = true; - mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); + mSkel = Ogre::SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); } else if (!mSkel.isNull() && !parentBone) inTheSkeletonTree = false; if (!mSkel.isNull()) //if there is a skeleton { - std::string name = node->name.toString(); + std::string name = node->name; // Quick-n-dirty workaround for the fact that several // bones may have the same name. @@ -1151,30 +1105,29 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, parentBone->addChild(bone); bone->setInheritOrientation(true); - bone->setPosition(convertVector3(node->trafo->pos)); - bone->setOrientation(convertRotation(node->trafo->rotation)); + bone->setPosition(node->trafo.pos); + bone->setOrientation(node->trafo.rotation); } } } - Transformation original = *(node->trafo); + Transformation original = node->trafo; // Apply the parent transformation to this node. We overwrite the // existing data with the final transformation. if (trafo) { // Get a non-const reference to the node's data, since we're // overwriting it. TODO: Is this necessary? - Transformation &final = *((Transformation*)node->trafo); + Transformation &final = node->trafo; // For both position and rotation we have that: // final_vector = old_vector + old_rotation*new_vector*old_scale - vectorMulAdd(trafo->rotation, trafo->pos, final.pos.array, trafo->scale); - vectorMulAdd(trafo->rotation, trafo->velocity, final.velocity.array, trafo->scale); + final.pos = trafo->pos + trafo->rotation*final.pos*trafo->scale; + final.velocity = trafo->velocity + trafo->rotation*final.velocity*trafo->scale; // Merge the rotations together - matrixMul(trafo->rotation, final.rotation); + final.rotation = trafo->rotation * final.rotation; - // Scalar values are so nice to deal with. Why can't everything - // just be scalar? + // Scale final.scale *= trafo->scale; } @@ -1187,12 +1140,12 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { if (list.has(i)) - handleNode(&list[i], flags, node->trafo, bounds, bone, boneSequence); + handleNode(&list[i], flags, &node->trafo, bounds, bone, boneSequence); } } else if (node->recType == RC_NiTriShape && bNiTri) { - std::string nodename = node->name.toString(); + std::string nodename = node->name; if (triname == "") { @@ -1207,7 +1160,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, } } -void NIFLoader::loadResource(Resource *resource) +void NIFLoader::loadResource(Ogre::Resource *resource) { inTheSkeletonTree = false; allanim.clear(); @@ -1293,22 +1246,13 @@ void NIFLoader::loadResource(Resource *resource) { calculateTransform(); } - // Set up the VFS if it hasn't been done already - if (!vfs) vfs = new OgreVFS(resourceGroup); - // Get the mesh - mesh = dynamic_cast(resource); + mesh = dynamic_cast(resource); assert(mesh); // Look it up resourceName = mesh->getName(); - //std::cout << resourceName << "\n"; - - if (!vfs->isFile(resourceName)) - { - warn("File "+resourceName+" not found."); - return; - } + // Helper that computes bounding boxes for us. BoundsFinder bounds; @@ -1317,8 +1261,7 @@ void NIFLoader::loadResource(Resource *resource) // of the early stages of development. Right now we WANT to catch // every error as early and intrusively as possible, as it's most // likely a sign of incomplete code rather than faulty input. - NIFFile nif(vfs->open(resourceName), resourceName); - + NIFFile nif(resourceName); if (nif.numRecords() < 1) { warn("Found no records in NIF."); @@ -1334,7 +1277,7 @@ void NIFLoader::loadResource(Resource *resource) if (node == NULL) { warn("First record in file was not a node, but a " + - r->recName.toString() + ". Skipping file."); + r->recName + ". Skipping file."); return; } @@ -1358,7 +1301,7 @@ void NIFLoader::loadResource(Resource *resource) if (f->timeStart >= 10000000000000000.0f) continue; - data->setBonename(o->name.toString()); + data->setBonename(o->name); data->setStartTime(f->timeStart); data->setStopTime(f->timeStop); @@ -1369,8 +1312,8 @@ void NIFLoader::loadResource(Resource *resource) // set the bounding value. if (bounds.isValid()) { - mesh->_setBounds(AxisAlignedBox(bounds.minX(), bounds.minY(), bounds.minZ(), - bounds.maxX(), bounds.maxY(), bounds.maxZ())); + mesh->_setBounds(Ogre::AxisAlignedBox(bounds.minX(), bounds.minY(), bounds.minZ(), + bounds.maxX(), bounds.maxY(), bounds.maxZ())); mesh->_setBoundingSphereRadius(bounds.getRadius()); } if(hasAnim && addAnim){ @@ -1392,7 +1335,7 @@ void NIFLoader::loadResource(Resource *resource) for(std::vector::iterator iter = needBoneAssignments.begin(); iter != needBoneAssignments.end(); iter++) { int boneIndex = mSkel->getNumBones() - 1; - VertexBoneAssignment vba; + Ogre::VertexBoneAssignment vba; vba.boneIndex = boneIndex; vba.vertexIndex = 0; vba.weight = 1; @@ -1411,20 +1354,19 @@ void NIFLoader::loadResource(Resource *resource) -MeshPtr NIFLoader::load(const std::string &name, - const std::string &group) +Ogre::MeshPtr NIFLoader::load(const std::string &name, const std::string &group) { - MeshManager *m = MeshManager::getSingletonPtr(); + Ogre::MeshManager *m = Ogre::MeshManager::getSingletonPtr(); // Check if the resource already exists - ResourcePtr ptr = m->getByName(name, group); - MeshPtr themesh; + Ogre::ResourcePtr ptr = m->getByName(name, group); + Ogre::MeshPtr themesh; if (!ptr.isNull()){ - themesh = MeshPtr(ptr); + themesh = Ogre::MeshPtr(ptr); } else // Nope, create a new one. { - themesh = MeshManager::getSingleton().createManual(name, group, NIFLoader::getSingletonPtr()); + themesh = Ogre::MeshManager::getSingleton().createManual(name, group, NIFLoader::getSingletonPtr()); } return themesh; } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index d73948fa8..7b32d24d1 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -28,32 +28,20 @@ #include #include -#include #include -#include -#include "../nif/nif_file.hpp" #include "../nif/node.hpp" -#include "../nif/data.hpp" -#include "../nif/property.hpp" -#include "../nif/controller.hpp" -#include "../nif/extra.hpp" -#include - -#include -#include -// For warning messages -#include -using namespace boost::algorithm; +#include class BoundsFinder; struct ciLessBoost : std::binary_function { - bool operator() (const std::string & s1, const std::string & s2) const { - //case insensitive version of is_less - return lexicographical_compare(s1, s2, is_iless()); + bool operator() (const std::string & s1, const std::string & s2) const + { + //case insensitive version of is_less + return boost::algorithm::lexicographical_compare(s1, s2, boost::algorithm::is_iless()); } }; @@ -62,16 +50,6 @@ namespace Nif class Node; class Transformation; class NiTriShape; - class Vector; - class Matrix; -} - -namespace Mangle -{ - namespace VFS - { - class OgreVFS; - } } namespace NifOgre @@ -110,9 +88,6 @@ class NIFLoader : Ogre::ManualResourceLoader std::map* getTextIndices(std::string name); - Ogre::Vector3 convertVector3(const Nif::Vector& vec); - Ogre::Quaternion convertRotation(const Nif::Matrix& rot); - void setOutputAnimFiles(bool output); void setVerbosePath(std::string path); @@ -136,10 +111,10 @@ class NIFLoader : Ogre::ManualResourceLoader void createOgreSubMesh(Nif::NiTriShape *shape, const Ogre::String &material, std::list &vertexBoneAssignments); void createMaterial(const Ogre::String &name, - const Nif::Vector &ambient, - const Nif::Vector &diffuse, - const Nif::Vector &specular, - const Nif::Vector &emissive, + const Ogre::Vector3 &ambient, + const Ogre::Vector3 &diffuse, + const Ogre::Vector3 &specular, + const Ogre::Vector3 &emissive, float glossiness, float alpha, int alphaFlags, float alphaTest, const Ogre::String &texName); @@ -154,13 +129,6 @@ class NIFLoader : Ogre::ManualResourceLoader return resourceName + ".skel"; } - // This is the interface to the Ogre resource system. It allows us to - // load NIFs from BSAs, in the file system and in any other place we - // tell Ogre to look (eg. in zip or rar files.) It's also used to - // check for the existence of texture files, so we can exchange the - // extension from .tga to .dds if the texture is missing. - Mangle::VFS::OgreVFS *vfs; - std::string verbosePath; std::string resourceName; std::string resourceGroup; @@ -197,3 +165,5 @@ class NIFLoader : Ogre::ManualResourceLoader } #endif + + diff --git a/components/nifogre/tests/ogre_common.cpp b/components/nifogre/tests/ogre_common.cpp index 949c91c4f..657913f30 100644 --- a/components/nifogre/tests/ogre_common.cpp +++ b/components/nifogre/tests/ogre_common.cpp @@ -1,6 +1,5 @@ #include #include -#include using namespace std; using namespace Ogre; diff --git a/components/terrain/esm_land_factory.cpp b/components/terrain/esm_land_factory.cpp index 315188234..a6335c6dc 100644 --- a/components/terrain/esm_land_factory.cpp +++ b/components/terrain/esm_land_factory.cpp @@ -8,41 +8,7 @@ using namespace Terrain; -static class ESMLandStream : public Mangle::Stream -{ -public: - ESMLandStream(ESM::Land *l, ESM::ESMReader &r) - { - } -}; - bool ESMLandFactory::has(int x, int y) { return store.landscapes.has(x,y); } - -LandDataPtr get(int x, int y, LandInfo &info) -{ - assert(has(x,y)); - - // Set up the info - info.grid = LGT_Quadratic; - info.data = LDT_Float; - - const float SIZE = 8192; // CHECK - - info.xsize = SIZE; - info.ysize = SIZE; - info.numx = 65; - info.numy = 65; - info.xoffset = SIZE*x; - info.yoffset = SIZE*y; - - // Get the Land struct from store - ESM::Land* land = store.landscapes.find(x,y); - assert(land->hasData); - - // Create a stream for the data and return it. - LandDataPtr ptr(new ESMLandStream(land, reader)); - return ptr; -} diff --git a/components/terrain/esm_land_factory.hpp b/components/terrain/esm_land_factory.hpp index 4fd95caa9..bb1f9a8c6 100644 --- a/components/terrain/esm_land_factory.hpp +++ b/components/terrain/esm_land_factory.hpp @@ -32,10 +32,6 @@ namespace Terrain // True if this factory has any data for the given grid cell. bool has(int x, int y); - - // Return stream to data for this cell. Additional data about the - // landscape is returned through the LandInfo struct. - LandDataPtr get(int x, int y, LandInfo &info); }; } #endif diff --git a/components/terrain/heightmapbuf.hpp b/components/terrain/heightmapbuf.hpp index 82154ce88..d147e6015 100644 --- a/components/terrain/heightmapbuf.hpp +++ b/components/terrain/heightmapbuf.hpp @@ -8,7 +8,7 @@ #include "heightmap.hpp" #include "land_factory.hpp" #include -#include +#include namespace Terrain { diff --git a/components/terrain/land_factory.hpp b/components/terrain/land_factory.hpp index f41946b49..c4d160443 100644 --- a/components/terrain/land_factory.hpp +++ b/components/terrain/land_factory.hpp @@ -1,8 +1,6 @@ #ifndef TERRAIN_LAND_FACTORY_H #define TERRAIN_LAND_FACTORY_H -#include - namespace Terrain { enum LandInfoGridType @@ -32,12 +30,6 @@ namespace Terrain float xoffset, yoffset; }; - /* We use normal streams for data. This allows us to just pass (for - example) a file stream as height map input later, with no extra - fuzz. - */ - typedef Mangle::Stream::StreamPtr LandDataPtr; - /* Factory class that provides streams to land data cells. Each "cell" has a unique integer coordinate in the plane. @@ -46,10 +38,6 @@ namespace Terrain { // True if this factory has any data for the given grid cell. virtual bool has(int x, int y) = 0; - - // Return stream to data for this cell. Additional data about the - // landscape is returned through the LandInfo struct. - virtual LandDataPtr get(int x, int y, LandInfo &info) = 0; }; } #endif diff --git a/components/terrain/triangulator.hpp b/components/terrain/triangulator.hpp index cedf0c6a2..c5c0e699b 100644 --- a/components/terrain/triangulator.hpp +++ b/components/terrain/triangulator.hpp @@ -28,7 +28,7 @@ terrains of the same size, once instance can usually be shared. */ -#include +#include namespace Terrain { diff --git a/components/to_utf8/gen_iconv.cpp b/components/to_utf8/gen_iconv.cpp index b7298e304..cc7cc191a 100644 --- a/components/to_utf8/gen_iconv.cpp +++ b/components/to_utf8/gen_iconv.cpp @@ -5,7 +5,7 @@ using namespace std; #include -#include +#include void tab() { cout << " "; } diff --git a/components/to_utf8/to_utf8.cpp b/components/to_utf8/to_utf8.cpp index 3fbbeb733..6bcbbd0e6 100644 --- a/components/to_utf8/to_utf8.cpp +++ b/components/to_utf8/to_utf8.cpp @@ -1,7 +1,7 @@ #include "to_utf8.hpp" #include -#include +#include /* This file contains the code to translate from WINDOWS-1252 (native charset used in English version of Morrowind) to UTF-8. The library diff --git a/credits.txt b/credits.txt new file mode 100644 index 000000000..16b41d56a --- /dev/null +++ b/credits.txt @@ -0,0 +1,58 @@ +CREDITS + +Current Developers: +Aleksandar Jovanov +Alexander “Ace” Olofsson +athile +BrotherBrick +Cris “Mirceam” Mihalache +gugus / gus +Jacob “Yacoby” Essex +Jannik “scrawl” Heller +Jason “jhooks” Hooks +Karl-Felix “k1ll” Glatzer +Lukasz “lgro” Gromanowski +Marc “Zini” Zinnschlag +Michael “werdanith” Papageorgiou +Nikolay “corristo” Kasyanov +Pieter “pvdk” van der Kloet +Roman "Kromgart" Melnik +Sebastian “swick” Wick +Sylvain "Garvek" T. + +Retired Developers: +Ardekantur +Armin Preiml +Diggory Hardy +Jan Borsodi +Jan-Peter “peppe” Nilsson +Josua Grawitter +Nicolay Korslund +sergoz +Star-Demon +Yuri Krupenin + +PR team and Translators: +Julien (jvoisin/ap0) Voisin +sirherrbatka +ElderTroll +spyboot +corristo +Okulo +penguinroad +Kingpix + +Reverser and Research: +natirips +Sadler +fragonard +Greendogo +Myckel +modred11 +HiPhish + +OpenMW: +Thanks to DokterDume for kindly providing us with the Moon and Star logo used as the application icon and project logo. + +Launcher: +Thanks to Kevin Ryan for kindly providing us with the icon used for the Data Files tab. diff --git a/files/plugins.cfg.linux b/files/plugins.cfg.linux index f34621a0f..7b8d99e8f 100644 --- a/files/plugins.cfg.linux +++ b/files/plugins.cfg.linux @@ -4,9 +4,8 @@ PluginFolder=${OGRE_PLUGIN_DIR_REL} # Define plugins -Plugin=RenderSystem_GL -Plugin=Plugin_ParticleFX -Plugin=Plugin_OctreeSceneManager -Plugin=Plugin_CgProgramManager - +Plugin=RenderSystem_GL${DEBUG_SUFFIX} +Plugin=Plugin_ParticleFX${DEBUG_SUFFIX} +Plugin=Plugin_OctreeSceneManager${DEBUG_SUFFIX} +Plugin=Plugin_CgProgramManager${DEBUG_SUFFIX} diff --git a/files/plugins.cfg.mac b/files/plugins.cfg.mac index 322070832..fac18dc8f 100644 --- a/files/plugins.cfg.mac +++ b/files/plugins.cfg.mac @@ -4,9 +4,9 @@ PluginFolder=${OGRE_PLUGIN_DIR} # Define plugins -Plugin=RenderSystem_GL.1.8.0 -Plugin=Plugin_ParticleFX.1.8.0 -Plugin=Plugin_OctreeSceneManager.1.8.0 -Plugin=Plugin_CgProgramManager.1.8.0 +Plugin=RenderSystem_GL${DEBUG_SUFFIX}.1.8.0 +Plugin=Plugin_ParticleFX${DEBUG_SUFFIX}.1.8.0 +Plugin=Plugin_OctreeSceneManager${DEBUG_SUFFIX}.1.8.0 +Plugin=Plugin_CgProgramManager${DEBUG_SUFFIX}.1.8.0 diff --git a/files/plugins.cfg.win32 b/files/plugins.cfg.win32 index ea12c0394..6b4e9ef9d 100644 --- a/files/plugins.cfg.win32 +++ b/files/plugins.cfg.win32 @@ -4,10 +4,10 @@ PluginFolder=.\ # Define plugins -Plugin=RenderSystem_Direct3D9 -Plugin=RenderSystem_GL -Plugin=Plugin_ParticleFX -Plugin=Plugin_OctreeSceneManager -Plugin=Plugin_CgProgramManager +Plugin=RenderSystem_Direct3D9${DEBUG_SUFFIX} +Plugin=RenderSystem_GL${DEBUG_SUFFIX} +Plugin=Plugin_ParticleFX${DEBUG_SUFFIX} +Plugin=Plugin_OctreeSceneManager${DEBUG_SUFFIX} +Plugin=Plugin_CgProgramManager${DEBUG_SUFFIX} diff --git a/libs/mangle/input/servers/ois_driver.cpp b/libs/mangle/input/servers/ois_driver.cpp index b8e4f5eb9..07ba3e83a 100644 --- a/libs/mangle/input/servers/ois_driver.cpp +++ b/libs/mangle/input/servers/ois_driver.cpp @@ -1,6 +1,6 @@ #include "ois_driver.hpp" -#include +#include #include #include #include diff --git a/libs/mangle/rend2d/servers/sdl_driver.cpp b/libs/mangle/rend2d/servers/sdl_driver.cpp index aa1ff6c6d..84a17933f 100644 --- a/libs/mangle/rend2d/servers/sdl_driver.cpp +++ b/libs/mangle/rend2d/servers/sdl_driver.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include using namespace Mangle::Rend2D; diff --git a/libs/mangle/rend2d/servers/sdl_gl_driver.cpp b/libs/mangle/rend2d/servers/sdl_gl_driver.cpp index 2bcb1d677..db519e091 100644 --- a/libs/mangle/rend2d/servers/sdl_gl_driver.cpp +++ b/libs/mangle/rend2d/servers/sdl_gl_driver.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include using namespace Mangle::Rend2D; diff --git a/libs/mangle/stream/clients/audiere_file.cpp b/libs/mangle/stream/clients/audiere_file.cpp deleted file mode 100644 index 16bc7891a..000000000 --- a/libs/mangle/stream/clients/audiere_file.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "audiere_file.hpp" - -using namespace audiere; -using namespace Mangle::Stream; - -bool AudiereFile::seek(int pos, SeekMode mode) -{ - assert(inp->isSeekable); - assert(inp->hasPosition); - - size_t newPos; - - switch(mode) - { - case BEGIN: newPos = pos; break; - case CURRENT: newPos = pos+tell(); break; - case END: - // Seeking from the end. This requires that we're able to get - // the entire size of the stream. The pos also has to be - // non-positive. - assert(inp->hasSize); - assert(pos <= 0); - newPos = inp->size() + pos; - break; - default: - assert(0 && "invalid seek mode"); - } - - inp->seek(newPos); - return inp->tell() == newPos; - -} diff --git a/libs/mangle/stream/clients/audiere_file.hpp b/libs/mangle/stream/clients/audiere_file.hpp deleted file mode 100644 index 61e26f21b..000000000 --- a/libs/mangle/stream/clients/audiere_file.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef MANGLE_STREAM_AUDIERECLIENT_H -#define MANGLE_STREAM_AUDIERECLIENT_H - -#include -#include - -#include "../stream.hpp" - -namespace Mangle { -namespace Stream { - -/** @brief An Audiere::File that wraps a Mangle::Stream input. - - This lets Audiere read sound files from any generic archive or - file manager that supports Mangle streams. - */ -class AudiereFile : public audiere::RefImplementation -{ - StreamPtr inp; - - public: - AudiereFile(StreamPtr _inp) - : inp(_inp) {} - - /// Read 'count' bytes, return bytes successfully read - int ADR_CALL read(void *buf, int count) - { return inp->read(buf,count); } - - /// Seek, relative to specified seek mode. Returns true if successful. - bool ADR_CALL seek(int pos, audiere::File::SeekMode mode); - - /// Get current position - int ADR_CALL tell() - { assert(inp->hasPosition); return inp->tell(); } -}; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/clients/io_stream.cpp b/libs/mangle/stream/clients/io_stream.cpp deleted file mode 100644 index 5f1edc221..000000000 --- a/libs/mangle/stream/clients/io_stream.cpp +++ /dev/null @@ -1,221 +0,0 @@ -#include "io_stream.hpp" - -// This seems to work -#ifndef EOF -#define EOF -1 -#endif - -using namespace Mangle::Stream; - -#define BSIZE 1024 - -// Streambuf for normal stream reading -class _istreambuf : public std::streambuf -{ - StreamPtr client; - char buf[BSIZE]; - -public: - _istreambuf(StreamPtr strm) : client(strm) - { - // Make sure we picked the right class - assert(client->isReadable); - assert(!client->hasPtr); - - // Tell streambuf to delegate reading operations to underflow() - setg(NULL,NULL,NULL); - - // Disallow writing - setp(NULL,NULL); - } - - /* Underflow is called when there is no more info to read in the - input buffer. We need to refill buf with new data (if any), and - set up the internal pointers with setg() to reflect the new - state. - */ - int underflow() - { - // Read some more data - size_t read = client->read(buf, BSIZE); - assert(read <= BSIZE); - - // If we're out of data, then EOF - if(read == 0) - return EOF; - - // Otherwise, set up input buffer - setg(buf, buf, buf+read); - - // Return the first char - return *((unsigned char*)buf); - } - - // Seek stream, if the source supports it. Ignores the second - // parameter as Mangle doesn't separate input and output pointers. - std::streampos seekpos(std::streampos pos, std::ios_base::openmode = std::ios_base::in) - { - // Does this stream know how to seek? - if(!client->isSeekable || !client->hasPosition) - // If not, signal an error. - return -1; - - // Set stream position and reset the buffer. - client->seek(pos); - setg(NULL,NULL,NULL); - - return client->tell(); - } -}; - -// Streambuf optimized for pointer-based input streams -class _ptrstreambuf : public std::streambuf -{ - StreamPtr client; - -public: - _ptrstreambuf(StreamPtr strm) : client(strm) - { - // Make sure we picked the right class - assert(client->isReadable); - assert(client->hasPtr); - - // seekpos() does all the work - seekpos(0); - } - - // Underflow is only called when we're at the end of the file - int underflow() { return EOF; } - - // Seek to a new position within the memory stream. This bypasses - // client->seek() entirely so isSeekable doesn't have to be set. - std::streampos seekpos(std::streampos pos, std::ios_base::openmode = std::ios_base::in) - { - // All pointer streams need a size - assert(client->hasSize); - - // Figure out how much will be left of the stream after seeking - size_t size = client->size() - pos; - - // Get a pointer - char* ptr = (char*)client->getPtr(pos,size); - - // And use it - setg(ptr,ptr,ptr+size); - - return pos; - } -}; - -// Streambuf for stream writing -class _ostreambuf : public std::streambuf -{ - StreamPtr client; - char buf[BSIZE]; - -public: - _ostreambuf(StreamPtr strm) : client(strm) - { - // Make sure we picked the right class - assert(client->isWritable); - - // Inform streambuf about our nice buffer - setp(buf, buf+BSIZE); - - // Disallow reading - setg(NULL,NULL,NULL); - } - - /* Sync means to flush (write) all current data to the output - stream. It will also set up the entire output buffer to be usable - again. - */ - int sync() - { - // Get the number of bytes that streambuf wants us to write - int num = pptr() - pbase(); - assert(num >= 0); - - // Is there any work to do? - if(num == 0) return 0; - - if((int)client->write(pbase(), num) != num) - // Inform caller that writing failed - return -1; - - // Reset output buffer pointers - setp(buf, buf+BSIZE); - - // No error - return 0; - } - - /* Called whenever the output buffer is full. - */ - int overflow(int c) - { - // First, write all existing data - if(sync()) return EOF; - - // Put the requested character in the next round of output - if(c != EOF) - { - *pptr() = c; - pbump(1); - } - - // No error - return 0; - } - - // Seek stream, if the source supports it. - std::streampos seekpos(std::streampos pos, std::ios_base::openmode = std::ios_base::out) - { - if(!client->isSeekable || !client->hasPosition) - return -1; - - // Flush data and reset buffers - sync(); - - // Set stream position - client->seek(pos); - - return client->tell(); - } -}; - -MangleIStream::MangleIStream(StreamPtr inp) - : std::istream(NULL) -{ - assert(inp->isReadable); - - // Pick the right streambuf implementation based on whether the - // input supports pointers or not. - if(inp->hasPtr) - buf = new _ptrstreambuf(inp); - else - buf = new _istreambuf(inp); - - rdbuf(buf); -} - -MangleIStream::~MangleIStream() -{ - delete buf; -} - -MangleOStream::MangleOStream(StreamPtr out) - : std::ostream(NULL) -{ - assert(out->isWritable); - buf = new _ostreambuf(out); - - rdbuf(buf); -} - -MangleOStream::~MangleOStream() -{ - // Make sure we don't have lingering data on exit - flush(); - delete buf; -} diff --git a/libs/mangle/stream/clients/io_stream.hpp b/libs/mangle/stream/clients/io_stream.hpp deleted file mode 100644 index 98c6252ed..000000000 --- a/libs/mangle/stream/clients/io_stream.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef MANGLE_STREAM_IOSTREAM_H -#define MANGLE_STREAM_IOSTREAM_H - -#include -#include "../stream.hpp" -#include - -namespace Mangle { -namespace Stream { - - /** This file contains classes for wrapping an std::istream or - std::ostream around a Mangle::Stream. - - This allows you to use Mangle streams in places that require std - streams. - - This is much easier than trying to make your own custom streams - into iostreams. The std::iostream interface is horrible and NOT - designed for easy subclassing. Create a Mangle::Stream instead, - and use this wrapper. - */ - - // An istream wrapping a readable Mangle::Stream. Has extra - // optimizations for pointer-based streams. - class MangleIStream : public std::istream - { - std::streambuf *buf; - public: - MangleIStream(StreamPtr inp); - ~MangleIStream(); - }; - - // An ostream wrapping a writable Mangle::Stream. - class MangleOStream : public std::ostream - { - std::streambuf *buf; - public: - MangleOStream(StreamPtr inp); - ~MangleOStream(); - }; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/clients/ogre_datastream.hpp b/libs/mangle/stream/clients/ogre_datastream.hpp deleted file mode 100644 index 76a6f20cf..000000000 --- a/libs/mangle/stream/clients/ogre_datastream.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef MANGLE_STREAM_OGRECLIENT_H -#define MANGLE_STREAM_OGRECLIENT_H - -#include -#include -#include "../stream.hpp" - -namespace Mangle { -namespace Stream { - -/** An OGRE DataStream that wraps a Mangle::Stream input. - - This has been built and tested against OGRE 1.6.2. You might have - to make your own modifications if you're working with newer (or - older) versions. - */ -class Mangle2OgreStream : public Ogre::DataStream -{ - StreamPtr inp; - - void init() - { - // Get the size, if possible - if(inp->hasSize) - mSize = inp->size(); - - // Allow writing if inp supports it - if(inp->isWritable) - mAccess |= Ogre::DataStream::WRITE; - } - - public: - /// Constructor without name - Mangle2OgreStream(StreamPtr _inp) - : inp(_inp) { init(); } - - /// Constructor for a named data stream - Mangle2OgreStream(const Ogre::String &name, StreamPtr _inp) - : Ogre::DataStream(name), inp(_inp) { init(); } - - // Only implement the DataStream functions we have to implement - - size_t read(void *buf, size_t count) - { return inp->read(buf,count); } - - size_t write(const void *buf, size_t count) - { assert(inp->isWritable); return inp->write(buf,count); } - - void skip(long count) - { - assert(inp->isSeekable && inp->hasPosition); - inp->seek(inp->tell() + count); - } - - void seek(size_t pos) - { assert(inp->isSeekable); inp->seek(pos); } - - size_t tell() const - { assert(inp->hasPosition); return inp->tell(); } - - bool eof() const { return inp->eof(); } - - /// Does nothing - void close() {} -}; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/filters/buffer_stream.hpp b/libs/mangle/stream/filters/buffer_stream.hpp deleted file mode 100644 index f037212a3..000000000 --- a/libs/mangle/stream/filters/buffer_stream.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef MANGLE_STREAM_BUFFER_H -#define MANGLE_STREAM_BUFFER_H - -#include "../servers/memory_stream.hpp" -#include - -namespace Mangle { -namespace Stream { - -/** A Stream that reads another Stream into a buffer, and serves it as - a MemoryStream. Might be expanded with other capabilities later. - */ - -class BufferStream : public MemoryStream -{ - std::vector buffer; - - public: - /* - input = stream to copy - ADD = each read increment (for streams without size()) - */ - BufferStream(StreamPtr input, size_t ADD = 32*1024) - { - assert(input); - - // Allocate memory, read the stream into it. Then call set() - if(input->hasSize) - { - // We assume that we can get the position as well - assert(input->hasPosition); - - // Calculate how much is left of the stream - size_t left = input->size() - input->tell(); - - // Allocate the buffer and fill it - buffer.resize(left); - input->read(&buffer[0], left); - } - else - { - // We DON'T know how big the stream is. We'll have to read - // it in increments. - size_t len=0, newlen; - - while(!input->eof()) - { - // Read one block - newlen = len + ADD; - buffer.resize(newlen); - size_t read = input->read(&buffer[len], ADD); - - // Increase the total length - len += read; - - // If we read less than expected, we should be at the - // end of the stream - assert(read == ADD || (read < ADD && input->eof())); - } - - // Downsize to match the real length - buffer.resize(len); - } - - // After the buffer has been filled, set up our MemoryStream - // ancestor to reference it. - set(&buffer[0], buffer.size()); - } -}; - -typedef boost::shared_ptr BufferStreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/filters/pure_filter.hpp b/libs/mangle/stream/filters/pure_filter.hpp deleted file mode 100644 index f0ce91f87..000000000 --- a/libs/mangle/stream/filters/pure_filter.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MANGLE_STREAM_FILTER_H -#define MANGLE_STREAM_FILTER_H - -#include "../stream.hpp" - -namespace Mangle { -namespace Stream { - -/** A stream that filters another stream with no changes. Intended as - a base class for other filters. - */ -class PureFilter : public Stream -{ - protected: - StreamPtr src; - - public: - PureFilter() {} - PureFilter(StreamPtr _src) - { setStream(_src); } - - void setStream(StreamPtr _src) - { - src = _src; - isSeekable = src->isSeekable; - isWritable = src->isWritable; - hasPosition = src->hasPosition; - hasSize = src->hasSize; - hasPtr = src->hasPtr; - } - - size_t read(void *buf, size_t count) { return src->read(buf, count); } - size_t write(const void *buf, size_t count) { return src->write(buf,count); } - void flush() { src->flush(); } - void seek(size_t pos) { src->seek(pos); } - size_t tell() const { return src->tell(); } - size_t size() const { return src->size(); } - bool eof() const { return src->eof(); } - const void *getPtr() { return src->getPtr(); } - const void *getPtr(size_t size) { return src->getPtr(size); } - const void *getPtr(size_t pos, size_t size) - { return src->getPtr(pos, size); } -}; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/filters/slice_stream.hpp b/libs/mangle/stream/filters/slice_stream.hpp deleted file mode 100644 index 6337b9d57..000000000 --- a/libs/mangle/stream/filters/slice_stream.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef MANGLE_STREAM_SLICE_H -#define MANGLE_STREAM_SLICE_H - -#include "../stream.hpp" - -namespace Mangle { -namespace Stream { - -/** A Stream that represents a subset (called a slice) of another stream. - */ -class SliceStream : public Stream -{ - StreamPtr src; - size_t offset, length, pos; - - public: - SliceStream(StreamPtr _src, size_t _offset, size_t _length) - : src(_src), offset(_offset), length(_length), pos(0) - { - assert(src->hasSize); - assert(src->isSeekable); - - // Make sure we can actually fit inside the source stream - assert(src->size() >= offset+length); - - isSeekable = true; - hasPosition = true; - hasSize = true; - hasPtr = src->hasPtr; - isWritable = src->isWritable; - } - - size_t read(void *buf, size_t count) - { - // Check that we're not reading past our slice - if(count > length-pos) - count = length-pos; - - // Seek into place and start reading - src->seek(offset+pos); - count = src->read(buf, count); - - pos += count; - assert(pos <= length); - return count; - } - - // Note that writing to a slice does not allow you to append data, - // you may only overwrite existing data. - size_t write(const void *buf, size_t count) - { - assert(isWritable); - // Check that we're not reading past our slice - if(count > length-pos) - count = length-pos; - - // Seek into place and action - src->seek(offset+pos); - count = src->write(buf, count); - - pos += count; - assert(pos <= length); - return count; - } - - void seek(size_t _pos) - { - pos = _pos; - if(pos > length) pos = length; - } - - bool eof() const { return pos == length; } - size_t tell() const { return pos; } - size_t size() const { return length; } - void flush() { src->flush(); } - - const void *getPtr() { return getPtr(0, length); } - const void *getPtr(size_t size) - { - const void *ptr = getPtr(pos, size); - seek(pos+size); - return ptr; - } - const void *getPtr(size_t pos, size_t size) - { - // Boundry checks on pos and size. Bounding the size is - // important even when getting pointers, as the source stream - // may use the size parameter for something (such as memory - // mapping or buffering.) - if(pos > length) pos = length; - if(pos+size > length) size = length-pos; - - // Ask the source to kindly give us a pointer - return src->getPtr(offset+pos, size); - } -}; - -typedef boost::shared_ptr SliceStreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/servers/file_stream.hpp b/libs/mangle/stream/servers/file_stream.hpp deleted file mode 100644 index 314a49642..000000000 --- a/libs/mangle/stream/servers/file_stream.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MANGLE_STREAM_FILESERVER_H -#define MANGLE_STREAM_FILESERVER_H - -#include "std_stream.hpp" -#include -#include - -namespace Mangle { -namespace Stream { - -/** Very simple file input stream, based on std::ifstream - */ -class FileStream : public StdStream -{ - std::ifstream file; - - public: - FileStream(const std::string &name) - : StdStream(&file) - { - file.open(name.c_str(), std::ios::binary); - - if(file.fail()) - throw std::runtime_error("FileStream: failed to open file " + name); - } - ~FileStream() { file.close(); } -}; - -typedef boost::shared_ptr FileStreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/servers/memory_stream.hpp b/libs/mangle/stream/servers/memory_stream.hpp deleted file mode 100644 index 0849e4a3c..000000000 --- a/libs/mangle/stream/servers/memory_stream.hpp +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef MANGLE_STREAM_MEMSERVER_H -#define MANGLE_STREAM_MEMSERVER_H - -#include -#include "../stream.hpp" -#include - -namespace Mangle { -namespace Stream { - -// Do this before the class declaration, since the class itself -// uses it. -class MemoryStream; -typedef boost::shared_ptr MemoryStreamPtr; - -/** A Stream wrapping a memory buffer - - This will create a fully seekable stream out of any pointer/length - pair you give it. - */ -class MemoryStream : public Stream -{ - const void *data; - size_t length, pos; - - public: - MemoryStream(const void *ptr, size_t len) - : data(ptr), length(len), pos(0) - { - isSeekable = true; - hasPosition = true; - hasSize = true; - hasPtr = true; - } - - MemoryStream() - : data(NULL), length(0), pos(0) - { - isSeekable = true; - hasPosition = true; - hasSize = true; - hasPtr = true; - } - - size_t read(void *buf, size_t count) - { - assert(data != NULL); - assert(pos <= length); - - // Don't read more than we have - if(count > (length - pos)) - count = length - pos; - - // Copy data - if(count) - memcpy(buf, ((char*)data)+pos, count); - - // aaand remember to increase the count - pos += count; - - return count; - } - - void seek(size_t _pos) - { - pos = _pos; - if(pos > length) - pos = length; - } - - size_t tell() const { return pos; } - size_t size() const { return length; } - bool eof() const { return pos == length; } - - const void *getPtr() { return data; } - const void *getPtr(size_t size) - { - // This variant of getPtr must move the position pointer - size_t opos = pos; - pos += size; - if(pos > length) pos = length; - return ((char*)data)+opos; - } - const void *getPtr(size_t pos, size_t size) - { - if(pos > length) pos = length; - return ((char*)data)+pos; - } - - // New members in MemoryStream: - - /// Set a new buffer and length. This will rewind the position to zero. - void set(const void* _data, size_t _length) - { - data = _data; - length = _length; - pos = 0; - } - - /// Clone this memory stream - /** Make a new stream of the same buffer. If setPos is true, we also - set the clone's position to be the same as ours. - - No memory is copied during this operation, the new stream is - just another 'view' into the same shared memory buffer. - */ - MemoryStreamPtr clone(bool setPos=false) const - { - MemoryStreamPtr res(new MemoryStream(data, length)); - if(setPos) res->seek(pos); - return res; - } -}; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/servers/ogre_datastream.hpp b/libs/mangle/stream/servers/ogre_datastream.hpp deleted file mode 100644 index a5be98c84..000000000 --- a/libs/mangle/stream/servers/ogre_datastream.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef MANGLE_STREAM_OGRESERVER_H -#define MANGLE_STREAM_OGRESERVER_H - -#include - -namespace Mangle { -namespace Stream { - -/** A Stream wrapping an OGRE DataStream. - - This has been built and tested against OGRE 1.6.2. You might have - to make your own modifications if you're working with newer (or - older) versions. - */ -class OgreStream : public Stream -{ - Ogre::DataStreamPtr inp; - - public: - OgreStream(Ogre::DataStreamPtr _inp) : inp(_inp) - { - isSeekable = true; - hasPosition = true; - hasSize = true; - } - - size_t read(void *buf, size_t count) { return inp->read(buf,count); } - void seek(size_t pos) { inp->seek(pos); } - size_t tell() const { return inp->tell(); } - size_t size() const { return inp->size(); } - bool eof() const { return inp->eof(); } -}; - -typedef boost::shared_ptr OgreStreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/servers/outfile_stream.hpp b/libs/mangle/stream/servers/outfile_stream.hpp deleted file mode 100644 index 8d953d904..000000000 --- a/libs/mangle/stream/servers/outfile_stream.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MANGLE_OSTREAM_FILESERVER_H -#define MANGLE_OSTREAM_FILESERVER_H - -#include "std_ostream.hpp" -#include - -namespace Mangle { -namespace Stream { - -/** File stream based on std::ofstream, only supports writing. - */ -class OutFileStream : public StdOStream -{ - std::ofstream file; - - public: - /** - By default we overwrite the file. If append=true, then we will - open an existing file and seek to the end instead. - */ - OutFileStream(const std::string &name, bool append=false) - : StdOStream(&file) - { - std::ios::openmode mode = std::ios::binary; - if(append) - mode |= std::ios::app; - else - mode |= std::ios::trunc; - - file.open(name.c_str(), mode); - - if(file.fail()) - throw std::runtime_error("OutFileStream: failed to open file " + name); - } - ~OutFileStream() { file.close(); } -}; - -typedef boost::shared_ptr OutFileStreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/servers/phys_stream.hpp b/libs/mangle/stream/servers/phys_stream.hpp deleted file mode 100644 index 4312ac041..000000000 --- a/libs/mangle/stream/servers/phys_stream.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MANGLE_STREAM_OGRESERVER_H -#define MANGLE_STREAM_OGRESERVER_H - -#include - -namespace Mangle { -namespace Stream { - -/// A Stream wrapping a PHYSFS_file stream from the PhysFS library. -class PhysFile : public Stream -{ - PHYSFS_file *file; - - public: - PhysFile(PHYSFS_file *inp) : file(inp) - { - isSeekable = true; - hasPosition = true; - hasSize = true; - } - - ~PhysFile() { PHYSFS_close(file); } - - size_t read(void *buf, size_t count) - { return PHYSFS_read(file, buf, 1, count); } - - void seek(size_t pos) { PHYSFS_seek(file, pos); } - size_t tell() const { return PHYSFS_tell(file); } - size_t size() const { return PHYSFS_fileLength(file); } - bool eof() const { return PHYSFS_eof(file); } -}; - -typedef boost::shared_ptr PhysFilePtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/servers/std_ostream.hpp b/libs/mangle/stream/servers/std_ostream.hpp deleted file mode 100644 index f406e1a93..000000000 --- a/libs/mangle/stream/servers/std_ostream.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef MANGLE_OSTREAM_STDIOSERVER_H -#define MANGLE_OSTREAM_STDIOSERVER_H - -#include "../stream.hpp" -#include -#include - -namespace Mangle { -namespace Stream { - -/** Simple wrapper for std::ostream, only supports output. - */ -class StdOStream : public Stream -{ - std::ostream *inf; - - static void fail(const std::string &msg) - { throw std::runtime_error("StdOStream: " + msg); } - - public: - StdOStream(std::ostream *_inf) - : inf(_inf) - { - isSeekable = true; - hasPosition = true; - hasSize = true; - isWritable = true; - isReadable = false; - } - - size_t write(const void* buf, size_t len) - { - inf->write((const char*)buf, len); - if(inf->fail()) - fail("error writing to stream"); - // Just return len, but that is ok. The only cases where we would - // return less than len is when an error occured. - return len; - } - - void flush() - { - inf->flush(); - } - - void seek(size_t pos) - { - inf->seekp(pos); - if(inf->fail()) - fail("seek error"); - } - - size_t tell() const - // Hack around the fact that ifstream->tellp() isn't const - { return ((StdOStream*)this)->inf->tellp(); } - - size_t size() const - { - // Use the standard iostream size hack, terrible as it is. - std::streampos pos = inf->tellp(); - inf->seekp(0, std::ios::end); - size_t res = inf->tellp(); - inf->seekp(pos); - - if(inf->fail()) - fail("could not get stream size"); - - return res; - } - - bool eof() const - { return inf->eof(); } -}; - -typedef boost::shared_ptr StdOStreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/servers/std_stream.hpp b/libs/mangle/stream/servers/std_stream.hpp deleted file mode 100644 index 163f023f6..000000000 --- a/libs/mangle/stream/servers/std_stream.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef MANGLE_STREAM_STDIOSERVER_H -#define MANGLE_STREAM_STDIOSERVER_H - -#include "../stream.hpp" -#include -#include - -namespace Mangle { -namespace Stream { - -/** Simple wrapper for std::istream. - */ -class StdStream : public Stream -{ - std::istream *inf; - - static void fail(const std::string &msg) - { throw std::runtime_error("StdStream: " + msg); } - - public: - StdStream(std::istream *_inf) - : inf(_inf) - { - isSeekable = true; - hasPosition = true; - hasSize = true; - } - - size_t read(void* buf, size_t len) - { - inf->read((char*)buf, len); - if(inf->bad()) - fail("error reading from stream"); - return inf->gcount(); - } - - void seek(size_t pos) - { - inf->clear(); - inf->seekg(pos); - if(inf->fail()) - fail("seek error"); - } - - size_t tell() const - // Hack around the fact that ifstream->tellg() isn't const - { return ((StdStream*)this)->inf->tellg(); } - - size_t size() const - { - // Use the standard iostream size hack, terrible as it is. - std::streampos pos = inf->tellg(); - inf->seekg(0, std::ios::end); - size_t res = inf->tellg(); - inf->seekg(pos); - - if(inf->fail()) - fail("could not get stream size"); - - return res; - } - - bool eof() const - { return inf->eof(); } -}; - -typedef boost::shared_ptr StdStreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/stream.hpp b/libs/mangle/stream/stream.hpp deleted file mode 100644 index 2ee4fcbd8..000000000 --- a/libs/mangle/stream/stream.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef MANGLE_STREAM_INPUT_H -#define MANGLE_STREAM_INPUT_H - -#include -#include "../tools/shared_ptr.hpp" -#include - -namespace Mangle { -namespace Stream { - -/// An abstract interface for a stream data. -class Stream -{ - public: - // Feature options. These should be set in the constructor. - - /// If true, seek() works - bool isSeekable; - - /// If true, tell() works - bool hasPosition; - - /// If true, size() works - bool hasSize; - - /// If true, write() works. Writing through pointer operations is - /// not (yet) supported. - bool isWritable; - - /// If true, read() and eof() works. - bool isReadable; - - /// If true, the getPtr() functions work - bool hasPtr; - - /// Initialize all bools to false by default, except isReadable. - Stream() : - isSeekable(false), hasPosition(false), hasSize(false), - isWritable(false), isReadable(true), hasPtr(false) {} - - /// Virtual destructor - virtual ~Stream() {} - - /** Read a given number of bytes from the stream. Returns the actual - number read. If the return value is less than count, then the - stream is empty or an error occured. Only required for readable - streams. - */ - virtual size_t read(void* buf, size_t count) { assert(0); return 0; } - - /** Write a given number of bytes from the stream. Semantics is - similar to read(). Only valid if isWritable is true. - - The returned value is the number of bytes written. However in - most cases, unlike for read(), a write-count less than requested - usually indicates an error. The implementation should throw such - errors as exceptions rather than expect the caller to handle - them. - - Since most implementations do NOT support writing we default to - an assert(0) here. - */ - virtual size_t write(const void *buf, size_t count) { assert(0); return 0; } - - /// Flush an output stream. Does nothing for non-writing streams. - virtual void flush() {} - - /// Seek to an absolute position in this stream. Not all streams are - /// seekable. - virtual void seek(size_t pos) { assert(0); } - - /// Get the current position in the stream. Non-seekable streams are - /// not required to keep track of this. - virtual size_t tell() const { assert(0); return 0; } - - /// Return the total size of the stream. For streams hasSize is - /// false, size() should fail in some way, since it is an error to - /// call it in those cases. - virtual size_t size() const { assert(0); return 0; } - - /// Returns true if the stream is empty. Required for readable - /// streams. - virtual bool eof() const { assert(0); return 0; } - - /// Return a pointer to the entire stream. This function (and the - /// other getPtr() variants below) should only be implemented for - /// memory-based streams where using them would be an optimization. - virtual const void *getPtr() { assert(0); return NULL; } - - /// Get a pointer to a memory region of 'size' bytes starting from - /// position 'pos' - virtual const void *getPtr(size_t pos, size_t size) { assert(0); return NULL; } - - /// Get a pointer to a memory region of 'size' bytes from the - /// current position. Unlike the two other getPtr variants, this - /// will advance the position past the returned area. - virtual const void *getPtr(size_t size) { assert(0); return NULL; } -}; - -typedef boost::shared_ptr StreamPtr; - -}} // namespaces -#endif diff --git a/libs/mangle/stream/tests/.gitignore b/libs/mangle/stream/tests/.gitignore deleted file mode 100644 index 9dfd618e2..000000000 --- a/libs/mangle/stream/tests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*_test -test.file diff --git a/libs/mangle/stream/tests/Makefile b/libs/mangle/stream/tests/Makefile deleted file mode 100644 index 5f4397819..000000000 --- a/libs/mangle/stream/tests/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -GCC=g++ -I../ -Wall -Werror - -all: ogre_client_test audiere_client_test memory_server_test buffer_filter_test file_server_test slice_filter_test file_write_test iostream_test - -I_OGRE=$(shell pkg-config --cflags OGRE) -L_OGRE=$(shell pkg-config --libs OGRE) -L_AUDIERE=-laudiere - -ogre_client_test: ogre_client_test.cpp ../stream.hpp ../clients/ogre_datastream.hpp - $(GCC) $< -o $@ $(I_OGRE) $(L_OGRE) - -audiere_client_test: audiere_client_test.cpp ../stream.hpp ../clients/audiere_file.hpp ../clients/audiere_file.cpp - $(GCC) $< -o $@ ../clients/audiere_file.cpp $(L_AUDIERE) - -iostream_test: iostream_test.cpp ../clients/io_stream.cpp - $(GCC) $^ -o $@ - -file_server_test: file_server_test.cpp ../stream.hpp ../servers/file_stream.hpp ../servers/std_stream.hpp - $(GCC) $< -o $@ - -file_write_test: file_write_test.cpp ../stream.hpp ../servers/outfile_stream.hpp ../servers/std_ostream.hpp - $(GCC) $< -o $@ - -memory_server_test: memory_server_test.cpp ../stream.hpp ../servers/memory_stream.hpp - $(GCC) $< -o $@ - -buffer_filter_test: buffer_filter_test.cpp ../stream.hpp ../servers/memory_stream.hpp ../filters/buffer_stream.hpp - $(GCC) $< -o $@ - -slice_filter_test: slice_filter_test.cpp ../stream.hpp ../servers/memory_stream.hpp ../filters/slice_stream.hpp - $(GCC) $< -o $@ - -clean: - rm *_test diff --git a/libs/mangle/stream/tests/audiere_client_test.cpp b/libs/mangle/stream/tests/audiere_client_test.cpp deleted file mode 100644 index 82be569cc..000000000 --- a/libs/mangle/stream/tests/audiere_client_test.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "../servers/memory_stream.hpp" -#include "../clients/audiere_file.hpp" -#include -#include - -using namespace Mangle::Stream; -using namespace audiere; -using namespace std; - -int main() -{ - char str[12]; - memset(str, 0, 12); - StreamPtr inp(new MemoryStream("hello world", 11)); - FilePtr p(new AudiereFile(inp)); - cout << "pos=" << p->tell() << endl; - p->read(str, 2); - cout << "2 bytes: " << str << endl; - cout << "pos=" << p->tell() << endl; - p->seek(4, File::BEGIN); - cout << "pos=" << p->tell() << endl; - p->read(str, 3); - cout << "3 bytes: " << str << endl; - p->seek(-1, File::CURRENT); - cout << "pos=" << p->tell() << endl; - p->seek(-4, File::END); - cout << "pos=" << p->tell() << endl; - p->read(str, 4); - cout << "last 4 bytes: " << str << endl; - p->seek(0, File::BEGIN); - p->read(str, 11); - cout << "entire stream: " << str << endl; - return 0; -} diff --git a/libs/mangle/stream/tests/buffer_filter_test.cpp b/libs/mangle/stream/tests/buffer_filter_test.cpp deleted file mode 100644 index e53bda651..000000000 --- a/libs/mangle/stream/tests/buffer_filter_test.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -#include "../filters/buffer_stream.hpp" - -using namespace Mangle::Stream; -using namespace std; - -int main() -{ - StreamPtr orig (new MemoryStream("hello world", 11)); - StreamPtr inp (new BufferStream(orig)); - - cout << "Size: " << inp->size() << endl; - cout << "Pos: " << inp->tell() << "\nSeeking...\n"; - inp->seek(3); - cout << "Pos: " << inp->tell() << endl; - char data[12]; - memset(data, 0, 12); - cout << "Reading: " << inp->read(data, 4) << endl; - cout << "Four bytes: " << data << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << "\nSeeking again...\n"; - inp->seek(33); - cout << "Pos: " << inp->tell() << endl; - cout << "Eof: " << inp->eof() << "\nSeek to 6\n"; - inp->seek(6); - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << endl; - cout << "Over-reading: " << inp->read(data, 200) << endl; - cout << "Result: " << data << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << endl; - inp->seek(0); - cout << "Finally, reading the entire string: " << inp->read(data,11) << endl; - cout << "Result: " << data << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << endl; - - return 0; -} diff --git a/libs/mangle/stream/tests/file_server_test.cpp b/libs/mangle/stream/tests/file_server_test.cpp deleted file mode 100644 index 3e1e3cfa5..000000000 --- a/libs/mangle/stream/tests/file_server_test.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "../servers/file_stream.hpp" -#include - -using namespace Mangle::Stream; -using namespace std; - -int main() -{ - StreamPtr inp(new FileStream("file_server_test.cpp")); - - char buf[21]; - buf[20] = 0; - cout << "pos=" << inp->tell() << " eof=" << inp->eof() << endl; - inp->read(buf, 20); - cout << "First 20 bytes: " << buf << endl; - cout << "pos=" << inp->tell() << " eof=" << inp->eof() << endl; - return 0; -} diff --git a/libs/mangle/stream/tests/file_write_test.cpp b/libs/mangle/stream/tests/file_write_test.cpp deleted file mode 100644 index c6c61fcca..000000000 --- a/libs/mangle/stream/tests/file_write_test.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "../servers/outfile_stream.hpp" -#include - -using namespace Mangle::Stream; -using namespace std; - -void print(Stream &str) -{ - cout << "size=" << str.size() - << " pos=" << str.tell() - << " eof=" << str.eof() - << endl; -} - -int main() -{ - { - cout << "\nCreating file\n"; - OutFileStream out("test.file"); - print(out); - out.write("hello",5); - print(out); - } - - { - cout << "\nAppending to file\n"; - OutFileStream out("test.file", true); - print(out); - out.write(" again\n",7); - print(out); - } - - { - cout << "\nOverwriting file\n"; - OutFileStream out("test.file"); - print(out); - out.write("overwrite!\n",11); - print(out); - } - return 0; -} diff --git a/libs/mangle/stream/tests/iostream_test.cpp b/libs/mangle/stream/tests/iostream_test.cpp deleted file mode 100644 index 60648c6c5..000000000 --- a/libs/mangle/stream/tests/iostream_test.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include -#include "../clients/io_stream.hpp" -#include "../servers/memory_stream.hpp" - -using namespace Mangle::Stream; -using namespace std; - -void test1() -{ - cout << "Testing ASCII reading from memory:\n"; - StreamPtr input(new MemoryStream("hello you world you", 19)); - MangleIStream inp(input); - - string str; - while(!inp.eof()) - { - inp >> str; - cout << "Got: " << str << endl; - } -} - -class Dummy : public Stream -{ - int count; - -public: - - Dummy() : count(0) - { - } - - size_t read(void *ptr, size_t num) - { - char *p = (char*)ptr; - char *start = p; - for(; (count < 2560) && (p-start < (int)num); count++) - { - *p = count / 10; - p++; - } - return p-start; - } - - bool eof() const { return count == 2560; } -}; - -void test2() -{ - cout << "\nTesting binary reading from non-memory:\n"; - - StreamPtr input(new Dummy); - MangleIStream inp(input); - - int x = 0; - while(!inp.eof()) - { - unsigned char buf[5]; - inp.read((char*)buf,5); - - // istream doesn't set eof() until we read _beyond_ the end of - // the stream, so we need an extra check. - if(inp.gcount() == 0) break; - - /* - for(int i=0;i<5;i++) - cout << (int)buf[i] << " "; - cout << endl; - */ - - assert(buf[4] == buf[0]); - assert(buf[0] == x/2); - x++; - } - cout << " Done\n"; -} - -struct Dummy2 : Stream -{ - Dummy2() - { - isWritable = true; - isReadable = false; - } - - size_t write(const void *ptr, size_t num) - { - const char *p = (const char*)ptr; - cout << " Got: "; - for(unsigned i=0;iwrite("testing", 7); - - cout << " Running through MangleOStream:\n"; - MangleOStream out(output); - out << "hello"; - out << " - are you ok?"; - cout << " Flushing:\n"; - out.flush(); - - cout << " Writing a hell of a lot of characters:\n"; - for(int i=0; i<127; i++) - out << "xxxxxxxx"; // 127 * 8 = 1016 - out << "fffffff"; // +7 = 1023 - cout << " Just one more:\n"; - out << "y"; - cout << " And oooone more:\n"; - out << "z"; - - cout << " Flushing again:\n"; - out.flush(); - cout << " Writing some more and exiting:\n"; - out << "blah bleh blob"; -} - -struct Dummy3 : Stream -{ - int pos; - - Dummy3() : pos(0) - { - hasPosition = true; - isSeekable = true; - } - - size_t read(void*, size_t num) - { - cout << " Reading " << num << " bytes from " << pos << endl; - pos += num; - return num; - } - - void seek(size_t npos) { pos = npos; } - size_t tell() const { return pos; } -}; - -void test4() -{ - cout << "\nTesting seeking;\n"; - StreamPtr input(new Dummy3); - - cout << " Direct reading:\n"; - input->read(0,10); - input->read(0,5); - - MangleIStream inp(input); - - cout << " Reading from istream:\n"; - char buf[20]; - inp.read(buf, 20); - inp.read(buf, 20); - inp.read(buf, 20); - - cout << " Seeking to 30 and reading again:\n"; - inp.seekg(30); - inp.read(buf, 20); -} - -int main() -{ - test1(); - test2(); - test3(); - test4(); - return 0; -} diff --git a/libs/mangle/stream/tests/memory_server_test.cpp b/libs/mangle/stream/tests/memory_server_test.cpp deleted file mode 100644 index 24d3bb17e..000000000 --- a/libs/mangle/stream/tests/memory_server_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#include "../servers/memory_stream.hpp" - -using namespace Mangle::Stream; -using namespace std; - -int main() -{ - Stream* inp = new MemoryStream("hello world\0", 12); - - cout << "Size: " << inp->size() << endl; - cout << "Pos: " << inp->tell() << "\nSeeking...\n"; - inp->seek(3); - cout << "Pos: " << inp->tell() << endl; - char data[12]; - memset(data, 0, 12); - cout << "Reading: " << inp->read(data, 4) << endl; - cout << "Four bytes: " << data << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << "\nSeeking again...\n"; - inp->seek(33); - cout << "Pos: " << inp->tell() << endl; - cout << "Eof: " << inp->eof() << "\nSeek to 6\n"; - inp->seek(6); - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << endl; - cout << "Over-reading: " << inp->read(data, 200) << endl; - cout << "Result: " << data << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << endl; - inp->seek(0); - cout << "Finally, reading the entire string: " << inp->read(data,11) << endl; - cout << "Result: " << data << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Pos: " << inp->tell() << endl; - - cout << "Entire stream from pointer: " << (char*)inp->getPtr() << endl; - - return 0; -} diff --git a/libs/mangle/stream/tests/ogre_client_test.cpp b/libs/mangle/stream/tests/ogre_client_test.cpp deleted file mode 100644 index c8d0442c0..000000000 --- a/libs/mangle/stream/tests/ogre_client_test.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "../servers/memory_stream.hpp" -#include "../clients/ogre_datastream.hpp" -#include - -using namespace Mangle::Stream; -using namespace Ogre; -using namespace std; - -int main() -{ - StreamPtr inp(new MemoryStream("hello world", 11)); - DataStreamPtr p(new Mangle2OgreStream("hello", inp)); - cout << "Name: " << p->getName() << endl; - cout << "As string: " << p->getAsString() << endl; - cout << "pos=" << p->tell() << " eof=" << p->eof() << endl; - p->seek(0); - cout << "pos=" << p->tell() << " eof=" << p->eof() << endl; - p->skip(5); - p->skip(-2); - cout << "pos=" << p->tell() << " eof=" << p->eof() << endl; - return 0; -} diff --git a/libs/mangle/stream/tests/output/audiere_client_test.out b/libs/mangle/stream/tests/output/audiere_client_test.out deleted file mode 100644 index 2130db9fd..000000000 --- a/libs/mangle/stream/tests/output/audiere_client_test.out +++ /dev/null @@ -1,9 +0,0 @@ -pos=0 -2 bytes: he -pos=2 -pos=4 -3 bytes: o w -pos=6 -pos=7 -last 4 bytes: orld -entire stream: hello world diff --git a/libs/mangle/stream/tests/output/buffer_filter_test.out b/libs/mangle/stream/tests/output/buffer_filter_test.out deleted file mode 100644 index 0ca252f25..000000000 --- a/libs/mangle/stream/tests/output/buffer_filter_test.out +++ /dev/null @@ -1,22 +0,0 @@ -Size: 11 -Pos: 0 -Seeking... -Pos: 3 -Reading: 4 -Four bytes: lo w -Eof: 0 -Pos: 7 -Seeking again... -Pos: 11 -Eof: 1 -Seek to 6 -Eof: 0 -Pos: 6 -Over-reading: 5 -Result: world -Eof: 1 -Pos: 11 -Finally, reading the entire string: 11 -Result: hello world -Eof: 1 -Pos: 11 diff --git a/libs/mangle/stream/tests/output/file_server_test.out b/libs/mangle/stream/tests/output/file_server_test.out deleted file mode 100644 index 240f066a3..000000000 --- a/libs/mangle/stream/tests/output/file_server_test.out +++ /dev/null @@ -1,3 +0,0 @@ -pos=0 eof=0 -First 20 bytes: #include "../servers -pos=20 eof=0 diff --git a/libs/mangle/stream/tests/output/file_write_test.out b/libs/mangle/stream/tests/output/file_write_test.out deleted file mode 100644 index 34b07c49f..000000000 --- a/libs/mangle/stream/tests/output/file_write_test.out +++ /dev/null @@ -1,12 +0,0 @@ - -Creating file -size=0 pos=0 eof=0 -size=5 pos=5 eof=0 - -Appending to file -size=5 pos=5 eof=0 -size=12 pos=12 eof=0 - -Overwriting file -size=0 pos=0 eof=0 -size=11 pos=11 eof=0 diff --git a/libs/mangle/stream/tests/output/iostream_test.out b/libs/mangle/stream/tests/output/iostream_test.out deleted file mode 100644 index b6da80c80..000000000 --- a/libs/mangle/stream/tests/output/iostream_test.out +++ /dev/null @@ -1,32 +0,0 @@ -Testing ASCII reading from memory: -Got: hello -Got: you -Got: world -Got: you - -Testing binary reading from non-memory: - Done - -Writing to dummy stream: - Pure dummy test: - Got: t e s t i n g - Running through MangleOStream: - Flushing: - Got: h e l l o - a r e y o u o k ? - Writing a hell of a lot of characters: - Just one more: - And oooone more: - Got: x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x f f f f f f f y - Flushing again: - Got: z - Writing some more and exiting: - Got: b l a h b l e h b l o b - -Testing seeking; - Direct reading: - Reading 10 bytes from 0 - Reading 5 bytes from 10 - Reading from istream: - Reading 1024 bytes from 15 - Seeking to 30 and reading again: - Reading 1024 bytes from 30 diff --git a/libs/mangle/stream/tests/output/memory_server_test.out b/libs/mangle/stream/tests/output/memory_server_test.out deleted file mode 100644 index 7cd9533e7..000000000 --- a/libs/mangle/stream/tests/output/memory_server_test.out +++ /dev/null @@ -1,23 +0,0 @@ -Size: 12 -Pos: 0 -Seeking... -Pos: 3 -Reading: 4 -Four bytes: lo w -Eof: 0 -Pos: 7 -Seeking again... -Pos: 12 -Eof: 1 -Seek to 6 -Eof: 0 -Pos: 6 -Over-reading: 6 -Result: world -Eof: 1 -Pos: 12 -Finally, reading the entire string: 11 -Result: hello world -Eof: 0 -Pos: 11 -Entire stream from pointer: hello world diff --git a/libs/mangle/stream/tests/output/ogre_client_test.out b/libs/mangle/stream/tests/output/ogre_client_test.out deleted file mode 100644 index 62cd14604..000000000 --- a/libs/mangle/stream/tests/output/ogre_client_test.out +++ /dev/null @@ -1,5 +0,0 @@ -Name: hello -As string: hello world -pos=11 eof=1 -pos=0 eof=0 -pos=3 eof=0 diff --git a/libs/mangle/stream/tests/output/slice_filter_test.out b/libs/mangle/stream/tests/output/slice_filter_test.out deleted file mode 100644 index 6d84704a7..000000000 --- a/libs/mangle/stream/tests/output/slice_filter_test.out +++ /dev/null @@ -1,36 +0,0 @@ - -Slice 1: --------- -Size: 6 -Pos: 0 -Seeking... -Reading 6 bytes -Result: hello -Pos: 6 -Eof: 1 -Seeking: -Pos: 2 -Eof: 0 -Reading 4 bytes -Result: llo -Pos: 6 -Eof: 1 -Entire stream as pointer: hello - -Slice 2: --------- -Size: 6 -Pos: 0 -Seeking... -Reading 6 bytes -Result: world -Pos: 6 -Eof: 1 -Seeking: -Pos: 2 -Eof: 0 -Reading 4 bytes -Result: rld -Pos: 6 -Eof: 1 -Entire stream as pointer: world diff --git a/libs/mangle/stream/tests/slice_filter_test.cpp b/libs/mangle/stream/tests/slice_filter_test.cpp deleted file mode 100644 index da90e24ad..000000000 --- a/libs/mangle/stream/tests/slice_filter_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#include "../filters/slice_stream.hpp" -#include "../servers/memory_stream.hpp" - -using namespace Mangle::Stream; -using namespace std; - -void test(StreamPtr inp) -{ - cout << "Size: " << inp->size() << endl; - cout << "Pos: " << inp->tell() << "\nSeeking...\n"; - char data[6]; - memset(data, 0, 6); - cout << "Reading " << inp->read(data, 6) << " bytes\n"; - cout << "Result: " << data << endl; - cout << "Pos: " << inp->tell() << endl; - cout << "Eof: " << inp->eof() << endl; - inp->seek(2); - cout << "Seeking:\nPos: " << inp->tell() << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Reading " << inp->read(data, 6) << " bytes\n"; - cout << "Result: " << data << endl; - cout << "Pos: " << inp->tell() << endl; - cout << "Eof: " << inp->eof() << endl; - cout << "Entire stream as pointer: " << (char*)inp->getPtr() << endl; -} - -int main() -{ - StreamPtr orig (new MemoryStream("hello\0world\0", 12)); - StreamPtr slice1 (new SliceStream(orig,0,6)); - StreamPtr slice2 (new SliceStream(orig,6,6)); - - cout << "\nSlice 1:\n--------\n"; - test(slice1); - cout << "\nSlice 2:\n--------\n"; - test(slice2); - - return 0; -} diff --git a/libs/mangle/stream/tests/test.sh b/libs/mangle/stream/tests/test.sh deleted file mode 100755 index 2d07708ad..000000000 --- a/libs/mangle/stream/tests/test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -make || exit - -mkdir -p output - -PROGS=*_test - -for a in $PROGS; do - if [ -f "output/$a.out" ]; then - echo "Running $a:" - ./$a | diff output/$a.out - - else - echo "Creating $a.out" - ./$a > "output/$a.out" - git add "output/$a.out" - fi -done diff --git a/libs/mangle/vfs/clients/ogre_archive.cpp b/libs/mangle/vfs/clients/ogre_archive.cpp deleted file mode 100644 index 2d3f7c520..000000000 --- a/libs/mangle/vfs/clients/ogre_archive.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "ogre_archive.hpp" - -#include "../../stream/clients/ogre_datastream.hpp" - -using namespace Mangle::VFS; -using namespace Mangle::Stream; - -Ogre::DataStreamPtr MangleArchive::open(const Ogre::String& filename) const -{ - return Ogre::DataStreamPtr(new Mangle2OgreStream - (filename, vfs->open(filename))); -} - -static void fill(Ogre::FileInfoList &out, FileInfoList &in) -{ - int size = in.size(); - out.resize(size); - - for(int i=0; ihasList); - FileInfoListPtr lst = vfs->list("", recursive, dirs); - Ogre::StringVector *res = new Ogre::StringVector; - - fill(*res, *lst); - - return Ogre::StringVectorPtr(res); -} - -Ogre::FileInfoListPtr MangleArchive::listFileInfo(bool recursive, bool dirs) -{ - assert(vfs->hasList); - FileInfoListPtr lst = vfs->list("", recursive, dirs); - Ogre::FileInfoList *res = new Ogre::FileInfoList; - - fill(*res, *lst); - - return Ogre::FileInfoListPtr(res); -} - -// Find functions will only work if vfs->hasFind is set. -Ogre::StringVectorPtr MangleArchive::find(const Ogre::String& pattern, - bool recursive, - bool dirs) -{ - assert(vfs->hasFind); - FileInfoListPtr lst = vfs->find(pattern, recursive, dirs); - Ogre::StringVector *res = new Ogre::StringVector; - - fill(*res, *lst); - - return Ogre::StringVectorPtr(res); -} - -Ogre::FileInfoListPtr MangleArchive::findFileInfo(const Ogre::String& pattern, - bool recursive, - bool dirs) -{ - assert(vfs->hasFind); - FileInfoListPtr lst = vfs->find(pattern, recursive, dirs); - Ogre::FileInfoList *res = new Ogre::FileInfoList; - - fill(*res, *lst); - - return Ogre::FileInfoListPtr(res); -} diff --git a/libs/mangle/vfs/clients/ogre_archive.hpp b/libs/mangle/vfs/clients/ogre_archive.hpp deleted file mode 100644 index 7b371c6ef..000000000 --- a/libs/mangle/vfs/clients/ogre_archive.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef MANGLE_VFS_OGRECLIENT_H -#define MANGLE_VFS_OGRECLIENT_H - -#include -#include -#include "../vfs.hpp" - -namespace Mangle { -namespace VFS { - -/** An OGRE Archive implementation that wraps a Mangle::VFS - filesystem. - - This has been built and tested against OGRE 1.6.2, and has been - extended for OGRE 1.7. You might have to make your own - modifications if you're working with newer (or older) versions. - */ -class MangleArchive : public Ogre::Archive -{ - VFSPtr vfs; - - public: - MangleArchive(VFSPtr _vfs, const std::string &name, - const std::string &archType = "Mangle") - : Ogre::Archive(name, archType) - , vfs(_vfs) - {} - - bool isCaseSensitive() const { return vfs->isCaseSensitive; } - - // These do nothing. You have to load / unload the archive in the - // constructor/destructor. - void load() {} - void unload() {} - - bool exists(const Ogre::String& filename) - { return vfs->isFile(filename); } - - time_t getModifiedTime(const Ogre::String& filename) - { return vfs->stat(filename)->time; } - - // With both these we support both OGRE 1.6 and 1.7 - Ogre::DataStreamPtr open(const Ogre::String& filename) const; - Ogre::DataStreamPtr open(const Ogre::String& filename, bool readOnly) const - { return open(filename); } - - Ogre::StringVectorPtr list(bool recursive = true, bool dirs = false); - Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false); - - // Find functions will only work if vfs->hasFind is set. - Ogre::StringVectorPtr find(const Ogre::String& pattern, bool recursive = true, - bool dirs = false); - Ogre::FileInfoListPtr findFileInfo(const Ogre::String& pattern, - bool recursive = true, - bool dirs = false); -}; - -}} // namespaces -#endif diff --git a/libs/mangle/vfs/servers/ogre_vfs.cpp b/libs/mangle/vfs/servers/ogre_vfs.cpp deleted file mode 100644 index 7f728c1b0..000000000 --- a/libs/mangle/vfs/servers/ogre_vfs.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "ogre_vfs.hpp" -#include "../../stream/servers/ogre_datastream.hpp" - -using namespace Mangle::VFS; -using namespace Mangle::Stream; - -OgreVFS::OgreVFS(const std::string &_group) - : group(_group) -{ - hasList = true; - hasFind = true; - isCaseSensitive = true; - - // Get the group manager once - gm = Ogre::ResourceGroupManager::getSingletonPtr(); - - // Use the default group if none was specified - if(group.empty()) - group = gm->getWorldResourceGroupName(); -} - -StreamPtr OgreVFS::open(const std::string &name) -{ - Ogre::DataStreamPtr data = gm->openResource(name, group); - return StreamPtr(new OgreStream(data)); -} - -static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs) -{ - int size = in.size(); - out.resize(size); - - for(int i=0; ilistResourceFileInfo(group, dirs); - FileInfoListPtr res(new FileInfoList); - fill(*res, *olist, dirs); - return res; -} - -FileInfoListPtr OgreVFS::find(const std::string& pattern, - bool recursive, - bool dirs) const -{ - Ogre::FileInfoListPtr olist = gm->findResourceFileInfo(group, pattern, dirs); - FileInfoListPtr res(new FileInfoList); - fill(*res, *olist, dirs); - return res; -} diff --git a/libs/mangle/vfs/servers/ogre_vfs.hpp b/libs/mangle/vfs/servers/ogre_vfs.hpp deleted file mode 100644 index 7ab64169d..000000000 --- a/libs/mangle/vfs/servers/ogre_vfs.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef MANGLE_VFS_OGRESERVER_H -#define MANGLE_VFS_OGRESERVER_H - -#include "../vfs.hpp" -#include - -namespace Mangle { -namespace VFS { - -/** @brief An interface into the OGRE VFS system. - - This class does NOT wrap a single Ogre::Archive, but rather an - entire resource group in Ogre. You can use this class to tap into - all paths, Zip files, custom archives on so on that have been - inserted into Ogre as resource locations. - - This has been built and tested against OGRE 1.6.2. You might have - to make your own modifications if you're working with newer (or - older) versions. - */ -class OgreVFS : public VFS -{ - std::string group; - Ogre::ResourceGroupManager *gm; - - public: - /** @brief Constructor - - OGRE must be initialized (ie. you must have created an - Ogre::Root object somewhere) before calling this. - - @param group Optional resource group name. If none is given, - OGRE's default (or 'World') resource group is used. - */ - OgreVFS(const std::string &_group = ""); - - /// Open a new data stream. Deleting the object should be enough to - /// close it. - virtual Stream::StreamPtr open(const std::string &name); - - /// Check for the existence of a file - virtual bool isFile(const std::string &name) const - { return gm->resourceExists(group, name); } - - /// This doesn't work, always returns false. - virtual bool isDir(const std::string &name) const - { return false; } - - /// This doesn't work. - virtual FileInfoPtr stat(const std::string &name) const - { return FileInfoPtr(); } - - /// List all entries in a given directory. A blank dir should be - /// interpreted as a the root/current directory of the archive. If - /// dirs is true, list directories instead of files. OGRE note: The - /// ogre resource systemd does not support recursive listing of - /// files. We might make a separate filter for this later. - virtual FileInfoListPtr list(const std::string& dir = "", - bool recurse=true, - bool dirs=false) const; - - /// Find files after a given pattern. Wildcards (*) are - /// supported. - virtual FileInfoListPtr find(const std::string& pattern, - bool recursive=true, - bool dirs=false) const; -}; - -}} // namespaces -#endif diff --git a/libs/mangle/vfs/servers/physfs_vfs.hpp b/libs/mangle/vfs/servers/physfs_vfs.hpp deleted file mode 100644 index 8535088e0..000000000 --- a/libs/mangle/vfs/servers/physfs_vfs.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef MANGLE_VFS_PHYSFS_SERVER_H -#define MANGLE_VFS_PHYSFS_SERVER_H - -#include "../vfs.hpp" -#include "../../stream/servers/phys_stream.hpp" - -#include -#include - -namespace Mangle { -namespace VFS { - -/** @brief An interface into the PhysFS virtual file system library - - You have to set up PhysFS on your own before using this class. - */ -class PhysVFS : public VFS -{ - public: - PhysVFS() - { - hasList = true; - hasFind = false; - isCaseSensitive = true; - } - - /// Open a new data stream. Deleting the object should be enough to - /// close it. - virtual Stream::StreamPtr open(const std::string &name) - { return Stream::StreamPtr(new Stream::PhysFile(PHYSFS_openRead(name.c_str()))); } - - /// Check for the existence of a file - virtual bool isFile(const std::string &name) const - { return PHYSFS_exists(name.c_str()); } - - /// Checks for a directory - virtual bool isDir(const std::string &name) const - { return PHYSFS_isDirectory(name.c_str()); } - - /// This doesn't work - virtual FileInfoPtr stat(const std::string &name) const - { assert(0); return FileInfoPtr(); } - - virtual FileInfoListPtr list(const std::string& dir = "", - bool recurse=true, - bool dirs=false) const - { - char **files = PHYSFS_enumerateFiles(dir.c_str()); - FileInfoListPtr lst(new FileInfoList); - - // Add all teh files - int i = 0; - while(files[i] != NULL) - { - FileInfo fi; - fi.name = files[i]; - fi.isDir = false; - - lst->push_back(fi); - } - return lst; - } - - virtual FileInfoListPtr find(const std::string& pattern, - bool recursive=true, - bool dirs=false) const - { assert(0); } -}; - -}} // namespaces -#endif diff --git a/libs/mangle/vfs/tests/.gitignore b/libs/mangle/vfs/tests/.gitignore deleted file mode 100644 index 814490404..000000000 --- a/libs/mangle/vfs/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*_test diff --git a/libs/mangle/vfs/tests/Makefile b/libs/mangle/vfs/tests/Makefile deleted file mode 100644 index a5d1d1712..000000000 --- a/libs/mangle/vfs/tests/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -GCC=g++ -I../ -Wall - -all: dummy_test ogre_client_test ogre_resource_test ogre_server_test physfs_server_test - -I_OGRE=$(shell pkg-config --cflags OGRE) -L_OGRE=$(shell pkg-config --libs OGRE) -L_PHYSFS=-lphysfs - -ogre_client_test: ogre_client_test.cpp dummy_vfs.cpp ../vfs.hpp ../clients/ogre_archive.hpp ../clients/ogre_archive.cpp - $(GCC) $< ../clients/ogre_archive.cpp -o $@ $(I_OGRE) $(L_OGRE) - -ogre_resource_test: ogre_resource_test.cpp - $(GCC) $< -o $@ $(I_OGRE) $(L_OGRE) - -ogre_server_test: ogre_server_test.cpp ../vfs.hpp ../servers/ogre_vfs.hpp ../servers/ogre_vfs.cpp - $(GCC) $< -o $@ $(I_OGRE) $(L_OGRE) ../servers/ogre_vfs.cpp - -physfs_server_test: physfs_server_test.cpp ../vfs.hpp ../servers/physfs_vfs.hpp - $(GCC) $< -o $@ $(L_PHYSFS) - -dummy_test: dummy_test.cpp dummy_vfs.cpp ../vfs.hpp - $(GCC) $< -o $@ - -clean: - rm *_test diff --git a/libs/mangle/vfs/tests/dummy_test.cpp b/libs/mangle/vfs/tests/dummy_test.cpp deleted file mode 100644 index 541010c6a..000000000 --- a/libs/mangle/vfs/tests/dummy_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "dummy_vfs.cpp" - -#include -#include - -using namespace std; - -void print(FileInfo &inf) -{ - cout << "name: " << inf.name << endl; - cout << "basename: " << inf.basename << endl; - cout << "isDir: " << inf.isDir << endl; - cout << "size: " << inf.size << endl; - cout << "time: " << inf.time << endl; -} -void print(FileInfoPtr inf) { print(*inf); } - -void print(FileInfoList &lst) -{ - for(unsigned i=0; isize() << endl; - - return 0; -} diff --git a/libs/mangle/vfs/tests/dummy_vfs.cpp b/libs/mangle/vfs/tests/dummy_vfs.cpp deleted file mode 100644 index 0448e96a5..000000000 --- a/libs/mangle/vfs/tests/dummy_vfs.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// This file is shared between several test programs -#include "vfs.hpp" -#include -#include - -#include "../../stream/servers/memory_stream.hpp" - -using namespace Mangle::VFS; -using namespace Mangle::Stream; - -class DummyVFS : public VFS -{ -public: - DummyVFS() - { - hasFind = false; - hasList = true; - isCaseSensitive = true; - } - - // We only support opening 'file1' at the moment. - StreamPtr open(const std::string &name) - { - assert(name == "file1"); - return StreamPtr(new MemoryStream("hello world", 11)); - } - - bool isFile(const std::string &name) const - { - return (name == "file1" || - name == "dir/file2"); - } - - bool isDir(const std::string &name) const - { - return name == "dir"; - } - - /// Get info about a single file - FileInfoPtr stat(const std::string &name) const - { - FileInfoPtr fi(new FileInfo); - fi->name = name; - fi->time = 0; - - if(isFile(name)) - { - if(name == "dir/file2") - { - fi->basename = "file2"; - fi->size = 2; - } - else - { - fi->basename = "file1"; - fi->size = 1; - } - fi->isDir = false; - } - else if(isDir(name)) - { - fi->basename = "dir"; - fi->isDir = true; - fi->size = 0; - } - else assert(0); - - return fi; - } - - /// List all entries in a given directory. A blank dir should be - /// interpreted as a the root/current directory of the archive. If - /// dirs is true, list directories instead of files. - virtual FileInfoListPtr list(const std::string& dir = "", - bool recurse=true, - bool dirs=false) const - { - assert(dir == ""); - - FileInfoListPtr fl(new FileInfoList); - - FileInfo fi; - - if(!dirs) - { - fi.name = "file1"; - fi.basename = "file1"; - fi.isDir = false; - fi.size = 1; - fi.time = 0; - fl->push_back(fi); - - if(recurse) - { - fi.name = "dir/file2"; - fi.basename = "file2"; - fi.size = 2; - fl->push_back(fi); - } - } - else - { - fi.name = "dir"; - fi.basename = "dir"; - fi.isDir = true; - fi.size = 0; - fi.time = 0; - fl->push_back(fi); - } - return fl; - } - - FileInfoListPtr find(const std::string& pattern, - bool recursive=true, - bool dirs=false) const - { assert(0); } -}; diff --git a/libs/mangle/vfs/tests/ogre_client_test.cpp b/libs/mangle/vfs/tests/ogre_client_test.cpp deleted file mode 100644 index 8e1269b56..000000000 --- a/libs/mangle/vfs/tests/ogre_client_test.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "dummy_vfs.cpp" -#include "../clients/ogre_archive.hpp" -#include - -using namespace Ogre; -using namespace std; - -void print(StringVectorPtr lst) -{ - int s = lst->size(); - - for(int i=0; isize() << endl; - cout << "contents: " << file->getAsString() << endl; - - return 0; -} diff --git a/libs/mangle/vfs/tests/ogre_resource_test.cpp b/libs/mangle/vfs/tests/ogre_resource_test.cpp deleted file mode 100644 index 8965adaa1..000000000 --- a/libs/mangle/vfs/tests/ogre_resource_test.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include - -/* - This isn't really a test of our implementation, but a test of using - the Ogre resource system to find files. If the Ogre interface - changes and you have to change this test, you will have to change - the servers/ogre_vfs.cpp implementation equivalently. - - */ - -using namespace std; -using namespace Ogre; - -ResourceGroupManager *gm; -String group; - -void find(const std::string &fileName) -{ - cout << "\nFile: " << fileName << endl; - - if(!gm->resourceExists(group, fileName)) - { - cout << "Does not exist\n"; - return; - } - - DataStreamPtr data = gm->openResource(fileName, group); - - cout << "Size: " << data->size() << endl; - cout << "First line: " << data->getLine() << "\n"; -} - -int main() -{ - // Disable logging - new LogManager; - Log *log = LogManager::getSingleton().createLog(""); - log->setDebugOutputEnabled(false); - - // Set up Ogre - Root root("","",""); - - root.addResourceLocation("./", "FileSystem", "General"); - - gm = ResourceGroupManager::getSingletonPtr(); - group = gm->getWorldResourceGroupName(); - - find("Makefile"); - find("ogre_resource_test.cpp"); - find("bleh"); - - cout << "\nAll source files:\n"; - FileInfoListPtr list = gm->findResourceFileInfo(group, "*.cpp"); - FileInfoList::iterator it, end; - it = list->begin(); - end = list->end(); - for(; it != end; it++) - cout << " " << it->filename << endl; -} diff --git a/libs/mangle/vfs/tests/ogre_server_test.cpp b/libs/mangle/vfs/tests/ogre_server_test.cpp deleted file mode 100644 index b846eef96..000000000 --- a/libs/mangle/vfs/tests/ogre_server_test.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "../servers/ogre_vfs.hpp" - -#include - -#include "server_common.cpp" - -Ogre::Root *root; - -void setupOgre() -{ - using namespace Ogre; - - // Disable logging - new LogManager; - Log *log = LogManager::getSingleton().createLog(""); - log->setDebugOutputEnabled(false); - - // Set up Root - root = new Root("","",""); - - // Add a zip file and the current directory - root->addResourceLocation("test.zip", "Zip", "General"); - root->addResourceLocation("./", "FileSystem", "General"); -} - -int main() -{ - // Set up the engine - setupOgre(); - - // This is our entry point into the resource file system - OgreVFS vfs("General"); - - // Run the test - testAll(vfs); - - return 0; -} diff --git a/libs/mangle/vfs/tests/output/dummy_test.out b/libs/mangle/vfs/tests/output/dummy_test.out deleted file mode 100644 index 61f1fda80..000000000 --- a/libs/mangle/vfs/tests/output/dummy_test.out +++ /dev/null @@ -1,31 +0,0 @@ -Listing all files: -name: file1 -basename: file1 -isDir: 0 -size: 1 -time: 0 -name: dir/file2 -basename: file2 -isDir: 0 -size: 2 -time: 0 - -Stat for single files: -name: file1 -basename: file1 -isDir: 0 -size: 1 -time: 0 - -name: dir/file2 -basename: file2 -isDir: 0 -size: 2 -time: 0 - -name: dir -basename: dir -isDir: 1 -size: 0 -time: 0 -filesize: 11 diff --git a/libs/mangle/vfs/tests/output/ogre_client_test.out b/libs/mangle/vfs/tests/output/ogre_client_test.out deleted file mode 100644 index bc10b1e5c..000000000 --- a/libs/mangle/vfs/tests/output/ogre_client_test.out +++ /dev/null @@ -1,12 +0,0 @@ -Case: 1 -Name: dummy -Type: Mangle -All files: - file1 - dir/file2 -Non-recursive: - file1 -Dirs: - dir -filesize: 11 -contents: hello world diff --git a/libs/mangle/vfs/tests/output/ogre_resource_test.out b/libs/mangle/vfs/tests/output/ogre_resource_test.out deleted file mode 100644 index 9bfc4ff5b..000000000 --- a/libs/mangle/vfs/tests/output/ogre_resource_test.out +++ /dev/null @@ -1,20 +0,0 @@ - -File: Makefile -Size: 828 -First line: GCC=g++ -I../ - -File: ogre_resource_test.cpp -Size: 1437 -First line: #include - -File: bleh -Does not exist - -All source files: - physfs_server_test.cpp - dummy_test.cpp - ogre_resource_test.cpp - server_common.cpp - dummy_vfs.cpp - ogre_client_test.cpp - ogre_server_test.cpp diff --git a/libs/mangle/vfs/tests/output/ogre_server_test.out b/libs/mangle/vfs/tests/output/ogre_server_test.out deleted file mode 100644 index 74f350844..000000000 --- a/libs/mangle/vfs/tests/output/ogre_server_test.out +++ /dev/null @@ -1,11 +0,0 @@ - -File: Makefile -Size: 828 -First 12 bytes: GCC=g++ -I.. - -File: testfile.txt -Size: 13 -First 12 bytes: hello world! - -File: blah_bleh -File doesn't exist diff --git a/libs/mangle/vfs/tests/output/physfs_server_test.out b/libs/mangle/vfs/tests/output/physfs_server_test.out deleted file mode 100644 index 74f350844..000000000 --- a/libs/mangle/vfs/tests/output/physfs_server_test.out +++ /dev/null @@ -1,11 +0,0 @@ - -File: Makefile -Size: 828 -First 12 bytes: GCC=g++ -I.. - -File: testfile.txt -Size: 13 -First 12 bytes: hello world! - -File: blah_bleh -File doesn't exist diff --git a/libs/mangle/vfs/tests/physfs_server_test.cpp b/libs/mangle/vfs/tests/physfs_server_test.cpp deleted file mode 100644 index 9e9d088cd..000000000 --- a/libs/mangle/vfs/tests/physfs_server_test.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "../servers/physfs_vfs.hpp" - -#include "server_common.cpp" - -#include - -int main() -{ - // Set up the library and paths - PHYSFS_init("blah"); - PHYSFS_addToSearchPath("test.zip", 1); - PHYSFS_addToSearchPath("./", 1); - - // Create our interface - PhysVFS vfs; - - // Run the test - testAll(vfs); - - return 0; -} diff --git a/libs/mangle/vfs/tests/server_common.cpp b/libs/mangle/vfs/tests/server_common.cpp deleted file mode 100644 index 1834bc25a..000000000 --- a/libs/mangle/vfs/tests/server_common.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include - -using namespace Mangle::VFS; -using namespace Mangle::Stream; -using namespace std; - -void find(VFS &vfs, const std::string &file) -{ - cout << "\nFile: " << file << endl; - - if(!vfs.isFile(file)) - { - cout << "File doesn't exist\n"; - return; - } - - StreamPtr data = vfs.open(file); - - cout << "Size: " << data->size() << endl; - - char buf[13]; - buf[12] = 0; - data->read(buf, 12); - - cout << "First 12 bytes: " << buf << "\n"; -} - -void testAll(VFS &vfs) -{ - find(vfs, "Makefile"); // From the file system - find(vfs, "testfile.txt"); // From the zip - find(vfs, "blah_bleh"); // Doesn't exist -} diff --git a/libs/mangle/vfs/tests/test.sh b/libs/mangle/vfs/tests/test.sh deleted file mode 100755 index 2d07708ad..000000000 --- a/libs/mangle/vfs/tests/test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -make || exit - -mkdir -p output - -PROGS=*_test - -for a in $PROGS; do - if [ -f "output/$a.out" ]; then - echo "Running $a:" - ./$a | diff output/$a.out - - else - echo "Creating $a.out" - ./$a > "output/$a.out" - git add "output/$a.out" - fi -done diff --git a/libs/mangle/vfs/tests/test.zip b/libs/mangle/vfs/tests/test.zip deleted file mode 100644 index ec82f8bc6..000000000 Binary files a/libs/mangle/vfs/tests/test.zip and /dev/null differ diff --git a/libs/mangle/vfs/vfs.hpp b/libs/mangle/vfs/vfs.hpp deleted file mode 100644 index 258a6b0a0..000000000 --- a/libs/mangle/vfs/vfs.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef MANGLE_VFS_H -#define MANGLE_VFS_H - -#include "../stream/stream.hpp" -#include -#include - -namespace Mangle { -namespace VFS { - -/// Generic file info structure -struct FileInfo -{ - /// Full name, including path - std::string name; - - /// Base name, not including path - std::string basename; - - /// Is this a directory? - bool isDir; - - /// File size - size_t size; - - /// Last modification date - time_t time; -}; - -typedef std::vector FileInfoList; - -typedef boost::shared_ptr FileInfoPtr; -typedef boost::shared_ptr FileInfoListPtr; - -/** An interface to any file system or other provider of named data - streams -*/ -class VFS -{ - public: - // Feature options. These should be set in the constructor. - - /// If true, the list() function work - bool hasList; - - /// If true, the find() function work - bool hasFind; - - /// If true, the file system is case sensitive - bool isCaseSensitive; - - /// Virtual destructor - virtual ~VFS() {} - - /// Open a new data stream. Deleting the object (letting all the - /// pointers to it go out of scope) should be enough to close it. - virtual Stream::StreamPtr open(const std::string &name) = 0; - - /// Check for the existence of a file - virtual bool isFile(const std::string &name) const = 0; - - /// Check for the existence of a directory - virtual bool isDir(const std::string &name) const = 0; - - /// Get info about a single file - virtual FileInfoPtr stat(const std::string &name) const = 0; - - /// List all entries in a given directory. A blank dir should be - /// interpreted as a the root/current directory of the archive. If - /// dirs is true, list directories instead of files. - virtual FileInfoListPtr list(const std::string& dir = "", - bool recurse=true, - bool dirs=false) const = 0; - - /// Find files after a given pattern. Wildcards (*) are - /// supported. Only valid if 'hasFind' is true. Don't implement your - /// own pattern matching here if the backend doesn't support it - /// natively; use a filter instead. - virtual FileInfoListPtr find(const std::string& pattern, - bool recursive=true, - bool dirs=false) const = 0; -}; - -typedef boost::shared_ptr VFSPtr; - -}} // namespaces -#endif diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 500e8a7ef..11c18010e 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -333,11 +333,18 @@ namespace Physic RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale) { + char uniqueID[8]; + sprintf( uniqueID, "%07.3f", scale ); + std::string sid = uniqueID; + std::string outputstring = mesh + uniqueID + "\"|"; + //std::cout << "The string" << outputstring << "\n"; + //get the shape from the .nif - mShapeLoader->load(mesh,"General"); - BulletShapeManager::getSingletonPtr()->load(mesh,"General"); - BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(mesh,"General"); - shape->Shape->setLocalScaling(btVector3(scale,scale,scale)); + mShapeLoader->load(outputstring,"General"); + BulletShapeManager::getSingletonPtr()->load(outputstring,"General"); + BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General"); + shape->Shape->setLocalScaling( btVector3(scale,scale,scale)); + //btScaledBvhTriangleMeshShape* scaled = new btScaledBvhTriangleMeshShape(dynamic_cast (shape->Shape), btVector3(scale,scale,scale)); //create the motionState CMotionState* newMotionState = new CMotionState(this,name); @@ -400,18 +407,32 @@ namespace Physic if (it != RigidBodyMap.end() ) { RigidBody* body = it->second; + //btScaledBvhTriangleMeshShape* scaled = dynamic_cast (body->getCollisionShape()); + if(body != NULL) { delete body; } + /*if(scaled != NULL) + { + delete scaled; + }*/ RigidBodyMap.erase(it); } } RigidBody* PhysicEngine::getRigidBody(std::string name) { - RigidBody* body = RigidBodyMap[name]; - return body; + RigidBodyContainer::iterator it = RigidBodyMap.find(name); + if (it != RigidBodyMap.end() ) + { + RigidBody* body = RigidBodyMap[name]; + return body; + } + else + { + return 0; + } } void PhysicEngine::stepSimulation(double deltaT) @@ -468,8 +489,16 @@ namespace Physic PhysicActor* PhysicEngine::getCharacter(std::string name) { - PhysicActor* act = PhysicActorMap[name]; - return act; + PhysicActorContainer::iterator it = PhysicActorMap.find(name); + if (it != PhysicActorMap.end() ) + { + PhysicActor* act = PhysicActorMap[name]; + return act; + } + else + { + return 0; + } } void PhysicEngine::emptyEventLists(void) diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index e327f24e1..3988c75a4 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -7,6 +7,7 @@ #include #include #include "BulletShapeLoader.h" +#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" class btRigidBody; class btBroadphaseInterface; diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index b723f67e4..e13e9e6c0 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -229,7 +229,7 @@ bool PM_SlideMove( bool gravity ) end = pm->ps.origin + pm->ps.velocity * time_left; // see if we can make it there - //pm->trace ( &trace, pm->ps->origin, pm->mins, pm->maxs, end, pm->ps->clientNum, pm->tracemask); + //pm->trace ( &trace, pm->ps->origin, pm->mins, pm->maxs, end, pm->ps->clientNum, pm->tracemaskg); //tracefunc(&trace, *(const D3DXVECTOR3* const)&(pm->ps.origin), *(const D3DXVECTOR3* const)&(end), *(const D3DXVECTOR3* const)&(pm->ps.velocity), 0, pml.traceObj); newtrace(&trace, pm->ps.origin, end, halfExtents, Ogre::Math::DegreesToRadians (pm->ps.viewangles.y), pm->isInterior, pm->mEngine); @@ -274,7 +274,7 @@ bool PM_SlideMove( bool gravity ) { // pm->ps->velocity += (trace.plane.normal + pm->ps->velocity) //VectorAdd( trace.plane.normal, pm->ps->velocity, pm->ps->velocity ); - pm->ps.velocity = (trace.planenormal + pm->ps.velocity); + pm->ps.velocity = trace.planenormal + pm->ps.velocity; break; } } @@ -298,6 +298,12 @@ bool PM_SlideMove( bool gravity ) if ( into >= 0.1 ) continue; // move doesn't interact with the plane + + if(planes[i].x >= .70) + { + pm->ps.velocity = Ogre::Vector3(0,0,0); + return true; + } // see how hard we are hitting things if ( -into > pml.impactSpeed ) pml.impactSpeed = -into; @@ -318,6 +324,13 @@ bool PM_SlideMove( bool gravity ) if (clipVelocity.dotProduct(planes[j]) >= 0.1) //if ( DotProduct( clipVelocity, planes[j] ) >= 0.1 ) continue; // move doesn't interact with the plane + + + + + //pm->ps.velocity = Ogre::Vector3(0,0,0); + //return true; + // try clipping the move to the plane PM_ClipVelocity( clipVelocity, planes[j], clipVelocity, OVERCLIP ); @@ -327,8 +340,8 @@ bool PM_SlideMove( bool gravity ) if (clipVelocity.dotProduct(planes[i]) >= 0) //if ( DotProduct( clipVelocity, planes[i] ) >= 0 ) continue; - - + + // slide the original velocity along the crease //dProduct (planes[i], planes[j], dir); dir = planes[i].crossProduct(planes[j]) ; @@ -360,6 +373,7 @@ bool PM_SlideMove( bool gravity ) // see if there is a third plane the the new move enters for ( k = 0 ; k < numplanes ; k++ ) { + if ( k == i || k == j ) continue; @@ -513,7 +527,7 @@ int PM_StepSlideMove( bool gravity ) delta = pm->ps.origin.z - start_o.z; if ( delta > 2 ) { - pm->ps.counter = 10; + pm->ps.counter = 5; /* if (gravity) @@ -844,6 +858,8 @@ static void PM_WalkMove( playerMove* const pmove ) float accelerate; float vel; //pm->ps.gravity = 4000; + + //std::cout << "Player is walking\n"; if ( pm->ps.waterlevel > 2 && //DotProduct( pml.forward, pml.groundTrace.plane.normal ) > 0 ) pml.forward.dotProduct(pml.groundTrace.planenormal) > 0.0f) @@ -1145,6 +1161,10 @@ void PM_GroundTraceMissed() { traceResults trace; Ogre::Vector3 point; + //We should not have significant upwards velocity when in the air, unless we jumped. + //This code protects against flying into the air when moving at high speeds. + //Z velocity is set to 50, instead of 0, to help move up certain steps. + //std::cout << "Ground trace missed\n"; // we just transitioned into freefall //if ( pm->debugLevel ) @@ -1407,10 +1427,13 @@ static void PM_GroundTrace( void ) // if the trace didn't hit anything, we are in free fall if ( trace.fraction == 1.0) { + if(pm->ps.velocity.z > 50.0f && pm->ps.bSnap && pm->ps.speed > 1000.0f) + pm->ps.velocity.z = 50.0f; if(pm->ps.snappingImplemented){ if(pm->ps.bSnap && pm->ps.counter <= 0) PM_GroundTraceMissed(); } + return; @@ -1457,6 +1480,7 @@ static void PM_GroundTrace( void ) // slopes that are too steep will not be considered onground //if ( trace.plane.normal[2] < MIN_WALK_NORMAL ) + //std::cout << "MinWalkNormal" << trace.planenormal.z; if (trace.planenormal.z < MIN_WALK_NORMAL) { //if ( pm->debugLevel ) @@ -1569,8 +1593,11 @@ void PM_AirMove() else PM_SlideMove ( qtrue ); #endif*/ + //std::cout << "Moving in the air" << pm->ps.velocity << "\n"; /*bprintf("%i ", */PM_StepSlideMove ( true )/* )*/; + + } static void PM_NoclipMove( void ) diff --git a/libs/openengine/bullet/pmove.h b/libs/openengine/bullet/pmove.h index 0fdb8f0d8..aea63d1db 100644 --- a/libs/openengine/bullet/pmove.h +++ b/libs/openengine/bullet/pmove.h @@ -28,7 +28,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2); #define MAX_CLIP_PLANES 5 #define OVERCLIP 1.001f //#define STEPSIZE 18 // 18 is way too much -#define STEPSIZE (18 / 2) +#define STEPSIZE (9) #ifndef M_PI #define M_PI 3.14159265358979323846f #endif @@ -41,7 +41,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2); #define MAX_GENTITIES (1 << GENTITYNUM_BITS) #define ENTITYNUM_NONE (MAX_GENTITIES - 1) #define ENTITYNUM_WORLD (MAX_GENTITIES - 2) -#define MIN_WALK_NORMAL 0.7f // can't walk on very steep slopes +#define MIN_WALK_NORMAL .7f // can't walk on very steep slopes #define JUMP_VELOCITY (270) #define PS_PMOVEFRAMECOUNTBITS 6 #define MINS_Z -24 diff --git a/libs/openengine/gui/events.cpp b/libs/openengine/gui/events.cpp index bce70704b..35b01158b 100644 --- a/libs/openengine/gui/events.cpp +++ b/libs/openengine/gui/events.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include "events.hpp" diff --git a/libs/openengine/gui/layout.hpp b/libs/openengine/gui/layout.hpp index e6feb3d0e..9040dfb90 100644 --- a/libs/openengine/gui/layout.hpp +++ b/libs/openengine/gui/layout.hpp @@ -1,7 +1,6 @@ #ifndef OENGINE_MYGUI_LAYOUT_H #define OENGINE_MYGUI_LAYOUT_H -#include #include namespace OEngine { diff --git a/libs/openengine/gui/manager.cpp b/libs/openengine/gui/manager.cpp index 022c5efb5..9c6ca37eb 100644 --- a/libs/openengine/gui/manager.cpp +++ b/libs/openengine/gui/manager.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include "manager.hpp" diff --git a/libs/openengine/input/dispatch_map.hpp b/libs/openengine/input/dispatch_map.hpp index f0d4cabe9..be13e7f01 100644 --- a/libs/openengine/input/dispatch_map.hpp +++ b/libs/openengine/input/dispatch_map.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace OEngine { namespace Input { diff --git a/libs/openengine/input/func_binder.hpp b/libs/openengine/input/func_binder.hpp index 7aa733edf..a815ba0ce 100644 --- a/libs/openengine/input/func_binder.hpp +++ b/libs/openengine/input/func_binder.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace OEngine { namespace Input { diff --git a/libs/openengine/misc/list.hpp b/libs/openengine/misc/list.hpp index b08b57494..bda9cb8de 100644 --- a/libs/openengine/misc/list.hpp +++ b/libs/openengine/misc/list.hpp @@ -1,7 +1,7 @@ #ifndef MISC_LIST_H #define MISC_LIST_H -#include +#include namespace Misc{ diff --git a/libs/openengine/ogre/fader.cpp b/libs/openengine/ogre/fader.cpp index 062559e00..41b7773ea 100644 --- a/libs/openengine/ogre/fader.cpp +++ b/libs/openengine/ogre/fader.cpp @@ -8,8 +8,6 @@ #include #include -#include - #define FADE_OVERLAY_NAME "FadeInOutOverlay" #define FADE_OVERLAY_PANEL_NAME "FadeInOutOverlayPanel" #define FADE_MATERIAL_NAME "FadeInOutMaterial" diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index 275b7385a..f2f4b4c81 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -9,7 +9,7 @@ #include "OgreTexture.h" #include "OgreHardwarePixelBuffer.h" -#include +#include #include using namespace Ogre; diff --git a/readme.txt b/readme.txt index aa981dba3..ded9bcd7b 100644 --- a/readme.txt +++ b/readme.txt @@ -12,8 +12,6 @@ EBGaramond-Regular.ttf: OFL (see OFL.txt for more information) VeraMono.ttf: custom (see Bitstream Vera License.txt for more information) -THIS IS A WORK IN PROGRESS - INSTALLATION @@ -90,47 +88,6 @@ Allowed options: --fallback arg fallback values -CREDITS - -Current Developers: -Aleksandar Jovanov -Alexander “Ace” Olofsson -athile -BrotherBrick -Cris “Mirceam” Mihalache -gugus / gus -Jacob “Yacoby” Essex -Jannik “scrawl” Heller -Jason “jhooks” Hooks -Karl-Felix “k1ll” Glatzer -Lukasz “lgro” Gromanowski -Marc “Zini” Zinnschlag -Michael “werdanith” Papageorgiou -Nikolay “corristo” Kasyanov -Pieter “pvdk” van der Kloet -Roman "Kromgart" Melnik -Sebastian “swick” Wick -Sylvain "Garvek" T. - -Retired Developers: -Ardekantur -Armin Preiml -Diggory Hardy -Jan Borsodi -Jan-Peter “peppe” Nilsson -Josua Grawitter -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. - -Launcher: -Thanks to Kevin Ryan for kindly providing us with the icon used for the Data Files tab. - - CHANGELOG 0.16.0 @@ -215,7 +172,6 @@ Task #113: Morrowind.ini Importer Task #215: Refactor the sound code Task #216: Update MyGUI - 0.13.0 Bug #145: Fixed sound problems after cell change @@ -273,7 +229,6 @@ 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 @@ -300,4 +255,95 @@ 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.1 changelog from wiki) +0.10.0 + +* NPC dialogue window (not functional yet) +* Collisions with objects +* Refactor the PlayerPos class +* Adjust file locations +* CMake files and test linking for Bullet +* Replace Ogre raycasting test for activation with something more precise +* Adjust player movement according to collision results +* FPS display +* Various Portability Improvements +* Mac OS X support is back! + +0.9.0 + +* Exterior cells loading, unloading and management +* Character Creation GUI +* Character creation +* Make cell names case insensitive when doing internal lookups +* Music player +* NPCs rendering + +0.8.0 + +* GUI +* Complete and working script engine +* In game console +* Sky rendering +* Sound and music +* Tons of smaller stuff + +0.7.0 + +* This release is a complete rewrite in C++. +* All D code has been culled, and all modules have been rewritten. +* The game is now back up to the level of rendering interior cells and moving around, but physics, sound, GUI, and scripting still remain to be ported from the old codebase. + +0.6.0 + +* Coded a GUI system using MyGUI +* Skinned MyGUI to look like Morrowind (work in progress) +* Integrated the Monster script engine +* Rewrote some functions into script code +* Very early MyGUI < > Monster binding +* Fixed Windows sound problems (replaced old openal32.dll) + +0.5.0 + +* Collision detection with Bullet +* Experimental walk & fall character physics +* New key bindings: + * t toggle physics mode (walking, flying, ghost), + * n night eye, brightens the scene +* Fixed incompatability with DMD 1.032 and newer compilers +* * (thanks to tomqyp) +* Various minor changes and updates + +0.4.0 + +* Switched from Audiere to OpenAL +* * (BIG thanks to Chris Robinson) +* Added complete Makefile (again) as a alternative build tool +* More realistic lighting (thanks again to Chris Robinson) +* Various localization fixes tested with Russian and French versions +* Temporary workaround for the Unicode issue: invalid UTF displayed as '?' +* Added ns option to disable sound, for debugging +* Various bug fixes +* Cosmetic changes to placate gdc Wall + +0.3.0 + +* Built and tested on Windows XP +* Partial support for FreeBSD (exceptions do not work) +* You no longer have to download Monster separately +* Made an alternative for building without DSSS (but DSSS still works) +* Renamed main program from 'morro' to 'openmw' +* Made the config system more robust +* Added oc switch for showing Ogre config window on startup +* Removed some config files, these are auto generated when missing. +* Separated plugins.cfg into linux and windows versions. +* Updated Makefile and sources for increased portability +* confirmed to work against OIS 1.0.0 (Ubuntu repository package) + +0.2.0 + +* Compiles with gdc +* Switched to DSSS for building D code +* Includes the program esmtool + +0.1.0 + +first release