NeonTiger Posted January 29, 2019 Share Posted January 29, 2019 This is a small update of an old resource that was on garage games. http://www.garagegames.com/community/blogs/view/21262I added the ability to mark files that you are working in to keeps systems and things like the editor from freaking out and breaking.example: exec("scripts/server/stuff.cs");torexec("scripts/server/stuff.cs"); // this file will now auto exec after saving ////////////////////////////////////////////////////////////////////////////First open up volume.hFind these lines template inline bool AddChangeNotification( const Path &path, T obj, U func )Then add code above themtemplate inline bool AddChangeNotification(const Path &path, U func) { FileSystemRef fs = GetFileSystem(path); if (!fs || !fs->getChangeNotifier()) return false; FileSystemChangeNotifier::ChangeDelegate dlg(func); return fs->getChangeNotifier()->addNotification(path, dlg); } Now open up console.cppAbove this function bool executeFile(const char* fileName, bool noCalls, bool journalScript)Addvoid reExec(const Torque::Path &path); Now change bool executeFile(const char* fileName, bool noCalls, bool journalScript) Tobool executeFile(const char* fileName, bool noCalls, bool journalScript, bool rexec) In the same function change this lineif( (dsoPath && *dsoPath == 0) || (prefsPath && prefsPath[ 0 ] && dStrnicmp(scriptFileName, prefsPath, dStrlen(prefsPath)) == 0) )Toif( (dsoPath && *dsoPath == 0) || dStrstr(scriptFileName, "prefs.cs")) //(prefsPath && prefsPath[ 0 ] && dStrnicmp(scriptFileName, prefsPath, dStrlen(prefsPath)) == 0) ) Still in the same function add this after the last #endif if (compiled && rexec) { Torque::Path path(scriptFileName); Torque::FS::AddChangeNotification(path, &reExec); } After the bool executeFile function add void reExec(const Torque::Path &path) { //we know this is a file that exists, and a .cs file, so we can skip a lot of checks... CodeBlock *newCodeBlock = new CodeBlock(); StringTableEntry name = StringTable->insert(path.getFullPath().c_str()); void *data; U32 dataSize = 0; Torque::FS::ReadFile(name, data, dataSize, true); newCodeBlock->compileExec(name, (char*)data, false, 0); delete[] data; } Now open up console.h and change bool executeFile(const char* fileName, bool noCalls, bool journalScript);Tobool executeFile(const char* fileName, bool noCalls, bool journalScript,bool rexec); Lastly open up consoleFunctioncs.cpp and replace DefineEngineFunction( exec, bool, ( const char* fileName, bool noCalls, bool journalScript ), ( false, false ), "Execute the given script file.\n" "@param fileName Path to the file to execute\n" "@param noCalls Deprecated\n" "@param journalScript Deprecated\n" "@return True if the script was successfully executed, false if not.\n\n" "@tsexample\n" "// Execute the init.cs script file found in the same directory as the current script file.\n" "exec( \"./init.cs\" );\n" "@endtsexample\n\n" "@see compile\n" "@see eval\n" "@ingroup Scripting" ) { return Con::executeFile(fileName, noCalls, journalScript); } With this DefineEngineFunction( exec, bool, ( const char* fileName, bool noCalls, bool journalScript ), ( false, false ), "Execute the given script file.\n" "@param fileName Path to the file to execute\n" "@param noCalls Deprecated\n" "@param journalScript Deprecated\n" "@return True if the script was successfully executed, false if not.\n\n" "@tsexample\n" "// Execute the init.cs script file found in the same directory as the current script file.\n" "exec( \"./init.cs\" );\n" "@endtsexample\n\n" "@see compile\n" "@see eval\n" "@ingroup Scripting" ) { return Con::executeFile(fileName, noCalls, journalScript, false); } DefineEngineFunction(rexec, bool, (const char* fileName, bool noCalls, bool journalScript), (false, false), "Execute the given script file. As well as re-execute said file automatically after saving\n") { return Con::executeFile(fileName, noCalls, journalScript, true); } Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted January 29, 2019 Share Posted January 29, 2019 I remember this one! Very useful. Thanks. Quote Link to comment Share on other sites More sharing options...
Duion Posted January 29, 2019 Share Posted January 29, 2019 @NeonTigerThis is something I was looking for as well, I would suggest you to make a pull request into the main repo with this, so it gets added into the engine as a new feature, so not everyone has to maintain their own fork. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.