llpathfindingnavmeshstatus.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @file llpathfindingnavmeshstatus.cpp
  3. * @brief Implementation of llpathfindingnavmeshstatus
  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 "llpathfindingnavmeshstatus.h"
  34. #include "llsd.h"
  35. #define REGION_FIELD "region_id"
  36. #define STATUS_FIELD "status"
  37. #define VERSION_FIELD "version"
  38. const std::string LLPathfindingNavMeshStatus::sStatusPending("pending");
  39. const std::string LLPathfindingNavMeshStatus::sStatusBuilding("building");
  40. const std::string LLPathfindingNavMeshStatus::sStatusComplete("complete");
  41. const std::string LLPathfindingNavMeshStatus::sStatusRepending("repending");
  42. LLPathfindingNavMeshStatus::LLPathfindingNavMeshStatus()
  43. : mIsValid(false),
  44. mRegionUUID(),
  45. mVersion(0U),
  46. mStatus(kComplete)
  47. {
  48. }
  49. LLPathfindingNavMeshStatus::LLPathfindingNavMeshStatus(const LLUUID& region_id)
  50. : mIsValid(false),
  51. mRegionUUID(region_id),
  52. mVersion(0U),
  53. mStatus(kComplete)
  54. {
  55. }
  56. LLPathfindingNavMeshStatus::LLPathfindingNavMeshStatus(const LLUUID& region_id,
  57. const LLSD& content)
  58. : mIsValid(true),
  59. mRegionUUID(region_id),
  60. mVersion(0U),
  61. mStatus(kComplete)
  62. {
  63. parseStatus(content);
  64. }
  65. LLPathfindingNavMeshStatus::LLPathfindingNavMeshStatus(const LLSD& content)
  66. : mIsValid(true),
  67. mVersion(0U),
  68. mStatus(kComplete)
  69. {
  70. llassert(content.has(REGION_FIELD));
  71. llassert(content.get(REGION_FIELD).isUUID());
  72. mRegionUUID = content.get(REGION_FIELD).asUUID();
  73. parseStatus(content);
  74. }
  75. LLPathfindingNavMeshStatus::LLPathfindingNavMeshStatus(const LLPathfindingNavMeshStatus& status)
  76. : mIsValid(status.mIsValid),
  77. mRegionUUID(status.mRegionUUID),
  78. mVersion(status.mVersion),
  79. mStatus(status.mStatus)
  80. {
  81. }
  82. LLPathfindingNavMeshStatus &LLPathfindingNavMeshStatus::operator=(const LLPathfindingNavMeshStatus& status)
  83. {
  84. mIsValid = status.mIsValid;
  85. mRegionUUID = status.mRegionUUID;
  86. mVersion = status.mVersion;
  87. mStatus = status.mStatus;
  88. return *this;
  89. }
  90. void LLPathfindingNavMeshStatus::parseStatus(const LLSD& content)
  91. {
  92. if (content.has(VERSION_FIELD) &&
  93. content.get(VERSION_FIELD).isInteger() &&
  94. content.get(VERSION_FIELD).asInteger() >= 0)
  95. {
  96. mVersion = static_cast<U32>(content.get(VERSION_FIELD).asInteger());
  97. }
  98. else
  99. {
  100. llwarns << "Malformed navmesh status data: missing version"
  101. << llendl;
  102. }
  103. if (!content.has(STATUS_FIELD) || !content.get(STATUS_FIELD).isString())
  104. {
  105. llwarns << "Malformed navmesh status data: missing status. Aborting !"
  106. << llendl;
  107. return;
  108. }
  109. std::string status = content.get(STATUS_FIELD).asString();
  110. if (LLStringUtil::compareStrings(status, sStatusPending) == 0)
  111. {
  112. mStatus = kPending;
  113. }
  114. else if (LLStringUtil::compareStrings(status, sStatusBuilding) == 0)
  115. {
  116. mStatus = kBuilding;
  117. }
  118. else if (LLStringUtil::compareStrings(status, sStatusComplete) == 0)
  119. {
  120. mStatus = kComplete;
  121. }
  122. else if (LLStringUtil::compareStrings(status, sStatusRepending) == 0)
  123. {
  124. mStatus = kRepending;
  125. }
  126. else
  127. {
  128. mStatus = kComplete;
  129. llwarns << "Malformed navmesh status data: bad status" << llendl;
  130. }
  131. }