parseArgs.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. function parseArgs()
  41. {
  42. for ($i = 1; $i < $Game::argc ; $i++)
  43. {
  44. $arg = $Game::argv[$i];
  45. $nextArg = $Game::argv[$i+1];
  46. $hasNextArg = $Game::argc - $i > 1;
  47. $logModeSpecified = false;
  48. // Check for dedicated run
  49. /*if( stricmp($arg,"-dedicated") == 0 )
  50. {
  51. $userDirs = $defaultGame;
  52. $dirCount = 1;
  53. $isDedicated = true;
  54. }*/
  55. switch$ ($arg)
  56. {
  57. //--------------------
  58. case "-dedicated":
  59. $userDirs = $defaultGame;
  60. $dirCount = 1;
  61. $isDedicated = true;
  62. $Server::Dedicated = true;
  63. enableWinConsole(true);
  64. $argUsed[%i]++;
  65. //--------------------
  66. case "-mission":
  67. $argUsed[%i]++;
  68. if ($hasNextArg)
  69. {
  70. $missionArg = $nextArg;
  71. $argUsed[%i+1]++;
  72. %i++;
  73. }
  74. else
  75. error("Error: Missing Command Line argument. Usage: -mission <filename>");
  76. //--------------------
  77. case "-connect":
  78. $argUsed[%i]++;
  79. if ($hasNextArg)
  80. {
  81. $JoinGameAddress = $nextArg;
  82. $argUsed[%i+1]++;
  83. %i++;
  84. }
  85. else
  86. error("Error: Missing Command Line argument. Usage: -connect <ip_address>");
  87. //--------------------
  88. case "-log":
  89. $argUsed[$i]++;
  90. if ($hasNextArg)
  91. {
  92. // Turn on console logging
  93. if ($nextArg != 0)
  94. {
  95. // Dump existing console to logfile first.
  96. $nextArg += 4;
  97. }
  98. setLogMode($nextArg);
  99. $logModeSpecified = true;
  100. $argUsed[$i+1]++;
  101. $i++;
  102. }
  103. else
  104. error("Error: Missing Command Line argument. Usage: -log <Mode: 0,1,2>");
  105. //--------------------
  106. case "-dir":
  107. $argUsed[$i]++;
  108. if ($hasNextArg)
  109. {
  110. // Append the mod to the end of the current list
  111. $userDirs = strreplace($userDirs, $nextArg, "");
  112. $userDirs = pushFront($userDirs, $nextArg, ";");
  113. $argUsed[$i+1]++;
  114. $i++;
  115. $dirCount++;
  116. }
  117. else
  118. error("Error: Missing Command Line argument. Usage: -dir <dir_name>");
  119. //--------------------
  120. // changed the default behavior of this command line arg. It now
  121. // defaults to ONLY loading the game, not tools
  122. // default auto-run already loads in tools --SRZ 11/29/07
  123. case "-game":
  124. $argUsed[$i]++;
  125. if ($hasNextArg)
  126. {
  127. // Set the selected dir --NOTE: we no longer allow tools with this argument
  128. /*
  129. if( $isDedicated )
  130. {
  131. $userDirs = $nextArg;
  132. $dirCount = 1;
  133. }
  134. else
  135. {
  136. $userDirs = "tools;" @ $nextArg;
  137. $dirCount = 2;
  138. }
  139. */
  140. $userDirs = $nextArg;
  141. $dirCount = 1;
  142. $argUsed[$i+1]++;
  143. $i++;
  144. error($userDirs);
  145. }
  146. else
  147. error("Error: Missing Command Line argument. Usage: -game <game_name>");
  148. //--------------------
  149. case "-console":
  150. enableWinConsole(true);
  151. $argUsed[$i]++;
  152. //--------------------
  153. case "-jSave":
  154. $argUsed[$i]++;
  155. if ($hasNextArg)
  156. {
  157. echo("Saving event log to journal: " @ $nextArg);
  158. saveJournal($nextArg);
  159. $argUsed[$i+1]++;
  160. $i++;
  161. }
  162. else
  163. error("Error: Missing Command Line argument. Usage: -jSave <journal_name>");
  164. //--------------------
  165. case "-jPlay":
  166. $argUsed[$i]++;
  167. if ($hasNextArg)
  168. {
  169. playJournal($nextArg);
  170. $argUsed[$i+1]++;
  171. $i++;
  172. }
  173. else
  174. error("Error: Missing Command Line argument. Usage: -jPlay <journal_name>");
  175. //--------------------
  176. case "-jPlayToVideo":
  177. $argUsed[$i]++;
  178. if ($hasNextArg)
  179. {
  180. $VideoCapture::journalName = $nextArg;
  181. $VideoCapture::captureFromJournal = true;
  182. $argUsed[$i+1]++;
  183. $i++;
  184. }
  185. else
  186. error("Error: Missing Command Line argument. Usage: -jPlayToVideo <journal_name>");
  187. //--------------------
  188. case "-vidCapFile":
  189. $argUsed[$i]++;
  190. if ($hasNextArg)
  191. {
  192. $VideoCapture::fileName = $nextArg;
  193. $argUsed[$i+1]++;
  194. $i++;
  195. }
  196. else
  197. error("Error: Missing Command Line argument. Usage: -vidCapFile <ouput_video_name>");
  198. //--------------------
  199. case "-vidCapFPS":
  200. $argUsed[$i]++;
  201. if ($hasNextArg)
  202. {
  203. $VideoCapture::fps = $nextArg;
  204. $argUsed[$i+1]++;
  205. $i++;
  206. }
  207. else
  208. error("Error: Missing Command Line argument. Usage: -vidCapFPS <ouput_video_framerate>");
  209. //--------------------
  210. case "-vidCapEncoder":
  211. $argUsed[$i]++;
  212. if ($hasNextArg)
  213. {
  214. $VideoCapture::encoder = $nextArg;
  215. $argUsed[$i+1]++;
  216. $i++;
  217. }
  218. else
  219. error("Error: Missing Command Line argument. Usage: -vidCapEncoder <ouput_video_encoder>");
  220. //--------------------
  221. case "-vidCapWidth":
  222. $argUsed[$i]++;
  223. if ($hasNextArg)
  224. {
  225. $videoCapture::width = $nextArg;
  226. $argUsed[$i+1]++;
  227. $i++;
  228. }
  229. else
  230. error("Error: Missing Command Line argument. Usage: -vidCapWidth <ouput_video_width>");
  231. //--------------------
  232. case "-vidCapHeight":
  233. $argUsed[$i]++;
  234. if ($hasNextArg)
  235. {
  236. $videoCapture::height = $nextArg;
  237. $argUsed[$i+1]++;
  238. $i++;
  239. }
  240. else
  241. error("Error: Missing Command Line argument. Usage: -vidCapHeight <ouput_video_height>");
  242. //--------------------
  243. case "-level":
  244. $argUsed[$i]++;
  245. if ($hasNextArg)
  246. {
  247. %hasExt = strpos($nextArg, ".mis");
  248. if(%hasExt == -1)
  249. {
  250. $levelToLoad = $nextArg @ " ";
  251. for(%i = $i + 2; %i < $Game::argc; %i++)
  252. {
  253. $arg = $Game::argv[%i];
  254. %hasExt = strpos($arg, ".mis");
  255. if(%hasExt == -1)
  256. {
  257. $levelToLoad = $levelToLoad @ $arg @ " ";
  258. } else
  259. {
  260. $levelToLoad = $levelToLoad @ $arg;
  261. break;
  262. }
  263. }
  264. }
  265. else
  266. {
  267. $levelToLoad = $nextArg;
  268. }
  269. $argUsed[$i+1]++;
  270. $i++;
  271. }
  272. else
  273. error("Error: Missing Command Line argument. Usage: -level <level file name (no path), with or without extension>");
  274. //-------------------
  275. case "-worldeditor":
  276. $startWorldEditor = true;
  277. $argUsed[$i]++;
  278. //-------------------
  279. case "-guieditor":
  280. $startGUIEditor = true;
  281. $argUsed[$i]++;
  282. //-------------------
  283. case "-help":
  284. $displayHelp = true;
  285. $argUsed[$i]++;
  286. //-------------------
  287. case "-compileAll":
  288. $compileAll = true;
  289. $argUsed[$i]++;
  290. //-------------------
  291. case "-compileTools":
  292. $compileTools = true;
  293. $argUsed[$i]++;
  294. //-------------------
  295. case "-genScript":
  296. $genScript = true;
  297. $argUsed[$i]++;
  298. case "-fullscreen":
  299. $cliFullscreen = true;
  300. $argUsed[%i]++;
  301. case "-windowed":
  302. $cliFullscreen = false;
  303. $argUsed[%i]++;
  304. case "-openGL":
  305. $pref::Video::displayDevice = "OpenGL";
  306. $argUsed[%i]++;
  307. case "-directX":
  308. $pref::Video::displayDevice = "D3D";
  309. $argUsed[%i]++;
  310. case "-autoVideo":
  311. $pref::Video::displayDevice = "";
  312. $argUsed[%i]++;
  313. case "-prefs":
  314. $argUsed[%i]++;
  315. if ($hasNextArg) {
  316. exec($nextArg, true, true);
  317. $argUsed[%i+1]++;
  318. %i++;
  319. }
  320. else
  321. error("Error: Missing Command Line argument. Usage: -prefs <path/script.cs>");
  322. //-------------------
  323. default:
  324. $argUsed[$i]++;
  325. if($userDirs $= "")
  326. $userDirs = $arg;
  327. }
  328. }
  329. //-----------------------------------------------
  330. // Play journal to video file?
  331. if ($VideoCapture::captureFromJournal && $VideoCapture::journalName !$= "")
  332. {
  333. if ($VideoCapture::fileName $= "")
  334. $VideoCapture::fileName = $VideoCapture::journalName;
  335. if ($VideoCapture::encoder $= "")
  336. $VideoCapture::encoder = "THEORA";
  337. if ($VideoCapture::fps $= "")
  338. $VideoCapture::fps = 30;
  339. if ($videoCapture::width $= "")
  340. $videoCapture::width = 0;
  341. if ($videoCapture::height $= "")
  342. $videoCapture::height = 0;
  343. playJournalToVideo( $VideoCapture::journalName, $VideoCapture::fileName,
  344. $VideoCapture::encoder, $VideoCapture::fps,
  345. $videoCapture::width SPC $videoCapture::height );
  346. }
  347. }