diff options
author | Adam Frisby | 2007-07-05 04:23:34 +0000 |
---|---|---|
committer | Adam Frisby | 2007-07-05 04:23:34 +0000 |
commit | ad86e94b3d69b0f9d525758a7e00dab86e11970f (patch) | |
tree | ff07add4891dffa1b455d7bc49676e11fe94a799 | |
parent | * Java engine fully back in Sugilite (diff) | |
download | opensim-SC-ad86e94b3d69b0f9d525758a7e00dab86e11970f.zip opensim-SC-ad86e94b3d69b0f9d525758a7e00dab86e11970f.tar.gz opensim-SC-ad86e94b3d69b0f9d525758a7e00dab86e11970f.tar.bz2 opensim-SC-ad86e94b3d69b0f9d525758a7e00dab86e11970f.tar.xz |
* Tweaks to Java engine (uses less threads). Added support for OnFrame and OnNewPresence events.
-rw-r--r-- | OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs | 148 |
1 files changed, 78 insertions, 70 deletions
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs index aaa1609..3e083cc 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs | |||
@@ -47,11 +47,6 @@ namespace OpenSim.Scripting.EmbeddedJVM | |||
47 | 47 | ||
48 | ScriptInfo scriptInfo; | 48 | ScriptInfo scriptInfo; |
49 | 49 | ||
50 | public JVMScript() | ||
51 | { | ||
52 | |||
53 | } | ||
54 | |||
55 | public void Initialise(ScriptInfo info) | 50 | public void Initialise(ScriptInfo info) |
56 | { | 51 | { |
57 | scriptInfo = info; | 52 | scriptInfo = info; |
@@ -59,81 +54,29 @@ namespace OpenSim.Scripting.EmbeddedJVM | |||
59 | _mainMemory = new MainMemory(); | 54 | _mainMemory = new MainMemory(); |
60 | Thread.GlobalMemory = this._mainMemory; | 55 | Thread.GlobalMemory = this._mainMemory; |
61 | Thread.World = info.world; | 56 | Thread.World = info.world; |
62 | compileThread = new System.Threading.Thread(new ThreadStart(CompileScript)); | 57 | CompileScript(); |
63 | compileThread.IsBackground = true; | ||
64 | compileThread.Start(); | ||
65 | 58 | ||
59 | scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame); | ||
60 | scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence); | ||
66 | } | 61 | } |
67 | 62 | ||
68 | public string getName() | 63 | void events_OnNewPresence(ScenePresence presence) |
69 | { | 64 | { |
70 | return "JVM Scripting Engine"; | 65 | for (int i = 0; i < this._threads.Count; i++) |
71 | } | ||
72 | |||
73 | public void LoadScript(string script) | ||
74 | { | ||
75 | Console.WriteLine("OpenSimJVM - loading new script: " + script); | ||
76 | CompileInfo comp = new CompileInfo(); | ||
77 | comp.script = script; | ||
78 | comp.scriptName = script; | ||
79 | this.CompileScripts.Enqueue(comp); | ||
80 | } | ||
81 | |||
82 | public void CompileScript() | ||
83 | { | ||
84 | while (true) | ||
85 | { | 66 | { |
86 | CompileInfo comp = this.CompileScripts.Dequeue(); | 67 | if (!this._threads[i].running) |
87 | string script = comp.script; | ||
88 | string scriptName = comp.scriptName; | ||
89 | try | ||
90 | { | ||
91 | //need to compile the script into a java class file | ||
92 | |||
93 | //first save it to a java source file | ||
94 | TextWriter tw = new StreamWriter(scriptName + ".java"); | ||
95 | tw.WriteLine(script); | ||
96 | tw.Close(); | ||
97 | |||
98 | //now compile | ||
99 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); | ||
100 | // psi.RedirectStandardOutput = true; | ||
101 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | ||
102 | psi.UseShellExecute = false; | ||
103 | |||
104 | System.Diagnostics.Process javacomp; | ||
105 | javacomp = System.Diagnostics.Process.Start(psi); | ||
106 | javacomp.WaitForExit(); | ||
107 | |||
108 | |||
109 | //now load in class file | ||
110 | ClassRecord class1 = new ClassRecord(); | ||
111 | class1.LoadClassFromFile(scriptName + ".class"); | ||
112 | class1.PrintToConsole(); | ||
113 | //Console.WriteLine(); | ||
114 | this._mainMemory.MethodArea.Classes.Add(class1); | ||
115 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); | ||
116 | |||
117 | Thread newThread = new Thread(); | ||
118 | this._threads.Add(newThread); | ||
119 | newThread.currentClass = class1; | ||
120 | newThread.scriptInfo = scriptInfo; | ||
121 | |||
122 | //now delete the created files | ||
123 | System.IO.File.Delete(scriptName + ".java"); | ||
124 | System.IO.File.Delete(scriptName + ".class"); | ||
125 | //this.OnFrame(); | ||
126 | } | ||
127 | catch (Exception e) | ||
128 | { | 68 | { |
129 | Console.WriteLine("exception"); | 69 | this._threads[i].StartMethod("OnNewPresence"); |
130 | Console.WriteLine(e.StackTrace); | 70 | bool run = true; |
131 | Console.WriteLine(e.Message); | 71 | while (run) |
72 | { | ||
73 | run = this._threads[i].Excute(); | ||
74 | } | ||
132 | } | 75 | } |
133 | } | 76 | } |
134 | } | 77 | } |
135 | 78 | ||
136 | public void OnFrame() | 79 | void events_OnFrame() |
137 | { | 80 | { |
138 | for (int i = 0; i < this._threads.Count; i++) | 81 | for (int i = 0; i < this._threads.Count; i++) |
139 | { | 82 | { |
@@ -149,6 +92,71 @@ namespace OpenSim.Scripting.EmbeddedJVM | |||
149 | } | 92 | } |
150 | } | 93 | } |
151 | 94 | ||
95 | public string getName() | ||
96 | { | ||
97 | return "JVM Scripting Engine"; | ||
98 | } | ||
99 | |||
100 | public void LoadScript(string script) | ||
101 | { | ||
102 | Console.WriteLine("OpenSimJVM - loading new script: " + script); | ||
103 | CompileInfo comp = new CompileInfo(); | ||
104 | comp.script = script; | ||
105 | comp.scriptName = script; | ||
106 | this.CompileScripts.Enqueue(comp); | ||
107 | } | ||
108 | |||
109 | public void CompileScript() | ||
110 | { | ||
111 | CompileInfo comp = this.CompileScripts.Dequeue(); | ||
112 | string script = comp.script; | ||
113 | string scriptName = comp.scriptName; | ||
114 | try | ||
115 | { | ||
116 | //need to compile the script into a java class file | ||
117 | |||
118 | //first save it to a java source file | ||
119 | TextWriter tw = new StreamWriter(scriptName + ".java"); | ||
120 | tw.WriteLine(script); | ||
121 | tw.Close(); | ||
122 | |||
123 | //now compile | ||
124 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); | ||
125 | // psi.RedirectStandardOutput = true; | ||
126 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | ||
127 | psi.UseShellExecute = false; | ||
128 | |||
129 | System.Diagnostics.Process javacomp; | ||
130 | javacomp = System.Diagnostics.Process.Start(psi); | ||
131 | javacomp.WaitForExit(); | ||
132 | |||
133 | |||
134 | //now load in class file | ||
135 | ClassRecord class1 = new ClassRecord(); | ||
136 | class1.LoadClassFromFile(scriptName + ".class"); | ||
137 | class1.PrintToConsole(); | ||
138 | //Console.WriteLine(); | ||
139 | this._mainMemory.MethodArea.Classes.Add(class1); | ||
140 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); | ||
141 | |||
142 | Thread newThread = new Thread(); | ||
143 | this._threads.Add(newThread); | ||
144 | newThread.currentClass = class1; | ||
145 | newThread.scriptInfo = scriptInfo; | ||
146 | |||
147 | //now delete the created files | ||
148 | System.IO.File.Delete(scriptName + ".java"); | ||
149 | System.IO.File.Delete(scriptName + ".class"); | ||
150 | //this.OnFrame(); | ||
151 | } | ||
152 | catch (Exception e) | ||
153 | { | ||
154 | Console.WriteLine("exception"); | ||
155 | Console.WriteLine(e.StackTrace); | ||
156 | Console.WriteLine(e.Message); | ||
157 | } | ||
158 | } | ||
159 | |||
152 | private class CompileInfo | 160 | private class CompileInfo |
153 | { | 161 | { |
154 | public string script; | 162 | public string script; |