llworld.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**
  2. * @file llworld.h
  3. * @brief Collection of viewer regions in the vacinity of the user.
  4. *
  5. * Represents the whole world, so far as 3D functionality is conserned.
  6. * Always contains the region that the user's avatar is in along with
  7. * neighboring regions. As the user crosses region boundaries, new
  8. * regions are added to the world and distant ones are rolled up.
  9. *
  10. * $LicenseInfo:firstyear=2001&license=viewergpl$
  11. *
  12. * Copyright (c) 2001-2009, Linden Research, Inc.
  13. *
  14. * Second Life Viewer Source Code
  15. * The source code in this file ("Source Code") is provided by Linden Lab
  16. * to you under the terms of the GNU General Public License, version 2.0
  17. * ("GPL"), unless you have obtained a separate licensing agreement
  18. * ("Other License"), formally executed by you and Linden Lab. Terms of
  19. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  20. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  21. *
  22. * There are special exceptions to the terms and conditions of the GPL as
  23. * it is applied to this Source Code. View the full text of the exception
  24. * in the file doc/FLOSS-exception.txt in this software distribution, or
  25. * online at
  26. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  27. *
  28. * By copying, modifying or distributing this software, you acknowledge
  29. * that you have read and understood your obligations described above,
  30. * and agree to abide by those obligations.
  31. *
  32. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  33. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  34. * COMPLETENESS OR PERFORMANCE.
  35. * $/LicenseInfo$
  36. */
  37. #ifndef LL_LLWORLD_H
  38. #define LL_LLWORLD_H
  39. #include "boost/function.hpp"
  40. #include "boost/signals2.hpp"
  41. #include "llmath.h"
  42. #include "llstring.h"
  43. #include "llvector3.h"
  44. #include "llpatchvertexarray.h"
  45. #include "llviewerpartsim.h"
  46. #include "llviewertexture.h"
  47. #include "llvowater.h"
  48. class LLCamera;
  49. class LLCloudPuff;
  50. class LLCloudGroup;
  51. class LLColor4;
  52. class LLCullResult;
  53. class LLHost;
  54. class LLMessageSystem;
  55. class LLSurfacePatch;
  56. class LLVector3d;
  57. class LLViewerObject;
  58. class LLViewerRegion;
  59. class LLVOAvatar;
  60. // Avoids a static constant. HB
  61. #define EDGE_WATER_OBJECTS_COUNT 8
  62. // LLWorld maintains a stack of unused viewer_regions and an array of pointers
  63. // to viewer regions as simulators are connected to, viewer_regions are popped
  64. // off the stack and connected as required as simulators are removed, they are
  65. // pushed back onto the stack
  66. class LLWorld
  67. {
  68. protected:
  69. LOG_CLASS(LLWorld);
  70. public:
  71. LLWorld();
  72. void initClass(); // Called from LLStartUp::idleStartup()
  73. void cleanupClass(); // Called from LLAppViewer::disconnectViewer()
  74. // Safe to call if already present, does the "right thing" if hosts are
  75. // same, or if hosts are different, etc...
  76. LLViewerRegion* addRegion(const U64& region_handle, const LLHost& host,
  77. // Variable region size support
  78. U32 width);
  79. void removeRegion(const LLHost& host);
  80. // Send quit messages to all child regions
  81. void disconnectRegions();
  82. LLViewerRegion* getRegion(const LLHost& host);
  83. LLViewerRegion* getRegionFromPosGlobal(const LLVector3d& pos);
  84. LLViewerRegion* getRegionFromPosAgent(const LLVector3& pos);
  85. LLViewerRegion* getRegionFromHandle(const U64& handle);
  86. LLViewerRegion* getRegionFromID(const LLUUID& region_id);
  87. // 'true' if position is in valid region:
  88. bool positionRegionValidGlobal(const LLVector3d& pos);
  89. LLVector3d clipToVisibleRegions(const LLVector3d& start_pos,
  90. const LLVector3d& end_pos);
  91. // All of these should be in the agent coordinate frame
  92. LLViewerRegion* resolveRegionGlobal(LLVector3& localpos,
  93. const LLVector3d& position);
  94. LLViewerRegion* resolveRegionAgent(LLVector3& localpos,
  95. const LLVector3& position);
  96. F32 resolveLandHeightGlobal(const LLVector3d& position);
  97. F32 resolveLandHeightAgent(const LLVector3& position);
  98. // Return the lowest allowed Z point to prevent objects from being moved
  99. // underground.
  100. F32 getMinAllowedZ(LLViewerObject* object);
  101. F32 getMinAllowedZ(LLViewerObject* object, const LLVector3d& global_pos);
  102. // Takes a line segment defined by point_a and point_b, then determines the
  103. // closest (to point_a) point of intersection that is on the land surface
  104. // or on an object of the world.
  105. // Stores results in "intersection" and "intersection_normal" and returns a
  106. // scalar value that is the normalized (by length of line segment) distance
  107. // along the line from "point_a" to "intersection".
  108. // Currently assumes point_a and point_b only differ in z-direction, but it
  109. // may eventually become more general.
  110. F32 resolveStepHeightGlobal(const LLVOAvatar* avatarp,
  111. const LLVector3d& pt_a, const LLVector3d& pt_b,
  112. LLVector3d& intersect, LLVector3& inter_norm,
  113. LLViewerObject** vobjp = NULL);
  114. LLSurfacePatch* resolveLandPatchGlobal(const LLVector3d& position);
  115. // Absolute frame:
  116. LLVector3 resolveLandNormalGlobal(const LLVector3d& position);
  117. #if 0 // Scales other than 1.f are not currently supported...
  118. LL_INLINE F32 getRegionScale() const { return 1.f; }
  119. #endif
  120. void updateRegions(F32 max_update_time);
  121. void updateVisibilities();
  122. void updateClouds(F32 dt);
  123. void killClouds();
  124. LLCloudGroup* findCloudGroup(const LLCloudPuff& puff);
  125. void renderPropertyLines();
  126. // Update network statistics for all the regions:
  127. void updateNetStats();
  128. void printPacketsLost();
  129. void requestCacheMisses();
  130. // deal with map object updates in the world.
  131. static void processCoarseUpdate(LLMessageSystem* msg, void** user_data);
  132. F32 getLandFarClip() const;
  133. void setLandFarClip(F32 far_clip);
  134. LL_INLINE LLViewerTexture* getDefaultWaterTexture()
  135. {
  136. return mDefaultWaterTexturep;
  137. }
  138. void updateWaterObjects();
  139. void precullWaterObjects(LLCamera& camera, LLCullResult* cull);
  140. void waterHeightRegionInfo(std::string const& sim_name, F32 water_height);
  141. void shiftRegions(const LLVector3& offset);
  142. void reloadAllSurfacePatches();
  143. void getInfo(LLSD& info);
  144. void clearAllVisibleObjects();
  145. typedef std::list<LLViewerRegion*> region_list_t;
  146. LL_INLINE const region_list_t& getRegionList() const
  147. {
  148. return mActiveRegionList;
  149. }
  150. typedef boost::signals2::signal<void(LLViewerRegion*)> region_remove_signal_t;
  151. boost::signals2::connection setRegionRemovedCallback(const region_remove_signal_t::slot_type& cb);
  152. // Returns lists of avatar IDs, their world-space positions and mini-map
  153. // colors within a given distance of a point. All arguments but avatar_ids
  154. // are optional. Given containers will be emptied and then filled. Not
  155. // supplying origin or radius input returns data on all avatars in the
  156. // known regions.
  157. void getAvatars(uuid_vec_t& avatar_ids,
  158. std::vector<LLVector3d>* positions = NULL,
  159. std::vector<LLColor4>* colors = NULL,
  160. const LLVector3d& relative_to = LLVector3d(),
  161. F32 radius = FLT_MAX) const;
  162. // Returns 'true' if the region is in mRegionList, 'false' if the region
  163. // has been removed due to region change or if the circuit to this
  164. // simulator had been lost.
  165. bool isRegionListed(const LLViewerRegion* region) const;
  166. static void processEnableSimulator(LLMessageSystem* msg, void**);
  167. static void processRegionHandshake(LLMessageSystem* msg, void**);
  168. static void processDisableSimulator(LLMessageSystem* msg, void**);
  169. static void idleDisableQueuedSim();
  170. static void sendAgentPause();
  171. static void sendAgentResume();
  172. private:
  173. void clearHoleWaterObjects();
  174. void clearEdgeWaterObjects();
  175. private:
  176. F32 mLastRegionDisabling;
  177. F32 mLandFarClip; // Far clip distance for land.
  178. S32 mLastPacketsIn;
  179. S32 mLastPacketsOut;
  180. S32 mLastPacketsLost;
  181. U64 mLastCurlBytes;
  182. LLPatchVertexArray mLandPatch;
  183. region_list_t mActiveRegionList;
  184. region_list_t mRegionList;
  185. region_list_t mVisibleRegionList;
  186. region_list_t mCulledRegionList;
  187. region_list_t mDisabledRegionList;
  188. region_remove_signal_t mRegionRemovedSignal;
  189. ////////////////////////////
  190. //
  191. // Data for "Fake" objects
  192. //
  193. typedef std::list<LLPointer<LLVOWater> > water_obj_list_t;
  194. water_obj_list_t mHoleWaterObjects;
  195. LLPointer<LLVOWater> mEdgeWaterObjects[EDGE_WATER_OBJECTS_COUNT];
  196. LLPointer<LLViewerTexture> mDefaultWaterTexturep;
  197. };
  198. extern LLWorld gWorld;
  199. #endif