diff options
author | MW | 2007-04-11 13:32:50 +0000 |
---|---|---|
committer | MW | 2007-04-11 13:32:50 +0000 |
commit | 00b7058e000d7871df2ae40075ead1042e8e81ac (patch) | |
tree | 2a7e4d5c51b4567b97a7fc06c1c970e6a4ac9d44 /OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs | |
parent | small improvement to the jvm and test script (diff) | |
download | opensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.zip opensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.gz opensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.bz2 opensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.xz |
Attempt to rearrange some of the directories
Diffstat (limited to 'OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs')
-rw-r--r-- | OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs b/OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs new file mode 100644 index 0000000..dc3402e --- /dev/null +++ b/OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs | |||
@@ -0,0 +1,140 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
5 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
6 | using OpenSim.Framework.Interfaces; | ||
7 | using OpenSim.Framework; | ||
8 | |||
9 | namespace 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 | // Console.WriteLine("returned x value " + vec3.X.ToString()); | ||
80 | this._mThread.currentFrame.OpStack.Push(pos); | ||
81 | } | ||
82 | this._mThread.PC += 2; | ||
83 | break; | ||
84 | case "GetEntityPositionY": | ||
85 | bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
86 | if (bs1 is Int) | ||
87 | { | ||
88 | //should get the position of the entity from the IScriptAPI | ||
89 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
90 | Float pos = new Float(); | ||
91 | pos.mValue = vec3.Y; | ||
92 | this._mThread.currentFrame.OpStack.Push(pos); | ||
93 | } | ||
94 | this._mThread.PC += 2; | ||
95 | break; | ||
96 | case "GetEntityPositionZ": | ||
97 | bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
98 | if (bs1 is Int) | ||
99 | { | ||
100 | //should get the position of the entity from the IScriptAPI | ||
101 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
102 | Float pos = new Float(); | ||
103 | pos.mValue = vec3.Z; | ||
104 | this._mThread.currentFrame.OpStack.Push(pos); | ||
105 | } | ||
106 | this._mThread.PC += 2; | ||
107 | break; | ||
108 | case "SetEntityPosition": | ||
109 | //pop the three float values and the entity id | ||
110 | BaseType ft3 = this._mThread.currentFrame.OpStack.Pop(); | ||
111 | BaseType ft2 = this._mThread.currentFrame.OpStack.Pop(); | ||
112 | BaseType ft1 = this._mThread.currentFrame.OpStack.Pop(); | ||
113 | BaseType in1 = this._mThread.currentFrame.OpStack.Pop(); | ||
114 | if (ft1 is Float && ft2 is Float && ft3 is Float) | ||
115 | { | ||
116 | if(in1 is Int) | ||
117 | { | ||
118 | //Console.WriteLine("set: " + ((Int)in1).mValue + " , " + ((Float)ft1).mValue + " , " + ((Float)ft2).mValue + " , " + ((Float)ft3).mValue); | ||
119 | Thread.OpenSimScriptAPI.SetEntityPosition((uint)((Int) in1).mValue, ((Float)ft1).mValue, ((Float)ft2).mValue, ((Float)ft3).mValue); | ||
120 | } | ||
121 | } | ||
122 | this._mThread.PC += 2; | ||
123 | break; | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | this._mThread.PC += 2; | ||
131 | } | ||
132 | result = true; | ||
133 | break; | ||
134 | } | ||
135 | |||
136 | return result; | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | } | ||