@@ -109,34 +109,19 @@ emitter_init(EmitterObject *self, PyObject *args, PyObject *kwds)
109109{
110110 Emitter * emitter = & self -> emitter ;
111111
112- static char * kwlist [] = {"emit_shape" ,
113- "emit_number" ,
114- "looping" ,
115- "emit_interval" ,
116- "emit_time" ,
117- "animation" ,
118- "particle_lifetime" ,
119- "speed_x" ,
120- "speed_y" ,
121- "acceleration_x" ,
122- "acceleration_y" ,
123- "angle" ,
124- "align_speed_to_angle" ,
125- "align_acceleration_to_angle" ,
126- "blend_mode" ,
127- NULL };
112+ static char * kwlist [] = {
113+ "emit_shape" , "emit_number" , "animation" , "particle_lifetime" ,
114+ "speed_x" , "speed_y" , "acceleration_x" , "acceleration_y" ,
115+ "blend_mode" , NULL };
128116
129117 PyObject * animation = NULL ;
130118 PyObject * lifetime_obj = NULL , * speedx_obj = NULL , * speedy_obj = NULL ,
131- * accx_obj = NULL , * accy_obj = NULL , * angle_obj = NULL ;
119+ * accx_obj = NULL , * accy_obj = NULL ;
132120
133121 if (!PyArg_ParseTupleAndKeywords (
134- args , kwds , "i|iiffOOOOOOOiii" , kwlist , & emitter -> spawn_shape ,
135- & emitter -> emission_number , & emitter -> looping ,
136- & emitter -> emission_interval , & emitter -> emission_time , & animation ,
137- & lifetime_obj , & speedx_obj , & speedy_obj , & accx_obj , & accy_obj ,
138- & angle_obj , & emitter -> align_speed_to_angle ,
139- & emitter -> align_acceleration_to_angle , & emitter -> blend_mode )) {
122+ args , kwds , "iiOO|OOOOi" , kwlist , & emitter -> spawn_shape ,
123+ & emitter -> emission_number , & animation , & lifetime_obj , & speedx_obj ,
124+ & speedy_obj , & accx_obj , & accy_obj , & emitter -> blend_mode )) {
140125 return -1 ;
141126 }
142127
@@ -237,96 +222,41 @@ emitter_init(EmitterObject *self, PyObject *args, PyObject *kwds)
237222 return -1 ;
238223 }
239224
240- if (angle_obj && !initGen_FromObj (angle_obj , & emitter -> angle )) {
241- PyErr_SetString (PyExc_TypeError , "Invalid angle argument" );
242- return -1 ;
243- }
244-
245- if (!emitter -> angle .in_use ) {
246- if (emitter -> align_speed_to_angle ) {
247- PyErr_SetString (
248- PyExc_ValueError ,
249- "align_speed_to_angle argument requires an angle to be set" );
250- return -1 ;
251- }
252- else if (emitter -> align_acceleration_to_angle ) {
253- PyErr_SetString (
254- PyExc_ValueError ,
255- "align_acceleration_to_angle argument requires an angle to be set" );
256- return -1 ;
257- }
258- }
259-
260225 return 0 ;
261226}
262227
228+ #define TF (x ) ((x) ? "Yes" : "No")
229+ #define CREATE_PYFLOAT (var , value ) \
230+ var = PyFloat_FromDouble(value); \
231+ if (PyErr_Occurred()) \
232+ goto on_error
233+
263234PyObject *
264235emitter_str (EmitterObject * self )
265236{
266237 Emitter * e = & self -> emitter ;
267238
268- PyObject * py_emission_interval = NULL , * py_emission_time = NULL ,
269- * lifetime_min = NULL , * lifetime_max = NULL , * speed_x_min = NULL ,
270- * speed_x_max = NULL , * speed_y_min = NULL , * speed_y_max = NULL ,
271- * acceleration_x_min = NULL , * acceleration_x_max = NULL ,
272- * acceleration_y_min = NULL , * acceleration_y_max = NULL ,
273- * angle_min = NULL , * angle_max = NULL ;
274-
275- py_emission_interval = PyFloat_FromDouble (e -> emission_interval );
276- if (PyErr_Occurred ())
277- return NULL ;
278-
279- py_emission_time = PyFloat_FromDouble (e -> emission_time );
280- if (PyErr_Occurred ())
281- goto on_error ;
282-
283- lifetime_min = PyFloat_FromDouble (e -> lifetime .min );
284- if (PyErr_Occurred ())
285- goto on_error ;
286-
287- lifetime_max = PyFloat_FromDouble (e -> lifetime .max );
288- if (PyErr_Occurred ())
289- goto on_error ;
290-
291- speed_x_min = PyFloat_FromDouble (e -> speed_x .min );
292- if (PyErr_Occurred ())
293- goto on_error ;
294-
295- speed_x_max = PyFloat_FromDouble (e -> speed_x .max );
296- if (PyErr_Occurred ())
297- goto on_error ;
298-
299- speed_y_min = PyFloat_FromDouble (e -> speed_y .min );
300- if (PyErr_Occurred ())
301- goto on_error ;
302-
303- speed_y_max = PyFloat_FromDouble (e -> speed_y .max );
304- if (PyErr_Occurred ())
305- goto on_error ;
306-
307- acceleration_x_min = PyFloat_FromDouble (e -> acceleration_x .min );
308- if (PyErr_Occurred ())
309- goto on_error ;
310-
311- acceleration_x_max = PyFloat_FromDouble (e -> acceleration_x .max );
312- if (PyErr_Occurred ())
313- goto on_error ;
314-
315- acceleration_y_min = PyFloat_FromDouble (e -> acceleration_y .min );
316- if (PyErr_Occurred ())
317- goto on_error ;
318-
319- acceleration_y_max = PyFloat_FromDouble (e -> acceleration_y .max );
320- if (PyErr_Occurred ())
321- goto on_error ;
322-
323- angle_min = PyFloat_FromDouble (e -> angle .min );
324- if (PyErr_Occurred ())
325- goto on_error ;
326-
327- angle_max = PyFloat_FromDouble (e -> angle .max );
328- if (PyErr_Occurred ())
329- goto on_error ;
239+ PyObject * lifetime_min = NULL ;
240+ PyObject * lifetime_max = NULL ;
241+ PyObject * speed_x_min = NULL ;
242+ PyObject * speed_x_max = NULL ;
243+ PyObject * speed_y_min = NULL ;
244+ PyObject * speed_y_max = NULL ;
245+ PyObject * acceleration_x_min = NULL ;
246+ PyObject * acceleration_x_max = NULL ;
247+ PyObject * acceleration_y_min = NULL ;
248+ PyObject * acceleration_y_max = NULL ;
249+
250+ CREATE_PYFLOAT (lifetime_min , e -> lifetime .min );
251+ CREATE_PYFLOAT (lifetime_max , e -> lifetime .max );
252+ CREATE_PYFLOAT (speed_x_min , e -> speed_x .min );
253+ CREATE_PYFLOAT (speed_x_max , e -> speed_x .max );
254+ CREATE_PYFLOAT (speed_y_min , e -> speed_y .min );
255+ CREATE_PYFLOAT (speed_y_max , e -> speed_y .max );
256+ CREATE_PYFLOAT (acceleration_x_min , e -> acceleration_x .min );
257+ CREATE_PYFLOAT (acceleration_x_max , e -> acceleration_x .max );
258+ CREATE_PYFLOAT (acceleration_y_min , e -> acceleration_y .min );
259+ CREATE_PYFLOAT (acceleration_y_max , e -> acceleration_y .max );
330260
331261 char * spawn_shape_str ;
332262 switch (e -> spawn_shape ) {
@@ -338,7 +268,6 @@ emitter_str(EmitterObject *self)
338268 break ;
339269 }
340270
341- generator * angle = & e -> angle ;
342271 generator * lifetime = & e -> lifetime ;
343272 generator * speed_x = & e -> speed_x ;
344273 generator * speed_y = & e -> speed_y ;
@@ -347,35 +276,21 @@ emitter_str(EmitterObject *self)
347276
348277 PyObject * str = PyUnicode_FromFormat (
349278 "Emitter("
350- "\n spawn_shape=%s,"
351- "\n emission_number=%d,"
352- "\n looping=%s,"
353- "\n emission_interval=%R,"
354- "\n emission_time=%R,"
355- "\n animation=(%d images),"
356- "\n lifetime=(%R, %R, random=%s),"
357- "\n speed_x=(%R, %R, random=%s),"
358- "\n speed_y=(%R, %R, random=%s),"
359- "\n acceleration_x=(%R, %R, random=%s),"
360- "\n acceleration_y=(%R, %R, random=%s),"
361- "\n angle=(%R, %R, random=%s),"
362- "\n align_speed_to_angle=%s,"
363- "\n align_acceleration_to_angle=%s"
279+ "\n spawn_shape: %s"
280+ "\n emission_number: %d"
281+ "\n animation: %d images,"
282+ "\n lifetime: %R to %R rng: %s"
283+ "\n speed_x: %R to %R rng: %s"
284+ "\n speed_y: %R to %R rng: %s"
285+ "\n acceleration_x: %R to %R rng: %s"
286+ "\n acceleration_y: %R to %R rng: %s"
364287 "\n)" ,
365- spawn_shape_str , e -> emission_number , e -> looping ? "True" : "False" ,
366- py_emission_interval , py_emission_time , e -> num_frames , lifetime_min ,
367- lifetime_max , lifetime -> randomize ? "True" : "False" , speed_x_min ,
368- speed_x_max , speed_x -> randomize ? "True" : "False" , speed_y_min , speed_y_max ,
369- speed_y -> randomize ? "True" : "False" , acceleration_x_min ,
370- acceleration_x_max , accel_x -> randomize ? "True" : "False" ,
371- acceleration_y_min , acceleration_y_max ,
372- accel_y -> randomize ? "True" : "False" , angle_min , angle_max ,
373- angle -> randomize ? "True" : "False" ,
374- e -> align_speed_to_angle ? "True" : "False" ,
375- e -> align_acceleration_to_angle ? "True" : "False" );
376-
377- Py_DECREF (py_emission_interval );
378- Py_DECREF (py_emission_time );
288+ spawn_shape_str , e -> emission_number , e -> num_frames , lifetime_min ,
289+ lifetime_max , TF (lifetime -> randomize ), speed_x_min , speed_x_max ,
290+ TF (speed_x -> randomize ), speed_y_min , speed_y_max , TF (speed_y -> randomize ),
291+ acceleration_x_min , acceleration_x_max , TF (accel_x -> randomize ),
292+ acceleration_y_min , acceleration_y_max , TF (accel_y -> randomize ));
293+
379294 Py_DECREF (lifetime_min );
380295 Py_DECREF (lifetime_max );
381296 Py_DECREF (speed_x_min );
@@ -386,14 +301,10 @@ emitter_str(EmitterObject *self)
386301 Py_DECREF (acceleration_x_max );
387302 Py_DECREF (acceleration_y_min );
388303 Py_DECREF (acceleration_y_max );
389- Py_DECREF (angle_min );
390- Py_DECREF (angle_max );
391304
392305 return str ;
393306
394307on_error :
395- Py_XDECREF (py_emission_interval );
396- Py_XDECREF (py_emission_time );
397308 Py_XDECREF (lifetime_min );
398309 Py_XDECREF (lifetime_max );
399310 Py_XDECREF (speed_x_min );
@@ -404,12 +315,13 @@ emitter_str(EmitterObject *self)
404315 Py_XDECREF (acceleration_x_max );
405316 Py_XDECREF (acceleration_y_min );
406317 Py_XDECREF (acceleration_y_max );
407- Py_XDECREF (angle_min );
408- Py_XDECREF (angle_max );
409318
410319 return NULL ;
411320}
412321
322+ #undef TF
323+ #undef CREATE_PYFLOAT
324+
413325void
414326emitter_dealloc (EmitterObject * self )
415327{
0 commit comments