|
@@ -119,32 +119,24 @@ void Entity::prepareTick( const Dimension* zDimension, Game* zGame )
|
|
|
int py = (int)floor( headPosition.y );
|
|
|
int pz = (int)floor( headPosition.z );
|
|
|
faceDir.normalize();
|
|
|
- bool needCollisionCheck = 1;
|
|
|
- while( needCollisionCheck )
|
|
|
+ Direction dir = BOTTOM;
|
|
|
+ while( true )
|
|
|
{
|
|
|
if( getDefaultBlock( zGame->zBlockAt( Vec3<int>{ px, py, pz }, zDimension->getDimensionId() ) )->isInteractable() )
|
|
|
{
|
|
|
delete target;
|
|
|
- target = new ActionTarget( { px, py, pz }, BOTTOM );
|
|
|
+ target = new ActionTarget( { px, py, pz }, dir );
|
|
|
break;
|
|
|
}
|
|
|
- needCollisionCheck = 0;
|
|
|
- // collision to neighbor of current block current block
|
|
|
+ // collision to neighbor of current block
|
|
|
if( faceDir.x > 0 )
|
|
|
{
|
|
|
float xt = ((float)px + 1.f - headPosition.x) / faceDir.x;
|
|
|
Vec3<float> tmp = headPosition + faceDir * xt;
|
|
|
if( xt <= targetDistanceLimit && tmp.y >= (float)py && tmp.y < (float)py + 1.f && tmp.z >= (float)pz && tmp.z < (float)pz + 1.f )
|
|
|
{
|
|
|
- if( !getDefaultBlock( zGame->zBlockAt( Vec3<int>{ px + 1, py, pz }, zDimension->getDimensionId() ) )->isInteractable() )
|
|
|
- {
|
|
|
- delete target;
|
|
|
- target = new ActionTarget( { px, py, pz }, WEST );
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- px++;
|
|
|
- needCollisionCheck = 1;
|
|
|
+ dir = WEST;
|
|
|
+ px++;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
@@ -152,92 +144,60 @@ void Entity::prepareTick( const Dimension* zDimension, Game* zGame )
|
|
|
{
|
|
|
float xt = ((float)px - headPosition.x) / faceDir.x;
|
|
|
Vec3<float> tmp = headPosition + faceDir * xt;
|
|
|
- if( xt <= 1.f && tmp.y >= (float)py && tmp.y < (float)py + 1.f && tmp.z >= (float)pz && tmp.z < (float)pz + 1.f )
|
|
|
+ if( xt <= targetDistanceLimit && tmp.y >= (float)py && tmp.y < (float)py + 1.f && tmp.z >= (float)pz && tmp.z < (float)pz + 1.f )
|
|
|
{
|
|
|
- if( !getDefaultBlock( zGame->zBlockAt( Vec3<int>{ px - 1, py, pz }, zDimension->getDimensionId() ) )->isPassable() )
|
|
|
- {
|
|
|
- delete target;
|
|
|
- target = new ActionTarget( { px, py, pz }, EAST );
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- px--;
|
|
|
- needCollisionCheck = 1;
|
|
|
+ dir = EAST;
|
|
|
+ px--;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if( speed.y > 0 )
|
|
|
+ if( faceDir.y > 0 )
|
|
|
{
|
|
|
float yt = ((float)py + 1.f - headPosition.y) / faceDir.y;
|
|
|
Vec3<float> tmp = headPosition + faceDir * yt;
|
|
|
- if( yt <= 1.f && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.z >= (float)pz && tmp.z < (float)pz + 1.f )
|
|
|
+ if( yt <= targetDistanceLimit && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.z >= (float)pz && tmp.z < (float)pz + 1.f )
|
|
|
{
|
|
|
- if( !getDefaultBlock( zGame->zBlockAt( Vec3<int>{ px, py + 1, pz }, zDimension->getDimensionId() ) )->isPassable() )
|
|
|
- {
|
|
|
- delete target;
|
|
|
- target = new ActionTarget( { px, py, pz }, NORTH );
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- py++;
|
|
|
- needCollisionCheck = 1;
|
|
|
+ dir = NORTH;
|
|
|
+ py++;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if( speed.y < 0 )
|
|
|
+ if( faceDir.y < 0 )
|
|
|
{
|
|
|
float yt = ((float)py - headPosition.y) / faceDir.y;
|
|
|
Vec3<float> tmp = headPosition + faceDir * yt;
|
|
|
- if( yt <= 1.f && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.z >= (float)pz && tmp.z < (float)pz + 1.f )
|
|
|
+ if( yt <= targetDistanceLimit && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.z >= (float)pz && tmp.z < (float)pz + 1.f )
|
|
|
{
|
|
|
- if( !getDefaultBlock( zGame->zBlockAt( Vec3<int>{ px, py - 1, pz }, zDimension->getDimensionId() ) )->isPassable() )
|
|
|
- {
|
|
|
- delete target;
|
|
|
- target = new ActionTarget( { px, py, pz }, SOUTH );
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- py--;
|
|
|
- needCollisionCheck = 1;
|
|
|
+ dir = SOUTH;
|
|
|
+ py--;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if( speed.z > 0 )
|
|
|
+ if( faceDir.z > 0 )
|
|
|
{
|
|
|
float zt = ((float)pz + 1.f - headPosition.z) / faceDir.z;
|
|
|
Vec3<float> tmp = headPosition + faceDir * zt;
|
|
|
- if( zt <= 1.f && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.y >= (float)py && tmp.y < (float)py + 1.f )
|
|
|
+ if( zt <= targetDistanceLimit && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.y >= (float)py && tmp.y < (float)py + 1.f )
|
|
|
{
|
|
|
- if( !getDefaultBlock( zGame->zBlockAt( Vec3<int>{ px, py, pz + 1 }, zDimension->getDimensionId() ) )->isPassable() )
|
|
|
- {
|
|
|
- delete target;
|
|
|
- target = new ActionTarget( { px, py, pz }, BOTTOM );
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- pz++;
|
|
|
- needCollisionCheck = 1;
|
|
|
+ dir = BOTTOM;
|
|
|
+ pz++;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if( speed.z < 0 )
|
|
|
+ if( faceDir.z < 0 )
|
|
|
{
|
|
|
float zt = ((float)pz - headPosition.z) / faceDir.z;
|
|
|
Vec3<float> tmp = headPosition + faceDir * zt;
|
|
|
- if( zt <= 1.f && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.y >= (float)py && tmp.y < (float)py + 1 )
|
|
|
+ if( zt <= targetDistanceLimit && tmp.x >= (float)px && tmp.x < (float)px + 1.f && tmp.y >= (float)py && tmp.y < (float)py + 1 )
|
|
|
{
|
|
|
- if( !getDefaultBlock( zGame->zBlockAt( Vec3<int>{ px, py, pz - 1 }, zDimension->getDimensionId() ) )->isPassable() )
|
|
|
- {
|
|
|
- delete target;
|
|
|
- target = new ActionTarget( { px, py, pz }, TOP );
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- pz--;
|
|
|
- needCollisionCheck = 1;
|
|
|
+ dir = TOP;
|
|
|
+ pz--;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
+ delete target;
|
|
|
+ target = 0;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -257,7 +217,7 @@ void Entity::tick( const Dimension* zDimension, Game* zGame )
|
|
|
while( needCollisionCheck )
|
|
|
{
|
|
|
needCollisionCheck = 0;
|
|
|
- // collision to neighbor of current block current block
|
|
|
+ // collision to neighbor of current block
|
|
|
if( speed.x > 0 )
|
|
|
{
|
|
|
float xt = ((float)px + 1.f - oldPos.x) / frameSpeed.x;
|