|
SDLGameEngine
|
00001 /* 00002 * Copyright (c) 2007 Heiko Irrgang 00003 * 00004 * The license and distribution terms for this file may be 00005 * found in the file COPYING in this distribution or at 00006 * http://93-interactive.com/cms/products/software/sdl-game-engine/license/ 00007 */ 00008 00009 #include <sge.h> 00010 00011 SDL_Joystick *defaultjoystick; 00012 00013 void sgeInit(int useAudio, int useJoystick) { 00014 time_t now; 00015 Uint32 flags=SDL_INIT_VIDEO|SDL_INIT_TIMER; 00016 if (useAudio) flags|=SDL_INIT_AUDIO; 00017 #ifdef GP2X 00018 flags|=SDL_INIT_JOYSTICK; // force joystick on gp2x 00019 useJoystick=1; 00020 #else 00021 if (useJoystick) flags|=SDL_INIT_JOYSTICK; 00022 #endif 00023 00024 if (SDL_Init (flags) < 0) { 00025 sgeBailOut("cannot initialize SDL: %s\n", SDL_GetError ()); 00026 } 00027 atexit(sgeTerminate); 00028 00029 if (useJoystick) { 00030 if (SDL_NumJoysticks() > 0) { 00031 defaultjoystick = SDL_JoystickOpen(0); 00032 if(!defaultjoystick) { 00033 fprintf (stderr, "cannot open joystick 0: %s\n", SDL_GetError ()); 00034 } 00035 } 00036 } 00037 00038 if (useAudio) { 00039 if (Mix_OpenAudio(sgeGetDefaultSampleRate(), MIX_DEFAULT_FORMAT, 2, 2048)==-1) { 00040 sgeBailOut("cannot initialize iibmixer: %s\n", Mix_GetError()); 00041 } 00042 } 00043 00044 time(&now); 00045 srand((unsigned int)now); 00046 } 00047 00048 void sgeTerminate() { 00049 if (SDL_WasInit(SDL_INIT_AUDIO)) { 00050 Mix_HaltChannel(-1); 00051 #ifndef MORPHOS 00052 Mix_CloseAudio(); 00053 #endif 00054 } 00055 SDL_Quit(); 00056 #ifdef GP2X 00057 chdir("/usr/gp2x"); 00058 execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL); 00059 #endif 00060 } 00061 00062 extern int run(int argc, char *argv[]); 00063 int main(int argc, char *argv[]) { 00064 return run(argc, argv); 00065 }