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.

This commit is contained in:
Justin Butler 2008-10-10 21:05:46 +00:00
parent 1c043e705b
commit 7f9a509f04
5 changed files with 79 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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"