Assuming you know how to iterate over the Python objects..
Code:
struct Vehicle : PyVarObject
{
inline PyBoolObject* isPlayer( void ) { return ( PyBoolObject* )PyTool_GetAttr( ( PyObject* )this, "isPlayer" ); }
inline VehicleType* typeDescriptor( void ) { return ( VehicleType* )PyTool_GetAttr( ( PyObject* )this, "typeDescriptor" ); }
inline PyBoolObject* isStarted( void ) { return ( PyBoolObject* )PyTool_GetAttr( ( PyObject* )this, "isStarted" ); }
inline PyIntObject* health( void ) { return ( PyIntObject* )PyTool_GetAttr( ( PyObject* )this, "health" ); }
inline PyBoolObject* isCrewActive( void ) { return ( PyBoolObject* )PyTool_GetAttr( ( PyObject* )this, "isCrewActive" ); }
// Custom function for my own sanity
inline Math::Angle GetAngle( void ) { return Math::Angle( yaw, pitch, roll, true ); }
long playerVehicleID;
Math::Vec3 position;
Math::Vec3 velocity;
float yaw;
float pitch;
float roll;
};
Code:
inline PyObject* PyTool_DictGetValue( PyObject* dict, const char* str )
{
PyObject* key,* value;
PyStringObject* sval;
Py_ssize_t pos = 0;
if ( dict == 0 || !PyDict_Check( dict ) )
return 0;
while ( PyDict_Next( dict, &pos, &key, &value ) )
{
sval = ( PyStringObject* )key;
if ( strcmp( ( char* )sval->ob_sval, str ) == 0 )
return value;
}
return 0;
}
inline PyObject* PyTool_GetAttr( PyObject* obj, const char* str )
{
PyObject* dict,* oval;
if ( obj == 0 || obj->ob_type == 0 )
return 0;
dict = obj->ob_type->tp_dict;
oval = PyTool_DictGetValue( dict, str );
if ( oval != 0 )
return oval;
if ( obj->ob_type->tp_dictoffset > 0 )
{
dict = *( PyObject** )( ( unsigned long )obj + ( obj->ob_type->tp_dictoffset ) );
oval = PyTool_DictGetValue( dict, str );
return oval;
}
return 0;
}