Search in sources :

Example 1 with Disposable

use of com.badlogic.gdx.utils.Disposable in project libgdx by libgdx.

the class BaseBulletTest method dispose.

@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();
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable)

Example 2 with Disposable

use of com.badlogic.gdx.utils.Disposable in project libgdx by libgdx.

the class TiledMapLayerOffsetTest method render.

@Override
public void render() {
    if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) {
        if (mapType != 0) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 0;
            map = assetManager.get(MAP_ORTHO);
            renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) {
        if (mapType != 1) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 1;
            map = assetManager.get(MAP_ORTHO);
            renderer = new OrthoCachedTiledMapRenderer(map, 1f / 32f);
            ((OrthoCachedTiledMapRenderer) renderer).setBlending(true);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) {
        if (mapType != 2) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 2;
            map = assetManager.get(MAP_ISO);
            renderer = new IsometricTiledMapRenderer(map, 1f / 48f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_4)) {
        if (mapType != 3) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 3;
            map = assetManager.get(MAP_ISO_STAG);
            renderer = new IsometricStaggeredTiledMapRenderer(map, 1f / 48f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_5)) {
        if (mapType != 4) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 4;
            map = assetManager.get(MAP_HEX_X);
            renderer = new HexagonalTiledMapRenderer(map, 1f / 48f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_6)) {
        if (mapType != 5) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 5;
            map = assetManager.get(MAP_HEX_Y);
            renderer = new HexagonalTiledMapRenderer(map, 1f / 48f);
        }
    }
    Gdx.gl.glClearColor(100f / 255f, 100f / 255f, 250f / 255f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    // add margin to view bounds so it is easy to see any issues with clipping, calculated same way as
    // BatchTiledMapRenderer#setView (OrthographicCamera)
    final float margin = 3;
    final float width = camera.viewportWidth * camera.zoom - margin * 2;
    final float height = camera.viewportHeight * camera.zoom - margin * 2;
    final float w = width * Math.abs(camera.up.y) + height * Math.abs(camera.up.x);
    final float h = height * Math.abs(camera.up.y) + width * Math.abs(camera.up.x);
    final float x = camera.position.x - w / 2;
    final float y = camera.position.y - h / 2;
    renderer.setView(camera.combined, x, y, w, h);
    renderer.render();
    shapeRenderer.setProjectionMatrix(camera.combined);
    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.setColor(Color.RED);
    shapeRenderer.rect(x, y, w, h);
    shapeRenderer.end();
    batch.begin();
    font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
    font.draw(batch, "Switch type with 1-6", Gdx.graphics.getHeight() - 100, 50);
    font.draw(batch, renderer.getClass().getSimpleName(), Gdx.graphics.getHeight() - 100, 20);
    batch.end();
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) IsometricTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer) IsometricStaggeredTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricStaggeredTiledMapRenderer) OrthoCachedTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer) HexagonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer)

Example 3 with Disposable

use of com.badlogic.gdx.utils.Disposable in project libgdx by libgdx.

the class AssetManager method unload.

/** Removes the asset and all its dependencies, if they are not used by other assets.
	 * @param fileName the file name */
public synchronized void unload(String fileName) {
    // and cancel if necessary
    if (tasks.size() > 0) {
        AssetLoadingTask currAsset = tasks.firstElement();
        if (currAsset.assetDesc.fileName.equals(fileName)) {
            currAsset.cancel = true;
            log.debug("Unload (from tasks): " + fileName);
            return;
        }
    }
    // check if it's in the queue
    int foundIndex = -1;
    for (int i = 0; i < loadQueue.size; i++) {
        if (loadQueue.get(i).fileName.equals(fileName)) {
            foundIndex = i;
            break;
        }
    }
    if (foundIndex != -1) {
        toLoad--;
        loadQueue.removeIndex(foundIndex);
        log.debug("Unload (from queue): " + fileName);
        return;
    }
    // get the asset and its type
    Class type = assetTypes.get(fileName);
    if (type == null)
        throw new GdxRuntimeException("Asset not loaded: " + fileName);
    RefCountedContainer assetRef = assets.get(type).get(fileName);
    // if it is reference counted, decrement ref count and check if we can really get rid of it.
    assetRef.decRefCount();
    if (assetRef.getRefCount() <= 0) {
        log.debug("Unload (dispose): " + fileName);
        // if it is disposable dispose it
        if (assetRef.getObject(Object.class) instanceof Disposable)
            ((Disposable) assetRef.getObject(Object.class)).dispose();
        // remove the asset from the manager.
        assetTypes.remove(fileName);
        assets.get(type).remove(fileName);
    } else {
        log.debug("Unload (decrement): " + fileName);
    }
    // remove any dependencies (or just decrement their ref count).
    Array<String> dependencies = assetDependencies.get(fileName);
    if (dependencies != null) {
        for (String dependency : dependencies) {
            if (isLoaded(dependency))
                unload(dependency);
        }
    }
    // remove dependencies if ref count < 0
    if (assetRef.getRefCount() <= 0) {
        assetDependencies.remove(fileName);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Disposable(com.badlogic.gdx.utils.Disposable)

Example 4 with Disposable

use of com.badlogic.gdx.utils.Disposable in project libgdx by libgdx.

the class ModelLoader method loadSync.

@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;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) ModelData(com.badlogic.gdx.graphics.g3d.model.data.ModelData) Model(com.badlogic.gdx.graphics.g3d.Model) TextureProvider(com.badlogic.gdx.graphics.g3d.utils.TextureProvider) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Texture(com.badlogic.gdx.graphics.Texture)

Example 5 with Disposable

use of com.badlogic.gdx.utils.Disposable in project libgdx by libgdx.

the class ModelBuilder method node.

/** Adds the nodes of the specified model to a new node of the model being build. After this method the given model can no
	 * longer be used. Do not call the {@link Model#dispose()} method on that model.
	 * @return The newly created node containing the nodes of the given model. */
public Node node(final String id, final Model model) {
    final Node node = new Node();
    node.id = id;
    node.addChildren(model.nodes);
    node(node);
    for (final Disposable disposable : model.getManagedDisposables()) manage(disposable);
    return node;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) Node(com.badlogic.gdx.graphics.g3d.model.Node)

Aggregations

Disposable (com.badlogic.gdx.utils.Disposable)7 Texture (com.badlogic.gdx.graphics.Texture)2 Model (com.badlogic.gdx.graphics.g3d.Model)2 ModelData (com.badlogic.gdx.graphics.g3d.model.data.ModelData)2 ModelTexture (com.badlogic.gdx.graphics.g3d.model.data.ModelTexture)2 TextureProvider (com.badlogic.gdx.graphics.g3d.utils.TextureProvider)2 BaseSystem (com.artemis.BaseSystem)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)1 Node (com.badlogic.gdx.graphics.g3d.model.Node)1 ModelMaterial (com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial)1 HexagonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer)1 IsometricStaggeredTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.IsometricStaggeredTiledMapRenderer)1 IsometricTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer)1 OrthoCachedTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer)1 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 PbrTextureAttribute (io.github.voidzombie.nhglib.graphics.shaders.attributes.PbrTextureAttribute)1