prboomInterface.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. Copyright (C) 2009 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "../doomiphone.h"
  17. int desired_fullscreen;
  18. int usejoystick;
  19. int joyright;
  20. int joyleft;
  21. int joydown;
  22. int joyup;
  23. int gl_colorbuffer_bits;
  24. int gl_depthbuffer_bits;
  25. int snd_card;
  26. int mus_card;
  27. int endoom_mode;
  28. int use_fullscreen;
  29. int snd_samplerate;
  30. int ms_to_next_tick;
  31. int realtic_clock_rate;
  32. /* I_SafeExit
  33. * This function is called instead of exit() by functions that might be called
  34. * during the exit process (i.e. after exit() has already been called)
  35. * Prevent infinitely recursive exits -- killough
  36. *
  37. * JDC: we don't do any atexit() calls on iphone, so this shouldn't be necessary
  38. */
  39. void I_SafeExit(int rc) {
  40. static int has_exited;
  41. if (!has_exited) {
  42. has_exited=rc ? 2 : 1;
  43. exit(rc);
  44. }
  45. }
  46. void I_uSleep( unsigned long usec ) {
  47. usleep( usec );
  48. }
  49. /*
  50. * HasTrailingSlash
  51. *
  52. * cphipps - simple test for trailing slash on dir names
  53. */
  54. boolean HasTrailingSlash(const char* dn)
  55. {
  56. return ( (dn[strlen(dn)-1] == '/') );
  57. }
  58. char* I_FindFile(const char* wfname, const char* ext)
  59. {
  60. char *p = malloc( 1024 );
  61. sprintf( p, "%s/base/%s", SysIphoneGetAppDir(), wfname );
  62. if (access(p,F_OK))
  63. strcat(p, ext); // try adding the extension
  64. if (!access(p,F_OK)) {
  65. lprintf(LO_INFO, " found %s\n", p);
  66. return p;
  67. }
  68. free( p );
  69. return NULL;
  70. #if 0
  71. // lookup table of directories to search
  72. static const struct {
  73. const char *dir; // directory
  74. const char *sub; // subdirectory
  75. const char *env; // environment variable
  76. const char *(*func)(void); // for I_DoomExeDir
  77. } search[] = {
  78. {NULL}, // current working directory
  79. {NULL, NULL, "DOOMWADDIR"}, // run-time $DOOMWADDIR
  80. {DOOMWADDIR}, // build-time configured DOOMWADDIR
  81. {NULL, "doom", "HOME"}, // ~/doom
  82. {NULL, NULL, "HOME"}, // ~
  83. {NULL, NULL, NULL, I_DoomExeDir}, // config directory
  84. {"/usr/local/share/games/doom"},
  85. {"/usr/share/games/doom"},
  86. {"/usr/local/share/doom"},
  87. {"/usr/share/doom"},
  88. };
  89. int i;
  90. /* Precalculate a length we will need in the loop */
  91. size_t pl = strlen(wfname) + strlen(ext) + 4;
  92. for (i = 0; i < sizeof(search)/sizeof(*search); i++) {
  93. char * p;
  94. const char * d = NULL;
  95. const char * s = NULL;
  96. /* Each entry in the switch sets d to the directory to look in,
  97. * and optionally s to a subdirectory of d */
  98. // switch replaced with lookup table
  99. if (search[i].env) {
  100. if (!(d = getenv(search[i].env)))
  101. continue;
  102. } else if (search[i].func)
  103. d = search[i].func();
  104. else
  105. d = search[i].dir;
  106. s = search[i].sub;
  107. p = malloc((d ? strlen(d) : 0) + (s ? strlen(s) : 0) + pl);
  108. sprintf(p, "%s%s%s%s%s", d ? d : "", (d && !HasTrailingSlash(d)) ? "/" : "",
  109. s ? s : "", (s && !HasTrailingSlash(s)) ? "/" : "",
  110. wfname);
  111. if (access(p,F_OK))
  112. strcat(p, ext);
  113. if (!access(p,F_OK)) {
  114. lprintf(LO_INFO, " found %s\n", p);
  115. return p;
  116. }
  117. free(p);
  118. }
  119. return NULL;
  120. #endif
  121. }
  122. boolean I_StartDisplay(void) {
  123. return true;
  124. }
  125. void I_EndDisplay(void) {}
  126. int I_GetTime_RealTime(void) { return 0; }
  127. fixed_t I_GetTimeFrac (void) { return 0; }
  128. void I_GetTime_SaveMS(void) {}
  129. unsigned long I_GetRandomTimeSeed(void) { return 0; }
  130. //const char* I_GetVersionString(char* buf, size_t sz);
  131. //const char* I_SigString(char* buf, size_t sz, int signum);
  132. const char *I_DoomExeDir(void) { return SysIphoneGetAppDir(); }
  133. //void I_SetAffinityMask(void);
  134. /*
  135. * I_Read
  136. *
  137. * cph 2001/11/18 - wrapper for read(2) which handles partial reads and aborts
  138. * on error.
  139. */
  140. void I_Read(int fd, void* vbuf, size_t sz)
  141. {
  142. unsigned char* buf = vbuf;
  143. while (sz) {
  144. int rc = read(fd,buf,sz);
  145. if (rc <= 0) {
  146. I_Error("I_Read: read failed: %s", rc ? strerror(errno) : "EOF");
  147. }
  148. sz -= rc; buf += rc;
  149. }
  150. }
  151. /*
  152. * I_Filelength
  153. *
  154. * Return length of an open file.
  155. */
  156. int I_Filelength(int handle)
  157. {
  158. struct stat fileinfo;
  159. if (fstat(handle,&fileinfo) == -1)
  160. I_Error("I_Filelength: %s",strerror(errno));
  161. return fileinfo.st_size;
  162. }
  163. //
  164. // MUSIC I/O
  165. //
  166. void I_InitMusic(void) {}
  167. void I_ShutdownMusic(void) {}
  168. void I_UpdateMusic(void) {}
  169. // Volume.
  170. void I_SetMusicVolume(int volume) {}
  171. // PAUSE game handling.
  172. void I_PauseSong(int handle) {}
  173. void I_ResumeSong(int handle) {}
  174. // Registers a song handle to song data.
  175. int I_RegisterSong(const void *data, size_t len) {
  176. return 0;
  177. }
  178. // cournia - tries to load a music file
  179. int I_RegisterMusic( const char* filename, musicinfo_t *music ) {
  180. return 0;
  181. }
  182. // Called by anything that wishes to start music.
  183. // plays a song, and when the song is done,
  184. // starts playing it again in an endless loop.
  185. // Horrible thing to do, considering.
  186. void I_PlaySong(int handle, int looping) {
  187. }
  188. // Stops a song over 3 seconds.
  189. void I_StopSong(int handle) {
  190. }
  191. // See above (register), then think backwards
  192. void I_UnRegisterSong(int handle) {
  193. }
  194. void I_PreInitGraphics(void){}
  195. void I_CalculateRes(unsigned int width, unsigned int height){}
  196. void I_ShutdownGraphics(void){}
  197. void I_SetPalette(int pal){}
  198. void I_UpdateNoBlit (void){}
  199. void I_FinishUpdate (void){}
  200. int I_ScreenShot (const char *fname){return 0;}
  201. // CPhipps -
  202. // I_SetRes
  203. // Sets the screen resolution
  204. void I_SetRes(void)
  205. {
  206. int i;
  207. I_CalculateRes(SCREENWIDTH, SCREENHEIGHT);
  208. // set first three to standard values
  209. for (i=0; i<3; i++) {
  210. screens[i].width = SCREENWIDTH;
  211. screens[i].height = SCREENHEIGHT;
  212. screens[i].byte_pitch = SCREENPITCH;
  213. screens[i].short_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE16);
  214. screens[i].int_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE32);
  215. }
  216. // statusbar
  217. screens[4].width = SCREENWIDTH;
  218. screens[4].height = (ST_SCALED_HEIGHT+1);
  219. screens[4].byte_pitch = SCREENPITCH;
  220. screens[4].short_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE16);
  221. screens[4].int_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE32);
  222. lprintf(LO_INFO,"I_SetRes: Using resolution %dx%d\n", SCREENWIDTH, SCREENHEIGHT);
  223. }
  224. void I_UpdateVideoMode(void)
  225. {
  226. lprintf(LO_INFO, "I_UpdateVideoMode: %dx%d\n", SCREENWIDTH, SCREENHEIGHT );
  227. V_InitMode(VID_MODEGL);
  228. I_SetRes();
  229. #if 0
  230. screens[0].not_on_heap = true;
  231. screens[0].data = NULL;
  232. screens[0].byte_pitch = screen->pitch;
  233. screens[0].short_pitch = screen->pitch / V_GetModePixelDepth(VID_MODE16);
  234. screens[0].int_pitch = screen->pitch / V_GetModePixelDepth(VID_MODE32);
  235. #endif
  236. V_AllocScreens();
  237. R_InitBuffer(SCREENWIDTH, SCREENHEIGHT);
  238. gld_Init(SCREENWIDTH, SCREENHEIGHT);
  239. }
  240. void I_InitGraphics(void)
  241. {
  242. char titlebuffer[2048];
  243. static int firsttime=1;
  244. SCREENWIDTH = displaywidth;
  245. SCREENHEIGHT = displayheight;
  246. if (firsttime)
  247. {
  248. firsttime = 0;
  249. atexit(I_ShutdownGraphics);
  250. lprintf(LO_INFO, "I_InitGraphics: %dx%d\n", SCREENWIDTH, SCREENHEIGHT);
  251. /* Set the video mode */
  252. I_UpdateVideoMode();
  253. /* Setup the window title */
  254. strcpy(titlebuffer,PACKAGE);
  255. strcat(titlebuffer," ");
  256. strcat(titlebuffer,VERSION);
  257. // SDL_WM_SetCaption(titlebuffer, titlebuffer);
  258. /* Initialize the input system */
  259. // I_InitInputs();
  260. }
  261. }
  262. /* I_StartTic
  263. * Called by D_DoomLoop,
  264. * called before processing each tic in a frame.
  265. * Quick syncronous operations are performed here.
  266. * Can call D_PostEvent.
  267. */
  268. void I_StartTic (void){}
  269. /* I_StartFrame
  270. * Called by D_DoomLoop,
  271. * called before processing any tics in a frame
  272. * (just after displaying a frame).
  273. * Time consuming syncronous operations
  274. * are performed here (joystick reading).
  275. * Can call D_PostEvent.
  276. */
  277. void I_StartFrame (void){}
  278. void I_Init(){}
  279. unsigned int SDL_GetTicks() { return 0; };
  280. int (*I_GetTime)(void) = I_GetTime_RealTime;