21 static const PN_stdfloat smooth_node_epsilon = 0.01;
22 static const double network_time_precision = 100.0;
27 CDistributedSmoothNodeBase::
28 CDistributedSmoothNodeBase() {
29 _repository =
nullptr;
34 _clock_delta =
nullptr;
44 CDistributedSmoothNodeBase::
45 ~CDistributedSmoothNodeBase() {
56 _node_path = node_path;
62 _store_xyz = _node_path.
get_pos();
63 _store_hpr = _node_path.
get_hpr();
72 _currL[0] = _currL[1];
73 d_setSmPosHprL(_store_xyz[0], _store_xyz[1], _store_xyz[2],
74 _store_hpr[0], _store_hpr[1], _store_hpr[2], _currL[0]);
83 LPoint3 xyz = _node_path.
get_pos();
84 LVecBase3 hpr = _node_path.
get_hpr();
88 if (!IS_THRESHOLD_EQUAL(_store_xyz[0], xyz[0], smooth_node_epsilon)) {
89 _store_xyz[0] = xyz[0];
93 if (!IS_THRESHOLD_EQUAL(_store_xyz[1], xyz[1], smooth_node_epsilon)) {
94 _store_xyz[1] = xyz[1];
98 if (!IS_THRESHOLD_EQUAL(_store_xyz[2], xyz[2], smooth_node_epsilon)) {
99 _store_xyz[2] = xyz[2];
103 if (!IS_THRESHOLD_EQUAL(_store_hpr[0], hpr[0], smooth_node_epsilon)) {
104 _store_hpr[0] = hpr[0];
108 if (!IS_THRESHOLD_EQUAL(_store_hpr[1], hpr[1], smooth_node_epsilon)) {
109 _store_hpr[1] = hpr[1];
113 if (!IS_THRESHOLD_EQUAL(_store_hpr[2], hpr[2], smooth_node_epsilon)) {
114 _store_hpr[2] = hpr[2];
118 if (_currL[0] != _currL[1]) {
121 _currL[0] = _currL[1];
124 d_setSmPosHprL(_store_xyz[0], _store_xyz[1], _store_xyz[2],
125 _store_hpr[0], _store_hpr[1], _store_hpr[2], _currL[0]);
127 }
else if (flags == 0) {
134 }
else if (only_changed(flags, F_new_h)) {
137 d_setSmH(_store_hpr[0]);
139 }
else if (only_changed(flags, F_new_z)) {
142 d_setSmZ(_store_xyz[2]);
144 }
else if (only_changed(flags, F_new_x | F_new_y)) {
147 d_setSmXY(_store_xyz[0], _store_xyz[1]);
149 }
else if (only_changed(flags, F_new_x | F_new_z)) {
152 d_setSmXZ(_store_xyz[0], _store_xyz[2]);
154 }
else if (only_changed(flags, F_new_x | F_new_y | F_new_z)) {
157 d_setSmPos(_store_xyz[0], _store_xyz[1], _store_xyz[2]);
159 }
else if (only_changed(flags, F_new_h | F_new_p | F_new_r)) {
162 d_setSmHpr(_store_hpr[0], _store_hpr[1], _store_hpr[2]);
164 }
else if (only_changed(flags, F_new_x | F_new_y | F_new_h)) {
167 d_setSmXYH(_store_xyz[0], _store_xyz[1], _store_hpr[0]);
169 }
else if (only_changed(flags, F_new_x | F_new_y | F_new_z | F_new_h)) {
172 d_setSmXYZH(_store_xyz[0], _store_xyz[1], _store_xyz[2], _store_hpr[0]);
177 d_setSmPosHpr(_store_xyz[0], _store_xyz[1], _store_xyz[2],
178 _store_hpr[0], _store_hpr[1], _store_hpr[2]);
188 LPoint3 xyz = _node_path.
get_pos();
189 LVecBase3 hpr = _node_path.
get_hpr();
193 if (!IS_THRESHOLD_EQUAL(_store_xyz[0], xyz[0], smooth_node_epsilon)) {
194 _store_xyz[0] = xyz[0];
198 if (!IS_THRESHOLD_EQUAL(_store_xyz[1], xyz[1], smooth_node_epsilon)) {
199 _store_xyz[1] = xyz[1];
203 if (!IS_THRESHOLD_EQUAL(_store_hpr[0], hpr[0], smooth_node_epsilon)) {
204 _store_hpr[0] = hpr[0];
215 }
else if (only_changed(flags, F_new_h)) {
218 d_setSmH(_store_hpr[0]);
220 }
else if (only_changed(flags, F_new_x | F_new_y)) {
223 d_setSmXY(_store_xyz[0], _store_xyz[1]);
228 d_setSmXYH(_store_xyz[0], _store_xyz[1], _store_hpr[0]);
238 LPoint3 xyz = _node_path.
get_pos();
242 if (!IS_THRESHOLD_EQUAL(_store_xyz[0], xyz[0], smooth_node_epsilon)) {
243 _store_xyz[0] = xyz[0];
247 if (!IS_THRESHOLD_EQUAL(_store_xyz[1], xyz[1], smooth_node_epsilon)) {
248 _store_xyz[1] = xyz[1];
262 d_setSmXY(_store_xyz[0], _store_xyz[1]);
270 void CDistributedSmoothNodeBase::
271 begin_send_update(
DCPacker &packer,
const std::string &field_name) {
273 nassertv(field !=
nullptr);
278 packer.RAW_PACK_CHANNEL(_do_id);
279 packer.RAW_PACK_CHANNEL(_ai_id);
298 void CDistributedSmoothNodeBase::
299 finish_send_update(
DCPacker &packer) {
301 nassertv(_clock_delta !=
nullptr);
302 PyObject *clock_delta = PyObject_GetAttrString(_clock_delta,
"delta");
303 nassertv(clock_delta !=
nullptr);
304 double delta = PyFloat_AsDouble(clock_delta);
305 Py_DECREF(clock_delta);
307 static const double delta = 0.0f;
308 #endif // HAVE_PYTHON
312 int network_time = (int)cfloor(((local_time - delta) * network_time_precision) + 0.5);
315 network_time = ((network_time + 0x8000) & 0xFFFF) - 0x8000;
322 nassertv(_repository !=
nullptr);
328 std::ostringstream error;
329 error <<
"Node position out of range for DC file: "
330 << _node_path <<
" pos = " << _store_xyz
331 <<
" hpr = " << _store_hpr
332 <<
" zoneId = " << _currL[0];
335 std::string message = error.str();
336 distributed_cat.warning()
338 PyErr_SetString(PyExc_ValueError, message.c_str());
340 nassert_raise(error.str());
344 const char *message =
"Unexpected pack error in DC file.";
346 distributed_cat.warning()
348 PyErr_SetString(PyExc_TypeError, message);
350 nassert_raise(message);
365 void CDistributedSmoothNodeBase::
367 std::cout <<
"printCurrL: sent l: " << _currL[1] <<
" last set l: " << _currL[0] <<
"\n";