Guest User

Untitled

a guest
Dec 5th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.46 KB | None | 0 0
  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. // Set the name of our application
  24. $appName = "Empty";
  25.  
  26. // The directory it is run from
  27. $defaultGame = "scripts";
  28.  
  29. // Set profile directory
  30. $Pref::Video::ProfilePath = "core/profile";
  31.  
  32. function createCanvas(%windowTitle)
  33. {
  34.    if ($isDedicated)
  35.    {
  36.       GFXInit::createNullDevice();
  37.       return true;
  38.    }
  39.  
  40.    // Create the Canvas
  41.    %foo = new GuiCanvas(Canvas)
  42.    {
  43.       displayWindow = $platform !$= "windows";
  44.    };
  45.  
  46.    $GameCanvas = %foo;
  47.  
  48.    // Set the window title
  49.    if (isObject(Canvas))
  50.       Canvas.setWindowTitle(getEngineName() @ " - " @ $appName);
  51.  
  52.    return true;
  53. }
  54.  
  55. // Display the optional commandline arguements
  56. $displayHelp = false;
  57.  
  58. // Use these to record and play back crashes
  59. //saveJournal("editorOnFileQuitCrash.jrn");
  60. //playJournal("editorOnFileQuitCrash.jrn");
  61.  
  62. //------------------------------------------------------------------------------
  63. // Check if a script file exists, compiled or not.
  64. function isScriptFile(%path)
  65. {
  66.    if( isFile(%path @ ".dso") || isFile(%path) )
  67.       return true;
  68.  
  69.    return false;
  70. }
  71.  
  72. //------------------------------------------------------------------------------
  73. // Process command line arguments
  74. exec("core/parseArgs.cs");
  75.  
  76. $isDedicated = false;
  77. $dirCount = 2;
  78. $userDirs = $defaultGame @ ";art;levels";
  79.  
  80. // load tools scripts if we're a tool build
  81. if (isToolBuild())
  82.     $userDirs = "tools;" @ $userDirs;
  83.  
  84.  
  85. // Parse the executable arguments with the standard
  86. // function from core/main.cs
  87. defaultParseArgs();
  88.  
  89.  
  90. if($dirCount == 0) {
  91.       $userDirs = $defaultGame;
  92.       $dirCount = 1;
  93. }
  94.  
  95. //-----------------------------------------------------------------------------
  96. // Display a splash window immediately to improve app responsiveness before
  97. // engine is initialized and main window created
  98. if (!$isDedicated)
  99.    displaySplashWindow();
  100.  
  101.  
  102. //-----------------------------------------------------------------------------
  103. // The displayHelp, onStart, onExit and parseArgs function are overriden
  104. // by mod packages to get hooked into initialization and cleanup.
  105.  
  106. function onStart()
  107. {
  108.    // Default startup function
  109. }
  110.  
  111. function onExit()
  112. {
  113.    // OnExit is called directly from C++ code, whereas onStart is
  114.    // invoked at the end of this file.
  115. }
  116.  
  117. function parseArgs()
  118. {
  119.    // Here for mod override, the arguments have already
  120.    // been parsed.
  121. }
  122.  
  123. function compileFiles(%pattern)
  124. {
  125.    %path = filePath(%pattern);
  126.  
  127.    %saveDSO    = $Scripts::OverrideDSOPath;
  128.    %saveIgnore = $Scripts::ignoreDSOs;
  129.  
  130.    $Scripts::OverrideDSOPath  = %path;
  131.    $Scripts::ignoreDSOs       = false;
  132.    %mainCsFile = makeFullPath("main.cs");
  133.  
  134.    for (%file = findFirstFileMultiExpr(%pattern); %file !$= ""; %file = findNextFileMultiExpr(%pattern))
  135.    {
  136.       // we don't want to try and compile the primary main.cs
  137.       if(%mainCsFile !$= %file)
  138.          compile(%file, true);
  139.    }
  140.  
  141.    $Scripts::OverrideDSOPath  = %saveDSO;
  142.    $Scripts::ignoreDSOs       = %saveIgnore;
  143.  
  144. }
  145.  
  146. if($compileAll)
  147. {
  148.    echo(" --- Compiling all files ---");
  149.    compileFiles("*.cs");
  150.    compileFiles("*.gui");
  151.    compileFiles("*.ts");
  152.    echo(" --- Exiting after compile ---");
  153.    quit();
  154. }
  155.  
  156. if($compileTools)
  157. {
  158.    echo(" --- Compiling tools scritps ---");
  159.    compileFiles("tools/*.cs");
  160.    compileFiles("tools/*.gui");
  161.    compileFiles("tools/*.ts");
  162.    echo(" --- Exiting after compile ---");
  163.    quit();
  164. }
  165.  
  166. package Help {
  167.    function onExit() {
  168.       // Override onExit when displaying help
  169.    }
  170. };
  171.  
  172. function displayHelp() {
  173.    activatePackage(Help);
  174.  
  175.       // Notes on logmode: console logging is written to console.log.
  176.       // -log 0 disables console logging.
  177.       // -log 1 appends to existing logfile; it also closes the file
  178.       // (flushing the write buffer) after every write.
  179.       // -log 2 overwrites any existing logfile; it also only closes
  180.       // the logfile when the application shuts down.  (default)
  181.  
  182.    error(
  183.       "Torque Demo command line options:\n"@
  184.       "  -log <logmode>         Logging behavior; see main.cs comments for details\n"@
  185.       "  -game <game_name>      Reset list of mods to only contain <game_name>\n"@
  186.       "  <game_name>            Works like the -game argument\n"@
  187.       "  -dir <dir_name>        Add <dir_name> to list of directories\n"@
  188.       "  -console               Open a separate console\n"@
  189.       "  -jSave  <file_name>    Record a journal\n"@
  190.       "  -jPlay  <file_name>    Play back a journal\n"@
  191.       "  -help                  Display this help message\n"
  192.    );
  193. }
  194.  
  195.  
  196. //--------------------------------------------------------------------------
  197.  
  198. // Default to a new logfile each session.
  199. if( !$logModeSpecified )
  200. {
  201.    if( $platform !$= "xbox" && $platform !$= "xenon" )
  202.       setLogMode(6);
  203. }
  204.  
  205. // Get the first dir on the list, which will be the last to be applied... this
  206. // does not modify the list.
  207. nextToken($userDirs, currentMod, ";");
  208.  
  209. // Execute startup scripts for each mod, starting at base and working up
  210. function loadDir(%dir)
  211. {
  212.    pushback($userDirs, %dir, ";");
  213.  
  214.    if (isScriptFile(%dir @ "/main.cs"))
  215.    exec(%dir @ "/main.cs");
  216. }
  217.  
  218. echo("--------- Loading DIRS ---------");
  219. function loadDirs(%dirPath)
  220. {
  221.    %dirPath = nextToken(%dirPath, token, ";");
  222.    if (%dirPath !$= "")
  223.       loadDirs(%dirPath);
  224.  
  225.    if(exec(%token @ "/main.cs") != true)
  226.    {
  227.       error("Error: Unable to find specified directory: " @ %token );
  228.       $dirCount--;
  229.    }
  230. }
  231. loadDirs($userDirs);
  232. echo("");
  233.  
  234. if($dirCount == 0) {
  235.    enableWinConsole(true);
  236.    error("Error: Unable to load any specified directories");
  237.    quit();
  238. }
  239. // Parse the command line arguments
  240. echo("--------- Parsing Arguments ---------");
  241. parseArgs();
  242.  
  243. // Either display the help message or startup the app.
  244. if ($displayHelp) {
  245.    enableWinConsole(true);
  246.    displayHelp();
  247.    quit();
  248. }
  249. else {
  250.    onStart();
  251.    echo("Engine initialized...");
  252.  
  253.    ModuleDatabase.scanModules( "" );
  254.  
  255.    //You can also explicitly decalre some modules here to be loaded by default if they are part of your game
  256.    //Ex: ModuleDatabase.LoadExplicit( "AppCore" );
  257.  
  258.    if( !$isDedicated )
  259.    {
  260.       // As we know at this point that the initial load is complete,
  261.       // we can hide any splash screen we have, and show the canvas.
  262.       // This keeps things looking nice, instead of having a blank window
  263.       closeSplashWindow();
  264.       Canvas.showWindow();
  265.    }
  266.  
  267.    // Auto-load on the 360
  268.    if( $platform $= "xenon" )
  269.    {
  270.       %mission = "levels/Empty Terrain.mis";
  271.  
  272.       echo("Xbox360 Autoloading level: '" @ %mission @ "'");
  273.  
  274.  
  275.       if ($pref::HostMultiPlayer)
  276.          %serverType = "MultiPlayer";
  277.       else
  278.          %serverType = "SinglePlayer";
  279.  
  280.       createAndConnectToLocalServer( %serverType, %mission );
  281.    }
  282. }
  283.  
  284. // Display an error message for unused arguments
  285. for ($i = 1; $i < $Game::argc; $i++)  {
  286.    if (!$argUsed[$i])
  287.       error("Error: Unknown command line argument: " @ $Game::argv[$i]);
  288. }
  289.  
  290. // Automatically start up the appropriate eidtor, if any
  291. if ($startWorldEditor) {
  292.    Canvas.setCursor("DefaultCursor");
  293.    Canvas.setContent(EditorChooseLevelGui);
  294. } else if ($startGUIEditor) {
  295.    Canvas.setCursor("DefaultCursor");
  296.    Canvas.setContent(EditorChooseGUI);
  297. }
Add Comment
Please, Sign In to add comment