com.vwp.j3d.loaders
Class DataCache

java.lang.Object
  extended by com.vwp.j3d.loaders.DataCache

public class DataCache
extends Object

This class can be used to cache objects. It can be used by the Objects 3D model loader classes e.g. to cache textures. So in case more 3D models are used which use same textures, the DataCache prevents the loader from donwloading them again. Every time an object is fetched from this DataCache, it is exchanged with the preceding object. That means, a special order is build in the underlying Vector automatically. In case the Vector is full, the upper half of it will be released and so only objects are removed which aren't fetched very often. This optimizes the caching efficiency.


Field Summary
static int MODE_FIFO
          Specifies the caching and sorting mode for the data, in MODE_FIFO the data put into the cache last are at the higher position and the data which are put into it first are removed first when data are flushed out of the vector.
static int MODE_MOSTUSED
          Specifies the caching and sorting mode for the data, in MODE_MOSTUSED the more often data are used the higher is their position in the vector and the lower is the possibility that they get lost when data are flushed out of the cache.
 
Constructor Summary
DataCache()
          Constructs a new DataCache object with a maximum size of MAX_DATA_SETS and in data caching mode MODE_MOSTUSED.
DataCache(int MaxCachedDataNum)
          Constructs a new DataCache object using the data caching mode MODE_MOSTUSED
DataCache(int MaxCachedDataNum, int DataCacheMode)
          Constructs a new DataCache object
 
Method Summary
 boolean containsBranchGroup(String Identifier)
          Checks if the DataCache contains a specific BranchGroup
 void flushAll()
          Flushes all stored data to let the GC free the related memory
 XBranchGroup getBranchGroup(String Identifier, boolean forceGeometryCopying)
          Fetches a cached BranchGroup object from the DataCache
 byte[] getData(String Identifier)
          Fetches a data buffer from the DataCache.
 javax.media.j3d.Shape3D getShape3D(String Identifier, boolean forceGeometryCopying)
          Fetches a cached Shape3D object from the DataCache.
 javax.media.j3d.Texture getTexture(String Identifier, boolean forceCopying)
          Fetches a cached Texture object from the DataCache
 void removeCachedObject(String Identifier)
          Removes a cached object from the DataCache
static void removeData(javax.media.j3d.Node inNode)
          Removes all data from a SceneGraph to allow a more effective garbage collection and to avoid some J3D-specific memory problems.
 void storeBranchGroup(XBranchGroup MyBranch, String Identifier)
          Stores a duplicated BranchGroup in the DataCache.
 void storeBranchGroup(XBranchGroup MyBranch, String Identifier, boolean doCloneShape)
          Stores a BranchGroup in the DataCache.
 void storeData(byte[] buffer, String Identifier)
          Stores a data buffer in the DataCache.
 void storeShape3D(javax.media.j3d.Shape3D MyShape3D, String Identifier)
          duplicates and stores a Shape3D in the DataCache.
 void storeShape3D(javax.media.j3d.Shape3D MyShape3D, String Identifier, boolean doCloneShape)
          Stores a Shape3D in the DataCache.
 void storeTexture(javax.media.j3d.Texture MyTexture, String Identifier)
          Stores a Texture in the DataCache.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_MOSTUSED

public static final int MODE_MOSTUSED
Specifies the caching and sorting mode for the data, in MODE_MOSTUSED the more often data are used the higher is their position in the vector and the lower is the possibility that they get lost when data are flushed out of the cache. This mode is the default one. The order of the data within a vector is modified during a get...() method.

See Also:
Constant Field Values

MODE_FIFO

public static final int MODE_FIFO
Specifies the caching and sorting mode for the data, in MODE_FIFO the data put into the cache last are at the higher position and the data which are put into it first are removed first when data are flushed out of the vector. The order of the data within a vector is modified during a store...() method when this mode is set.

See Also:
Constant Field Values
Constructor Detail

DataCache

public DataCache(int MaxCachedDataNum)
Constructs a new DataCache object using the data caching mode MODE_MOSTUSED

Parameters:
MaxCachedDataNum - specifies the size of the cache; if this limit of cached objects is reached, half of the cache will be released and the stored objects will be removed during the next garbage collection if they are not referenced..

DataCache

public DataCache(int MaxCachedDataNum,
                 int DataCacheMode)
Constructs a new DataCache object

Parameters:
MaxCachedDataNum - specifies the size of the cache; if this limit of cached objects is reached, half of the cache will be released and the stored objects will be removed during the next garbage collection if they are not referenced..
DataCacheMode - specifies the mode for the data caching and sorting

DataCache

public DataCache()
Constructs a new DataCache object with a maximum size of MAX_DATA_SETS and in data caching mode MODE_MOSTUSED. If the limit of MAX_DATA_SETS cached objects is reached, half of the cache will be flushed out of the cache and the stored objects will be removed during the next garbage collection if they are not referenced.

Method Detail

removeData

public static void removeData(javax.media.j3d.Node inNode)
Removes all data from a SceneGraph to allow a more effective garbage collection and to avoid some J3D-specific memory problems.

Parameters:
inNode - the node which is base of the SceneGraph which has to be disbanded

flushAll

public void flushAll()
Flushes all stored data to let the GC free the related memory


removeCachedObject

public void removeCachedObject(String Identifier)
Removes a cached object from the DataCache

Parameters:
Identifier - string which identifies the object which has to be removed

getShape3D

public javax.media.j3d.Shape3D getShape3D(String Identifier,
                                          boolean forceGeometryCopying)
Fetches a cached Shape3D object from the DataCache.

Parameters:
Identifier - string which identifies the object which has to be fetched
forceGeometryCopying - if this parameter is set to true all related gemoetry data are copied, elsewhere they are referenced only so that different retrieved Shape3Ds share the same geometry data

getData

public byte[] getData(String Identifier)
Fetches a data buffer from the DataCache.

Parameters:
Identifier - string which identifies the object which has to be fetched
Returns:
the data buffer or null if it could not be found

containsBranchGroup

public boolean containsBranchGroup(String Identifier)
Checks if the DataCache contains a specific BranchGroup

Parameters:
Identifier - string which identifies the BranchGroup object this method looks for

getBranchGroup

public XBranchGroup getBranchGroup(String Identifier,
                                   boolean forceGeometryCopying)
Fetches a cached BranchGroup object from the DataCache

Parameters:
Identifier - string which identifies the object which has to be fetched
forceGeometryCopying - if this parameter is set to true all geometry data of subsequent Shapes are copied, elsewhere they are referenced only so that different retrieved BranchGroups' Shapes share the same underlying geometry data

storeShape3D

public void storeShape3D(javax.media.j3d.Shape3D MyShape3D,
                         String Identifier)
duplicates and stores a Shape3D in the DataCache.

Parameters:
MyShape3D - the Shape3D object which has to be stored
Identifier - the identification string under what the object is stored and which can be used to accessed it later

storeShape3D

public void storeShape3D(javax.media.j3d.Shape3D MyShape3D,
                         String Identifier,
                         boolean doCloneShape)
Stores a Shape3D in the DataCache.

Parameters:
MyShape3D - the Shape3D object which has to be stored
Identifier - the identification string under what the object is stored and which can be used to accessed it later
doCloneShape - specifies if the shape3D has to be duplicated (true) or if the original has to be stored

storeData

public void storeData(byte[] buffer,
                      String Identifier)
Stores a data buffer in the DataCache.

Parameters:
buffer - the data buffer which has to be stored
Identifier - the identification string under what the object is stored and which can be used to accessed it later

getTexture

public javax.media.j3d.Texture getTexture(String Identifier,
                                          boolean forceCopying)
Fetches a cached Texture object from the DataCache

Parameters:
Identifier - string which identifies the object which has to be fetched

storeBranchGroup

public void storeBranchGroup(XBranchGroup MyBranch,
                             String Identifier)
Stores a duplicated BranchGroup in the DataCache.

Parameters:
MyBranch - the BranchGroup object which has to be stored
Identifier - the identification string under what the object is stored and which can be used to accessed it later

storeBranchGroup

public void storeBranchGroup(XBranchGroup MyBranch,
                             String Identifier,
                             boolean doCloneShape)
Stores a BranchGroup in the DataCache.

Parameters:
MyBranch - the BranchGroup object which has to be stored
Identifier - the identification string under what the object is stored and which can be used to accessed it later
doCloneShape - specifies if the shape3D has to be duplicated (true) or if the original has to be stored

storeTexture

public void storeTexture(javax.media.j3d.Texture MyTexture,
                         String Identifier)
Stores a Texture in the DataCache.

Parameters:
MyTexture - the Texture object which has to be stored
Identifier - the identification string under what the object is stored and which can be used to accessed it later