1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-25 16:43:33 +00:00

Reorganize ActorFrameData members:

- constify all read-only variables
- order them so that all variables modified as aprt of the simulation
  fits in one cache line
This commit is contained in:
fredzio 2021-07-23 23:08:35 +02:00
parent 0c5cf6ec19
commit bcd6541d3e
2 changed files with 39 additions and 41 deletions

View File

@ -797,7 +797,8 @@ namespace MWPhysics
if(cell->getCell()->hasWater()) if(cell->getCell()->hasWater())
waterlevel = cell->getWaterLevel(); waterlevel = cell->getWaterLevel();
const MWMechanics::MagicEffects& effects = actor.getClass().getCreatureStats(ptr).getMagicEffects(); const auto& stats = ptr.getClass().getCreatureStats(ptr);
const MWMechanics::MagicEffects& effects = stats.getMagicEffects();
bool waterCollision = false; bool waterCollision = false;
if (cell->getCell()->hasWater() && effects.get(ESM::MagicEffect::WaterWalking).getMagnitude()) if (cell->getCell()->hasWater() && effects.get(ESM::MagicEffect::WaterWalking).getMagnitude())
@ -810,9 +811,11 @@ namespace MWPhysics
// Slow fall reduces fall speed by a factor of (effect magnitude / 200) // Slow fall reduces fall speed by a factor of (effect magnitude / 200)
const float slowFall = 1.f - std::max(0.f, std::min(1.f, effects.get(ESM::MagicEffect::SlowFall).getMagnitude() * 0.005f)); const float slowFall = 1.f - std::max(0.f, std::min(1.f, effects.get(ESM::MagicEffect::SlowFall).getMagnitude() * 0.005f));
const bool godmode = ptr == world->getPlayerConstPtr() && world->getGodModeState();
const bool inert = stats.isDead() || (!godmode && stats.getMagicEffects().get(ESM::MagicEffect::Paralyze).getModifier() > 0);
framedata.first.emplace_back(physicActor); framedata.first.emplace_back(physicActor);
framedata.second.emplace_back(*physicActor, waterCollision, slowFall, waterlevel); framedata.second.emplace_back(*physicActor, inert, waterCollision, slowFall, waterlevel);
// if the simulation will run, a jump request will be fulfilled. Update mechanics accordingly. // if the simulation will run, a jump request will be fulfilled. Update mechanics accordingly.
if (willSimulate) if (willSimulate)
@ -984,34 +987,29 @@ namespace MWPhysics
mDebugDrawer->addCollision(position, normal); mDebugDrawer->addCollision(position, normal);
} }
ActorFrameData::ActorFrameData(Actor& actor, bool waterCollision, float slowFall, float waterlevel) ActorFrameData::ActorFrameData(Actor& actor, bool inert, bool waterCollision, float slowFall, float waterlevel)
: mCollisionObject(actor.getCollisionObject()) : mPosition()
, mStandingOn(nullptr) , mStandingOn(nullptr)
, mWasOnGround(actor.getOnGround())
, mIsOnGround(actor.getOnGround()) , mIsOnGround(actor.getOnGround())
, mIsOnSlope(actor.getOnSlope()) , mIsOnSlope(actor.getOnSlope())
, mNeedLand(false)
, mWaterCollision(waterCollision)
, mWalkingOnWater(false) , mWalkingOnWater(false)
, mSkipCollisionDetection(actor.skipCollisions() || !actor.getCollisionMode()) , mInert(inert)
, mWaterlevel(waterlevel) , mCollisionObject(actor.getCollisionObject())
, mSwimLevel(waterlevel - (actor.getRenderingHalfExtents().z() * 2 * MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fSwimHeightScale")->mValue.getFloat()))
, mSlowFall(slowFall) , mSlowFall(slowFall)
, mRotation()
, mMovement(actor.velocity())
, mWaterlevel(waterlevel)
, mHalfExtentsZ(actor.getHalfExtents().z())
, mOldHeight(0) , mOldHeight(0)
, mFallHeight(0) , mFallHeight(0)
, mHalfExtentsZ(actor.getHalfExtents().z()) , mFlying(MWBase::Environment::get().getWorld()->isFlying(actor.getPtr()))
, mMovement(actor.velocity()) , mWasOnGround(actor.getOnGround())
, mPosition() , mIsAquatic(actor.getPtr().getClass().isPureWaterCreature(actor.getPtr()))
, mRotation() , mWaterCollision(waterCollision)
, mSkipCollisionDetection(actor.skipCollisions() || !actor.getCollisionMode())
, mNeedLand(false)
{ {
const MWBase::World *world = MWBase::Environment::get().getWorld();
const auto ptr = actor.getPtr();
mFlying = world->isFlying(ptr);
mIsAquatic = ptr.getClass().isPureWaterCreature(ptr);
const auto& stats = ptr.getClass().getCreatureStats(ptr);
const bool godmode = ptr == world->getPlayerConstPtr() && world->getGodModeState();
mInert = stats.isDead() || (!godmode && stats.getMagicEffects().get(ESM::MagicEffect::Paralyze).getModifier() > 0);
static const float fSwimHeightScale = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fSwimHeightScale")->mValue.getFloat();
mSwimLevel = mWaterlevel - (actor.getRenderingHalfExtents().z() * 2 * fSwimHeightScale);
} }
void ActorFrameData::updatePosition(Actor& actor, btCollisionWorld* world) void ActorFrameData::updatePosition(Actor& actor, btCollisionWorld* world)

View File

@ -78,32 +78,32 @@ namespace MWPhysics
struct ActorFrameData struct ActorFrameData
{ {
ActorFrameData(Actor& actor, bool moveToWaterSurface, float slowFall, float waterlevel); ActorFrameData(Actor& actor, bool inert, bool waterCollision, float slowFall, float waterlevel);
void updatePosition(Actor& actor, btCollisionWorld* world); void updatePosition(Actor& actor, btCollisionWorld* world);
btCollisionObject* mCollisionObject; osg::Vec3f mPosition;
osg::Vec3f mInertia;
const btCollisionObject* mStandingOn; const btCollisionObject* mStandingOn;
bool mFlying;
bool mWasOnGround;
bool mIsOnGround; bool mIsOnGround;
bool mIsOnSlope; bool mIsOnSlope;
bool mInert;
bool mNeedLand;
bool mIsAquatic;
bool mWaterCollision;
bool mWalkingOnWater; bool mWalkingOnWater;
bool mSkipCollisionDetection; const bool mInert;
unsigned int mStuckFrames; btCollisionObject* mCollisionObject;
float mWaterlevel; const float mSwimLevel;
float mSwimLevel; const float mSlowFall;
float mSlowFall; osg::Vec2f mRotation;
osg::Vec3f mMovement;
osg::Vec3f mLastStuckPosition;
const float mWaterlevel;
const float mHalfExtentsZ;
float mOldHeight; float mOldHeight;
float mFallHeight; float mFallHeight;
float mHalfExtentsZ; unsigned int mStuckFrames;
osg::Vec3f mMovement; const bool mFlying;
osg::Vec3f mPosition; const bool mWasOnGround;
osg::Vec2f mRotation; const bool mIsAquatic;
osg::Vec3f mInertia; const bool mWaterCollision;
osg::Vec3f mLastStuckPosition; const bool mSkipCollisionDetection;
bool mNeedLand;
}; };
struct WorldFrameData struct WorldFrameData