@@ -0,0 +1,3610 @@
+package com.nucleus.assets;%0A%0Aimport java.io.IOException;%0Aimport java.util.Hashtable;%0A%0Aimport com.nucleus.io.ExternalReference;%0Aimport com.nucleus.renderer.NucleusRenderer;%0Aimport com.nucleus.texturing.Texture2D;%0Aimport com.nucleus.texturing.TextureFactory;%0Aimport com.nucleus.texturing.TextureSetup;%0A%0A/**%0A * Loading and unloading assets, mainly textures.%0A * %0A * @author Richard Sahlin%0A *%0A */%0Apublic class AssetManager %7B%0A%0A    protected static AssetManager assetManager = null;%0A%0A    private final static String NO_TEXTURE_SOURCE_ERROR = %22No texture source for id: %22;%0A%0A    /**%0A     * Store textures using the source image name.%0A     */%0A    private Hashtable%3CString, Texture2D%3E textures = new Hashtable%3CString, Texture2D%3E();%0A    /**%0A     * Use to convert from object id (texture reference) to name of source (file)%0A     */%0A    private Hashtable%3CString, ExternalReference%3E sourceNames = new Hashtable%3CString, ExternalReference%3E();%0A%0A    /**%0A     * Hide the constructor%0A     */%0A    private AssetManager() %7B%0A    %7D%0A%0A    public static AssetManager getInstance() %7B%0A        if (assetManager == null) %7B%0A            assetManager = new AssetManager();%0A        %7D%0A        return assetManager;%0A    %7D%0A%0A    public interface Asset %7B%0A        /**%0A         * Loads an instance of the asset into memory, after this method returns the asset SHALL be ready to be used.%0A         * %0A         * @param source The source of the object, it is up to implementations to decide what sources to support.%0A         * For images the normal usecase is InputStream%0A         * %0A         * @return The id of the asset, this is a counter starting at 1 and increasing.%0A         * @throws IOException If there is an exception reading from the stream.%0A         */%0A        public int load(Object source) throws IOException;%0A%0A        /**%0A         * Releases the asset and all allocated memory, after this method returns all memory and objects shall be%0A         * released.%0A         */%0A        public void destroy();%0A    %7D%0A%0A    /**%0A     * Returns the texture, if the texture has not been loaded it will be loaded and stored in the assetmanager.%0A     * %0A     * @param renderer%0A     * @param source%0A     * @return The texture%0A     * @throws IOException%0A     */%0A    public Texture2D getTexture(NucleusRenderer renderer, TextureSetup source) throws IOException %7B%0A%0A        Texture2D texture = textures.get(source.getSourceName());%0A        if (texture != null) %7B%0A            return texture;%0A        %7D%0A%0A        texture = TextureFactory.createTexture(renderer.getGLES(), renderer.getImageFactory(), source);%0A        textures.put(source.getSourceName(), texture);%0A        ExternalReference ref = new ExternalReference(source.getSourceName());%0A        ref.setId(source.getId());%0A        sourceNames.put(source.getId(), ref);%0A        return texture;%0A    %7D%0A%0A    /**%0A     * Returns the source reference for the texture with the specified id, this can be used to fetch texture%0A     * source name from a texture reference/id.%0A     * If the source reference cannot be found it is considered an error and an exception is thrown.%0A     * %0A     * @param Id%0A     * @return The source (file) reference or null if not found.%0A     * @throws IllegalArgumentException If a texture source could not be found for the Id.%0A     */%0A    public ExternalReference getSourceReference(String Id) %7B%0A        ExternalReference ref = sourceNames.get(Id);%0A        if (ref == null) %7B%0A            // Horrendous error - cannot export data!%0A            // TODO Is there a way to recover?%0A            throw new IllegalArgumentException(NO_TEXTURE_SOURCE_ERROR + Id);%0A        %7D%0A        return ref;%0A    %7D%0A%0A%7D%0A

Move assetmanager to nucleus (from graphics-engine)