<commit_before>package ethanjones.modularworld.graphics.world;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.RenderableProvider;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import ethanjones.modularworld.block.Block;
import ethanjones.modularworld.core.util.Direction;
import ethanjones.modularworld.graphics.GraphicsHelper;
import ethanjones.modularworld.world.storage.Area;

import static ethanjones.modularworld.world.storage.Area.SIZE_BLOCKS;
import static ethanjones.modularworld.world.storage.Area.SIZE_BLOCKS_CUBED;

public class AreaRenderer implements RenderableProvider {

  public static final int topOffset = SIZE_BLOCKS * SIZE_BLOCKS;
  public static final int bottomOffset = -SIZE_BLOCKS * SIZE_BLOCKS;
  public static final int leftOffset = -1;
  public static final int rightOffset = 1;
  public static final int frontOffset = -SIZE_BLOCKS;
  public static final int backOffset = SIZE_BLOCKS;
  public static final int VERTEX_SIZE = 6;

  public static short[] indices;

  static {
    int len = SIZE_BLOCKS_CUBED * 6 * 6 / 3;
    indices = new short[len];
    short j = 0;
    for (int i = 0; i < len; i += 6, j += 4) {
      indices[i + 0] = (short) (j + 0);
      indices[i + 1] = (short) (j + 1);
      indices[i + 2] = (short) (j + 2);
      indices[i + 3] = (short) (j + 2);
      indices[i + 4] = (short) (j + 3);
      indices[i + 5] = (short) (j + 0);
    }
  }

  public FaceProvider faceProvider;
  public Mesh mesh;
  public boolean dirty = true;
  Vector3 offset = new Vector3();
  private float vertices[];
  private int numVertices = 0;
  private Camera camera;
  private Area area;

  public AreaRenderer(Area area) {
    this.area = area;
    this.offset.set(area.minBlockX, area.minBlockY, area.minBlockZ);
    faceProvider = new FaceProvider(area);
    mesh = new Mesh(true, SIZE_BLOCKS_CUBED * 8 * 4, SIZE_BLOCKS_CUBED * 36 / 3, GraphicsHelper.vertexAttributes);
    mesh.setIndices(indices);
    vertices = new float[VERTEX_SIZE * 6 * SIZE_BLOCKS_CUBED];
  }

  public static int createTop(Vector3 offset, TextureRegion region, int x, int y, int z, float[] vertices, int vertexOffset) {
    vertices[vertexOffset++] = offset.x + x;
    vertices[vertexOffset++] = offset.y + y + 1;
    vertices[vertexOffset++] = offset.z + z + 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = region.getU2();
    vertices[vertexOffset++] = region.getV2();

    vertices[vertexOffset++] = offset.x + x + 1;
    vertices[vertexOffset++] = offset.y + y + 1;
    vertices[vertexOffset++] = offset.z + z + 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = region.getU2();
    vertices[vertexOffset++] = region.getV();

    vertices[vertexOffset++] = offset.x + x + 1;
    vertices[vertexOffset++] = offset.y + y + 1;
    vertices[vertexOffset++] = offset.z + z;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = region.getU();
    vertices[vertexOffset++] = region.getV();
<commit_msg>Reduced ram usage when rendering more then one chunk.<commit_after>package ethanjones.modularworld.graphics.world;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.RenderableProvider;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import ethanjones.modularworld.block.Block;
import ethanjones.modularworld.core.util.Direction;
import ethanjones.modularworld.graphics.GraphicsHelper;
import ethanjones.modularworld.world.storage.Area;

import static ethanjones.modularworld.world.storage.Area.SIZE_BLOCKS;
import static ethanjones.modularworld.world.storage.Area.SIZE_BLOCKS_CUBED;

public class AreaRenderer implements RenderableProvider {

  public static final int topOffset = SIZE_BLOCKS * SIZE_BLOCKS;
  public static final int bottomOffset = -SIZE_BLOCKS * SIZE_BLOCKS;
  public static final int leftOffset = -1;
  public static final int rightOffset = 1;
  public static final int frontOffset = -SIZE_BLOCKS;
  public static final int backOffset = SIZE_BLOCKS;
  public static final int VERTEX_SIZE = 6;

  private static short[] indices;
  private static float vertices[];

  static {
    int len = SIZE_BLOCKS_CUBED * 6 * 6 / 3;
    indices = new short[len];
    short j = 0;
    for (int i = 0; i < len; i += 6, j += 4) {
      indices[i + 0] = (short) (j + 0);
      indices[i + 1] = (short) (j + 1);
      indices[i + 2] = (short) (j + 2);
      indices[i + 3] = (short) (j + 2);
      indices[i + 4] = (short) (j + 3);
      indices[i + 5] = (short) (j + 0);
    }

    vertices = new float[VERTEX_SIZE * 6 * SIZE_BLOCKS_CUBED];
  }

  public FaceProvider faceProvider;
  public Mesh mesh;
  public boolean dirty = true;
  Vector3 offset = new Vector3();
  private int numVertices = 0;
  private Camera camera;
  private Area area;

  public AreaRenderer(Area area) {
    this.area = area;
    this.offset.set(area.minBlockX, area.minBlockY, area.minBlockZ);
    faceProvider = new FaceProvider(area);
    mesh = new Mesh(true, SIZE_BLOCKS_CUBED * 8 * 4, SIZE_BLOCKS_CUBED * 36 / 3, GraphicsHelper.vertexAttributes);
    mesh.setIndices(indices);
  }

  public static int createTop(Vector3 offset, TextureRegion region, int x, int y, int z, float[] vertices, int vertexOffset) {
    vertices[vertexOffset++] = offset.x + x;
    vertices[vertexOffset++] = offset.y + y + 1;
    vertices[vertexOffset++] = offset.z + z + 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = region.getU2();
    vertices[vertexOffset++] = region.getV2();

    vertices[vertexOffset++] = offset.x + x + 1;
    vertices[vertexOffset++] = offset.y + y + 1;
    vertices[vertexOffset++] = offset.z + z + 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = region.getU2();
    vertices[vertexOffset++] = region.getV();

    vertices[vertexOffset++] = offset.x + x + 1;
    vertices[vertexOffset++] = offset.y + y + 1;
    vertices[vertexOffset++] = offset.z + z;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = 1;
    vertices[vertexOffset++] = 0;
    vertices[vertexOffset++] = region.getU();
    vertices[vertexOffset++] = region.getV();

{'fraction_non_alphanumeric': 0.13022113022113022, 'fraction_numerical': 0.016476369417545888, 'mean_word_length': 3.9287749287749287, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6021796', 'n_tokens_mistral': 2374, 'n_tokens_neox': 2300, 'n_words': 559}