From 96ef6084aedb24821a584bb864f704c98915bf2e Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Mon, 4 Nov 2013 17:14:49 -0700 Subject: Flowers, mushrooms and air are no longer collidable. --- source/Tracer.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source/Tracer.cpp') diff --git a/source/Tracer.cpp b/source/Tracer.cpp index 42f1ae5dd..675905b11 100644 --- a/source/Tracer.cpp +++ b/source/Tracer.cpp @@ -225,15 +225,24 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); // No collision with water ;) - if ((BlockID != E_BLOCK_AIR) || IsBlockWater(BlockID)) // _X 2013_03_29: Why is the IsBlockWater condition here? water equals air? + switch(BlockID) { - BlockHitPosition = pos; - int Normal = GetHitNormal(a_Start, End, pos ); - if(Normal > 0) + case E_BLOCK_AIR: + case E_BLOCK_YELLOW_FLOWER: + case E_BLOCK_RED_ROSE: + case E_BLOCK_RED_MUSHROOM: + case E_BLOCK_BROWN_MUSHROOM: + break; + default: { - HitNormal = m_NormalTable[Normal-1]; + BlockHitPosition = pos; + int Normal = GetHitNormal(a_Start, End, pos ); + if(Normal > 0) + { + HitNormal = m_NormalTable[Normal-1]; + } + return true; } - return 1; } } return 0; -- cgit v1.2.3 From b23047f47b19722354ce6fcb4fa671dd7e3528f2 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Mon, 4 Nov 2013 20:10:29 -0700 Subject: Reworked collision to use g_BlockIsSolid --- source/Tracer.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'source/Tracer.cpp') diff --git a/source/Tracer.cpp b/source/Tracer.cpp index 675905b11..d7a613891 100644 --- a/source/Tracer.cpp +++ b/source/Tracer.cpp @@ -225,24 +225,15 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); // No collision with water ;) - switch(BlockID) + if (g_BlockIsSolid[BlockID]) { - case E_BLOCK_AIR: - case E_BLOCK_YELLOW_FLOWER: - case E_BLOCK_RED_ROSE: - case E_BLOCK_RED_MUSHROOM: - case E_BLOCK_BROWN_MUSHROOM: - break; - default: + BlockHitPosition = pos; + int Normal = GetHitNormal(a_Start, End, pos ); + if(Normal > 0) { - BlockHitPosition = pos; - int Normal = GetHitNormal(a_Start, End, pos ); - if(Normal > 0) - { - HitNormal = m_NormalTable[Normal-1]; - } - return true; + HitNormal = m_NormalTable[Normal-1]; } + return true; } } return 0; -- cgit v1.2.3 From 9d5d74d826ceaa227c3d1684dde0743c08ae1175 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 5 Nov 2013 14:01:51 -0700 Subject: Added more documentation. Changed cTracer::Trace to return a bool instead of an int because it was only returning 1 or 0 anyways. --- source/Tracer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/Tracer.cpp') diff --git a/source/Tracer.cpp b/source/Tracer.cpp index d7a613891..4d036486e 100644 --- a/source/Tracer.cpp +++ b/source/Tracer.cpp @@ -131,12 +131,12 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction) -int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance) +bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance) { if ((a_Start.y < 0) || (a_Start.y >= cChunkDef::Height)) { LOGD("%s: Start Y is outside the world (%.2f), not tracing.", __FUNCTION__, a_Start.y); - return 0; + return false; } SetValues(a_Start, a_Direction); @@ -157,7 +157,7 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int // check if first is occupied if (pos.Equals(end1)) { - return 0; + return false; } bool reachedX = false, reachedY = false, reachedZ = false; @@ -236,7 +236,7 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int return true; } } - return 0; + return false; } -- cgit v1.2.3 From eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 5 Nov 2013 14:11:13 -0700 Subject: cTracer can now handle mob sight. --- source/Tracer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source/Tracer.cpp') diff --git a/source/Tracer.cpp b/source/Tracer.cpp index 4d036486e..bad1604d7 100644 --- a/source/Tracer.cpp +++ b/source/Tracer.cpp @@ -131,7 +131,7 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction) -bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance) +bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight) { if ((a_Start.y < 0) || (a_Start.y >= cChunkDef::Height)) { @@ -224,8 +224,9 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int } BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); - // No collision with water ;) - if (g_BlockIsSolid[BlockID]) + // Block is counted as a collision if we are not doing a line of sight and it is solid, + // or if the block is not air and not water. That way mobs can still see underwater. + if ((!a_LineOfSight && g_BlockIsSolid[BlockID]) || (BlockID != E_BLOCK_AIR && !IsBlockWater(BlockID))) { BlockHitPosition = pos; int Normal = GetHitNormal(a_Start, End, pos ); -- cgit v1.2.3 From 5d353fd8f82f93ba881e2f770ab65682dcfe9286 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 5 Nov 2013 14:13:12 -0700 Subject: Added missing check for a_LineOfSight --- source/Tracer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Tracer.cpp') diff --git a/source/Tracer.cpp b/source/Tracer.cpp index bad1604d7..ef136302f 100644 --- a/source/Tracer.cpp +++ b/source/Tracer.cpp @@ -226,7 +226,7 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); // Block is counted as a collision if we are not doing a line of sight and it is solid, // or if the block is not air and not water. That way mobs can still see underwater. - if ((!a_LineOfSight && g_BlockIsSolid[BlockID]) || (BlockID != E_BLOCK_AIR && !IsBlockWater(BlockID))) + if ((!a_LineOfSight && g_BlockIsSolid[BlockID]) || (a_LineOfSight && (BlockID != E_BLOCK_AIR) && !IsBlockWater(BlockID))) { BlockHitPosition = pos; int Normal = GetHitNormal(a_Start, End, pos ); -- cgit v1.2.3