llgesturemgr.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * @file llgesturemgr.h
  3. * @brief Manager for playing gestures on the viewer
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-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_LLGESTUREMGR_H
  33. #define LL_LLGESTUREMGR_H
  34. #include "llassetstorage.h" // LLAssetType
  35. #include "hbfastmap.h"
  36. #include "llviewerinventory.h"
  37. class LLMultiGesture;
  38. class LLGestureStep;
  39. class LLUUID;
  40. class LLGestureManagerObserver
  41. {
  42. public:
  43. virtual ~LLGestureManagerObserver() {}
  44. virtual void changed() = 0;
  45. };
  46. class LLGestureManager
  47. {
  48. protected:
  49. LOG_CLASS(LLGestureManager);
  50. public:
  51. LLGestureManager();
  52. ~LLGestureManager();
  53. // Loads and activates gestures on login
  54. void load(const LLSD& gestures);
  55. // Call once per frame to manage gestures
  56. void update();
  57. // Loads a gesture out of inventory into the in-memory active form. Note
  58. // that the inventory item must exist, so we can look up the asset id.
  59. void activateGesture(const LLUUID& item_id);
  60. // Activate a list of gestures
  61. void activateGestures(LLViewerInventoryItem::item_array_t& items);
  62. // If you change a gesture, you need to build a new multigesture
  63. // and call this method.
  64. void replaceGesture(const LLUUID& item_id,
  65. LLMultiGesture* new_gesturep,
  66. const LLUUID& asset_id);
  67. void replaceGesture(const LLUUID& item_id, const LLUUID& asset_id);
  68. // Load gesture into in-memory active form. Can be called even if the
  69. // inventory item isn't loaded yet. inform_server true will send message
  70. // upstream to update database user_gesture_active table, which isn't
  71. // necessary on login. deactivate_similar will cause other gestures with
  72. // the same trigger phrase or keybinding to be deactivated.
  73. void activateGestureWithAsset(const LLUUID& item_id,
  74. const LLUUID& asset_id, bool inform_server,
  75. bool deactivate_similar);
  76. // Takes gesture out of active list and deletes it.
  77. void deactivateGesture(const LLUUID& item_id);
  78. // Deactivates all gestures that match either this trigger phrase or this
  79. // hot key.
  80. void deactivateSimilarGestures(LLMultiGesture* gesture,
  81. const LLUUID& in_item_id);
  82. bool isGestureActive(const LLUUID& item_id);
  83. bool isGesturePlaying(const LLUUID& item_id);
  84. // Forces a gesture to be played, for example, if it is being previewed.
  85. void playGesture(LLMultiGesture* gesturep);
  86. void playGesture(const LLUUID& item_id);
  87. // Stops all requested or playing anims for this gesture. Also removes from
  88. // playing list.
  89. void stopGesture(LLMultiGesture* gesturep);
  90. void stopGesture(const LLUUID& item_id);
  91. // Trigger the first gesture that matches this key.
  92. // Returns true if it finds a gesture bound to that key.
  93. bool triggerGesture(KEY key, MASK mask);
  94. // Triggers all gestures referenced as substrings in this string
  95. bool triggerAndReviseString(const std::string& str,
  96. std::string* revised_string = NULL);
  97. S32 getPlayingCount() const;
  98. void addObserver(LLGestureManagerObserver* observer);
  99. void removeObserver(LLGestureManagerObserver* observer);
  100. void notifyObservers();
  101. bool matchPrefix(const std::string& in_str, std::string* out_str);
  102. // Copy item ids into the vector
  103. void getItemIDs(uuid_vec_t* ids);
  104. static void notifyLoadFailed(const LLUUID& item_id, S32 status);
  105. protected:
  106. // Handle the processing of a single gesture
  107. void stepGesture(LLMultiGesture* gesturep);
  108. // Do a single step in a gesture
  109. void runStep(LLMultiGesture* gesturep, LLGestureStep* step);
  110. // Used by loadGesture
  111. static void onLoadComplete(const LLUUID& asset_uuid,
  112. LLAssetType::EType type, void* user_data,
  113. S32 status, LLExtStat);
  114. public:
  115. std::vector<LLMultiGesture*> mPlaying;
  116. // Maps inventory item_id to gesture
  117. typedef fast_hmap<LLUUID, LLMultiGesture*> item_map_t;
  118. // Active gestures. NOTE: The gesture pointer CAN BE NULL. This means that
  119. // there is a gesture with that item_id, but the asset data is still on its
  120. // way down from the server.
  121. item_map_t mActive;
  122. std::vector<LLGestureManagerObserver*> mObservers;
  123. std::string mDeactivateSimilarNames;
  124. S32 mLoadingCount;
  125. bool mValid;
  126. };
  127. extern LLGestureManager gGestureManager;
  128. #endif