iphone_main.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /*
  2. Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
  3. Copyright (C) 1997-2001 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.
  11. See the 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. /*
  17. doom
  18. ----
  19. modifications to config.h
  20. don't add the d_ipxgate.c file
  21. don't add d_server.c file
  22. don't add mmus2mid.[ch] files
  23. don't add w_memcache.c, use w_mmap.c instead
  24. added new SDL_opengl.h, changed code files from <SDL_opengl.h> to "SDL_opengl.h"
  25. commented out #include <SDL.h>
  26. Commented out the static on D_DoomMainSetup();
  27. Add define HAVE_CONFIG_H to the target settings
  28. Add define _DEBUG
  29. #if around uses of GL_TEXTURE_RESIDENT in gl_texture.c
  30. // JDC: not in GLES, not needed since it is the default condition glDisable(GL_POLYGON_SMOOTH);
  31. // JDC #define USE_VERTEX_ARRAYS in gl_main.c
  32. add the iphoneRotateForLandscape calls
  33. static JDC removed short consistancy[MAXPLAYERS][BACKUPTICS];
  34. // JDC glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  35. // JDC glDisableClientState(GL_VERTEX_ARRAY);
  36. #ifdef IPHONE // JDC
  37. #define MAX_SCREENWIDTH 480
  38. #define MAX_SCREENHEIGHT 320
  39. #else
  40. code notes
  41. ----------
  42. all the fixed point mess
  43. goofy polar clipping
  44. path traverse should have used a BSP tree
  45. rename vldoor_e close and open enums to not conflict with unistd
  46. opengl_error_break
  47. WiFi internet play
  48. ---------
  49. voip instead of key chat
  50. extra asset work
  51. ----------------------
  52. perfect weapon scales
  53. demo of each level?
  54. additive art separation -- attacks, buttons, etc
  55. tuned option
  56. ------------
  57. last kill / last secret / last item messages
  58. more achievements in general
  59. better item pickup sounds
  60. scale blood spray with distance
  61. easier item pickup
  62. crosshair
  63. better movement clipping to walls
  64. better key pickup sound
  65. textured automap
  66. better low health warning
  67. better feedback on where bullets hit
  68. better bob cycle when going down stairs
  69. map item should also show all monsters and items to make it cool
  70. barrels explode easier
  71. wave FOV when berzerk
  72. pistol shots are useless in deathmatch
  73. show opponent / enemy health when attacking them?
  74. cpu optimizations
  75. -------------
  76. convert to 16 bit vertex data
  77. void gld_BindPatch(GLTexture *gltexture, int cm) is expensive
  78. fixedMul / fixedDiv in asm (negligable performance gain)
  79. atlas all of the non-character items (and bodies?)
  80. remove the pitch changes from sound?
  81. gpu optimizations
  82. ------------------
  83. use fog instead of full screen blend for damage/pickup flash (3 msec on IP3G)
  84. pvrtc walls and floors
  85. art needed
  86. ----------
  87. new map / menu button
  88. awards on medals
  89. icon
  90. thumbsticks
  91. settings gears
  92. must do
  93. -------
  94. pause music in menu
  95. timelimit carry over to new levels
  96. server going to demo causes client to crash
  97. fixed 10/13/09
  98. --------------
  99. recover from sound interruption
  100. caps for slider bar text
  101. reset defaults doesn't reset reverse-landscape
  102. pause music when going to the menu
  103. reset timelimit each level on deathmatch
  104. disable demos, new game, and web site during multiplayer
  105. fixed
  106. -----
  107. automap / menu button actions with multi-thread
  108. capitalized "game saved."
  109. Added punctuation to "Ned a blue keycard", etc
  110. added "defaults" button in options
  111. todo
  112. ----
  113. don't accept fire from an owned touch?
  114. text scaling in buttons isn't perfect
  115. better view angle transport
  116. audio bugs
  117. rotor control shouldn't be dimmed
  118. volume button hack?
  119. change background color for networking
  120. tapping weapon change to cycle
  121. is openal thread safe? we issue touch clicks from asynctic
  122. disable multiplayer button if no ethernet addresses found
  123. touch latching issues
  124. add one tic latency to server?
  125. select new game while in netgame
  126. multiplayer arrow colors
  127. remove players with stale joins
  128. rocket explosion offset
  129. texture preload status bar stuff and blood / impacts
  130. stereo panning for headphones
  131. directly build 16 bit textures instead of translating from 32 bit
  132. texture wrap seam after end of e3m8
  133. sliders should be touch-latch controls
  134. respawn flash sounds sometimes not playing?
  135. don't allow starting on secret levels
  136. loaded savegame spot on different level didn't get view height on first frame
  137. use graphic?
  138. don't ever close doors with auto-use
  139. separators in map select
  140. rotor speed adjust
  141. check all powerup effects
  142. remove uses of prboom.wad?
  143. check patch outlining code
  144. flash all controls on initial level load
  145. touch sounds when cancelling demo playback
  146. play sound on respawn
  147. catch memory warning, purge textures
  148. use wad sound data
  149. stop sound cleanly
  150. entire gun doesn't get fullbright with muzzle flash
  151. require four touches in line for console
  152. restartable pwad interface
  153. somewhat normal based lighting on walls
  154. help menu
  155. visual tilt indicator
  156. tilt draw the turnstick when active
  157. console
  158. */
  159. #include "doomiphone.h"
  160. cvar_t *freeLevelOfWeek;
  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 *mapScale;
  180. cvar_t *drawControls;
  181. cvar_t *autoUse;
  182. cvar_t *statusBar;
  183. cvar_t *touchClick;
  184. cvar_t *messages;
  185. cvar_t *timeLimit;
  186. cvar_t *fragLimit;
  187. cvar_t *mpDeathmatch;
  188. cvar_t *mpSkill;
  189. cvar_t *mpDataset;
  190. cvar_t *mpEpisode;
  191. cvar_t *mpMap;
  192. cvar_t *mpExpansion;
  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( const char * iwad, const char * pwad );
  253. void iphoneStartup() {
  254. int start = SysIphoneMilliseconds();
  255. // microseconds will be plenty random for playerID and localGameID
  256. playerID = localGameID = SysIphoneMicroseconds();
  257. InitImmediateModeGL();
  258. // init OpenAL before pak file, so the pak file can
  259. // make all the al static buffers
  260. Sound_Init();
  261. char buffer[1028];
  262. sprintf( buffer, "%s/base.iPack", SysIphoneGetAppDir() );
  263. // get our new-style pak file
  264. PK_Init( buffer );
  265. // register console commands
  266. Cmd_AddCommand( "listcvars", Cvar_List_f );
  267. Cmd_AddCommand( "resetcvars", Cvar_Reset_f );
  268. Cmd_AddCommand( "resetmaps", ResetMaps_f );
  269. Cmd_AddCommand( "listcmds", Cmd_ListCommands_f );
  270. Cmd_AddCommand( "give", Give_f );
  271. Cmd_AddCommand( "god", God_f );
  272. Cmd_AddCommand( "mail", EmailConsole ); //gsh, mails the console to id
  273. // register console variables
  274. Cvar_Get( "version", va( "%3.1f %s %s", DOOM_IPHONE_VERSION, __DATE__, __TIME__ ), 0 );
  275. freeLevelOfWeek = Cvar_Get("freeLevelOfWeek", "0", 0 );
  276. skill = Cvar_Get( "skill", "1", CVAR_ARCHIVE );
  277. episode = Cvar_Get( "episode", "0", CVAR_ARCHIVE );
  278. controlScheme = Cvar_Get( "controlScheme", "0", CVAR_ARCHIVE );
  279. stickTurn = Cvar_Get( "stickTurn", "128", CVAR_ARCHIVE );
  280. stickMove = Cvar_Get( "stickMove", "128", CVAR_ARCHIVE );
  281. stickDeadBand = Cvar_Get( "stickDeadBand", "0.05", CVAR_ARCHIVE );
  282. rotorTurn = Cvar_Get( "rotorTurn", "50000", CVAR_ARCHIVE );
  283. tiltTurn = Cvar_Get( "tiltTurn", "0", CVAR_ARCHIVE );
  284. tiltMove = Cvar_Get( "tiltMove", "0", CVAR_ARCHIVE );
  285. tiltDeadBand = Cvar_Get( "tiltDeadBand", "0.08", CVAR_ARCHIVE );
  286. tiltAverages = Cvar_Get( "tiltAverages", "3", CVAR_ARCHIVE );
  287. centerSticks = Cvar_Get( "centerSticks", "1", CVAR_ARCHIVE );
  288. rampTurn = Cvar_Get( "rampTurn", "1", CVAR_ARCHIVE );
  289. music = Cvar_Get( "music", "1", CVAR_ARCHIVE );
  290. cropSprites = Cvar_Get( "cropSprites", "1", 0 );
  291. mapScale = Cvar_Get( "mapScale", "10", CVAR_ARCHIVE );
  292. drawControls = Cvar_Get( "drawControls", "1", CVAR_ARCHIVE );
  293. autoUse = Cvar_Get( "autoUse", "1", CVAR_ARCHIVE );
  294. statusBar = Cvar_Get( "statusBar", "1", CVAR_ARCHIVE );
  295. touchClick = Cvar_Get( "touchClick", "1", CVAR_ARCHIVE );
  296. messages = Cvar_Get( "messages", "1", CVAR_ARCHIVE );
  297. mapSelectY = Cvar_Get( "mapSelectY", "0", CVAR_ARCHIVE );
  298. miniNet = Cvar_Get( "miniNet", "1", CVAR_ARCHIVE );
  299. // multiplayer setup
  300. timeLimit = Cvar_Get( "timeLimit", "0", CVAR_ARCHIVE );
  301. fragLimit = Cvar_Get( "fragLimit", "5", CVAR_ARCHIVE );
  302. mpDeathmatch = Cvar_Get( "mpDeathmatch", "0", CVAR_ARCHIVE );
  303. mpDataset = Cvar_Get( "mpDataset", "0", CVAR_ARCHIVE );
  304. mpEpisode = Cvar_Get( "mpEpisode", "1", CVAR_ARCHIVE );
  305. mpSkill = Cvar_Get( "mpSkill", "1", CVAR_ARCHIVE );
  306. mpMap = Cvar_Get( "mpMap", "1", CVAR_ARCHIVE );
  307. mpExpansion = Cvar_Get( "mpExpansion", "0", CVAR_ARCHIVE | CVAR_NOSET );
  308. // debug tools
  309. showTilt = Cvar_Get( "showTilt", "-1", 0 );
  310. showTime = Cvar_Get( "showTime", "0", 0 );
  311. showNet = Cvar_Get( "showNet", "0", 0 );
  312. showSound = Cvar_Get( "showSound", "0", 0 );
  313. noBlend = Cvar_Get( "noBlend", "0", 0 ); // disable the damae blends for screenshots
  314. glfinish = Cvar_Get( "glfinish", "0", 0 );
  315. throttle = Cvar_Get( "throttle", "0", 0 ); // network packet throttle enable
  316. // Was origiinally 4. Trying different values to help internet play.
  317. netBuffer = Cvar_Get( "netBuffer", "12", 0 ); // max tics to buffer ahead
  318. // load the archived cvars
  319. Cmd_ExecuteFile( va( "%s/config.cfg", SysIphoneGetDocDir() ) );
  320. // start the intro music if it wasn't disabled with the music cvar
  321. iphonePlayMusic( "intro" );
  322. // iphonePlayMusic( "e1m1" );
  323. // these should get overwritten by the config loading
  324. memset( &playState, 0, sizeof( playState ) );
  325. playState.map.skill = 1;
  326. playState.map.episode = 1;
  327. playState.map.map = 1;
  328. HudSetForScheme( 0 );
  329. // load the binary config file
  330. FILE *f = fopen( va( "%s/binaryConfig.bin", SysIphoneGetDocDir() ), "rb" );
  331. if ( f ) {
  332. int version;
  333. version = 0;
  334. fread( &version, 1, sizeof( version ), f );
  335. if ( version != VERSION_BCONFIG ) {
  336. Com_Printf( "Binary config file bad version.\n" );
  337. } else {
  338. fread( &playState, 1, sizeof( playState ), f );
  339. fread( &huds, 1, sizeof( huds ), f );
  340. version = 0;
  341. fread( &version, 1, sizeof( version ), f );
  342. if ( version != VERSION_BCONFIG ) {
  343. Com_Error( "Binary config file bad trailing version.\n" );
  344. }
  345. }
  346. fclose( f );
  347. }
  348. Com_Printf( "startup time: %i msec\n", SysIphoneMilliseconds() - start );
  349. start = SysIphoneMilliseconds();
  350. // the texnums might have been different in the savegame
  351. HudSetTexnums();
  352. arialFontTexture = PK_FindTexture( "iphone/arialImageLAL.tga" );
  353. Com_Printf( "preloadBeforePlay(): %i msec\n", SysIphoneMilliseconds() - start );
  354. // prBoom seems to draw the static pic screens without setting up 2D, causing
  355. // a bad first frame
  356. iphoneSet2D();
  357. menuState = IPM_MAIN;
  358. lastState = IPM_MAIN;
  359. #if 0
  360. // jump right to the save spot for debugging
  361. ResumeGame();
  362. #endif
  363. }
  364. /*
  365. ==================
  366. iphoneDoomSetup
  367. Run the Doom game setup functions. This was made seperate from iphoneStartup so that the user
  368. could select a mission pack first.
  369. ==================
  370. */
  371. void iphoneDoomStartup( const char * iwad, const char * pwad ) {
  372. Com_Printf( "---------- D_DoomMain ----------\n" );
  373. D_DoomMainSetup( iwad, pwad );
  374. // put savegames here
  375. strcpy( basesavegame, SysIphoneGetDocDir() );
  376. }
  377. /*
  378. ==================
  379. iphoneShutdown
  380. Write out configs and save the game at this position
  381. ==================
  382. */
  383. void iphoneShutdown() {
  384. FILE *fp;
  385. char path[1024];
  386. cvar_t *var;
  387. char buffer[1024];
  388. if( lastState == IPM_GAME && gamestate != GS_INTERMISSION && !demoplayback ) {
  389. G_DoSaveGame( false );
  390. }
  391. // write the ascii config file
  392. snprintf( path, sizeof( path ), "%s/config.cfg", SysIphoneGetDocDir() );
  393. fp = fopen( path, "w" );
  394. if( ! fp ) {
  395. Com_Printf( "Could not write config.cfg.\n" );
  396. return;
  397. }
  398. // write out commands to set the archived cvars
  399. for( var = cvar_vars ; var ; var = var->next ) {
  400. if( var->flags & CVAR_ARCHIVE ) {
  401. snprintf( buffer, sizeof( buffer ), "%s %s\n", var->name, var->string );
  402. fprintf( fp, "%s", buffer );
  403. Com_Printf( "%s", buffer );
  404. }
  405. }
  406. fclose( fp );
  407. // write the binary config file
  408. FILE *f = fopen( va( "%s/binaryConfig.bin", SysIphoneGetDocDir() ), "wb" );
  409. if ( !f ) {
  410. Com_Printf( "Could not write binaryConfig.cfg.\n" );
  411. return;
  412. }
  413. int version = VERSION_BCONFIG;
  414. fwrite( &version, 1, sizeof( version ), f );
  415. fwrite( &playState, 1, sizeof( playState ), f );
  416. fwrite( &huds, 1, sizeof( huds ), f );
  417. fwrite( &version, 1, sizeof( version ), f );
  418. fclose( f );
  419. }