Merge pull request #1677 from Areloch/i386FlagFlip
[Torque-3d.git] / Templates / Full / game / main.cs.in
bloba541cf3b79d109ab8493da770c6c838202fb2136
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:
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
20 // IN THE SOFTWARE.
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)
34 if ($isDedicated)
36 GFXInit::createNullDevice();
37 return true;
40 // Create the Canvas
41 %foo = new GuiCanvas(Canvas)
43 displayWindow = $platform !$= "windows";
46 $GameCanvas = %foo;
48 // Set the window title
49 if (isObject(Canvas))
50 Canvas.setWindowTitle(getEngineName() @ " - " @ $appName);
52 return true;
55 // Display the optional commandline arguements
56 $displayHelp = false;
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) )
67 return true;
69 return false;
72 //------------------------------------------------------------------------------
73 // Process command line arguments
74 exec("core/parseArgs.cs");
76 $isDedicated = false;
77 $dirCount = 2;
78 $userDirs = $defaultGame @ ";art;levels";
80 // load tools scripts if we're a tool build
81 if (isToolBuild())
82 $userDirs = "tools;" @ $userDirs;
85 // Parse the executable arguments with the standard
86 // function from core/main.cs
87 defaultParseArgs();
90 if($dirCount == 0) {
91 $userDirs = $defaultGame;
92 $dirCount = 1;
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();
102 //-----------------------------------------------------------------------------
103 // The displayHelp, onStart, onExit and parseArgs function are overriden
104 // by mod packages to get hooked into initialization and cleanup.
106 function onStart()
108 // Default startup function
111 function onExit()
113 // OnExit is called directly from C++ code, whereas onStart is
114 // invoked at the end of this file.
117 function parseArgs()
119 // Here for mod override, the arguments have already
120 // been parsed.
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;
146 if($compileAll)
148 echo(" --- Compiling all files ---");
149 compileFiles("*.cs");
150 compileFiles("*.gui");
151 compileFiles("*.ts");
152 echo(" --- Exiting after compile ---");
153 quit();
156 if($compileTools)
158 echo(" --- Compiling tools scritps ---");
159 compileFiles("tools/*.cs");
160 compileFiles("tools/*.gui");
161 compileFiles("tools/*.ts");
162 echo(" --- Exiting after compile ---");
163 quit();
166 package Help {
167 function onExit() {
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)
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"
196 //--------------------------------------------------------------------------
198 // Default to a new logfile each session.
199 if( !$logModeSpecified )
201 if( $platform !$= "xbox" && $platform !$= "xenon" )
202 setLogMode(6);
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, ";");
222 if (%dirPath !$= "")
223 loadDirs(%dirPath);
225 if(exec(%token @ "/main.cs") != true)
227 error("Error: Unable to find specified directory: " @ %token );
228 $dirCount--;
231 loadDirs($userDirs);
232 echo("");
234 if($dirCount == 0) {
235 enableWinConsole(true);
236 error("Error: Unable to load any specified directories");
237 quit();
239 // Parse the command line arguments
240 echo("--------- Parsing Arguments ---------");
241 parseArgs();
243 // Either display the help message or startup the app.
244 if ($displayHelp) {
245 enableWinConsole(true);
246 displayHelp();
247 quit();
249 else {
250 onStart();
251 echo("Engine initialized...");
253 if( !$isDedicated )
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
258 closeSplashWindow();
259 Canvas.showWindow();
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";
272 else
273 %serverType = "SinglePlayer";
275 createAndConnectToLocalServer( %serverType, %mission );
279 // Display an error message for unused arguments
280 for ($i = 1; $i < $Game::argc; $i++) {
281 if (!$argUsed[$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);