HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DOP_Parent.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: DOP_Parent.h ( SOP Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __DOP_Parent_h__
12 #define __DOP_Parent_h__
13 
14 #include "DOP_API.h"
15 #include "DOP_FullPathData.h"
16 #include "DOP_Node.h"
17 
18 #include <SIM/SIM_Utils.h>
19 #include <OP/OP_DopParent.h>
20 
21 class DEP_MicroNode;
22 class DOP_Parent;
23 template <typename T> class UT_Array;
24 
25 typedef enum {
30 
32 {
33 public:
34  DOP_Parent();
35  ~DOP_Parent() override;
36 
37  const DOP_Engine &getEngine() const;
38  DOP_Engine &getNonConstEngine();
39 
40  int dopparentUniqueId() const
41  { return myDopParentUniqueId; }
42 
43  void setNeedsToResimulateLastTimestep();
44  void setNeedsToFilterData();
45  void setNeedsToCompletelyReset() override;
46 
47  /// Sets the current simulation time, solving all intermediate steps.
48  /// Note that the time t passed in to this function is a global
49  /// Houdini time, and may not match the simulation time.
50  void setDOPTime(const SIM_Time &t);
51  /// Returns the simulation time that corresponds to a given global
52  /// Houdini time.
53  const SIM_Time getDOPTime(const SIM_Time &t) const;
54  /// Returns the global Houdini time that corresponds to a given
55  /// simulation time.
56  const SIM_Time getGlobalTime(const SIM_Time &t) const;
57  void resimulate();
58  /// Resets the simulation and cooks to a specific DOP time, this
59  /// avoids double cooking if you are resetting to frame 0.
60  void resimulateToTime(const SIM_Time &t);
61 
62  /// Returns true if the DOP network has changed such that the
63  /// simulation needs to be reset.
64  bool getNeedsResimulation() const;
65 
66  /// Attributes for controlling the simulation behavior.
67  /// Offset time is a global time for mapping simulation time 0
68  const SIM_Time &getOffsetTime() const;
69  void setOffsetTime(const SIM_Time &t);
70  /// Live Simulation time is a simulation time of where the live sim
71  /// currently is.
72  const SIM_Time &getLiveSimulationTime() const;
73  void setLiveSimulationTime(const SIM_Time &t);
74  exint getLastLiveTick() const;
75  void setLastLiveTick(exint tick);
76  fpreal getTimeScale() const;
77  void setTimeScale(fpreal scale);
78  bool getAutoResimulation() const;
79  void setAutoResimulation(bool autoreset);
80  bool getInterpolateData(const SIM_Time &t) const;
81  void setInterpolateData(bool interpolate);
82  bool getIsSimulating() const;
83  virtual bool getIsTimeless() const { return false; }
84 
85  /// Used by SIM_Engine to flag this privately if it is during
86  /// an internally generated simulation pass
87  void setIsSimulating(bool val)
88  { mySimulating = val; }
89 
90  /// Used externally to flag that we do not want to resimulate
91  /// due to our setDOPTime() invocations.
92  bool getDisableSimulation() const
93  { return myDisableSimulation; }
94  void setDisableSimulation(bool disable)
95  { myDisableSimulation = disable; }
96 
97  /// Get all objects that match a particular string. This calls the
98  /// SIM_Engine::findAllObjectsFromString() function, but converts the
99  /// time value from global time to simulation time, and passes our
100  /// getInterpolateData() value as the interpolate parameter.
101  void findAllObjectsFromString(const char *objspec,
102  SIM_ConstObjectArray &objects,
103  const SIM_Time &t) const;
104  /// Get the object that matches a particular string. This calls the
105  /// SIM_Engine::findObjectFromString() function, but converts the
106  /// time value from global time to simulation time, and passes our
107  /// getInterpolateData() value as the interpolate parameter.
108  const SIM_Object *findObjectFromString(const char *objspec,
109  int whichmatch, int *nummatch,
110  const SIM_Time &t) const;
111  /// Get all relationships that match a particular string. This calls the
112  /// SIM_Engine::findAllRelationshipsFromString() function, but converts the
113  /// time value from global time to simulation time, and passes our
114  /// getInterpolateData() value as the interpolate parameter.
115  void findAllRelationshipsFromString(
116  const char *relspec,
117  SIM_ConstDataArray &relationships,
118  const SIM_Time &t) const;
119  /// Get the relationship that matches a particular string. This calls the
120  /// SIM_Engine::findRelationshipFromString() function, but converts the
121  /// time value from global time to simulation time, and passes our
122  /// getInterpolateData() value as the interpolate parameter.
123  const SIM_Relationship *findRelationshipFromString(
124  const char *relspec,
125  int whichmatch, int *nummatch,
126  const SIM_Time &t) const;
127 
128  /// Returns data used by DOP_Nodes during their cook process. This is
129  /// information that is global to the DOP Network as it cooks.
130  DOP_Node::DOP_CookData &getDopNodeCookData();
131 
132  /// Sends out a parm changed message so that anyone interested in the
133  /// simulation will know to refresh their data. This call also protects
134  /// the DOP Network from causing infinite recursion when the DOP Network
135  /// is interested in a SOP node which is interested in the DOP Network
136  /// (a common and legal situation when using a SOP Solver, for example).
137  void sendResimulateNotification(
138  bool callnotify,
139  bool changingguideparm);
140 
142  { return getNonConstEngineSubclass().simMicroNode(); }
144  { return getNonConstEngineSubclass().simInputMicroNode(); }
146  { return getNonConstEngineSubclass().resimParmsMicroNode(); }
148  { return getEngineSubclass().resimParmsMicroNode(); }
150  { return getNonConstEngineSubclass().refilterParmsMicroNode(); }
152  { return getEngineSubclass().refilterParmsMicroNode(); }
153 
155  OP_NodeList &extras) const override;
156 
157  fpreal opGetLatestCacheTime() const override
158  { return getEngine().getLatestCacheTime(); }
159  OP_Node *opGetOwner() const override
160  { return getEngine().getOwner(); }
161 
163  bool callnotify, bool changingguideparm) override
164  { sendResimulateNotification(callnotify, changingguideparm); }
165  void opResimulate() override { resimulate(); }
166  void opResetPlayer() override { getNonConstEngine().resetPlayer(); }
167  bool opIsContinuousCook() const override { return false; }
168  exint opContinuousCookTick() const override { return -1; }
169  bool opIsSimFrameCached(exint simframe) const override;
170  virtual void addExtraSimDependencies(DEP_MicroNode *depnode)
171  { }
172 
173  /// The current dopnet may not be the top of the recently used.
174  /// Dopnets that are inside locked assets, for example, are rather
175  /// useless as destinations.
176  /// Except we do want access to those for tracking cache settings,
177  /// reset flags, etc.
178  /// These may also be dop-like caches.
180  { return opGetMostRecentDopOwner(); }
181  /// The most recent writeable will be a DOP_Parent.
182  static OP_Node *getMostRecentWriteableDopOwner();
183 
184  bool opGetNeedsResimulation() const override
185  { return getNeedsResimulation(); }
186  bool opGetDisableSimulation() const override;
187  /// Query cache size.
188  void opGetDiskCache(
189  UT_Array<int> &frames) const override;
190  void opGetMemoryCache(
191  UT_Array<int> &frames) const override;
192 
193  /// Update re-simulation parameters, ensuring getOffsetTime and the
194  /// ilk are valid. This is required before getDOPTime will work
195  /// as expected (but note setDOPTime() implicitly invokes this)
196  void updateResimParms(const SIM_Time &t);
197 
198 protected:
199  const SIM_Time &getLastSetTime() const;
200  void resimulateLastTimestep();
201  /// Sets a flag that says we need to re-filter our simulation data the
202  /// next time a request for the data is made.
203  void setNeedsToFilterData(const SIM_Time &t);
204  /// Check if we need to filter our simulation data, and do so if required.
205  void filterDataIfRequired() const;
206  /// This function calls filterDataSubclass() to cache pointers to the
207  /// simulation data that is of interest to us.
208  void filterData(const SIM_Time &t);
209 
210  virtual const DOP_Engine &getEngineSubclass() const = 0;
211  virtual void resimulateLastTimestepSubclass();
212  virtual void setDOPTimeSubclass(const SIM_Time &t);
213  virtual DOP_Engine &getNonConstEngineSubclass() = 0;
214  virtual void filterDataSubclass(const SIM_Time &t) = 0;
215 
216  virtual void handleRefilterParms(const SIM_Time &t) {}
217  virtual void handleResimParms(const SIM_Time &t) {}
218 
219  void notifySimulationChangeSinksOfChange();
220  void notifySimulationChangeSinksOfDelete();
221 
222 private:
223  UT_ValArray<DOP_SimulationChangeSink *> mySimulationChangeSinks;
224  DOP_Node::DOP_CookData myDopNodeCookData;
225  SIM_Time myLastSetTime;
226 
227  bool myLiveSimulation;
228  SIM_Time myLiveSimulationTime;
229  exint myLastLiveTick;
230 
231  SIM_Time myOffsetTime;
232  SIM_Time myNeedsToFilterDataTime;
233  fpreal myTimeScale;
234  bool myNeedsToFilterData;
235  bool mySimulating;
236  bool myNeedsToResimulateFrame;
237  bool myNeedsToResimulateCompletely;
238  bool myAutoResimulation;
239  bool myInterpolateData;
240  bool mySendingResimulateNotification;
241  bool myDisableSimulation;
242  int myDopParentUniqueId;
243 
245  friend class DOP_Engine;
246 };
247 
249 {
250 public:
252  { }
254  { removeAllSimulationChangeSinks(); }
255 
256  virtual void simulationChanged(DOP_Parent *dopparent) = 0;
257  virtual void simulationDeleted(DOP_Parent *dopparent)
258  { removeSimulationChangeSink(dopparent); }
259 
260 protected:
262  {
263  if( !dopparent ) return;
264  dopparent->mySimulationChangeSinks.append(this, 1);
265  myDopParents.append(dopparent, 1);
266  }
268  {
269  if( !dopparent ) return;
270  dopparent->mySimulationChangeSinks.findAndRemove(this);
271  myDopParents.findAndRemove(dopparent);
272  }
274  {
275  for( int i = myDopParents.entries(); i --> 0; )
276  removeSimulationChangeSink(myDopParents(i));
277  }
278 
279 private:
280  UT_ValArray<DOP_Parent *> myDopParents;
281 };
282 
283 #endif
bool getDisableSimulation() const
Definition: DOP_Parent.h:92
int dopparentUniqueId() const
Definition: DOP_Parent.h:40
void addSimulationChangeSink(DOP_Parent *dopparent)
Definition: DOP_Parent.h:261
virtual void simulationDeleted(DOP_Parent *dopparent)
Definition: DOP_Parent.h:257
static OP_Node * opGetMostRecentDopOwner()
virtual void setNeedsToCompletelyReset()=0
exint findAndRemove(const S &s)
virtual bool opGetDisableSimulation() const =0
void removeAllSimulationChangeSinks()
Definition: DOP_Parent.h:273
void removeSimulationChangeSink(DOP_Parent *dopparent)
Definition: DOP_Parent.h:267
int64 exint
Definition: SYS_Types.h:125
DEP_MicroNode & resimParmsMicroNode()
Definition: DOP_Parent.h:145
virtual void handleRefilterParms(const SIM_Time &t)
Definition: DOP_Parent.h:216
void setIsSimulating(bool val)
Definition: DOP_Parent.h:87
void setDisableSimulation(bool disable)
Definition: DOP_Parent.h:94
GA_API const UT_StringHolder scale
#define DOP_API
Definition: DOP_API.h:10
const DEP_MicroNode & refilterParmsMicroNode() const
Definition: DOP_Parent.h:151
exint opContinuousCookTick() const override
Current continuous cook tick.
Definition: DOP_Parent.h:168
virtual ~DOP_SimulationChangeSink()
Definition: DOP_Parent.h:253
virtual void handleResimParms(const SIM_Time &t)
Definition: DOP_Parent.h:217
virtual void opGetDiskCache(UT_Array< int > &frames) const =0
DEP_MicroNode & simMicroNode()
Definition: DOP_Parent.h:141
void resetPlayer()
Rebuilds the player cache.
bool opIsContinuousCook() const override
Returns if the operator is in Continous Cook mode.
Definition: DOP_Parent.h:167
const SIM_Time & getLatestCacheTime() const
Holds pointers to a number of const SIM_Object objects.
exint append()
Definition: UT_Array.h:142
GLdouble t
Definition: glad.h:2397
void opResetPlayer() override
Definition: DOP_Parent.h:166
void opSendResimulateNotification(bool callnotify, bool changingguideparm) override
Definition: DOP_Parent.h:162
static OP_Node * getMostRecentDopOwner()
Definition: DOP_Parent.h:179
OP_Node * opGetOwner() const override
Definition: DOP_Parent.h:159
OP_Node * getOwner() const
virtual void opGetMemoryCache(UT_Array< int > &frames) const =0
virtual bool getIsTimeless() const
Definition: DOP_Parent.h:83
virtual bool opIsSimFrameCached(exint simframe) const =0
Note this is in simulation frames, not global.
fpreal64 fpreal
Definition: SYS_Types.h:278
GLuint GLfloat * val
Definition: glcorearb.h:1608
DEP_MicroNode & refilterParmsMicroNode()
Definition: DOP_Parent.h:149
void opResimulate() override
Definition: DOP_Parent.h:165
bool opGetNeedsResimulation() const override
Definition: DOP_Parent.h:184
DEP_MicroNode & simInputMicroNode()
Definition: DOP_Parent.h:143
fpreal opGetLatestCacheTime() const override
Definition: DOP_Parent.h:157
virtual void opGetSimExtraInputNodes(OP_NodeList &extras) const =0
DOP_ParentEventType
Definition: DOP_Parent.h:25
const DEP_MicroNode & resimParmsMicroNode() const
Definition: DOP_Parent.h:147
virtual void addExtraSimDependencies(DEP_MicroNode *depnode)
Definition: DOP_Parent.h:170