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