mirror of
https://github.com/OpenMW/openmw.git
synced 2025-11-09 01:46:40 +00:00
Run ~CharacterController when invalidating an Actor
This commit is contained in:
parent
c098f2ccde
commit
b2bb12cd19
2 changed files with 16 additions and 9 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
#define OPENMW_MECHANICS_ACTOR_H
|
#define OPENMW_MECHANICS_ACTOR_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
#include "creaturestats.hpp"
|
#include "creaturestats.hpp"
|
||||||
|
|
@ -29,18 +30,18 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Actor(const MWWorld::Ptr& ptr, MWRender::Animation* animation)
|
Actor(const MWWorld::Ptr& ptr, MWRender::Animation* animation)
|
||||||
: mCharacterController(ptr, animation)
|
: mPositionAdjusted(ptr.getClass().getCreatureStats(ptr).getFallHeight() > 0)
|
||||||
, mPositionAdjusted(ptr.getClass().getCreatureStats(ptr).getFallHeight() > 0)
|
|
||||||
{
|
{
|
||||||
|
mCharacterController.emplace(ptr, animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MWWorld::Ptr& getPtr() const { return mCharacterController.getPtr(); }
|
const MWWorld::Ptr& getPtr() const { return mCharacterController->getPtr(); }
|
||||||
|
|
||||||
/// Notify this actor of its new base object Ptr, use when the object changed cells
|
/// Notify this actor of its new base object Ptr, use when the object changed cells
|
||||||
void updatePtr(const MWWorld::Ptr& newPtr) { mCharacterController.updatePtr(newPtr); }
|
void updatePtr(const MWWorld::Ptr& newPtr) { mCharacterController->updatePtr(newPtr); }
|
||||||
|
|
||||||
CharacterController& getCharacterController() { return mCharacterController; }
|
CharacterController& getCharacterController() { return *mCharacterController; }
|
||||||
const CharacterController& getCharacterController() const { return mCharacterController; }
|
const CharacterController& getCharacterController() const { return *mCharacterController; }
|
||||||
|
|
||||||
int getGreetingTimer() const { return mGreetingTimer; }
|
int getGreetingTimer() const { return mGreetingTimer; }
|
||||||
void setGreetingTimer(int timer) { mGreetingTimer = timer; }
|
void setGreetingTimer(int timer) { mGreetingTimer = timer; }
|
||||||
|
|
@ -62,11 +63,15 @@ namespace MWMechanics
|
||||||
void setPositionAdjusted(bool adjusted) { mPositionAdjusted = adjusted; }
|
void setPositionAdjusted(bool adjusted) { mPositionAdjusted = adjusted; }
|
||||||
bool getPositionAdjusted() const { return mPositionAdjusted; }
|
bool getPositionAdjusted() const { return mPositionAdjusted; }
|
||||||
|
|
||||||
void invalidate() { mInvalid = true; }
|
void invalidate()
|
||||||
|
{
|
||||||
|
mInvalid = true;
|
||||||
|
mCharacterController.reset();
|
||||||
|
}
|
||||||
bool isInvalid() const { return mInvalid; }
|
bool isInvalid() const { return mInvalid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CharacterController mCharacterController;
|
std::optional<CharacterController> mCharacterController;
|
||||||
int mGreetingTimer{ 0 };
|
int mGreetingTimer{ 0 };
|
||||||
float mTargetAngleRadians{ 0.f };
|
float mTargetAngleRadians{ 0.f };
|
||||||
GreetingState mGreetingState{ Greet_None };
|
GreetingState mGreetingState{ Greet_None };
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,8 @@ namespace
|
||||||
{
|
{
|
||||||
for (const MWMechanics::Actor& actor : actors)
|
for (const MWMechanics::Actor& actor : actors)
|
||||||
{
|
{
|
||||||
|
if (actor.isInvalid())
|
||||||
|
continue;
|
||||||
const MWWorld::Ptr& iteratedActor = actor.getPtr();
|
const MWWorld::Ptr& iteratedActor = actor.getPtr();
|
||||||
if (iteratedActor == player || iteratedActor == actorPtr)
|
if (iteratedActor == player || iteratedActor == actorPtr)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -345,7 +347,7 @@ namespace MWMechanics
|
||||||
// Find something nearby.
|
// Find something nearby.
|
||||||
for (const Actor& otherActor : actors)
|
for (const Actor& otherActor : actors)
|
||||||
{
|
{
|
||||||
if (otherActor.getPtr() == ptr)
|
if (otherActor.isInvalid() || otherActor.getPtr() == ptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
updateHeadTracking(
|
updateHeadTracking(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue