InterpreterMethods.cs 9.0 KB

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