PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/quake3/q3map2/main.c

https://gitlab.com/illwieckz/netradiant
C | 301 lines | 160 code | 62 blank | 79 comment | 56 complexity | 2fc8be49deca022ec156b3a9ccdfc367 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0
  1. /* -------------------------------------------------------------------------------
  2. Copyright (C) 1999-2007 id Software, Inc. and contributors.
  3. For a list of contributors, see the accompanying CONTRIBUTORS file.
  4. This file is part of GtkRadiant.
  5. GtkRadiant is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. GtkRadiant 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. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GtkRadiant; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. -------------------------------------------------------------------------------
  17. This code has been altered significantly from its original form, to support
  18. several games based on the Quake III Arena engine, in the form of "Q3Map2."
  19. ------------------------------------------------------------------------------- */
  20. /* marker */
  21. #define MAIN_C
  22. /* dependencies */
  23. #include "q3map2.h"
  24. #include <glib.h>
  25. /*
  26. Random()
  27. returns a pseudorandom number between 0 and 1
  28. */
  29. vec_t Random( void ){
  30. return (vec_t) rand() / RAND_MAX;
  31. }
  32. char *Q_strncpyz( char *dst, const char *src, size_t len ) {
  33. if ( len == 0 ) {
  34. abort();
  35. }
  36. strncpy( dst, src, len );
  37. dst[ len - 1 ] = '\0';
  38. return dst;
  39. }
  40. char *Q_strcat( char *dst, size_t dlen, const char *src ) {
  41. size_t n = strlen( dst );
  42. if ( n > dlen ) {
  43. abort(); /* buffer overflow */
  44. }
  45. return Q_strncpyz( dst + n, src, dlen - n );
  46. }
  47. char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
  48. size_t n = strlen( dst );
  49. if ( n > dlen ) {
  50. abort(); /* buffer overflow */
  51. }
  52. return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
  53. }
  54. /*
  55. ExitQ3Map()
  56. cleanup routine
  57. */
  58. static void ExitQ3Map( void ){
  59. BSPFilesCleanup();
  60. if ( mapDrawSurfs != NULL ) {
  61. free( mapDrawSurfs );
  62. }
  63. }
  64. /*
  65. main()
  66. q3map mojo...
  67. */
  68. int main( int argc, char **argv ){
  69. int i, r;
  70. double start, end;
  71. extern qboolean werror;
  72. /* we want consistent 'randomness' */
  73. srand( 0 );
  74. /* start timer */
  75. start = I_FloatTime();
  76. /* this was changed to emit version number over the network */
  77. printf( Q3MAP_VERSION "\n" );
  78. /* set exit call */
  79. atexit( ExitQ3Map );
  80. /* read general options first */
  81. for ( i = 1; i < argc; i++ )
  82. {
  83. /* -help */
  84. if ( !strcmp( argv[ i ], "-h" ) || !strcmp( argv[ i ], "--help" )
  85. || !strcmp( argv[ i ], "-help" ) ) {
  86. HelpMain( ( i + 1 < argc ) ? argv[ i + 1 ] : NULL );
  87. return 0;
  88. }
  89. /* -connect */
  90. if ( !strcmp( argv[ i ], "-connect" ) ) {
  91. if ( ++i >= argc || !argv[ i ] ) {
  92. Error( "Out of arguments: No address specified after %s", argv[ i - 1 ] );
  93. }
  94. argv[ i - 1 ] = NULL;
  95. Broadcast_Setup( argv[ i ] );
  96. argv[ i ] = NULL;
  97. }
  98. /* verbose */
  99. else if ( !strcmp( argv[ i ], "-v" ) ) {
  100. if ( !verbose ) {
  101. verbose = qtrue;
  102. argv[ i ] = NULL;
  103. }
  104. }
  105. /* force */
  106. else if ( !strcmp( argv[ i ], "-force" ) ) {
  107. force = qtrue;
  108. argv[ i ] = NULL;
  109. }
  110. /* make all warnings into errors */
  111. else if ( !strcmp( argv[ i ], "-werror" ) ) {
  112. werror = qtrue;
  113. argv[ i ] = NULL;
  114. }
  115. /* patch subdivisions */
  116. else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
  117. if ( ++i >= argc || !argv[ i ] ) {
  118. Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
  119. }
  120. argv[ i - 1 ] = NULL;
  121. patchSubdivisions = atoi( argv[ i ] );
  122. argv[ i ] = NULL;
  123. if ( patchSubdivisions <= 0 ) {
  124. patchSubdivisions = 1;
  125. }
  126. }
  127. /* threads */
  128. else if ( !strcmp( argv[ i ], "-threads" ) ) {
  129. if ( ++i >= argc || !argv[ i ] ) {
  130. Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
  131. }
  132. argv[ i - 1 ] = NULL;
  133. numthreads = atoi( argv[ i ] );
  134. argv[ i ] = NULL;
  135. }
  136. }
  137. /* init model library */
  138. PicoInit();
  139. PicoSetMallocFunc( safe_malloc );
  140. PicoSetFreeFunc( free );
  141. PicoSetPrintFunc( PicoPrintFunc );
  142. PicoSetLoadFileFunc( PicoLoadFileFunc );
  143. PicoSetFreeFileFunc( free );
  144. /* set number of threads */
  145. ThreadSetDefault();
  146. /* generate sinusoid jitter table */
  147. for ( i = 0; i < MAX_JITTERS; i++ )
  148. {
  149. jitters[ i ] = sin( i * 139.54152147 );
  150. //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
  151. }
  152. /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
  153. and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
  154. Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
  155. Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
  156. Sys_Printf( RADIANT_NAME " - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
  157. Sys_Printf( "%s\n", Q3MAP_MOTD );
  158. /* ydnar: new path initialization */
  159. InitPaths( &argc, argv );
  160. /* set game options */
  161. if ( !patchSubdivisions ) {
  162. patchSubdivisions = game->patchSubdivisions;
  163. }
  164. /* check if we have enough options left to attempt something */
  165. if ( argc < 2 ) {
  166. Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
  167. }
  168. /* fixaas */
  169. if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
  170. r = FixAASMain( argc - 1, argv + 1 );
  171. }
  172. /* analyze */
  173. else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
  174. r = AnalyzeBSPMain( argc - 1, argv + 1 );
  175. }
  176. /* info */
  177. else if ( !strcmp( argv[ 1 ], "-info" ) ) {
  178. r = BSPInfoMain( argc - 2, argv + 2 );
  179. }
  180. /* vis */
  181. else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
  182. r = VisMain( argc - 1, argv + 1 );
  183. }
  184. /* light */
  185. else if ( !strcmp( argv[ 1 ], "-light" ) ) {
  186. r = LightMain( argc - 1, argv + 1 );
  187. }
  188. /* vlight */
  189. else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
  190. Sys_FPrintf( SYS_WRN, "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
  191. argv[ 1 ] = "-fast"; /* eek a hack */
  192. r = LightMain( argc, argv );
  193. }
  194. /* QBall: export entities */
  195. else if ( !strcmp( argv[ 1 ], "-exportents" ) ) {
  196. r = ExportEntitiesMain( argc - 1, argv + 1 );
  197. }
  198. /* ydnar: lightmap export */
  199. else if ( !strcmp( argv[ 1 ], "-export" ) ) {
  200. r = ExportLightmapsMain( argc - 1, argv + 1 );
  201. }
  202. /* ydnar: lightmap import */
  203. else if ( !strcmp( argv[ 1 ], "-import" ) ) {
  204. r = ImportLightmapsMain( argc - 1, argv + 1 );
  205. }
  206. /* ydnar: bsp scaling */
  207. else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
  208. r = ScaleBSPMain( argc - 1, argv + 1 );
  209. }
  210. /* ydnar: bsp conversion */
  211. else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
  212. r = ConvertBSPMain( argc - 1, argv + 1 );
  213. }
  214. /* div0: minimap */
  215. else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
  216. r = MiniMapBSPMain( argc - 1, argv + 1 );
  217. }
  218. /* ydnar: otherwise create a bsp */
  219. else {
  220. /* used to write Smokin'Guns like tex file */
  221. compile_map = qtrue;
  222. r = BSPMain( argc, argv );
  223. }
  224. /* emit time */
  225. end = I_FloatTime();
  226. Sys_Printf( "%9.0f seconds elapsed\n", end - start );
  227. /* shut down connection */
  228. Broadcast_Shutdown();
  229. /* return any error code */
  230. return r;
  231. }