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.0.1-prestable
parent
ffd7a6b8c2
commit
5ad6d5a939
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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("<ScriptEngine:"))
|
||||
{
|
||||
string substring1 = "";
|
||||
string script = "";
|
||||
Console.WriteLine("searching for script engine");
|
||||
// Console.WriteLine("searching for script engine");
|
||||
substring1 = substring.Remove(0, 14);
|
||||
int dev = substring1.IndexOf(',');
|
||||
string sEngine = substring1.Substring(0, dev);
|
||||
substring1 = substring1.Remove(0, dev+1);
|
||||
int end = substring1.IndexOf('>');
|
||||
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++;
|
||||
|
|
|
@ -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<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
|
||||
|
||||
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
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
48
OpenSim.sln
48
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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue