diff --git a/direct/src/deadrec/smoothMover.I b/direct/src/deadrec/smoothMover.I index 0eecb480a8..e1ae2e5214 100644 --- a/direct/src/deadrec/smoothMover.I +++ b/direct/src/deadrec/smoothMover.I @@ -276,9 +276,9 @@ set_timestamp(double timestamp) { // With no parameter, the function uses // ClockObject::get_frame_time() as the default time. //////////////////////////////////////////////////////////////////// -INLINE void SmoothMover:: +INLINE bool SmoothMover:: compute_smooth_position() { - compute_smooth_position(ClockObject::get_global_clock()->get_frame_time()); + return compute_smooth_position(ClockObject::get_global_clock()->get_frame_time()); } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/deadrec/smoothMover.cxx b/direct/src/deadrec/smoothMover.cxx index e084a51db5..92180aff7b 100644 --- a/direct/src/deadrec/smoothMover.cxx +++ b/direct/src/deadrec/smoothMover.cxx @@ -44,6 +44,7 @@ SmoothMover() { _smooth_mat = LMatrix4f::ident_mat(); _smooth_timestamp = 0.0; _smooth_position_known = false; + _smooth_position_changed = true; _computed_smooth_mat = true; _smooth_forward_velocity = 0.0; @@ -170,8 +171,13 @@ clear_positions(bool reset_velocity) { // the previous position reports. After this call has // been made, get_smooth_pos() etc. may be called to // retrieve the smoothed position. +// +// The return value is true if the value has changed (or +// might have changed) since the last call to +// compute_smooth_position(), or false if it remains the +// same. //////////////////////////////////////////////////////////////////// -void SmoothMover:: +bool SmoothMover:: compute_smooth_position(double timestamp) { if (_points.empty()) { // With no position reports available, this function does nothing, @@ -185,14 +191,18 @@ compute_smooth_position(double timestamp) { _smooth_rotational_velocity = 0.0; } } - return; + bool result = _smooth_position_changed; + _smooth_position_changed = false; + return result; } if (_smooth_mode == SM_off) { // With smoothing disabled, this function also does nothing, // except to ensure that any old bogus position reports are // cleared. clear_positions(false); - return; + bool result = _smooth_position_changed; + _smooth_position_changed = false; + return result; } // First, back up in time by the specified delay factor. @@ -226,15 +236,21 @@ compute_smooth_position(double timestamp) { } if (point_before == -1) { - nassertv(point_after != -1); + nassertr(point_after != -1, false); // If we only have an after point, we have to start there. + bool result = !(_last_point_before == point_before && + _last_point_after == point_after); const SamplePoint &point = _points[point_after]; set_smooth_pos(point._pos, point._hpr, timestamp); _smooth_forward_velocity = 0.0; _smooth_rotational_velocity = 0.0; - return; + _last_point_before = point_before; + _last_point_after = point_after; + return result; } + bool result = true; + if (point_after == -1 || timestamp_before == timestamp_after) { // If we only have a before point, we have to stop there, unless // we have prediction in effect. @@ -247,6 +263,11 @@ compute_smooth_position(double timestamp) { _smooth_rotational_velocity = 0.0; } + result = !(_last_point_before == point_before && + _last_point_after == point_after); + _last_point_before = point_before; + _last_point_after = point_after; + } else { // If we have two points, we can linearly interpolate between them. linear_interpolate(point_before, point_after, timestamp); @@ -262,6 +283,8 @@ compute_smooth_position(double timestamp) { _last_point_before = -1; _last_point_after = -1; } + + return result; } //////////////////////////////////////////////////////////////////// @@ -328,6 +351,7 @@ set_smooth_pos(const LPoint3f &pos, const LVecBase3f &hpr, _smooth_hpr = hpr; _smooth_timestamp = timestamp; _smooth_position_known = true; + _smooth_position_changed = true; _computed_smooth_mat = false; } diff --git a/direct/src/deadrec/smoothMover.h b/direct/src/deadrec/smoothMover.h index 5f612cc8c0..a7aabd2eaf 100644 --- a/direct/src/deadrec/smoothMover.h +++ b/direct/src/deadrec/smoothMover.h @@ -83,8 +83,8 @@ PUBLISHED: void mark_position(); void clear_positions(bool reset_velocity); - INLINE void compute_smooth_position(); - void compute_smooth_position(double timestamp); + INLINE bool compute_smooth_position(); + bool compute_smooth_position(double timestamp); bool get_latest_position(); INLINE const LPoint3f &get_smooth_pos() const; @@ -153,6 +153,7 @@ private: LMatrix4f _smooth_mat; double _smooth_timestamp; bool _smooth_position_known; + bool _smooth_position_changed; bool _computed_smooth_mat; double _smooth_forward_velocity;