#define SDL_MAIN_USE_CALLBACKS #include #include #include #include "src/Game.h" /* This function runs once at startup. */ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; SDL_SetAppMetadata("Example Input Joystick Polling", "1.0", "com.example.input-joystick-polling"); if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) { SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); return SDL_APP_FAILURE; } if (!SDL_CreateWindowAndRenderer("Witch-Game", 640, 480, SDL_WINDOW_RESIZABLE, &window, &renderer)) { SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); return SDL_APP_FAILURE; } *appstate = new Game(window, renderer); return SDL_APP_CONTINUE; /* carry on with the program! */ } /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) { Game* game = (Game*) appstate; switch(event->type) { case SDL_EVENT_QUIT: return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ case SDL_EVENT_KEY_DOWN: game->HandleKeyboardInput(*event); break; case SDL_EVENT_KEY_UP: game->HandleKeyboardInput(*event); break; case SDL_EVENT_GAMEPAD_ADDED: game->AddGamepad(event->gdevice.which); break; case SDL_EVENT_GAMEPAD_REMOVED: game->RemoveGamepad(event->gdevice.which); break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: game->HandleGamepadButton(*event); break; case SDL_EVENT_GAMEPAD_BUTTON_UP: game->HandleGamepadButton(*event); break; case SDL_EVENT_GAMEPAD_AXIS_MOTION: game->HandleGamepadAxis(*event); break; } return SDL_APP_CONTINUE; /* carry on with the program! */ } /* This function runs once per frame, and is the heart of the program. */ SDL_AppResult SDL_AppIterate(void *appstate) { Game* game = (Game*) appstate; game ->Run(); return SDL_APP_CONTINUE; /* carry on with the program! */ } /* This function runs once at shutdown. */ void SDL_AppQuit(void *appstate, SDL_AppResult result) { delete (Game*)appstate; /* SDL will clean up the window/renderer for us. */ }