aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcharacter/llstatemachine.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcharacter/llstatemachine.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llcharacter/llstatemachine.h')
-rw-r--r--linden/indra/llcharacter/llstatemachine.h149
1 files changed, 149 insertions, 0 deletions
diff --git a/linden/indra/llcharacter/llstatemachine.h b/linden/indra/llcharacter/llstatemachine.h
new file mode 100644
index 0000000..0f986bd
--- /dev/null
+++ b/linden/indra/llcharacter/llstatemachine.h
@@ -0,0 +1,149 @@
1/**
2 * @file llstatemachine.h
3 * @brief LLStateMachine class header file.
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLSTATEMACHINE_H
29#define LL_LLSTATEMACHINE_H
30
31#include <string>
32
33#include "llassoclist.h"
34#include "llerror.h"
35#include <map>
36
37class LLUniqueID
38{
39 friend bool operator==(const LLUniqueID &a, const LLUniqueID &b);
40 friend bool operator!=(const LLUniqueID &a, const LLUniqueID &b);
41protected:
42 static U32 sNextID;
43 U32 mId;
44public:
45 LLUniqueID(){mId = sNextID++;}
46 virtual ~LLUniqueID(){}
47 U32 getID() {return mId;}
48};
49
50class LLFSMTransition : public LLUniqueID
51{
52public:
53 LLFSMTransition() : LLUniqueID(){};
54 virtual std::string getName(){ return "unnamed"; }
55};
56
57class LLFSMState : public LLUniqueID
58{
59public:
60 LLFSMState() : LLUniqueID(){};
61 virtual void onEntry(void *){};
62 virtual void onExit(void *){};
63 virtual void execute(void *){};
64 virtual std::string getName(){ return "unnamed"; }
65};
66
67class LLStateDiagram
68{
69typedef std::map<LLFSMTransition*, LLFSMState*> Transitions;
70
71friend std::ostream& operator<<(std::ostream &s, LLStateDiagram &FSM);
72friend class LLStateMachine;
73
74protected:
75 typedef std::map<LLFSMState*, Transitions> StateMap;
76 StateMap mStates;
77 Transitions mDefaultTransitions;
78 LLFSMState* mDefaultState;
79 BOOL mUseDefaultState;
80
81public:
82 LLStateDiagram();
83 virtual ~LLStateDiagram();
84
85protected:
86 // add a state to the state graph, executed implicitly when adding transitions
87 BOOL addState(LLFSMState *state);
88
89 // add a directed transition between 2 states
90 BOOL addTransition(LLFSMState& start_state, LLFSMState& end_state, LLFSMTransition& transition);
91
92 // add an undirected transition between 2 states
93 BOOL addUndirectedTransition(LLFSMState& start_state, LLFSMState& end_state, LLFSMTransition& transition);
94
95 // add a transition that is taken if none other exist
96 void addDefaultTransition(LLFSMState& end_state, LLFSMTransition& transition);
97
98 // process a possible transition, and get the resulting state
99 LLFSMState* processTransition(LLFSMState& start_state, LLFSMTransition& transition);
100
101 // add a transition that exists for every state
102 void setDefaultState(LLFSMState& default_state);
103
104 // return total number of states with no outgoing transitions
105 S32 numDeadendStates();
106
107 // does this state exist in the state diagram?
108 BOOL stateIsValid(LLFSMState& state);
109
110 // get a state pointer by ID
111 LLFSMState* getState(U32 state_id);
112
113public:
114 // save the graph in a DOT file for rendering and visualization
115 BOOL saveDotFile(const char* filename);
116};
117
118class LLStateMachine
119{
120protected:
121 LLFSMState* mCurrentState;
122 LLFSMState* mLastState;
123 LLFSMTransition* mLastTransition;
124 LLStateDiagram* mStateDiagram;
125
126public:
127 LLStateMachine();
128 virtual ~LLStateMachine();
129
130 // set state diagram
131 void setStateDiagram(LLStateDiagram* diagram);
132
133 // process this transition
134 void processTransition(LLFSMTransition &transition, void* user_data);
135
136 // returns current state
137 LLFSMState* getCurrentState() const;
138
139 // execute current state
140 void runCurrentState(void *data);
141
142 // set state by state pointer
143 BOOL setCurrentState(LLFSMState *initial_state, void* user_data, BOOL skip_entry = TRUE);
144
145 // set state by unique ID
146 BOOL setCurrentState(U32 state_id, void* user_data, BOOL skip_entry = TRUE);
147};
148
149#endif //_LL_LLSTATEMACHINE_H