llpathfindinglinksetlist.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * @file llpathfindinglinksetlist.cpp
  3. * @brief Implementation of llpathfindinglinksetlist
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewergpl$
  6. *
  7. * Copyright (c) 2012, 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. #include "llviewerprecompiledheaders.h"
  33. #include "llpathfindinglinksetlist.h"
  34. #include "llsd.h"
  35. LLPathfindingLinksetList::LLPathfindingLinksetList()
  36. : LLPathfindingObjectList()
  37. {
  38. }
  39. LLPathfindingLinksetList::LLPathfindingLinksetList(const LLSD& data)
  40. : LLPathfindingObjectList()
  41. {
  42. parseLinksetListData(data);
  43. }
  44. LLSD LLPathfindingLinksetList::encodeObjectFields(EUsage use, S32 a, S32 b,
  45. S32 c, S32 d) const
  46. {
  47. LLSD list_data;
  48. for (const_iterator iter = begin(); iter != end(); ++iter)
  49. {
  50. const LLPathfindingObject::ptr_t objectp = iter->second;
  51. if (!objectp) continue;
  52. const LLPathfindingLinkset* linksetp = objectp.get()->asLinkset();
  53. if (linksetp && !linksetp->isTerrain())
  54. {
  55. LLSD data = linksetp->encodeAlteredFields(use, a, b, c, d);
  56. if (!data.isUndefined())
  57. {
  58. list_data[iter->first.asString()] = data;
  59. }
  60. }
  61. }
  62. return list_data;
  63. }
  64. LLSD LLPathfindingLinksetList::encodeTerrainFields(EUsage use, S32 a, S32 b,
  65. S32 c, S32 d) const
  66. {
  67. for (const_iterator iter = begin(); iter != end(); ++iter)
  68. {
  69. const LLPathfindingObject::ptr_t objectp = iter->second;
  70. if (!objectp) continue;
  71. const LLPathfindingLinkset* linksetp = objectp.get()->asLinkset();
  72. if (linksetp && linksetp->isTerrain())
  73. {
  74. return linksetp->encodeAlteredFields(use, a, b, c, d);
  75. }
  76. }
  77. return LLSD();
  78. }
  79. bool LLPathfindingLinksetList::showUnmodifiablePhantomWarning(EUsage use) const
  80. {
  81. for (const_iterator iter = begin(); iter != end(); ++iter)
  82. {
  83. const LLPathfindingObject::ptr_t objectp = iter->second;
  84. if (!objectp) continue;
  85. const LLPathfindingLinkset* linksetp = objectp.get()->asLinkset();
  86. if (linksetp && linksetp->showUnmodifiablePhantomWarning(use))
  87. {
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. bool LLPathfindingLinksetList::showPhantomToggleWarning(EUsage use) const
  94. {
  95. for (const_iterator iter = begin(); iter != end(); ++iter)
  96. {
  97. const LLPathfindingObject::ptr_t objectp = iter->second;
  98. if (!objectp) continue;
  99. const LLPathfindingLinkset* linksetp = objectp.get()->asLinkset();
  100. if (linksetp && linksetp->showPhantomToggleWarning(use))
  101. {
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. bool LLPathfindingLinksetList::showCannotBeVolumeWarning(EUsage use) const
  108. {
  109. for (const_iterator iter = begin(); iter != end(); ++iter)
  110. {
  111. const LLPathfindingObject::ptr_t objectp = iter->second;
  112. if (!objectp) continue;
  113. const LLPathfindingLinkset* linksetp = objectp.get()->asLinkset();
  114. if (linksetp && linksetp->showCannotBeVolumeWarning(use))
  115. {
  116. return true;
  117. }
  118. }
  119. return false;
  120. }
  121. void LLPathfindingLinksetList::determinePossibleStates(bool& walkable,
  122. bool& static_obstacle,
  123. bool& dynamic_obstacle,
  124. bool& material_volume,
  125. bool& exclusion_volume,
  126. bool& dynamic_phantom) const
  127. {
  128. walkable = static_obstacle = dynamic_obstacle = material_volume =
  129. exclusion_volume = dynamic_phantom = false;
  130. for (const_iterator iter = begin();
  131. !(walkable && static_obstacle && dynamic_obstacle &&
  132. material_volume && exclusion_volume && dynamic_phantom) &&
  133. iter != end();
  134. ++iter)
  135. {
  136. const LLPathfindingObject::ptr_t objectp = iter->second;
  137. if (!objectp) continue;
  138. const LLPathfindingLinkset* linksetp = objectp.get()->asLinkset();
  139. if (!linksetp) continue;
  140. if (linksetp->isTerrain())
  141. {
  142. walkable = true;
  143. }
  144. else if (linksetp->isModifiable())
  145. {
  146. walkable = true;
  147. static_obstacle = true;
  148. dynamic_obstacle = true;
  149. dynamic_phantom = true;
  150. if (linksetp->canBeVolume())
  151. {
  152. material_volume = true;
  153. exclusion_volume = true;
  154. }
  155. }
  156. else if (linksetp->isPhantom())
  157. {
  158. dynamic_phantom = true;
  159. if (linksetp->canBeVolume())
  160. {
  161. material_volume = true;
  162. exclusion_volume = true;
  163. }
  164. }
  165. else
  166. {
  167. walkable = true;
  168. static_obstacle = true;
  169. dynamic_obstacle = true;
  170. }
  171. }
  172. }
  173. void LLPathfindingLinksetList::parseLinksetListData(const LLSD& data)
  174. {
  175. LLPathfindingObject::map_t& obj_map = getObjectMap();
  176. std::string id_str;
  177. LLUUID id;
  178. for (LLSD::map_const_iterator iter = data.beginMap(), end = data.endMap();
  179. iter != end; ++iter)
  180. {
  181. id_str = iter->first;
  182. const LLSD& data = iter->second;
  183. if (!data.size())
  184. {
  185. llwarns << "Empty data for path finding linkset Id: " << id_str
  186. << llendl;
  187. continue;
  188. }
  189. if (LLUUID::validate(id_str))
  190. {
  191. LLUUID id = LLUUID(id_str);
  192. obj_map.emplace(id,
  193. std::make_shared<LLPathfindingLinkset>(id, data));
  194. }
  195. else
  196. {
  197. llwarns << "Invalid path finding linkset Id: " << id_str << llendl;
  198. }
  199. }
  200. }