/** * Helper method to release a cached asset (texture, sound, font, ...). * * <p> * If {@link RefCountedAsset#release()} returns {@code true}, the asset is also * removed from the cache. * </p> * * @param cache The cache where to search for the asset to be released. * @param valueToRelease The asset to release. * @param <K> Key type in the {@code Map}. * @param <T> The asset type. */ private static <K, T extends Disposable> void release(Map<K, RefCountedAsset<T>> cache, T valueToRelease) { K keyToRemove = null; for (Map.Entry<K, RefCountedAsset<T>> entry : cache.entrySet()) { if (entry.getValue().wrapsAsset(valueToRelease)) { if (entry.getValue().release()) { keyToRemove = entry.getKey(); } break; } } if (keyToRemove != null) { cache.remove(keyToRemove); } }
/** * Disposes of the underlying {@link Resource} and * {@link Disposable} pair held by this * {@link ResourceFactory}. */ public final void dispose() { this.onDispose(); if(this.disposableGen != null) { this.cancelGen = true; } if (this.disposable != null) { if (this.disposeOnGameThread()) { Disposable copy = this.disposable; Gdx.app.postRunnable(() -> copy.dispose()); } else { this.disposable.dispose(); } this.disposable = null; } if (this.reference != null) { if (this.reference.get() != null) this.reference.get().disposable = null; this.reference.enqueue(); this.reference = null; } }
@Override protected CompletableFuture<Disposable> loadDisposable() { return CompletableFuture.supplyAsync(() -> { try { reader.read(tmxFile, this.getResourceReference()); } catch (Exception e) { String message = "Failed to load tilemap " + this.tmxFile.getAbsolutePath() + " (" + e.getMessage() + ")"; BadAssetException thrown = new BadAssetException(message); thrown.initCause(e); Thread.getDefaultUncaughtExceptionHandler() .uncaughtException(Thread.currentThread(), thrown); } return null; }); }
@Override public void enter(NhgEntry nhgEntry) { NhgLogger.log(this, "Engine is closing."); nhgEntry.onClose(); ImmutableBag<BaseSystem> systems = nhgEntry.nhg.entities.getEntitySystems(); for (BaseSystem bs : systems) { if (bs instanceof Disposable) { ((Disposable) bs).dispose(); } } nhgEntry.nhg.assets.dispose(); nhgEntry.nhg.threading.terminate(); Gdx.app.exit(); }
@Override public void dispose () { world.dispose(); world = null; for (Disposable disposable : disposables) disposable.dispose(); disposables.clear(); modelBatch.dispose(); modelBatch = null; shadowBatch.dispose(); shadowBatch = null; if (shadows) ((DirectionalShadowLight)light).dispose(); light = null; super.dispose(); }
@Override public void dispose() { try { final Object value = Reflection.getFieldValue(field, fieldOwner); if (value instanceof Disposable) { ((Disposable) value).dispose(); } else if (value instanceof Lazy<?>) { final Lazy<?> lazy = (Lazy<?>) value; if (lazy.isInitialized() && lazy.get() instanceof Disposable) { ((Disposable) lazy.get()).dispose(); } } } catch (final Exception exception) { Exceptions.ignore(exception); // Ignored. Closing the application, invalid objects can occur. } }
@Override public Model loadSync (AssetManager manager, String fileName, FileHandle file, P parameters) { ModelData data = null; synchronized (items) { for (int i = 0; i < items.size; i++) { if (items.get(i).key.equals(fileName)) { data = items.get(i).value; items.removeIndex(i); } } } if (data == null) return null; final Model result = new Model(data, new TextureProvider.AssetTextureProvider(manager)); // need to remove the textures from the managed disposables, or else ref counting // doesn't work! Iterator<Disposable> disposables = result.getManagedDisposables().iterator(); while (disposables.hasNext()) { Disposable disposable = disposables.next(); if (disposable instanceof Texture) { disposables.remove(); } } data = null; return result; }
@Override public void dispose() { for (Disposable disp : disposables) { /*if (disp instanceof BulletBase) { System.out.println("ownership: " + ((BulletBase) disp).hasOwnership()); }*/ Tools.dispose(disp); } for (btCollisionShape shape : shapes) { shape.dispose(); } for (btCollisionObject object : objects) { object.dispose(); } disposables.clear(); shapes.clear(); objects.clear(); }
@Override public HeadlessModel loadSync (AssetManager manager, String fileName, FileHandle file, P parameters) { ModelData data = null; synchronized (items) { for (int i = 0; i < items.size; i++) { if (items.get(i).key.equals(fileName)) { data = items.get(i).value; items.removeIndex(i); } } } if (data == null) return null; final HeadlessModel result = new HeadlessModel(data, new TextureProvider.AssetTextureProvider(manager)); // need to remove the textures from the managed disposables, or else ref counting // doesn't work! Iterator<Disposable> disposables = result.getManagedDisposables().iterator(); while (disposables.hasNext()) { Disposable disposable = disposables.next(); if (disposable instanceof Texture) { disposables.remove(); } } data = null; return result; }
@Override public void dispose () { world.dispose(); world = null; for (Disposable disposable : disposables) disposable.dispose(); disposables.clear(); modelBatch.dispose(); modelBatch = null; shadowBatch.dispose(); shadowBatch = null; if (shadows) ((DirectionalShadowLight)light).dispose(); light = null; }
public void dispose() { if (this.atlas != null) this.atlas.dispose(); Iterator localIterator1 = this.resources.values().iterator(); while (localIterator1.hasNext()) { Iterator localIterator2 = ((ObjectMap)localIterator1.next()).values().iterator(); while (localIterator2.hasNext()) { Object localObject = localIterator2.next(); if ((localObject instanceof Disposable)) ((Disposable)localObject).dispose(); } } }
public final bj a(i parami, ba paramba, ai paramai) { if (this.b.tryAcquire()) { if (parami.d(paramba)) { Disposable localDisposable = parami.b(paramba).a(); if ((localDisposable instanceof c)) { c localc = (c)localDisposable; if (localc.b()) return new l(this.d, localc.c()); } } if ((ag.a == ah.a) && (parami.e(paramba))) new Object[1][0] = paramba.b(); return new d(this.c, "sounds", paramai); } throw new bl("acquireSoundPlayer too many sound players."); }
@Override public void dispose () { System.out.println("Dispose"); if (disposables != null) for (Disposable d : disposables) d.dispose(); }
@Override public Model loadSync(AssetManager manager, String fileName, FileHandle file, P parameters) { ModelData data = null; synchronized (items) { for (int i = 0; i < items.size; i++) { if (items.get(i).key.equals(fileName)) { data = items.get(i).value; items.removeIndex(i); } } } if (data == null) return null; final Model result = new Model(data, new TextureProvider.AssetTextureProvider(manager)); // need to remove the textures from the managed disposables, or else ref counting // doesn't work! Iterator<Disposable> disposables = result.getManagedDisposables().iterator(); while (disposables.hasNext()) { Disposable disposable = disposables.next(); if (disposable instanceof Texture) { disposables.remove(); } } // Automatically convert all materials to PBR for (Material material : result.materials) { TextureAttribute textureAttribute = (TextureAttribute) material.get(TextureAttribute.Diffuse); if (textureAttribute != null) { material.set(PbrTextureAttribute.createAlbedo(textureAttribute.textureDescription.texture)); } } data = null; return result; }
public static void disposeAll(Disposable[] obj) { for(int i = 0;i < obj.length;i++) { if(obj[i] != null) { obj[i].dispose(); obj[i] = null; } } }
@Override public void dispose() { logger.info("dispose"); for (EntitySystem system : engine.getSystems()) { if (system instanceof Disposable) { ((Disposable)system).dispose(); } } }
@Override public void dispose() { rigidBody.dispose(); motionState.dispose(); disposables.forEach(Disposable::dispose); }
@Override public void dispose() { buffer.dispose(); if (renderLayer instanceof Disposable) { ((Disposable) renderLayer).dispose(); } }
@Override public void dispose() { for (GameObjectRenderer renderer : rendererMap.values()) { if (renderer instanceof Disposable) { ((Disposable) renderer).dispose(); } } rendererMap.clear(); }
/** @param keysAndValues pairs of keys and values. * @return a new DisposableObjectMap created with the passed keys and values. * @throws IllegalArgumentException if keys and values total amount is not even. * @throws ClassCastException if received unexpected object type. */ @SuppressWarnings("unchecked") public static <Key, Value extends Disposable> DisposableObjectMap<Key, Value> of(final Object... keysAndValues) { if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException("Keys and values have to be passed in pairs."); } final DisposableObjectMap<Key, Value> map = new DisposableObjectMap<Key, Value>(); for (int index = 0; index < keysAndValues.length; index += 2) { map.put((Key) keysAndValues[index], (Value) keysAndValues[index + 1]); } return map; }
@Override public void dispose() { for (final Disposable disposable : values()) { if (disposable != null) { disposable.dispose(); } } }
/** @return a new DisposableObjectSet with the passed values. */ public static <Type extends Disposable> DisposableObjectSet<Type> of(final Type... disposables) { final DisposableObjectSet<Type> set = new DisposableObjectSet<Type>(disposables.length); for (final Type disposable : disposables) { set.add(disposable); } return set; }
@Override public void dispose() { for (final Disposable disposable : this) { if (disposable != null) { disposable.dispose(); } } }
/** @param values will be appended to the array. * @return a new DisposableArray with the passed values. */ public static <Type extends Disposable> DisposableArray<Type> with(final Iterable<? extends Type> values) { final DisposableArray<Type> array = new DisposableArray<Type>(); for (final Type value : values) { array.add(value); } return array; }
/** @param values will be appended to the array. * @return a new typed DisposableArray with the passed values. */ public static <Type extends Disposable> DisposableArray<Type> with(final Class<Type> forClass, final Iterable<? extends Type> values) { final DisposableArray<Type> array = new DisposableArray<Type>(forClass); for (final Type value : values) { array.add(value); } return array; }
/** Performs null checks and disposes of assets. * * @param disposables will be disposed of (if they exist). */ public static void disposeOf(final Disposable... disposables) { if (disposables != null) { for (final Disposable disposable : disposables) { disposeOf(disposable); } } }
/** Performs null checks and disposes of assets. * * @param disposables will be disposed of (if they exist). */ public static void disposeOf(final Iterable<? extends Disposable> disposables) { if (disposables != null) { for (final Disposable disposable : disposables) { disposeOf(disposable); } } }
/** Performs null checks and disposes of assets. * * @param disposables its values will be disposed of (if they exist). Can be null. */ public static void disposeOf(final ObjectMap<?, ? extends Disposable> disposables) { if (disposables != null) { for (final Disposable disposable : disposables.values()) { disposeOf(disposable); } } }
/** Performs null checks and disposes of assets. * * @param disposables its values will be disposed of (if they exist). Can be null. */ public static void disposeOf(final Map<?, ? extends Disposable> disposables) { if (disposables != null) { for (final Disposable disposable : disposables.values()) { disposeOf(disposable); } } }
/** Performs null check and disposes of an asset. Ignores exceptions. * * @param disposable will be disposed of (if it exists). */ public static void gracefullyDisposeOf(final Disposable disposable) { try { if (disposable != null) { disposable.dispose(); } } catch (final Throwable exception) { Gdx.app.error("WARN", "Unable to dispose: " + disposable + ". Ignored.", exception); } }
/** Performs null checks and disposes of assets. Ignores exceptions. * * @param disposables will be disposed of (if they exist). */ public static void gracefullyDisposeOf(final Disposable... disposables) { if (disposables != null) { for (final Disposable disposable : disposables) { gracefullyDisposeOf(disposable); } } }
/** Performs null checks and disposes of assets. Ignores exceptions. * * @param disposables will be disposed of (if they exist). */ public static void gracefullyDisposeOf(final Iterable<? extends Disposable> disposables) { if (disposables != null) { for (final Disposable disposable : disposables) { gracefullyDisposeOf(disposable); } } }
/** Performs null checks and disposes of assets. Ignores exceptions. * * @param disposables its values will be disposed of (if they exist). Can be null. */ public static void gracefullyDisposeOf(final ObjectMap<?, ? extends Disposable> disposables) { if (disposables != null) { for (final Disposable disposable : disposables.values()) { gracefullyDisposeOf(disposable); } } }
/** Performs null checks and disposes of assets. Ignores exceptions. * * @param disposables its values will be disposed of (if they exist). Can be null. */ public static void gracefullyDisposeOf(final Map<?, ? extends Disposable> disposables) { if (disposables != null) { for (final Disposable disposable : disposables.values()) { gracefullyDisposeOf(disposable); } } }
@Override public void dispose() { Gdx.app.log(TAG, "disposing instance"); removeAllEntities(); clearPools(); for (EntitySystem system : getSystems()) { if (system instanceof Disposable) { ((Disposable) system).dispose(); } system = null; removeSystem(system); } }
/** * Null-safe dispose method * * @return {@code null}, so you can write: {@code object = DisposeUtil.dispose(object);} */ public static @Nullable <T extends Disposable> T dispose(@Nullable T disposable) { if (disposable != null) { disposable.dispose(); } return null; }
/** * Registers a new generated resource. The resource is disposed when the returned {@link IResource} wrapper is no * longer referenced. */ public <T extends Serializable & Disposable> IResource<T> register(T value) { cleanUp(); GeneratedResource<T> resource = new GeneratedResource<>(selfId, value); resources.add(new ResourceRef<>(resource, value, garbage)); return resource; }