mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 15:35:23 +00:00
#5336: Refactor World::updatePlayer in to Player::update
This commit is contained in:
parent
06dee79cc3
commit
2bbd0ba976
@ -9,6 +9,7 @@
|
||||
#include <components/esm3/player.hpp>
|
||||
#include <components/esm/defs.hpp>
|
||||
#include <components/esm3/loadbsgn.hpp>
|
||||
#include <components/fallback/fallback.hpp>
|
||||
|
||||
#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<ESM::GameSetting>().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<int>(magicEffects.get(ESM::MagicEffect::Blind).getMagnitude());
|
||||
windowMgr->setBlindness(std::clamp(blind, 0, 100));
|
||||
|
||||
int nightEye = static_cast<int>(magicEffects.get(ESM::MagicEffect::NightEye).getMagnitude());
|
||||
rendering->setNightEyeFactor(std::min(1.f, (nightEye / 100.f)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -135,6 +135,8 @@ namespace MWWorld
|
||||
void erasePreviousItem(const std::string& boundItemId);
|
||||
|
||||
void setSelectedSpell(const std::string& spellId);
|
||||
|
||||
void update();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
@ -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<ESM::GameSetting>().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<int>(magicEffects.get(ESM::MagicEffect::Blind).getMagnitude());
|
||||
MWBase::Environment::get().getWindowManager()->setBlindness(std::clamp(blind, 0, 100));
|
||||
|
||||
int nightEye = static_cast<int>(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();
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user