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;
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";
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool send_datagram(const Datagram &dg)
Queues the indicated datagram for sending to the server.
void set_curr_l(uint64_t l)
Appends the timestamp and sends the update.
void initialize(const NodePath &node_path, DCClass *dclass, CHANNEL_TYPE do_id)
Initializes the internal structures from some constructs that are normally stored only in Python.
void send_everything()
Broadcasts the current pos/hpr in its complete form.
void broadcast_pos_hpr_xyh()
Examines only X, Y, and H of the pos/hpr information, and broadcasts the appropriate messages.
void broadcast_pos_hpr_full()
Examines the complete pos/hpr information to see which of the six elements have changed,...
void broadcast_pos_hpr_xy()
Examines only X and Y of the pos/hpr information, and broadcasts the appropriate messages.
get_real_time
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last ...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
Defines a particular DistributedClass as read from an input .dc file.
DCField * get_field_by_name(const std::string &name) const
Returns a pointer to the DCField that shares the indicated name.
A single field of a Distributed Class, either atomic or molecular.
int get_number() const
Returns a unique index number associated with this field.
This class can be used for packing a series of numeric and string data into a binary stream,...
void push()
Marks the beginning of a nested series of fields.
void begin_pack(const DCPackerInterface *root)
Begins a packing session.
bool had_range_error() const
Returns true if there has been an range validation error since the most recent call to begin(); in pa...
void pack_int(int value)
Packs the indicated numeric or string value into the stream.
void raw_pack_uint32(unsigned int value)
Packs the data into the buffer between packing sessions.
void raw_pack_uint16(unsigned int value)
Packs the data into the buffer between packing sessions.
void raw_pack_uint8(unsigned int value)
Packs the data into the buffer between packing sessions.
void pop()
Marks the end of a nested series of fields.
bool end_pack()
Finishes a packing session.
const char * get_data() const
Returns the beginning of the data buffer.
size_t get_length() const
Returns the current length of the buffer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
LVecBase3 get_hpr() const
Retrieves the rotation component of the transform.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
bool is_empty() const
Returns true if the NodePath contains no nodes.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.