Entity.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Axiom.MathLib;
  5. using OpenSim.Physics.Manager;
  6. using OpenSim.types;
  7. using libsecondlife;
  8. using OpenSim.RegionServer.world.scripting;
  9. namespace OpenSim.world
  10. {
  11. public abstract class Entity : IScriptReadonlyEntity
  12. {
  13. public libsecondlife.LLUUID uuid;
  14. public uint localid;
  15. public LLVector3 velocity;
  16. public Quaternion rotation;
  17. protected List<Entity> children;
  18. protected LLVector3 m_pos;
  19. protected PhysicsActor _physActor;
  20. protected World m_world;
  21. protected string m_name;
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. public virtual string Name
  26. {
  27. get { return m_name; }
  28. }
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. public virtual LLVector3 Pos
  33. {
  34. get
  35. {
  36. if (this._physActor != null)
  37. {
  38. m_pos.X = _physActor.Position.X;
  39. m_pos.Y = _physActor.Position.Y;
  40. m_pos.Z = _physActor.Position.Z;
  41. }
  42. return m_pos;
  43. }
  44. set
  45. {
  46. if (this._physActor != null)
  47. {
  48. try
  49. {
  50. lock (this.m_world.LockPhysicsEngine)
  51. {
  52. this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
  53. }
  54. }
  55. catch (Exception e)
  56. {
  57. Console.WriteLine(e.Message);
  58. }
  59. }
  60. m_pos = value;
  61. }
  62. }
  63. /// <summary>
  64. /// Creates a new Entity (should not occur on it's own)
  65. /// </summary>
  66. public Entity()
  67. {
  68. uuid = new libsecondlife.LLUUID();
  69. localid = 0;
  70. m_pos = new LLVector3();
  71. velocity = new LLVector3();
  72. rotation = new Quaternion();
  73. m_name = "(basic entity)";
  74. children = new List<Entity>();
  75. }
  76. /// <summary>
  77. ///
  78. /// </summary>
  79. public virtual void addForces()
  80. {
  81. foreach (Entity child in children)
  82. {
  83. child.addForces();
  84. }
  85. }
  86. /// <summary>
  87. /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
  88. /// </summary>
  89. public virtual void update() {
  90. // Do any per-frame updates needed that are applicable to every type of entity
  91. foreach (Entity child in children)
  92. {
  93. child.update();
  94. }
  95. }
  96. /// <summary>
  97. /// Returns a mesh for this object and any dependents
  98. /// </summary>
  99. /// <returns>The mesh of this entity tree</returns>
  100. public virtual Mesh getMesh()
  101. {
  102. Mesh mesh = new Mesh();
  103. foreach (Entity child in children)
  104. {
  105. mesh += child.getMesh();
  106. }
  107. return mesh;
  108. }
  109. /// <summary>
  110. /// Called at a set interval to inform entities that they should back themsleves up to the DB
  111. /// </summary>
  112. public virtual void BackUp()
  113. {
  114. }
  115. /// <summary>
  116. /// Infoms the entity that the land (heightmap) has changed
  117. /// </summary>
  118. public virtual void LandRenegerated()
  119. {
  120. }
  121. }
  122. }