fix data members as required fields
This commit is contained in:
parent
9dae916780
commit
aa678ea8a3
|
|
@ -381,11 +381,10 @@ receive_update_broadcast_required(PyObject *distobj, DatagramIterator &di) const
|
|||
int num_fields = get_num_inherited_fields();
|
||||
for (int i = 0; i < num_fields && !PyErr_Occurred(); ++i) {
|
||||
DCField *field = get_inherited_field(i);
|
||||
DCAtomicField *atom = field->as_atomic_field();
|
||||
if (atom != (DCAtomicField *)NULL &&
|
||||
atom->is_required() && atom->is_broadcast()) {
|
||||
packer.begin_unpack(atom);
|
||||
atom->receive_update(packer, distobj);
|
||||
if (field->as_molecular_field() == (DCMolecularField *)NULL &&
|
||||
field->is_required() && field->is_broadcast()) {
|
||||
packer.begin_unpack(field);
|
||||
field->receive_update(packer, distobj);
|
||||
if (!packer.end_unpack()) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -416,10 +415,10 @@ receive_update_all_required(PyObject *distobj, DatagramIterator &di) const {
|
|||
int num_fields = get_num_inherited_fields();
|
||||
for (int i = 0; i < num_fields && !PyErr_Occurred(); ++i) {
|
||||
DCField *field = get_inherited_field(i);
|
||||
DCAtomicField *atom = field->as_atomic_field();
|
||||
if (atom != (DCAtomicField *)NULL && atom->is_required()) {
|
||||
packer.begin_unpack(atom);
|
||||
atom->receive_update(packer, distobj);
|
||||
if (field->as_molecular_field() == (DCMolecularField *)NULL &&
|
||||
field->is_required()) {
|
||||
packer.begin_unpack(field);
|
||||
field->receive_update(packer, distobj);
|
||||
if (!packer.end_unpack()) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -563,8 +562,7 @@ pack_required_field(DCPacker &packer, PyObject *distobj,
|
|||
return pack_ok;
|
||||
}
|
||||
|
||||
const DCAtomicField *atom = field->as_atomic_field();
|
||||
if (atom == (DCAtomicField *)NULL) {
|
||||
if (field->as_molecular_field() != (DCMolecularField *)NULL) {
|
||||
ostringstream strm;
|
||||
strm << "Cannot pack molecular field " << field->get_name()
|
||||
<< " for generate";
|
||||
|
|
@ -572,6 +570,9 @@ pack_required_field(DCPacker &packer, PyObject *distobj,
|
|||
return false;
|
||||
}
|
||||
|
||||
const DCAtomicField *atom = field->as_atomic_field();
|
||||
nassertr(atom != (DCAtomicField *)NULL, false);
|
||||
|
||||
// We need to get the initial value of this field. There isn't a
|
||||
// good, robust way to get this; presently, we just mangle the
|
||||
// "setFoo()" name of the required field into "getFoo()" and call
|
||||
|
|
|
|||
|
|
@ -532,31 +532,45 @@ unpack_args(DCPacker &packer) const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
void DCField::
|
||||
receive_update(DCPacker &packer, PyObject *distobj) const {
|
||||
if (!PyObject_HasAttrString(distobj, (char *)_name.c_str())) {
|
||||
// If there's no Python method to receive this message, don't
|
||||
// bother unpacking it to a Python tuple--just skip past the
|
||||
// message.
|
||||
packer.unpack_skip();
|
||||
if (as_parameter() != (DCParameter *)NULL) {
|
||||
// If it's a parameter-type field, just store a new value on the
|
||||
// object.
|
||||
PyObject *value = unpack_args(packer);
|
||||
if (value != (PyObject *)NULL) {
|
||||
PyObject_SetAttrString(distobj, (char *)_name.c_str(), value);
|
||||
}
|
||||
Py_DECREF(value);
|
||||
|
||||
} else {
|
||||
// Otherwise, get a Python tuple from the args and call the Python
|
||||
// method.
|
||||
PyObject *args = unpack_args(packer);
|
||||
// Otherwise, it must be an atomic or molecular field, so call the
|
||||
// corresponding method.
|
||||
|
||||
if (args != (PyObject *)NULL) {
|
||||
PyObject *func = PyObject_GetAttrString(distobj, (char *)_name.c_str());
|
||||
nassertv(func != (PyObject *)NULL);
|
||||
if (!PyObject_HasAttrString(distobj, (char *)_name.c_str())) {
|
||||
// If there's no Python method to receive this message, don't
|
||||
// bother unpacking it to a Python tuple--just skip past the
|
||||
// message.
|
||||
packer.unpack_skip();
|
||||
|
||||
} else {
|
||||
// Otherwise, get a Python tuple from the args and call the Python
|
||||
// method.
|
||||
PyObject *args = unpack_args(packer);
|
||||
|
||||
if (args != (PyObject *)NULL) {
|
||||
PyObject *func = PyObject_GetAttrString(distobj, (char *)_name.c_str());
|
||||
nassertv(func != (PyObject *)NULL);
|
||||
|
||||
PyObject *result;
|
||||
{
|
||||
PyObject *result;
|
||||
{
|
||||
#ifdef WITHIN_PANDA
|
||||
PStatTimer timer(((DCField *)this)->_field_update_pcollector);
|
||||
PStatTimer timer(((DCField *)this)->_field_update_pcollector);
|
||||
#endif
|
||||
result = PyObject_CallObject(func, args);
|
||||
result = PyObject_CallObject(func, args);
|
||||
}
|
||||
Py_XDECREF(result);
|
||||
Py_DECREF(func);
|
||||
Py_DECREF(args);
|
||||
}
|
||||
Py_XDECREF(result);
|
||||
Py_DECREF(func);
|
||||
Py_DECREF(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,7 +232,6 @@ write_instance(ostream &out, bool brief, int indent_level,
|
|||
const string &postname) const {
|
||||
indent(out, indent_level);
|
||||
output_instance(out, brief, prename, name, postname);
|
||||
output_flags(out);
|
||||
out << ";";
|
||||
if (!brief && _number >= 0) {
|
||||
out << " // field " << _number;
|
||||
|
|
|
|||
Loading…
Reference in New Issue