<commit_before>/*
 * Copyright 2013, <NAME>. All rights reserved.
 * If you intend to use, modify or redistribute this file contact <EMAIL>
 */

package com.elfeck.ephemeral;

import java.util.List;

import com.elfeck.ephemeral.glContext.EPHRenderContext;
import com.elfeck.ephemeral.glContext.EPHVertexArrayObject;


public class EPHemeral {

	public static final String VERSION = "0.00.1";

	private int width, height;
	private EPHSurface surface;
	private EPHRenderContext renderContext;
	private EPHRunnableContext renderJob, logicJob;
	private Thread renderThread, logicThread;

	public EPHemeral(int width, int height, int fpsCap, int lpsCap, String shaderParentPath, String title) {
		this.width = width;
		this.height = height;
		renderContext = EPHRenderContext.createRenderContext(this, Math.min(1000, Math.max(1, fpsCap)), shaderParentPath, title);
		renderThread = new Thread(renderJob = new EPHRenderJob(this, Math.max(1, (int) Math.round((1.0 / fpsCap) * 1000 - 5))), "RenderThread");
		logicThread = new Thread(logicJob = new EPHLogicJob(this, Math.max(1, (int) Math.round((1.0 / lpsCap) * 1000))), "LogicThread");
		renderThread.setPriority(Thread.MAX_PRIORITY);
		logicThread.setPriority(Thread.MIN_PRIORITY);
		surface = null;
		start();
	}
	public EPHemeral(int width, int height, String title) {
		this(width, height, 60, 1000, "shader/", title);
	}

	private void start() {
		renderThread.start();
		logicThread.start();
	}

	protected synchronized void reqLogic(long delta) {
		if (surface != null) surface.execLogic(delta);
	}

	protected synchronized void reqRender() {
		renderContext.glRender();
		if (renderContext.wasResized()) {
			width = renderContext.getWidth();
			height = renderContext.getHeight();
		}
	}

	public void updateVaos() {
		surface.updateVaos();
	}

	public void glDestroyVaos() {
		surface.destroyVaos();
		EPHVertexArrayObject.glDisposeShaderPrograms();
	}

	public synchronized void destroy() {
		renderContext.glDestroy();
		renderJob.destroy();
		logicJob.destroy();
	}

	public List<EPHVertexArrayObject> getVaos() {
		return surface.getVaos();
	}

	public void setSurface(EPHSurface surface) {
		this.surface = surface;
	}

	public EPHSurface getSurface() {
		return surface;
	}

	public void setDebug(int renderPrintDelay, int logicPrintDelay, int renderWarningThreshold, int logicWarningThreshold) {
		renderJob.setConsoleDebug(renderPrintDelay, renderWarningThreshold);
		logicJob.setConsoleDebug(logicPrintDelay, logicWarningThreshold);<commit_msg>Fixed an issue when the renderThread was faster than the thread creating and adding a surface. NPE was thrown.<commit_after>/*
 * Copyright 2013, <NAME>. All rights reserved.
 * If you intend to use, modify or redistribute this file contact <EMAIL>
 */

package com.elfeck.ephemeral;

import java.util.List;

import com.elfeck.ephemeral.glContext.EPHRenderContext;
import com.elfeck.ephemeral.glContext.EPHVertexArrayObject;


public class EPHemeral {

	public static final String VERSION = "0.00.1";

	private int width, height;
	private EPHSurface surface;
	private EPHRenderContext renderContext;
	private EPHRunnableContext renderJob, logicJob;
	private Thread renderThread, logicThread;

	public EPHemeral(int width, int height, int fpsCap, int lpsCap, String shaderParentPath, String title) {
		this.width = width;
		this.height = height;
		renderContext = EPHRenderContext.createRenderContext(this, Math.min(1000, Math.max(1, fpsCap)), shaderParentPath, title);
		renderThread = new Thread(renderJob = new EPHRenderJob(this, Math.max(1, (int) Math.round((1.0 / fpsCap) * 1000 - 5))), "RenderThread");
		logicThread = new Thread(logicJob = new EPHLogicJob(this, Math.max(1, (int) Math.round((1.0 / lpsCap) * 1000))), "LogicThread");
		renderThread.setPriority(Thread.MAX_PRIORITY);
		logicThread.setPriority(Thread.MIN_PRIORITY);
		surface = null;
		start();
	}
	public EPHemeral(int width, int height, String title) {
		this(width, height, 60, 1000, "shader/", title);
	}

	private void start() {
		renderThread.start();
		logicThread.start();
	}

	protected synchronized void reqLogic(long delta) {
		if (surface != null) surface.execLogic(delta);
	}

	protected synchronized void reqRender() {
		renderContext.glRender();
		if (renderContext.wasResized()) {
			width = renderContext.getWidth();
			height = renderContext.getHeight();
		}
	}

	public void updateVaos() {
		if (surface != null) surface.updateVaos();
	}

	public void glDestroyVaos() {
		surface.destroyVaos();
		EPHVertexArrayObject.glDisposeShaderPrograms();
	}

	public synchronized void destroy() {
		renderContext.glDestroy();
		renderJob.destroy();
		logicJob.destroy();
	}

	public List<EPHVertexArrayObject> getVaos() {
		return surface.getVaos();
	}

	public void setSurface(EPHSurface surface) {
		this.surface = surface;
	}

	public EPHSurface getSurface() {
		return surface;
	}

	public void setDebug(int renderPrintDelay, int logicPrintDelay, int renderWarningThreshold, int logicWarningThreshold) {
		renderJob.setConsoleDebug(renderPrintDelay, renderWarningThreshold);
		logicJob.setConsoleDebug(logicPrintDelay, logicWarningThreshold);
{'fraction_non_alphanumeric': 0.1122369446609509, 'fraction_numerical': 0.013250194855806703, 'mean_word_length': 5.221818181818182, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5757087', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1597, 'n_words': 400}