* Tweaks to Java engine (uses less threads). Added support for OnFrame and OnNewPresence events.

Sugilite
Adam Frisby 2007-07-05 04:23:34 +00:00
parent c570b107f8
commit ad86e94b3d
1 changed files with 72 additions and 64 deletions

View File

@ -47,11 +47,6 @@ namespace OpenSim.Scripting.EmbeddedJVM
ScriptInfo scriptInfo; ScriptInfo scriptInfo;
public JVMScript()
{
}
public void Initialise(ScriptInfo info) public void Initialise(ScriptInfo info)
{ {
scriptInfo = info; scriptInfo = info;
@ -59,10 +54,42 @@ namespace OpenSim.Scripting.EmbeddedJVM
_mainMemory = new MainMemory(); _mainMemory = new MainMemory();
Thread.GlobalMemory = this._mainMemory; Thread.GlobalMemory = this._mainMemory;
Thread.World = info.world; Thread.World = info.world;
compileThread = new System.Threading.Thread(new ThreadStart(CompileScript)); CompileScript();
compileThread.IsBackground = true;
compileThread.Start();
scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
}
void events_OnNewPresence(ScenePresence presence)
{
for (int i = 0; i < this._threads.Count; i++)
{
if (!this._threads[i].running)
{
this._threads[i].StartMethod("OnNewPresence");
bool run = true;
while (run)
{
run = this._threads[i].Excute();
}
}
}
}
void events_OnFrame()
{
for (int i = 0; i < this._threads.Count; i++)
{
if (!this._threads[i].running)
{
this._threads[i].StartMethod("OnFrame");
bool run = true;
while (run)
{
run = this._threads[i].Excute();
}
}
}
} }
public string getName() public string getName()
@ -81,71 +108,52 @@ namespace OpenSim.Scripting.EmbeddedJVM
public void CompileScript() public void CompileScript()
{ {
while (true) CompileInfo comp = this.CompileScripts.Dequeue();
string script = comp.script;
string scriptName = comp.scriptName;
try
{ {
CompileInfo comp = this.CompileScripts.Dequeue(); //need to compile the script into a java class file
string script = comp.script;
string scriptName = comp.scriptName;
try
{
//need to compile the script into a java class file
//first save it to a java source file //first save it to a java source file
TextWriter tw = new StreamWriter(scriptName + ".java"); TextWriter tw = new StreamWriter(scriptName + ".java");
tw.WriteLine(script); tw.WriteLine(script);
tw.Close(); tw.Close();
//now compile //now compile
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java");
// psi.RedirectStandardOutput = true; // psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false; psi.UseShellExecute = false;
System.Diagnostics.Process javacomp; System.Diagnostics.Process javacomp;
javacomp = System.Diagnostics.Process.Start(psi); javacomp = System.Diagnostics.Process.Start(psi);
javacomp.WaitForExit(); javacomp.WaitForExit();
//now load in class file
ClassRecord class1 = new ClassRecord();
class1.LoadClassFromFile(scriptName + ".class");
class1.PrintToConsole();
//Console.WriteLine();
this._mainMemory.MethodArea.Classes.Add(class1);
class1.AddMethodsToMemory(this._mainMemory.MethodArea);
Thread newThread = new Thread(); //now load in class file
this._threads.Add(newThread); ClassRecord class1 = new ClassRecord();
newThread.currentClass = class1; class1.LoadClassFromFile(scriptName + ".class");
newThread.scriptInfo = scriptInfo; class1.PrintToConsole();
//Console.WriteLine();
this._mainMemory.MethodArea.Classes.Add(class1);
class1.AddMethodsToMemory(this._mainMemory.MethodArea);
//now delete the created files Thread newThread = new Thread();
System.IO.File.Delete(scriptName + ".java"); this._threads.Add(newThread);
System.IO.File.Delete(scriptName + ".class"); newThread.currentClass = class1;
//this.OnFrame(); newThread.scriptInfo = scriptInfo;
}
catch (Exception e) //now delete the created files
{ System.IO.File.Delete(scriptName + ".java");
Console.WriteLine("exception"); System.IO.File.Delete(scriptName + ".class");
Console.WriteLine(e.StackTrace); //this.OnFrame();
Console.WriteLine(e.Message);
}
} }
} catch (Exception e)
public void OnFrame()
{
for (int i = 0; i < this._threads.Count; i++)
{ {
if (!this._threads[i].running) Console.WriteLine("exception");
{ Console.WriteLine(e.StackTrace);
this._threads[i].StartMethod("OnFrame"); Console.WriteLine(e.Message);
bool run = true;
while (run)
{
run = this._threads[i].Excute();
}
}
} }
} }