RegionModule.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 OpenSim 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;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Text;
  31. using libsecondlife;
  32. using Nini.Config;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Environment.Interfaces;
  35. using OpenSim.Region.Environment.Scenes;
  36. namespace OpenSim.Region.Examples.SimpleModule
  37. {
  38. public class RegionModule : IRegionModule
  39. {
  40. #region IRegionModule Members
  41. private Scene m_scene;
  42. public void Initialise(Scene scene, IConfigSource source)
  43. {
  44. m_scene = scene;
  45. }
  46. public void PostInitialise()
  47. {
  48. RegionInfo regionInfo = m_scene.RegionInfo;
  49. LLVector3 pos = new LLVector3(110, 129, 27);
  50. AddCpuCounter(regionInfo, pos);
  51. // AddComplexObjects(regionInfo, pos);
  52. // AddAvatars();
  53. AddFileSystemObjects();
  54. }
  55. private void AddFileSystemObjects()
  56. {
  57. DirectoryInfo dirInfo = new DirectoryInfo(".");
  58. float x = 0;
  59. float z = 0;
  60. foreach (FileInfo fileInfo in dirInfo.GetFiles())
  61. {
  62. LLVector3 filePos = new LLVector3(100 + x, 129, 27 + z);
  63. x = x + 2;
  64. if (x > 50)
  65. {
  66. x = 0;
  67. z = z + 2;
  68. }
  69. FileSystemObject fileObject = new FileSystemObject(m_scene, fileInfo, filePos);
  70. m_scene.AddEntity(fileObject);
  71. fileObject.ScheduleGroupForFullUpdate();
  72. }
  73. }
  74. private void AddAvatars()
  75. {
  76. for (int i = 0; i < 2; i++)
  77. {
  78. MyNpcCharacter m_character = new MyNpcCharacter(m_scene.EventManager);
  79. m_scene.AddNewClient(m_character, false);
  80. }
  81. List<ScenePresence> avatars = m_scene.GetAvatars();
  82. foreach (ScenePresence avatar in avatars)
  83. {
  84. avatar.AbsolutePosition =
  85. new LLVector3((float)Util.RandomClass.Next(100, 200), (float)Util.RandomClass.Next(30, 200), 2);
  86. }
  87. }
  88. private void AddComplexObjects(RegionInfo regionInfo, LLVector3 pos)
  89. {
  90. int objs = 3;
  91. for (int i = 0; i < (objs*objs*objs); i++)
  92. {
  93. LLVector3 posOffset = new LLVector3((i % objs) * 4, ((i % (objs*objs)) / ( objs )) * 4, (i / (objs*objs)) * 4);
  94. ComplexObject complexObject =
  95. new ComplexObject(m_scene, regionInfo.RegionHandle, LLUUID.Zero, m_scene.PrimIDAllocate(),
  96. pos + posOffset);
  97. m_scene.AddEntity(complexObject);
  98. }
  99. }
  100. private void AddCpuCounter(RegionInfo regionInfo, LLVector3 pos)
  101. {
  102. SceneObjectGroup sceneObject =
  103. new CpuCounterObject(m_scene, regionInfo.RegionHandle, LLUUID.Zero, m_scene.PrimIDAllocate(),
  104. pos + new LLVector3(1f, 1f, 1f));
  105. m_scene.AddEntity(sceneObject);
  106. }
  107. public void Close()
  108. {
  109. m_scene = null;
  110. }
  111. public string Name
  112. {
  113. get { return GetType().AssemblyQualifiedName; }
  114. }
  115. public bool IsSharedModule
  116. {
  117. get { return false; }
  118. }
  119. #endregion
  120. }
  121. }