TorqueX "script" behavior question
by Pauliver · in Torque Game Engine · 10/03/2006 (7:21 am) · 8 replies
I'm not sure how to phrase this question so i'm going to use source code instead:
The code below is in Managed C++ not C# but you could easily port it to C#
I guesss what i'm really wondering is TorqueX going to include that code (except in C#)? So that its more like other torque projects where the engine itself compiles what is refered to as "Script" and then loads it (*if not dibs on the resource*) Or will work on TorqueX have to occure inside a C# capable IDE and you will have to compile everything before you want to run it?
*before people start to correct me* i would imagine that TorqueX could only work like that under windows, i know the full .net framework isn't available on Xbox 360.
The code below is in Managed C++ not C# but you could easily port it to C#
System::String^ GatherFiles(System::String^ path)
{
//over my post limit so the code in here had to go
//it gathers multiple files data into a single string
}
void CompileScripts(bool DebugInfo)
{
System::String ^AssemblyName = gcnew System::String("Basic.dll");
Microsoft::CSharp::CSharpCodeProvider ^myCodeProvider = gcnew Microsoft::CSharp::CSharpCodeProvider();
System::CodeDom::Compiler::ICodeCompiler ^myCodeCompiler = myCodeProvider->CreateCompiler();
array<String^> ^references = gcnew array<String^> {"System.dll","ScriptSystem.dll"};//,"GameBryoScriptSystem.exe"};
System::CodeDom::Compiler::CompilerParameters ^myCompilerParameters = gcnew System::CodeDom::Compiler::CompilerParameters(references,AssemblyName,DebugInfo);
myCompilerParameters->GenerateExecutable = false;
myCompilerParameters->GenerateInMemory = false;
String ^CsharpSourceCode = gcnew String("");
//it runs from the directory that hte project file is in by default
//if this is returning false then wwe need to change the startup directory
//in the project file
CsharpSourceCode = GatherFiles("./");
//we will need to go through this
//and remove duplicate instances of
// "Using <thing>;
//
//
System::CodeDom::Compiler::CompilerResults ^myCompilerResults;
try{
myCompilerResults = myCodeCompiler->CompileAssemblyFromSource(myCompilerParameters, CsharpSourceCode);
}catch(System::Exception^ ex)
{
throw gcnew System::Exception(ex->ToString());
}
if(myCompilerResults->Errors->Count > 0 )
{
//this should probably go from void to bool, or better yet string
//or the data could be packed into something else and gathered from that
//or dumped into a .log file
myCompilerResults->Errors->ToString();
}
else
{
System::AppDomainSetup ^ads = gcnew System::AppDomainSetup();
ads->ShadowCopyFiles = "true";
System::AppDomain::CurrentDomain->SetShadowCopyFiles();
System::AppDomain ^newDomain = System::AppDomain::CreateDomain("BasicDomain");
//byte[] rawAssembly = loadFile("TestClass.dll");
// we are loading the assembly in its own app domain so we can UNLOAD it
// if we reach a point where such functionality might be usefull
// if there are problems with callign things from the script
// this might be it so try puting it in the same AppDomain as the rest of
// the executable
//System::Reflection::Assembly ^a = System::Reflection::Assembly::Load(myCompilerResults->CompiledAssembly->GetName());
try{
System::Reflection::Assembly ^a = newDomain->Load(myCompilerResults->CompiledAssembly->GetName());
System::Type ^t = a->GetType("ScriptMain");
System::Object ^object = a->CreateInstance("ScriptMain");
}catch(System::Exception ^ex)
{
throw gcnew System::Exception(ex->ToString()); //should do some kind of exception handling
}
}
}I guesss what i'm really wondering is TorqueX going to include that code (except in C#)? So that its more like other torque projects where the engine itself compiles what is refered to as "Script" and then loads it (*if not dibs on the resource*) Or will work on TorqueX have to occure inside a C# capable IDE and you will have to compile everything before you want to run it?
*before people start to correct me* i would imagine that TorqueX could only work like that under windows, i know the full .net framework isn't available on Xbox 360.
#2
I understand TorqueX will use C# exclusvily. I'm asking about what game model will it follow.
.. Im still not sure how to phrase this correctly.. The code i paisted above will take a series of C# files and compile them into a .dll and then load them. I designed it for use in another game engine so that i could drive it from C# but didn't have to use visual studio .net to re-compile it every time. (As a matter of fact it was finially settled on because the artists will want to be able to tweak there stuff but do not have visual studio installed).
Will the TorqueX engine require all work to be done in a C# ide and compiled at once and then run
or will it be an engine written in C#, and then haveing a C# based scripting system. that is compiled by that engine.
I hope that is more clear?
10/03/2006 (10:31 am)
I dont think we are communicating correctly...I understand TorqueX will use C# exclusvily. I'm asking about what game model will it follow.
.. Im still not sure how to phrase this correctly.. The code i paisted above will take a series of C# files and compile them into a .dll and then load them. I designed it for use in another game engine so that i could drive it from C# but didn't have to use visual studio .net to re-compile it every time. (As a matter of fact it was finially settled on because the artists will want to be able to tweak there stuff but do not have visual studio installed).
Will the TorqueX engine require all work to be done in a C# ide and compiled at once and then run
or will it be an engine written in C#, and then haveing a C# based scripting system. that is compiled by that engine.
I hope that is more clear?
#3
The above Managed C++ code is right along those lines and is very similar to what I have referenced in Reality Engine and other things with C# Interfacing.
Reality Engine is C++ with a ScriptingSystem which is Managed C++ that interfaces the C# side of Windows (CLI and such). It compiles the C# files at runtime and generates a dll which is then dynamically loaded. This allows for some quicker development time in certain scenarios, but not in others.
Then you have an engine like Source which is C++, but for any changes to the gameplay aspects requires loading Visual Studio or such and compiling a brand new DLL.
10/03/2006 (10:39 am)
I think what he is asking is if the "scripting" side of TorqueX will be all C# precompiled, or if there will be methods to compile into Memory or locations (Hard drive, etc).The above Managed C++ code is right along those lines and is very similar to what I have referenced in Reality Engine and other things with C# Interfacing.
Reality Engine is C++ with a ScriptingSystem which is Managed C++ that interfaces the C# side of Windows (CLI and such). It compiles the C# files at runtime and generates a dll which is then dynamically loaded. This allows for some quicker development time in certain scenarios, but not in others.
Then you have an engine like Source which is C++, but for any changes to the gameplay aspects requires loading Visual Studio or such and compiling a brand new DLL.
#4
10/04/2006 (2:26 pm)
Is this unclear? Has a decision not been made? Did no one think about this till i posted?
#5
10/04/2006 (2:30 pm)
It's simply not something we're ready to discuss yet.
#6
10/04/2006 (3:39 pm)
Ok thanks :)
#7
Don't get me wrong...I'm not TorqueScript fanboy, I'd actually be *glad* if it went away and was either replaced by a C# script engine, or even if I had to add my own C# scripting engine (which is fairly trivial). Having written hundreds of thousands of C# code I would actually be *extremely pleased* if a C# script engine replaced TorqueScript for TorqueX as it would be a productivity plus.
However, based on the public information disseminated on the product page, I had been feeling this would never happen...until I happened across this tread.
So what gives...is TorqueScript definately 100% not in TorqueX? If so, then will you folks be providing a C# scripting engine (which as I said should be pretty trivial to build), or will you leave that up to the community?
Thanks,
Ryan
11/24/2006 (3:58 pm)
I'm confused by this thread. Robert states quite clearly that TXE doesn't use or have TorqueScript. This surprises me as GG has made it very clear that you should develop in TGB now...and port to TXE later (see marketing info on TXE product page). It has been said that TankBusters was "ported in a day or two" somewhere that I read. But, how is that possible with no support for TorqueScript?Don't get me wrong...I'm not TorqueScript fanboy, I'd actually be *glad* if it went away and was either replaced by a C# script engine, or even if I had to add my own C# scripting engine (which is fairly trivial). Having written hundreds of thousands of C# code I would actually be *extremely pleased* if a C# script engine replaced TorqueScript for TorqueX as it would be a productivity plus.
However, based on the public information disseminated on the product page, I had been feeling this would never happen...until I happened across this tread.
So what gives...is TorqueScript definately 100% not in TorqueX? If so, then will you folks be providing a C# scripting engine (which as I said should be pretty trivial to build), or will you leave that up to the community?
Thanks,
Ryan
#8
http://www.theultrageeks.com/spanish/?p=272
No TorqueScript for TorqueX.
This is actually good news to me... ;-)
- Ryan
11/24/2006 (5:09 pm)
Answered my own question here:http://www.theultrageeks.com/spanish/?p=272
No TorqueScript for TorqueX.
This is actually good news to me... ;-)
- Ryan
Torque 3D Owner Robert Blanchet Jr.