Merge branch 'master' into physics3d-material

This commit is contained in:
Lynix
2018-02-11 14:39:14 +01:00
19 changed files with 352 additions and 96 deletions

View File

@@ -67,7 +67,7 @@ namespace Nz
*/
float Clock::GetSeconds() const
{
return GetMicroseconds()/1000000.f;
return GetMicroseconds()/1'000'000.f;
}
/*!
@@ -132,15 +132,26 @@ namespace Nz
/*!
* \brief Restart the clock
* \return Microseconds elapsed
*
* Restarts the clock, putting it's time counter back to zero (as if the clock got constructed).
* It also compute the elapsed microseconds since the last Restart() call without any time loss (a problem that the combination of GetElapsedMicroseconds and Restart have).
*/
void Clock::Restart()
UInt64 Clock::Restart()
{
NazaraLock(m_mutex);
Nz::UInt64 now = GetElapsedMicroseconds();
Nz::UInt64 elapsedTime = m_elapsedTime;
if (!m_paused)
elapsedTime += (now - m_refTime);
m_elapsedTime = 0;
m_refTime = GetElapsedMicroseconds();
m_refTime = now;
m_paused = false;
return elapsedTime;
}
/*!

View File

@@ -80,6 +80,7 @@ namespace Nz
}
PhysWorld2D::PhysWorld2D() :
m_maxStepCount(50),
m_stepSize(0.005f),
m_timestepAccumulator(0.f)
{
@@ -144,6 +145,16 @@ namespace Nz
return m_handle;
}
std::size_t PhysWorld2D::GetIterationCount() const
{
return cpSpaceGetIterations(m_handle);
}
std::size_t PhysWorld2D::GetMaxStepCount() const
{
return m_maxStepCount;
}
float PhysWorld2D::GetStepSize() const
{
return m_stepSize;
@@ -281,6 +292,16 @@ namespace Nz
cpSpaceSetGravity(m_handle, cpv(gravity.x, gravity.y));
}
void PhysWorld2D::SetIterationCount(std::size_t iterationCount)
{
cpSpaceSetIterations(m_handle, int(iterationCount));
}
void PhysWorld2D::SetMaxStepCount(std::size_t maxStepCount)
{
m_maxStepCount = maxStepCount;
}
void PhysWorld2D::SetStepSize(float stepSize)
{
m_stepSize = stepSize;
@@ -290,7 +311,8 @@ namespace Nz
{
m_timestepAccumulator += timestep;
while (m_timestepAccumulator >= m_stepSize)
std::size_t stepCount = 0;
while (m_timestepAccumulator >= m_stepSize && stepCount < m_maxStepCount)
{
OnPhysWorld2DPreStep(this);
@@ -309,9 +331,15 @@ namespace Nz
}
m_timestepAccumulator -= m_stepSize;
stepCount++;
}
}
void PhysWorld2D::UseSpatialHash(float cellSize, std::size_t entityCount)
{
cpSpaceUseSpatialHash(m_handle, cpFloat(cellSize), int(entityCount));
}
void PhysWorld2D::InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks)
{
auto it = m_callbacks.emplace(handler, std::make_unique<Callback>(callbacks)).first;

View File

@@ -12,6 +12,7 @@ namespace Nz
{
PhysWorld3D::PhysWorld3D() :
m_gravity(Vector3f::Zero()),
m_maxStepCount(50),
m_stepSize(0.005f),
m_timestepAccumulator(0.f)
{
@@ -66,6 +67,11 @@ namespace Nz
return it->second;
}
std::size_t PhysWorld3D::GetMaxStepCount() const
{
return m_maxStepCount;
}
float PhysWorld3D::GetStepSize() const
{
return m_stepSize;
@@ -76,6 +82,11 @@ namespace Nz
m_gravity = gravity;
}
void PhysWorld3D::SetMaxStepCount(std::size_t maxStepCount)
{
m_maxStepCount = maxStepCount;
}
void PhysWorld3D::SetSolverModel(unsigned int model)
{
NewtonSetSolverModel(m_world, model);
@@ -132,10 +143,12 @@ namespace Nz
{
m_timestepAccumulator += timestep;
while (m_timestepAccumulator >= m_stepSize)
std::size_t stepCount = 0;
while (m_timestepAccumulator >= m_stepSize && stepCount < m_maxStepCount)
{
NewtonUpdate(m_world, m_stepSize);
m_timestepAccumulator -= m_stepSize;
stepCount++;
}
}