iphone_main.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. * unix_main.c: UNIX interface to application.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. *
  21. * Acknowledgement:
  22. * This code was derived from Quake II, and was originally
  23. * written by Id Software, Inc.
  24. *
  25. */
  26. #include "../wolfiphone.h"
  27. cvar_t *controlScheme;
  28. cvar_t *sensitivity;
  29. cvar_t *stickSize;
  30. cvar_t *stickTurnBase;
  31. cvar_t *stickTurnScale;
  32. cvar_t *stickMoveBase;
  33. cvar_t *stickMoveScale;
  34. cvar_t *stickDeadBand;
  35. cvar_t *tiltTurn;
  36. cvar_t *tiltMove;
  37. cvar_t *tiltDeadBand;
  38. cvar_t *tiltAverages;
  39. cvar_t *tiltFire;
  40. cvar_t *music;
  41. cvar_t *showTilt;
  42. cvar_t *cropSprites;
  43. cvar_t *blends;
  44. cvar_t *gunFrame;
  45. cvar_t *slowAI;
  46. W32 sys_frame_time;
  47. void Sys_Error( const char *format, ... )
  48. {
  49. va_list argptr;
  50. char string[ 1024 ];
  51. va_start( argptr, format );
  52. (void)vsnprintf( string, sizeof( string ), format, argptr );
  53. va_end( argptr );
  54. fprintf( stderr, "Error: %s\n", string );
  55. _exit( 1 );
  56. }
  57. void Sys_Quit (void)
  58. {
  59. _exit( 0 );
  60. }
  61. void Sys_SendKeyEvents (void)
  62. {
  63. }
  64. char *Sys_GetClipboardData( void )
  65. {
  66. return NULL;
  67. }
  68. void Reset_f() {
  69. memset( &currentMap, 0, sizeof( currentMap ) );
  70. currentMap.skill = 1;
  71. cvar_vars = NULL; // don't write any cvars to the config file
  72. iphoneShutdown();
  73. }
  74. /*
  75. ==================
  76. iphoneStartup
  77. ==================
  78. */
  79. void iphoneStartup() {
  80. int i;
  81. char *s;
  82. int start = Sys_Milliseconds();
  83. z_chain.next = z_chain.prev = &z_chain;
  84. InitImmediateModeGL();
  85. // Prepare enough of the subsystems to handle
  86. // cvar and command buffer management.
  87. COM_InitArgv( 0, NULL ); // FIXME: get args...
  88. Cmd_Init();
  89. Cvar_Init();
  90. Con_Init();
  91. FS_InitFilesystem();
  92. // We need to add the early commands twice, because
  93. // a basedir or cddir needs to be set before execing
  94. // config files, but we want other parms to override
  95. // the settings of the config files.
  96. Cbuf_AddEarlyCommands( false );
  97. Cbuf_Execute();
  98. R_Init();
  99. Cmd_AddCommand( "reset", Reset_f );
  100. developer = Cvar_Get( "developer", "0", CVAR_INIT );
  101. logfile_active = Cvar_Get( "logfile", "0", CVAR_INIT );
  102. s = va( "%s %s %s %s %s %s", APP_VERSION, RELEASENAME, CPUSTRING, __DATE__, __TIME__, BUILDSTRING );
  103. Cvar_Get( "version", s, CVAR_SERVERINFO | CVAR_NOSET );
  104. Con_Init();
  105. Sound_Init();
  106. Game_Init(); // game and player init
  107. Cbuf_AddText( "exec config.cfg\n" );
  108. Cbuf_AddEarlyCommands( true );
  109. Cbuf_Execute();
  110. // add + commands from command line
  111. Cbuf_AddLateCommands();
  112. Cbuf_Execute();
  113. for ( i = 0 ; i < 10 ; i++ ) {
  114. char name[64];
  115. sprintf( name, "iphone/font/%i.tga", i );
  116. numberPics[i] = TM_FindTexture( name, TT_Pic );
  117. }
  118. Com_Printf( "\n====== Application Initialized ======\n\n" );
  119. Sound_Activate( true );
  120. consoleActive = 0;
  121. controlScheme = Cvar_Get( "controlScheme", "0", CVAR_ARCHIVE );
  122. sensitivity = Cvar_Get( "sensitivity", "0.3", CVAR_ARCHIVE );
  123. stickSize = Cvar_Get( "stickSize", "120", CVAR_ARCHIVE );
  124. stickTurnBase = Cvar_Get( "stickTurnBase", "300", CVAR_ARCHIVE );
  125. stickTurnScale = Cvar_Get( "stickTurnScale", "500", CVAR_ARCHIVE );
  126. stickMoveBase = Cvar_Get( "stickMoveBase", "3000", CVAR_ARCHIVE );
  127. stickMoveScale = Cvar_Get( "stickMoveScale", "5000", CVAR_ARCHIVE );
  128. stickDeadBand = Cvar_Get( "stickDeadBand", "0.2", CVAR_ARCHIVE );
  129. tiltTurn = Cvar_Get( "tiltTurn", "0", CVAR_ARCHIVE );
  130. tiltMove = Cvar_Get( "tiltMove", "0", CVAR_ARCHIVE );
  131. tiltFire = Cvar_Get( "tiltFire", "0", CVAR_ARCHIVE );
  132. music = Cvar_Get( "music", "1", CVAR_ARCHIVE );
  133. tiltDeadBand = Cvar_Get( "tiltDeadBand", "0.08", CVAR_ARCHIVE );
  134. tiltAverages = Cvar_Get( "tiltAverages", "3", CVAR_ARCHIVE );
  135. cropSprites = Cvar_Get( "cropSprites", "1", 0 );
  136. showTilt = Cvar_Get( "showTilt", "-1", 0 );
  137. blends = Cvar_Get( "blends", "1", 0 );
  138. gunFrame = Cvar_Get( "gunFrame", "0", 0 );
  139. slowAI = Cvar_Get( "slowAI", "0", 0 );
  140. // these should get overwritten by LoadTheGame
  141. currentMap.skill = 1;
  142. currentMap.episode = 0;
  143. if ( !LoadTheGame() ) {
  144. memset( currentMap.mapFlags, 0,sizeof( currentMap.mapFlags ) );
  145. PL_NewGame( &Player );
  146. iphoneStartMap( 0, 0, 1 );
  147. }
  148. // always start at main menu
  149. menuState = IPM_MAIN;
  150. Com_Printf( "startup time: %i msec\n", Sys_Milliseconds() - start );
  151. }
  152. /*
  153. ==================
  154. iphoneWriteConfig
  155. ==================
  156. */
  157. void iphoneWriteConfig( void ) {
  158. FILE *fp;
  159. char path[ MAX_OSPATH];
  160. cvar_t *var;
  161. char buffer[1024];
  162. my_snprintf( path, sizeof( path ), "%s/config.cfg", iphoneDocDirectory );
  163. fp = fopen( path, "w" );
  164. if( ! fp ) {
  165. Com_Printf( "Could not write config.cfg.\n" );
  166. return;
  167. }
  168. // write out commands to set the archived cvars
  169. for( var = cvar_vars ; var ; var = var->next ) {
  170. if( var->flags & CVAR_ARCHIVE ) {
  171. my_snprintf( buffer, sizeof( buffer ), "set %s \"%s\"\n", var->name, var->string );
  172. fprintf( fp, "%s", buffer );
  173. Com_Printf( "%s", buffer );
  174. }
  175. }
  176. fclose( fp );
  177. }
  178. /*
  179. ==================
  180. iphoneShutdown
  181. Save the game at this position
  182. ==================
  183. */
  184. void iphoneShutdown() {
  185. Sound_StopAllSounds();
  186. Sound_StopBGTrack();
  187. iphoneWriteConfig();
  188. SaveTheGame();
  189. exit( 0 );
  190. }