Core/Movement: sync spline code with master branch
This commit is contained in:
1 parent
dfa6f7a709
commit
770f9e11db
10 files changed
+143
-138
No files matched your search
@@ -43,21 +43,22 @@ Location MoveSpline::computePosition(int32 time_point, int32 point_index) const
|
||||
else if (splineflags.falling)
|
||||
computeFallElevation(time_point, c.z);
|
||||
|
||||
if (splineflags.done && splineflags.isFacing())
|
||||
if (splineflags.done && facing.type != MONSTER_MOVE_NORMAL)
|
||||
{
|
||||
if (splineflags.final_angle)
|
||||
if (facing.type == MONSTER_MOVE_FACING_ANGLE)
|
||||
c.orientation = facing.angle;
|
||||
else if (splineflags.final_point)
|
||||
else if (facing.type == MONSTER_MOVE_FACING_SPOT)
|
||||
c.orientation = std::atan2(facing.f.y - c.y, facing.f.x - c.x);
|
||||
//nothing to do for MoveSplineFlag::Final_Target flag
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!splineflags.hasFlag(MoveSplineFlag::OrientationFixed | MoveSplineFlag::Falling | MoveSplineFlag::Unknown0))
|
||||
if (!splineflags.hasFlag(MoveSplineFlag::OrientationFixed | MoveSplineFlag::Falling | MoveSplineFlag::Unknown_0x8))
|
||||
{
|
||||
Vector3 hermite;
|
||||
spline.evaluate_derivative(point_Idx, u, hermite);
|
||||
c.orientation = std::atan2(hermite.y, hermite.x);
|
||||
if (hermite.x != 0.f || hermite.y != 0.f)
|
||||
c.orientation = std::atan2(hermite.y, hermite.x);
|
||||
}
|
||||
|
||||
if (splineflags.backward)
|
||||
@@ -186,6 +187,9 @@ void MoveSpline::Initialize(MoveSplineInitArgs const& args)
|
||||
time_passed = 0;
|
||||
vertical_acceleration = 0.f;
|
||||
effect_start_time = 0;
|
||||
anim_tier = args.animTier;
|
||||
splineIsFacingOnly = args.path.size() == 2 && args.facing.type != MONSTER_MOVE_NORMAL && ((args.path[1] - args.path[0]).length() < 0.1f);
|
||||
|
||||
velocity = args.velocity;
|
||||
|
||||
// Check if its a stop spline
|
||||
@@ -201,12 +205,16 @@ void MoveSpline::Initialize(MoveSplineInitArgs const& args)
|
||||
// spline initialized, duration known and i able to compute parabolic acceleration
|
||||
if (args.flags & (MoveSplineFlag::Parabolic | MoveSplineFlag::Animation))
|
||||
{
|
||||
effect_start_time = Duration() * args.time_perc;
|
||||
if (args.flags.parabolic && effect_start_time < Duration())
|
||||
int32 spline_duration = Duration();
|
||||
effect_start_time = spline_duration * args.effect_start_time_percent + args.effect_start_time.count();
|
||||
if (effect_start_time > spline_duration)
|
||||
effect_start_time = spline_duration;
|
||||
|
||||
if (args.flags.parabolic && effect_start_time < spline_duration)
|
||||
{
|
||||
if (args.parabolic_amplitude != 0.0f)
|
||||
{
|
||||
float f_duration = MSToSec(Duration() - effect_start_time);
|
||||
float f_duration = MSToSec(spline_duration - effect_start_time);
|
||||
vertical_acceleration = args.parabolic_amplitude * 8.f / (f_duration * f_duration);
|
||||
}
|
||||
else if (args.vertical_acceleration != 0.0f)
|
||||
@@ -219,14 +227,15 @@ void MoveSpline::Initialize(MoveSplineInitArgs const& args)
|
||||
|
||||
MoveSpline::MoveSpline() : m_Id(0), time_passed(0),
|
||||
vertical_acceleration(0.f), initialOrientation(0.f), effect_start_time(0), point_Idx(0), point_Idx_offset(0), velocity(0.f),
|
||||
onTransport(false)
|
||||
onTransport(false), splineIsFacingOnly(false)
|
||||
{
|
||||
splineflags.done = true;
|
||||
}
|
||||
|
||||
MoveSplineInitArgs::MoveSplineInitArgs(size_t path_capacity /*= 16*/) : path_Idx_offset(0), velocity(0.f),
|
||||
parabolic_amplitude(0.f), vertical_acceleration(0.f), time_perc(0.f), splineId(0), initialOrientation(0.f), walk(false),
|
||||
HasVelocity(false), TransformForTransport(true)
|
||||
parabolic_amplitude(0.f), vertical_acceleration(0.0f), effect_start_time_percent(0.f), effect_start_time(0ms),
|
||||
splineId(0), initialOrientation(0.f),
|
||||
walk(false), HasVelocity(false), TransformForTransport(true)
|
||||
{
|
||||
path.reserve(path_capacity);
|
||||
}
|
||||
@@ -250,35 +259,22 @@ bool MoveSplineInitArgs::Validate(Unit* unit) const
|
||||
}
|
||||
CHECK(path.size() > 1);
|
||||
CHECK(velocity >= 0.01f);
|
||||
CHECK(time_perc >= 0.f && time_perc <= 1.f);
|
||||
//CHECK(_checkPathLengths());
|
||||
CHECK(effect_start_time_percent >= 0.f && effect_start_time_percent <= 1.f);
|
||||
CHECK(_checkPathLengths());
|
||||
return true;
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
// MONSTER_MOVE packet format limitation for not CatmullRom movement:
|
||||
// each vertex offset packed into 11 bytes
|
||||
bool MoveSplineInitArgs::_checkPathBounds() const
|
||||
// check path lengths - why are we even starting such short movement?
|
||||
bool MoveSplineInitArgs::_checkPathLengths() const
|
||||
{
|
||||
if (!(flags & MoveSplineFlag::Catmullrom) && path.size() > 2)
|
||||
{
|
||||
enum{
|
||||
MAX_OFFSET = (1 << 11) / 2
|
||||
};
|
||||
Vector3 middle = (path.front()+path.back()) / 2;
|
||||
Vector3 offset;
|
||||
for (uint32 i = 1; i < path.size()-1; ++i)
|
||||
{
|
||||
offset = path[i] - middle;
|
||||
if (std::fabs(offset.x) >= float(MAX_OFFSET) || std::fabs(offset.y) >= float(MAX_OFFSET) || std::fabs(offset.z) >= float(MAX_OFFSET))
|
||||
{
|
||||
TC_LOG_ERROR("misc", "MoveSplineInitArgs::_checkPathBounds check failed");
|
||||
if (path.size() > 2 || facing.type == MONSTER_MOVE_NORMAL)
|
||||
for (uint32 i = 0; i < path.size() - 1; ++i)
|
||||
if ((path[i + 1] - path[i]).length() < 0.1f)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// ============================================================================================
|
||||
|
||||
MoveSpline::UpdateResult MoveSpline::_updateState(int32& ms_time_diff)
|
||||
@@ -365,11 +361,11 @@ std::string MoveSpline::ToString() const
|
||||
str << "MoveSpline" << std::endl;
|
||||
str << "spline Id: " << GetId() << std::endl;
|
||||
str << "flags: " << splineflags.ToString() << std::endl;
|
||||
if (splineflags.final_angle)
|
||||
if (facing.type == MONSTER_MOVE_FACING_ANGLE)
|
||||
str << "facing angle: " << facing.angle;
|
||||
else if (splineflags.final_target)
|
||||
else if (facing.type == MONSTER_MOVE_FACING_TARGET)
|
||||
str << "facing target: " << facing.target.ToString();
|
||||
else if (splineflags.final_point)
|
||||
else if (facing.type == MONSTER_MOVE_FACING_SPOT)
|
||||
str << "facing point: " << facing.f.x << " " << facing.f.y << " " << facing.f.z;
|
||||
str << std::endl;
|
||||
str << "time passed: " << time_passed << std::endl;
|
||||
|
||||
Reference in new issue
Block a user