@@ -83,7 +83,6 @@ struct Engine {
83
83
const ASensor* accelerometerSensor;
84
84
ASensorEventQueue* sensorEventQueue;
85
85
86
- int animating;
87
86
EGLDisplay display;
88
87
EGLSurface surface;
89
88
EGLContext context;
@@ -104,6 +103,19 @@ struct Engine {
104
103
sensorEventQueue = ASensorManager_createEventQueue (
105
104
sensorManager, app->looper , ALOOPER_POLL_CALLBACK, callback, this );
106
105
}
106
+
107
+ bool animating () const { return animating_; }
108
+
109
+ void StartRendering () {
110
+ animating_ = true ;
111
+ }
112
+
113
+ void StopRendering () {
114
+ animating_ = false ;
115
+ }
116
+
117
+ private:
118
+ bool animating_;
107
119
};
108
120
109
121
/* *
@@ -238,7 +250,7 @@ static void engine_term_display(Engine* engine) {
238
250
}
239
251
eglTerminate (engine->display );
240
252
}
241
- engine->animating = 0 ;
253
+ engine->StopRendering () ;
242
254
engine->display = EGL_NO_DISPLAY;
243
255
engine->context = EGL_NO_CONTEXT;
244
256
engine->surface = EGL_NO_SURFACE;
@@ -251,7 +263,7 @@ static int32_t engine_handle_input(android_app* app,
251
263
AInputEvent* event) {
252
264
auto * engine = (Engine*)app->userData ;
253
265
if (AInputEvent_getType (event) == AINPUT_EVENT_TYPE_MOTION) {
254
- engine->animating = 1 ;
266
+ engine->StartRendering () ;
255
267
engine->state .x = AMotionEvent_getX (event, 0 );
256
268
engine->state .y = AMotionEvent_getY (event, 0 );
257
269
return 1 ;
@@ -300,8 +312,7 @@ static void engine_handle_cmd(android_app* app, int32_t cmd) {
300
312
ASensorEventQueue_disableSensor (engine->sensorEventQueue ,
301
313
engine->accelerometerSensor );
302
314
}
303
- // Also stop animating.
304
- engine->animating = 0 ;
315
+ engine->StopRendering ();
305
316
engine_draw_frame (engine);
306
317
break ;
307
318
default :
@@ -356,10 +367,10 @@ void android_main(android_app* state) {
356
367
int events;
357
368
android_poll_source* source;
358
369
359
- // If not animating , we will block forever waiting for events.
360
- // If animating , we loop until all events are read, then continue
370
+ // If not animating_ , we will block forever waiting for events.
371
+ // If animating_ , we loop until all events are read, then continue
361
372
// to draw the next frame of animation.
362
- while ((ALooper_pollAll (engine.animating ? 0 : -1 , nullptr , &events,
373
+ while ((ALooper_pollAll (engine.animating () ? 0 : -1 , nullptr , &events,
363
374
(void **)&source)) >= 0 ) {
364
375
// Process this event.
365
376
if (source != nullptr ) {
@@ -373,7 +384,7 @@ void android_main(android_app* state) {
373
384
}
374
385
}
375
386
376
- if (engine.animating ) {
387
+ if (engine.animating () ) {
377
388
// Done with events; draw next animation frame.
378
389
engine.state .angle += .01f ;
379
390
if (engine.state .angle > 1 ) {
0 commit comments