HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Cache Class Reference

#include <SIM_Cache.h>

Public Member Functions

 SIM_Cache ()
 
 ~SIM_Cache ()
 Destructor destroys all objects and temp files. More...
 
void setEngine (SIM_Engine *engine)
 
const SIM_CacheOptionsgetCacheOptions () const
 Returns a reference to our caching option data. More...
 
void setCacheOptions (const SIM_CacheOptions &src)
 Sets the cache options. More...
 
void cacheAndAdvance ()
 
void setCurrentTime (const SIM_Time &time)
 
bool deleteAfterTime (const SIM_Time &time)
 
void clear ()
 
void clearForDestruction ()
 
void preload ()
 
const SIM_TimegetCurrentTime () const
 
const SIM_TimegetEarliestTime () const
 
const SIM_TimegetLatestTime () const
 
SIM_SimulationState & getCurrentSimulationObjects () const
 
void getCachedFrames (UT_Array< int > &frames, bool memory) const
 Returns the live cached frames. More...
 
const SIM_ObjectgetObjectAtTime (const SIM_Object &object, const SIM_Time &time, bool allowinterpolation)
 
SIM_ObjectgetAffectorAtTime (SIM_Object &object, const SIM_Time &time, bool allowinterpolation)
 
int getObjectsAtPastTimes (const SIM_Object **const past_objects[], SIM_Time past_times[], const int num_objects, const SIM_Object *const objects[], const int max_past)
 
int getRelationshipsAtPastTimes (const SIM_Relationship **const past_rels[], SIM_Time past_times[], const int num_rels, const SIM_Relationship *const rels[], const int max_past)
 Equivalent of getObjectsAtPastTimes() for relationships. More...
 
SIM_ObjectcreateSubStepObject (const SIM_Object &object, const SIM_Time &time)
 
void clearInterpolatedObjects (const SIM_ObjectArray &objects)
 
void postSimulationStep ()
 

Detailed Description

This class is the cache for a SIM_Engine. It holds all the actual objects for the simulation for the entire cached time range.

Definition at line 26 of file SIM_Cache.h.

Constructor & Destructor Documentation

SIM_Cache::SIM_Cache ( )

Constructor intializes this class with no object data. A single cache entry is created to hold any new objects.

SIM_Cache::~SIM_Cache ( )

Destructor destroys all objects and temp files.

Member Function Documentation

void SIM_Cache::cacheAndAdvance ( )

Caches the current object data and advances by one time step. Basically this consists of creating a copy of all objects in the simulation and setting the new current time. If the cache size is exceeded, a cache entry will be deleted. A cache entry may also get pushed to disk. If caching is disabled, this function does nothing except advance the current time.

void SIM_Cache::clear ( )

Clears all cache entries. A single empty cache entry is then created to act as the current entry to shich new objects may be added.

void SIM_Cache::clearForDestruction ( )

Clears all cache entries. Does not create a cache entry to act as a current entry, so the state is invalid and this should be shortly deleted.

void SIM_Cache::clearInterpolatedObjects ( const SIM_ObjectArray objects)

Deletes any objects from the myInterpolatedObjects array that match the provided object id. This function is called by the engine just prior to solving the object. The idea is that the object may have been used to create an interpolated object prior to its solve for a given timestep. After its solve, all the interpolation is incorrect, so leaving the interpolated objects around is potentially misleading and harmful.

SIM_Object* SIM_Cache::createSubStepObject ( const SIM_Object object,
const SIM_Time time 
)

Returns a substep version of the specified object. The substep object is always created within the current simulation state regardless of the time value. The reason the SIM_Cache is used as an intermediary here is so that if we already have an interpolated version of the object at the requested time, we can convert the interpolated object into a substep (which is really different only in the sense of whether the SIM_Cache or the SIM_SimulationState owns it).

bool SIM_Cache::deleteAfterTime ( const SIM_Time time)

Deletes all cache entries after the specified time. The cache entry for the specified time itself is also deleted. The cache is moved to the entry just prior to the earliest deleted entry. If there is insufficient cache to fulfil the request, then nothing is changed and the function returns false. Otherwise it returns true.

SIM_Object* SIM_Cache::getAffectorAtTime ( SIM_Object object,
const SIM_Time time,
bool  allowinterpolation 
)

Returns a non-const object from the specified earlier time. The returned value is always a pointer to the passed in object, or a substep object. If a time in some earlier timestep is specified, the earlier object is copied as a substep object of the current time. Otheriwse this function could be used to modify the past.

void SIM_Cache::getCachedFrames ( UT_Array< int > &  frames,
bool  memory 
) const

Returns the live cached frames.

const SIM_CacheOptions& SIM_Cache::getCacheOptions ( ) const

Returns a reference to our caching option data.

SIM_SimulationState& SIM_Cache::getCurrentSimulationObjects ( ) const

Returns the objects that belong to the current cache entry. This function is called by the SIM_Engine getSimulationObject() and related functions.

const SIM_Time& SIM_Cache::getCurrentTime ( ) const

Returns the time of the current cache entry. This function is called by the SIM_Engine::getSimulationTime() function.

const SIM_Time& SIM_Cache::getEarliestTime ( ) const

Returns the time of the earliest cache entry. This function is called by the SIM_Engine::getEarliestCacheTime() function.

const SIM_Time& SIM_Cache::getLatestTime ( ) const
const SIM_Object* SIM_Cache::getObjectAtTime ( const SIM_Object object,
const SIM_Time time,
bool  allowinterpolation 
)

Returns the specified object at an earlier time step. If the object at the exact specified time cannot be found, we create a new object by interpolating between the previous and next available states of the object.

int SIM_Cache::getObjectsAtPastTimes ( const SIM_Object **const  past_objects[],
SIM_Time  past_times[],
const int  num_objects,
const SIM_Object *const  objects[],
const int  max_past 
)

Before the call, 'past_objects' must be a valid array of valid arrays, and 'past_times' must be a valid array. 'past_objects' must have size 'max_past' each element of 'past_objects' must be an array of SIM_Object* of size 'num_objects' 'past_times' must be an array of size 'max_past'

Output: The number of cached frames is returned. The cached version of object[oi] at time past_times[i] is stored in the array past_objects[i] at location oi, for all 0 <= i < "the returned number of cached frames"

int SIM_Cache::getRelationshipsAtPastTimes ( const SIM_Relationship **const  past_rels[],
SIM_Time  past_times[],
const int  num_rels,
const SIM_Relationship *const  rels[],
const int  max_past 
)

Equivalent of getObjectsAtPastTimes() for relationships.

void SIM_Cache::postSimulationStep ( )

This performs the cleanup required after performing a simulation step. All temporary interpolated objects are deleted, and any excess cache entries in memory are flushed to disk.

void SIM_Cache::preload ( )

Attempts to re-load explicit cache entries from the last loaded etnry

void SIM_Cache::setCacheOptions ( const SIM_CacheOptions src)

Sets the cache options.

void SIM_Cache::setCurrentTime ( const SIM_Time time)

Tells the cache to move to a new current time. Whatever cache entry is the best match for the specfied time will be made the current cache entry. If the new time is earlier than any cache entry, then the earliest cache entry is used. If the new time is later than the latest cache entry, the last entry is used. Note that this means the cache's current time won't necessarily be set to the requested value. It is up to the SIM_Engine to perform simulation steps to get to the actual desired time.

void SIM_Cache::setEngine ( SIM_Engine engine)

Initialize this object with a SIM_Engine pointer. This must be done as soon as the SIM_Cache is created.


The documentation for this class was generated from the following file: