com.badlogic.gdx.utils.Disposable Java Examples

The following examples show how to use com.badlogic.gdx.utils.Disposable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BulletSteeringTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: HeadlessModelLoader.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: Physics.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #4
Source File: MPQViewer.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void setDelegate(T drawable) {
  if (Objects.equals(drawable, delegate)) {
    return;
  }

  if (delegate instanceof Disposable) ((Disposable) delegate).dispose();
  delegate = drawable;
}
 
Example #5
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * Disposes the {@link TextureAtlas} and all {@link Disposable} resources in
 * the skin.
 */
public void dispose() {
	if (atlas != null)
		atlas.dispose();
	for (ObjectMap<String, Object> entry : resources.values()) {
		for (Object resource : entry.values())
			if (resource instanceof Disposable)
				((Disposable) resource).dispose();
	}
}
 
Example #6
Source File: SetActorAttrAction.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private void removeUIActor(Scene scn, InteractiveActor actor) {
	InteractiveActor a = w.getUIActors().removeActor(actor.getId());

	if (a != null) {
		if (scn != w.getCurrentScene() && a instanceof Disposable)
			((Disposable) a).dispose();

		scn.addActor(a);
	} else {
		EngineLogger.debug("UIActor not found: " + actor.getId());
	}
}
 
Example #7
Source File: UIActors.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
	for (InteractiveActor a : actors)
		if (a instanceof SpriteActor)
			((Disposable) a).dispose();

	disposed = true;
}
 
Example #8
Source File: GameScreen.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  //map.dispose(); // FIXME: additional instances aren't reloading textures properly (DT1s disposal)
  charData.clearListeners();
  engine.dispose();
  for (Actor actor : stage.getActors()) if (actor instanceof Disposable) ((Disposable) actor).dispose();
  stage.dispose();
  for (AssetDescriptor asset : preloadedAssets) Riiablo.assets.unload(asset.fileName);
}
 
Example #9
Source File: MPQViewer.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void setDrawable(Drawable drawable) {
  if (Objects.equals(drawable, this.drawable)) {
    return;
  }

  if (this.drawable instanceof Disposable) ((Disposable) this.drawable).dispose();
  this.drawable = drawable;
}
 
Example #10
Source File: MPQViewer.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  if (backgroundTexture != null) backgroundTexture.dispose();
  if (drawable instanceof Disposable) ((Disposable) drawable).dispose();
  else if (drawable instanceof TextureRegionDrawable)
    ((TextureRegionDrawable) drawable).getRegion().getTexture().dispose();
}
 
Example #11
Source File: MPQViewer.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  if (delegate instanceof Disposable) ((Disposable) delegate).dispose();
  btnPlayPause     .removeListener(clickListener);
  btnFirstFrame    .removeListener(clickListener);
  btnLastFrame     .removeListener(clickListener);
  btnPrevFrame     .removeListener(clickListener);
  btnNextFrame     .removeListener(clickListener);
  paletteList      .removeListener(changeListener);
  daDirection      .removeListener(changeListener);
  slDirection      .removeListener(changeListener);
  slFrameIndex     .removeListener(changeListener);
  slFrameDuration  .removeListener(changeListener);
  //sbBlendMode      .removeListener(changeListener);
  //cbCombineFrames.removeListener(clickListener);
  btnPlayPauseAudio.removeListener(clickListener);
  btnRestartAudio  .removeListener(clickListener);
  slAudioScrubber  .removeListener(changeListener);
  slVolume         .removeListener(changeListener);
  imageControls    .removeListener(this);
  slPage           .removeListener(changeListener);
  btnFirstPage     .removeListener(clickListener);
  btnLastPage      .removeListener(clickListener);
  btnPrevPage      .removeListener(clickListener);
  btnNextPage      .removeListener(clickListener);
  slDirectionPage  .removeListener(changeListener);
  //sbBlendModePage  .removeListener(changeListener);
  components       .removeListener(changeListener);
  wclasses         .removeListener(changeListener);
}
 
Example #12
Source File: BlenderAssetManager.java    From GdxDemo3D with Apache License 2.0 4 votes vote down vote up
public <T extends Disposable> void manageDisposable(String assetId, T asset, Class<T> type) {
	disposableHolder.add(assetId, asset, type);
}
 
Example #13
Source File: MoveToSceneAction.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public boolean run(VerbRunner cb) {
	final Scene s = actor.getScene(w);

	final String actorId = actor.getActorId();

	if (actorId == null) {
		// if called in a scene verb and no actor is specified, we do nothing
		EngineLogger.error(getClass() + ": No actor specified");
		return false;
	}

	BaseActor a = s.getActor(actorId, false);

	if (a == null) {
		EngineLogger.error(getClass() + "- Actor not found: " + actorId + " in scene: " + s.getId());
		return false;
	}

	s.removeActor(a);

	Scene ts = null;

	if (scene == null)
		ts = w.getCurrentScene();
	else
		ts = w.getScene(scene);

	// Dispose if s is the current scene or a cached scene and the target is not the
	// current scene or a cache scene
	if ((s == w.getCurrentScene() || w.getCachedScene(ts.getId()) != null)
			&& !(ts == w.getCurrentScene() || w.getCachedScene(ts.getId()) != null) && a instanceof Disposable) {
		((Disposable) a).dispose();
	}

	// We must load assets when the target scene is the current scene or when
	// the scene is cached.
	if ((ts == w.getCurrentScene() || w.getCachedScene(ts.getId()) != null)
			&& !(s == w.getCurrentScene() || w.getCachedScene(s.getId()) != null) && a instanceof AssetConsumer) {
		((AssetConsumer) a).loadAssets();
		EngineAssetManager.getInstance().finishLoading();
		((AssetConsumer) a).retrieveAssets();
	}

	ts.addActor(a);

	return false;
}
 
Example #14
Source File: Tools.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public static void dispose(Disposable disp) {
	dispose(disp, "");
}
 
Example #15
Source File: Tools.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public static void dispose(Disposable disp, String name) {
	Log.debug("dispose: " + name + " -- " + disp);
	disp.dispose();
}
 
Example #16
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
/** Adds a {@link com.badlogic.gdx.utils.Disposable} to be managed and disposed by this Model. Can be used to keep track of manually loaded textures
 * for {@link com.badlogic.gdx.graphics.g3d.ModelInstance}.
 * @param disposable the Disposable */
public void manageDisposable (Disposable disposable) {
	if (!disposables.contains(disposable, true)) disposables.add(disposable);
}
 
Example #17
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
/** @return the {@link com.badlogic.gdx.utils.Disposable} objects that will be disposed when the {@link #dispose()} method is called. */
public Iterable<Disposable> getManagedDisposables () {
	return disposables;
}
 
Example #18
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
@Override
public void dispose () {
	for (Disposable disposable : disposables) {
		disposable.dispose();
	}
}
 
Example #19
Source File: DropItemAction.java    From bladecoder-adventure-engine with Apache License 2.0 3 votes vote down vote up
private void removeActor(Inventory inv, Scene ts, BaseActor a) {

		float scale = EngineAssetManager.getInstance().getScale();

		inv.removeItem(a.getId());

		if (ts != w.getCurrentScene() && w.getCachedScene(ts.getId()) == null && a instanceof Disposable)
			((Disposable) a).dispose();

		ts.addActor(a);

		if (pos != null)
			a.setPosition(pos.x * scale, pos.y * scale);
	}