|
@@ -326,146 +326,40 @@ void Entity::prepareTick(const Dimension* zDimension)
|
|
|
|
|
|
void Entity::tick(const Dimension* zDimension)
|
|
|
{
|
|
|
- /*
|
|
|
- Vec3<float> oldPos = location;
|
|
|
- // current block cooredinates
|
|
|
- int px = (int)floor(location.x);
|
|
|
- int py = (int)floor(location.y);
|
|
|
- int pz = (int)floor(location.z);
|
|
|
- // falling down
|
|
|
- speed.z -= (zDimension->getGravity() * gravityMultiplier) * time;
|
|
|
- // movement in current tick
|
|
|
- Vec3<float> frameSpeed = speed * time;
|
|
|
- // loop through all collided blocks
|
|
|
- bool hasCollided = 0;
|
|
|
- bool needCollisionCheck = 1;
|
|
|
- while (needCollisionCheck)
|
|
|
+ if (time.isMeasuring())
|
|
|
{
|
|
|
- needCollisionCheck = 0;
|
|
|
- // collision to neighbor of current block
|
|
|
- if (speed.x > 0)
|
|
|
- {
|
|
|
- float xt = ((float)px + 1.f - oldPos.x) / frameSpeed.x;
|
|
|
- Vec3<float> tmp = oldPos + frameSpeed * 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 (!getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{ px + 1, py, pz }, zDimension->getDimensionId()))->isPassable())
|
|
|
- {
|
|
|
- frameSpeed.x = frameSpeed.x * (xt - 0.1f);
|
|
|
- speed.x = 0;
|
|
|
- hasCollided = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- px++;
|
|
|
- needCollisionCheck = 1;
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (speed.x < 0)
|
|
|
- {
|
|
|
- float xt = ((float)px - oldPos.x) / frameSpeed.x;
|
|
|
- Vec3<float> tmp = oldPos + frameSpeed * 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 (!getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{ px - 1, py, pz }, zDimension->getDimensionId()))->isPassable())
|
|
|
- {
|
|
|
- frameSpeed.x = frameSpeed.x * (xt - 0.1f);
|
|
|
- speed.x = 0;
|
|
|
- hasCollided = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- px--;
|
|
|
- needCollisionCheck = 1;
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (speed.y > 0)
|
|
|
- {
|
|
|
- float yt = ((float)py + 1.f - oldPos.y) / frameSpeed.y;
|
|
|
- Vec3<float> tmp = oldPos + frameSpeed * 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 (!getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{ px, py + 1, pz }, zDimension->getDimensionId()))->isPassable())
|
|
|
- {
|
|
|
- frameSpeed.y = frameSpeed.y * (yt - 0.1f);
|
|
|
- speed.y = 0;
|
|
|
- hasCollided = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- py++;
|
|
|
- needCollisionCheck = 1;
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (speed.y < 0)
|
|
|
- {
|
|
|
- float yt = ((float)py - oldPos.y) / frameSpeed.y;
|
|
|
- Vec3<float> tmp = oldPos + frameSpeed * 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 (!getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{ px, py - 1, pz }, zDimension->getDimensionId()))->isPassable())
|
|
|
- {
|
|
|
- frameSpeed.y = frameSpeed.y * (yt - 0.1f);
|
|
|
- speed.y = 0;
|
|
|
- hasCollided = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- py--;
|
|
|
- needCollisionCheck = 1;
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (speed.z > 0)
|
|
|
+ time.messungEnde();
|
|
|
+ if (movements.getEintragAnzahl() > 0)
|
|
|
{
|
|
|
- float zt = ((float)pz + 1.f - oldPos.z) / frameSpeed.z;
|
|
|
- Vec3<float> tmp = oldPos + frameSpeed * 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)
|
|
|
+ MovementFrame currentFrame = movements.get(0);
|
|
|
+ double seconds = time.getSekunden();
|
|
|
+ while (seconds > 0)
|
|
|
{
|
|
|
- if (!getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{ px, py, pz + 1 }, zDimension->getDimensionId()))->isPassable())
|
|
|
+ if (currentFrame.duration <= 0)
|
|
|
{
|
|
|
- frameSpeed.z = frameSpeed.z * (zt - 0.1f);
|
|
|
- speed.z = 0;
|
|
|
- hasCollided = 1;
|
|
|
+ cs.lock();
|
|
|
+ movements.remove(0);
|
|
|
+ cs.unlock();
|
|
|
+ if (movements.getEintragAnzahl() > 0)
|
|
|
+ currentFrame = movements.get(0);
|
|
|
+ else
|
|
|
+ break;
|
|
|
}
|
|
|
- else
|
|
|
- pz++;
|
|
|
- needCollisionCheck = 1;
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (speed.z < 0)
|
|
|
- {
|
|
|
- float zt = ((float)pz - oldPos.z) / frameSpeed.z;
|
|
|
- Vec3<float> tmp = oldPos + frameSpeed * 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 (!getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{ px, py, pz - 1 }, zDimension->getDimensionId()))->isPassable())
|
|
|
+ double t = MIN(currentFrame.duration, seconds);
|
|
|
+ // TODO: add collisin detection to reduce cheating capability
|
|
|
+ location += (currentFrame.targetPosition - location) * (float)(t / currentFrame.duration);
|
|
|
+ currentFrame.duration -= t;
|
|
|
+ seconds -= t;
|
|
|
+ if (currentFrame.duration <= 0)
|
|
|
{
|
|
|
- frameSpeed.z = frameSpeed.z * (zt - 0.1f);
|
|
|
- onFall(speed.z);
|
|
|
- speed.z = 0;
|
|
|
- hasCollided = 1;
|
|
|
+ location = currentFrame.targetPosition;
|
|
|
}
|
|
|
- else
|
|
|
- pz--;
|
|
|
- needCollisionCheck = 1;
|
|
|
- continue;
|
|
|
}
|
|
|
+ if (currentFrame.duration > 0)
|
|
|
+ movements.set(currentFrame, 0);
|
|
|
}
|
|
|
}
|
|
|
- location += frameSpeed;
|
|
|
- if (hasCollided)
|
|
|
- {
|
|
|
- NetworkMessage changeMsg;
|
|
|
- changeMsg.addressEntity(this);
|
|
|
- char msg[13];
|
|
|
- msg[0] = 1; // position correction
|
|
|
- *(float*)(msg + 1) = this->location.x;
|
|
|
- *(float*)(msg + 5) = this->location.y;
|
|
|
- *(float*)(msg + 9) = this->location.z;
|
|
|
- changeMsg.setMessage(msg, 13, 0);
|
|
|
- Game::INSTANCE->sendMessage(&changeMsg, this);
|
|
|
- }*/
|
|
|
+ time.messungStart();
|
|
|
}
|
|
|
|
|
|
void Entity::api(Framework::StreamReader* zRequest, NetworkMessage* zResponse)
|