diff --git a/Templates/Empty/game/main.cs.in b/Templates/Empty/game/main.cs.in new file mode 100644 index 000000000..db8436e7d --- /dev/null +++ b/Templates/Empty/game/main.cs.in @@ -0,0 +1,280 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2012 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +// Set the name of our application +$appName = "@TORQUE_APP_NAME@"; + +// The directory it is run from +$defaultGame = "scripts"; + +// Set profile directory +$Pref::Video::ProfilePath = "core/profile"; + +function createCanvas(%windowTitle) +{ + if ($isDedicated) + { + GFXInit::createNullDevice(); + return true; + } + + // Create the Canvas + %foo = new GuiCanvas(Canvas); + + // Set the window title + if (isObject(Canvas)) + Canvas.setWindowTitle(getEngineName() @ " - " @ $appName); + + return true; +} + +// Display the optional commandline arguements +$displayHelp = false; + +// Use these to record and play back crashes +//saveJournal("editorOnFileQuitCrash.jrn"); +//playJournal("editorOnFileQuitCrash.jrn", false); + +//------------------------------------------------------------------------------ +// Check if a script file exists, compiled or not. +function isScriptFile(%path) +{ + if( isFile(%path @ ".dso") || isFile(%path) ) + return true; + + return false; +} + +//------------------------------------------------------------------------------ +// Process command line arguments +exec("core/parseArgs.cs"); + +$isDedicated = false; +$dirCount = 2; +$userDirs = $defaultGame @ ";art;levels"; + +// load tools scripts if we're a tool build +if (isToolBuild()) + $userDirs = "tools;" @ $userDirs; + + +// Parse the executable arguments with the standard +// function from core/main.cs +defaultParseArgs(); + + +if($dirCount == 0) { + $userDirs = $defaultGame; + $dirCount = 1; +} + +//----------------------------------------------------------------------------- +// Display a splash window immediately to improve app responsiveness before +// engine is initialized and main window created +if (!$isDedicated) + displaySplashWindow(); + + +//----------------------------------------------------------------------------- +// The displayHelp, onStart, onExit and parseArgs function are overriden +// by mod packages to get hooked into initialization and cleanup. + +function onStart() +{ + // Default startup function +} + +function onExit() +{ + // OnExit is called directly from C++ code, whereas onStart is + // invoked at the end of this file. +} + +function parseArgs() +{ + // Here for mod override, the arguments have already + // been parsed. +} + +function compileFiles(%pattern) +{ + %path = filePath(%pattern); + + %saveDSO = $Scripts::OverrideDSOPath; + %saveIgnore = $Scripts::ignoreDSOs; + + $Scripts::OverrideDSOPath = %path; + $Scripts::ignoreDSOs = false; + %mainCsFile = makeFullPath("main.cs"); + + for (%file = findFirstFileMultiExpr(%pattern); %file !$= ""; %file = findNextFileMultiExpr(%pattern)) + { + // we don't want to try and compile the primary main.cs + if(%mainCsFile !$= %file) + compile(%file, true); + } + + $Scripts::OverrideDSOPath = %saveDSO; + $Scripts::ignoreDSOs = %saveIgnore; + +} + +if($compileAll) +{ + echo(" --- Compiling all files ---"); + compileFiles("*.cs"); + compileFiles("*.gui"); + compileFiles("*.ts"); + echo(" --- Exiting after compile ---"); + quit(); +} + +if($compileTools) +{ + echo(" --- Compiling tools scritps ---"); + compileFiles("tools/*.cs"); + compileFiles("tools/*.gui"); + compileFiles("tools/*.ts"); + echo(" --- Exiting after compile ---"); + quit(); +} + +package Help { + function onExit() { + // Override onExit when displaying help + } +}; + +function displayHelp() { + activatePackage(Help); + + // Notes on logmode: console logging is written to console.log. + // -log 0 disables console logging. + // -log 1 appends to existing logfile; it also closes the file + // (flushing the write buffer) after every write. + // -log 2 overwrites any existing logfile; it also only closes + // the logfile when the application shuts down. (default) + + error( + "Torque Demo command line options:\n"@ + " -log Logging behavior; see main.cs comments for details\n"@ + " -game Reset list of mods to only contain \n"@ + " Works like the -game argument\n"@ + " -dir Add to list of directories\n"@ + " -console Open a separate console\n"@ + " -show Deprecated\n"@ + " -jSave Record a journal\n"@ + " -jPlay Play back a journal\n"@ + " -jDebug Play back a journal and issue an int3 at the end\n"@ + " -help Display this help message\n" + ); +} + + +//-------------------------------------------------------------------------- + +// Default to a new logfile each session. +if( !$logModeSpecified ) +{ + if( $platform !$= "xbox" && $platform !$= "xenon" ) + setLogMode(6); +} + +// Get the first dir on the list, which will be the last to be applied... this +// does not modify the list. +nextToken($userDirs, currentMod, ";"); + +// Execute startup scripts for each mod, starting at base and working up +function loadDir(%dir) +{ + pushback($userDirs, %dir, ";"); + + if (isScriptFile(%dir @ "/main.cs")) + exec(%dir @ "/main.cs"); +} + +echo("--------- Loading DIRS ---------"); +function loadDirs(%dirPath) +{ + %dirPath = nextToken(%dirPath, token, ";"); + if (%dirPath !$= "") + loadDirs(%dirPath); + + if(exec(%token @ "/main.cs") != true) + { + error("Error: Unable to find specified directory: " @ %token ); + $dirCount--; + } +} +loadDirs($userDirs); +echo(""); + +if($dirCount == 0) { + enableWinConsole(true); + error("Error: Unable to load any specified directories"); + quit(); +} +// Parse the command line arguments +echo("--------- Parsing Arguments ---------"); +parseArgs(); + +// Either display the help message or startup the app. +if ($displayHelp) { + enableWinConsole(true); + displayHelp(); + quit(); +} +else { + onStart(); + echo("Engine initialized..."); + + // Auto-load on the 360 + if( $platform $= "xenon" ) + { + %mission = "levels/Empty Terrain.mis"; + + echo("Xbox360 Autoloading level: '" @ %mission @ "'"); + + + if ($pref::HostMultiPlayer) + %serverType = "MultiPlayer"; + else + %serverType = "SinglePlayer"; + + createAndConnectToLocalServer( %serverType, %mission ); + } +} + +// Display an error message for unused arguments +for ($i = 1; $i < $Game::argc; $i++) { + if (!$argUsed[$i]) + error("Error: Unknown command line argument: " @ $Game::argv[$i]); +} + +// Automatically start up the appropriate eidtor, if any +if ($startWorldEditor) { + Canvas.setCursor("DefaultCursor"); + Canvas.setContent(EditorChooseLevelGui); +} else if ($startGUIEditor) { + Canvas.setCursor("DefaultCursor"); + Canvas.setContent(EditorChooseGUI); +} diff --git a/Templates/Full/game/main.cs.in b/Templates/Full/game/main.cs.in new file mode 100644 index 000000000..db8436e7d --- /dev/null +++ b/Templates/Full/game/main.cs.in @@ -0,0 +1,280 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2012 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +// Set the name of our application +$appName = "@TORQUE_APP_NAME@"; + +// The directory it is run from +$defaultGame = "scripts"; + +// Set profile directory +$Pref::Video::ProfilePath = "core/profile"; + +function createCanvas(%windowTitle) +{ + if ($isDedicated) + { + GFXInit::createNullDevice(); + return true; + } + + // Create the Canvas + %foo = new GuiCanvas(Canvas); + + // Set the window title + if (isObject(Canvas)) + Canvas.setWindowTitle(getEngineName() @ " - " @ $appName); + + return true; +} + +// Display the optional commandline arguements +$displayHelp = false; + +// Use these to record and play back crashes +//saveJournal("editorOnFileQuitCrash.jrn"); +//playJournal("editorOnFileQuitCrash.jrn", false); + +//------------------------------------------------------------------------------ +// Check if a script file exists, compiled or not. +function isScriptFile(%path) +{ + if( isFile(%path @ ".dso") || isFile(%path) ) + return true; + + return false; +} + +//------------------------------------------------------------------------------ +// Process command line arguments +exec("core/parseArgs.cs"); + +$isDedicated = false; +$dirCount = 2; +$userDirs = $defaultGame @ ";art;levels"; + +// load tools scripts if we're a tool build +if (isToolBuild()) + $userDirs = "tools;" @ $userDirs; + + +// Parse the executable arguments with the standard +// function from core/main.cs +defaultParseArgs(); + + +if($dirCount == 0) { + $userDirs = $defaultGame; + $dirCount = 1; +} + +//----------------------------------------------------------------------------- +// Display a splash window immediately to improve app responsiveness before +// engine is initialized and main window created +if (!$isDedicated) + displaySplashWindow(); + + +//----------------------------------------------------------------------------- +// The displayHelp, onStart, onExit and parseArgs function are overriden +// by mod packages to get hooked into initialization and cleanup. + +function onStart() +{ + // Default startup function +} + +function onExit() +{ + // OnExit is called directly from C++ code, whereas onStart is + // invoked at the end of this file. +} + +function parseArgs() +{ + // Here for mod override, the arguments have already + // been parsed. +} + +function compileFiles(%pattern) +{ + %path = filePath(%pattern); + + %saveDSO = $Scripts::OverrideDSOPath; + %saveIgnore = $Scripts::ignoreDSOs; + + $Scripts::OverrideDSOPath = %path; + $Scripts::ignoreDSOs = false; + %mainCsFile = makeFullPath("main.cs"); + + for (%file = findFirstFileMultiExpr(%pattern); %file !$= ""; %file = findNextFileMultiExpr(%pattern)) + { + // we don't want to try and compile the primary main.cs + if(%mainCsFile !$= %file) + compile(%file, true); + } + + $Scripts::OverrideDSOPath = %saveDSO; + $Scripts::ignoreDSOs = %saveIgnore; + +} + +if($compileAll) +{ + echo(" --- Compiling all files ---"); + compileFiles("*.cs"); + compileFiles("*.gui"); + compileFiles("*.ts"); + echo(" --- Exiting after compile ---"); + quit(); +} + +if($compileTools) +{ + echo(" --- Compiling tools scritps ---"); + compileFiles("tools/*.cs"); + compileFiles("tools/*.gui"); + compileFiles("tools/*.ts"); + echo(" --- Exiting after compile ---"); + quit(); +} + +package Help { + function onExit() { + // Override onExit when displaying help + } +}; + +function displayHelp() { + activatePackage(Help); + + // Notes on logmode: console logging is written to console.log. + // -log 0 disables console logging. + // -log 1 appends to existing logfile; it also closes the file + // (flushing the write buffer) after every write. + // -log 2 overwrites any existing logfile; it also only closes + // the logfile when the application shuts down. (default) + + error( + "Torque Demo command line options:\n"@ + " -log Logging behavior; see main.cs comments for details\n"@ + " -game Reset list of mods to only contain \n"@ + " Works like the -game argument\n"@ + " -dir Add to list of directories\n"@ + " -console Open a separate console\n"@ + " -show Deprecated\n"@ + " -jSave Record a journal\n"@ + " -jPlay Play back a journal\n"@ + " -jDebug Play back a journal and issue an int3 at the end\n"@ + " -help Display this help message\n" + ); +} + + +//-------------------------------------------------------------------------- + +// Default to a new logfile each session. +if( !$logModeSpecified ) +{ + if( $platform !$= "xbox" && $platform !$= "xenon" ) + setLogMode(6); +} + +// Get the first dir on the list, which will be the last to be applied... this +// does not modify the list. +nextToken($userDirs, currentMod, ";"); + +// Execute startup scripts for each mod, starting at base and working up +function loadDir(%dir) +{ + pushback($userDirs, %dir, ";"); + + if (isScriptFile(%dir @ "/main.cs")) + exec(%dir @ "/main.cs"); +} + +echo("--------- Loading DIRS ---------"); +function loadDirs(%dirPath) +{ + %dirPath = nextToken(%dirPath, token, ";"); + if (%dirPath !$= "") + loadDirs(%dirPath); + + if(exec(%token @ "/main.cs") != true) + { + error("Error: Unable to find specified directory: " @ %token ); + $dirCount--; + } +} +loadDirs($userDirs); +echo(""); + +if($dirCount == 0) { + enableWinConsole(true); + error("Error: Unable to load any specified directories"); + quit(); +} +// Parse the command line arguments +echo("--------- Parsing Arguments ---------"); +parseArgs(); + +// Either display the help message or startup the app. +if ($displayHelp) { + enableWinConsole(true); + displayHelp(); + quit(); +} +else { + onStart(); + echo("Engine initialized..."); + + // Auto-load on the 360 + if( $platform $= "xenon" ) + { + %mission = "levels/Empty Terrain.mis"; + + echo("Xbox360 Autoloading level: '" @ %mission @ "'"); + + + if ($pref::HostMultiPlayer) + %serverType = "MultiPlayer"; + else + %serverType = "SinglePlayer"; + + createAndConnectToLocalServer( %serverType, %mission ); + } +} + +// Display an error message for unused arguments +for ($i = 1; $i < $Game::argc; $i++) { + if (!$argUsed[$i]) + error("Error: Unknown command line argument: " @ $Game::argv[$i]); +} + +// Automatically start up the appropriate eidtor, if any +if ($startWorldEditor) { + Canvas.setCursor("DefaultCursor"); + Canvas.setContent(EditorChooseLevelGui); +} else if ($startGUIEditor) { + Canvas.setCursor("DefaultCursor"); + Canvas.setContent(EditorChooseGUI); +} diff --git a/Tools/CMake/basics.cmake b/Tools/CMake/basics.cmake index ead6ccc62..e69bb2330 100644 --- a/Tools/CMake/basics.cmake +++ b/Tools/CMake/basics.cmake @@ -1,6 +1,6 @@ project("Torque3DEngine") -set(TORQUE_TEMPLATE "Empty" CACHE STRING "the template to use") +set(TORQUE_TEMPLATE "Full" CACHE STRING "the template to use") set(projectDir "${CMAKE_SOURCE_DIR}/My Projects/${TORQUE_APP_NAME}") set(projectOutDir "${projectDir}/game") @@ -14,9 +14,6 @@ set(cmakeDir "${CMAKE_SOURCE_DIR}/Tools/CMake") #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${projectOutDir}/game) #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${projectOutDir}/game) -# change the default installation path to My Projects/app name -SET(CMAKE_INSTALL_PREFIX "${projectDir}" CACHE INTERNAL "Prefix prepended to install directories" FORCE) - # finds and adds sources files in a folder macro(addPath dir) set(tmpa "") @@ -117,12 +114,6 @@ endmacro() # macro to add an executable macro(addExecutable) - # more paths? - if(${ARGC} GREATER 0) - foreach(dir ${ARGV0}) - addPath("${dir}") - endforeach() - endif() # now inspect the paths we got set(firstDir "") foreach(dir ${${PROJECT_NAME}_paths}) @@ -133,9 +124,7 @@ macro(addExecutable) generateFilters("${firstDir}") add_executable("${PROJECT_NAME}" WIN32 ${${PROJECT_NAME}_files}) # omg - only use the first folder ... otehrwise we get lots of header name collisions - #foreach(dir ${${PROJECT_NAME}_paths}) addInclude("${firstDir}") - #endforeach() endmacro() diff --git a/Tools/CMake/template.torsion.in b/Tools/CMake/template.torsion.in new file mode 100644 index 000000000..f832ad13b --- /dev/null +++ b/Tools/CMake/template.torsion.in @@ -0,0 +1,39 @@ + +@TORQUE_APP_NAME@ + +main.cs +dbgSetParameters( #port#, "#password#", true ); + +core +scripts +art +levels +shaders +tools + +cs; gui + + +Release +@TORQUE_APP_NAME@.exe + +true +true +true +false + + +Debug +@TORQUE_APP_NAME@.exe + +true +true +true +false + + + +@TORQUE_APP_NAME@ +HEAD +true + diff --git a/Tools/CMake/torque3d.cmake b/Tools/CMake/torque3d.cmake index 99dec40b4..e31eeb92f 100644 --- a/Tools/CMake/torque3d.cmake +++ b/Tools/CMake/torque3d.cmake @@ -1,4 +1,4 @@ -project(torque3d) +project(${TORQUE_APP_NAME}) # TODO: fmod support @@ -317,12 +317,18 @@ endif() if(NOT EXISTS "${projectSrcDir}/torque.ico") CONFIGURE_FILE("${cmakeDir}/torque.ico" "${projectSrcDir}/torque.ico" COPYONLY) endif() +if(NOT EXISTS "${projectOutDir}/${PROJECT_NAME}.torsion") + CONFIGURE_FILE("${cmakeDir}/template.torsion.in" "${projectOutDir}/${PROJECT_NAME}.torsion") +endif() +if(EXISTS "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/game/main.cs.in" AND NOT EXISTS "${projectOutDir}/main.cs") + CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/game/main.cs.in" "${projectOutDir}/main.cs") +endif() if(WIN32) if(NOT EXISTS "${projectSrcDir}/torque.rc") CONFIGURE_FILE("${cmakeDir}/torque-win.rc.in" "${projectSrcDir}/torque.rc") endif() - if(NOT EXISTS "${projectDir}/cleanup.bat") - CONFIGURE_FILE("${cmakeDir}/cleanup-win.bat.in" "${projectDir}/cleanup.bat") + if(NOT EXISTS "${projectOutDir}/cleanup.bat") + CONFIGURE_FILE("${cmakeDir}/cleanup-win.bat.in" "${projectOutDir}/cleanup.bat") endif() endif() @@ -435,12 +441,12 @@ endif() ############################################################################### # Installation ############################################################################### -INSTALL_FILES(/ FILES ${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/game) +INSTALL(DIRECTORY "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/game" DESTINATION "${projectDir}") if(WIN32) - INSTALL_FILES(/ FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/cleanShaders.bat") - INSTALL_FILES(/ FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/DeleteCachedDTSs.bat") - INSTALL_FILES(/ FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/DeleteDSOs.bat") - INSTALL_FILES(/ FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/DeletePrefs.bat") + INSTALL(FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/cleanShaders.bat" DESTINATION "${projectDir}") + INSTALL(FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/DeleteCachedDTSs.bat" DESTINATION "${projectDir}") + INSTALL(FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/DeleteDSOs.bat" DESTINATION "${projectDir}") + INSTALL(FILES "${CMAKE_SOURCE_DIR}/Templates/${TORQUE_TEMPLATE}/DeletePrefs.bat" DESTINATION "${projectDir}") endif() INCLUDE(CPack) \ No newline at end of file