From 78740306db6aecdb345174cbdef9faa7d13d1697 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 00:45:45 +0400 Subject: [PATCH 1/9] non-const access to Store from ESMStore --- apps/openmw/mwworld/esmstore.hpp | 230 +++++++++++++++++++++++++++++++ apps/openmw/mwworld/worldimp.cpp | 4 +- 2 files changed, 232 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 0a6ea01b3..dfe2ac03a 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -145,6 +145,11 @@ namespace MWWorld throw std::runtime_error("Storage for this type not exist"); } + template + Store &get() { + throw std::runtime_error("Storage for this type not exist (non-const)"); + } + template T *insert(const T &x) { Store &store = const_cast &>(get()); @@ -396,6 +401,231 @@ namespace MWWorld inline const Store &ESMStore::get() const { return mAttributes; } + + template <> + inline Store &ESMStore::get() { + return mActivators; + } + + template <> + inline Store &ESMStore::get() { + return mPotions; + } + + template <> + inline Store &ESMStore::get() { + return mAppas; + } + + template <> + inline Store &ESMStore::get() { + return mArmors; + } + + template <> + inline Store &ESMStore::get() { + return mBodyParts; + } + + template <> + inline Store &ESMStore::get() { + return mBooks; + } + + template <> + inline Store &ESMStore::get() { + return mBirthSigns; + } + + template <> + inline Store &ESMStore::get() { + return mClasses; + } + + template <> + inline Store &ESMStore::get() { + return mClothes; + } + + template <> + inline Store &ESMStore::get() { + return mContChange; + } + + template <> + inline Store &ESMStore::get() { + return mContainers; + } + + template <> + inline Store &ESMStore::get() { + return mCreatures; + } + + template <> + inline Store &ESMStore::get() { + return mCreaChange; + } + + template <> + inline Store &ESMStore::get() { + return mDialogs; + } + + template <> + inline Store &ESMStore::get() { + return mDoors; + } + + template <> + inline Store &ESMStore::get() { + return mEnchants; + } + + template <> + inline Store &ESMStore::get() { + return mFactions; + } + + template <> + inline Store &ESMStore::get() { + return mGlobals; + } + + template <> + inline Store &ESMStore::get() { + return mIngreds; + } + + template <> + inline Store &ESMStore::get() { + return mCreatureLists; + } + + template <> + inline Store &ESMStore::get() { + return mItemLists; + } + + template <> + inline Store &ESMStore::get() { + return mLights; + } + + template <> + inline Store &ESMStore::get() { + return mLockpicks; + } + + template <> + inline Store &ESMStore::get() { + return mMiscItems; + } + + template <> + inline Store &ESMStore::get() { + return mNpcs; + } + + template <> + inline Store &ESMStore::get() { + return mNpcChange; + } + + template <> + inline Store &ESMStore::get() { + return mProbes; + } + + template <> + inline Store &ESMStore::get() { + return mRaces; + } + + template <> + inline Store &ESMStore::get() { + return mRegions; + } + + template <> + inline Store &ESMStore::get() { + return mRepairs; + } + + template <> + inline Store &ESMStore::get() { + return mSoundGens; + } + + template <> + inline Store &ESMStore::get() { + return mSounds; + } + + template <> + inline Store &ESMStore::get() { + return mSpells; + } + + template <> + inline Store &ESMStore::get() { + return mStartScripts; + } + + template <> + inline Store &ESMStore::get() { + return mStatics; + } + + template <> + inline Store &ESMStore::get() { + return mWeapons; + } + + template <> + inline Store &ESMStore::get() { + return mGameSettings; + } + + template <> + inline Store &ESMStore::get() { + return mScripts; + } + + template <> + inline Store &ESMStore::get() { + return mCells; + } + + template <> + inline Store &ESMStore::get() { + return mLands; + } + + template <> + inline Store &ESMStore::get() { + return mLandTextures; + } + + template <> + inline Store &ESMStore::get() { + return mPathgrids; + } + + template <> + inline Store &ESMStore::get() { + return mMagicEffects; + } + + template <> + inline Store &ESMStore::get() { + return mSkills; + } + + template <> + inline Store &ESMStore::get() { + return mAttributes; + } } #endif diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 9f5b7520c..532d335c3 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1058,12 +1058,12 @@ namespace MWWorld // door leads to exterior, use cell name (if any), otherwise translated region name int x,y; positionToIndex (ref.mRef.mDoorDest.pos[0], ref.mRef.mDoorDest.pos[1], x, y); - const ESM::Cell* cell = mStore.get().find(x,y); + const ESM::Cell* cell = ((const ESMStore &) mStore).get().find(x,y); if (cell->mName != "") dest = cell->mName; else { - dest = mStore.get().find(cell->mRegion)->mName; + dest = ((const ESMStore &) mStore).get().find(cell->mRegion)->mName; } } From 9ab2c16055ccd4c1ef35742f289d5392f83125f2 Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 7 Nov 2012 17:49:45 +0400 Subject: [PATCH 2/9] store created character classes as dynamic records --- apps/openmw/mwgui/charactercreation.cpp | 9 ++++++--- apps/openmw/mwgui/windowmanagerimp.cpp | 4 +--- apps/openmw/mwgui/windowmanagerimp.hpp | 1 - apps/openmw/mwworld/player.cpp | 10 +--------- apps/openmw/mwworld/player.hpp | 8 ++++---- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 253e0779c..cdfa43b3b 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -559,9 +559,12 @@ void CharacterCreation::onCreateClassDialogDone(WindowBase* parWindow) klass.mData.mSkills[i][1] = majorSkills[i]; klass.mData.mSkills[i][0] = minorSkills[i]; } - MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass); - mPlayerClass = klass; - mWM->setPlayerClass(klass); + std::pair res = + MWBase::Environment::get().getWorld()->createRecord(klass); + + MWBase::Environment::get().getMechanicsManager()->setPlayerClass(*res.second); + mPlayerClass = *res.second; + mWM->setPlayerClass(*res.second); mWM->removeDialog(mCreateClassDialog); mCreateClassDialog = 0; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 8e4187f7f..dfca04948 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -83,7 +83,6 @@ WindowManager::WindowManager( , mSpellCreationDialog(NULL) , mEnchantingDialog(NULL) , mTrainingWindow(NULL) - , mPlayerClass() , mPlayerName() , mPlayerRaceId() , mPlayerAttributes() @@ -499,8 +498,7 @@ void WindowManager::setValue (const std::string& id, int value) void WindowManager::setPlayerClass (const ESM::Class &class_) { - mPlayerClass = class_; - mStatsWindow->setValue("class", mPlayerClass.mName); + mStatsWindow->setValue("class", class_.mName); } void WindowManager::configureSkills (const SkillList& major, const SkillList& minor) diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index aa796343e..2e684b5da 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -261,7 +261,6 @@ namespace MWGui /// \todo get rid of this stuff. Move it to the respective UI element classes, if needed. // Various stats about player as needed by window manager - ESM::Class mPlayerClass; std::string mPlayerName; std::string mPlayerRaceId; std::map > mPlayerAttributes; diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index a1318f727..5cf1fa379 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -26,8 +26,7 @@ namespace MWWorld float* playerPos = mPlayer.mData.getPosition().pos; playerPos[0] = playerPos[1] = playerPos[2] = 0; - /// \todo Do not make a copy of classes defined in esm/p records. - mClass = new ESM::Class (*world.getStore().get().find (player->mClass)); + mClass = world.getStore().get().find (player->mClass); } Player::~Player() @@ -35,13 +34,6 @@ namespace MWWorld delete mClass; } - void Player::setClass (const ESM::Class& class_) - { - ESM::Class *new_class = new ESM::Class (class_); - delete mClass; - mClass = new_class; - } - void Player::setDrawState (MWMechanics::DrawState_ state) { MWWorld::Ptr ptr = getPlayer(); diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 68df2ec6d..a7a0ec430 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -1,8 +1,6 @@ #ifndef GAME_MWWORLD_PLAYER_H #define GAME_MWWORLD_PLAYER_H -#include "OgreCamera.h" - #include "../mwworld/cellstore.hpp" #include "../mwworld/refdata.hpp" #include "../mwworld/ptr.hpp" @@ -27,7 +25,7 @@ namespace MWWorld bool mMale; std::string mRace; std::string mBirthsign; - ESM::Class *mClass; + const ESM::Class *mClass; bool mAutoMove; int mForwardBackward; public: @@ -67,7 +65,9 @@ namespace MWWorld mBirthsign = birthsign; } - void setClass (const ESM::Class& class_); + void setClass (const ESM::Class& class_) { + mClass = &class_; + } void setDrawState (MWMechanics::DrawState_ state); From 5b9621bca585ab22e3f121346d1a9213d3a254c6 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 01:36:43 +0400 Subject: [PATCH 3/9] store player record data in ESMStore --- apps/openmw/mwbase/world.hpp | 6 ++ apps/openmw/mwgui/charactercreation.cpp | 8 +- apps/openmw/mwgui/levelupdialog.cpp | 2 +- apps/openmw/mwgui/stats_window.cpp | 16 ++-- .../mwmechanics/mechanicsmanagerimp.cpp | 50 +++++++------ apps/openmw/mwworld/player.cpp | 50 ++++++++++--- apps/openmw/mwworld/player.hpp | 74 +++++++++---------- apps/openmw/mwworld/store.hpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 46 ++++++++++++ apps/openmw/mwworld/worldimp.hpp | 6 ++ 10 files changed, 172 insertions(+), 88 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 3a7cb0874..f28ff0184 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -296,6 +296,12 @@ namespace MWBase /// 1 - only waiting \n /// 2 - player is underwater \n /// 3 - enemies are nearby (not implemented) + + /// Update player record part with given value + virtual void updatePlayer(int flag, const std::string &value) = 0; + + /// Update player record part with given value + virtual void updatePlayer(int flag, bool value) = 0; }; } diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index cdfa43b3b..a054f34dd 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -559,12 +559,10 @@ void CharacterCreation::onCreateClassDialogDone(WindowBase* parWindow) klass.mData.mSkills[i][1] = majorSkills[i]; klass.mData.mSkills[i][0] = minorSkills[i]; } - std::pair res = - MWBase::Environment::get().getWorld()->createRecord(klass); - MWBase::Environment::get().getMechanicsManager()->setPlayerClass(*res.second); - mPlayerClass = *res.second; - mWM->setPlayerClass(*res.second); + MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass); + mPlayerClass = klass; + mWM->setPlayerClass(klass); mWM->removeDialog(mCreateClassDialog); mCreateClassDialog = 0; diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index 399ff74a3..d8f12bcbb 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -120,7 +120,7 @@ namespace MWGui setAttributeValues(); // set class image - const ESM::Class& playerClass = MWBase::Environment::get().getWorld ()->getPlayer ().getClass (); + const ESM::Class& playerClass = *MWBase::Environment::get().getWorld ()->getPlayer ().getClass (); // retrieve the ID to this class std::string classId; const MWWorld::Store &classes = diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 9d6842068..ae86cbf1a 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -253,7 +253,10 @@ void StatsWindow::onFrame () setFactions(PCstats.getFactionRanks()); - setBirthSign(MWBase::Environment::get().getWorld()->getPlayer().getBirthsign()); + const ESM::BirthSign *sign = + MWBase::Environment::get().getWorld()->getPlayer().getBirthsign(); + + setBirthSign((sign != 0) ? sign->mId : ""); if (mChanged) updateSkillArea(); @@ -430,7 +433,7 @@ void StatsWindow::updateSkillArea() // race tooltip const ESM::Race* playerRace = - store.get().find (MWBase::Environment::get().getWorld()->getPlayer().getRace()); + MWBase::Environment::get().getWorld()->getPlayer().getRace(); MyGUI::Widget* raceWidget; getWidget(raceWidget, "RaceText"); @@ -440,11 +443,14 @@ void StatsWindow::updateSkillArea() // class tooltip MyGUI::Widget* classWidget; - const ESM::Class& playerClass = MWBase::Environment::get().getWorld()->getPlayer().getClass(); + + const ESM::Class *playerClass = + MWBase::Environment::get().getWorld()->getPlayer().getClass(); + getWidget(classWidget, "ClassText"); - ToolTips::createClassToolTip(classWidget, playerClass); + ToolTips::createClassToolTip(classWidget, *playerClass); getWidget(classWidget, "Class_str"); - ToolTips::createClassToolTip(classWidget, playerClass); + ToolTips::createClassToolTip(classWidget, *playerClass); if (!mFactions.empty()) { diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 94418c522..7fc7635a4 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -42,9 +42,7 @@ namespace MWMechanics if (mRaceSelected) { const ESM::Race *race = - MWBase::Environment::get().getWorld()->getStore().get().find ( - MWBase::Environment::get().getWorld()->getPlayer().getRace() - ); + MWBase::Environment::get().getWorld()->getPlayer().getRace(); bool male = MWBase::Environment::get().getWorld()->getPlayer().isMale(); @@ -89,12 +87,11 @@ namespace MWMechanics } // birthsign - if (!MWBase::Environment::get().getWorld()->getPlayer().getBirthsign().empty()) - { - const ESM::BirthSign *sign = - MWBase::Environment::get().getWorld()->getStore().get().find ( - MWBase::Environment::get().getWorld()->getPlayer().getBirthsign()); + const ESM::BirthSign *sign = + MWBase::Environment::get().getWorld()->getPlayer().getBirthsign(); + if (sign != 0) + { for (std::vector::const_iterator iter (sign->mPowers.mList.begin()); iter!=sign->mPowers.mList.end(); ++iter) { @@ -105,11 +102,12 @@ namespace MWMechanics // class if (mClassSelected) { - const ESM::Class& class_ = MWBase::Environment::get().getWorld()->getPlayer().getClass(); + const ESM::Class *class_ = + MWBase::Environment::get().getWorld()->getPlayer().getClass(); for (int i=0; i<2; ++i) { - int attribute = class_.mData.mAttribute[i]; + int attribute = class_->mData.mAttribute[i]; if (attribute>=0 && attribute<8) { creatureStats.getAttribute(attribute).setBase ( @@ -123,7 +121,7 @@ namespace MWMechanics for (int i2=0; i2<5; ++i2) { - int index = class_.mData.mSkills[i2][i]; + int index = class_->mData.mSkills[i2][i]; if (index>=0 && index<27) { @@ -139,7 +137,7 @@ namespace MWMechanics MWWorld::Store::iterator iter = skills.begin(); for (; iter != skills.end(); ++iter) { - if (iter->mData.mSpecialization==class_.mData.mSpecialization) + if (iter->mData.mSpecialization==class_->mData.mSpecialization) { int index = iter->mIndex; @@ -266,12 +264,12 @@ namespace MWMechanics MWBase::WindowManager *winMgr = MWBase::Environment::get().getWindowManager(); - MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Player &player = world->getPlayer(); + MWWorld::Player &player = + MWBase::Environment::get().getWorld()->getPlayer(); winMgr->setValue ("name", player.getName()); - winMgr->setValue ("race", world->getStore().get().find (player.getRace())->mName); - winMgr->setValue ("class", player.getClass().mName); + winMgr->setValue ("race", player.getRace()->mName); + winMgr->setValue ("class", player.getClass()->mName); mUpdatePlayer = false; @@ -280,8 +278,8 @@ namespace MWMechanics for (int i=0; i<5; ++i) { - minorSkills[i] = player.getClass().mData.mSkills[i][0]; - majorSkills[i] = player.getClass().mData.mSkills[i][1]; + minorSkills[i] = player.getClass()->mData.mSkills[i][0]; + majorSkills[i] = player.getClass()->mData.mSkills[i][1]; } winMgr->configureSkills (majorSkills, minorSkills); @@ -319,22 +317,26 @@ namespace MWMechanics void MechanicsManager::setPlayerClass (const std::string& id) { - MWBase::Environment::get().getWorld()->getPlayer().setClass ( - *MWBase::Environment::get().getWorld()->getStore().get().find (id) - ); + MWBase::Environment::get().getWorld()->getPlayer().setClass(id); mClassSelected = true; buildPlayer(); mUpdatePlayer = true; } - void MechanicsManager::setPlayerClass (const ESM::Class& class_) + void MechanicsManager::setPlayerClass (const ESM::Class &cls) { - MWBase::Environment::get().getWorld()->getPlayer().setClass (class_); + MWBase::World *world = MWBase::Environment::get().getWorld(); + + std::pair res = + world->createRecord(cls); + + world->getPlayer().setClass(res.second->mId); + mClassSelected = true; buildPlayer(); mUpdatePlayer = true; } - + int MechanicsManager::countDeaths (const std::string& id) const { return mActors.countDeaths (id); diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 5cf1fa379..48767a1a1 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -13,25 +13,22 @@ namespace MWWorld { - Player::Player (const ESM::NPC *player, const MWBase::World& world) : - mCellStore (0), mClass (0), - mAutoMove (false), mForwardBackward (0) + Player::Player (const ESM::NPC *player, const MWBase::World& world) + : mCellStore(0), + mClass(0), + mRace(0), + mSign(0), + mAutoMove(false), + mForwardBackward (0) { mPlayer.mBase = player; mPlayer.mRef.mRefID = "player"; - mName = player->mName; - mMale = !(player->mFlags & ESM::NPC::Female); - mRace = player->mRace; float* playerPos = mPlayer.mData.getPosition().pos; playerPos[0] = playerPos[1] = playerPos[2] = 0; mClass = world.getStore().get().find (player->mClass); - } - - Player::~Player() - { - delete mClass; + mRace = world.getStore().get().find(player->mRace); } void Player::setDrawState (MWMechanics::DrawState_ state) @@ -95,4 +92,35 @@ namespace MWWorld return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState(); } + void Player::setName(const std::string &value) + { + MWBase::Environment::get().getWorld()->updatePlayer(Data_Name, value); + } + + void Player::setGender(bool value) + { + MWBase::Environment::get().getWorld()->updatePlayer(Data_Male, value); + } + + void Player::setRace(const std::string &value) + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + world->updatePlayer(Data_Race, value); + + mRace = world->getStore().get().find(value); + } + + void Player::setBirthsign(const std::string &value) + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + mSign = world->getStore().get().find(value); + } + + void Player::setClass(const std::string &value) + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + world->updatePlayer(Data_Class, value); + + mClass = world->getStore().get().find(value); + } } diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index a7a0ec430..1e6dae2c2 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -19,21 +19,31 @@ namespace MWWorld /// \brief NPC object representing the player and additional player data class Player { - LiveCellRef mPlayer; - MWWorld::CellStore *mCellStore; - std::string mName; - bool mMale; - std::string mRace; - std::string mBirthsign; - const ESM::Class *mClass; - bool mAutoMove; - int mForwardBackward; + LiveCellRef mPlayer; + MWWorld::CellStore *mCellStore; + + // cached referenced data + const ESM::Class *mClass; + const ESM::Race *mRace; + const ESM::BirthSign *mSign; + + bool mAutoMove; + int mForwardBackward; + public: + enum { + Data_Male, + Data_Name, + Data_Race, + Data_Class, + Data_Sign, + Data_Model, + Data_Head, + Data_Hair + }; Player(const ESM::NPC *player, const MWBase::World& world); - ~Player(); - void setCell (MWWorld::CellStore *cellStore) { mCellStore = cellStore; @@ -45,55 +55,37 @@ namespace MWWorld return ptr; } - void setName (const std::string& name) - { - mName = name; - } - - void setGender (bool male) - { - mMale = male; - } - - void setRace (const std::string& race) - { - mRace = race; - } - - void setBirthsign (const std::string& birthsign) - { - mBirthsign = birthsign; - } - - void setClass (const ESM::Class& class_) { - mClass = &class_; - } + void setName (const std::string& name); + void setGender (bool male); + void setRace (const std::string& race); + void setBirthsign (const std::string& birthsign); + void setClass (const std::string &cls); void setDrawState (MWMechanics::DrawState_ state); std::string getName() const { - return mName; + return mPlayer.mBase->mName; } bool isMale() const { - return mMale; + return (mPlayer.mBase->mFlags & 0x1) == 0; } - std::string getRace() const + const ESM::Race *getRace() const { return mRace; } - std::string getBirthsign() const + const ESM::BirthSign *getBirthsign() const { - return mBirthsign; + return mSign; } - const ESM::Class& getClass() const + const ESM::Class *getClass() const { - return *mClass; + return mClass; } bool getAutoMove() const diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 395abcd83..c645f6613 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -554,7 +554,7 @@ namespace MWWorld ESM::Cell *ptr = search(x, y); if (ptr == 0) { std::ostringstream msg; - msg << "Exterior at (" << x << ", " << y << ") not found (non-const"; + msg << "Exterior at (" << x << ", " << y << ") not found (non-const)"; throw std::runtime_error(msg.str()); } return ptr; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 532d335c3..1c1a3939d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1252,4 +1252,50 @@ namespace MWWorld return 0; } + + void World::updatePlayer(int flag, const std::string &value) + { + ESM::NPC *player = mStore.get().find("player"); + + switch (flag) { + case Player::Data_Name: + player->mName = value; + break; + + case Player::Data_Class: + player->mClass = value; + break; + + case Player::Data_Race: + player->mRace = value; + break; + + case Player::Data_Model: + player->mModel = value; + break; + + case Player::Data_Head: + player->mHead = value; + break; + + case Player::Data_Hair: + player->mHair = value; + break; + + default: + break; + } + } + + void World::updatePlayer(int flag, bool value) + { + ESM::NPC *player = mStore.get().find("player"); + + if (flag == Player::Data_Male) { + player->mFlags |= 0x1; + if (value) { + player->mFlags ^= 0x1; + } + } + } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 2b2ad7821..fe9e96110 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -327,6 +327,12 @@ namespace MWWorld /// 1 - only waiting \n /// 2 - player is underwater \n /// 3 - enemies are nearby (not implemented) + + /// Update player record part with given value + virtual void updatePlayer(int flag, const std::string &value); + + /// Update player record part with given value + virtual void updatePlayer(int flag, bool value); }; } From f818fa1ebfa84a54948b31f9ce4c6de145f036d3 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 01:39:24 +0400 Subject: [PATCH 4/9] minor update since records contains own id --- apps/openmw/mwgui/levelupdialog.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index d8f12bcbb..099132b8b 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -120,19 +120,10 @@ namespace MWGui setAttributeValues(); // set class image - const ESM::Class& playerClass = *MWBase::Environment::get().getWorld ()->getPlayer ().getClass (); - // retrieve the ID to this class - std::string classId; - const MWWorld::Store &classes = - MWBase::Environment::get().getWorld()->getStore().get(); - - MWWorld::Store::iterator it = classes.begin(); - for (; it != classes.end(); ++it) - { - if (playerClass.mName == it->mName) - classId = it->mId; - } - mClassImage->setImageTexture ("textures\\levelup\\" + classId + ".dds"); + const ESM::Class *cls = + MWBase::Environment::get().getWorld ()->getPlayer ().getClass (); + + mClassImage->setImageTexture ("textures\\levelup\\" + cls->mId + ".dds"); /// \todo replace this with INI-imported texts int level = creatureStats.getLevel ()+1; From 9dc9098fa7a2254f3baeee2acf004babba164551 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 01:52:34 +0400 Subject: [PATCH 5/9] update MWBase::World interface since records contains own id --- apps/openmw/mwbase/world.hpp | 6 +++--- apps/openmw/mwgui/spellcreationdialog.cpp | 4 ++-- apps/openmw/mwmechanics/alchemy.cpp | 2 +- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 5 ++--- apps/openmw/mwworld/worldimp.cpp | 15 ++++++--------- apps/openmw/mwworld/worldimp.hpp | 6 +++--- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index f28ff0184..611e70fe0 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -230,17 +230,17 @@ namespace MWBase ///< Toggle a render mode. ///< \return Resulting mode - virtual std::pair createRecord (const ESM::Potion& record) + virtual const ESM::Potion *createRecord (const ESM::Potion& record) = 0; ///< Create a new recrod (of type potion) in the ESM store. /// \return ID, pointer to created record - virtual std::pair createRecord (const ESM::Spell& record) + virtual const ESM::Spell *createRecord (const ESM::Spell& record) = 0; ///< Create a new recrod (of type spell) in the ESM store. /// \return ID, pointer to created record - virtual std::pair createRecord (const ESM::Class& record) + virtual const ESM::Class *createRecord (const ESM::Class& record) = 0; ///< Create a new recrod (of type class) in the ESM store. /// \return ID, pointer to created record diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 2ece05cb6..25af72c50 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -336,12 +336,12 @@ namespace MWGui MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0); - std::pair result = MWBase::Environment::get().getWorld()->createRecord(mSpell); + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->createRecord(mSpell); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); - spells.add (result.first); + spells.add (spell->mId); MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0); diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index 5ccdc5750..c07c60209 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -279,7 +279,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name) newRecord.mEffects.mList = mEffects; - record = MWBase::Environment::get().getWorld()->createRecord (newRecord).second; + record = MWBase::Environment::get().getWorld()->createRecord (newRecord); } MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 7fc7635a4..3ca3a4ba0 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -327,10 +327,9 @@ namespace MWMechanics { MWBase::World *world = MWBase::Environment::get().getWorld(); - std::pair res = - world->createRecord(cls); + const ESM::Class *ptr = world->createRecord(cls); - world->getPlayer().setClass(res.second->mId); + world->getPlayer().setClass(ptr->mId); mClassSelected = true; buildPlayer(); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 1c1a3939d..e2122aa2d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -779,22 +779,19 @@ namespace MWWorld return mRendering->toggleRenderMode (mode); } - std::pair World::createRecord (const ESM::Potion& record) + const ESM::Potion *World::createRecord (const ESM::Potion& record) { - const ESM::Potion *ptr = mStore.insert(record); - return std::make_pair(ptr->mId, ptr); + return mStore.insert(record); } - std::pair World::createRecord (const ESM::Class& record) + const ESM::Class *World::createRecord (const ESM::Class& record) { - const ESM::Class *ptr = mStore.insert(record); - return std::make_pair(ptr->mId, ptr); + return mStore.insert(record); } - std::pair World::createRecord (const ESM::Spell& record) + const ESM::Spell *World::createRecord (const ESM::Spell& record) { - const ESM::Spell *ptr = mStore.insert(record); - return std::make_pair(ptr->mId, ptr); + return mStore.insert(record); } const ESM::Cell *World::createRecord (const ESM::Cell& record) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index fe9e96110..123ad1f87 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -250,15 +250,15 @@ namespace MWWorld ///< Toggle a render mode. ///< \return Resulting mode - virtual std::pair createRecord (const ESM::Potion& record); + virtual const ESM::Potion *createRecord (const ESM::Potion& record); ///< Create a new recrod (of type potion) in the ESM store. /// \return ID, pointer to created record - virtual std::pair createRecord (const ESM::Spell& record); + virtual const ESM::Spell *createRecord (const ESM::Spell& record); ///< Create a new recrod (of type spell) in the ESM store. /// \return ID, pointer to created record - virtual std::pair createRecord (const ESM::Class& record); + virtual const ESM::Class *createRecord (const ESM::Class& record); ///< Create a new recrod (of type class) in the ESM store. /// \return ID, pointer to created record From 2a06d72e32b6fdcb6698d48a89b1703b736a74d7 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 02:27:01 +0400 Subject: [PATCH 6/9] remove unused custom character classes --- apps/openmw/mwworld/worldimp.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index e2122aa2d..26013e4ff 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1260,6 +1260,7 @@ namespace MWWorld break; case Player::Data_Class: + mStore.get().erase(player->mClass); player->mClass = value; break; From 83e758ee500a5975b6f1d2c09986b6ffb750cf4f Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 16:37:57 +0400 Subject: [PATCH 7/9] clean up interfaces --- apps/openmw/mwbase/world.hpp | 12 +- apps/openmw/mwgui/levelupdialog.cpp | 7 +- apps/openmw/mwgui/stats_window.cpp | 14 +- .../mwmechanics/mechanicsmanagerimp.cpp | 83 ++++-- .../mwmechanics/mechanicsmanagerimp.hpp | 1 + apps/openmw/mwworld/esmstore.hpp | 259 ++---------------- apps/openmw/mwworld/player.cpp | 38 --- apps/openmw/mwworld/player.hpp | 46 ---- apps/openmw/mwworld/store.hpp | 57 ---- apps/openmw/mwworld/worldimp.cpp | 56 +--- apps/openmw/mwworld/worldimp.hpp | 12 +- 11 files changed, 121 insertions(+), 464 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 611e70fe0..54cb12c59 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -29,6 +29,7 @@ namespace ESM struct Class; struct Potion; struct Spell; + struct NPC; } namespace MWRender @@ -249,6 +250,11 @@ namespace MWBase ///< Create a new recrod (of type cell) in the ESM store. /// \return ID, pointer to created record + virtual const ESM::NPC *createRecord(const ESM::NPC &record) = 0; + ///< Create a new recrod (of type npc) in the ESM store. + ///< \note special treatment for 'player' record + /// \return ID, pointer to created record + virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number = 1) = 0; ///< Run animation for a MW-reference. Calls to this function for references that are @@ -296,12 +302,6 @@ namespace MWBase /// 1 - only waiting \n /// 2 - player is underwater \n /// 3 - enemies are nearby (not implemented) - - /// Update player record part with given value - virtual void updatePlayer(int flag, const std::string &value) = 0; - - /// Update player record part with given value - virtual void updatePlayer(int flag, bool value) = 0; }; } diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index 099132b8b..45890b89f 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -108,7 +108,8 @@ namespace MWGui void LevelupDialog::open() { - MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer(); + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr player = world->getPlayer().getPlayer(); MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player); MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); @@ -119,9 +120,11 @@ namespace MWGui setAttributeValues(); + const ESM::NPC *playerData = player.get()->mBase; + // set class image const ESM::Class *cls = - MWBase::Environment::get().getWorld ()->getPlayer ().getClass (); + world->getStore().get().find(playerData->mClass); mClassImage->setImageTexture ("textures\\levelup\\" + cls->mId + ".dds"); diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index ae86cbf1a..a557539b7 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -252,12 +252,12 @@ void StatsWindow::onFrame () } setFactions(PCstats.getFactionRanks()); - +/* const ESM::BirthSign *sign = MWBase::Environment::get().getWorld()->getPlayer().getBirthsign(); setBirthSign((sign != 0) ? sign->mId : ""); - +*/ if (mChanged) updateSkillArea(); } @@ -429,11 +429,13 @@ void StatsWindow::updateSkillArea() if (!mMiscSkills.empty()) addSkills(mMiscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); - const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); + MWBase::World *world = MWBase::Environment::get().getWorld(); + const MWWorld::ESMStore &store = world->getStore(); + const ESM::NPC *player = + world->getPlayer().getPlayer().get()->mBase; // race tooltip - const ESM::Race* playerRace = - MWBase::Environment::get().getWorld()->getPlayer().getRace(); + const ESM::Race* playerRace = store.get().find(player->mRace); MyGUI::Widget* raceWidget; getWidget(raceWidget, "RaceText"); @@ -445,7 +447,7 @@ void StatsWindow::updateSkillArea() MyGUI::Widget* classWidget; const ESM::Class *playerClass = - MWBase::Environment::get().getWorld()->getPlayer().getClass(); + store.get().find(player->mClass); getWidget(classWidget, "ClassText"); ToolTips::createClassToolTip(classWidget, *playerClass); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 3ca3a4ba0..be675d1bd 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -37,14 +37,17 @@ namespace MWMechanics creatureStats.getAttribute(5).setBase (player->mNpdt52.mEndurance); creatureStats.getAttribute(6).setBase (player->mNpdt52.mPersonality); creatureStats.getAttribute(7).setBase (player->mNpdt52.mLuck); + + const MWWorld::ESMStore &esmStore = + MWBase::Environment::get().getWorld()->getStore(); // race if (mRaceSelected) { const ESM::Race *race = - MWBase::Environment::get().getWorld()->getPlayer().getRace(); + esmStore.get().find(player->mRace); - bool male = MWBase::Environment::get().getWorld()->getPlayer().isMale(); + bool male = (player->mFlags & ESM::NPC::Female) == 0; for (int i=0; i<8; ++i) { @@ -87,11 +90,11 @@ namespace MWMechanics } // birthsign - const ESM::BirthSign *sign = - MWBase::Environment::get().getWorld()->getPlayer().getBirthsign(); - - if (sign != 0) + if (!mSign.empty()) { + const ESM::BirthSign *sign = + esmStore.get().find(mSign); + for (std::vector::const_iterator iter (sign->mPowers.mList.begin()); iter!=sign->mPowers.mList.end(); ++iter) { @@ -103,7 +106,7 @@ namespace MWMechanics if (mClassSelected) { const ESM::Class *class_ = - MWBase::Environment::get().getWorld()->getPlayer().getClass(); + esmStore.get().find(player->mClass); for (int i=0; i<2; ++i) { @@ -132,7 +135,7 @@ namespace MWMechanics } const MWWorld::Store &skills = - MWBase::Environment::get().getWorld()->getStore().get(); + esmStore.get(); MWWorld::Store::iterator iter = skills.begin(); for (; iter != skills.end(); ++iter) @@ -263,13 +266,19 @@ namespace MWMechanics // basic player profile; should not change anymore after the creation phase is finished. MWBase::WindowManager *winMgr = MWBase::Environment::get().getWindowManager(); - - MWWorld::Player &player = - MWBase::Environment::get().getWorld()->getPlayer(); + + MWBase::World *world = MWBase::Environment::get().getWorld(); + const ESM::NPC *player = + world->getPlayer().getPlayer().get()->mBase; - winMgr->setValue ("name", player.getName()); - winMgr->setValue ("race", player.getRace()->mName); - winMgr->setValue ("class", player.getClass()->mName); + const ESM::Race *race = + world->getStore().get().find(player->mRace); + const ESM::Class *cls = + world->getStore().get().find(player->mClass); + + winMgr->setValue ("name", player->mName); + winMgr->setValue ("race", race->mName); + winMgr->setValue ("class", cls->mName); mUpdatePlayer = false; @@ -278,8 +287,8 @@ namespace MWMechanics for (int i=0; i<5; ++i) { - minorSkills[i] = player.getClass()->mData.mSkills[i][0]; - majorSkills[i] = player.getClass()->mData.mSkills[i][1]; + minorSkills[i] = cls->mData.mSkills[i][0]; + majorSkills[i] = cls->mData.mSkills[i][1]; } winMgr->configureSkills (majorSkills, minorSkills); @@ -295,14 +304,33 @@ namespace MWMechanics void MechanicsManager::setPlayerName (const std::string& name) { - MWBase::Environment::get().getWorld()->getPlayer().setName (name); + MWBase::World *world = MWBase::Environment::get().getWorld(); + + ESM::NPC player = + *world->getPlayer().getPlayer().get()->mBase; + player.mName = name; + + world->createRecord(player); + mUpdatePlayer = true; } void MechanicsManager::setPlayerRace (const std::string& race, bool male) { - MWBase::Environment::get().getWorld()->getPlayer().setGender (male); - MWBase::Environment::get().getWorld()->getPlayer().setRace (race); + MWBase::World *world = MWBase::Environment::get().getWorld(); + + ESM::NPC player = + *world->getPlayer().getPlayer().get()->mBase; + + player.mRace = race; + + player.mFlags |= ESM::NPC::Female; + if (male) { + player.mFlags ^= ESM::NPC::Female; + } + + world->createRecord(player); + mRaceSelected = true; buildPlayer(); mUpdatePlayer = true; @@ -310,14 +338,21 @@ namespace MWMechanics void MechanicsManager::setPlayerBirthsign (const std::string& id) { - MWBase::Environment::get().getWorld()->getPlayer().setBirthsign (id); + mSign = id; buildPlayer(); mUpdatePlayer = true; } void MechanicsManager::setPlayerClass (const std::string& id) { - MWBase::Environment::get().getWorld()->getPlayer().setClass(id); + MWBase::World *world = MWBase::Environment::get().getWorld(); + + ESM::NPC player = + *world->getPlayer().getPlayer().get()->mBase; + player.mClass = id; + + world->createRecord(player); + mClassSelected = true; buildPlayer(); mUpdatePlayer = true; @@ -329,7 +364,11 @@ namespace MWMechanics const ESM::Class *ptr = world->createRecord(cls); - world->getPlayer().setClass(ptr->mId); + ESM::NPC player = + *world->getPlayer().getPlayer().get()->mBase; + player.mClass = ptr->mId; + + world->createRecord(player); mClassSelected = true; buildPlayer(); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index 38536d3bd..cc4d8c46a 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -29,6 +29,7 @@ namespace MWMechanics bool mUpdatePlayer; bool mClassSelected; bool mRaceSelected; + std::string mSign; Actors mActors; void buildPlayer(); diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index dfe2ac03a..9917254ee 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -146,13 +146,13 @@ namespace MWWorld } template - Store &get() { - throw std::runtime_error("Storage for this type not exist (non-const)"); - } - - template - T *insert(const T &x) { + const T *insert(const T &x) { Store &store = const_cast &>(get()); + if (store.search(x.mId) != 0) { + std::ostringstream msg; + msg << "Try to override existing record '" << x.mId << "'"; + throw std::runtime_error(msg.str()); + } T record = x; std::ostringstream id; @@ -173,10 +173,30 @@ namespace MWWorld }; template <> - inline ESM::Cell *ESMStore::insert(const ESM::Cell &cell) { + inline const ESM::Cell *ESMStore::insert(const ESM::Cell &cell) { return mCells.insert(cell); } + template <> + inline const ESM::NPC *ESMStore::insert(const ESM::NPC &npc) { + if (StringUtils::ciEqual(npc.mId, "player")) { + return mNpcs.insert(npc); + } else if (mNpcs.search(npc.mId) != 0) { + std::ostringstream msg; + msg << "Try to override existing record '" << npc.mId << "'"; + throw std::runtime_error(msg.str()); + } + ESM::NPC record = npc; + + std::ostringstream id; + id << "$dynamic" << mDynamicCount++; + record.mId = id.str(); + + ESM::NPC *ptr = mNpcs.insert(record); + mIds[ptr->mId] = ESM::REC_NPC_; + return ptr; + } + template <> inline const Store &ESMStore::get() const { return mActivators; @@ -401,231 +421,6 @@ namespace MWWorld inline const Store &ESMStore::get() const { return mAttributes; } - - template <> - inline Store &ESMStore::get() { - return mActivators; - } - - template <> - inline Store &ESMStore::get() { - return mPotions; - } - - template <> - inline Store &ESMStore::get() { - return mAppas; - } - - template <> - inline Store &ESMStore::get() { - return mArmors; - } - - template <> - inline Store &ESMStore::get() { - return mBodyParts; - } - - template <> - inline Store &ESMStore::get() { - return mBooks; - } - - template <> - inline Store &ESMStore::get() { - return mBirthSigns; - } - - template <> - inline Store &ESMStore::get() { - return mClasses; - } - - template <> - inline Store &ESMStore::get() { - return mClothes; - } - - template <> - inline Store &ESMStore::get() { - return mContChange; - } - - template <> - inline Store &ESMStore::get() { - return mContainers; - } - - template <> - inline Store &ESMStore::get() { - return mCreatures; - } - - template <> - inline Store &ESMStore::get() { - return mCreaChange; - } - - template <> - inline Store &ESMStore::get() { - return mDialogs; - } - - template <> - inline Store &ESMStore::get() { - return mDoors; - } - - template <> - inline Store &ESMStore::get() { - return mEnchants; - } - - template <> - inline Store &ESMStore::get() { - return mFactions; - } - - template <> - inline Store &ESMStore::get() { - return mGlobals; - } - - template <> - inline Store &ESMStore::get() { - return mIngreds; - } - - template <> - inline Store &ESMStore::get() { - return mCreatureLists; - } - - template <> - inline Store &ESMStore::get() { - return mItemLists; - } - - template <> - inline Store &ESMStore::get() { - return mLights; - } - - template <> - inline Store &ESMStore::get() { - return mLockpicks; - } - - template <> - inline Store &ESMStore::get() { - return mMiscItems; - } - - template <> - inline Store &ESMStore::get() { - return mNpcs; - } - - template <> - inline Store &ESMStore::get() { - return mNpcChange; - } - - template <> - inline Store &ESMStore::get() { - return mProbes; - } - - template <> - inline Store &ESMStore::get() { - return mRaces; - } - - template <> - inline Store &ESMStore::get() { - return mRegions; - } - - template <> - inline Store &ESMStore::get() { - return mRepairs; - } - - template <> - inline Store &ESMStore::get() { - return mSoundGens; - } - - template <> - inline Store &ESMStore::get() { - return mSounds; - } - - template <> - inline Store &ESMStore::get() { - return mSpells; - } - - template <> - inline Store &ESMStore::get() { - return mStartScripts; - } - - template <> - inline Store &ESMStore::get() { - return mStatics; - } - - template <> - inline Store &ESMStore::get() { - return mWeapons; - } - - template <> - inline Store &ESMStore::get() { - return mGameSettings; - } - - template <> - inline Store &ESMStore::get() { - return mScripts; - } - - template <> - inline Store &ESMStore::get() { - return mCells; - } - - template <> - inline Store &ESMStore::get() { - return mLands; - } - - template <> - inline Store &ESMStore::get() { - return mLandTextures; - } - - template <> - inline Store &ESMStore::get() { - return mPathgrids; - } - - template <> - inline Store &ESMStore::get() { - return mMagicEffects; - } - - template <> - inline Store &ESMStore::get() { - return mSkills; - } - - template <> - inline Store &ESMStore::get() { - return mAttributes; - } } #endif diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 48767a1a1..3414ba448 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -15,9 +15,6 @@ namespace MWWorld { Player::Player (const ESM::NPC *player, const MWBase::World& world) : mCellStore(0), - mClass(0), - mRace(0), - mSign(0), mAutoMove(false), mForwardBackward (0) { @@ -26,9 +23,6 @@ namespace MWWorld float* playerPos = mPlayer.mData.getPosition().pos; playerPos[0] = playerPos[1] = playerPos[2] = 0; - - mClass = world.getStore().get().find (player->mClass); - mRace = world.getStore().get().find(player->mRace); } void Player::setDrawState (MWMechanics::DrawState_ state) @@ -91,36 +85,4 @@ namespace MWWorld MWWorld::Ptr ptr = getPlayer(); return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState(); } - - void Player::setName(const std::string &value) - { - MWBase::Environment::get().getWorld()->updatePlayer(Data_Name, value); - } - - void Player::setGender(bool value) - { - MWBase::Environment::get().getWorld()->updatePlayer(Data_Male, value); - } - - void Player::setRace(const std::string &value) - { - MWBase::World *world = MWBase::Environment::get().getWorld(); - world->updatePlayer(Data_Race, value); - - mRace = world->getStore().get().find(value); - } - - void Player::setBirthsign(const std::string &value) - { - MWBase::World *world = MWBase::Environment::get().getWorld(); - mSign = world->getStore().get().find(value); - } - - void Player::setClass(const std::string &value) - { - MWBase::World *world = MWBase::Environment::get().getWorld(); - world->updatePlayer(Data_Class, value); - - mClass = world->getStore().get().find(value); - } } diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 1e6dae2c2..7c5ac0018 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -22,25 +22,10 @@ namespace MWWorld LiveCellRef mPlayer; MWWorld::CellStore *mCellStore; - // cached referenced data - const ESM::Class *mClass; - const ESM::Race *mRace; - const ESM::BirthSign *mSign; - bool mAutoMove; int mForwardBackward; public: - enum { - Data_Male, - Data_Name, - Data_Race, - Data_Class, - Data_Sign, - Data_Model, - Data_Head, - Data_Hair - }; Player(const ESM::NPC *player, const MWBase::World& world); @@ -55,39 +40,8 @@ namespace MWWorld return ptr; } - void setName (const std::string& name); - void setGender (bool male); - void setRace (const std::string& race); - void setBirthsign (const std::string& birthsign); - void setClass (const std::string &cls); - void setDrawState (MWMechanics::DrawState_ state); - std::string getName() const - { - return mPlayer.mBase->mName; - } - - bool isMale() const - { - return (mPlayer.mBase->mFlags & 0x1) == 0; - } - - const ESM::Race *getRace() const - { - return mRace; - } - - const ESM::BirthSign *getBirthsign() const - { - return mSign; - } - - const ESM::Class *getClass() const - { - return mClass; - } - bool getAutoMove() const { return mAutoMove; diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index c645f6613..00f67c8ea 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -168,26 +168,6 @@ namespace MWWorld } } - T *search(const std::string &id) { - std::string key = StringUtils::lowerCase(id); - typename Dynamic::iterator dit = mDynamic.find(key); - - if (dit != mDynamic.end()) { - return &dit->second; - } - return 0; - } - - T *find(const std::string &id) { - T *ptr = search(id); - if (ptr == 0) { - std::ostringstream msg; - msg << "Object '" << id << "' not found (non-const)"; - throw std::runtime_error(msg.str()); - } - return ptr; - } - T *insert(const T &item) { std::string id = StringUtils::lowerCase(item.mId); std::pair result = @@ -523,43 +503,6 @@ namespace MWWorld } } - ESM::Cell *search(const std::string &id) { - std::string key = StringUtils::lowerCase(id); - DynamicInt::iterator it = mDynamicInt.find(key); - if (it != mDynamicInt.end()) { - return &it->second; - } - return 0; - } - - ESM::Cell *find(const std::string &id) { - ESM::Cell *ptr = search(id); - if (ptr == 0) { - std::ostringstream msg; - msg << "Interior '" << id << "' not found (non-const)"; - throw std::runtime_error(msg.str()); - } - return ptr; - } - - ESM::Cell *search(int x, int y) { - DynamicExt::iterator it = mDynamicExt.find(std::make_pair(x, y)); - if (it != mDynamicExt.end()) { - return &it->second; - } - return 0; - } - - ESM::Cell *find(int x, int y) { - ESM::Cell *ptr = search(x, y); - if (ptr == 0) { - std::ostringstream msg; - msg << "Exterior at (" << x << ", " << y << ") not found (non-const)"; - throw std::runtime_error(msg.str()); - } - return ptr; - } - ESM::Cell *insert(const ESM::Cell &cell) { if (search(cell) != 0) { std::ostringstream msg; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 26013e4ff..af5745744 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -799,6 +799,11 @@ namespace MWWorld return mStore.insert(record); } + const ESM::NPC *World::createRecord(const ESM::NPC &record) + { + return mStore.insert(record); + } + void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number) { @@ -1055,12 +1060,12 @@ namespace MWWorld // door leads to exterior, use cell name (if any), otherwise translated region name int x,y; positionToIndex (ref.mRef.mDoorDest.pos[0], ref.mRef.mDoorDest.pos[1], x, y); - const ESM::Cell* cell = ((const ESMStore &) mStore).get().find(x,y); + const ESM::Cell* cell = mStore.get().find(x,y); if (cell->mName != "") dest = cell->mName; else { - dest = ((const ESMStore &) mStore).get().find(cell->mRegion)->mName; + dest = mStore.get().find(cell->mRegion)->mName; } } @@ -1249,51 +1254,4 @@ namespace MWWorld return 0; } - - void World::updatePlayer(int flag, const std::string &value) - { - ESM::NPC *player = mStore.get().find("player"); - - switch (flag) { - case Player::Data_Name: - player->mName = value; - break; - - case Player::Data_Class: - mStore.get().erase(player->mClass); - player->mClass = value; - break; - - case Player::Data_Race: - player->mRace = value; - break; - - case Player::Data_Model: - player->mModel = value; - break; - - case Player::Data_Head: - player->mHead = value; - break; - - case Player::Data_Hair: - player->mHair = value; - break; - - default: - break; - } - } - - void World::updatePlayer(int flag, bool value) - { - ESM::NPC *player = mStore.get().find("player"); - - if (flag == Player::Data_Male) { - player->mFlags |= 0x1; - if (value) { - player->mFlags ^= 0x1; - } - } - } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 123ad1f87..20590ff0a 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -266,6 +266,12 @@ namespace MWWorld ///< Create a new recrod (of type cell) in the ESM store. /// \return ID, pointer to created record + virtual const ESM::NPC *createRecord(const ESM::NPC &record); + ///< Create a new recrod (of type npc) in the ESM store. + ///< \note special treatment for 'player' record + /// \return ID, pointer to created record + + virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number = 1); ///< Run animation for a MW-reference. Calls to this function for references that are @@ -327,12 +333,6 @@ namespace MWWorld /// 1 - only waiting \n /// 2 - player is underwater \n /// 3 - enemies are nearby (not implemented) - - /// Update player record part with given value - virtual void updatePlayer(int flag, const std::string &value); - - /// Update player record part with given value - virtual void updatePlayer(int flag, bool value); }; } From 2a86432887545756c52cd627f7681ab280df3b23 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 18:50:18 +0400 Subject: [PATCH 8/9] store birthsign in MWWorld::Player --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwgui/stats_window.cpp | 10 +++++----- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 9 ++++++--- apps/openmw/mwmechanics/mechanicsmanagerimp.hpp | 1 - apps/openmw/mwworld/player.hpp | 9 +++++++++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 54cb12c59..199b563da 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -252,7 +252,7 @@ namespace MWBase virtual const ESM::NPC *createRecord(const ESM::NPC &record) = 0; ///< Create a new recrod (of type npc) in the ESM store. - ///< \note special treatment for 'player' record + /// \note special treatment for 'player' record /// \return ID, pointer to created record virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index a557539b7..4b47bb025 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -252,12 +252,12 @@ void StatsWindow::onFrame () } setFactions(PCstats.getFactionRanks()); -/* - const ESM::BirthSign *sign = - MWBase::Environment::get().getWorld()->getPlayer().getBirthsign(); - setBirthSign((sign != 0) ? sign->mId : ""); -*/ + const std::string &signId = + MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); + + setBirthSign(signId); + if (mChanged) updateSkillArea(); } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index be675d1bd..50868eeb3 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -90,10 +90,13 @@ namespace MWMechanics } // birthsign - if (!mSign.empty()) + const std::string &signId = + MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); + + if (!signId.empty()) { const ESM::BirthSign *sign = - esmStore.get().find(mSign); + esmStore.get().find(signId); for (std::vector::const_iterator iter (sign->mPowers.mList.begin()); iter!=sign->mPowers.mList.end(); ++iter) @@ -338,7 +341,7 @@ namespace MWMechanics void MechanicsManager::setPlayerBirthsign (const std::string& id) { - mSign = id; + MWBase::Environment::get().getWorld()->getPlayer().setBirthSign(id); buildPlayer(); mUpdatePlayer = true; } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index cc4d8c46a..38536d3bd 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -29,7 +29,6 @@ namespace MWMechanics bool mUpdatePlayer; bool mClassSelected; bool mRaceSelected; - std::string mSign; Actors mActors; void buildPlayer(); diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 7c5ac0018..1c1ef76cf 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -21,6 +21,7 @@ namespace MWWorld { LiveCellRef mPlayer; MWWorld::CellStore *mCellStore; + std::string mSign; bool mAutoMove; int mForwardBackward; @@ -40,6 +41,14 @@ namespace MWWorld return ptr; } + void setBirthSign(const std::string &sign) { + mSign = sign; + } + + const std::string &getBirthSign() const { + return mSign; + } + void setDrawState (MWMechanics::DrawState_ state); bool getAutoMove() const From b5a59c3a07a5b8b2453a3528c21e34cb07db1269 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 8 Nov 2012 19:01:42 +0400 Subject: [PATCH 9/9] minor doxygen comments update --- apps/openmw/mwbase/world.hpp | 11 +++++------ apps/openmw/mwworld/worldimp.hpp | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 199b563da..5416945e7 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -234,26 +234,25 @@ namespace MWBase virtual const ESM::Potion *createRecord (const ESM::Potion& record) = 0; ///< Create a new recrod (of type potion) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::Spell *createRecord (const ESM::Spell& record) = 0; ///< Create a new recrod (of type spell) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::Class *createRecord (const ESM::Class& record) = 0; ///< Create a new recrod (of type class) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::Cell *createRecord (const ESM::Cell& record) = 0; ///< Create a new recrod (of type cell) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::NPC *createRecord(const ESM::NPC &record) = 0; ///< Create a new recrod (of type npc) in the ESM store. - /// \note special treatment for 'player' record - /// \return ID, pointer to created record + /// \return pointer to created record virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number = 1) = 0; diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 20590ff0a..0962c292c 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -252,24 +252,23 @@ namespace MWWorld virtual const ESM::Potion *createRecord (const ESM::Potion& record); ///< Create a new recrod (of type potion) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::Spell *createRecord (const ESM::Spell& record); ///< Create a new recrod (of type spell) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::Class *createRecord (const ESM::Class& record); ///< Create a new recrod (of type class) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::Cell *createRecord (const ESM::Cell& record); ///< Create a new recrod (of type cell) in the ESM store. - /// \return ID, pointer to created record + /// \return pointer to created record virtual const ESM::NPC *createRecord(const ESM::NPC &record); ///< Create a new recrod (of type npc) in the ESM store. - ///< \note special treatment for 'player' record - /// \return ID, pointer to created record + /// \return pointer to created record virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,