AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ActionManager.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
18
19
20#ifndef AGXCONTROL_ACTION_MANAGER_H
21#define AGXCONTROL_ACTION_MANAGER_H
22
23#include <agx/config.h>
24
25#include <agxControl/Action.h>
28#include <agx/List.h>
29#include <agx/TimeStamp.h>
30
31
43namespace agxControl
44{
45 AGX_DECLARE_POINTER_TYPES(ActionManager);
46
47
48
49
54 class AGXPHYSICS_EXPORT ActionManager : public agxSDK::EventListener
55 {
56 public:
57 ActionManager();
58
66 bool add(agxControl::Action* action);
67
74 bool remove(const agxControl::Action* action);
75
84 bool add(agxControl::Operation* operation);
85
92 bool remove(agxControl::Operation* operation);
93
94
95 void cleanup();
96
97 void cleanup( agx::Real newCurrentTime );
98
104 void stepActions(agx::TimeStamp time);
105
111 void takeActions(ActionManager* other);
112
113 /*
114 The ActionManager doesn't quite follow the normal store/restore behavior
115 because the simulation that the ActionManager is restored into may be at
116 another time stamp than the time stored in the serialized ActionManager.
117 Because of this is is not correct to read in and simply add all Actions and
118 operations found since that could activate the wrong events. Instead, the
119 restored ActionManager is used as a temporary Action/Operation container and
120 the restored Actions and Operations are later
121 */
122 AGXSTREAM_DECLARE_SERIALIZABLE(agxControl::ActionManager);
123
124
125 public:
127 AGX_DECLARE_POINTER_TYPES(ActionTag);
128 AGX_DECLARE_POINTER_TYPES(OperationTag);
129 AGX_DECLARE_POINTER_TYPES(BeginOperationTag);
130 AGX_DECLARE_POINTER_TYPES(EndOperationTag);
131
133 enum Type { ACTION, OPERATION };
134
136 enum Endpoint { OPERATION_BEGIN, OPERATION_END };
137
138 typedef agx::List<TagRef> TagList;
139 typedef agx::List<OperationRef> OperationList;
140
141 private:
148 TagList::iterator insertSorted(TagRef& tag, TagList& list);
149
163 bool findAndEraseOperationsTag(TagList::iterator& begin, const Operation* operation, Endpoint endpoint);
164
177 TagList::iterator takeAction( TagList& otherTags, TagRef& nextToTake, TagList::iterator writeIt );
178
182 void restoreActionQueue(agxStream::InputArchive& in, const char* sectionName);
183
184 size_t countActions() const;
185 size_t countOperations() const;
186
191 const TagList& getTags() const;
192
193 private:
194 friend class Tag;
195 friend class ActionTag;
196 friend class OperationTag;
197 friend class BeginOperationTag;
198 friend class EndOperationTag;
199
200 // A trigger of a Tag will end up in one of these, which will do the actual
201 // triggering and also perform the necessary updates to the internal state
202 // of the ActionManager.
203 void performTrigger(ActionTag* actionTag, agx::Real time);
204 void performTrigger(BeginOperationTag* beginTag, agx::Real time);
205 void performTrigger(EndOperationTag* endTag, agx::Real time);
206
207 private:
208 agx::Real m_lastSeenTimeStamp;
209
211 TagList m_tags;
212
214 TagList::iterator m_nextTag;
215
217 OperationList m_activeOperations;
218 };
219
220
221 AGXPHYSICS_EXPORT bool operator==(const agxControl::ActionManager::Tag& left, const agxControl::ActionManager::Tag& right);
222
227 class agxControl::ActionManager::Tag : public agx::Referenced
228 {
229 public:
230 Tag(ActionManager::Type type);
231 virtual void trigger(agxControl::ActionManager* manager, agx::Real time) = 0;
232 virtual agx::Real getTime() const = 0;
233 ActionManager::Type getType() const;
234 protected:
235 virtual ~Tag() {};
236 private:
237 ActionManager::Type m_type;
238 };
239
240 class agxControl::ActionManager::ActionTag : public agxControl::ActionManager::Tag
241 {
242 public:
243 ActionTag(Action* action);
244 virtual void trigger(agxControl::ActionManager* manager, agx::Real time) override;
245 virtual agx::Real getTime() const override;
246 agxControl::Action* getAction();
247 const agxControl::Action* getAction() const;
248 protected:
249 virtual ~ActionTag() {}
250 private:
251 agxControl::ActionRef m_action;
252 };
253
258 class ActionManager::OperationTag : public ActionManager::Tag
259 {
260 public:
261 OperationTag(agxControl::Operation* operation, ActionManager::Endpoint endpoint);
262 virtual void trigger(agxControl::ActionManager* manager, agx::Real time) = 0;
263 virtual agx::Real getTime() const = 0;
264 agxControl::Operation* getOperation();
265 const agxControl::Operation* getOperation() const;
266 ActionManager::Endpoint getEndpoint() const;
267 protected:
268 virtual ~OperationTag() {};
269 private:
270 agxControl::OperationRef m_operation;
271 ActionManager::Endpoint m_endpoint;
272 };
273
274 class ActionManager::BeginOperationTag : public OperationTag
275 {
276 public:
277 BeginOperationTag(agxControl::Operation* operation);
278 virtual void trigger(agxControl::ActionManager* manager, agx::Real time) override;
279 virtual agx::Real getTime() const override;
280 protected:
281 virtual ~BeginOperationTag() {}
282 };
283
284 class ActionManager::EndOperationTag : public OperationTag
285 {
286 public:
287 EndOperationTag(agxControl::Operation* operation);
288 virtual void trigger(agxControl::ActionManager* manager, agx::Real time) override;
289 virtual agx::Real getTime() const override;
290 protected:
291 virtual ~EndOperationTag() {}
292 };
293}
294
295// Include guard.
296#endif
297
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
An EventListener can be associated to a Simulation and triggered upon various events.
Class for reading a binary stream of serialized data.
Base class providing referencing counted objects.
Definition Referenced.h:120
This namespace contains general operation and action classes which can be used to control a agxSDK::S...
AGXCORE_EXPORT Type * getType(const agx::String &name)
double Real
Definition Real.h:42
bool operator==(T val, InvalidIndexStruct)
Definition agx.h:201
agx::Real TimeStamp
Definition TimeStamp.h:26