Skip to content

Commit

Permalink
Remove some C garbage.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanAlbert committed May 1, 2024
1 parent 932bceb commit 3153659
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions native-activity/app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct SavedState {
* Shared state for our app.
*/
struct Engine {
struct android_app* app;
android_app* app;

ASensorManager* sensorManager;
const ASensor* accelerometerSensor;
Expand All @@ -89,7 +89,7 @@ struct Engine {
EGLContext context;
int32_t width;
int32_t height;
struct SavedState state;
SavedState state;

void CreateSensorListener(ALooper_callbackFunc callback) {
CHECK_NOT_NULL(app);
Expand All @@ -109,7 +109,7 @@ struct Engine {
/**
* Initialize an EGL context for the current display.
*/
static int engine_init_display(struct Engine* engine) {
static int engine_init_display(Engine* engine) {
// initialize OpenGL ES and EGL

/*
Expand Down Expand Up @@ -209,7 +209,7 @@ static int engine_init_display(struct Engine* engine) {
/**
* Just the current frame in the display.
*/
static void engine_draw_frame(struct Engine* engine) {
static void engine_draw_frame(Engine* engine) {
if (engine->display == nullptr) {
// No display.
return;
Expand All @@ -226,7 +226,7 @@ static void engine_draw_frame(struct Engine* engine) {
/**
* Tear down the EGL context currently associated with the display.
*/
static void engine_term_display(struct Engine* engine) {
static void engine_term_display(Engine* engine) {
if (engine->display != EGL_NO_DISPLAY) {
eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT);
Expand All @@ -247,9 +247,9 @@ static void engine_term_display(struct Engine* engine) {
/**
* Process the next input event.
*/
static int32_t engine_handle_input(struct android_app* app,
static int32_t engine_handle_input(android_app* app,
AInputEvent* event) {
auto* engine = (struct Engine*)app->userData;
auto* engine = (Engine*)app->userData;
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
engine->animating = 1;
engine->state.x = AMotionEvent_getX(event, 0);
Expand All @@ -262,14 +262,14 @@ static int32_t engine_handle_input(struct android_app* app,
/**
* Process the next main command.
*/
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
auto* engine = (struct Engine*)app->userData;
static void engine_handle_cmd(android_app* app, int32_t cmd) {
auto* engine = (Engine*)app->userData;
switch (cmd) {
case APP_CMD_SAVE_STATE:
// The system has asked us to save our current state. Do so.
engine->app->savedState = malloc(sizeof(struct SavedState));
*((struct SavedState*)engine->app->savedState) = engine->state;
engine->app->savedStateSize = sizeof(struct SavedState);
engine->app->savedState = malloc(sizeof(SavedState));
*((SavedState*)engine->app->savedState) = engine->state;
engine->app->savedStateSize = sizeof(SavedState);
break;
case APP_CMD_INIT_WINDOW:
// The window is being shown, get it ready.
Expand Down Expand Up @@ -311,7 +311,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {

int OnSensorEvent(int /* fd */, int /* events */, void* data) {
CHECK_NOT_NULL(data);
Engine* engine = reinterpret_cast<struct Engine*>(data);
Engine* engine = reinterpret_cast<Engine*>(data);

CHECK_NOT_NULL(engine->accelerometerSensor);
ASensorEvent event;
Expand All @@ -332,8 +332,8 @@ int OnSensorEvent(int /* fd */, int /* events */, void* data) {
* android_native_app_glue. It runs in its own thread, with its own
* event loop for receiving input events and doing other things.
*/
void android_main(struct android_app* state) {
struct Engine engine {};
void android_main(android_app* state) {
Engine engine {};

memset(&engine, 0, sizeof(engine));
state->userData = &engine;
Expand All @@ -346,15 +346,15 @@ void android_main(struct android_app* state) {

if (state->savedState != nullptr) {
// We are starting with a previous saved state; restore from it.
engine.state = *(struct SavedState*)state->savedState;
engine.state = *(SavedState*)state->savedState;
}

// loop waiting for stuff to do.

while (true) {
// Read all pending events.
int events;
struct android_poll_source* source;
android_poll_source* source;

// If not animating, we will block forever waiting for events.
// If animating, we loop until all events are read, then continue
Expand Down

0 comments on commit 3153659

Please sign in to comment.