parseArgs.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. // Support functions used to manage the directory list
  24. function pushFront(%list, %token, %delim)
  25. {
  26. if (%list !$= "")
  27. return %token @ %delim @ %list;
  28. return %token;
  29. }
  30. function pushBack(%list, %token, %delim)
  31. {
  32. if (%list !$= "")
  33. return %list @ %delim @ %token;
  34. return %token;
  35. }
  36. function popFront(%list, %delim)
  37. {
  38. return nextToken(%list, unused, %delim);
  39. }
  40. //-----------------------------------------------------------------------------
  41. // The default global argument parsing
  42. function defaultParseArgs()
  43. {
  44. for ($i = 1; $i < $Game::argc ; $i++)
  45. {
  46. $arg = $Game::argv[$i];
  47. $nextArg = $Game::argv[$i+1];
  48. $hasNextArg = $Game::argc - $i > 1;
  49. $logModeSpecified = false;
  50. // Check for dedicated run
  51. if( stricmp($arg,"-dedicated") == 0 )
  52. {
  53. $userDirs = $defaultGame;
  54. $dirCount = 1;
  55. $isDedicated = true;
  56. }
  57. switch$ ($arg)
  58. {
  59. //--------------------
  60. case "-log":
  61. $argUsed[$i]++;
  62. if ($hasNextArg)
  63. {
  64. // Turn on console logging
  65. if ($nextArg != 0)
  66. {
  67. // Dump existing console to logfile first.
  68. $nextArg += 4;
  69. }
  70. setLogMode($nextArg);
  71. $logModeSpecified = true;
  72. $argUsed[$i+1]++;
  73. $i++;
  74. }
  75. else
  76. error("Error: Missing Command Line argument. Usage: -log <Mode: 0,1,2>");
  77. //--------------------
  78. case "-dir":
  79. $argUsed[$i]++;
  80. if ($hasNextArg)
  81. {
  82. // Append the mod to the end of the current list
  83. $userDirs = strreplace($userDirs, $nextArg, "");
  84. $userDirs = pushFront($userDirs, $nextArg, ";");
  85. $argUsed[$i+1]++;
  86. $i++;
  87. $dirCount++;
  88. }
  89. else
  90. error("Error: Missing Command Line argument. Usage: -dir <dir_name>");
  91. //--------------------
  92. // changed the default behavior of this command line arg. It now
  93. // defaults to ONLY loading the game, not tools
  94. // default auto-run already loads in tools --SRZ 11/29/07
  95. case "-game":
  96. $argUsed[$i]++;
  97. if ($hasNextArg)
  98. {
  99. // Set the selected dir --NOTE: we no longer allow tools with this argument
  100. /*
  101. if( $isDedicated )
  102. {
  103. $userDirs = $nextArg;
  104. $dirCount = 1;
  105. }
  106. else
  107. {
  108. $userDirs = "tools;" @ $nextArg;
  109. $dirCount = 2;
  110. }
  111. */
  112. $userDirs = $nextArg;
  113. $dirCount = 1;
  114. $argUsed[$i+1]++;
  115. $i++;
  116. error($userDirs);
  117. }
  118. else
  119. error("Error: Missing Command Line argument. Usage: -game <game_name>");
  120. /* deprecated SRZ 11/29/07
  121. //--------------------
  122. case "-show":
  123. // A useful shortcut for -mod show
  124. $userMods = strreplace($userMods, "show", "");
  125. $userMods = pushFront($userMods, "show", ";");
  126. $argUsed[$i]++;
  127. $modcount++;
  128. */
  129. //--------------------
  130. case "-console":
  131. enableWinConsole(true);
  132. $argUsed[$i]++;
  133. //--------------------
  134. case "-jSave":
  135. $argUsed[$i]++;
  136. if ($hasNextArg)
  137. {
  138. echo("Saving event log to journal: " @ $nextArg);
  139. saveJournal($nextArg);
  140. $argUsed[$i+1]++;
  141. $i++;
  142. }
  143. else
  144. error("Error: Missing Command Line argument. Usage: -jSave <journal_name>");
  145. //--------------------
  146. case "-jPlay":
  147. $argUsed[$i]++;
  148. if ($hasNextArg)
  149. {
  150. playJournal($nextArg);
  151. $argUsed[$i+1]++;
  152. $i++;
  153. }
  154. else
  155. error("Error: Missing Command Line argument. Usage: -jPlay <journal_name>");
  156. //--------------------
  157. case "-jPlayToVideo":
  158. $argUsed[$i]++;
  159. if ($hasNextArg)
  160. {
  161. $VideoCapture::journalName = $nextArg;
  162. $VideoCapture::captureFromJournal = true;
  163. $argUsed[$i+1]++;
  164. $i++;
  165. }
  166. else
  167. error("Error: Missing Command Line argument. Usage: -jPlayToVideo <journal_name>");
  168. //--------------------
  169. case "-vidCapFile":
  170. $argUsed[$i]++;
  171. if ($hasNextArg)
  172. {
  173. $VideoCapture::fileName = $nextArg;
  174. $argUsed[$i+1]++;
  175. $i++;
  176. }
  177. else
  178. error("Error: Missing Command Line argument. Usage: -vidCapFile <ouput_video_name>");
  179. //--------------------
  180. case "-vidCapFPS":
  181. $argUsed[$i]++;
  182. if ($hasNextArg)
  183. {
  184. $VideoCapture::fps = $nextArg;
  185. $argUsed[$i+1]++;
  186. $i++;
  187. }
  188. else
  189. error("Error: Missing Command Line argument. Usage: -vidCapFPS <ouput_video_framerate>");
  190. //--------------------
  191. case "-vidCapEncoder":
  192. $argUsed[$i]++;
  193. if ($hasNextArg)
  194. {
  195. $VideoCapture::encoder = $nextArg;
  196. $argUsed[$i+1]++;
  197. $i++;
  198. }
  199. else
  200. error("Error: Missing Command Line argument. Usage: -vidCapEncoder <ouput_video_encoder>");
  201. //--------------------
  202. case "-vidCapWidth":
  203. $argUsed[$i]++;
  204. if ($hasNextArg)
  205. {
  206. $videoCapture::width = $nextArg;
  207. $argUsed[$i+1]++;
  208. $i++;
  209. }
  210. else
  211. error("Error: Missing Command Line argument. Usage: -vidCapWidth <ouput_video_width>");
  212. //--------------------
  213. case "-vidCapHeight":
  214. $argUsed[$i]++;
  215. if ($hasNextArg)
  216. {
  217. $videoCapture::height = $nextArg;
  218. $argUsed[$i+1]++;
  219. $i++;
  220. }
  221. else
  222. error("Error: Missing Command Line argument. Usage: -vidCapHeight <ouput_video_height>");
  223. //--------------------
  224. case "-level":
  225. $argUsed[$i]++;
  226. if ($hasNextArg)
  227. {
  228. %hasExt = strpos($nextArg, ".mis");
  229. if(%hasExt == -1)
  230. {
  231. $levelToLoad = $nextArg @ " ";
  232. for(%i = $i + 2; %i < $Game::argc; %i++)
  233. {
  234. %arg = $Game::argv[%i];
  235. %hasExt = strpos(%arg, ".mis");
  236. if(%hasExt == -1)
  237. {
  238. $levelToLoad = $levelToLoad @ %arg @ " ";
  239. } else
  240. {
  241. $levelToLoad = $levelToLoad @ %arg;
  242. break;
  243. }
  244. }
  245. } else
  246. $levelToLoad = $nextArg;
  247. $argUsed[$i+1]++;
  248. $i++;
  249. }
  250. else
  251. error("Error: Missing Command Line argument. Usage: -level <level file name (no path), with or without extension>");
  252. //-------------------
  253. case "-worldeditor":
  254. $startWorldEditor = true;
  255. $argUsed[$i]++;
  256. //-------------------
  257. case "-guieditor":
  258. $startGUIEditor = true;
  259. $argUsed[$i]++;
  260. //-------------------
  261. case "-help":
  262. $displayHelp = true;
  263. $argUsed[$i]++;
  264. //-------------------
  265. case "-compileAll":
  266. $compileAll = true;
  267. $argUsed[$i]++;
  268. //-------------------
  269. case "-compileTools":
  270. $compileTools = true;
  271. $argUsed[$i]++;
  272. //-------------------
  273. case "-genScript":
  274. $genScript = true;
  275. $argUsed[$i]++;
  276. //-------------------
  277. default:
  278. $argUsed[$i]++;
  279. if($userDirs $= "")
  280. $userDirs = $arg;
  281. }
  282. }
  283. //-----------------------------------------------
  284. // Play journal to video file?
  285. if ($VideoCapture::captureFromJournal && $VideoCapture::journalName !$= "")
  286. {
  287. if ($VideoCapture::fileName $= "")
  288. $VideoCapture::fileName = $VideoCapture::journalName;
  289. if ($VideoCapture::encoder $= "")
  290. $VideoCapture::encoder = "THEORA";
  291. if ($VideoCapture::fps $= "")
  292. $VideoCapture::fps = 30;
  293. if ($videoCapture::width $= "")
  294. $videoCapture::width = 0;
  295. if ($videoCapture::height $= "")
  296. $videoCapture::height = 0;
  297. playJournalToVideo( $VideoCapture::journalName, $VideoCapture::fileName,
  298. $VideoCapture::encoder, $VideoCapture::fps,
  299. $videoCapture::width SPC $videoCapture::height );
  300. }
  301. }