1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-29 12:20:41 +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();
auto it = actor.movement().begin();
while (it != actor.movement().end())
{
if (it->jump)
{
// Adjusting inertia is instant and should not be performed over time like other movement is.
it++;
continue;
}
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++;
}
std::erase_if(actor.movement(), [&](MWPhysics::Movement& v) {
if (v.mJump)
return false;
float start = std::max(v.mSimulationTimeStart, startTime);
float stop = std::min(v.mSimulationTimeStop, endTime);
movement += v.mVelocity * (stop - start);
if (std::abs(stop - v.mSimulationTimeStop) < 0.0001f)
return true;
return false;
});
return movement;
}
@ -232,17 +225,14 @@ namespace
std::optional<osg::Vec3f> takeInertia(MWPhysics::PtrHolder& actor, float startTime) const
{
std::optional<osg::Vec3f> inertia = std::nullopt;
auto it = actor.movement().begin();
while (it != actor.movement().end())
{
if (it->jump && it->simulationTimeStart >= startTime)
std::erase_if(actor.movement(), [&](MWPhysics::Movement& v) {
if (v.mJump && v.mSimulationTimeStart >= startTime)
{
inertia = it->velocity;
it = actor.movement().erase(it);
inertia = v.mVelocity;
return true;
}
else
it++;
}
return false;
});
return inertia;
}

View File

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