Live updating for scripts
by Dan Keller · 09/23/2011 (8:26 am) · 10 comments
The moral equivalent of the live resource updater. Edit your script, save it, and have it update instantly in the game. What's not to like?
Note: This ignores .mis, prefs.cs, etc. There really isn't a good reason to live update those. It will also only update scripts for which there is no .dso, so it won't do anything in a release version (ie if TORQUE_NO_DSO_GENERATION is not defined).
Use:
In core/volume.h at line 429 add
In consoleconsoleFunctions.cpp at line 1808 add
change line 1895 from
At line 2112 after #endif add
And at 2138 after the function add
Enjoy!
Note: This ignores .mis, prefs.cs, etc. There really isn't a good reason to live update those. It will also only update scripts for which there is no .dso, so it won't do anything in a release version (ie if TORQUE_NO_DSO_GENERATION is not defined).
Use:
In core/volume.h at line 429 add
/// Adds a file change notification callback for a function.
///@ingroup VolumeSystem
template <class U>
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 );
}In consoleconsoleFunctions.cpp at line 1808 add
void reExec(const Torque::Path &path);
change line 1895 from
if( (dsoPath && *dsoPath == 0) || (prefsPath && prefsPath[ 0 ] && dStrnicmp(scriptFileName, prefsPath, dStrlen(prefsPath)) == 0) )to
if( (dsoPath && *dsoPath == 0) || dStrstr(scriptFileName, "prefs.cs")) //(prefsPath && prefsPath[ 0 ] && dStrnicmp(scriptFileName, prefsPath, dStrlen(prefsPath)) == 0) )This also fixes that line so prefs files don't generate dso's
At line 2112 after #endif add
if (compiled) //if this is true TORQUE_NO_DSO_GENERATION must be defined and it must not be prefs / .mis
{
Torque::Path path(scriptFileName);
Torque::FS::AddChangeNotification(path, &reExec);
}And at 2138 after the 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;
}Enjoy!
#2
09/25/2011 (7:06 am)
That's a good resource,thanks!
#3
10/03/2011 (11:08 pm)
I implemented this, haven't had the time to test it yet though. compiled alright.
#4
This is the most awesome Torque productivity tool, ever.
Thank you so much for posting this as a resource!
10/04/2011 (12:58 pm)
I'm working on multiple running servers, and they all pick up the change to a single source tree while running. This is the most awesome Torque productivity tool, ever.
Thank you so much for posting this as a resource!
#5
I was keeping a script file in my tree, full of exec() commands to various scripts I am always changing, so I could easily copy and paste those lines into the console after editing a script to see the changes immediately in-game... But this resource does all of this automatically now whenever I change a script, which is a FANTASTIC tool.
Many thanks, this will get used more times than I can count...
Kudos!
11/03/2011 (9:06 am)
Works like a charm!I was keeping a script file in my tree, full of exec() commands to various scripts I am always changing, so I could easily copy and paste those lines into the console after editing a script to see the changes immediately in-game... But this resource does all of this automatically now whenever I change a script, which is a FANTASTIC tool.
Many thanks, this will get used more times than I can count...
Kudos!
#6
11/06/2011 (3:13 am)
Thank you very much Dan. This is gonna save me some valuable time!
#7
01/07/2012 (2:23 pm)
I had to put the very last code at line 1165 in T3D 1.2
#8
01/24/2012 (8:29 am)
Works perfectly - fantastic resource!
#9
04/18/2012 (4:56 am)
Umm the line numbers doesn't work out in my version of the engine, could you write what comes before or after each codesnippet? :) Thank you very much!
#10
so not sure in 1.2 where to add this lines:
as u r saying "TORQUE_NO_DSO_GENERATION must be defined ",so i have added it just after :
is that correct?
09/13/2012 (3:25 am)
i do not have t3d 1.1 code at hand now.so not sure in 1.2 where to add this lines:
Quote:
At line 2112 after #endif add
if (compiled) //if this is true TORQUE_NO_DSO_GENERATION must be defined and it must not be prefs / .mis
{
Torque::Path path(scriptFileName);
Torque::FS::AddChangeNotification(path, &reExec);
}
as u r saying "TORQUE_NO_DSO_GENERATION must be defined ",so i have added it just after :
else
{
// We have to exit out here, as otherwise we get double error reports.
delete [] script;
execDepth--;
return false;
}
}
#endifis that correct?

Torque Owner Guy Allard
Default Studio Name