PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/gnujump-1.0.7/src/main.c

#
C | 276 lines | 225 code | 27 blank | 24 comment | 38 complexity | 68a6bdeb28e03c6a67767525a9681013 MD5 | raw file
Possible License(s): GPL-3.0
  1. /*
  2. * GNUjump
  3. * =======
  4. *
  5. * Copyright (C) 2005-2008, Juan Pedro Bolivar Puente
  6. *
  7. * GNUjump is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * GNUjump is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "gnujump.h"
  21. #include "setup.h"
  22. #include "game.h"
  23. #include "menu.h"
  24. #include "records.h"
  25. #include "replay.h"
  26. SDL_Surface *screen = NULL;
  27. L_gblOptions gblOps;
  28. void displayHelp ();
  29. void displayInfo ();
  30. int parseArgs (int argc, char *argv[], char **replay);
  31. int
  32. main (int argc, char *argv[])
  33. {
  34. data_t gfxdata;
  35. char *cfgFile;
  36. char *hscFile;
  37. char *homeDir;
  38. char *replay = NULL;
  39. /* Init gettext */
  40. setlocale (LC_ALL, "");
  41. textdomain (PACKAGE);
  42. bindtextdomain (PACKAGE, LOCALEDIR);
  43. /* Get the config file name */
  44. #ifndef WIN32
  45. homeDir = getenv ("HOME");
  46. cfgFile =
  47. malloc (sizeof (char) *
  48. (strlen (homeDir) + strlen (CONFDIR) + strlen (CFGFILE) + 3));
  49. hscFile =
  50. malloc (sizeof (char) *
  51. (strlen (homeDir) + strlen (CONFDIR) + strlen (HSCFILE) + 3));
  52. sprintf (cfgFile, "%s/" CONFDIR "/", homeDir);
  53. sprintf (hscFile, "%s/" CONFDIR "/", homeDir);
  54. #else
  55. cfgFile = malloc (sizeof (char) * strlen (CFGFILE) + 1);
  56. hscFile = malloc (sizeof (char) * strlen (HSCFILE) + 1);
  57. cfgFile[0] = hscFile[0] = '\0';
  58. #endif
  59. strcat (cfgFile, CFGFILE);
  60. strcat (hscFile, HSCFILE);
  61. if (!loadConfigFile (cfgFile))
  62. {
  63. initGblOps (); /* Set default options */
  64. }
  65. if (!loadRecords (hscFile, gblOps.records))
  66. {
  67. defaultRecords (gblOps.records);
  68. }
  69. /* Parse args */
  70. if (parseArgs (argc, argv, &replay))
  71. {
  72. return 1;
  73. }
  74. EngineInit ();
  75. gfxdata.soundloaded = FALSE;
  76. if (!loadGraphics (&gfxdata, gblOps.dataDir))
  77. return 1;
  78. //gblOps.fps = 20;
  79. if (replay != NULL)
  80. loadReplay (&gfxdata, replay);
  81. else
  82. mainMenu (&gfxdata);
  83. writeConfigFile (cfgFile);
  84. writeRecords (hscFile, gblOps.records);
  85. /* Free some things */
  86. freeGraphics (&gfxdata);
  87. freeSounds (&gfxdata);
  88. cleanGblOps ();
  89. Mix_CloseAudio ();
  90. free (cfgFile);
  91. free (hscFile);
  92. printf (_("\nHave a nice day!\n\n"));
  93. return 0;
  94. }
  95. void
  96. displayHelp ()
  97. {
  98. printf (_("GNUjump, an xjump clone. By Juan Pedro Bolivar Puente.\n\
  99. This software can be redistributed and modified under the terms of the GPL.\n\n\
  100. Usage: sdljump [REPLAY_FILE] [OPTIONS] \n\
  101. Availible options:\n\
  102. -b <int> --bpp <int> Sets the screen bitdepth to <int>. \n\
  103. -f --fullscreen Force fullscreen mode.\n\
  104. -s --software Force software rendering.\n\
  105. -o --opengl Force OpenGL rendering.\n\
  106. -a --antialias Force antialiasing for rotating sprites. \n\
  107. -n --no-aa Disables antialiasing for rotating sprites. \n\
  108. -? --help Displays this help screen.\n\
  109. \nExample: sdljump myRep.rep -o -f\n"));
  110. }
  111. void
  112. displayInfo ()
  113. {
  114. printf
  115. ("\n*********************************************************************"
  116. "\n* GNUjump *"
  117. "\n*********************************************************************"
  118. "\nCopyright (C) 2005, Juan Pedro Bolivar Puente\n");
  119. printf ("\nVERSION: %s", VERSION);
  120. printf
  121. ("\n\n GNUjump is free software; you can redistribute it and/or modify\n"
  122. "it under the terms of the GNU General Public License as published by\n"
  123. "the Free Software Foundation; either version 3 of the License, or\n"
  124. "(at your option) any later version.\n\n"
  125. "SDLjump is distributed in the hope that it will be useful,\n"
  126. "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  127. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
  128. "GNU General Public License for more details.\n\n"
  129. "You should have received a copy of the GNU General Public License\n"
  130. "along with GNUjump; if not, write to the Free Software\n"
  131. "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
  132. }
  133. int
  134. parseArgs (int argc, char *argv[], char **replay)
  135. {
  136. int i;
  137. for (i = 1; i < argc; i++)
  138. {
  139. if (argv[i][0] == '-')
  140. {
  141. if (argv[i][1] != '-')
  142. { /* Short arg */
  143. switch (argv[i][1])
  144. {
  145. case 'w':
  146. if ((i + 1) < argc)
  147. {
  148. gblOps.w = atoi (argv[i + 1]);
  149. i++;
  150. }
  151. break;
  152. case 'h':
  153. if ((i + 1) < argc)
  154. {
  155. gblOps.h = atoi (argv[i + 1]);
  156. i++;
  157. }
  158. break;
  159. case 'b':
  160. if ((i + 1) < argc)
  161. {
  162. gblOps.bpp = atoi (argv[i + 1]);
  163. i++;
  164. }
  165. break;
  166. case 'f':
  167. gblOps.fullsc = TRUE;
  168. break;
  169. case 'o':
  170. gblOps.useGL = TRUE;
  171. break;
  172. case 's':
  173. gblOps.useGL = FALSE;
  174. break;
  175. case 'a':
  176. gblOps.aa = 1;
  177. break;
  178. case 'n':
  179. gblOps.aa = 0;
  180. break;
  181. case '?':
  182. displayHelp ();
  183. return 1;
  184. break;
  185. }
  186. }
  187. else
  188. { /* Long arg */
  189. if (strcmp (argv[i], "--width") == 0)
  190. {
  191. if ((i + 1) < argc)
  192. {
  193. gblOps.w = atoi (argv[i + 1]);
  194. i++;
  195. }
  196. }
  197. if (strcmp (argv[i], "--height") == 0)
  198. {
  199. if ((i + 1) < argc)
  200. {
  201. gblOps.h = atoi (argv[i + 1]);
  202. i++;
  203. }
  204. }
  205. if (strcmp (argv[i], "--bpp") == 0)
  206. {
  207. if ((i + 1) < argc)
  208. {
  209. gblOps.bpp = atoi (argv[i + 1]);
  210. i++;
  211. }
  212. }
  213. if (strcmp (argv[i], "--fullscreen") == 0)
  214. {
  215. gblOps.fullsc = TRUE;
  216. }
  217. if (strcmp (argv[i], "--opengl") == 0)
  218. {
  219. gblOps.useGL = TRUE;
  220. }
  221. if (strcmp (argv[i], "--software") == 0)
  222. {
  223. gblOps.useGL = FALSE;
  224. }
  225. if (strcmp (argv[i], "--antialias") == 0)
  226. {
  227. gblOps.aa = 1;
  228. }
  229. if (strcmp (argv[i], "--no-aa") == 0)
  230. {
  231. gblOps.aa = 0;
  232. }
  233. if (strcmp (argv[i], "--help") == 0)
  234. {
  235. displayHelp ();
  236. return 1;
  237. }
  238. }
  239. }
  240. else
  241. { /* Replay */
  242. if (*replay != NULL)
  243. free (*replay);
  244. *replay = malloc ((strlen (argv[i]) + 1) * sizeof (char));
  245. strcpy (*replay, argv[i]);
  246. }
  247. }
  248. return FALSE;
  249. }