1
0

RegionModule.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections.Generic;
  28. using Nini.Config;
  29. using OpenMetaverse;
  30. using OpenSim.Framework;
  31. using OpenSim.Region.Framework.Interfaces;
  32. using OpenSim.Region.Framework.Scenes;
  33. namespace OpenSim.Region.Examples.SimpleModule
  34. {
  35. /// <summary>
  36. /// Example region module.
  37. /// </summary>
  38. /// <remarks>
  39. /// This is an old and unmaintained region module which uses the old style module interface. It is not loaded into
  40. /// OpenSim by default. If you want to try enabling it, look in the bin folder of this project.
  41. /// Please see the README.txt in this project on the filesystem for some more information.
  42. /// Nonetheless, it may contain some useful example code so has been left here for now.
  43. ///
  44. /// You can see bare bones examples of the more modern region module system in OpenSim/Region/OptionalModules/Example
  45. /// </remarks>
  46. public class RegionModule : IRegionModule
  47. {
  48. #region IRegionModule Members
  49. private Scene m_scene;
  50. public void Initialise(Scene scene, IConfigSource source)
  51. {
  52. m_scene = scene;
  53. }
  54. public void PostInitialise()
  55. {
  56. // RegionInfo regionInfo = m_scene.RegionInfo;
  57. // Vector3 pos = new Vector3(110, 129, 27);
  58. //AddCpuCounter(regionInfo, pos);
  59. // AddComplexObjects(regionInfo, pos);
  60. AddAvatars();
  61. // AddFileSystemObjects();
  62. }
  63. // private void AddFileSystemObjects()
  64. // {
  65. // DirectoryInfo dirInfo = new DirectoryInfo(".");
  66. // float x = 0;
  67. // float z = 0;
  68. // foreach (FileInfo fileInfo in dirInfo.GetFiles())
  69. // {
  70. // Vector3 filePos = new Vector3(100 + x, 129, 27 + z);
  71. // x = x + 2;
  72. // if (x > 50)
  73. // {
  74. // x = 0;
  75. // z = z + 2;
  76. // }
  77. // FileSystemObject fileObject = new FileSystemObject(m_scene, fileInfo, filePos);
  78. // m_scene.AddNewSceneObject(fileObject, true);
  79. // }
  80. // }
  81. private void AddAvatars()
  82. {
  83. for (int i = 0; i < 1; i++)
  84. {
  85. MyNpcCharacter m_character = new MyNpcCharacter(m_scene);
  86. m_scene.AddNewClient(m_character, PresenceType.Npc);
  87. m_scene.AgentCrossing(m_character.AgentId, Vector3.Zero, false);
  88. }
  89. m_scene.ForEachScenePresence(delegate(ScenePresence sp)
  90. {
  91. if (!sp.IsChildAgent)
  92. sp.AbsolutePosition =
  93. new Vector3((float)Util.RandomClass.Next(100, 200), (float)Util.RandomClass.Next(30, 200), 2);
  94. });
  95. }
  96. // private void AddComplexObjects(RegionInfo regionInfo, Vector3 pos)
  97. // {
  98. // int objs = 3;
  99. // for (int i = 0; i < (objs*objs*objs); i++)
  100. // {
  101. // Vector3 posOffset = new Vector3((i % objs) * 4, ((i % (objs*objs)) / (objs)) * 4, (i / (objs*objs)) * 4);
  102. // ComplexObject complexObject =
  103. // new ComplexObject(m_scene, regionInfo.RegionHandle, UUID.Zero, pos + posOffset);
  104. // m_scene.AddNewSceneObject(complexObject, true);
  105. // }
  106. // }
  107. // private void AddCpuCounter(RegionInfo regionInfo, Vector3 pos)
  108. // {
  109. // SceneObjectGroup sceneObject =
  110. // new CpuCounterObject(m_scene, regionInfo.RegionHandle, UUID.Zero, pos + new Vector3(1f, 1f, 1f));
  111. // m_scene.AddNewSceneObject(sceneObject, true);
  112. // }
  113. public void Close()
  114. {
  115. m_scene = null;
  116. }
  117. public string Name
  118. {
  119. get { return GetType().AssemblyQualifiedName; }
  120. }
  121. public bool IsSharedModule
  122. {
  123. get { return false; }
  124. }
  125. #endregion
  126. }
  127. }