PageRenderTime 143ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llgesturemgr.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 194 lines | 84 code | 40 blank | 70 comment | 0 complexity | 77b650d7ae4a8dcfb9fcee83af43ae92 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llgesturemgr.h
  3. * @brief Manager for playing gestures on the viewer
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLGESTUREMGR_H
  27. #define LL_LLGESTUREMGR_H
  28. #include <map>
  29. #include <string>
  30. #include <vector>
  31. #include "llassetstorage.h" // LLAssetType
  32. #include "llinventoryobserver.h"
  33. #include "llsingleton.h"
  34. #include "llviewerinventory.h"
  35. class LLMultiGesture;
  36. class LLGestureListener;
  37. class LLGestureStep;
  38. class LLUUID;
  39. class LLVFS;
  40. class LLGestureManagerObserver
  41. {
  42. public:
  43. virtual ~LLGestureManagerObserver() { };
  44. virtual void changed() = 0;
  45. };
  46. class LLGestureMgr : public LLSingleton<LLGestureMgr>, public LLInventoryFetchItemsObserver
  47. {
  48. public:
  49. typedef boost::function<void (LLMultiGesture* loaded_gesture)> gesture_loaded_callback_t;
  50. // Maps inventory item_id to gesture
  51. typedef std::map<LLUUID, LLMultiGesture*> item_map_t;
  52. typedef std::map<LLUUID, gesture_loaded_callback_t> callback_map_t;
  53. LLGestureMgr();
  54. ~LLGestureMgr();
  55. void init();
  56. // Call once per frame to manage gestures
  57. void update();
  58. // Loads a gesture out of inventory into the in-memory active form
  59. // Note that the inventory item must exist, so we can look up the
  60. // asset id.
  61. void activateGesture(const LLUUID& item_id);
  62. // Activate a list of gestures
  63. void activateGestures(LLViewerInventoryItem::item_array_t& items);
  64. // If you change a gesture, you need to build a new multigesture
  65. // and call this method.
  66. void replaceGesture(const LLUUID& item_id, LLMultiGesture* new_gesture, const LLUUID& asset_id);
  67. void replaceGesture(const LLUUID& item_id, const LLUUID& asset_id);
  68. // Load gesture into in-memory active form.
  69. // Can be called even if the inventory item isn't loaded yet.
  70. // inform_server TRUE will send message upstream to update database
  71. // user_gesture_active table, which isn't necessary on login.
  72. // deactivate_similar will cause other gestures with the same trigger phrase
  73. // or keybinding to be deactivated.
  74. void activateGestureWithAsset(const LLUUID& item_id, const LLUUID& asset_id, BOOL inform_server, BOOL deactivate_similar);
  75. // Takes gesture out of active list and deletes it.
  76. void deactivateGesture(const LLUUID& item_id);
  77. // Deactivates all gestures that match either this trigger phrase,
  78. // or this hot key.
  79. void deactivateSimilarGestures(LLMultiGesture* gesture, const LLUUID& in_item_id);
  80. BOOL isGestureActive(const LLUUID& item_id);
  81. BOOL isGesturePlaying(const LLUUID& item_id);
  82. BOOL isGesturePlaying(LLMultiGesture* gesture);
  83. const item_map_t& getActiveGestures() const { return mActive; }
  84. // Force a gesture to be played, for example, if it is being
  85. // previewed.
  86. void playGesture(LLMultiGesture* gesture);
  87. void playGesture(const LLUUID& item_id);
  88. // Stop all requested or playing anims for this gesture
  89. // Also remove from playing list
  90. void stopGesture(LLMultiGesture* gesture);
  91. void stopGesture(const LLUUID& item_id);
  92. /**
  93. * Add cb into callbackMap.
  94. * Note:
  95. * Manager will call cb after gesture will be loaded and will remove cb automatically.
  96. */
  97. void setGestureLoadedCallback(LLUUID inv_item_id, gesture_loaded_callback_t cb)
  98. {
  99. mCallbackMap[inv_item_id] = cb;
  100. }
  101. // Trigger the first gesture that matches this key.
  102. // Returns TRUE if it finds a gesture bound to that key.
  103. BOOL triggerGesture(KEY key, MASK mask);
  104. // Trigger all gestures referenced as substrings in this string
  105. BOOL triggerAndReviseString(const std::string &str, std::string *revised_string = NULL);
  106. // Does some gesture have this key bound?
  107. BOOL isKeyBound(KEY key, MASK mask);
  108. S32 getPlayingCount() const;
  109. void addObserver(LLGestureManagerObserver* observer);
  110. void removeObserver(LLGestureManagerObserver* observer);
  111. void notifyObservers();
  112. // Overriding so we can update active gesture names and notify observers
  113. void changed(U32 mask);
  114. BOOL matchPrefix(const std::string& in_str, std::string* out_str);
  115. // Copy item ids into the vector
  116. void getItemIDs(uuid_vec_t* ids);
  117. protected:
  118. // Handle the processing of a single gesture
  119. void stepGesture(LLMultiGesture* gesture);
  120. // Do a single step in a gesture
  121. void runStep(LLMultiGesture* gesture, LLGestureStep* step);
  122. // LLInventoryCompletionObserver trigger
  123. void done();
  124. // Used by loadGesture
  125. static void onLoadComplete(LLVFS *vfs,
  126. const LLUUID& asset_uuid,
  127. LLAssetType::EType type,
  128. void* user_data, S32 status, LLExtStat ext_status);
  129. // Used by playGesture to load an asset file
  130. // required to play a gesture step
  131. static void onAssetLoadComplete(LLVFS *vfs,
  132. const LLUUID& asset_uuid,
  133. LLAssetType::EType type,
  134. void* user_data, S32 status, LLExtStat ext_status);
  135. // Checks whether all animation and sound assets
  136. // needed to play a gesture are loaded.
  137. static bool hasLoadingAssets(LLMultiGesture* gesture);
  138. private:
  139. // Active gestures.
  140. // NOTE: The gesture pointer CAN BE NULL. This means that
  141. // there is a gesture with that item_id, but the asset data
  142. // is still on its way down from the server.
  143. item_map_t mActive;
  144. S32 mLoadingCount;
  145. std::string mDeactivateSimilarNames;
  146. std::vector<LLGestureManagerObserver*> mObservers;
  147. callback_map_t mCallbackMap;
  148. std::vector<LLMultiGesture*> mPlaying;
  149. BOOL mValid;
  150. std::set<LLUUID> mLoadingAssets;
  151. // LLEventHost interface
  152. boost::shared_ptr<LLGestureListener> mListener;
  153. };
  154. #endif