Search in sources :

Example 1 with CloneableSmartAsset

use of com.jme3.asset.CloneableSmartAsset in project jmonkeyengine by jMonkeyEngine.

the class DesktopAssetManager method loadAsset.

@Override
public <T> T loadAsset(AssetKey<T> key) {
    if (key == null)
        throw new IllegalArgumentException("key cannot be null");
    for (AssetEventListener listener : eventListeners) {
        listener.assetRequested(key);
    }
    AssetCache cache = handler.getCache(key.getCacheType());
    AssetProcessor proc = handler.getProcessor(key.getProcessorType());
    Object obj = cache != null ? cache.getFromCache(key) : null;
    if (obj == null) {
        // Asset not in cache, load it from file system.
        AssetInfo info = handler.tryLocate(key);
        if (info == null) {
            if (handler.getParentKey() != null) {
                // that something went wrong.
                for (AssetEventListener listener : eventListeners) {
                    listener.assetDependencyNotFound(handler.getParentKey(), key);
                }
            }
            throw new AssetNotFoundException(key.toString());
        }
        obj = loadLocatedAsset(key, info, proc, cache);
    }
    T clone = (T) obj;
    if (obj instanceof CloneableSmartAsset) {
        clone = registerAndCloneSmartAsset(key, clone, proc, cache);
    }
    return clone;
}
Also used : AssetCache(com.jme3.asset.cache.AssetCache)

Example 2 with CloneableSmartAsset

use of com.jme3.asset.CloneableSmartAsset in project jmonkeyengine by jMonkeyEngine.

the class WeakRefCloneAssetCache method addToCache.

public <T> void addToCache(AssetKey<T> originalKey, T obj) {
    // Make room for new asset
    removeCollectedAssets();
    CloneableSmartAsset asset = (CloneableSmartAsset) obj;
    // No circular references, since the original asset is 
    // strongly referenced, we don't want the key strongly referenced.
    asset.setKey(null);
    // Start tracking the collection of originalKey
    // (this adds the KeyRef to the ReferenceQueue)
    KeyRef ref = new KeyRef(originalKey, refQueue);
    // Place the asset in the cache, but use a clone of 
    // the original key.
    smartCache.put(ref.clonedKey, new AssetRef(asset, originalKey));
    // Push the original key used to load the asset
    // so that it can be set on the clone later
    ArrayList<AssetKey> loadStack = assetLoadStack.get();
    loadStack.add(originalKey);
}
Also used : CloneableSmartAsset(com.jme3.asset.CloneableSmartAsset) AssetKey(com.jme3.asset.AssetKey)

Aggregations

AssetKey (com.jme3.asset.AssetKey)1 CloneableSmartAsset (com.jme3.asset.CloneableSmartAsset)1 AssetCache (com.jme3.asset.cache.AssetCache)1