From 5ad6d5a939fb7bf0fdfdc6925d4afed306e08641 Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 11 Apr 2007 12:13:21 +0000 Subject: First basic test script now works in the jvm scripting engine. For it to work you need to have a java sdk installed and the javac.exe somewhere in the environment Path variable. Then To test, copy the text from bin/script1.text into a note card and then add that note to a prim. --- OpenSim.Framework/IScriptAPI.cs | 13 +++ OpenSim.Framework/IScriptEngine.cs | 14 +++ OpenSim.Framework/OSVector3.cs | 18 +++ OpenSim.RegionServer/world/World.cs | 10 +- OpenSim.RegionServer/world/WorldScripting.cs | 122 +++++++++++++++++++++ OpenSim.Scripting.EmbeddedJVM/Interpreter.cs | 3 + OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs | 4 +- .../InterpreterMethods.cs | 3 +- OpenSim.Scripting.EmbeddedJVM/OpenSimJVM.cs | 7 +- OpenSim.sln | 48 -------- bin/OpenSimAPI.java | 36 ++++++ 11 files changed, 219 insertions(+), 59 deletions(-) create mode 100644 OpenSim.Framework/IScriptAPI.cs create mode 100644 OpenSim.Framework/IScriptEngine.cs create mode 100644 OpenSim.Framework/OSVector3.cs create mode 100644 OpenSim.RegionServer/world/WorldScripting.cs create mode 100644 bin/OpenSimAPI.java diff --git a/OpenSim.Framework/IScriptAPI.cs b/OpenSim.Framework/IScriptAPI.cs new file mode 100644 index 0000000..2f58198 --- /dev/null +++ b/OpenSim.Framework/IScriptAPI.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Framework.Interfaces +{ + public interface IScriptAPI + { + OSVector3 GetEntityPosition(uint localID); + void SetEntityPosition(uint localID, float x, float y, float z); + uint GetRandomAvatarID(); + } +} diff --git a/OpenSim.Framework/IScriptEngine.cs b/OpenSim.Framework/IScriptEngine.cs new file mode 100644 index 0000000..ed8974c --- /dev/null +++ b/OpenSim.Framework/IScriptEngine.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Framework.Interfaces +{ + public interface IScriptEngine + { + bool Init(IScriptAPI api); + string GetName(); + void LoadScript(string script, string scriptName, uint entityID); + void OnFrame(); + } +} diff --git a/OpenSim.Framework/OSVector3.cs b/OpenSim.Framework/OSVector3.cs new file mode 100644 index 0000000..b5d1223 --- /dev/null +++ b/OpenSim.Framework/OSVector3.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Framework +{ + public class OSVector3 + { + public float X; + public float Y; + public float Z; + + public OSVector3() + { + + } + } +} diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index 74325b0..a973c6c 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs @@ -87,22 +87,22 @@ namespace OpenSim.world //Console.WriteLine("searching for script to add: " + substring); ScriptFactory scriptFactory; - Console.WriteLine("script string is " + substring); + //Console.WriteLine("script string is " + substring); if(substring.StartsWith("'); string sName = substring1.Substring(0, end); - Console.WriteLine(" script info : " + sEngine + " , " + sName); + //Console.WriteLine(" script info : " + sEngine + " , " + sName); int startscript = substring.IndexOf('>'); script = substring.Remove(0, startscript + 1); - Console.WriteLine("script data is " + script); + // Console.WriteLine("script data is " + script); if (this.scriptEngines.ContainsKey(sEngine)) { this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid); @@ -172,7 +172,7 @@ namespace OpenSim.world } foreach (IScriptEngine scripteng in this.scriptEngines.Values) { - //scripteng.OnFrame(); + scripteng.OnFrame(); } //backup world data this.storageCount++; diff --git a/OpenSim.RegionServer/world/WorldScripting.cs b/OpenSim.RegionServer/world/WorldScripting.cs new file mode 100644 index 0000000..83838b4 --- /dev/null +++ b/OpenSim.RegionServer/world/WorldScripting.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Framework.Interfaces; +using libsecondlife; + +namespace OpenSim.world +{ + public partial class World + { + private Dictionary scriptEngines = new Dictionary(); + + private void LoadScriptEngines() + { + this.LoadScriptPlugins(); + } + + public void LoadScriptPlugins() + { + string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines"); + string[] pluginFiles = Directory.GetFiles(path, "*.dll"); + + + for (int i = 0; i < pluginFiles.Length; i++) + { + this.AddPlugin(pluginFiles[i]); + } + } + + private void AddPlugin(string FileName) + { + Assembly pluginAssembly = Assembly.LoadFrom(FileName); + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("IScriptEngine", true); + + if (typeInterface != null) + { + IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + plug.Init(this); + this.scriptEngines.Add(plug.GetName(), plug); + + } + + typeInterface = null; + } + } + } + + pluginAssembly = null; + } + + public void LoadScript(string scriptType, string scriptName, string script, Entity ent) + { + if(this.scriptEngines.ContainsKey(scriptType)) + { + this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid); + } + } + + #region IScriptAPI Methods + + public OSVector3 GetEntityPosition(uint localID) + { + OSVector3 res = new OSVector3(); + // Console.WriteLine("script- getting entity " + localID + " position"); + foreach (Entity entity in this.Entities.Values) + { + if (entity.localid == localID) + { + res.X = entity.Pos.X; + res.Y = entity.Pos.Y; + res.Z = entity.Pos.Z; + } + } + return res; + } + + public void SetEntityPosition(uint localID, float x , float y, float z) + { + foreach (Entity entity in this.Entities.Values) + { + if (entity.localid == localID && entity is Primitive) + { + LLVector3 pos = entity.Pos; + pos.X = x; + Primitive prim = entity as Primitive; + // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. + prim.UpdatePosition(pos); + // Console.WriteLine("script- setting entity " + localID + " positon"); + } + } + + } + + public uint GetRandomAvatarID() + { + //Console.WriteLine("script- getting random avatar id"); + uint res = 0; + foreach (Entity entity in this.Entities.Values) + { + if (entity is Avatar) + { + res = entity.localid; + } + } + return res; + } + + #endregion + + + } +} diff --git a/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs b/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs index aeeee0a..b94248c 100644 --- a/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs +++ b/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs @@ -49,6 +49,7 @@ namespace OpenSim.Scripting.EmbeddedJVM else { // Console.WriteLine("No parent function so ending program"); + this._mThread.stack.StackFrames.Pop(); run = false; } handled = true; @@ -71,6 +72,7 @@ namespace OpenSim.Scripting.EmbeddedJVM else { // Console.WriteLine("No parent function so ending program"); + this._mThread.stack.StackFrames.Pop(); run = false; } handled = true; @@ -88,6 +90,7 @@ namespace OpenSim.Scripting.EmbeddedJVM else { // Console.WriteLine("No parent function so ending program"); + this._mThread.stack.StackFrames.Pop(); run = false; } handled = true; diff --git a/OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs b/OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs index 673970a..8c895af 100644 --- a/OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs +++ b/OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs @@ -274,11 +274,11 @@ namespace OpenSim.Scripting.EmbeddedJVM if (flcom1 is Float && flcom2 is Float) { Int compres = new Int(); - if (((Float)flcom1).mValue > ((Float)flcom2).mValue) + if (((Float)flcom1).mValue < ((Float)flcom2).mValue) { compres.mValue = -1; } - else if (((Float)flcom1).mValue < ((Float)flcom2).mValue) + else if (((Float)flcom1).mValue > ((Float)flcom2).mValue) { compres.mValue = 1; } diff --git a/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs b/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs index e025293..dc3402e 100644 --- a/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs +++ b/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs @@ -71,11 +71,12 @@ namespace OpenSim.Scripting.EmbeddedJVM BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); if (bs1 is Int) { - Console.WriteLine("get entity pos for " + ((Int)bs1).mValue); + //Console.WriteLine("get entity pos for " + ((Int)bs1).mValue); //should get the position of the entity from the IScriptAPI OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); Float pos = new Float(); pos.mValue = vec3.X; + // Console.WriteLine("returned x value " + vec3.X.ToString()); this._mThread.currentFrame.OpStack.Push(pos); } this._mThread.PC += 2; diff --git a/OpenSim.Scripting.EmbeddedJVM/OpenSimJVM.cs b/OpenSim.Scripting.EmbeddedJVM/OpenSimJVM.cs index 77a92e5..b47bb50 100644 --- a/OpenSim.Scripting.EmbeddedJVM/OpenSimJVM.cs +++ b/OpenSim.Scripting.EmbeddedJVM/OpenSimJVM.cs @@ -66,10 +66,11 @@ namespace OpenSim.Scripting.EmbeddedJVM tw.Close(); //now compile - System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\Program Files\Java\jdk1.6.0_01\bin\javac.exe", "*.java"); - psi.RedirectStandardOutput = true; + System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); + // psi.RedirectStandardOutput = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; psi.UseShellExecute = false; + System.Diagnostics.Process javacomp; javacomp = System.Diagnostics.Process.Start(psi); javacomp.WaitForExit(); @@ -91,7 +92,7 @@ namespace OpenSim.Scripting.EmbeddedJVM //now delete the created files System.IO.File.Delete(scriptName + ".java"); System.IO.File.Delete(scriptName + ".class"); - this.OnFrame(); + //this.OnFrame(); } catch (Exception e) { diff --git a/OpenSim.sln b/OpenSim.sln index 2fac201..555bd96 100644 --- a/OpenSim.sln +++ b/OpenSim.sln @@ -1,21 +1,5 @@ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual C# Express 2005 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Terrain.BasicTerrain", "OpenSim.Terrain.BasicTerrain\OpenSim.Terrain.BasicTerrain.csproj", "{2270B8FE-0000-0000-0000-000000000000}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.RegionServer", "OpenSim.RegionServer\OpenSim.RegionServer.csproj", "{632E1BFD-0000-0000-0000-000000000000}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Physics.OdePlugin", "OpenSim.Physics\OdePlugin\OpenSim.Physics.OdePlugin.csproj", "{63A05FE9-0000-0000-0000-000000000000}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Framework.Console", "OpenSim.Framework.Console\OpenSim.Framework.Console.csproj", "{A7CD0630-0000-0000-0000-000000000000}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Storage.LocalStorageBerkeleyDB", "OpenSim.Storage.LocalStorageBerkeleyDB\OpenSim.Storage.LocalStorageBerkeleyDB.csproj", "{EE9E5D96-0000-0000-0000-000000000000}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim", "OpenSim\OpenSim.csproj", "{438A9556-0000-0000-0000-000000000000}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.GenericConfig.Xml", "OpenSim.GenericConfig\Xml\OpenSim.GenericConfig.Xml.csproj", "{E88EF749-0000-0000-0000-000000000000}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Physics.Manager", "OpenSim.Physics\Manager\OpenSim.Physics.Manager.csproj", "{8BE16150-0000-0000-0000-000000000000}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Scripting.EmbeddedJVM", "OpenSim.Scripting.EmbeddedJVM\OpenSim.Scripting.EmbeddedJVM.csproj", "{97A82740-0000-0000-0000-000000000000}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenGridServices.UserServer", "OpenGridServices.UserServer\OpenGridServices.UserServer.csproj", "{66591469-0000-0000-0000-000000000000}" @@ -48,38 +32,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2270B8FE-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2270B8FE-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2270B8FE-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2270B8FE-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {632E1BFD-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {632E1BFD-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {632E1BFD-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {632E1BFD-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {63A05FE9-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {63A05FE9-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {63A05FE9-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {63A05FE9-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {A7CD0630-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A7CD0630-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A7CD0630-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A7CD0630-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {EE9E5D96-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EE9E5D96-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EE9E5D96-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EE9E5D96-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {438A9556-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {438A9556-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {438A9556-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {438A9556-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {E88EF749-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E88EF749-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E88EF749-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E88EF749-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {8BE16150-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8BE16150-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8BE16150-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8BE16150-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU {97A82740-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {97A82740-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU {97A82740-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/bin/OpenSimAPI.java b/bin/OpenSimAPI.java new file mode 100644 index 0000000..472b947 --- /dev/null +++ b/bin/OpenSimAPI.java @@ -0,0 +1,36 @@ + + +public class OpenSimAPI { + + public static int GetEntityID() + { + return 0; + } + + public static int GetRandomAvatarID() + { + return 0; + } + + public static float GetEntityPositionX(int id) + { + return 0.0f; + } + + public static float GetEntityPositionY(int id) + { + return 0.0f; + } + + public static float GetEntityPositionZ(int id) + { + return 0.0f; + } + + public static void SetEntityPosition(int id, float x, float y, float z) + { + + } + + +} \ No newline at end of file -- cgit v1.1