<commit_before>package emergencylanding.k.library.lwjgl.tex;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.Raster;
import java.awt.image.SinglePixelPackedSampleModel;
import java.awt.image.WritableRaster;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL30;

import emergencylanding.k.library.debug.Memory;
import emergencylanding.k.library.exceptions.lwjgl.TextureBindException0;
import emergencylanding.k.library.lwjgl.render.GLData;
import emergencylanding.k.library.main.KMain;
import emergencylanding.k.library.util.LUtils;

public abstract class ELTexture {
    public static class DestTexture extends ELTexture {

        public DestTexture(ELTexture texture) {
            buf = ByteBuffer.allocateDirect(1);
            dim = new Dimension(1, 1);
            setConstructingOverrideId(texture.id);
            init();
            ELTexture.texlist.remove(getID());
            ELTexture.currentSpace -= buf.capacity();
            ELTexture.removedIDs.add(getID());
            GL11.glDeleteTextures(getID());
            texture.destruction0();
        }

        @Override
        public void setup() {

        }

        @Override
        protected BufferedImage toBufferedImageAbstract() {
            throw new UnsupportedOperationException("This texture is removed");
        }

        @Override
        protected void onDestruction() {
        }

    }

    private int id = -1;
    private int useID = -1;
    static {
        System.gc();
    }
    public static final long TOTAL_TEXTURE_SPACE = Runtime.getRuntime()
            .maxMemory() * 2 / 3;
    // private static IntBuffer ids = BufferUtils.createIntBuffer(1);
    private static HashMap<Integer, ELTexture> texlist = new HashMap<Integer, ELTexture>();
    private static ArrayList<Integer> removedIDs = new ArrayList<Integer>();
    public static long currentSpace = 0;
    public ByteBuffer buf = null;
    public Dimension dim = null;
    private static ArrayList<Runnable> glThreadQueue = new ArrayList<Runnable>();
    static {
        System.gc();
        Memory.printAll();
    }

    // Define static Textures AFTER this comment

    public static final ELTexture invisible = new ColorTexture(new Color(0, 0,
            0, 0), new Dimension(1, 1));

    public ELTexture() {
    }

    private void bind0() {
        final ELTexture texObj = this;
        Runnable runnable = null;
        synchronized (glThreadQueue) {
            glThreadQueue.add(runnable = new Runnable() {
                @Override
                public void run() {
                    if (buf == null || dim == null) {
                        throw new TextureBindException0(
                                "A required variable is null when creating textures!");
                    } else if (buf.capacity() < dim.height * dim.width * 4) {
                        ByteBuffer tmp = ByteBuffer.allocateDirect(dim.height
                                * dim.width * 4);
                        tmp.put(buf);
                        buf = tmp;
                        buf.rewind();
                    }
                    buf.rewind();
                    ELTexture lookAlike;
                    if ((lookAlike = ELTexture.similar(texObj)) != null) {
                        id = lookAlike.id;
                        LUtils.print("Overrode id: " + id + " (obj=" + texObj
                                + ", overriden=" + lookAlike + ")");
                        if (LUtils.debugLevel > 3) {
                            new Throwable().printStackTrace();
                        }
                        ELTexture.texlist.put(lookAlike.id, texObj);
                    } else {
                        boolean override = false;
                        ELTexture.currentSpace += buf.capacity();
                        if (ELTexture.removedIDs.size() > 0 && useID == -1) {
                            id = ELTexture.removedIDs.get(0);
                            ELTexture.removedIDs.remove(0);
                        }
                        if (useID > -1) {
                            override = true;
                            id = useID;
                            LUtils.print("Force-overrode id: " + id);
                            if (ELTexture.texlist.get(id) != null) {
                                ELTexture.currentSpace -= ELTexture.texlist
                                        .get(id).buf.capacity();
                            } else {
                                LUtils.print("Interesting, it appears that id "
                                        + id
                                        + " is null. This shouldn't be happening, but we'll let it slide for now.");
                            }
                        }<commit_msg>Fix typo<commit_after>package emergencylanding.k.library.lwjgl.tex;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.Raster;
import java.awt.image.SinglePixelPackedSampleModel;
import java.awt.image.WritableRaster;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL30;

import emergencylanding.k.library.debug.Memory;
import emergencylanding.k.library.exceptions.lwjgl.TextureBindException0;
import emergencylanding.k.library.lwjgl.render.GLData;
import emergencylanding.k.library.main.KMain;
import emergencylanding.k.library.util.LUtils;

public abstract class ELTexture {
    public static class DestTexture extends ELTexture {

        public DestTexture(ELTexture texture) {
            buf = ByteBuffer.allocateDirect(1);
            dim = new Dimension(1, 1);
            setConstructingOverrideId(texture.id);
            init();
            ELTexture.texlist.remove(getID());
            ELTexture.currentSpace -= buf.capacity();
            ELTexture.removedIDs.add(getID());
            GL11.glDeleteTextures(getID());
            texture.destruction0();
        }

        @Override
        public void setup() {

        }

        @Override
        protected BufferedImage toBufferedImageAbstract() {
            throw new UnsupportedOperationException("This texture is removed");
        }

        @Override
        protected void onDestruction() {
        }

    }

    private int id = -1;
    private int useID = -1;
    static {
        System.gc();
    }
    public static final long TOTAL_TEXTURE_SPACE = Runtime.getRuntime()
            .maxMemory() * 2 / 3;
    // private static IntBuffer ids = BufferUtils.createIntBuffer(1);
    private static HashMap<Integer, ELTexture> texlist = new HashMap<Integer, ELTexture>();
    private static ArrayList<Integer> removedIDs = new ArrayList<Integer>();
    public static long currentSpace = 0;
    public ByteBuffer buf = null;
    public Dimension dim = null;
    private static ArrayList<Runnable> glThreadQueue = new ArrayList<Runnable>();
    static {
        System.gc();
        Memory.printAll();
    }

    // Define static Textures AFTER this comment

    public static final ELTexture invisible = new ColorTexture(new Color(0, 0,
            0, 0), new Dimension(1, 1));

    public ELTexture() {
    }

    private void bind0() {
        final ELTexture texObj = this;
        Runnable runnable = null;
        synchronized (glThreadQueue) {
            glThreadQueue.add(runnable = new Runnable() {
                @Override
                public void run() {
                    if (buf == null || dim == null) {
                        throw new TextureBindException0(
                                "A required variable is null when creating textures!");
                    } else if (buf.capacity() < dim.height * dim.width * 4) {
                        ByteBuffer tmp = ByteBuffer.allocateDirect(dim.height
                                * dim.width * 4);
                        tmp.put(buf);
                        buf = tmp;
                        buf.rewind();
                    }
                    buf.rewind();
                    ELTexture lookAlike;
                    if ((lookAlike = ELTexture.similar(texObj)) != null) {
                        id = lookAlike.id;
                        LUtils.print("Overrode id: " + id + " (obj=" + texObj
                                + ", overridden=" + lookAlike + ")");
                        if (LUtils.debugLevel > 3) {
                            new Throwable().printStackTrace();
                        }
                        ELTexture.texlist.put(lookAlike.id, texObj);
                    } else {
                        boolean override = false;
                        ELTexture.currentSpace += buf.capacity();
                        if (ELTexture.removedIDs.size() > 0 && useID == -1) {
                            id = ELTexture.removedIDs.get(0);
                            ELTexture.removedIDs.remove(0);
                        }
                        if (useID > -1) {
                            override = true;
                            id = useID;
                            LUtils.print("Force-overrode id: " + id);
                            if (ELTexture.texlist.get(id) != null) {
                                ELTexture.currentSpace -= ELTexture.texlist
                                        .get(id).buf.capacity();
                            } else {
                                LUtils.print("Interesting, it appears that id "
                                        + id
                                        + " is null. This shouldn't be happening, but we'll let it slide for now.");
                            }
                        }
{'fraction_non_alphanumeric': 0.09497882637628555, 'fraction_numerical': 0.007057874571486187, 'mean_word_length': 1.4897088353413654, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '976666', 'n_tokens_mistral': 2583, 'n_tokens_neox': 2456, 'n_words': 577}