PageRenderTime 73ms CodeModel.GetById 54ms app.highlight 15ms RepoModel.GetById 1ms 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
  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
 27#ifndef LL_LLGESTUREMGR_H
 28#define LL_LLGESTUREMGR_H
 29
 30#include <map>
 31#include <string>
 32#include <vector>
 33
 34#include "llassetstorage.h"	// LLAssetType
 35#include "llinventoryobserver.h"
 36#include "llsingleton.h"
 37#include "llviewerinventory.h"
 38
 39class LLMultiGesture;
 40class LLGestureListener;
 41class LLGestureStep;
 42class LLUUID;
 43class LLVFS;
 44
 45class LLGestureManagerObserver
 46{
 47public:
 48	virtual ~LLGestureManagerObserver() { };
 49	virtual void changed() = 0;
 50};
 51
 52class LLGestureMgr : public LLSingleton<LLGestureMgr>, public LLInventoryFetchItemsObserver
 53{
 54public:
 55
 56	typedef boost::function<void (LLMultiGesture* loaded_gesture)> gesture_loaded_callback_t;
 57	// Maps inventory item_id to gesture
 58	typedef std::map<LLUUID, LLMultiGesture*> item_map_t;
 59	typedef std::map<LLUUID, gesture_loaded_callback_t> callback_map_t;
 60
 61	LLGestureMgr();
 62	~LLGestureMgr();
 63
 64	void init();
 65
 66	// Call once per frame to manage gestures
 67	void update();
 68
 69	// Loads a gesture out of inventory into the in-memory active form
 70	// Note that the inventory item must exist, so we can look up the 
 71	// asset id.
 72	void activateGesture(const LLUUID& item_id);
 73
 74	// Activate a list of gestures
 75	void activateGestures(LLViewerInventoryItem::item_array_t& items);
 76
 77	// If you change a gesture, you need to build a new multigesture
 78	// and call this method.
 79	void replaceGesture(const LLUUID& item_id, LLMultiGesture* new_gesture, const LLUUID& asset_id);
 80	void replaceGesture(const LLUUID& item_id, const LLUUID& asset_id);
 81
 82	// Load gesture into in-memory active form.
 83	// Can be called even if the inventory item isn't loaded yet.
 84	// inform_server TRUE will send message upstream to update database
 85	// user_gesture_active table, which isn't necessary on login.
 86	// deactivate_similar will cause other gestures with the same trigger phrase
 87	// or keybinding to be deactivated.
 88	void activateGestureWithAsset(const LLUUID& item_id, const LLUUID& asset_id, BOOL inform_server, BOOL deactivate_similar);
 89
 90	// Takes gesture out of active list and deletes it.
 91	void deactivateGesture(const LLUUID& item_id);
 92
 93	// Deactivates all gestures that match either this trigger phrase,
 94	// or this hot key.
 95	void deactivateSimilarGestures(LLMultiGesture* gesture, const LLUUID& in_item_id);
 96
 97	BOOL isGestureActive(const LLUUID& item_id);
 98
 99	BOOL isGesturePlaying(const LLUUID& item_id);
100
101	BOOL isGesturePlaying(LLMultiGesture* gesture);
102
103	const item_map_t& getActiveGestures() const { return mActive; }
104	// Force a gesture to be played, for example, if it is being
105	// previewed.
106	void playGesture(LLMultiGesture* gesture);
107	void playGesture(const LLUUID& item_id);
108
109	// Stop all requested or playing anims for this gesture
110	// Also remove from playing list
111	void stopGesture(LLMultiGesture* gesture);
112	void stopGesture(const LLUUID& item_id);
113	/**
114	 * Add cb into callbackMap.
115	 * Note:
116	 * Manager will call cb after gesture will be loaded and will remove cb automatically. 
117	 */
118	void setGestureLoadedCallback(LLUUID inv_item_id, gesture_loaded_callback_t cb)
119	{
120		mCallbackMap[inv_item_id] = cb;
121	}
122	// Trigger the first gesture that matches this key.
123	// Returns TRUE if it finds a gesture bound to that key.
124	BOOL triggerGesture(KEY key, MASK mask);
125
126	// Trigger all gestures referenced as substrings in this string
127	BOOL triggerAndReviseString(const std::string &str, std::string *revised_string = NULL);
128
129	// Does some gesture have this key bound?
130	BOOL isKeyBound(KEY key, MASK mask);
131
132	S32 getPlayingCount() const;
133
134	void addObserver(LLGestureManagerObserver* observer);
135	void removeObserver(LLGestureManagerObserver* observer);
136	void notifyObservers();
137
138	// Overriding so we can update active gesture names and notify observers 
139	void changed(U32 mask); 
140
141	BOOL matchPrefix(const std::string& in_str, std::string* out_str);
142
143	// Copy item ids into the vector
144	void getItemIDs(uuid_vec_t* ids);
145
146protected:
147	// Handle the processing of a single gesture
148	void stepGesture(LLMultiGesture* gesture);
149
150	// Do a single step in a gesture
151	void runStep(LLMultiGesture* gesture, LLGestureStep* step);
152
153	// LLInventoryCompletionObserver trigger
154	void done();
155
156	// Used by loadGesture
157	static void onLoadComplete(LLVFS *vfs,
158						   const LLUUID& asset_uuid,
159						   LLAssetType::EType type,
160						   void* user_data, S32 status, LLExtStat ext_status);
161
162	// Used by playGesture to load an asset file
163	// required to play a gesture step
164	static void onAssetLoadComplete(LLVFS *vfs,
165									const LLUUID& asset_uuid,
166									LLAssetType::EType type,
167									void* user_data, S32 status, LLExtStat ext_status);
168
169	// Checks whether all animation and sound assets
170	// needed to play a gesture are loaded.
171	static bool hasLoadingAssets(LLMultiGesture* gesture);
172
173private:
174	// Active gestures.
175	// NOTE: The gesture pointer CAN BE NULL.  This means that
176	// there is a gesture with that item_id, but the asset data
177	// is still on its way down from the server.
178	item_map_t mActive;
179
180	S32 mLoadingCount;
181	std::string mDeactivateSimilarNames;
182	
183	std::vector<LLGestureManagerObserver*> mObservers;
184	callback_map_t mCallbackMap;
185	std::vector<LLMultiGesture*> mPlaying;	
186	BOOL mValid;
187
188	std::set<LLUUID> mLoadingAssets;
189
190	// LLEventHost interface
191	boost::shared_ptr<LLGestureListener> mListener;
192};
193
194#endif