diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 45e87a7942..64acf1c10f 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "../mwworld/esmstore.hpp" #include "../mwworld/inventorystore.hpp" @@ -23,6 +24,9 @@ #include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/spellutil.hpp" +#include "../mwrender/renderingmanager.hpp" +#include "../mwrender/camera.hpp" + #include "cellstore.hpp" #include "class.hpp" #include "ptr.hpp" @@ -514,4 +518,56 @@ namespace MWWorld MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, castChance); MWBase::Environment::get().getWindowManager()->updateSpellWindow(); } + + void Player::update() + { + auto player = getPlayer(); + auto* world = MWBase::Environment::get().getWorld(); + auto* rendering = world->getRenderingManager(); + auto& store = world->getStore(); + auto& playerClass = player.getClass(); + auto* windowMgr = MWBase::Environment::get().getWindowManager(); + + if (player.getCell()->isExterior()) + { + ESM::Position pos = player.getRefData().getPosition(); + setLastKnownExteriorPosition(pos.asVec3()); + } + + bool isWerewolf = playerClass.getNpcStats(player).isWerewolf(); + bool isFirstPerson = world->isFirstPerson(); + if (isWerewolf && isFirstPerson) + { + float werewolfFov = Fallback::Map::getFloat("General_Werewolf_FOV"); + if (werewolfFov != 0) + rendering->overrideFieldOfView(werewolfFov); + windowMgr->setWerewolfOverlay(true); + } + else + { + rendering->resetFieldOfView(); + windowMgr->setWerewolfOverlay(false); + } + + // Sink the camera while sneaking + bool sneaking = playerClass.getCreatureStats(player).getStance(MWMechanics::CreatureStats::Stance_Sneak); + bool swimming = world->isSwimming(player); + bool flying = world->isFlying(player); + + static const float i1stPersonSneakDelta = store.get().find("i1stPersonSneakDelta")->mValue.getFloat(); + if (sneaking && !swimming && !flying) + rendering->getCamera()->setSneakOffset(i1stPersonSneakDelta); + else + rendering->getCamera()->setSneakOffset(0.f); + + int blind = 0; + const auto& magicEffects = playerClass.getCreatureStats(player).getMagicEffects(); + if (!world->getGodModeState()) + blind = static_cast(magicEffects.get(ESM::MagicEffect::Blind).getMagnitude()); + windowMgr->setBlindness(std::clamp(blind, 0, 100)); + + int nightEye = static_cast(magicEffects.get(ESM::MagicEffect::NightEye).getMagnitude()); + rendering->setNightEyeFactor(std::min(1.f, (nightEye / 100.f))); + } + } diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 4add58541e..3a3c58cb5d 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -135,6 +135,8 @@ namespace MWWorld void erasePreviousItem(const std::string& boundItemId); void setSelectedSpell(const std::string& spellId); + + void update(); }; } #endif diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index f925ebec82..ff343e0828 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1845,7 +1845,7 @@ namespace MWWorld updateNavigator(); } - updatePlayer(); + mPlayer->update(); mPhysics->debugDraw(); @@ -1876,54 +1876,6 @@ namespace MWWorld } } - void World::updatePlayer() - { - MWWorld::Ptr player = getPlayerPtr(); - - // TODO: move to MWWorld::Player - - if (player.getCell()->isExterior()) - { - ESM::Position pos = player.getRefData().getPosition(); - mPlayer->setLastKnownExteriorPosition(pos.asVec3()); - } - - bool isWerewolf = player.getClass().getNpcStats(player).isWerewolf(); - bool isFirstPerson = this->isFirstPerson(); - if (isWerewolf && isFirstPerson) - { - float werewolfFov = Fallback::Map::getFloat("General_Werewolf_FOV"); - if (werewolfFov != 0) - mRendering->overrideFieldOfView(werewolfFov); - MWBase::Environment::get().getWindowManager()->setWerewolfOverlay(true); - } - else - { - mRendering->resetFieldOfView(); - MWBase::Environment::get().getWindowManager()->setWerewolfOverlay(false); - } - - // Sink the camera while sneaking - bool sneaking = player.getClass().getCreatureStats(getPlayerPtr()).getStance(MWMechanics::CreatureStats::Stance_Sneak); - bool swimming = isSwimming(player); - bool flying = isFlying(player); - - static const float i1stPersonSneakDelta = mStore.get().find("i1stPersonSneakDelta")->mValue.getFloat(); - if (sneaking && !swimming && !flying) - mRendering->getCamera()->setSneakOffset(i1stPersonSneakDelta); - else - mRendering->getCamera()->setSneakOffset(0.f); - - int blind = 0; - const auto& magicEffects = player.getClass().getCreatureStats(player).getMagicEffects(); - if (!mGodMode) - blind = static_cast(magicEffects.get(ESM::MagicEffect::Blind).getMagnitude()); - MWBase::Environment::get().getWindowManager()->setBlindness(std::clamp(blind, 0, 100)); - - int nightEye = static_cast(magicEffects.get(ESM::MagicEffect::NightEye).getMagnitude()); - mRendering->setNightEyeFactor(std::min(1.f, (nightEye/100.f))); - } - void World::preloadSpells() { std::string selectedSpell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 2dc1f3c81a..fb1b80daf3 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -141,7 +141,6 @@ namespace MWWorld Ptr copyObjectToCell(const ConstPtr &ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos); void updateSoundListener(); - void updatePlayer(); void preloadSpells();