lllandmark.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @file lllandmark.h
  3. * @brief Landmark asset class
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLLANDMARK_H
  33. #define LL_LLLANDMARK_H
  34. #include <map> // For multimap
  35. #include "boost/function.hpp"
  36. #include "hbfastmap.h"
  37. #include "llframetimer.h"
  38. #include "lluuid.h"
  39. #include "llvector3d.h"
  40. class LLMessageSystem;
  41. class LLHost;
  42. class LLLandmark
  43. {
  44. protected:
  45. LOG_CLASS(LLLandmark);
  46. public:
  47. // For calling back interested parties when a region handle comes back.
  48. typedef boost::function<void(const LLUUID& region_id,
  49. const U64& region_handle)> region_handle_callback_t;
  50. ~LLLandmark() {}
  51. // Returns true if the position is known.
  52. bool getGlobalPos(LLVector3d& pos);
  53. // Setter used in conjunction if more information needs to be collected
  54. // from the server.
  55. void setGlobalPos(const LLVector3d& pos);
  56. // Returns true if the region is known
  57. bool getRegionID(LLUUID& region_id);
  58. // Returns the local coordinates if known
  59. LLVector3 getRegionPos() const;
  60. // Constructs a new LLLandmark from a string. Return NULL if there is an
  61. // error.
  62. static LLLandmark* constructFromString(const char* buffer, S32 buff_size);
  63. // Registers callbacks that this class handles
  64. static void registerCallbacks(LLMessageSystem* msg);
  65. // Requests information about region_id to region_handle. The callback
  66. // pointer will be erased but NOT deleted after the callback is made.
  67. // This method may call into the message system to get the information.
  68. static void requestRegionHandle(LLMessageSystem* msg,
  69. const LLHost& upstream_host,
  70. const LLUUID& region_id,
  71. region_handle_callback_t callback);
  72. // Call this method to create a lookup for this region. This simplifies a
  73. // lot of the code.
  74. static void setRegionHandle(const LLUUID& region_id, U64 region_handle);
  75. private:
  76. LLLandmark(const LLUUID& region_id, const LLVector3& local_pos);
  77. LLLandmark(const LLVector3d& global_pos);
  78. static void processRegionIDAndHandle(LLMessageSystem* msg, void**);
  79. static void expireOldEntries();
  80. private:
  81. LLUUID mRegionID;
  82. LLVector3 mRegionPos;
  83. LLVector3d mGlobalPos;
  84. bool mGlobalPositionKnown;
  85. struct CacheInfo
  86. {
  87. U64 mRegionHandle;
  88. LLFrameTimer mTimer;
  89. };
  90. static std::pair<LLUUID, U64> mLocalRegion;
  91. typedef fast_hmap<LLUUID, CacheInfo> region_map_t;
  92. static region_map_t mRegions;
  93. typedef std::multimap<LLUUID, region_handle_callback_t> region_callback_map_t;
  94. static region_callback_map_t mRegionCallback;
  95. };
  96. #endif