1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-17 01:10:10 +00:00
This commit is contained in:
Mads Buvik Sandvei 2023-12-18 22:28:38 +01:00
parent 76232c49df
commit 5a6dbf8714
2 changed files with 23 additions and 33 deletions

View File

@ -208,23 +208,16 @@ namespace
{ {
osg::Vec3f movement = osg::Vec3f(); osg::Vec3f movement = osg::Vec3f();
auto it = actor.movement().begin(); auto it = actor.movement().begin();
while (it != actor.movement().end()) std::erase_if(actor.movement(), [&](MWPhysics::Movement& v) {
{ if (v.mJump)
if (it->jump) return false;
{ float start = std::max(v.mSimulationTimeStart, startTime);
// Adjusting inertia is instant and should not be performed over time like other movement is. float stop = std::min(v.mSimulationTimeStop, endTime);
it++; movement += v.mVelocity * (stop - start);
continue; if (std::abs(stop - v.mSimulationTimeStop) < 0.0001f)
} return true;
return false;
float start = std::max(it->simulationTimeStart, startTime); });
float stop = std::min(it->simulationTimeStop, endTime);
movement += it->velocity * (stop - start);
if (std::abs(stop - it->simulationTimeStop) < 0.0001f)
it = actor.movement().erase(it);
else
it++;
}
return movement; return movement;
} }
@ -232,17 +225,14 @@ namespace
std::optional<osg::Vec3f> takeInertia(MWPhysics::PtrHolder& actor, float startTime) const std::optional<osg::Vec3f> takeInertia(MWPhysics::PtrHolder& actor, float startTime) const
{ {
std::optional<osg::Vec3f> inertia = std::nullopt; std::optional<osg::Vec3f> inertia = std::nullopt;
auto it = actor.movement().begin(); std::erase_if(actor.movement(), [&](MWPhysics::Movement& v) {
while (it != actor.movement().end()) if (v.mJump && v.mSimulationTimeStart >= startTime)
{ {
if (it->jump && it->simulationTimeStart >= startTime) inertia = v.mVelocity;
{ return true;
inertia = it->velocity;
it = actor.movement().erase(it);
}
else
it++;
} }
return false;
});
return inertia; return inertia;
} }

View File

@ -1,7 +1,7 @@
#ifndef OPENMW_MWPHYSICS_PTRHOLDER_H #ifndef OPENMW_MWPHYSICS_PTRHOLDER_H
#define OPENMW_MWPHYSICS_PTRHOLDER_H #define OPENMW_MWPHYSICS_PTRHOLDER_H
#include <deque> #include <list>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <utility> #include <utility>
@ -16,10 +16,10 @@ namespace MWPhysics
{ {
struct Movement struct Movement
{ {
osg::Vec3f velocity = osg::Vec3f(); osg::Vec3f mVelocity = osg::Vec3f();
float simulationTimeStart = 0.f; // The time at which this movement begun float mSimulationTimeStart = 0.f; // The time at which this movement begun
float simulationTimeStop = 0.f; // The time at which this movement finished float mSimulationTimeStop = 0.f; // The time at which this movement finished
bool jump = false; bool mJump = false;
}; };
class PtrHolder class PtrHolder
@ -47,7 +47,7 @@ namespace MWPhysics
mMovement.push_back(Movement{ velocity, simulationTimeStart, simulationTimeStop, jump }); mMovement.push_back(Movement{ velocity, simulationTimeStart, simulationTimeStop, jump });
} }
std::deque<Movement>& movement() { return mMovement; } std::list<Movement>& movement() { return mMovement; }
void setSimulationPosition(const osg::Vec3f& position) { mSimulationPosition = position; } void setSimulationPosition(const osg::Vec3f& position) { mSimulationPosition = position; }
@ -66,7 +66,7 @@ namespace MWPhysics
protected: protected:
MWWorld::Ptr mPtr; MWWorld::Ptr mPtr;
std::unique_ptr<btCollisionObject> mCollisionObject; std::unique_ptr<btCollisionObject> mCollisionObject;
std::deque<Movement> mMovement; std::list<Movement> mMovement;
osg::Vec3f mSimulationPosition; osg::Vec3f mSimulationPosition;
osg::Vec3d mPosition; osg::Vec3d mPosition;
osg::Vec3d mPreviousPosition; osg::Vec3d mPreviousPosition;