iphone_main.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
  4. Copyright (C) 1997-2001 Id Software, Inc.
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. See the GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. doom
  19. ----
  20. modifications to config.h
  21. don't add the d_ipxgate.c file
  22. don't add d_server.c file
  23. don't add mmus2mid.[ch] files
  24. don't add w_memcache.c, use w_mmap.c instead
  25. added new SDL_opengl.h, changed code files from <SDL_opengl.h> to "SDL_opengl.h"
  26. commented out #include <SDL.h>
  27. Commented out the static on D_DoomMainSetup();
  28. Add define HAVE_CONFIG_H to the target settings
  29. Add define _DEBUG
  30. #if around uses of GL_TEXTURE_RESIDENT in gl_texture.c
  31. // JDC: not in GLES, not needed since it is the default condition glDisable(GL_POLYGON_SMOOTH);
  32. // JDC #define USE_VERTEX_ARRAYS in gl_main.c
  33. add the iphoneRotateForLandscape calls
  34. static JDC removed short consistancy[MAXPLAYERS][BACKUPTICS];
  35. // JDC glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  36. // JDC glDisableClientState(GL_VERTEX_ARRAY);
  37. #ifdef IPHONE // JDC
  38. #define MAX_SCREENWIDTH 480
  39. #define MAX_SCREENHEIGHT 320
  40. #else
  41. code notes
  42. ----------
  43. all the fixed point mess
  44. goofy polar clipping
  45. path traverse should have used a BSP tree
  46. rename vldoor_e close and open enums to not conflict with unistd
  47. opengl_error_break
  48. WiFi internet play
  49. ---------
  50. voip instead of key chat
  51. extra asset work
  52. ----------------------
  53. perfect weapon scales
  54. demo of each level?
  55. additive art separation -- attacks, buttons, etc
  56. tuned option
  57. ------------
  58. last kill / last secret / last item messages
  59. more achievements in general
  60. better item pickup sounds
  61. scale blood spray with distance
  62. easier item pickup
  63. crosshair
  64. better movement clipping to walls
  65. better key pickup sound
  66. textured automap
  67. better low health warning
  68. better feedback on where bullets hit
  69. better bob cycle when going down stairs
  70. map item should also show all monsters and items to make it cool
  71. barrels explode easier
  72. wave FOV when berzerk
  73. pistol shots are useless in deathmatch
  74. show opponent / enemy health when attacking them?
  75. cpu optimizations
  76. -------------
  77. convert to 16 bit vertex data
  78. void gld_BindPatch(GLTexture *gltexture, int cm) is expensive
  79. fixedMul / fixedDiv in asm (negligable performance gain)
  80. atlas all of the non-character items (and bodies?)
  81. remove the pitch changes from sound?
  82. gpu optimizations
  83. ------------------
  84. use fog instead of full screen blend for damage/pickup flash (3 msec on IP3G)
  85. pvrtc walls and floors
  86. art needed
  87. ----------
  88. new map / menu button
  89. awards on medals
  90. icon
  91. thumbsticks
  92. settings gears
  93. must do
  94. -------
  95. pause music in menu
  96. timelimit carry over to new levels
  97. server going to demo causes client to crash
  98. fixed 10/13/09
  99. --------------
  100. recover from sound interruption
  101. caps for slider bar text
  102. reset defaults doesn't reset reverse-landscape
  103. pause music when going to the menu
  104. reset timelimit each level on deathmatch
  105. disable demos, new game, and web site during multiplayer
  106. fixed
  107. -----
  108. automap / menu button actions with multi-thread
  109. capitalized "game saved."
  110. Added punctuation to "Ned a blue keycard", etc
  111. added "defaults" button in options
  112. todo
  113. ----
  114. don't accept fire from an owned touch?
  115. text scaling in buttons isn't perfect
  116. better view angle transport
  117. audio bugs
  118. rotor control shouldn't be dimmed
  119. volume button hack?
  120. change background color for networking
  121. tapping weapon change to cycle
  122. is openal thread safe? we issue touch clicks from asynctic
  123. disable multiplayer button if no ethernet addresses found
  124. touch latching issues
  125. add one tic latency to server?
  126. select new game while in netgame
  127. multiplayer arrow colors
  128. remove players with stale joins
  129. rocket explosion offset
  130. texture preload status bar stuff and blood / impacts
  131. stereo panning for headphones
  132. directly build 16 bit textures instead of translating from 32 bit
  133. texture wrap seam after end of e3m8
  134. sliders should be touch-latch controls
  135. respawn flash sounds sometimes not playing?
  136. don't allow starting on secret levels
  137. loaded savegame spot on different level didn't get view height on first frame
  138. use graphic?
  139. don't ever close doors with auto-use
  140. separators in map select
  141. rotor speed adjust
  142. check all powerup effects
  143. remove uses of prboom.wad?
  144. check patch outlining code
  145. flash all controls on initial level load
  146. touch sounds when cancelling demo playback
  147. play sound on respawn
  148. catch memory warning, purge textures
  149. use wad sound data
  150. stop sound cleanly
  151. entire gun doesn't get fullbright with muzzle flash
  152. require four touches in line for console
  153. restartable pwad interface
  154. somewhat normal based lighting on walls
  155. help menu
  156. visual tilt indicator
  157. tilt draw the turnstick when active
  158. console
  159. */
  160. #include "../doomiphone.h"
  161. cvar_t *skill;
  162. cvar_t *episode;
  163. cvar_t *controlScheme;
  164. cvar_t *stickTurn;
  165. cvar_t *stickMove;
  166. cvar_t *stickDeadBand;
  167. cvar_t *rotorTurn;
  168. cvar_t *tiltTurn;
  169. cvar_t *tiltMove;
  170. cvar_t *tiltDeadBand;
  171. cvar_t *tiltAverages;
  172. cvar_t *miniNet;
  173. cvar_t *music;
  174. cvar_t *showTilt;
  175. cvar_t *showTime;
  176. cvar_t *showNet;
  177. cvar_t *showSound;
  178. cvar_t *cropSprites;
  179. cvar_t *revLand;
  180. cvar_t *mapScale;
  181. cvar_t *drawControls;
  182. cvar_t *autoUse;
  183. cvar_t *statusBar;
  184. cvar_t *touchClick;
  185. cvar_t *messages;
  186. cvar_t *timeLimit;
  187. cvar_t *fragLimit;
  188. cvar_t *mpDeathmatch;
  189. cvar_t *mpSkill;
  190. cvar_t *mpDataset;
  191. cvar_t *mpEpisode;
  192. cvar_t *mpMap;
  193. cvar_t *noBlend;
  194. cvar_t *glfinish;
  195. cvar_t *mapSelectY;
  196. cvar_t *throttle;
  197. cvar_t *centerSticks;
  198. cvar_t *rampTurn;
  199. cvar_t *netBuffer;
  200. #define VERSION_BCONFIG ( 0x89490000 + sizeof( huds ) + sizeof( playState ) )
  201. void Sys_Error( const char *format, ... )
  202. {
  203. va_list argptr;
  204. char string[ 1024 ];
  205. va_start( argptr, format );
  206. (void)vsnprintf( string, sizeof( string ), format, argptr );
  207. va_end( argptr );
  208. fprintf( stderr, "Error: %s\n", string );
  209. _exit( 1 );
  210. }
  211. #define plyr (players+consoleplayer) /* the console player */
  212. void Give_f() {
  213. plyr->armorpoints = idfa_armor; // Ty 03/09/98 - deh
  214. plyr->armortype = idfa_armor_class; // Ty 03/09/98 - deh
  215. // You can't own weapons that aren't in the game // phares 02/27/98
  216. for (int i=0;i<NUMWEAPONS;i++)
  217. if (!(((i == wp_plasma || i == wp_bfg) && gamemode == shareware) ||
  218. (i == wp_supershotgun && gamemode != commercial)))
  219. plyr->weaponowned[i] = true;
  220. for (int i=0;i<NUMAMMO;i++)
  221. if (i!=am_cell || gamemode!=shareware)
  222. plyr->ammo[i] = plyr->maxammo[i];
  223. plyr->message = s_STSTR_FAADDED;
  224. for (int i=0;i<NUMCARDS;i++)
  225. if (!plyr->cards[i]) // only print message if at least one key added
  226. { // however, caller may overwrite message anyway
  227. plyr->cards[i] = true;
  228. }
  229. }
  230. void God_f() {
  231. plyr->cheats ^= CF_GODMODE;
  232. if (plyr->cheats & CF_GODMODE)
  233. {
  234. if (plyr->mo)
  235. plyr->mo->health = god_health; // Ty 03/09/98 - deh
  236. plyr->health = god_health;
  237. plyr->message = s_STSTR_DQDON; // Ty 03/27/98 - externalized
  238. }
  239. else
  240. plyr->message = s_STSTR_DQDOFF; // Ty 03/27/98 - externalized
  241. }
  242. void ResetMaps_f() {
  243. playState.numMapStats = 0;
  244. memset( playState.mapStats, 0, sizeof( playState.mapStats ) );
  245. }
  246. /*
  247. ==================
  248. iphoneStartup
  249. ==================
  250. */
  251. struct addrinfo *addrinfoHead;
  252. void D_DoomMainSetup();
  253. void iphoneStartup() {
  254. int start = SysIphoneMilliseconds();
  255. // print networking information
  256. ReportNetworkInterfaces();
  257. // microseconds will be plenty random for playerID and localGameID
  258. playerID = localGameID = SysIphoneMicroseconds();
  259. InitImmediateModeGL();
  260. // init OpenAL before pak file, so the pak file can
  261. // make all the al static buffers
  262. Sound_Init();
  263. // get our new-style pak file
  264. char pakFile[1024];
  265. sprintf( pakFile, "%s/base/base.iPack", SysIphoneGetAppDir() );
  266. PK_Init( pakFile );
  267. // register console commands
  268. Cmd_AddCommand( "listcvars", Cvar_List_f );
  269. Cmd_AddCommand( "resetcvars", Cvar_Reset_f );
  270. Cmd_AddCommand( "resetmaps", ResetMaps_f );
  271. Cmd_AddCommand( "listcmds", Cmd_ListCommands_f );
  272. Cmd_AddCommand( "give", Give_f );
  273. Cmd_AddCommand( "god", God_f );
  274. Cmd_AddCommand( "mail", EmailConsole ); //gsh, mails the console to id
  275. // register console variables
  276. Cvar_Get( "version", va( "%3.1f %s %s", DOOM_IPHONE_VERSION, __DATE__, __TIME__ ), 0 );
  277. skill = Cvar_Get( "skill", "1", CVAR_ARCHIVE );
  278. episode = Cvar_Get( "episode", "0", CVAR_ARCHIVE );
  279. controlScheme = Cvar_Get( "controlScheme", "0", CVAR_ARCHIVE );
  280. stickTurn = Cvar_Get( "stickTurn", "128", CVAR_ARCHIVE );
  281. stickMove = Cvar_Get( "stickMove", "128", CVAR_ARCHIVE );
  282. stickDeadBand = Cvar_Get( "stickDeadBand", "0.05", CVAR_ARCHIVE );
  283. rotorTurn = Cvar_Get( "rotorTurn", "50000", CVAR_ARCHIVE );
  284. tiltTurn = Cvar_Get( "tiltTurn", "0", CVAR_ARCHIVE );
  285. tiltMove = Cvar_Get( "tiltMove", "0", CVAR_ARCHIVE );
  286. tiltDeadBand = Cvar_Get( "tiltDeadBand", "0.08", CVAR_ARCHIVE );
  287. tiltAverages = Cvar_Get( "tiltAverages", "3", CVAR_ARCHIVE );
  288. centerSticks = Cvar_Get( "centerSticks", "1", CVAR_ARCHIVE );
  289. rampTurn = Cvar_Get( "rampTurn", "1", CVAR_ARCHIVE );
  290. music = Cvar_Get( "music", "1", CVAR_ARCHIVE );
  291. cropSprites = Cvar_Get( "cropSprites", "1", 0 );
  292. revLand = Cvar_Get( "revLand", "0", CVAR_ARCHIVE );
  293. mapScale = Cvar_Get( "mapScale", "10", CVAR_ARCHIVE );
  294. drawControls = Cvar_Get( "drawControls", "1", CVAR_ARCHIVE );
  295. autoUse = Cvar_Get( "autoUse", "1", CVAR_ARCHIVE );
  296. statusBar = Cvar_Get( "statusBar", "1", CVAR_ARCHIVE );
  297. touchClick = Cvar_Get( "touchClick", "0.15", CVAR_ARCHIVE );
  298. messages = Cvar_Get( "messages", "1", CVAR_ARCHIVE );
  299. mapSelectY = Cvar_Get( "mapSelectY", "0", CVAR_ARCHIVE );
  300. miniNet = Cvar_Get( "miniNet", "1", CVAR_ARCHIVE );
  301. // multiplayer setup
  302. timeLimit = Cvar_Get( "timeLimit", "0", CVAR_ARCHIVE );
  303. fragLimit = Cvar_Get( "fragLimit", "5", CVAR_ARCHIVE );
  304. mpDeathmatch = Cvar_Get( "mpDeathmatch", "0", CVAR_ARCHIVE );
  305. mpDataset = Cvar_Get( "mpDataset", "0", CVAR_ARCHIVE );
  306. mpEpisode = Cvar_Get( "mpEpisode", "1", CVAR_ARCHIVE );
  307. mpSkill = Cvar_Get( "mpSkill", "1", CVAR_ARCHIVE );
  308. mpMap = Cvar_Get( "mpMap", "1", CVAR_ARCHIVE );
  309. // debug tools
  310. showTilt = Cvar_Get( "showTilt", "-1", 0 );
  311. showTime = Cvar_Get( "showTime", "0", 0 );
  312. showNet = Cvar_Get( "showNet", "0", 0 );
  313. showSound = Cvar_Get( "showSound", "0", 0 );
  314. noBlend = Cvar_Get( "noBlend", "0", 0 ); // disable the damae blends for screenshots
  315. glfinish = Cvar_Get( "glfinish", "0", 0 );
  316. throttle = Cvar_Get( "throttle", "1", 0 ); // network packet throttle enable
  317. netBuffer = Cvar_Get( "netBuffer", "4", 0 ); // max tics to buffer ahead
  318. // load the archived cvars
  319. Cmd_ExecuteFile( va( "%s/config.cfg", SysIphoneGetDocDir() ) );
  320. // make sure volume changes and incoming calls draw the right orientation
  321. SysIPhoneSetUIKitOrientation( revLand->value );
  322. // start the intro music if it wasn't disabled with the music cvar
  323. iphonePlayMusic( "intro" );
  324. // iphonePlayMusic( "e1m1" );
  325. // these should get overwritten by the config loading
  326. memset( &playState, 0, sizeof( playState ) );
  327. playState.map.skill = 1;
  328. playState.map.episode = 1;
  329. playState.map.map = 1;
  330. HudSetForScheme( 0 );
  331. // load the binary config file
  332. FILE *f = fopen( va( "%s/binaryConfig.bin", SysIphoneGetDocDir() ), "rb" );
  333. if ( f ) {
  334. int version;
  335. version = 0;
  336. fread( &version, 1, sizeof( version ), f );
  337. if ( version != VERSION_BCONFIG ) {
  338. Com_Printf( "Binary config file bad version.\n" );
  339. } else {
  340. fread( &playState, 1, sizeof( playState ), f );
  341. fread( &huds, 1, sizeof( huds ), f );
  342. version = 0;
  343. fread( &version, 1, sizeof( version ), f );
  344. if ( version != VERSION_BCONFIG ) {
  345. Com_Error( "Binary config file bad trailing version.\n" );
  346. }
  347. }
  348. fclose( f );
  349. }
  350. Com_Printf( "startup time: %i msec\n", SysIphoneMilliseconds() - start );
  351. start = SysIphoneMilliseconds();
  352. // the texnums might have been different in the savegame
  353. HudSetTexnums();
  354. arialFontTexture = PK_FindTexture( "iphone/arialImageLAL.tga" );
  355. Com_Printf( "preloadBeforePlay(): %i msec\n", SysIphoneMilliseconds() - start );
  356. Com_Printf( "---------- D_DoomMain ----------\n" );
  357. D_DoomMainSetup();
  358. // put savegames here
  359. strcpy( basesavegame, SysIphoneGetDocDir() );
  360. // prBoom seems to draw the static pic screens without setting up 2D, causing
  361. // a bad first frame
  362. iphoneSet2D();
  363. menuState = IPM_MAIN;
  364. lastState = IPM_MAIN;
  365. #if 0
  366. // jump right to the save spot for debugging
  367. ResumeGame();
  368. #endif
  369. }
  370. /*
  371. ==================
  372. iphoneShutdown
  373. Write out configs and save the game at this position
  374. ==================
  375. */
  376. void iphoneShutdown() {
  377. FILE *fp;
  378. char path[1024];
  379. cvar_t *var;
  380. char buffer[1024];
  381. if( lastState == IPM_GAME ) {
  382. G_DoSaveGame( false );
  383. }
  384. // write the ascii config file
  385. snprintf( path, sizeof( path ), "%s/config.cfg", SysIphoneGetDocDir() );
  386. fp = fopen( path, "w" );
  387. if( ! fp ) {
  388. Com_Printf( "Could not write config.cfg.\n" );
  389. return;
  390. }
  391. // write out commands to set the archived cvars
  392. for( var = cvar_vars ; var ; var = var->next ) {
  393. if( var->flags & CVAR_ARCHIVE ) {
  394. snprintf( buffer, sizeof( buffer ), "%s %s\n", var->name, var->string );
  395. fprintf( fp, "%s", buffer );
  396. Com_Printf( "%s", buffer );
  397. }
  398. }
  399. fclose( fp );
  400. // write the binary config file
  401. FILE *f = fopen( va( "%s/binaryConfig.bin", SysIphoneGetDocDir() ), "wb" );
  402. if ( !f ) {
  403. Com_Printf( "Could not write binaryConfig.cfg.\n" );
  404. return;
  405. }
  406. int version = VERSION_BCONFIG;
  407. fwrite( &version, 1, sizeof( version ), f );
  408. fwrite( &playState, 1, sizeof( playState ), f );
  409. fwrite( &huds, 1, sizeof( huds ), f );
  410. fwrite( &version, 1, sizeof( version ), f );
  411. fclose( f );
  412. }