From c373e91564ac7ec14964429d01743cd74917d928 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 6 Feb 2007 17:27:09 +0000 Subject: [PATCH] make smoothmover parameters be instance variables --- direct/src/deadrec/smoothMover.cxx | 16 ++-- direct/src/deadrec/smoothMover.h | 44 +++++---- .../src/distributed/DistributedSmoothNode.py | 94 +++++++++++-------- 3 files changed, 86 insertions(+), 68 deletions(-) diff --git a/direct/src/deadrec/smoothMover.cxx b/direct/src/deadrec/smoothMover.cxx index 9b5b5daedc..732dd6f292 100644 --- a/direct/src/deadrec/smoothMover.cxx +++ b/direct/src/deadrec/smoothMover.cxx @@ -20,14 +20,6 @@ #include "pnotify.h" #include "compose_matrix.h" -SmoothMover::SmoothMode SmoothMover::_smooth_mode = SmoothMover::SM_off; -SmoothMover::PredictionMode SmoothMover::_prediction_mode = SmoothMover::PM_off; -double SmoothMover::_delay = 0.2; -bool SmoothMover::_accept_clock_skew = true; -double SmoothMover::_max_position_age = 0.25; -double SmoothMover::_expected_broadcast_period = 0.2; -double SmoothMover::_reset_velocity_age = 0.3; - //////////////////////////////////////////////////////////////////// // Function: SmoothMover::Constructor // Access: Published @@ -63,6 +55,14 @@ SmoothMover() { _timestamp_delays.push_back(0); _last_heard_from = 0.0; + + _smooth_mode = SM_off; + _prediction_mode = PM_off; + _delay = 0.2; + _accept_clock_skew = true; + _max_position_age = 0.25; + _expected_broadcast_period = 0.2; + _reset_velocity_age = 0.3; } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/deadrec/smoothMover.h b/direct/src/deadrec/smoothMover.h index 27763fa66e..549ee6bd33 100644 --- a/direct/src/deadrec/smoothMover.h +++ b/direct/src/deadrec/smoothMover.h @@ -111,8 +111,6 @@ PUBLISHED: INLINE float get_smooth_rotational_velocity() const; INLINE const LVecBase3f &get_forward_axis() const; - // These static methods control the global properties of all - // SmoothMovers. enum SmoothMode { SM_off, SM_on, @@ -127,26 +125,26 @@ PUBLISHED: // well. }; - INLINE static void set_smooth_mode(SmoothMode mode); - INLINE static SmoothMode get_smooth_mode(); + INLINE void set_smooth_mode(SmoothMode mode); + INLINE SmoothMode get_smooth_mode(); - INLINE static void set_prediction_mode(PredictionMode mode); - INLINE static PredictionMode get_prediction_mode(); + INLINE void set_prediction_mode(PredictionMode mode); + INLINE PredictionMode get_prediction_mode(); - INLINE static void set_delay(double delay); - INLINE static double get_delay(); + INLINE void set_delay(double delay); + INLINE double get_delay(); - INLINE static void set_accept_clock_skew(bool flag); - INLINE static bool get_accept_clock_skew(); + INLINE void set_accept_clock_skew(bool flag); + INLINE bool get_accept_clock_skew(); - INLINE static void set_max_position_age(double age); - INLINE static double get_max_position_age(); + INLINE void set_max_position_age(double age); + INLINE double get_max_position_age(); - INLINE static void set_expected_broadcast_period(double period); - INLINE static double get_expected_broadcast_period(); + INLINE void set_expected_broadcast_period(double period); + INLINE double get_expected_broadcast_period(); - INLINE static void set_reset_velocity_age(double age); - INLINE static double get_reset_velocity_age(); + INLINE void set_reset_velocity_age(double age); + INLINE double get_reset_velocity_age(); void output(ostream &out) const; void write(ostream &out) const; @@ -208,13 +206,13 @@ private: int _net_timestamp_delay; double _last_heard_from; - static SmoothMode _smooth_mode; - static PredictionMode _prediction_mode; - static double _delay; - static bool _accept_clock_skew; - static double _max_position_age; - static double _expected_broadcast_period; - static double _reset_velocity_age; + SmoothMode _smooth_mode; + PredictionMode _prediction_mode; + double _delay; + bool _accept_clock_skew; + double _max_position_age; + double _expected_broadcast_period; + double _reset_velocity_age; }; #include "smoothMover.I" diff --git a/direct/src/distributed/DistributedSmoothNode.py b/direct/src/distributed/DistributedSmoothNode.py index 3a71623224..8cb64f4fc8 100644 --- a/direct/src/distributed/DistributedSmoothNode.py +++ b/direct/src/distributed/DistributedSmoothNode.py @@ -30,46 +30,25 @@ Lag = base.config.GetDouble("smooth-lag", 0.2) PredictionLag = base.config.GetDouble("smooth-prediction-lag", 0.0) +GlobalSmoothing = 0 +GlobalPrediction = 0 +def globalActivateSmoothing(smoothing, prediction): + """ Globally activates or deactivates smoothing and prediction on + all DistributedSmoothNodes currently in existence, or yet to be + generated. """ -def activateSmoothing(smoothing, prediction): - """ - Enables or disables the smoothing of other avatars' motion. - This is a global flag that controls the behavior of all - SmoothMovers in the world. If smoothing is off, no kind of - smoothing will be performed, regardless of the setting of - prediction. - - This is not necessarily predictive smoothing; if predictive - smoothing is off, avatars will be lagged by a certain factor - to achieve smooth motion. Otherwise, if predictive smoothing - is on, avatars will be drawn as nearly as possible in their - current position, by extrapolating from old position reports. + global GlobalSmoothing, GlobalPrediction + GlobalSmoothing = smoothing + GlobalPrediction = prediction - This assumes you have a client repository that knows its - localAvatarDoId -- stored in self.cr.localAvatarDoId - """ + for obj in base.cr.getAllOfType(DistributedSmoothNode): + obj.activateSmoothing(smoothing, prediction) - if smoothing and EnableSmoothing: - if prediction and EnablePrediction: - # Prediction and smoothing. - SmoothMover.setSmoothMode(SmoothMover.SMOn) - SmoothMover.setPredictionMode(SmoothMover.PMOn) - SmoothMover.setDelay(PredictionLag) - else: - # Smoothing, but no prediction. - SmoothMover.setSmoothMode(SmoothMover.SMOn) - SmoothMover.setPredictionMode(SmoothMover.PMOff) - SmoothMover.setDelay(Lag) - # Set these other variables relative to the lag factor - SmoothMover.setExpectedBroadcastPeriod(Lag) - SmoothMover.setMaxPositionAge(Lag * 1.25) - SmoothMover.setResetVelocityAge(Lag * 1.5) - else: - # No smoothing, no prediction. - SmoothMover.setSmoothMode(SmoothMover.SMOff) - SmoothMover.setPredictionMode(SmoothMover.PMOff) - SmoothMover.setDelay(0.0) - +# For historical reasons, we temporarily define +# DistributedSmoothNode.activateSmoothing() to be the global function. +# We'll remove this soon, so it won't get confused with the instance +# method, below. +activateSmoothing = globalActivateSmoothing class DistributedSmoothNode(DistributedNode.DistributedNode, @@ -97,6 +76,10 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, DistributedSmoothNodeBase.DistributedSmoothNodeBase.delete(self) DistributedNode.DistributedNode.delete(self) + def generate(self): + DistributedNode.DistributedNode.generate(self) + self.activateSmoothing(GlobalSmoothing, GlobalPrediction) + ### Methods to handle computing and updating of the smoothed ### position. @@ -378,3 +361,40 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, self.cr.timeManager.synchronize("suggested by %d" % (avId)) return gotSync + + def activateSmoothing(self, smoothing, prediction): + """ + Enables or disables the smoothing of other avatars' motion. + This used to be a global flag, but now it is specific to each + avatar instance. However, see globalActivateSmoothing() in + this module. + + If smoothing is off, no kind of smoothing will be performed, + regardless of the setting of prediction. + + This is not necessarily predictive smoothing; if predictive + smoothing is off, avatars will be lagged by a certain factor + to achieve smooth motion. Otherwise, if predictive smoothing + is on, avatars will be drawn as nearly as possible in their + current position, by extrapolating from old position reports. + + This assumes you have a client repository that knows its + localAvatarDoId -- stored in self.cr.localAvatarDoId + """ + + if smoothing and EnableSmoothing: + if prediction and EnablePrediction: + # Prediction and smoothing. + self.smoother.setSmoothMode(SmoothMover.SMOn) + self.smoother.setPredictionMode(SmoothMover.PMOn) + self.smoother.setDelay(PredictionLag) + else: + # Smoothing, but no prediction. + self.smoother.setSmoothMode(SmoothMover.SMOn) + self.smoother.setPredictionMode(SmoothMover.PMOff) + self.smoother.setDelay(Lag) + else: + # No smoothing, no prediction. + self.smoother.setSmoothMode(SmoothMover.SMOff) + self.smoother.setPredictionMode(SmoothMover.PMOff) + self.smoother.setDelay(0.0)