llpathfindingcharacter.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * @file llpathfindingcharacter.cpp
  3. * @brief Definition of a pathfinding character that contains various properties required for havok pathfinding.
  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 "llpathfindingcharacter.h"
  34. #include "llpathfindingobject.h"
  35. #include "llsd.h"
  36. #define CHARACTER_CPU_TIME_FIELD "cpu_time"
  37. #define CHARACTER_HORIZONTAL_FIELD "horizontal"
  38. #define CHARACTER_LENGTH_FIELD "length"
  39. #define CHARACTER_RADIUS_FIELD "radius"
  40. LLPathfindingCharacter::LLPathfindingCharacter(const LLUUID& id,
  41. const LLSD& char_data)
  42. : LLPathfindingObject(id, char_data),
  43. mCPUTime(0U),
  44. mIsHorizontal(false),
  45. mLength(0.f),
  46. mRadius(0.f)
  47. {
  48. parseCharacterData(char_data);
  49. }
  50. LLPathfindingCharacter::LLPathfindingCharacter(const LLPathfindingCharacter& obj)
  51. : LLPathfindingObject(obj),
  52. mCPUTime(obj.mCPUTime),
  53. mIsHorizontal(obj.mIsHorizontal),
  54. mLength(obj.mLength),
  55. mRadius(obj.mRadius)
  56. {
  57. }
  58. LLPathfindingCharacter& LLPathfindingCharacter::operator=(const LLPathfindingCharacter& obj)
  59. {
  60. dynamic_cast<LLPathfindingObject&>(*this) = obj;
  61. mCPUTime = obj.mCPUTime;
  62. mIsHorizontal = obj.mIsHorizontal;
  63. mLength = obj.mLength;
  64. mRadius = obj.mRadius;
  65. return *this;
  66. }
  67. void LLPathfindingCharacter::parseCharacterData(const LLSD& char_data)
  68. {
  69. if (char_data.has(CHARACTER_CPU_TIME_FIELD) &&
  70. char_data.get(CHARACTER_CPU_TIME_FIELD).isReal())
  71. {
  72. mCPUTime = char_data.get(CHARACTER_CPU_TIME_FIELD).asReal();
  73. }
  74. else
  75. {
  76. llwarns << "Malformed pathfinding character data: no CPU time"
  77. << llendl;
  78. }
  79. if (char_data.has(CHARACTER_HORIZONTAL_FIELD) &&
  80. char_data.get(CHARACTER_HORIZONTAL_FIELD).isBoolean())
  81. {
  82. mIsHorizontal = char_data.get(CHARACTER_HORIZONTAL_FIELD).asBoolean();
  83. }
  84. else
  85. {
  86. llwarns << "Malformed pathfinding character data: no horizontal flag"
  87. << llendl;
  88. }
  89. if (char_data.has(CHARACTER_LENGTH_FIELD) &&
  90. char_data.get(CHARACTER_LENGTH_FIELD).isReal())
  91. {
  92. mLength = char_data.get(CHARACTER_LENGTH_FIELD).asReal();
  93. }
  94. else
  95. {
  96. llwarns << "Malformed pathfinding character data: no length"
  97. << llendl;
  98. }
  99. if (char_data.has(CHARACTER_RADIUS_FIELD) &&
  100. char_data.get(CHARACTER_RADIUS_FIELD).isReal())
  101. {
  102. mRadius = char_data.get(CHARACTER_RADIUS_FIELD).asReal();
  103. }
  104. else
  105. {
  106. llwarns << "Malformed pathfinding character data: no radius"
  107. << llendl;
  108. }
  109. }