HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Engine.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  */
7 
8 #ifndef __SIM_Engine_h__
9 #define __SIM_Engine_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_Cache.h"
13 #include "SIM_Data.h"
14 #include "SIM_Error.h"
15 #include "SIM_ObjectSolveInfo.h"
16 #include <OP/OP_Value.h>
17 #include <OP/OP_DopParent.h>
18 #include <DEP/DEP_MicroNode.h>
19 #include <UT/UT_Array.h>
20 #include <UT/UT_IntrusivePtr.h>
21 #include <UT/UT_Map.h>
22 #include <UT/UT_Set.h>
23 #include <UT/UT_SymbolTable.h>
24 
25 #define SIM_PATH_SEPCHAR '/'
26 #define SIM_OBJECT_SEPCHAR ':'
27 #define SIM_OBJECTNUM_SEPCHAR '.'
28 #define SIM_OBJECTDATA_SEPCHAR '/'
29 
30 class UT_InfoTree;
31 class UT_StringArray;
32 class UT_StringRef;
33 class OP_Node;
34 class SIM_BaseCache;
35 class SIM_DopDescription;
37 class SIM_DataFactory;
38 class SIM_Data;
39 class SIM_SimulationState;
40 class SIM_MetaObject;
41 class SIM_MetaObjectArray;
43 class SIM_ObjectArray;
44 class SIM_SaveCommand;
45 
47 {
48 public:
50 
51  const char *className() const override
52  { return "SIM_SimulationMicroNode"; }
53  void becameDirty(
55  const DEP_PropagateData &data) override;
56 
57 protected:
59 };
60 
61 /// This is the main engine behind all simulations. Any number of these
62 /// can be created to create independent simulations. Generally a simulation
63 /// will be owned by a particular OP_Node. For example, the DopNet object
64 /// contains a SIM_Engine.
65 class SIM_API SIM_Engine : public UT_IntrusiveRefCounter<SIM_Engine>
66 {
67 public:
68  /// Constructor to create a new simulation.
69  SIM_Engine(OP_Node *owner);
70  /// Destructor to destroy all data associated with a simulation.
71  virtual ~SIM_Engine();
72 
73  SIM_Engine(const SIM_Engine &) = delete;
74  SIM_Engine &operator=(const SIM_Engine &) = delete;
75 
76  /// Returns the OP_Node that owns this engine. This may be null if
77  /// the engine isn't associated with a particular node.
78  OP_Node *getOwner() const;
79  /// Gets the full path to the DOP Network node that owns this simulation.
80  const UT_String &getOwnerFullPath() const;
81  void getOwnerFullPathString(UT_String &str) const;
82 
83  /// Allocates a new SIM_Object and adds it to the simulation.
84  /// The name parameter is assigned to the object. This name does not
85  /// have to be unique.
86  SIM_Object *addSimulationObject(bool solvefirstframe);
87  /// Removes a SIM_Object from the simulation.
88  /// The index value is the current location of the object in the
89  /// simulations's list of objects. This value will not be the same
90  /// as the SIM_Object::getObjectId() value, and may change when objects
91  /// are added to or removed from the simulation.
92  void removeSimulationObject(int index);
93  /// Removes a SIM_Object from the simulation.
94  /// This version of this function takes a SIM_Object pointer instead
95  /// of an index. The pointer is converted to an index and the indexed
96  /// version of removeSimulationObject() is called.
97  void removeSimulationObject(SIM_Object *object);
98  /// Returns the number of objects currently in the simulation.
99  int getNumSimulationObjects() const;
100  /// Returns the number of objects currently in the simulation.
101  int64 getNumSimulationData() const;
102  /// Returns a pointer to the SIM_Object at the specified index.
103  /// The index value is the current location of the object in the
104  /// simulations's list of objects. This value will not be the same
105  /// as the SIM_Object::getObjectId() value.
106  const SIM_Object *getSimulationObject(int index) const;
107  /// Returns a pointer to the SIM_Object with the specified unique id.
108  /// This function searches the current list of objects for the
109  /// specified objectid. If the objectid is not found, this function
110  /// returns null.
111  const SIM_Object *getSimulationObjectFromId(int objectid) const;
112  /// Returns the "nth" simulation object that matches a supplied filter.
113  /// If less than the supplied n objects match the filter, 0 is returned.
114  const SIM_Object *getNthSimulationObject(
115  const SIM_DataFilter &filter,
116  int n) const;
117 
118  /// Creates a new relationship. The creationflags parameter accepts the
119  /// same SIM_DATA_* flags accepted by the creationflags parameter of
120  /// SIM_Data::createNamedSubData().
121  SIM_Relationship *addRelationship(const char *name,
122  int creationflags);
123  /// Returns the number of relationships in the current simulation state.
124  int getNumRelationships() const;
125  /// This function allows looping through the simulations relationships.
126  const SIM_Relationship *getRelationship(int index) const;
127  /// Returns the relationship with the specified name.
128  const SIM_Relationship *getRelationship(const char *name) const;
129  /// Gets all the relationships of a particular type. The type of a
130  /// relationship is defined by the one subdata on the SIM_Relationship.
131  void filterConstRelationships(
132  const SIM_DataFilter &filter,
133  SIM_ConstDataArray &rels) const;
134  /// Removes the relationship at the specified position.
135  void removeRelationship(int index);
136  /// Removes the relationship with the specified name.
137  void removeRelationship(const char *name);
138  /// Removes the specified relationship.
139  void removeRelationship(SIM_Relationship *rel);
140  /// Removes all relationships created by a particular DOP node. If -1
141  /// is specified, then all relationships are removed. Relationships in
142  /// the "except" array are not removed.
143  void removeAllRelationships(int createdby,
144  const SIM_RelationshipArray *except);
145 
146  /// Returns either a SIM_Relationship or SIM_Object depending on the
147  /// information stored in the id parameter.
148  const SIM_RootData *getRootDataFromId(
149  const SIM_RootDataId &id) const;
150 
151  // Only HOM should call this method:
152  SIM_RootData *getNonConstRootDataFromId(
153  const SIM_RootDataId &id);
154 
155  /// Returns a pointer to the state of an object at some time in the past.
156  /// This function searches for these past object states in three ways.
157  /// First, if the specified time is equal to a past time step, the state
158  /// for that time step is returned. Second, if the specified time is not
159  /// equal to a past time step, then past time steps are searched for
160  /// object states stored explicitly with createSubStepObject(). Finally,
161  /// if both these methods fail to find a matching object state, then the
162  /// closest object states before and after the specified time are found
163  /// using the first two approaches. Then a new object state is created by
164  /// interpolating between these two states using SIM_Data::interpolate().
165  /// This third approach is skipped if allowinterpolation is set to false.
166  /// If no previous or no future object state can be found, then this
167  /// function returns null.
168  const SIM_Object *getObjectAtTime(const SIM_Object &object,
169  const SIM_Time &time,
170  bool allowinterpolation) const;
171 
172  /// Returns a non-const pointer to an object for a particular time.
173  /// This function is very similar to getObjectAtTime() except for two
174  /// things. First, it requires a non-const starting object, and it is
175  /// a non-const function. Second, if the specified time exactly matches
176  /// a time in the past, the returned object will be a copy of that past
177  /// object, not the object itself. Otherwise modifying that object could
178  /// modify the past. However, if the current time is sepcified, the actual
179  /// object (i.e. a pointer to the passed in SIM_Object) is returned.
180  /// This function is for use by solvers that want to modify their
181  /// affector objects and which do substepping.
182  SIM_Object *getAffectorAtTime(SIM_Object &object,
183  const SIM_Time &time,
184  bool allowinterpolation);
185 
186  /// This is a more direct, more efficient method for reading
187  /// cached versions of objects from previous frames, without interpolation.
188  ///
189  /// Before the call, 'past_objects' must be a valid array of
190  /// SIM_Object* arrays and 'past_times' must be a valid array of SIM_Time.
191  /// 'past_objects' must have size 'max_past'
192  /// each element of 'past_objects' must be an array of SIM_Object* of
193  //// size 'num_objects'
194  /// 'past_times' must be an array of size 'max_past'
195  ///
196  /// Output:
197  /// The number of cached frames is returned.
198  /// The cached version of object[oi] at time past_times[i]
199  /// is stored in the array past_objects[i] at location oi,
200  /// for all 0 <= i < "the returned number of cached frames"
201 
202  int getObjectsAtPastTimes(
203  const SIM_Object**const past_objects[],
204  SIM_Time past_times[],
205  const int num_objects,
206  const SIM_Object*const objects[],
207  const int max_past
208  );
209 
210  /// Equivalent of getObjectsAtPastTimes() for relationships.
211  int getRelationshipsAtPastTimes(
212  const SIM_Relationship**const past_rels[],
213  SIM_Time past_times[],
214  const int num_rels,
215  const SIM_Relationship*const rels[],
216  const int max_past
217  ) const;
218 
219  /// Creates an object in the current state with a particular time stamp.
220  /// This function is useful for solvers that need to do their own time
221  /// stepping with step sizes smaller than the globally specified time
222  /// step size. These explicitly stored subsamples are accessible later
223  /// with the getObjectAtTime() function.
224  SIM_Object *createSubStepObject(const SIM_Object &object,
225  const SIM_Time &time);
226  /// Removes an object previously created by createSubStepObject().
227  /// If the allwithmatchingid parameter is set to true, not only will
228  /// the specified object be destroyed, but all other objects with the
229  /// same object id created using createSubStepObject() will be destroyed.
230  /// This provides a quick way to destroy all temporary working copies
231  /// of a particular object.
232  void removeSubStepObject(SIM_Object *objectattime,
233  bool allwithmatchingid);
234 
235  /// Loads a simulation state from a file and merges it into the current
236  /// simulation state. The data that gets loaded is not allowed to do any
237  /// sharing of data with the current state, since the data id's can't
238  /// be expected to match. Objects from the file will replace objects from
239  /// the current state if their object ids match. Objects loaded from the
240  /// file will be flagged so that they will not be solved in the current
241  /// timestep. In subsequent timesteps these objects will be solved.
242  /// The filter parameter specifies which objects stored in the file
243  /// are merged in.
244  bool mergeSimulationFile(const char *filename,
245  const SIM_DataFilter &filter,
246  const SIM_ObjectArray &replaceobjects,
247  const OP_Node *defaultcreator,
248  bool forcecreatortodefault,
249  bool acceptnewobjects,
250  bool matchbyname,
251  const char *nameprefix);
252  /// Schedules some objects to be saved to a files at the end of the
253  /// current timestep. The filter parameter makes it possible to save
254  /// only some of the objects to the file. The actual save happens
255  /// in the postSimulationStep().
256  void saveSimulationFile(OP_Node *node,
257  const char *filename,
258  const SIM_DataFilter &filter,
259  const SIM_ObjectArray &objects,
261  /// Saves the entire current state of the simulation immediately.
262  bool saveSimulationState(std::ostream &os,
264  bool saveSimulationStateToFile(const char *fname,
266  bool threadedio) const;
267 
268  /// Sets the current time for the simulation. If the new simulation
269  /// time is less than the current time, the SIM_Cache is simply set to
270  /// use its best match for the chosen time. If the new simulation time
271  /// is greater than the current time, the simulation is stepped forward
272  /// in time to the new time. The resimlasttimestep parameter causes the
273  /// most recent cache entry to be deleted before trying to set the
274  /// current time. This is useful if some parameter of the simulation
275  /// changes on the current timestep. It causes the timestep to be
276  /// recooked with the new parameter. This resimulation may also happen
277  /// if the simulation was interrupted the last time this function was
278  /// called. The forceresetsim parameter tells the SIM_Engine to reset
279  /// the simulation before trying to move to the specified time, whether
280  /// the reset is required or not.
281  void setSimulationTime(const SIM_Time &t,
282  bool resimlasttimestep,
283  bool forceresetsim,
284  bool allowsimulation);
285 
286  /// Marks this engine as invalid without actually clearing or
287  /// resetting anything. A proper reset implies also a frame
288  /// advance to the first frame that can be expensive.
289  /// Note the cache will not be cleared until it is cooked, however!
291  { myFirstSimulationStep = true; }
292 
293  /// Returns the current simulation time.
294  const SIM_Time &getSimulationTime() const;
295  /// Returns the simulation time that corresponds to the given global time.
296  const SIM_Time getEngineTime(const SIM_Time &t) const;
297  /// Returns the global time that corresponds to the given simulation time.
298  const SIM_Time getGlobalTime(const SIM_Time &t) const;
299  /// Returns the time of the earliest simulation state in the cache.
300  const SIM_Time &getEarliestCacheTime() const;
301  const SIM_Time &getLatestCacheTime() const;
302  /// Returns the cached frames.
303  /// Inclusive.
304  void getCachedFrames(UT_Array<int> &frames,
305  bool inmemory) const;
306  /// Returns if a frame is cached.
307  bool isFrameCached(exint frame) const;
308  /// Returns a reference to the cache options for this simulation.
309  const SIM_CacheOptions &getCacheOptions() const;
310  /// Sets the cache options for this simulation.
311  void setCacheOptions(const SIM_CacheOptions &o);
312  /// Returns the time step size.
313  const SIM_Time &getTimeStep() const;
314  /// Sets the global time step size.
315  void setTimeStep(const SIM_Time &time);
316  /// Gets the maximum number of allowed feedback iterations.
317  int getMaxFeedbackIterations() const;
318  /// Sets the maximum number of allowed feedback iterations.
319  void setMaxFeedbackIterations(int max);
320  /// Gets the current feedback iteration we are on. If we are not
321  /// currently solving, this function will return -1;
322  int getFeedbackIteration() const;
323  /// Returns true if the engine is providing data hierarchy hints.
324  bool getProvideDataHints() const;
325  /// Specifies whether the engine should provide data hierarchy hints.
326  void setProvideDataHints(bool providehints);
327  /// Gets the id for the node that is currently being processed.
329  { return myCurrentCreatorId; }
330  /// Gets the index of the node output that is currently being processed.
332  { return myCurrentCreatorIndex; }
333  /// Set the creator information. These values are automatically reset
334  /// to (-1, -1) before performing a simulation step.
335  void setCreatorInfo(int id, int index);
336  /// Returns the SIM_Data pointer with the specified unique id.
337  const SIM_Data *getConstDataWithId(const UT_Guid &id) const;
338  /// Returns the simulation frame number that corresponds to the given
339  /// time. The simulation frame number is the number of timesteps that
340  /// need to be run to get to the specified time, plus one (so that
341  /// time zero is frame 1).
342  int getSimulationFrame(const SIM_Time &time) const;
343  /// Returns the simulation time that corresponds to the given simulation
344  /// frame.
345  const SIM_Time getSimulationTime(int frame) const;
346 
347  /// Adds an error to the engine. The object and data parameters allow
348  /// the DOP_Engine to put the error message on an appropriate DOP Node.
349  /// Errors are found in the SIM error file. This function simply calls
350  /// addErrorSubclass().
351  void addError(const SIM_RootData *rootdata,
352  const SIM_Data *data,
353  int errorcode,
354  const char *errorparm,
355  UT_ErrorSeverity severity) const;
356  /// Resets the errors stored in the simulation.
357  void resetErrors();
358 
359  /// Returns the total amount of memory used by all data currently in
360  /// this simulation, at the current time or in the cache.
361  int64 getTotalMemorySize() const;
362 
363  /// Removes all node interests from the engine.
364  void removeAllOPInterests() const;
365  /// Adds an interest in the supplied node. When the node changes, the
366  /// engine's handleExternalNodeChange function will be called.
367  void addOPInterest(OP_Node *node) const;
368  void addGuideOPInterest(OP_Node *node) const;
369 
370  /// Returns whether there is an explicit interest on the node.
371  bool hasOPInterest(OP_Node *node) const
372  { return myOPInterestNodes.contains(node); }
373 
374  /// Passes up to our owner to alert anything that needs an OP_Event
375  /// in response to use becoming dirty.
377 
378  /// Returns all available data type names.
379  /// If a null type pointer is passed in, this function returns a list
380  /// of every data type that the SIM_Engine can create. If a data type
381  /// name is passed in, the list returned will only contain those data
382  /// types that can be cast to the specified data type using the
383  /// SIM_Data::getPointerToType() function.
384  void getDataTypes(UT_StringArray &datatypes,
385  const UT_StringRef &datatype) const;
386  /// Returns a list of the superclass names for the specified data type.
387  void getDataTypeSuperclasses(
388  const UT_StringRef &datatype,
389  UT_StringArray &classes) const;
390  /// Returns all available data types and the source of their definition.
391  /// The definition source will be an empty string if the data type is
392  /// defined internally to Houdini. Otherwise it will be the name of the
393  /// DSO or DLL file that contains the data type.
394  void getDataTypeSources(UT_StringArray &datatypes,
395  UT_StringArray &srcs) const;
396  /// Returns the descriptive name for a data type.
397  /// Given the unique identifying name for a data type this function
398  /// finds the appropriate data factory and returns the descriptive
399  /// string assigned to the type.
400  const char *getDescription(
401  const UT_StringRef &datatype) const;
402  /// Returns the SIM_DopDescription from the SIM_DataFactory of a
403  /// particular data type.
404  const SIM_DopDescription *getDopDescription(
405  const UT_StringRef &datatype) const;
406 
407  /// Returns whether we can cast to a superclass data type without creating
408  /// the SIM_Data.
409  static bool canCastToDataType(
410  const UT_StringRef &from_type,
411  const UT_StringRef &to_type);
412 
413  /// Filters all our simulation objects based on a string pattern.
414  /// Note that the time value is a simulation time, not global time.
415  void findAllObjectsFromString(const char *objspec,
416  SIM_ConstObjectArray &objects,
417  const SIM_Time &t,
418  bool interpolateobj) const;
419  /// Returns a single object matching a specified string pattern.
420  /// Note that the time value is a simulation time, not global time.
421  const SIM_Object *findObjectFromString(const char *objspec,
422  int whichmatch, int *nummatch,
423  const SIM_Time &t,
424  bool interpolateobj) const;
425  /// Returns a list of objects created by the specified node, or any
426  /// nodes inside the specified node (if it is a subnet).
427  void findAllObjectsCreatedBy(OP_Node *creator,
428  SIM_ConstObjectArray &objects) const;
429  /// Filters all our relationships based on a string pattern.
430  /// Note that the time value is a simulation time, not global time.
431  void findAllRelationshipsFromString(
432  const char *relspec,
433  SIM_ConstDataArray &relationships,
434  const SIM_Time &t,
435  bool interpolaterel) const;
436  /// Returns a single relationship matching a specified string pattern.
437  /// Note that the time value is a simulation time, not global time.
438  const SIM_Relationship *findRelationshipFromString(
439  const char *relspec,
440  int whichmatch, int *nummatch,
441  const SIM_Time &t,
442  bool interpolaterel) const;
443 
444  /// Gets a list of all selected data in the simulation.
445  void getSelection(SIM_ConstDataArray &data) const;
446  /// Clears the selection flag on all data in this simulation.
447  void clearSelection() const;
448 
449  /// Returns the scale factor to convert a value in the provided units
450  /// into the equivalent MKS value.
451  fpreal scaleToMKS(const char *fromunits) const;
452  /// Returns the scale factor to convert a value in MKS units into the
453  /// equivalent value in the provided units.
454  fpreal scaleFromMKS(const char *tounits) const;
455 
456  /// The micronode representing the simulation result. It is marked as
457  /// dirtied and propagated whenever the simulation is cleared. Callers can
458  /// use this to express dependencies on/from the simulation.
460  { return mySimMicroNode; }
461  const DEP_MicroNode & simMicroNode() const
462  { return mySimMicroNode; }
463  /// This micronode holds the simulation input. It is wired directly
464  /// to the simMicroNode, however, does not care about refilter
465  /// events.
467  { return mySimInputMicroNode; }
469  { return mySimInputMicroNode; }
471  { return myResimParmsMicroNode; }
473  { return myResimParmsMicroNode; }
475  { return myRefilterParmsMicroNode; }
477  { return myRefilterParmsMicroNode; }
478 
479  /// Fetch all the nodes in which this simulation has an interest. This
480  /// method can get the normal node interests, guide geometry interests,
481  /// or both.
482  void getExtraInterests(OP_NodeList &extras, bool normal, bool guides) const;
483 
484  /// Sets this simulation as a player. It will replace it's cache
485  /// with simulation data from the files given and not simulate,
486  /// just read the files.
487  void setIsPlayer(bool isPlayer);
488  bool isPlayer() const { return myIsPlayer; }
489 
490  /// Rebuilds the player cache.
491  void resetPlayer();
492  /// Tries to expand the cached frame range
493  void updatePlayerFrames();
494 
495  /// Unique id that is bumped whenever the simulation is reset or a frame is
496  /// resimulated.
497  int64 getModVersion() const { return myModVersion; }
498 
499 protected:
500  /// Resets the simulation to a clean state. This function calls
501  /// clearSimulation(), then builds a single empty simulation state.
502  virtual void resetSimulation();
503  /// This function is run before passing each object to its solver.
504  /// The implementation at this level clears out all temporary data
505  /// from the simulation objects.
506  virtual void preSimulationStep();
507  /// This function is run after all objects are processed by their solvers.
508  virtual void postSimulationStep();
509  /// This function is called by our cache whenever the most recent
510  /// simulated timestep is being removed from memory (either deleted
511  /// or moved onto disk).
512  virtual void clearReferencesToMostRecentState();
513  /// Initializes a newly created object. This function is called by
514  /// addSimulationObject(). The default implementation does nothing.
515  virtual void objectCreated(SIM_Object *object);
516  /// Allows special handling of objects that are being removed. This
517  /// function is called by removeSimulationObject(). The default
518  /// implementation does nothing.
519  virtual void objectRemoved(SIM_Object *object);
520  /// Override this method to handle changes to external nodes in which
521  /// we have an interest. The default implementation does nothing.
522  virtual void handleExternalNodeChangeSubclass(
523  OP_Node *changednode,
524  OP_EventType eventtype,
525  void *data,
526  bool isguide);
527  /// The default implementation of this function does nothing.
528  virtual void addErrorSubclass(const SIM_RootData *rootdata,
529  const SIM_Data *data,
530  int errorcode,
531  const char *errorparm,
532  UT_ErrorSeverity severity) const;
533  virtual void resetErrorsSubclass();
534  /// Returns the simulation time that corresponds to the given global time.
535  virtual const SIM_Time getEngineTimeSubclass(const SIM_Time &t) const;
536  /// Returns the global time that corresponds to the given simulation time.
537  virtual const SIM_Time getGlobalTimeSubclass(const SIM_Time &t) const;
538  /// This function is the only way for a SIM_Engine subclass to get a
539  /// non-const SIM_Object pointer.
540  SIM_Object *getNonConstSimulationObject(int index);
541 
542  /// Alerts our owner that we are simulating due to an internally
543  /// generated need. Returns the previous state
544  virtual bool setIsSimulating(bool issimulating) const;
545 
546 private:
547  /// Gets the unique id of the OP_Node that owns this engine.
548  int getOwnerUniqueId() const;
549  /// Completely clears all existing data related to a simulation.
550  /// This will still reset to ensure the simulation has one good frame.
551  void clearSimulation();
552  /// Completely clears all existing data for the simulation and
553  /// does not attempt to reset. It will have no good frames and
554  /// this should only be used in the destructor path.
555  void clearSimulationForDestruction();
556  /// Takes one time step forward in the simulation.
557  void doSimulationStep(bool forreset);
558  /// Solves a meta object for one time step. All affectors will already
559  /// be solved.
560  void doSimulationStepForMetaObject(
561  SIM_MetaObject &metaobject,
562  const SIM_Time &timestep,
563  bool isLastMetaObject);
564  /// Merges another simulation state in with our current state. This
565  /// state can come from a file or another live simulation.
566  void mergeSimulation(
567  SIM_SimulationState &fromstate,
568  const SIM_DataFilter *filter,
569  const SIM_ObjectArray *replaceobjects,
570  bool acceptnewobjects,
571  bool matchbyname,
572  const char *nameprefix);
573 
574  /// Solves a relationship for one timestep. All objects will
575  /// already be solved.
576  void solveRelationship(SIM_Relationship *relation,
577  const SIM_Time &timestep);
578 
579  /// Gets the current simulation state. Notably, it returns non-const.
580  /// It is quite questionable to use this non-const function in
581  /// solvers! One should acquire non-const SIM_Objects through
582  /// your affector lists or other ways.
583  SIM_SimulationState &getSimulationObjects();
584  /// Gets a const reference to the current simulation state.
585  const SIM_SimulationState &getSimulationObjects() const;
586 
587  SIM_Object *getNonConstSimulationObjectFromId(
588  int objectid);
589  SIM_Relationship *getNonConstRelationship(const char *name);
590  SIM_Relationship *getNonConstRelationshipFromIndex(int index);
591 
592  /// Returns the SIM_Data pointer with the specified unique id.
593  SIM_Data *getDataWithId(const UT_Guid &id) const;
594  /// Destroy any data that has a zero reference count.
595  void purgeUnusedData() const;
596 
597  /// Register a new piece of data with the engine. This is
598  /// called from the SIM_DataFactory newData function to add
599  /// the data to myAllData and myAllChangedSizeData.
600  void registerNewData(SIM_Data *newdata) const;
601  /// Create data using our factories.
602  /// Only SIM_Data should use this functions.
603  SIM_Data *newData(const UT_StringRef &datatype,
604  bool doinit=true) const;
605  /// Create data using our factories, and set the uniqueid of the new data.
606  /// Only SIM_SimulationState should use this functions.
607  SIM_Data *newData(const UT_StringRef &datatype,
608  const UT_Guid &uniqueid) const;
609  /// Unregister a piece of data that is being deleted. This is
610  /// called from the SIM_DataFactory deleteData function to remove
611  /// the data from myAllData and myAllChangedSizeData.
612  void unregisterDeletedData(SIM_Data *deleteddata) const;
613  /// Delete data using our factories.
614  /// Only SIM_Data should use this functions.
615  void deleteData(SIM_Data *data) const;
616  /// This function is called when the unique id of a SIM_Data changes.
617  /// It lets us keep the myAllData hash table up to date.
618  void changeDataUniqueId(SIM_Data *data,
619  const UT_Guid &newid) const;
620  /// This function is called when a piece of data has decided it needs
621  /// to recalculate its memory size.
622  void setNeedsToRecalculateMemorySize(
623  const SIM_Data *data) const;
624 
625  /// Access our data factories.
626  SIM_DataFactory *getDataFactory(const UT_StringRef &name) const;
627  void addDataFactory(SIM_DataFactory *factory);
628 
629  /// This function is called when an external node in which we have an
630  /// interest changes. It calls handleExternalNodeChangeSubclass.
631  void handleExternalNodeChange(OP_Node *changednode,
632  OP_EventType eventtype,
633  void *data,
634  bool isguide);
635  /// This static version of handleExternalNodeChange converts the callee
636  /// pointer to a SIM_Engine pointer and calls handleExternalNodeChange
637  /// on that engine.
638  static void handleExternalNodeChange(OP_Node *changednode,
639  void *callee,
640  OP_EventType eventtype,
641  void *data);
642  static void handleExternalGuideNodeChange(OP_Node *changednode,
643  void *callee,
644  OP_EventType eventtype,
645  void *data);
646 
647  /// Clears all the active solve info attached to this engine.
648  void clearAllSolveInfo();
649 
650  /// Adds a SIM_DataFactoryCreator to the global list.
651  static void addDataFactoryCreator(SIM_DataFactoryCreator *creator);
652  /// Removes a SIM_DataFactoryCreator from the global list.
653  static void removeDataFactoryCreator(SIM_DataFactoryCreator *creator);
654  /// Returns the global list of data factory creators.
655  static UT_Array<SIM_DataFactoryCreator *> &getCreators();
656 
658  SIM_Cache myCache;
659  SIM_BaseCache *myBaseCache;
660  SIM_Time myTimeStep;
661  OP_Node *myOwner;
662  int myMaxFeedbackIterations;
663  int myFeedbackIteration;
664  int myCurrentCreatorId;
665  int myCurrentCreatorIndex;
666  mutable UT_String myOwnerFullPath;
667  mutable UT_Array<SIM_SaveCommand *> mySaveCommands;
668  mutable UT_Map<UT_Guid, SIM_Data *> myAllData;
669  mutable UT_Set<const SIM_Data *> myAllChangedSizeData;
670  mutable UT_Set<OP_Node *> myOPInterestNodes;
671  mutable UT_Set<OP_Node *> myGuideOPInterestNodes;
672  mutable int64 myTotalMemorySize;
673  bool myProvideDataHints;
674  bool myFirstSimulationStep;
675  bool myLastCookInterrupted;
676  int64 myModVersion;
677  mutable SIM_ObjectSolveInfoArray mySolveInfo;
678  mutable bool myClearingSolveInfos;
679 
680  friend class SIM_Data;
681  friend class SIM_DataFactory;
683  friend class SIM_SimulationState;
684  friend class SIM_SaveCommand;
685  friend class SIM_BaseCache;
686  friend class SIM_Cache;
687 
688  friend class SIM_ObjectSolveInfo;
689 
690 protected:
696 
697 };
698 
699 #endif
DEP_MicroNode & refilterParmsMicroNode()
Definition: SIM_Engine.h:474
DEP_MicroNode myResimParmsMicroNode
Definition: SIM_Engine.h:693
PXL_API const char * getDescription(const ColorSpace *space)
Return the description of the color space.
GT_API const UT_StringHolder filename
virtual void becameDirty(DEP_MicroNode &src, const DEP_PropagateData &propdata)
GT_API const UT_StringHolder time
DEP_MicroNode & resimParmsMicroNode()
Definition: SIM_Engine.h:470
const char * className() const override
Definition: SIM_Engine.h:51
bool myIsPlayer
Definition: SIM_Engine.h:695
int64 exint
Definition: SYS_Types.h:125
UT_ErrorSeverity
Definition: UT_Error.h:25
virtual void notifySimulationChangeSinksOfChange()
Definition: SIM_Engine.h:376
A reference counter base class for use with UT_IntrusivePtr.
int getCurrentCreatorId() const
Gets the id for the node that is currently being processed.
Definition: SIM_Engine.h:328
Holds pointers to a number of SIM_Relationships.
UT_IntrusiveRefCounter & operator=(const UT_IntrusiveRefCounter &) noexcept
Assignment operator: Does not modify counter.
void resetToFirstSimulationStep()
Definition: SIM_Engine.h:290
GLdouble n
Definition: glcorearb.h:2008
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
SIM_SimulationMicroNode mySimInputMicroNode
Definition: SIM_Engine.h:691
DEP_MicroNode & simInputMicroNode()
Definition: SIM_Engine.h:466
Holds pointers to a number of SIM_Object objects.
long long int64
Definition: SYS_Types.h:116
int64 getModVersion() const
Definition: SIM_Engine.h:497
GLenum GLenum severity
Definition: glcorearb.h:2539
OP_DopParentMicroNode mySimMicroNode
Definition: SIM_Engine.h:692
GLuint const GLchar * name
Definition: glcorearb.h:786
DEP_MicroNode myRefilterParmsMicroNode
Definition: SIM_Engine.h:694
Holds pointers to a number of const SIM_Object objects.
GLdouble t
Definition: glad.h:2397
SIM_Engine & myEngine
Definition: SIM_Engine.h:58
bool hasOPInterest(OP_Node *node) const
Returns whether there is an explicit interest on the node.
Definition: SIM_Engine.h:371
const DEP_MicroNode & refilterParmsMicroNode() const
Definition: SIM_Engine.h:476
const DEP_MicroNode & resimParmsMicroNode() const
Definition: SIM_Engine.h:472
fpreal64 fpreal
Definition: SYS_Types.h:278
UT_CompressionType
bool isPlayer() const
Definition: SIM_Engine.h:488
GLuint index
Definition: glcorearb.h:786
#define SIM_API
Definition: SIM_API.h:12
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
OP_EventType
Definition: OP_Value.h:22
Propagation info for a dep micro node.
Definition: DEP_MicroNode.h:36
This class stores all the caching options used by the SIM_Cache.
int getCurrentCreatorIndex() const
Gets the index of the node output that is currently being processed.
Definition: SIM_Engine.h:331
const DEP_MicroNode & simInputMicroNode() const
Definition: SIM_Engine.h:468
DEP_MicroNode & simMicroNode()
Definition: SIM_Engine.h:459
Definition: format.h:1821
const DEP_MicroNode & simMicroNode() const
Definition: SIM_Engine.h:461
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
GLenum src
Definition: glcorearb.h:1793