From 2a9664d6ca8aa9eb4f554301e4d9b0ec33b465ce Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 11 Jan 2015 21:12:26 +0000 Subject: Initial convertion of a_Dt to std::chrono also refactored cWorld::m_WorldAge and cWorld::m_TimeOfDay --- src/Entities/Entity.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 54b9f2a20..c64d94528 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -772,7 +772,7 @@ void cEntity::SetHealth(int a_Health) -void cEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { m_TicksAlive++; @@ -841,7 +841,7 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) -void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { int BlockX = POSX_TOINT; int BlockY = POSY_TOINT; @@ -851,15 +851,15 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, BlockX, BlockZ) // TODO Add collision detection with entities. - a_Dt /= 1000; // Convert from msec to sec + auto DtSec = std::chrono::duration_cast>(a_Dt); Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ()); if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { // Outside of the world - AddSpeedY(m_Gravity * a_Dt); - AddPosition(GetSpeed() * a_Dt); + AddSpeedY(m_Gravity * DtSec.count()); + AddPosition(GetSpeed() * DtSec.count()); return; } @@ -930,8 +930,8 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) float fallspeed; if (IsBlockWater(BlockIn)) { - fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water - ApplyFriction(NextSpeed, 0.7, a_Dt); + fallspeed = m_Gravity * DtSec.count() / 3; // Fall 3x slower in water + ApplyFriction(NextSpeed, 0.7, DtSec.count()); } else if (BlockIn == E_BLOCK_COBWEB) { @@ -941,13 +941,13 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) else { // Normal gravity - fallspeed = m_Gravity * a_Dt; + fallspeed = m_Gravity * DtSec.count(); } NextSpeed.y += fallspeed; } else { - ApplyFriction(NextSpeed, 0.7, a_Dt); + ApplyFriction(NextSpeed, 0.7, DtSec.count()); } // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we @@ -1002,14 +1002,14 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { cTracer Tracer(GetWorld()); // Distance traced is an integer, so we round up from the distance we should go (Speed * Delta), else we will encounter collision detection failurse - int DistanceToTrace = (int)(ceil((NextSpeed * a_Dt).SqrLength()) * 2); + int DistanceToTrace = (int)(ceil((NextSpeed * DtSec.count()).SqrLength()) * 2); bool HasHit = Tracer.Trace(NextPos, NextSpeed, DistanceToTrace); if (HasHit) { // Oh noez! We hit something: verify that the (hit position - current) was smaller or equal to the (position that we should travel without obstacles - current) // This is because previously, we traced with a length that was rounded up (due to integer limitations), and in the case that something was hit, we don't want to overshoot our projected movement - if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength()) + if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * DtSec.count()).SqrLength()) { // Block hit was within our projected path // Begin by stopping movement in the direction that we hit something. The Normal is the line perpendicular to a 2D face and in this case, stores what block face was hit through either -1 or 1. @@ -1044,13 +1044,13 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) // and that this piece of software will come to be hailed as the epitome of performance and functionality in C++, never before seen, and of such a like that will never // be henceforth seen again in the time of programmers and man alike // - NextPos += (NextSpeed * a_Dt); + NextPos += (NextSpeed * DtSec.count()); } } else { // We didn't hit anything, so move =] - NextPos += (NextSpeed * a_Dt); + NextPos += (NextSpeed * DtSec.count()); } } -- cgit v1.2.3 From e211aafaa45b0e4a12e9c50ee445377077ea8172 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 18 Jan 2015 11:02:17 +0100 Subject: Fixed type-conversion warnings. --- src/Entities/Entity.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c64d94528..c51a27961 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -927,11 +927,11 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (!m_bOnGround) { - float fallspeed; + double fallspeed; if (IsBlockWater(BlockIn)) { fallspeed = m_Gravity * DtSec.count() / 3; // Fall 3x slower in water - ApplyFriction(NextSpeed, 0.7, DtSec.count()); + ApplyFriction(NextSpeed, 0.7, static_cast(DtSec.count())); } else if (BlockIn == E_BLOCK_COBWEB) { @@ -943,11 +943,11 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) // Normal gravity fallspeed = m_Gravity * DtSec.count(); } - NextSpeed.y += fallspeed; + NextSpeed.y += static_cast(fallspeed); } else { - ApplyFriction(NextSpeed, 0.7, DtSec.count()); + ApplyFriction(NextSpeed, 0.7, static_cast(DtSec.count())); } // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we -- cgit v1.2.3