mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
ode: remove dependency on Python.h from odeBody.h
This commit is contained in:
parent
49b72fb198
commit
82459fa21b
@ -89,12 +89,10 @@ set_data(void *data) {
|
||||
dBodySetData(_id, data);
|
||||
}
|
||||
|
||||
#ifndef HAVE_PYTHON
|
||||
INLINE void* OdeBody::
|
||||
INLINE void *OdeBody::
|
||||
get_data() const {
|
||||
return dBodyGetData(_id);
|
||||
}
|
||||
#endif
|
||||
|
||||
INLINE void OdeBody::
|
||||
set_position(dReal x, dReal y, dReal z) {
|
||||
|
@ -15,10 +15,6 @@
|
||||
#include "odeBody.h"
|
||||
#include "odeJoint.h"
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
#include "py_panda.h"
|
||||
#endif
|
||||
|
||||
TypeHandle OdeBody::_type_handle;
|
||||
|
||||
OdeBody::
|
||||
@ -38,29 +34,14 @@ OdeBody::
|
||||
|
||||
void OdeBody::
|
||||
destroy() {
|
||||
#ifdef HAVE_PYTHON
|
||||
Py_XDECREF((PyObject*) dBodyGetData(_id));
|
||||
#endif
|
||||
if (_destroy_callback != nullptr) {
|
||||
_destroy_callback(*this);
|
||||
_destroy_callback = nullptr;
|
||||
}
|
||||
nassertv(_id);
|
||||
dBodyDestroy(_id);
|
||||
}
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
void OdeBody::
|
||||
set_data(PyObject *data) {
|
||||
Py_XDECREF((PyObject*) dBodyGetData(_id));
|
||||
Py_XINCREF(data);
|
||||
dBodySetData(_id, data);
|
||||
}
|
||||
|
||||
PyObject* OdeBody::
|
||||
get_data() const {
|
||||
PyObject* data = (PyObject*) dBodyGetData(_id);
|
||||
Py_XINCREF(data);
|
||||
return data;
|
||||
}
|
||||
#endif
|
||||
|
||||
OdeJoint OdeBody::
|
||||
get_joint(int index) const {
|
||||
nassertr(_id != nullptr, OdeJoint(nullptr));
|
||||
|
@ -51,9 +51,7 @@ PUBLISHED:
|
||||
INLINE void set_auto_disable_flag(int do_auto_disable);
|
||||
INLINE void set_auto_disable_defaults();
|
||||
INLINE void set_data(void *data);
|
||||
#ifdef HAVE_PYTHON
|
||||
void set_data(PyObject *data);
|
||||
#endif
|
||||
EXTENSION(void set_data(PyObject *data));
|
||||
|
||||
INLINE void set_position(dReal x, dReal y, dReal z);
|
||||
INLINE void set_position(const LVecBase3f &pos);
|
||||
@ -71,11 +69,10 @@ PUBLISHED:
|
||||
INLINE int get_auto_disable_steps() const;
|
||||
INLINE dReal get_auto_disable_time() const;
|
||||
INLINE int get_auto_disable_flag() const;
|
||||
#ifdef HAVE_PYTHON
|
||||
PyObject* get_data() const;
|
||||
#else
|
||||
INLINE void* get_data() const;
|
||||
#ifndef CPPPARSER
|
||||
INLINE void *get_data() const;
|
||||
#endif
|
||||
EXTENSION(PyObject *get_data() const);
|
||||
|
||||
INLINE LVecBase3f get_position() const;
|
||||
INLINE LMatrix3f get_rotation() const;
|
||||
@ -150,6 +147,10 @@ PUBLISHED:
|
||||
private:
|
||||
dBodyID _id;
|
||||
|
||||
public:
|
||||
typedef void (*DestroyCallback)(OdeBody &body);
|
||||
DestroyCallback _destroy_callback = nullptr;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
@ -13,6 +13,19 @@
|
||||
|
||||
#include "odeJoint_ext.h"
|
||||
|
||||
/**
|
||||
* Returns the custom data associated with the OdeBody.
|
||||
*/
|
||||
INLINE PyObject *Extension<OdeBody>::
|
||||
get_data() const {
|
||||
PyObject *data = (PyObject *)_this->get_data();
|
||||
if (data == nullptr) {
|
||||
data = Py_None;
|
||||
}
|
||||
Py_INCREF(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent to get_joint().convert()
|
||||
*/
|
||||
|
37
panda/src/ode/odeBody_ext.cxx
Normal file
37
panda/src/ode/odeBody_ext.cxx
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file odeBody_ext.cxx
|
||||
* @author rdb
|
||||
* @date 2018-11-06
|
||||
*/
|
||||
|
||||
#include "odeBody_ext.h"
|
||||
|
||||
static void destroy_callback(OdeBody &body) {
|
||||
Py_XDECREF((PyObject *)body.get_data());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets custom data to be associated with the OdeBody.
|
||||
*/
|
||||
void Extension<OdeBody>::
|
||||
set_data(PyObject *data) {
|
||||
void *old_data = _this->get_data();
|
||||
|
||||
if (data != nullptr && data != Py_None) {
|
||||
Py_INCREF(data);
|
||||
_this->set_data((void *)data);
|
||||
_this->_destroy_callback = &destroy_callback;
|
||||
} else {
|
||||
_this->set_data(nullptr);
|
||||
_this->_destroy_callback = nullptr;
|
||||
}
|
||||
|
||||
Py_XDECREF((PyObject *)old_data);
|
||||
}
|
@ -30,6 +30,9 @@
|
||||
template<>
|
||||
class Extension<OdeBody> : public ExtensionBase<OdeBody> {
|
||||
public:
|
||||
void set_data(PyObject *);
|
||||
INLINE PyObject *get_data() const;
|
||||
|
||||
INLINE PyObject *get_converted_joint(int i) const;
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "odeBody_ext.cxx"
|
||||
#include "odeGeom_ext.cxx"
|
||||
#include "odeJoint_ext.cxx"
|
||||
#include "odeSpace_ext.cxx"
|
||||
|
Loading…
x
Reference in New Issue
Block a user