MCPcopy Create free account
hub / github.com/carbonengine/trinity / PySetData

Function PySetData

trinity/Tr2RuntimeInstanceData_Blue.cpp:77–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77static PyObject* PySetData( PyObject* self, PyObject* args )
78{
79 Tr2RuntimeInstanceData* pThis = BluePythonCast<Tr2RuntimeInstanceData*>( self );
80
81 PyObject* pyData;
82 if( !PyArg_ParseTuple( args, "O!", &PyList_Type, &pyData ) )
83 {
84 return nullptr;
85 }
86
87 const Tr2VertexDefinition& def = pThis->GetLayout();
88 if( def.m_items.empty() )
89 {
90 PyErr_SetString( PyExc_RuntimeError, "Need to set valid element layout with SetElementLayout before calling SetData" );
91 return nullptr;
92 }
93
94 float* data = reinterpret_cast<float*>( pThis->GetData( unsigned( PyList_GET_SIZE( pyData ) ) ) );
95 if( !data )
96 {
97 PyErr_SetString( PyExc_RuntimeError, "Could not lock data" );
98 return nullptr;
99 }
100
101
102 for( int i = 0; i < PyList_GET_SIZE( pyData ); ++i )
103 {
104 PyObject* item = PyList_GetItem( pyData, i );
105 if( !PyTuple_Check( item ) || PyTuple_GET_SIZE( item ) != def.m_items.size() )
106 {
107 pThis->DestroyData();
108 PyErr_SetString( PyExc_TypeError, "Argument 1 needs to be a list of tuples and tuples need to match element layout" );
109 return nullptr;
110 }
111 for( size_t j = 0; j < def.m_items.size(); ++j )
112 {
113 PyObject* element = PyTuple_GET_ITEM( item, j );
114 unsigned size = def.GetDataTypeSizeInMembers( def.m_items[j].m_dataType );
115 if( size == 1 )
116 {
117 if( !PyFloat_Check( element ) )
118 {
119 pThis->DestroyData();
120 PyErr_SetString( PyExc_TypeError, "Argument 1 needs to be a list of tuples and tuples need to match element layout" );
121 return nullptr;
122 }
123 *data++ = float( PyFloat_AsDouble( element ) );
124 }
125 else
126 {
127 if( !PyTuple_Check( element ) )
128 {
129 pThis->DestroyData();
130 PyErr_SetString( PyExc_TypeError, "Argument 1 needs to be a list of tuples and tuples need to match element layout" );
131 return nullptr;
132 }
133 for( unsigned k = 0; k < size; ++k )
134 {

Callers

nothing calls this directly

Calls 5

emptyMethod · 0.80
sizeMethod · 0.80
GetDataMethod · 0.45
DestroyDataMethod · 0.45

Tested by

no test coverage detected