#ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" #endif #include "Core.hpp" extern "C" void iPhoneFrame(void *) { core.doProcess(); } /* handleAppEvents This function is used with SDL_SetEventFilter to intercept important events related to RtB entering the background and similar on mobile devices. If we do not handle the events in this fashion, RtB will terminate */ extern "C" int handleAppEvents(void *userdata, SDL_Event *event) { switch (event->type) { case SDL_APP_TERMINATING: core.closeSystem(); // TODO: close everything break; case SDL_APP_LOWMEMORY: // TODO: not sure? free memory? break; case SDL_APP_WILLENTERBACKGROUND: // TODO: pause loops. activated when "home" is hit or a call is recv'd break; case SDL_APP_DIDENTERBACKGROUND: core.closeSystem(); // TODO: occurs if WILLENTER was accepted. Have to save state? break; case SDL_APP_WILLENTERFOREGROUND: // TODO: occurs when app comes back, either from reactivation or if WILLENTER is denied. Restore state? break; case SDL_APP_DIDENTERFOREGROUND: // TODO: restart loops. break; default: // Add event to the standard event stack return 1; break; } return 0; } int main(int argc, char *argv[]) { #ifdef __APPLE__ char path[PATH_MAX]; CFURLRef res = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); CFURLGetFileSystemRepresentation(res, TRUE, (UInt8 *)path, PATH_MAX); CFRelease(res); chdir(path); #endif core.initSystem(); SDL_SetEventFilter(handleAppEvents, NULL); #if __IPHONEOS__ //InitGameCenter(); SDL_iPhoneSetAnimationCallback(core.getWindow(), 1, iPhoneFrame, 0); #else // begin our main loop while (core.flags & Core::IS_RUNNING) { core.doProcess(); SDL_Delay(1); } core.closeSystem(); #endif return 0; }