llagentpilot.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * @file llagentpilot.h
  3. * @brief LLAgentPilot class definition
  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_LLAGENTPILOT_H
  33. #define LL_LLAGENTPILOT_H
  34. #include <vector>
  35. #include "lltimer.h"
  36. #include "stdtypes.h"
  37. #include "llvector3d.h"
  38. // NOTE: all the *AutoPilot* stuff used to be in llagent.*. Moved it here for
  39. // coherency. This class therefore now deals with both the agent auto-pilot and
  40. // the agent pilot recorder/player. HB
  41. class LLAgentPilot final
  42. {
  43. protected:
  44. LOG_CLASS(LLAgentPilot);
  45. public:
  46. enum EActionType
  47. {
  48. STRAIGHT,
  49. TURN
  50. };
  51. LLAgentPilot();
  52. LL_INLINE bool isActive() const { return mAutoPilot; }
  53. LL_INLINE LLVector3d getAutoPilotTargetGlobal() const
  54. {
  55. return mAutoPilotTargetGlobal;
  56. }
  57. void startAutoPilotGlobal(const LLVector3d& pos_global,
  58. const std::string& behavior_name = std::string(),
  59. const LLQuaternion* target_rotation = NULL,
  60. void (*finish_callback)(bool, void*) = NULL,
  61. void* callback_data = NULL,
  62. F32 stop_distance = 0.f,
  63. F32 rotation_threshold = 0.03f,
  64. bool allow_flying = true);
  65. // Returns false if leader_id is null, or auto-pilot is currently active,
  66. // or leader_id is not an object currently present in the viewer objects
  67. // list (non-rezzed or inexistent object). Starts following the leader and
  68. // returns true otherwise.
  69. bool startFollowPilot(const LLUUID& leader_id, bool allow_flying = true,
  70. F32 stop_distance = 0.f);
  71. void stopAutoPilot(bool user_cancel = false);
  72. // Auto-pilot walking action, angles in radians
  73. void autoPilot(F32* delta_yaw);
  74. #if 0 // Not used
  75. void renderAutoPilotTarget();
  76. #endif
  77. bool load(const std::string& filename);
  78. bool save(const std::string& filename);
  79. static void remove(const std::string& filename);
  80. LL_INLINE bool isRecording() const { return mRecording; }
  81. LL_INLINE bool isPlaying() const { return mPlaying; }
  82. LL_INLINE bool hasRecord() const { return !mActions.empty(); }
  83. bool startRecord();
  84. bool stopRecord();
  85. void addAction(enum EActionType action);
  86. bool startPlayback(S32 num_runs, bool allow_flying);
  87. bool stopPlayback();
  88. void updateTarget();
  89. // Used only in llviewermenu.cpp, for menu-triggered recorder actions
  90. static void beginRecord(void*);
  91. static void endRecord(void*);
  92. static void forgetRecord(void*);
  93. static void startPlayback(void*);
  94. static void stopPlayback(void*);
  95. private:
  96. class Action
  97. {
  98. public:
  99. EActionType mType;
  100. LLVector3d mTarget;
  101. F64 mTime;
  102. };
  103. private:
  104. LLVector3d mAutoPilotTargetGlobal;
  105. LLVector3 mAutoPilotTargetFacing;
  106. std::string mAutoPilotBehaviorName;
  107. LLUUID mLeaderID;
  108. void (*mAutoPilotFinishedCallback)(bool, void*);
  109. void* mAutoPilotCallbackData;
  110. F32 mAutoPilotStopDistance;
  111. F32 mAutoPilotTargetDist;
  112. S32 mAutoPilotNoProgressFrameCount;
  113. F32 mAutoPilotRotationThreshold;
  114. LLTimer mTimer;
  115. std::vector<Action> mActions;
  116. S32 mCurrentAction;
  117. F32 mLastRecordTime;
  118. S32 mNumRuns;
  119. bool mAutoPilot;
  120. bool mAutoPilotAllowFlying;
  121. bool mAutoPilotFlyOnStop;
  122. bool mAutoPilotUseRotation;
  123. bool mRecording;
  124. bool mStarted;
  125. bool mPlaying;
  126. bool mAllowFlying;
  127. public:
  128. // Used only in llviewermenu.cpp, for menu-triggered recorder actions
  129. static bool sLoop;
  130. static bool sAllowFlying;
  131. };
  132. extern LLAgentPilot gAgentPilot;
  133. #endif // LL_LLAGENTPILOT_H