1 //-----------------------------------------------------------------------------
2 // Copyright (c) 2012 GarageGames, LLC
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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
21 //-----------------------------------------------------------------------------
23 // Set the name of our application
24 $appName
= "@TORQUE_APP_NAME@";
26 // The directory it is run from
27 $defaultGame
= "scripts";
29 // Set profile directory
30 $Pref
::Video
::ProfilePath
= "core/profile";
32 function
createCanvas(%windowTitle
)
36 GFXInit::createNullDevice();
41 %foo
= new GuiCanvas(Canvas
)
43 displayWindow
= $platform
!$= "windows";
48 // Set the window title
50 Canvas
.setWindowTitle(getEngineName() @ " - " @ $appName
);
55 // Display the optional commandline arguements
58 // Use these to record and play back crashes
59 //saveJournal("editorOnFileQuitCrash.jrn");
60 //playJournal("editorOnFileQuitCrash.jrn");
62 //------------------------------------------------------------------------------
63 // Check if a script file exists, compiled or not.
64 function
isScriptFile(%path
)
66 if( isFile(%path
@ ".dso") || isFile(%path
) )
72 //------------------------------------------------------------------------------
73 // Process command line arguments
74 exec("core/parseArgs.cs");
78 $userDirs
= $defaultGame
@ ";art;levels";
80 // load tools scripts if we're a tool build
82 $userDirs
= "tools;" @ $userDirs
;
85 // Parse the executable arguments with the standard
86 // function from core/main.cs
91 $userDirs
= $defaultGame
;
95 //-----------------------------------------------------------------------------
96 // Display a splash window immediately to improve app responsiveness before
97 // engine is initialized and main window created
99 displaySplashWindow();
102 //-----------------------------------------------------------------------------
103 // The displayHelp, onStart, onExit and parseArgs function are overriden
104 // by mod packages to get hooked into initialization and cleanup.
108 // Default startup function
113 // OnExit is called directly from C++ code, whereas onStart is
114 // invoked at the end of this file.
119 // Here for mod override, the arguments have already
123 function
compileFiles(%pattern
)
125 %path
= filePath(%pattern
);
127 %saveDSO
= $Scripts
::OverrideDSOPath
;
128 %saveIgnore
= $Scripts
::ignoreDSOs
;
130 $Scripts
::OverrideDSOPath
= %path
;
131 $Scripts
::ignoreDSOs
= false;
132 %mainCsFile
= makeFullPath("main.cs");
134 for (%file
= findFirstFileMultiExpr(%pattern
); %file
!$= ""; %file
= findNextFileMultiExpr(%pattern
))
136 // we don't want to try and compile the primary main.cs
137 if(%mainCsFile
!$= %file
)
138 compile(%file
, true);
141 $Scripts
::OverrideDSOPath
= %saveDSO
;
142 $Scripts
::ignoreDSOs
= %saveIgnore
;
148 echo(" --- Compiling all files ---");
149 compileFiles("*.cs");
150 compileFiles("*.gui");
151 compileFiles("*.ts");
152 echo(" --- Exiting after compile ---");
158 echo(" --- Compiling tools scritps ---");
159 compileFiles("tools/*.cs");
160 compileFiles("tools/*.gui");
161 compileFiles("tools/*.ts");
162 echo(" --- Exiting after compile ---");
168 // Override onExit when displaying help
172 function
displayHelp() {
173 activatePackage(Help
);
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)
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"
196 //--------------------------------------------------------------------------
198 // Default to a new logfile each session.
199 if( !$logModeSpecified
)
201 if( $platform
!$= "xbox" && $platform
!$= "xenon" )
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
, ";");
209 // Execute startup scripts for each mod, starting at base and working up
210 function
loadDir(%dir
)
212 pushback($userDirs
, %dir
, ";");
214 if (isScriptFile(%dir
@ "/main.cs"))
215 exec(%dir
@ "/main.cs");
218 echo("--------- Loading DIRS ---------");
219 function
loadDirs(%dirPath
)
221 %dirPath
= nextToken(%dirPath
, token
, ";");
225 if(exec(%token
@ "/main.cs") != true)
227 error("Error: Unable to find specified directory: " @ %token
);
235 enableWinConsole(true);
236 error("Error: Unable to load any specified directories");
239 // Parse the command line arguments
240 echo("--------- Parsing Arguments ---------");
243 // Either display the help message or startup the app.
245 enableWinConsole(true);
251 echo("Engine initialized...");
255 // As we know at this point that the initial load is complete,
256 // we can hide any splash screen we have, and show the canvas.
257 // This keeps things looking nice, instead of having a blank window
262 // Auto-load on the 360
263 if( $platform
$= "xenon" )
265 %mission
= "levels/Empty Terrain.mis";
267 echo("Xbox360 Autoloading level: '" @ %mission
@ "'");
270 if ($pref
::HostMultiPlayer
)
271 %serverType
= "MultiPlayer";
273 %serverType
= "SinglePlayer";
275 createAndConnectToLocalServer( %serverType
, %mission
);
279 // Display an error message for unused arguments
280 for ($i
= 1; $i
< $Game
::argc
; $i
++) {
282 error("Error: Unknown command line argument: " @ $Game
::argv
[$i
]);
285 // Automatically start up the appropriate eidtor, if any
286 if ($startWorldEditor
) {
287 Canvas
.setCursor("DefaultCursor");
288 Canvas
.setContent(EditorChooseLevelGui
);
289 } else if ($startGUIEditor
) {
290 Canvas
.setCursor("DefaultCursor");
291 Canvas
.setContent(EditorChooseGUI
);