From 7f9a509f0462963ca51780127e38ec01acb2ef41 Mon Sep 17 00:00:00 2001 From: Justin Butler Date: Fri, 10 Oct 2008 21:05:46 +0000 Subject: [PATCH] Smooth object movement fix for pirates. Added a zoneId value that is sent along with position to better sync position and location for those that need it. --- .../src/distributed/DistributedSmoothNode.py | 17 +++++++++++ .../distributed/DistributedSmoothNodeAI.py | 7 +++++ .../distributed/cDistributedSmoothNodeBase.I | 22 ++++++++++++++ .../cDistributedSmoothNodeBase.cxx | 29 +++++++++++++++++-- .../distributed/cDistributedSmoothNodeBase.h | 6 ++++ 5 files changed, 79 insertions(+), 2 deletions(-) diff --git a/direct/src/distributed/DistributedSmoothNode.py b/direct/src/distributed/DistributedSmoothNode.py index 9983a58d47..756a9fcf3f 100644 --- a/direct/src/distributed/DistributedSmoothNode.py +++ b/direct/src/distributed/DistributedSmoothNode.py @@ -91,6 +91,9 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, self.activateSmoothing(GlobalSmoothing, GlobalPrediction) + # clear stopped flag for re-generate + self.stopped = False + def disable(self): DistributedSmoothNodeBase.DistributedSmoothNodeBase.disable(self) DistributedNode.DistributedNode.disable(self) @@ -243,6 +246,16 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, self.setComponentP(p) self.setComponentR(r) self.setComponentTLive(timestamp) + def setSmPosHprL(self, l, x, y, z, h, p, r, timestamp=None): + self._checkResume() + self.setComponentL(l) + self.setComponentX(x) + self.setComponentY(y) + self.setComponentZ(z) + self.setComponentH(h) + self.setComponentP(p) + self.setComponentR(r) + self.setComponentTLive(timestamp) ### component set pos and hpr functions ### @@ -261,6 +274,10 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, self.smoother.setP(p) def setComponentR(self, r): self.smoother.setR(r) + def setComponentL(self, l): + if (l != self.zoneId): + # only perform set location if location is different + self.setLocation(self.parentId,l) def setComponentT(self, timestamp): # This is a little bit hacky. If *this* function is called, # it must have been called directly by the server, for diff --git a/direct/src/distributed/DistributedSmoothNodeAI.py b/direct/src/distributed/DistributedSmoothNodeAI.py index ce63b2c07a..8db1e4deab 100755 --- a/direct/src/distributed/DistributedSmoothNodeAI.py +++ b/direct/src/distributed/DistributedSmoothNodeAI.py @@ -61,6 +61,9 @@ class DistributedSmoothNodeAI(DistributedNodeAI.DistributedNodeAI, def setSmPosHpr(self, x, y, z, h, p, r, t=None): self.setPosHpr(x, y, z, h, p, r) + def setSmPosHprL(self, l, x, y, z, h, p, r, t=None): + self.setPosHpr(x, y, z, h, p, r) + def clearSmoothing(self, bogus = None): pass @@ -78,6 +81,8 @@ class DistributedSmoothNodeAI(DistributedNodeAI.DistributedNodeAI, self.setP(p) def setComponentR(self, r): self.setR(r) + def setComponentL(self, l): + pass def setComponentT(self, t): pass @@ -93,5 +98,7 @@ class DistributedSmoothNodeAI(DistributedNodeAI.DistributedNodeAI, return self.getP() def getComponentR(self): return self.getR() + def getComponentL(self): + pass def getComponentT(self): pass diff --git a/direct/src/distributed/cDistributedSmoothNodeBase.I b/direct/src/distributed/cDistributedSmoothNodeBase.I index 8706c99e17..3edc8f4cfb 100644 --- a/direct/src/distributed/cDistributedSmoothNodeBase.I +++ b/direct/src/distributed/cDistributedSmoothNodeBase.I @@ -207,3 +207,25 @@ d_setSmPosHpr(float x, float y, float z, float h, float p, float r) { packer.pack_double(r); finish_send_update(packer); } + +//////////////////////////////////////////////////////////////////// +// Function: CDistributedSmoothNodeBase::d_setSmPosHprL +// send out pos, hpr, and location info (zoneId) +// Access: Private +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void CDistributedSmoothNodeBase:: +d_setSmPosHprL(float x, float y, float z, float h, float p, float r, PN_uint64 l) { + //cout << "d_setSmPosHprL: " << x << ", " << y << ", " << z << ", " << h << ", " << p << ", " << r << l << endl; + DCPacker packer; + begin_send_update(packer, "setSmPosHprL"); + packer.pack_uint64(_currL[0]); + packer.pack_double(x); + packer.pack_double(y); + packer.pack_double(z); + packer.pack_double(h); + packer.pack_double(p); + packer.pack_double(r); + finish_send_update(packer); +} + diff --git a/direct/src/distributed/cDistributedSmoothNodeBase.cxx b/direct/src/distributed/cDistributedSmoothNodeBase.cxx index 5bc62b8de8..a5c2b87810 100644 --- a/direct/src/distributed/cDistributedSmoothNodeBase.cxx +++ b/direct/src/distributed/cDistributedSmoothNodeBase.cxx @@ -36,6 +36,8 @@ PyObject *CDistributedSmoothNodeBase::_clock_delta = NULL; //////////////////////////////////////////////////////////////////// CDistributedSmoothNodeBase:: CDistributedSmoothNodeBase() { + _currL[0] = 0; + _currL[1] = 0; } //////////////////////////////////////////////////////////////////// @@ -124,7 +126,16 @@ broadcast_pos_hpr_full() { flags |= F_new_r; } - if (flags == 0) { + if (_currL[0] != _currL[1]) { + // location (zoneId) has changed, send out all info + // copy over 'set' location over to 'sent' location + _currL[0] = _currL[1]; + // Any other change + _store_stop = false; + d_setSmPosHprL(_store_xyz[0], _store_xyz[1], _store_xyz[2], + _store_hpr[0], _store_hpr[1], _store_hpr[2], _currL[0]); + + } else if (flags == 0) { // No change. Send one and only one "stop" message. if (!_store_stop) { _store_stop = true; @@ -335,7 +346,8 @@ finish_send_update(DCPacker &packer) { ostringstream error; error << "Node position out of range for DC file: " << _node_path << " pos = " << _store_xyz - << " hpr = " << _store_hpr; + << " hpr = " << _store_hpr + << " zoneId = " << _currL[0]; nassert_raise(error.str()); } else { @@ -345,3 +357,16 @@ finish_send_update(DCPacker &packer) { } } +//////////////////////////////////////////////////////////////////// +// Function: CDistributedSmoothNodeBase::set_curr_l +// published function to set current location for +// this object, this location is then sent out along +// with the next position broadcast +// Access: Private +// Description: Appends the timestamp and sends the update. +//////////////////////////////////////////////////////////////////// +void CDistributedSmoothNodeBase:: +set_curr_l(PN_uint64 l) { + _currL[1] = l; +} + diff --git a/direct/src/distributed/cDistributedSmoothNodeBase.h b/direct/src/distributed/cDistributedSmoothNodeBase.h index 1c24e132e6..395f5e63d9 100644 --- a/direct/src/distributed/cDistributedSmoothNodeBase.h +++ b/direct/src/distributed/cDistributedSmoothNodeBase.h @@ -54,6 +54,8 @@ PUBLISHED: void broadcast_pos_hpr_xyh(); void broadcast_pos_hpr_xy(); + void set_curr_l(PN_uint64 l); + private: INLINE static bool only_changed(int flags, int compare); @@ -67,6 +69,7 @@ private: INLINE void d_setSmXYH(float x, float y, float h); INLINE void d_setSmXYZH(float x, float y, float z, float h); INLINE void d_setSmPosHpr(float x, float y, float z, float h, float p, float r); + INLINE void d_setSmPosHprL(float x, float y, float z, float h, float p, float r, PN_uint64 l); void begin_send_update(DCPacker &packer, const string &field_name); void finish_send_update(DCPacker &packer); @@ -94,6 +97,9 @@ private: LPoint3f _store_xyz; LVecBase3f _store_hpr; bool _store_stop; + // contains most recently sent location info as + // index 0, index 1 contains most recently set location info + PN_uint64 _currL[2]; }; #include "cDistributedSmoothNodeBase.I"