Search in sources :

Example 6 with Disposable

use of com.badlogic.gdx.utils.Disposable in project nhglib by VoidZombie.

the class NhgModelLoader 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();
        }
    }
    // 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;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) ModelData(com.badlogic.gdx.graphics.g3d.model.data.ModelData) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) TextureProvider(com.badlogic.gdx.graphics.g3d.utils.TextureProvider) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Texture(com.badlogic.gdx.graphics.Texture) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) PbrTextureAttribute(io.github.voidzombie.nhglib.graphics.shaders.attributes.PbrTextureAttribute)

Example 7 with Disposable

use of com.badlogic.gdx.utils.Disposable in project nhglib by VoidZombie.

the class EngineStateClosing method enter.

@Override
public void enter(NhgEntry nhgEntry) {
    Logger.log(this, "Engine is closing.");
    nhgEntry.engineClosing();
    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();
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) BaseSystem(com.artemis.BaseSystem)

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