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::
|
||||
set_x(float x) {
|
||||
bool result = (x != _sample._pos[0]);
|
||||
/*
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "set_x " << x << "\n";
|
||||
}
|
||||
*/
|
||||
_sample._pos[0] = x;
|
||||
return result;
|
||||
}
|
||||
@ -144,6 +149,11 @@ set_x(float x) {
|
||||
INLINE bool SmoothMover::
|
||||
set_y(float y) {
|
||||
bool result = (y != _sample._pos[1]);
|
||||
/*
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "set_y " << y << "\n";
|
||||
}
|
||||
*/
|
||||
_sample._pos[1] = y;
|
||||
return result;
|
||||
}
|
||||
@ -156,6 +166,11 @@ set_y(float y) {
|
||||
INLINE bool SmoothMover::
|
||||
set_z(float z) {
|
||||
bool result = (z != _sample._pos[2]);
|
||||
/*
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "set_z " << z << "\n";
|
||||
}
|
||||
*/
|
||||
_sample._pos[2] = z;
|
||||
return result;
|
||||
}
|
||||
@ -208,6 +223,11 @@ set_hpr(float h, float p, float r) {
|
||||
INLINE bool SmoothMover::
|
||||
set_h(float h) {
|
||||
bool result = (h != _sample._hpr[0]);
|
||||
/*
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "set_h " << h << "\n";
|
||||
}
|
||||
*/
|
||||
_sample._hpr[0] = h;
|
||||
return result;
|
||||
}
|
||||
@ -220,6 +240,11 @@ set_h(float h) {
|
||||
INLINE bool SmoothMover::
|
||||
set_p(float p) {
|
||||
bool result = (p != _sample._hpr[1]);
|
||||
/*
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "set_p " << p << "\n";
|
||||
}
|
||||
*/
|
||||
_sample._hpr[1] = p;
|
||||
return result;
|
||||
}
|
||||
@ -232,6 +257,11 @@ set_p(float p) {
|
||||
INLINE bool SmoothMover::
|
||||
set_r(float r) {
|
||||
bool result = (r != _sample._hpr[2]);
|
||||
/*
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "set_r " << r << "\n";
|
||||
}
|
||||
*/
|
||||
_sample._hpr[2] = r;
|
||||
return result;
|
||||
}
|
||||
@ -276,6 +306,7 @@ INLINE void SmoothMover::
|
||||
set_phony_timestamp() {
|
||||
double now = ClockObject::get_global_clock()->get_frame_time();
|
||||
_sample._timestamp = now;
|
||||
_most_recent_timestamp = now;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -287,10 +318,39 @@ set_phony_timestamp() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void SmoothMover::
|
||||
set_timestamp(double timestamp) {
|
||||
/*
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "set_timestamp " << timestamp << "\n";
|
||||
}
|
||||
*/
|
||||
_sample._timestamp = timestamp;
|
||||
_most_recent_timestamp = 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
|
||||
// Access: Published
|
||||
|
@ -107,6 +107,9 @@ set_mat(const LMatrix4f &mat) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void SmoothMover::
|
||||
mark_position() {
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "mark_position\n";
|
||||
}
|
||||
if (_smooth_mode == SM_off) {
|
||||
// With smoothing disabled, mark_position() simply stores its
|
||||
// current position in the smooth_position members.
|
||||
@ -138,6 +141,12 @@ mark_position() {
|
||||
// report.
|
||||
|
||||
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
|
||||
// reset our clock. Flush the sequence and start again.
|
||||
_points.clear();
|
||||
@ -149,11 +158,19 @@ mark_position() {
|
||||
_points.push_back(_sample);
|
||||
|
||||
} 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
|
||||
// value simply replaces the previous value.
|
||||
_points.back() = _sample;
|
||||
|
||||
} 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
|
||||
// one.
|
||||
_points.pop_front();
|
||||
@ -181,6 +198,11 @@ mark_position() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void SmoothMover::
|
||||
clear_positions(bool reset_velocity) {
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug()
|
||||
<< "clear_positions " << reset_velocity << "\n";
|
||||
}
|
||||
|
||||
_points.clear();
|
||||
_last_point_before = -1;
|
||||
_last_point_after = -1;
|
||||
@ -530,6 +552,9 @@ compute_smooth_position(double timestamp) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool SmoothMover::
|
||||
get_latest_position() {
|
||||
if (deadrec_cat.is_debug()) {
|
||||
deadrec_cat.debug() << "get_latest_position\n";
|
||||
}
|
||||
if (_points.empty()) {
|
||||
// Nothing to do if there are no points.
|
||||
return _smooth_position_known;
|
||||
|
@ -87,6 +87,9 @@ PUBLISHED:
|
||||
INLINE void set_phony_timestamp();
|
||||
INLINE void set_timestamp(double timestamp);
|
||||
|
||||
INLINE double get_most_recent_timestamp();
|
||||
void set_most_recent_timestamp(double timestamp);
|
||||
|
||||
void mark_position();
|
||||
void clear_positions(bool reset_velocity);
|
||||
|
||||
@ -198,6 +201,8 @@ private:
|
||||
double _smooth_lateral_velocity;
|
||||
double _smooth_rotational_velocity;
|
||||
|
||||
double _most_recent_timestamp;
|
||||
|
||||
// typedef CircBuffer<SamplePoint, max_position_reports> Points;
|
||||
typedef pdeque<SamplePoint> Points;
|
||||
Points _points;
|
||||
|
Loading…
x
Reference in New Issue
Block a user