mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
added get/set_most_recent_timestamp to allow local (non-distributed) smooth pos updates
This commit is contained in:
parent
701cfb9821
commit
b421580c9b
@ -132,6 +132,11 @@ set_pos(float x, float y, float z) {
|
|||||||
INLINE bool SmoothMover::
|
INLINE bool SmoothMover::
|
||||||
set_x(float x) {
|
set_x(float x) {
|
||||||
bool result = (x != _sample._pos[0]);
|
bool result = (x != _sample._pos[0]);
|
||||||
|
/*
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "set_x " << x << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
_sample._pos[0] = x;
|
_sample._pos[0] = x;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -144,6 +149,11 @@ set_x(float x) {
|
|||||||
INLINE bool SmoothMover::
|
INLINE bool SmoothMover::
|
||||||
set_y(float y) {
|
set_y(float y) {
|
||||||
bool result = (y != _sample._pos[1]);
|
bool result = (y != _sample._pos[1]);
|
||||||
|
/*
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "set_y " << y << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
_sample._pos[1] = y;
|
_sample._pos[1] = y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -156,6 +166,11 @@ set_y(float y) {
|
|||||||
INLINE bool SmoothMover::
|
INLINE bool SmoothMover::
|
||||||
set_z(float z) {
|
set_z(float z) {
|
||||||
bool result = (z != _sample._pos[2]);
|
bool result = (z != _sample._pos[2]);
|
||||||
|
/*
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "set_z " << z << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
_sample._pos[2] = z;
|
_sample._pos[2] = z;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -208,6 +223,11 @@ set_hpr(float h, float p, float r) {
|
|||||||
INLINE bool SmoothMover::
|
INLINE bool SmoothMover::
|
||||||
set_h(float h) {
|
set_h(float h) {
|
||||||
bool result = (h != _sample._hpr[0]);
|
bool result = (h != _sample._hpr[0]);
|
||||||
|
/*
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "set_h " << h << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
_sample._hpr[0] = h;
|
_sample._hpr[0] = h;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -220,6 +240,11 @@ set_h(float h) {
|
|||||||
INLINE bool SmoothMover::
|
INLINE bool SmoothMover::
|
||||||
set_p(float p) {
|
set_p(float p) {
|
||||||
bool result = (p != _sample._hpr[1]);
|
bool result = (p != _sample._hpr[1]);
|
||||||
|
/*
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "set_p " << p << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
_sample._hpr[1] = p;
|
_sample._hpr[1] = p;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -232,6 +257,11 @@ set_p(float p) {
|
|||||||
INLINE bool SmoothMover::
|
INLINE bool SmoothMover::
|
||||||
set_r(float r) {
|
set_r(float r) {
|
||||||
bool result = (r != _sample._hpr[2]);
|
bool result = (r != _sample._hpr[2]);
|
||||||
|
/*
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "set_r " << r << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
_sample._hpr[2] = r;
|
_sample._hpr[2] = r;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -276,6 +306,7 @@ INLINE void SmoothMover::
|
|||||||
set_phony_timestamp() {
|
set_phony_timestamp() {
|
||||||
double now = ClockObject::get_global_clock()->get_frame_time();
|
double now = ClockObject::get_global_clock()->get_frame_time();
|
||||||
_sample._timestamp = now;
|
_sample._timestamp = now;
|
||||||
|
_most_recent_timestamp = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -287,10 +318,39 @@ set_phony_timestamp() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void SmoothMover::
|
INLINE void SmoothMover::
|
||||||
set_timestamp(double timestamp) {
|
set_timestamp(double timestamp) {
|
||||||
|
/*
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "set_timestamp " << timestamp << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
_sample._timestamp = timestamp;
|
_sample._timestamp = timestamp;
|
||||||
|
_most_recent_timestamp = timestamp;
|
||||||
record_timestamp_delay(timestamp);
|
record_timestamp_delay(timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: SmoothMover::get_most_recent_timestamp
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns most recently recorded timestamp
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE double SmoothMover::
|
||||||
|
get_most_recent_timestamp() {
|
||||||
|
return _most_recent_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: SmoothMover::set_most_recent_timestamp
|
||||||
|
// Access: Published
|
||||||
|
// Description: Specifies the time that the current position report
|
||||||
|
// applies. This should be called after a call to
|
||||||
|
// mark_position().
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE void SmoothMover::
|
||||||
|
set_most_recent_timestamp(double timestamp) {
|
||||||
|
_points.back()._timestamp = timestamp;
|
||||||
|
_most_recent_timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: SmoothMover::compute_smooth_position
|
// Function: SmoothMover::compute_smooth_position
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -107,6 +107,9 @@ set_mat(const LMatrix4f &mat) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void SmoothMover::
|
void SmoothMover::
|
||||||
mark_position() {
|
mark_position() {
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "mark_position\n";
|
||||||
|
}
|
||||||
if (_smooth_mode == SM_off) {
|
if (_smooth_mode == SM_off) {
|
||||||
// With smoothing disabled, mark_position() simply stores its
|
// With smoothing disabled, mark_position() simply stores its
|
||||||
// current position in the smooth_position members.
|
// current position in the smooth_position members.
|
||||||
@ -138,6 +141,12 @@ mark_position() {
|
|||||||
// report.
|
// report.
|
||||||
|
|
||||||
if (!_points.empty() && _points.back()._timestamp > _sample._timestamp) {
|
if (!_points.empty() && _points.back()._timestamp > _sample._timestamp) {
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug()
|
||||||
|
<< "*** timestamp out of order " << _points.back()._timestamp << " "
|
||||||
|
<< _sample._timestamp << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
// If we get a timestamp out of order, one of us must have just
|
// If we get a timestamp out of order, one of us must have just
|
||||||
// reset our clock. Flush the sequence and start again.
|
// reset our clock. Flush the sequence and start again.
|
||||||
_points.clear();
|
_points.clear();
|
||||||
@ -149,11 +158,19 @@ mark_position() {
|
|||||||
_points.push_back(_sample);
|
_points.push_back(_sample);
|
||||||
|
|
||||||
} else if (!_points.empty() && _points.back()._timestamp == _sample._timestamp) {
|
} else if (!_points.empty() && _points.back()._timestamp == _sample._timestamp) {
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug()
|
||||||
|
<< "*** same timestamp\n";
|
||||||
|
}
|
||||||
// If the new timestamp is the same as the last timestamp, the
|
// If the new timestamp is the same as the last timestamp, the
|
||||||
// value simply replaces the previous value.
|
// value simply replaces the previous value.
|
||||||
_points.back() = _sample;
|
_points.back() = _sample;
|
||||||
|
|
||||||
} else if ((int)_points.size() >= max_position_reports) {
|
} else if ((int)_points.size() >= max_position_reports) {
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug()
|
||||||
|
<< "*** dropped oldest position report\n";
|
||||||
|
}
|
||||||
// If we have too many position reports, throw away the oldest
|
// If we have too many position reports, throw away the oldest
|
||||||
// one.
|
// one.
|
||||||
_points.pop_front();
|
_points.pop_front();
|
||||||
@ -181,6 +198,11 @@ mark_position() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void SmoothMover::
|
void SmoothMover::
|
||||||
clear_positions(bool reset_velocity) {
|
clear_positions(bool reset_velocity) {
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug()
|
||||||
|
<< "clear_positions " << reset_velocity << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
_points.clear();
|
_points.clear();
|
||||||
_last_point_before = -1;
|
_last_point_before = -1;
|
||||||
_last_point_after = -1;
|
_last_point_after = -1;
|
||||||
@ -530,6 +552,9 @@ compute_smooth_position(double timestamp) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool SmoothMover::
|
bool SmoothMover::
|
||||||
get_latest_position() {
|
get_latest_position() {
|
||||||
|
if (deadrec_cat.is_debug()) {
|
||||||
|
deadrec_cat.debug() << "get_latest_position\n";
|
||||||
|
}
|
||||||
if (_points.empty()) {
|
if (_points.empty()) {
|
||||||
// Nothing to do if there are no points.
|
// Nothing to do if there are no points.
|
||||||
return _smooth_position_known;
|
return _smooth_position_known;
|
||||||
|
@ -86,6 +86,9 @@ PUBLISHED:
|
|||||||
|
|
||||||
INLINE void set_phony_timestamp();
|
INLINE void set_phony_timestamp();
|
||||||
INLINE void set_timestamp(double timestamp);
|
INLINE void set_timestamp(double timestamp);
|
||||||
|
|
||||||
|
INLINE double get_most_recent_timestamp();
|
||||||
|
void set_most_recent_timestamp(double timestamp);
|
||||||
|
|
||||||
void mark_position();
|
void mark_position();
|
||||||
void clear_positions(bool reset_velocity);
|
void clear_positions(bool reset_velocity);
|
||||||
@ -198,6 +201,8 @@ private:
|
|||||||
double _smooth_lateral_velocity;
|
double _smooth_lateral_velocity;
|
||||||
double _smooth_rotational_velocity;
|
double _smooth_rotational_velocity;
|
||||||
|
|
||||||
|
double _most_recent_timestamp;
|
||||||
|
|
||||||
// typedef CircBuffer<SamplePoint, max_position_reports> Points;
|
// typedef CircBuffer<SamplePoint, max_position_reports> Points;
|
||||||
typedef pdeque<SamplePoint> Points;
|
typedef pdeque<SamplePoint> Points;
|
||||||
Points _points;
|
Points _points;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user