1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 21:40:03 +00:00

Merge branch 'rm_actors_static' into 'master'

Make MWMechanics::Actors local static variables to be members

See merge request OpenMW/openmw!1839
This commit is contained in:
psi29a 2022-05-09 07:31:15 +00:00
commit 8bf5de69ad
2 changed files with 66 additions and 57 deletions

View File

@ -380,7 +380,7 @@ namespace MWMechanics
return; return;
// Play a random voice greeting if the player gets too close // Play a random voice greeting if the player gets too close
static int iGreetDistanceMultiplier = MWBase::Environment::get().getWorld()->getStore() static const int iGreetDistanceMultiplier = MWBase::Environment::get().getWorld()->getStore()
.get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->mValue.getInteger(); .get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->mValue.getInteger();
float helloDistance = static_cast<float>(actorStats.getAiSetting(CreatureStats::AI_Hello).getModified() * iGreetDistanceMultiplier); float helloDistance = static_cast<float>(actorStats.getAiSetting(CreatureStats::AI_Hello).getModified() * iGreetDistanceMultiplier);
@ -1207,18 +1207,17 @@ namespace MWMechanics
} }
// check if we still have any player enemies to switch music // check if we still have any player enemies to switch music
static int currentMusic = 0; if (mCurrentMusic != MusicType::Explore && !hasHostiles
&& !(player.getClass().getCreatureStats(player).isDead()
if (currentMusic != 1 && !hasHostiles && !(player.getClass().getCreatureStats(player).isDead() && && MWBase::Environment::get().getSoundManager()->isMusicPlaying()))
MWBase::Environment::get().getSoundManager()->isMusicPlaying()))
{ {
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore")); MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
currentMusic = 1; mCurrentMusic = MusicType::Explore;
} }
else if (currentMusic != 2 && hasHostiles) else if (mCurrentMusic != MusicType::Battle && hasHostiles)
{ {
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Battle")); MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Battle"));
currentMusic = 2; mCurrentMusic = MusicType::Battle;
} }
} }
@ -1374,15 +1373,19 @@ namespace MWMechanics
{ {
if(!paused) if(!paused)
{ {
static float timerUpdateHeadTrack = 0;
static float timerUpdateEquippedLight = 0;
static float timerUpdateHello = 0;
const float updateEquippedLightInterval = 1.0f; const float updateEquippedLightInterval = 1.0f;
if (timerUpdateHeadTrack >= 0.3f) timerUpdateHeadTrack = 0; if (mTimerUpdateHeadTrack >= 0.3f)
if (timerUpdateHello >= 0.25f) timerUpdateHello = 0; mTimerUpdateHeadTrack = 0;
if (mTimerDisposeSummonsCorpses >= 0.2f) mTimerDisposeSummonsCorpses = 0;
if (timerUpdateEquippedLight >= updateEquippedLightInterval) timerUpdateEquippedLight = 0; if (mTimerUpdateHello >= 0.25f)
mTimerUpdateHello = 0;
if (mTimerDisposeSummonsCorpses >= 0.2f)
mTimerDisposeSummonsCorpses = 0;
if (mTimerUpdateEquippedLight >= updateEquippedLightInterval)
mTimerUpdateEquippedLight = 0;
// show torches only when there are darkness and no precipitations // show torches only when there are darkness and no precipitations
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
@ -1470,7 +1473,7 @@ namespace MWMechanics
engageCombat(iter->first, it->first, cachedAllies, it->first == player); engageCombat(iter->first, it->first, cachedAllies, it->first == player);
} }
} }
if (timerUpdateHeadTrack == 0) if (mTimerUpdateHeadTrack == 0)
{ {
float sqrHeadTrackDistance = std::numeric_limits<float>::max(); float sqrHeadTrackDistance = std::numeric_limits<float>::max();
MWWorld::Ptr headTrackTarget; MWWorld::Ptr headTrackTarget;
@ -1518,7 +1521,7 @@ namespace MWMechanics
if (isConscious(iter->first) && !(luaControls && luaControls->mDisableAI)) if (isConscious(iter->first) && !(luaControls && luaControls->mDisableAI))
{ {
stats.getAiSequence().execute(iter->first, *ctrl, duration); stats.getAiSequence().execute(iter->first, *ctrl, duration);
updateGreetingState(iter->first, *iter->second, timerUpdateHello > 0); updateGreetingState(iter->first, *iter->second, mTimerUpdateHello > 0);
playIdleDialogue(iter->first); playIdleDialogue(iter->first);
updateMovementSpeed(iter->first); updateMovementSpeed(iter->first);
} }
@ -1535,7 +1538,7 @@ namespace MWMechanics
// We can not update drowning state for actors outside of AI distance - they can not resurface to breathe // We can not update drowning state for actors outside of AI distance - they can not resurface to breathe
updateDrowning(iter->first, duration, ctrl->isKnockedOut(), isPlayer); updateDrowning(iter->first, duration, ctrl->isKnockedOut(), isPlayer);
} }
if(timerUpdateEquippedLight == 0 && iter->first.getClass().hasInventoryStore(iter->first)) if(mTimerUpdateEquippedLight == 0 && iter->first.getClass().hasInventoryStore(iter->first))
updateEquippedLight(iter->first, updateEquippedLightInterval, showTorches); updateEquippedLight(iter->first, updateEquippedLightInterval, showTorches);
if (luaControls && isConscious(iter->first)) if (luaControls && isConscious(iter->first))
@ -1577,9 +1580,9 @@ namespace MWMechanics
if (avoidCollisions) if (avoidCollisions)
predictAndAvoidCollisions(duration); predictAndAvoidCollisions(duration);
timerUpdateHeadTrack += duration; mTimerUpdateHeadTrack += duration;
timerUpdateEquippedLight += duration; mTimerUpdateEquippedLight += duration;
timerUpdateHello += duration; mTimerUpdateHello += duration;
mTimerDisposeSummonsCorpses += duration; mTimerDisposeSummonsCorpses += duration;
// Animation/movement update // Animation/movement update
@ -1829,8 +1832,6 @@ namespace MWMechanics
void Actors::updateSneaking(CharacterController* ctrl, float duration) void Actors::updateSneaking(CharacterController* ctrl, float duration)
{ {
static float sneakTimer = 0.f; // Times update of sneak icon
if (!ctrl) if (!ctrl)
{ {
MWBase::Environment::get().getWindowManager()->setSneakVisibility(false); MWBase::Environment::get().getWindowManager()->setSneakVisibility(false);
@ -1845,17 +1846,15 @@ namespace MWMechanics
return; return;
} }
static float sneakSkillTimer = 0.f; // Times sneak skill progress from "avoid notice"
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
const MWWorld::Store<ESM::GameSetting>& gmst = world->getStore().get<ESM::GameSetting>(); const MWWorld::Store<ESM::GameSetting>& gmst = world->getStore().get<ESM::GameSetting>();
static const float fSneakUseDist = gmst.find("fSneakUseDist")->mValue.getFloat(); static const float fSneakUseDist = gmst.find("fSneakUseDist")->mValue.getFloat();
static const float fSneakUseDelay = gmst.find("fSneakUseDelay")->mValue.getFloat(); static const float fSneakUseDelay = gmst.find("fSneakUseDelay")->mValue.getFloat();
if (sneakTimer >= fSneakUseDelay) if (mSneakTimer >= fSneakUseDelay)
sneakTimer = 0.f; mSneakTimer = 0.f;
if (sneakTimer == 0.f) if (mSneakTimer == 0.f)
{ {
// Set when an NPC is within line of sight and distance, but is still unaware. Used for skill progress. // Set when an NPC is within line of sight and distance, but is still unaware. Used for skill progress.
bool avoidedNotice = false; bool avoidedNotice = false;
@ -1893,18 +1892,18 @@ namespace MWMechanics
} }
} }
if (sneakSkillTimer >= fSneakUseDelay) if (mSneakSkillTimer >= fSneakUseDelay)
sneakSkillTimer = 0.f; mSneakSkillTimer = 0.f;
if (avoidedNotice && sneakSkillTimer == 0.f) if (avoidedNotice && mSneakSkillTimer == 0.f)
player.getClass().skillUsageSucceeded(player, ESM::Skill::Sneak, 0); player.getClass().skillUsageSucceeded(player, ESM::Skill::Sneak, 0);
if (!detected) if (!detected)
MWBase::Environment::get().getWindowManager()->setSneakVisibility(true); MWBase::Environment::get().getWindowManager()->setSneakVisibility(true);
} }
sneakTimer += duration; mSneakTimer += duration;
sneakSkillTimer += duration; mSneakSkillTimer += duration;
} }
int Actors::getHoursToRest(const MWWorld::Ptr &ptr) const int Actors::getHoursToRest(const MWWorld::Ptr &ptr) const

View File

@ -39,24 +39,6 @@ namespace MWMechanics
class Actors class Actors
{ {
std::map<std::string, int> mDeathCount;
void adjustMagicEffects (const MWWorld::Ptr& creature, float duration);
void calculateRestoration (const MWWorld::Ptr& ptr, float duration);
void updateDrowning (const MWWorld::Ptr& ptr, float duration, bool isKnockedOut, bool isPlayer);
void updateEquippedLight (const MWWorld::Ptr& ptr, float duration, bool mayEquip);
void updateCrimePursuit (const MWWorld::Ptr& ptr, float duration);
void killDeadActors ();
void purgeSpellEffects (int casterActorId);
void predictAndAvoidCollisions(float duration);
public: public:
Actors(); Actors();
@ -200,14 +182,42 @@ namespace MWMechanics
GreetingState getGreetingState(const MWWorld::Ptr& ptr) const; GreetingState getGreetingState(const MWWorld::Ptr& ptr) const;
bool isTurningToPlayer(const MWWorld::Ptr& ptr) const; bool isTurningToPlayer(const MWWorld::Ptr& ptr) const;
private: private:
void updateVisibility (const MWWorld::Ptr& ptr, CharacterController* ctrl); enum class MusicType
{
Explore,
Battle
};
PtrActorMap mActors; std::map<std::string, int> mDeathCount;
float mTimerDisposeSummonsCorpses; PtrActorMap mActors;
float mActorsProcessingRange; float mTimerDisposeSummonsCorpses;
float mTimerUpdateHeadTrack = 0;
float mTimerUpdateEquippedLight = 0;
float mTimerUpdateHello = 0;
float mSneakTimer = 0; // Times update of sneak icon
float mSneakSkillTimer = 0; // Times sneak skill progress from "avoid notice"
float mActorsProcessingRange;
bool mSmoothMovement;
MusicType mCurrentMusic = MusicType::Explore;
bool mSmoothMovement; void updateVisibility (const MWWorld::Ptr& ptr, CharacterController* ctrl);
void adjustMagicEffects (const MWWorld::Ptr& creature, float duration);
void calculateRestoration (const MWWorld::Ptr& ptr, float duration);
void updateDrowning (const MWWorld::Ptr& ptr, float duration, bool isKnockedOut, bool isPlayer);
void updateEquippedLight (const MWWorld::Ptr& ptr, float duration, bool mayEquip);
void updateCrimePursuit (const MWWorld::Ptr& ptr, float duration);
void killDeadActors ();
void purgeSpellEffects (int casterActorId);
void predictAndAvoidCollisions(float duration);
}; };
} }