Physics2D/PhysWorld2D: Add invStepCount argument to pre/post steps callbacks

This commit is contained in:
Jérôme Leclercq 2018-04-30 14:55:28 +02:00
parent d1a969288f
commit 95f137816a
3 changed files with 8 additions and 7 deletions

View File

@ -94,6 +94,7 @@ Nazara Engine:
- ⚠️ Stream::ReadLine will now returns empty lines if present in the file
- Fixed cubemaps seams with OpenGL
- HandledObject movement constructor/assignement operator are now marked noexcept
- ⚠️ PhysWorld2D callbacks OnPhysWorld2DPreStep and OnPhysWorld2DPostStep now takes a invStepCount depending on the number of step taken this update, fixing force application and other
Nazara Development Kit:
- Added ImageWidget (#139)

View File

@ -123,8 +123,8 @@ namespace Nz
float fraction;
};
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/);
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/);
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
private:
void InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks);

View File

@ -311,14 +311,15 @@ namespace Nz
{
m_timestepAccumulator += timestep;
std::size_t stepCount = 0;
while (m_timestepAccumulator >= m_stepSize && stepCount < m_maxStepCount)
std::size_t stepCount = std::min(static_cast<std::size_t>(m_timestepAccumulator / m_stepSize), m_maxStepCount);
float invStepCount = 1.f / stepCount;
for (std::size_t i = 0; i < stepCount; ++i)
{
OnPhysWorld2DPreStep(this);
OnPhysWorld2DPreStep(this, invStepCount);
cpSpaceStep(m_handle, m_stepSize);
OnPhysWorld2DPostStep(this);
OnPhysWorld2DPostStep(this, invStepCount);
if (!m_rigidPostSteps.empty())
{
for (const auto& pair : m_rigidPostSteps)
@ -331,7 +332,6 @@ namespace Nz
}
m_timestepAccumulator -= m_stepSize;
stepCount++;
}
}