aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs139
1 files changed, 139 insertions, 0 deletions
diff --git a/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs b/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs
new file mode 100644
index 0000000..e025293
--- /dev/null
+++ b/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs
@@ -0,0 +1,139 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.Scripting.EmbeddedJVM.Types;
5using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
6using OpenSim.Framework.Interfaces;
7using OpenSim.Framework;
8
9namespace OpenSim.Scripting.EmbeddedJVM
10{
11 partial class Thread
12 {
13 private partial class Interpreter
14 {
15 private bool IsMethodOpCode(byte opcode)
16 {
17 bool result = false;
18 switch (opcode)
19 {
20 case 184:
21 short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
22 //Console.WriteLine("call to method : "+refIndex);
23 if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef)
24 {
25 // Console.WriteLine("which is " + ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value + "." + ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value);
26 // Console.WriteLine("of type " + ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value);
27 string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value;
28 string typeparam = "";
29 string typereturn = "";
30 int firstbrak = 0;
31 int secondbrak = 0;
32 firstbrak = typ.LastIndexOf('(');
33 secondbrak = typ.LastIndexOf(')');
34 typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1);
35 typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1);
36 //Console.WriteLine("split is " + typeparam + " which is length " + typeparam.Length + " , " + typereturn);
37 if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value)
38 {
39 //calling a method in this class
40 if (typeparam.Length == 0)
41 {
42 this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2));
43 }
44 else
45 {
46 this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2));
47 }
48 }
49 else
50 {
51 //calling a method of a different class
52
53 //for now we will have a built in OpenSimAPI class, but this should be a java class that then calls native methods
54 if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI")
55 {
56 switch (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value)
57 {
58 case "GetEntityID":
59 Int entityID = new Int();
60 entityID.mValue =(int) this._mThread.EntityId;
61 this._mThread.currentFrame.OpStack.Push(entityID);
62 this._mThread.PC += 2;
63 break;
64 case "GetRandomAvatarID":
65 entityID = new Int();
66 entityID.mValue = (int)Thread.OpenSimScriptAPI.GetRandomAvatarID();
67 this._mThread.currentFrame.OpStack.Push(entityID);
68 this._mThread.PC += 2;
69 break;
70 case "GetEntityPositionX":
71 BaseType bs1 = this._mThread.currentFrame.OpStack.Pop();
72 if (bs1 is Int)
73 {
74 Console.WriteLine("get entity pos for " + ((Int)bs1).mValue);
75 //should get the position of the entity from the IScriptAPI
76 OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue);
77 Float pos = new Float();
78 pos.mValue = vec3.X;
79 this._mThread.currentFrame.OpStack.Push(pos);
80 }
81 this._mThread.PC += 2;
82 break;
83 case "GetEntityPositionY":
84 bs1 = this._mThread.currentFrame.OpStack.Pop();
85 if (bs1 is Int)
86 {
87 //should get the position of the entity from the IScriptAPI
88 OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue);
89 Float pos = new Float();
90 pos.mValue = vec3.Y;
91 this._mThread.currentFrame.OpStack.Push(pos);
92 }
93 this._mThread.PC += 2;
94 break;
95 case "GetEntityPositionZ":
96 bs1 = this._mThread.currentFrame.OpStack.Pop();
97 if (bs1 is Int)
98 {
99 //should get the position of the entity from the IScriptAPI
100 OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue);
101 Float pos = new Float();
102 pos.mValue = vec3.Z;
103 this._mThread.currentFrame.OpStack.Push(pos);
104 }
105 this._mThread.PC += 2;
106 break;
107 case "SetEntityPosition":
108 //pop the three float values and the entity id
109 BaseType ft3 = this._mThread.currentFrame.OpStack.Pop();
110 BaseType ft2 = this._mThread.currentFrame.OpStack.Pop();
111 BaseType ft1 = this._mThread.currentFrame.OpStack.Pop();
112 BaseType in1 = this._mThread.currentFrame.OpStack.Pop();
113 if (ft1 is Float && ft2 is Float && ft3 is Float)
114 {
115 if(in1 is Int)
116 {
117 //Console.WriteLine("set: " + ((Int)in1).mValue + " , " + ((Float)ft1).mValue + " , " + ((Float)ft2).mValue + " , " + ((Float)ft3).mValue);
118 Thread.OpenSimScriptAPI.SetEntityPosition((uint)((Int) in1).mValue, ((Float)ft1).mValue, ((Float)ft2).mValue, ((Float)ft3).mValue);
119 }
120 }
121 this._mThread.PC += 2;
122 break;
123 }
124 }
125 }
126 }
127 else
128 {
129 this._mThread.PC += 2;
130 }
131 result = true;
132 break;
133 }
134
135 return result;
136 }
137 }
138 }
139}