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  bool solvecurrentframe = false);
253  /// Schedules some objects to be saved to a files at the end of the
254  /// current timestep. The filter parameter makes it possible to save
255  /// only some of the objects to the file. The actual save happens
256  /// in the postSimulationStep().
257  void saveSimulationFile(OP_Node *node,
258  const char *filename,
259  const SIM_DataFilter &filter,
260  const SIM_ObjectArray &objects,
262  /// Saves the entire current state of the simulation immediately.
263  bool saveSimulationState(std::ostream &os,
265  bool saveSimulationStateToFile(const char *fname,
267  bool threadedio) const;
268 
269  /// Sets the current time for the simulation. If the new simulation
270  /// time is less than the current time, the SIM_Cache is simply set to
271  /// use its best match for the chosen time. If the new simulation time
272  /// is greater than the current time, the simulation is stepped forward
273  /// in time to the new time. The resimlasttimestep parameter causes the
274  /// most recent cache entry to be deleted before trying to set the
275  /// current time. This is useful if some parameter of the simulation
276  /// changes on the current timestep. It causes the timestep to be
277  /// recooked with the new parameter. This resimulation may also happen
278  /// if the simulation was interrupted the last time this function was
279  /// called. The forceresetsim parameter tells the SIM_Engine to reset
280  /// the simulation before trying to move to the specified time, whether
281  /// the reset is required or not.
282  void setSimulationTime(const SIM_Time &t,
283  bool resimlasttimestep,
284  bool forceresetsim,
285  bool allowsimulation);
286 
287  /// Marks this engine as invalid without actually clearing or
288  /// resetting anything. A proper reset implies also a frame
289  /// advance to the first frame that can be expensive.
290  /// Note the cache will not be cleared until it is cooked, however!
292  { myFirstSimulationStep = true; }
293 
294  /// Returns the current simulation time.
295  const SIM_Time &getSimulationTime() const;
296  /// Returns the simulation time that corresponds to the given global time.
297  const SIM_Time getEngineTime(const SIM_Time &t) const;
298  /// Returns the global time that corresponds to the given simulation time.
299  const SIM_Time getGlobalTime(const SIM_Time &t) const;
300  /// Returns the time of the earliest simulation state in the cache.
301  const SIM_Time &getEarliestCacheTime() const;
302  const SIM_Time &getLatestCacheTime() const;
303  /// Returns the cached frames.
304  /// Inclusive.
305  void getCachedFrames(UT_Array<int> &frames,
306  bool inmemory) const;
307  /// Returns if a frame is cached.
308  bool isFrameCached(exint frame) const;
309  /// Returns a reference to the cache options for this simulation.
310  const SIM_CacheOptions &getCacheOptions() const;
311  /// Sets the cache options for this simulation.
312  void setCacheOptions(const SIM_CacheOptions &o);
313  /// Returns the time step size.
314  const SIM_Time &getTimeStep() const;
315  /// Sets the global time step size.
316  void setTimeStep(const SIM_Time &time);
317  /// Gets the maximum number of allowed feedback iterations.
318  int getMaxFeedbackIterations() const;
319  /// Sets the maximum number of allowed feedback iterations.
320  void setMaxFeedbackIterations(int max);
321  /// Gets the current feedback iteration we are on. If we are not
322  /// currently solving, this function will return -1;
323  int getFeedbackIteration() const;
324  /// Returns true if the engine is providing data hierarchy hints.
325  bool getProvideDataHints() const;
326  /// Specifies whether the engine should provide data hierarchy hints.
327  void setProvideDataHints(bool providehints);
328  /// Gets the id for the node that is currently being processed.
330  { return myCurrentCreatorId; }
331  /// Gets the index of the node output that is currently being processed.
333  { return myCurrentCreatorIndex; }
334  /// Set the creator information. These values are automatically reset
335  /// to (-1, -1) before performing a simulation step.
336  void setCreatorInfo(int id, int index);
337  /// Returns the SIM_Data pointer with the specified unique id.
338  const SIM_Data *getConstDataWithId(const UT_Guid &id) const;
339  /// Returns the simulation frame number that corresponds to the given
340  /// time. The simulation frame number is the number of timesteps that
341  /// need to be run to get to the specified time, plus one (so that
342  /// time zero is frame 1).
343  int getSimulationFrame(const SIM_Time &time) const;
344  /// Returns the simulation time that corresponds to the given simulation
345  /// frame.
346  const SIM_Time getSimulationTime(int frame) const;
347 
348  /// Adds an error to the engine. The object and data parameters allow
349  /// the DOP_Engine to put the error message on an appropriate DOP Node.
350  /// Errors are found in the SIM error file. This function simply calls
351  /// addErrorSubclass().
352  void addError(const SIM_RootData *rootdata,
353  const SIM_Data *data,
354  int errorcode,
355  const char *errorparm,
356  UT_ErrorSeverity severity) const;
357  /// Resets the errors stored in the simulation.
358  void resetErrors();
359 
360  /// Returns the total amount of memory used by all data currently in
361  /// this simulation, at the current time or in the cache.
362  int64 getTotalMemorySize() const;
363 
364  /// Removes all node interests from the engine.
365  void removeAllOPInterests() const;
366  /// Adds an interest in the supplied node. When the node changes, the
367  /// engine's handleExternalNodeChange function will be called.
368  void addOPInterest(OP_Node *node) const;
369  void addGuideOPInterest(OP_Node *node) const;
370 
371  /// Returns whether there is an explicit interest on the node.
372  bool hasOPInterest(OP_Node *node) const
373  { return myOPInterestNodes.contains(node); }
374 
375  /// Passes up to our owner to alert anything that needs an OP_Event
376  /// in response to use becoming dirty.
378 
379  /// Returns all available data type names.
380  /// If a null type pointer is passed in, this function returns a list
381  /// of every data type that the SIM_Engine can create. If a data type
382  /// name is passed in, the list returned will only contain those data
383  /// types that can be cast to the specified data type using the
384  /// SIM_Data::getPointerToType() function.
385  void getDataTypes(UT_StringArray &datatypes,
386  const UT_StringRef &datatype) const;
387  /// Returns a list of the superclass names for the specified data type.
388  void getDataTypeSuperclasses(
389  const UT_StringRef &datatype,
390  UT_StringArray &classes) const;
391  /// Returns all available data types and the source of their definition.
392  /// The definition source will be an empty string if the data type is
393  /// defined internally to Houdini. Otherwise it will be the name of the
394  /// DSO or DLL file that contains the data type.
395  void getDataTypeSources(UT_StringArray &datatypes,
396  UT_StringArray &srcs) const;
397  /// Returns the descriptive name for a data type.
398  /// Given the unique identifying name for a data type this function
399  /// finds the appropriate data factory and returns the descriptive
400  /// string assigned to the type.
401  const char *getDescription(
402  const UT_StringRef &datatype) const;
403  /// Returns the SIM_DopDescription from the SIM_DataFactory of a
404  /// particular data type.
405  const SIM_DopDescription *getDopDescription(
406  const UT_StringRef &datatype) const;
407 
408  /// Returns whether we can cast to a superclass data type without creating
409  /// the SIM_Data.
410  static bool canCastToDataType(
411  const UT_StringRef &from_type,
412  const UT_StringRef &to_type);
413 
414  /// Filters all our simulation objects based on a string pattern.
415  /// Note that the time value is a simulation time, not global time.
416  void findAllObjectsFromString(const char *objspec,
417  SIM_ConstObjectArray &objects,
418  const SIM_Time &t,
419  bool interpolateobj) const;
420  /// Returns a single object matching a specified string pattern.
421  /// Note that the time value is a simulation time, not global time.
422  const SIM_Object *findObjectFromString(const char *objspec,
423  int whichmatch, int *nummatch,
424  const SIM_Time &t,
425  bool interpolateobj) const;
426  /// Returns a list of objects created by the specified node, or any
427  /// nodes inside the specified node (if it is a subnet).
428  void findAllObjectsCreatedBy(OP_Node *creator,
429  SIM_ConstObjectArray &objects) const;
430  /// Filters all our relationships based on a string pattern.
431  /// Note that the time value is a simulation time, not global time.
432  void findAllRelationshipsFromString(
433  const char *relspec,
434  SIM_ConstDataArray &relationships,
435  const SIM_Time &t,
436  bool interpolaterel) const;
437  /// Returns a single relationship matching a specified string pattern.
438  /// Note that the time value is a simulation time, not global time.
439  const SIM_Relationship *findRelationshipFromString(
440  const char *relspec,
441  int whichmatch, int *nummatch,
442  const SIM_Time &t,
443  bool interpolaterel) const;
444 
445  /// Gets a list of all selected data in the simulation.
446  void getSelection(SIM_ConstDataArray &data) const;
447  /// Clears the selection flag on all data in this simulation.
448  void clearSelection() const;
449 
450  /// Returns the scale factor to convert a value in the provided units
451  /// into the equivalent MKS value.
452  fpreal scaleToMKS(const char *fromunits) const;
453  /// Returns the scale factor to convert a value in MKS units into the
454  /// equivalent value in the provided units.
455  fpreal scaleFromMKS(const char *tounits) const;
456 
457  /// The micronode representing the simulation result. It is marked as
458  /// dirtied and propagated whenever the simulation is cleared. Callers can
459  /// use this to express dependencies on/from the simulation.
461  { return mySimMicroNode; }
462  const DEP_MicroNode & simMicroNode() const
463  { return mySimMicroNode; }
464  /// This micronode holds the simulation input. It is wired directly
465  /// to the simMicroNode, however, does not care about refilter
466  /// events.
468  { return mySimInputMicroNode; }
470  { return mySimInputMicroNode; }
472  { return myResimParmsMicroNode; }
474  { return myResimParmsMicroNode; }
476  { return myRefilterParmsMicroNode; }
478  { return myRefilterParmsMicroNode; }
479 
480  /// Fetch all the nodes in which this simulation has an interest. This
481  /// method can get the normal node interests, guide geometry interests,
482  /// or both.
483  void getExtraInterests(OP_NodeList &extras, bool normal, bool guides) const;
484 
485  /// Sets this simulation as a player. It will replace it's cache
486  /// with simulation data from the files given and not simulate,
487  /// just read the files.
488  void setIsPlayer(bool isPlayer);
489  bool isPlayer() const { return myIsPlayer; }
490 
491  /// Rebuilds the player cache.
492  void resetPlayer();
493  /// Tries to expand the cached frame range
494  void updatePlayerFrames();
495 
496  /// Unique id that is bumped whenever the simulation is reset or a frame is
497  /// resimulated.
498  int64 getModVersion() const { return myModVersion; }
499 
500 protected:
501  /// Resets the simulation to a clean state. This function calls
502  /// clearSimulation(), then builds a single empty simulation state.
503  virtual void resetSimulation();
504  /// This function is run before passing each object to its solver.
505  /// The implementation at this level clears out all temporary data
506  /// from the simulation objects.
507  virtual void preSimulationStep();
508  /// This function is run after all objects are processed by their solvers.
509  virtual void postSimulationStep();
510  /// This function is called by our cache whenever the most recent
511  /// simulated timestep is being removed from memory (either deleted
512  /// or moved onto disk).
513  virtual void clearReferencesToMostRecentState();
514  /// Initializes a newly created object. This function is called by
515  /// addSimulationObject(). The default implementation does nothing.
516  virtual void objectCreated(SIM_Object *object);
517  /// Allows special handling of objects that are being removed. This
518  /// function is called by removeSimulationObject(). The default
519  /// implementation does nothing.
520  virtual void objectRemoved(SIM_Object *object);
521  /// Override this method to handle changes to external nodes in which
522  /// we have an interest. The default implementation does nothing.
523  virtual void handleExternalNodeChangeSubclass(
524  OP_Node *changednode,
525  OP_EventType eventtype,
526  void *data,
527  bool isguide);
528  /// The default implementation of this function does nothing.
529  virtual void addErrorSubclass(const SIM_RootData *rootdata,
530  const SIM_Data *data,
531  int errorcode,
532  const char *errorparm,
533  UT_ErrorSeverity severity) const;
534  virtual void resetErrorsSubclass();
535  /// Returns the simulation time that corresponds to the given global time.
536  virtual const SIM_Time getEngineTimeSubclass(const SIM_Time &t) const;
537  /// Returns the global time that corresponds to the given simulation time.
538  virtual const SIM_Time getGlobalTimeSubclass(const SIM_Time &t) const;
539  /// This function is the only way for a SIM_Engine subclass to get a
540  /// non-const SIM_Object pointer.
541  SIM_Object *getNonConstSimulationObject(int index);
542 
543  /// Alerts our owner that we are simulating due to an internally
544  /// generated need. Returns the previous state
545  virtual bool setIsSimulating(bool issimulating) const;
546 
547 private:
548  /// Gets the unique id of the OP_Node that owns this engine.
549  int getOwnerUniqueId() const;
550  /// Completely clears all existing data related to a simulation.
551  /// This will still reset to ensure the simulation has one good frame.
552  void clearSimulation();
553  /// Completely clears all existing data for the simulation and
554  /// does not attempt to reset. It will have no good frames and
555  /// this should only be used in the destructor path.
556  void clearSimulationForDestruction();
557  /// Takes one time step forward in the simulation.
558  void doSimulationStep(bool forreset);
559  /// Solves a meta object for one time step. All affectors will already
560  /// be solved.
561  void doSimulationStepForMetaObject(
562  SIM_MetaObject &metaobject,
563  const SIM_Time &timestep,
564  bool isLastMetaObject);
565  /// Merges another simulation state in with our current state. This
566  /// state can come from a file or another live simulation.
567  void mergeSimulation(
568  SIM_SimulationState &fromstate,
569  const SIM_DataFilter *filter,
570  const SIM_ObjectArray *replaceobjects,
571  bool acceptnewobjects,
572  bool matchbyname,
573  const char *nameprefix,
574  bool solvecurrentframe);
575 
576  /// Solves a relationship for one timestep. All objects will
577  /// already be solved.
578  void solveRelationship(SIM_Relationship *relation,
579  const SIM_Time &timestep);
580 
581  /// Gets the current simulation state. Notably, it returns non-const.
582  /// It is quite questionable to use this non-const function in
583  /// solvers! One should acquire non-const SIM_Objects through
584  /// your affector lists or other ways.
585  SIM_SimulationState &getSimulationObjects();
586  /// Gets a const reference to the current simulation state.
587  const SIM_SimulationState &getSimulationObjects() const;
588 
589  SIM_Object *getNonConstSimulationObjectFromId(
590  int objectid);
591  SIM_Relationship *getNonConstRelationship(const char *name);
592  SIM_Relationship *getNonConstRelationshipFromIndex(int index);
593 
594  /// Returns the SIM_Data pointer with the specified unique id.
595  SIM_Data *getDataWithId(const UT_Guid &id) const;
596  /// Destroy any data that has a zero reference count.
597  void purgeUnusedData() const;
598 
599  /// Register a new piece of data with the engine. This is
600  /// called from the SIM_DataFactory newData function to add
601  /// the data to myAllData and myAllChangedSizeData.
602  void registerNewData(SIM_Data *newdata) const;
603  /// Create data using our factories.
604  /// Only SIM_Data should use this functions.
605  SIM_Data *newData(const UT_StringRef &datatype,
606  bool doinit=true) const;
607  /// Create data using our factories, and set the uniqueid of the new data.
608  /// Only SIM_SimulationState should use this functions.
609  SIM_Data *newData(const UT_StringRef &datatype,
610  const UT_Guid &uniqueid) const;
611  /// Unregister a piece of data that is being deleted. This is
612  /// called from the SIM_DataFactory deleteData function to remove
613  /// the data from myAllData and myAllChangedSizeData.
614  void unregisterDeletedData(SIM_Data *deleteddata) const;
615  /// Delete data using our factories.
616  /// Only SIM_Data should use this functions.
617  void deleteData(SIM_Data *data) const;
618  /// This function is called when the unique id of a SIM_Data changes.
619  /// It lets us keep the myAllData hash table up to date.
620  void changeDataUniqueId(SIM_Data *data,
621  const UT_Guid &newid) const;
622  /// This function is called when a piece of data has decided it needs
623  /// to recalculate its memory size.
624  void setNeedsToRecalculateMemorySize(
625  const SIM_Data *data) const;
626 
627  /// Access our data factories.
628  SIM_DataFactory *getDataFactory(const UT_StringRef &name) const;
629  void addDataFactory(SIM_DataFactory *factory);
630 
631  /// This function is called when an external node in which we have an
632  /// interest changes. It calls handleExternalNodeChangeSubclass.
633  void handleExternalNodeChange(OP_Node *changednode,
634  OP_EventType eventtype,
635  void *data,
636  bool isguide);
637  /// This static version of handleExternalNodeChange converts the callee
638  /// pointer to a SIM_Engine pointer and calls handleExternalNodeChange
639  /// on that engine.
640  static void handleExternalNodeChange(OP_Node *changednode,
641  void *callee,
642  OP_EventType eventtype,
643  void *data);
644  static void handleExternalGuideNodeChange(OP_Node *changednode,
645  void *callee,
646  OP_EventType eventtype,
647  void *data);
648 
649  /// Clears all the active solve info attached to this engine.
650  void clearAllSolveInfo();
651 
652  /// Adds a SIM_DataFactoryCreator to the global list.
653  static void addDataFactoryCreator(SIM_DataFactoryCreator *creator);
654  /// Removes a SIM_DataFactoryCreator from the global list.
655  static void removeDataFactoryCreator(SIM_DataFactoryCreator *creator);
656  /// Returns the global list of data factory creators.
657  static UT_Array<SIM_DataFactoryCreator *> &getCreators();
658 
660  SIM_Cache myCache;
661  SIM_BaseCache *myBaseCache;
662  SIM_Time myTimeStep;
663  OP_Node *myOwner;
664  int myMaxFeedbackIterations;
665  int myFeedbackIteration;
666  int myCurrentCreatorId;
667  int myCurrentCreatorIndex;
668  mutable UT_String myOwnerFullPath;
669  mutable UT_Array<SIM_SaveCommand *> mySaveCommands;
670  mutable UT_Map<UT_Guid, SIM_Data *> myAllData;
671  mutable UT_Set<const SIM_Data *> myAllChangedSizeData;
672  mutable UT_Set<OP_Node *> myOPInterestNodes;
673  mutable UT_Set<OP_Node *> myGuideOPInterestNodes;
674  mutable int64 myTotalMemorySize;
675  bool myProvideDataHints;
676  bool myFirstSimulationStep;
677  bool myLastCookInterrupted;
678  int64 myModVersion;
679  mutable SIM_ObjectSolveInfoArray mySolveInfo;
680  mutable bool myClearingSolveInfos;
681 
682  friend class SIM_Data;
683  friend class SIM_DataFactory;
685  friend class SIM_SimulationState;
686  friend class SIM_SaveCommand;
687  friend class SIM_BaseCache;
688  friend class SIM_Cache;
689 
690  friend class SIM_ObjectSolveInfo;
691 
692 protected:
698 
699 };
700 
701 #endif
DEP_MicroNode & refilterParmsMicroNode()
Definition: SIM_Engine.h:475
DEP_MicroNode myResimParmsMicroNode
Definition: SIM_Engine.h:695
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:471
const char * className() const override
Definition: SIM_Engine.h:51
bool myIsPlayer
Definition: SIM_Engine.h:697
int64 exint
Definition: SYS_Types.h:125
UT_ErrorSeverity
Definition: UT_Error.h:25
virtual void notifySimulationChangeSinksOfChange()
Definition: SIM_Engine.h:377
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:329
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:291
GLdouble n
Definition: glcorearb.h:2008
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
SIM_SimulationMicroNode mySimInputMicroNode
Definition: SIM_Engine.h:693
DEP_MicroNode & simInputMicroNode()
Definition: SIM_Engine.h:467
Holds pointers to a number of SIM_Object objects.
long long int64
Definition: SYS_Types.h:116
int64 getModVersion() const
Definition: SIM_Engine.h:498
GLenum GLenum severity
Definition: glcorearb.h:2539
OP_DopParentMicroNode mySimMicroNode
Definition: SIM_Engine.h:694
GLuint const GLchar * name
Definition: glcorearb.h:786
DEP_MicroNode myRefilterParmsMicroNode
Definition: SIM_Engine.h:696
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:372
const DEP_MicroNode & refilterParmsMicroNode() const
Definition: SIM_Engine.h:477
const DEP_MicroNode & resimParmsMicroNode() const
Definition: SIM_Engine.h:473
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_CompressionType
bool isPlayer() const
Definition: SIM_Engine.h:489
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:332
const DEP_MicroNode & simInputMicroNode() const
Definition: SIM_Engine.h:469
DEP_MicroNode & simMicroNode()
Definition: SIM_Engine.h:460
Definition: format.h:1821
const DEP_MicroNode & simMicroNode() const
Definition: SIM_Engine.h:462
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
GLenum src
Definition: glcorearb.h:1793