refactor: refactor to package me.srvstr

This commit is contained in:
Sven Vogel 2024-12-18 18:25:22 +01:00
parent 5abc9e112f
commit f5e0f68143
84 changed files with 3927 additions and 5297 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
/target/ /target/
.project
.classpath
.settings

View File

@ -0,0 +1,33 @@
package me.srvstr.bot;
/**
* A direction the bot can walk towards.
*
* @since 1.0.0
*/
public enum Direction {
NORTH, SOUTH, WEST, EAST;
/**
* Convert specific codepoints into a direction. Maps arrow lookalike
* characters such as >,<,v,^ to the directions: EAST, WEST, SOUTH, NORTH.
*
* @since 1.0.0
* @param current Character to convert.
* @return Codepoint specific direction or NORTH as default.
*/
public static Direction directionFromCodePoint(char current) {
switch (current) {
case '^':
return NORTH;
case '>':
return WEST;
case 'V':
case 'v':
return SOUTH;
case '<':
return EAST;
}
return NORTH;
}
}

View File

@ -0,0 +1,19 @@
package me.srvstr.bot;
/**
* Utility class for single precision floating point math.
*/
public class FloatUtils {
public static final float PI = 3.1415927F;
public static final float PI_HALF = 1.5707964F;
private static final float EPSILON = 0.001F;
/**
* Test whether a value is closer to zero than the specific threshold value
* of EPSILON.
*/
public static final boolean isZeroWithTolerance(float x) {
return Math.abs(x) < FloatUtils.EPSILON;
}
}

View File

@ -0,0 +1,168 @@
package me.srvstr.bot;
import me.srvstr.objects.WorldObject;
import java.awt.*;
import java.awt.geom.Point2D;
public class Gytebot extends WorldObject {
private static final float RCP_FORCE_DAMPING = 8.0F;
private Direction direction;
private Point2D.Float velocity;
private float angleVelocity;
private float viewAngle;
private boolean isReady;
public Gytebot(Point2D.Float position, Direction direction) {
super(position);
this.direction = direction;
this.velocity = new Point2D.Float();
convertDirectionToAngle(direction);
}
public Gytebot(Gytebot gytebot) {
super(new Point2D.Float());
if (gytebot != null) {
this.direction = gytebot.getDirection();
this.viewAngle = gytebot.getViewAngle();
this.angleVelocity = gytebot.getViewAngleVelocity();
this.position.x = (gytebot.getPosition()).x;
this.position.y = (gytebot.getPosition()).y;
}
}
private float getViewAngleVelocity() {
return this.angleVelocity;
}
public void updateRotation(float elapsedTime) {
this.viewAngle += this.angleVelocity * elapsedTime * Gytebot.RCP_FORCE_DAMPING;
this.angleVelocity += -this.angleVelocity * elapsedTime * Gytebot.RCP_FORCE_DAMPING;
this.position.x += this.velocity.x * elapsedTime * Gytebot.RCP_FORCE_DAMPING;
this.position.y += this.velocity.y * elapsedTime * Gytebot.RCP_FORCE_DAMPING;
this.velocity.x += -this.velocity.x * elapsedTime * Gytebot.RCP_FORCE_DAMPING;
this.velocity.y += -this.velocity.y * elapsedTime * Gytebot.RCP_FORCE_DAMPING;
this.isReady = (FloatUtils.isZeroWithTolerance(this.angleVelocity)
&& FloatUtils.isZeroWithTolerance(this.velocity.x) && FloatUtils.isZeroWithTolerance(this.velocity.y));
}
public void turnRight() {
switch (this.direction) {
case NORTH:
this.direction = Direction.WEST;
break;
case WEST:
this.direction = Direction.SOUTH;
break;
case SOUTH:
this.direction = Direction.EAST;
break;
case EAST:
this.direction = Direction.NORTH;
break;
default:
break;
}
this.angleVelocity = 1.5707964F;
this.isReady = false;
}
public void turnLeft() {
switch (this.direction) {
case NORTH:
this.direction = Direction.EAST;
break;
case EAST:
this.direction = Direction.SOUTH;
break;
case SOUTH:
this.direction = Direction.WEST;
break;
case WEST:
this.direction = Direction.NORTH;
default:
break;
}
this.angleVelocity = -1.5707964F;
this.isReady = false;
}
private void convertDirectionToAngle(Direction direction) {
switch (direction) {
case NORTH:
this.viewAngle = 1.5707964F;
break;
case SOUTH:
this.viewAngle = -1.5707964F;
break;
case EAST:
this.viewAngle = 0.0F;
break;
case WEST:
this.viewAngle = 3.1415927F;
default:
break;
}
}
public void goForward() {
switch (this.direction) {
case NORTH:
this.velocity = new Point2D.Float(0.0F, -1.0F);
break;
case SOUTH:
this.velocity = new Point2D.Float(0.0F, 1.0F);
break;
case EAST:
this.velocity = new Point2D.Float(-1.0F, 0.0F);
break;
case WEST:
this.velocity = new Point2D.Float(1.0F, 0.0F);
break;
default:
this.velocity = new Point2D.Float();
break;
}
this.isReady = false;
}
public Point getForwardLocation() {
switch (this.direction) {
case NORTH:
return new Point(Math.round(this.position.x), Math.round(this.position.y) - 1);
case SOUTH:
return new Point(Math.round(this.position.x), Math.round(this.position.y) + 1);
case EAST:
return new Point(Math.round(this.position.x) - 1, Math.round(this.position.y));
case WEST:
return new Point(Math.round(this.position.x) + 1, Math.round(this.position.y));
default:
break;
}
return null;
}
public final Direction getDirection() {
return this.direction;
}
public final float getViewAngle() {
return this.viewAngle;
}
public boolean isReady() {
return this.isReady;
}
}

View File

@ -0,0 +1,140 @@
package me.srvstr.engine;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWImage;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class Display implements AutoCloseable {
private final long handle;
private final Dimension size;
private volatile boolean requiredRebuild;
public Display(BufferedImage icon) {
this.size = Toolkit.getDefaultToolkit().getScreenSize();
this.size.width >>= 1;
this.size.height >>= 1;
GLFW.glfwDefaultWindowHints();
GLFW.glfwWindowHint(131076, 0);
GLFW.glfwWindowHint(131075, 1);
this.handle = GLFW.glfwCreateWindow(this.size.width, this.size.height, "RTX-GYTEBOT", 0L, 0L);
setWindowIcon(icon);
if (this.handle == 0L) {
throw new AssertionError("Failed to create the GLFW window!");
}
orientateWindow();
GLFW.glfwMakeContextCurrent(this.handle);
Exception exception1 = null, exception2 = null;
try {
MemoryStack frame = MemoryStack.stackPush();
try {
IntBuffer framebufferSize = frame.mallocInt(2);
GLFW.nglfwGetFramebufferSize(this.handle, MemoryUtil.memAddress(framebufferSize),
MemoryUtil.memAddress(framebufferSize) + 4L);
this.size.width = framebufferSize.get(0);
this.size.height = framebufferSize.get(1);
} finally {
if (frame != null)
frame.close();
}
} finally {
exception2 = null;
if (exception1 == null) {
exception1 = exception2;
} else if (exception1 != exception2) {
exception1.addSuppressed(exception2);
}
}
}
private void setWindowIcon(BufferedImage icon) {
byte[] data = ((DataBufferByte) icon.getRaster().getDataBuffer()).getData();
ByteBuffer pixels = BufferUtils.createByteBuffer(data.length);
pixels.put(data);
pixels.flip();
GLFWImage.Buffer gb = GLFWImage.create(1);
GLFWImage image = GLFWImage.create().set(icon.getWidth(), icon.getHeight(), pixels);
gb.put(0, image);
GLFW.glfwSetWindowIcon(this.handle, gb);
}
private void orientateWindow() {
int[] left = new int[1];
int[] top = new int[1];
int[] right = new int[1];
int[] bottom = new int[1];
GLFW.glfwGetWindowFrameSize(this.handle, left, top, right, bottom);
this.size.width = this.size.width - left[0] - right[0];
this.size.height = this.size.height - bottom[0] - top[0];
GLFW.glfwSetWindowSize(this.handle, this.size.width, this.size.height);
GLFW.glfwSetWindowPos(this.handle, right[0], top[0]);
}
public final void close() {
// this.framebufferSizeCallback.free();
GLFW.glfwDestroyWindow(this.handle);
}
public final void show() {
GLFW.glfwShowWindow(this.handle);
}
public final boolean shouldNotClose() {
return !GLFW.glfwWindowShouldClose(this.handle);
}
public final void swapBuffers() {
GLFW.glfwSwapBuffers(this.handle);
}
public final long getWindowHandle() {
return this.handle;
}
public final int getWidth() {
return this.size.width;
}
public final int getHeight() {
return this.size.height;
}
public final Dimension getSize() {
return this.size;
}
public boolean wasScaled() {
if (this.requiredRebuild) {
this.requiredRebuild = false;
return true;
}
return false;
}
}

View File

@ -0,0 +1,129 @@
package me.srvstr.engine;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import org.lwjgl.opengl.GL;
import me.srvstr.ui.UIAccess;
import me.srvstr.ui.icons.IconLoader;
import me.srvstr.view.Camera;
import me.srvstr.world.World;
public class Engine {
private GLFWErrorCallback errorCallback;
private Display display;
private Renderer renderer;
private Camera camera;
private UIAccess ui;
private World world;
private float globalTime;
private float elapsedTime;
public Engine() {
try {
this.ui = new UIAccess();
this.ui.putInfoLoadingMessage("Loading Icon set...", 10);
IconLoader.loadIcons();
GLFW.glfwSetErrorCallback((GLFWErrorCallbackI) (this.errorCallback = GLFWErrorCallback.createPrint(System.err)));
this.ui.putInfoLoadingMessage("Initalizing GLFW...", 25);
if (!GLFW.glfwInit()) {
throw new AssertionError("Could not initalize GLFW!");
}
this.ui.putInfoLoadingMessage("Creating GLFW window...", 50);
this.display = new Display(this.ui.getWindowIcon());
GLFW.glfwSwapInterval(1);
GL.createCapabilities();
this.ui.putInfoLoadingMessage("Creating Shaders...", 65);
this.renderer = new Renderer(this.display.getSize());
this.ui.putInfoLoadingMessage("Setting up window callbacks", 80);
this.camera = new Camera(this.display.getWindowHandle());
this.ui.putInfoLoadingMessage("Creating World...", 90);
this.world = new World();
this.ui.putInfoLoadingMessage("Done", 100);
} catch (Exception e) {
e.printStackTrace();
} finally {
this.ui.close();
}
}
public final void run() {
try {
this.ui.apply(this.world, this.renderer.getPpConfig());
this.display.show();
// this.ui.openDocs();
while (this.display.shouldNotClose() && !this.ui.windowCloseRequest()) {
long startTime = System.currentTimeMillis();
GLFW.glfwPollEvents();
if (this.world.getGytebot() != null) {
this.world.getGytebot().updateRotation(this.elapsedTime);
}
this.camera.update(this.elapsedTime);
this.renderer.update(this.display.getSize(), this.globalTime, this.camera, this.world,
this.display.wasScaled());
this.renderer.render();
this.display.swapBuffers();
long passedTime = System.currentTimeMillis() - startTime;
if (passedTime < 16L) {
Thread.sleep(16L - passedTime);
}
this.elapsedTime = (float) (System.currentTimeMillis() - startTime) * 0.001F;
this.globalTime += this.elapsedTime;
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
close();
}
}
private final void close() {
try {
this.errorCallback.free();
this.camera.close();
this.display.close();
this.renderer.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
GLFW.glfwTerminate();
System.exit(0);
}
}
public static void main(String[] args) {
(new Engine()).run();
}
}

View File

@ -0,0 +1,133 @@
package me.srvstr.engine;
import java.awt.Dimension;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30C;
import me.srvstr.renderer.FBO;
import me.srvstr.renderer.PostProcessConfig;
import me.srvstr.renderer.PostProcessor;
import me.srvstr.renderer.SceneRenderer;
import me.srvstr.view.Camera;
import me.srvstr.world.World;
public class Renderer
implements AutoCloseable {
private static final float[] QUAD_VERTICES = new float[] { -1.0F, 1.0F, 1.0F, 1.0F, 1.0F, -1.0F, 1.0F, -1.0F, -1.0F,
-1.0F, 1.0F };
private static final int DRAW_COUNT = QUAD_VERTICES.length >> 1;
private int arrayBufferHandle;
private PostProcessConfig ppConfig;
private PostProcessor postProcessor;
private SceneRenderer sceneRenderer;
private FBO fbo;
private Dimension size;
public Renderer(Dimension size) throws AssertionError {
this.ppConfig = new PostProcessConfig();
createQuadGeometry();
GL11.glEnable(3553);
this.sceneRenderer = new SceneRenderer();
this.postProcessor = new PostProcessor();
this.fbo = new FBO(size);
this.size = size;
}
private void createQuadGeometry() {
this.arrayBufferHandle = GL15.glGenBuffers();
FloatBuffer buffer = BufferUtils.createFloatBuffer(QUAD_VERTICES.length);
buffer.put(QUAD_VERTICES);
buffer.flip();
GL15.glBindBuffer(34962, this.arrayBufferHandle);
GL15.glBufferData(34962, buffer, 35044);
GL15.glBindBuffer(34962, 0);
buffer.clear();
}
public void update(Dimension size, float globalTime, Camera camera, World world, boolean rebuildFBO) {
if (rebuildFBO) {
this.fbo.recreate(size);
}
this.sceneRenderer.bind();
this.sceneRenderer.loadUniformData(size, globalTime, camera, world);
}
public final void render() {
renderSceneToFBO();
renderFBOtoScreen();
}
private void renderFBOtoScreen() {
GL11.glEnableClientState(32884);
GL15.glBindBuffer(34962, this.arrayBufferHandle);
GL11.glVertexPointer(2, 5126, 0, 0L);
this.postProcessor.bind();
this.postProcessor.loadData(this.size, this.fbo, this.ppConfig);
GL11.glDrawArrays(4, 0, DRAW_COUNT);
this.postProcessor.unbind();
GL15.glBindBuffer(34962, 0);
GL30C.glBindVertexArray(0);
GL11.glDisableClientState(32884);
}
private void renderSceneToFBO() {
GL11.glEnableClientState(32884);
GL15.glBindBuffer(34962, this.arrayBufferHandle);
GL11.glVertexPointer(2, 5126, 0, 0L);
this.fbo.bind();
GL11.glDrawArrays(4, 0, DRAW_COUNT);
this.fbo.unbind();
GL15.glBindBuffer(34962, 0);
GL30C.glBindVertexArray(0);
GL20.glUseProgram(0);
GL11.glDisableClientState(32884);
}
public void close() throws Exception {
GL15.glDeleteBuffers(this.arrayBufferHandle);
this.sceneRenderer.close();
this.postProcessor.close();
this.fbo.close();
}
public final PostProcessConfig getPpConfig() {
return this.ppConfig;
}
}

View File

@ -0,0 +1,85 @@
package me.srvstr.logic;
import me.srvstr.run.ForcedStopException;
import me.srvstr.world.World;
public class GyteController {
private World world;
private int coinCount;
public GyteController(World world) {
this.world = world;
}
public final void turnRight() throws ForcedStopException {
this.world.getGytebot().turnRight();
waitForGytebotApprove();
}
public final void turnLeft() throws ForcedStopException {
this.world.getGytebot().turnLeft();
waitForGytebotApprove();
}
public final void goForward() throws ForcedStopException {
if (!this.world.isLocationObstructed(this.world.getGytebot().getForwardLocation())) {
this.world.getGytebot().goForward();
}
waitForGytebotApprove();
}
public final void pickup() throws ForcedStopException {
if (this.world.isCoinPlacedHere(this.world.getGytebot().getPosition())) {
this.world.removeObject(Math.round((this.world.getGytebot().getPosition()).x),
Math.round((this.world.getGytebot().getPosition()).y));
this.coinCount++;
}
delay();
}
private void delay() throws ForcedStopException {
try {
Thread.sleep(250L);
} catch (InterruptedException e) {
throw new ForcedStopException();
}
}
public final void place() throws ForcedStopException {
if (this.coinCount > 0) {
this.world.setCoin(Math.round((this.world.getGytebot().getPosition()).x),
Math.round((this.world.getGytebot().getPosition()).y));
this.coinCount--;
}
delay();
}
private void waitForGytebotApprove() throws ForcedStopException {
while (!this.world.getGytebot().isReady()) {
try {
Thread.sleep(30L);
} catch (InterruptedException e) {
throw new ForcedStopException();
}
}
}
public final boolean hasWallFront() throws ForcedStopException {
return this.world.isLocationObstructed(this.world.getGytebot().getForwardLocation());
}
public final boolean isOnCoin() throws ForcedStopException {
return this.world.isCoinPlacedHere(this.world.getGytebot().getPosition());
}
public final int getCoinCount() throws ForcedStopException {
return this.coinCount;
}
}

View File

@ -0,0 +1,71 @@
package me.srvstr.logic;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JOptionPane;
import me.srvstr.ui.editors.code.CodeEditor;
public class GyteProcessor
extends Thread {
private GyteController gyteController;
private CodeEditor editor;
private Program program;
public GyteProcessor(GyteController gyteController, CodeEditor editor) {
this.gyteController = gyteController;
this.editor = editor;
}
public void run() {
this.editor.setProgramStatus(true);
try {
this.program.getMainMethod().invoke(this.program.getProgram(), new Object[] { this.gyteController });
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
if (!(e.getCause() instanceof me.srvstr.run.ForcedStopException)) {
System.err.println("The Gyte-Processors Thread did not respond in time and killed");
}
}
System.out.println("> Gyte-Processor has finished");
this.editor.setProgramStatus(false);
}
public void dispatchProgram(Program program) {
this.program = program;
synchronized (this) {
start();
}
}
public void halt() {
interrupt();
try {
join(2000L);
if (isAlive()) {
stop();
}
} catch (InterruptedException interruptedException) {
} catch (SecurityException death)
{
JOptionPane.showMessageDialog(null, "The Thread running GYTEBOTS code needed to be stopped by ThreadDeath",
"Error - stopping Thread", 0);
}
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/logic/GyteProcessor.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,21 @@
package me.srvstr.logic;
import java.lang.reflect.Method;
public class Program {
private Object program;
private Method mainMethod;
public Program(Object program, Method mainMethod) {
this.program = program;
this.mainMethod = mainMethod;
}
public final Object getProgram() {
return this.program;
}
public final Method getMainMethod() {
return this.mainMethod;
}
}

View File

@ -0,0 +1,10 @@
package me.srvstr.objects;
import java.awt.geom.Point2D;
public class Coin extends WorldObject {
public Coin(Point2D.Float position) {
super(position);
}
}

View File

@ -0,0 +1,10 @@
package me.srvstr.objects;
import java.awt.geom.Point2D;
public class Wall extends WorldObject {
public Wall(Point2D.Float position) {
super(position);
}
}

View File

@ -0,0 +1,22 @@
package me.srvstr.objects;
import java.awt.geom.Point2D;
/**
* Abstract class of any object that can exist in a world.
*/
public abstract class WorldObject {
protected Point2D.Float position;
public WorldObject(Point2D.Float position) {
this.position = position;
}
public final Point2D.Float getPosition() {
return this.position;
}
public final void setPosition(Point2D.Float position) {
this.position = position;
}
}

View File

@ -0,0 +1,67 @@
package me.srvstr.renderer;
import java.awt.Dimension;
import java.nio.ByteBuffer;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL32C;
public class FBO
implements AutoCloseable {
private int fboHandle;
private int fboTexture;
public FBO(Dimension size) {
generate(size);
unbind();
}
private void generate(Dimension size) {
this.fboHandle = GL30C.glGenFramebuffers();
this.fboTexture = GL11C.glGenTextures();
GL11C.glBindTexture(3553, this.fboTexture);
GL11C.glTexImage2D(3553, 0, 34836, size.width, size.height, 0, 6408, 5126, (ByteBuffer) null);
GL11C.glTexParameteri(3553, 10240, 9729);
GL11C.glTexParameteri(3553, 10241, 9729);
GL30C.glBindFramebuffer(36160, this.fboHandle);
GL32C.glFramebufferTexture(36160, 36064, this.fboTexture, 0);
}
public final void recreate(Dimension size) {
GL30C.glDeleteFramebuffers(this.fboHandle);
GL11C.glDeleteTextures(this.fboTexture);
generate(size);
}
public final void bind() {
GL11C.glBindTexture(3553, 0);
GL30C.glBindFramebuffer(36160, this.fboHandle);
}
public final void unbind() {
GL30C.glBindFramebuffer(36160, 0);
}
public int getTextureHandle() {
return this.fboTexture;
}
public final void close() {
GL30C.glDeleteFramebuffers(this.fboHandle);
GL11C.glDeleteTextures(this.fboTexture);
}
}
/*
* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/renderer/FBO.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,51 @@
package me.srvstr.renderer;
public class PostProcessConfig {
private boolean filterDoF = true;
private boolean filterFXAA = true;
private boolean filterGrain = true;
public final boolean isFilterGrain() {
return this.filterGrain;
}
public final void setFilterGrain(boolean filterGrain) {
this.filterGrain = filterGrain;
}
public final boolean isFilterDoF() {
return this.filterDoF;
}
public final void setFilterDoF(boolean filterDoF) {
this.filterDoF = filterDoF;
}
public final boolean isFilterFXAA() {
return this.filterFXAA;
}
public final void setFilterFXAA(boolean filterFXAA) {
this.filterFXAA = filterFXAA;
}
public int getFilterFXAAAsInteger() {
return this.filterFXAA ? 1 : 0;
}
public int getFilterGrainAsInteger() {
return this.filterGrain ? 1 : 0;
}
public int getFilterDoFAsInteger() {
return this.filterDoF ? 1 : 0;
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/renderer/PostProcessConfig.
* class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,50 @@
package me.srvstr.renderer;
import java.awt.Dimension;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL20C;
import me.srvstr.shader.ShaderProgram;
public class PostProcessor
extends ShaderProgram {
private int fboTextureLocation;
private int resolutionLocation;
private int useFXAALocation;
private int useDoFLocation;
private int useGrainLocation;
public PostProcessor() throws AssertionError {
super("/data/shader/PostProcessor");
this.fboTextureLocation = GL20C.glGetUniformLocation(this.program, "fboTexture");
this.resolutionLocation = GL20C.glGetUniformLocation(this.program, "resolution");
this.useFXAALocation = GL20C.glGetUniformLocation(this.program, "boolFilterFXAA");
this.useDoFLocation = GL20C.glGetUniformLocation(this.program, "boolFilterDoF");
this.useGrainLocation = GL20C.glGetUniformLocation(this.program, "boolFilterGrain");
}
public void loadData(Dimension size, FBO fbo, PostProcessConfig config) {
GL20C.glUniform2f(this.resolutionLocation, size.width, size.height);
GL20C.glUniform1i(this.useFXAALocation, config.getFilterFXAAAsInteger());
GL20C.glUniform1i(this.useDoFLocation, config.getFilterDoFAsInteger());
GL20C.glUniform1i(this.useGrainLocation, config.getFilterGrainAsInteger());
GL13C.glActiveTexture(33984);
GL11C.glBindTexture(3553, fbo.getTextureHandle());
GL20C.glUniform1i(this.fboTextureLocation, 0);
}
public final void close() {
super.close();
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/renderer/PostProcessor.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,190 @@
package me.srvstr.renderer;
import java.awt.Dimension;
import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL15C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL43C;
import me.srvstr.shader.ShaderProgram;
import me.srvstr.textures.Texture;
import me.srvstr.view.Camera;
import me.srvstr.world.World;
public class SceneRenderer
extends ShaderProgram {
public static final String[] UNIFORM_NAMES = new String[] {
"resolution",
"time",
"cameraRotation",
"cameraZoom",
"worldTexture",
"environmentTexture",
"coinTexture",
"width",
"height",
"drawGytebot",
"gytebotLocation",
"gytebotRotation" };
private Texture worldTexture;
private Texture environmentTexture;
private Texture coinTexture;
private Texture testTexture;
private int coinBuffer;
private int coinSsbo;
private int wallBuffer;
private int wallSsbo;
private Map<String, Integer> uniformLocations;
public SceneRenderer() throws AssertionError {
super("/data/shader/SceneRenderer");
this.uniformLocations = new HashMap<>();
this.coinSsbo = GL15C.glGenBuffers();
this.wallSsbo = GL15C.glGenBuffers();
createUniforms();
try {
createTextures();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Unable to load texture(s)", "Error - loading textures", 0);
e.printStackTrace();
}
}
private void createTextures() throws Exception {
this.worldTexture = new Texture("data/icons/atlas.png");
this.environmentTexture = new Texture("data/icons/environment.png");
this.coinTexture = new Texture("data/icons/coin.png");
this.testTexture = new Texture("data/icons/test.png");
}
private void createUniforms() {
byte b;
int i;
String[] arrayOfString;
for (i = (arrayOfString = UNIFORM_NAMES).length, b = 0; b < i;) {
String uniformName = arrayOfString[b];
int location = GL20C.glGetUniformLocation(this.program, uniformName);
if (location == -1) {
System.err.println("Unable to find uniform: " + uniformName);
}
this.uniformLocations.put(uniformName, Integer.valueOf(location));
b++;
}
GL20C.glUseProgram(this.program);
IntBuffer props = BufferUtils.createIntBuffer(1);
IntBuffer params = BufferUtils.createIntBuffer(1);
props.put(0, 37634);
int coinBufferResourceIndex = GL43C.glGetProgramResourceIndex(this.program, 37606, "CoinBuffer");
int wallBufferResourceIndex = GL43C.glGetProgramResourceIndex(this.program, 37606, "WallBuffer");
GL43C.glGetProgramResourceiv(this.program, 37606, coinBufferResourceIndex, props, null, params);
this.coinBuffer = params.get(0);
GL43C.glGetProgramResourceiv(this.program, 37606, wallBufferResourceIndex, props, null, params);
this.wallBuffer = params.get(0);
GL20C.glUseProgram(0);
}
public void loadUniformData(Dimension size, float globalTime, Camera camera, World world) {
if (world.updateCoinTextureData()) {
GL15C.glBindBuffer(34962, this.coinSsbo);
GL15C.glBufferData(34962, world.getCoinTextureData(), 35044);
GL15C.glBindBuffer(34962, 0);
}
if (world.updateWallBufferData()) {
GL15C.glBindBuffer(34962, this.wallSsbo);
GL15C.glBufferData(34962, world.getWallBufferData(), 35044);
GL15C.glBindBuffer(34962, 0);
}
GL20C.glUniform2f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[0])).intValue(), size.width, size.height);
GL20C.glUniform1f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[1])).intValue(), globalTime);
GL20C.glUniform2f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[2])).intValue(), camera.getCameraRotationX(),
camera.getCameraRotationY());
GL20C.glUniform1f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[3])).intValue(), camera.getCameraZoom());
GL13C.glActiveTexture(33984);
GL11C.glBindTexture(3553, this.worldTexture.getHandle());
GL20C.glUniform1i(((Integer) this.uniformLocations.get(UNIFORM_NAMES[4])).intValue(), 0);
GL13C.glActiveTexture(33985);
GL11C.glBindTexture(3553, this.environmentTexture.getHandle());
GL20C.glUniform1i(((Integer) this.uniformLocations.get(UNIFORM_NAMES[5])).intValue(), 1);
GL13C.glActiveTexture(33986);
GL11C.glBindTexture(3553, this.coinTexture.getHandle());
GL20C.glUniform1i(((Integer) this.uniformLocations.get(UNIFORM_NAMES[6])).intValue(), 2);
GL13C.glActiveTexture(33987);
GL11C.glBindTexture(3553, this.testTexture.getHandle());
GL20C.glUniform1i(GL20C.glGetUniformLocation(this.program, "testTexture"), 3);
GL20C.glUniform1f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[7])).intValue(), world.getWidth());
GL20C.glUniform1f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[8])).intValue(), world.getHeight());
GL20C.glUniform1i(((Integer) this.uniformLocations.get(UNIFORM_NAMES[9])).intValue(), world.getDrawGytebotAsInt());
if (world.getGytebot() != null) {
GL20C.glUniform2f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[10])).intValue(),
(world.getGytebot().getPosition()).x, (world.getGytebot().getPosition()).y);
GL20C.glUniform1f(((Integer) this.uniformLocations.get(UNIFORM_NAMES[11])).intValue(),
world.getGytebot().getViewAngle());
}
}
public void bind() {
super.bind();
GL30C.glBindBufferBase(37074, this.coinBuffer, this.coinSsbo);
GL30C.glBindBufferBase(37074, this.wallBuffer, this.wallSsbo);
}
public void unbind() {
super.unbind();
GL30C.glBindBufferBase(37074, this.coinBuffer, 0);
GL30C.glBindBufferBase(37074, this.wallBuffer, 0);
}
public final void close() {
super.close();
GL15C.glDeleteBuffers(this.coinSsbo);
GL15C.glDeleteBuffers(this.coinSsbo);
this.worldTexture.close();
this.environmentTexture.close();
this.coinTexture.close();
}
}

View File

@ -0,0 +1,10 @@
package me.srvstr.run;
public class ForcedStopException
extends Exception {
private static final long serialVersionUID = -5622884875009979898L;
public ForcedStopException() {
super("The running thread needed to be stopped violently, no excusses");
}
}

View File

@ -0,0 +1,187 @@
package me.srvstr.run;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.util.Arrays;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import me.srvstr.logic.GyteController;
import me.srvstr.logic.GyteProcessor;
import me.srvstr.logic.Program;
import me.srvstr.ui.debug.Console;
import me.srvstr.ui.debug.Entry;
import me.srvstr.ui.editors.code.CodeEditor;
import me.srvstr.world.World;
public class GyteCompiler {
private static final String CLASS_NAME = "GyteProgram";
private static final String METHOD_NAME = "run";
private static final boolean SUCCESS = true;
private volatile GyteProcessor processor;
private World world;
private CodeEditor editor;
private Console console;
private File[] file;
private JavaCompiler compiler;
private StandardJavaFileManager fileManager;
private Iterable<? extends JavaFileObject> compilationUnits;
private DiagnosticCollector<JavaFileObject> diagnostics;
private boolean isCompilerInstalled;
public GyteCompiler(World world, Console console, CodeEditor editor) {
this.world = world;
this.console = console;
this.editor = editor;
this.compiler = ToolProvider.getSystemJavaCompiler();
this.isCompilerInstalled = (this.compiler != null);
if (this.isCompilerInstalled) {
this.fileManager = this.compiler.getStandardFileManager(null, null, null);
} else {
console.createLog("No Java Compiler could be found on this system\n", Entry.WARNING);
console.createLog("See README.MD for futher instructions/help\n", Entry.WARNING);
}
System.setOut(console.getStdOut());
System.setErr(console.getStdErr());
}
public final void compileAndRunProgram(String source) {
this.console.createLog("Compiling source...\n", Entry.INFORMATION);
Path temp = Paths.get(System.getProperty("java.io.tmpdir"), new String[] { "GyteProgram" });
try {
Files.createDirectories(temp, (FileAttribute<?>[]) new FileAttribute[0]);
Path javaSourceFile = Paths.get(temp.normalize().toAbsolutePath().toString(),
new String[] { "GyteProgram.java" });
Files.write(javaSourceFile, source.getBytes(), new java.nio.file.OpenOption[0]);
compile(javaSourceFile, temp);
Path classFile = Paths.get(temp.normalize().toAbsolutePath().toString(), new String[] { "GyteProgram.class" });
if (Files.exists(classFile, new java.nio.file.LinkOption[0])) {
Files.delete(classFile);
}
Files.delete(javaSourceFile);
Files.delete(temp);
} catch (IOException e1) {
this.console.createLog("Unable to find or edit \"java.io.tmpdir\": " + temp.toString() + "\n", Entry.ERROR);
}
}
private void compile(Path javaSourceFile, Path temp) {
this.file = new File[] { javaSourceFile.toFile() };
this.compilationUnits = this.fileManager.getJavaFileObjectsFromFiles(Arrays.asList(this.file));
this.diagnostics = new DiagnosticCollector<>();
JavaCompiler.CompilationTask task = this.compiler.getTask(null, this.fileManager, this.diagnostics, null, null,
this.compilationUnits);
boolean compilationStatus = task.call().booleanValue();
for (Diagnostic<?> diagnostic : this.diagnostics.getDiagnostics()) {
this.console
.createLog(
String.format("Error in line: %d\nat: %s\n%s\n\n", new Object[] {
Long.valueOf(diagnostic.getLineNumber()), diagnostic.getSource(), diagnostic.getMessage(null) }),
Entry.ERROR);
this.editor.markLine((int) diagnostic.getLineNumber());
}
if (compilationStatus) {
runProgram(temp);
}
try {
this.fileManager.close();
} catch (IOException e) {
this.console.createLog("The compiler's file resources could not be deleted\n", Entry.ERROR);
}
}
private void runProgram(Path temp) {
try {
ClassLoader classLoader = getClass().getClassLoader();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { temp.toUri().toURL() }, classLoader);
try {
Class<?> javaDemoClass = urlClassLoader.loadClass("GyteProgram");
try {
Object instance = javaDemoClass.getConstructor(new Class[0]).newInstance(new Object[0]);
Method method = instance.getClass().getMethod("run", new Class[] { GyteController.class });
if (this.processor != null && this.processor.isAlive()) {
this.processor.halt();
this.console.createLog("A processor was still running, an was thus shutdown\n", Entry.WARNING);
}
this.processor = new GyteProcessor(new GyteController(this.world), this.editor);
this.processor.dispatchProgram(new Program(instance, method));
this.console.createLog("Dispatching program...\n", Entry.INFORMATION);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
urlClassLoader.close();
} catch (ClassNotFoundException e1) {
this.console.createLog("The required Class \"GyteProgram\" was not defined or could not be compiled.\n",
Entry.ERROR);
} catch (NoSuchMethodException e1) {
this.console.createLog("The required Method \"run\"\nin type \"GyteProgram\" was not defined.\n", Entry.ERROR);
} catch (SecurityException e1) {
this.console.createLog("Security violation detected.", Entry.ERROR);
} catch (IOException e) {
this.console.createLog("Unable to close class loader", Entry.ERROR);
}
} catch (MalformedURLException e) {
this.console.createLog("The class file(s) URL was invalid!\n", Entry.ERROR);
}
}
public final GyteProcessor getProcessor() {
return this.processor;
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/run/GyteCompiler.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,46 @@
package me.srvstr.shader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.lwjgl.opengl.GL20C;
public class Shader
implements AutoCloseable {
private int shaderHandle;
public Shader(String fileName, int shaderType) throws AssertionError {
this.shaderHandle = GL20C.glCreateShader(shaderType);
GL20C.glShaderSource(this.shaderHandle, getSource(fileName));
GL20C.glCompileShader(this.shaderHandle);
if (GL20C.glGetShaderi(this.shaderHandle, 35713) == 0) {
System.err.println(GL20C.glGetShaderInfoLog(this.shaderHandle));
throw new AssertionError("Could not compile Shader: " + fileName);
}
}
private String getSource(String fileName) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResource(fileName).openStream()));
String result = reader.lines().reduce("", (A, B) -> String.valueOf(A) + B + System.lineSeparator());
reader.close();
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public final int getHandle() {
return this.shaderHandle;
}
public void close() {
GL20C.glDeleteShader(this.shaderHandle);
}
}

View File

@ -0,0 +1,51 @@
package me.srvstr.shader;
import org.lwjgl.opengl.GL20C;
public class ShaderProgram
implements AutoCloseable {
protected int program;
private Shader vertexShader;
private Shader fragmentShader;
public ShaderProgram(String shaderName) throws AssertionError {
this.program = GL20C.glCreateProgram();
this.vertexShader = new Shader(String.valueOf(shaderName) + ".vsh.glsl", 35633);
this.fragmentShader = new Shader(String.valueOf(shaderName) + ".fsh.glsl", 35632);
GL20C.glAttachShader(this.program, this.vertexShader.getHandle());
GL20C.glAttachShader(this.program, this.fragmentShader.getHandle());
GL20C.glBindAttribLocation(this.program, 0, "vertexPosition");
GL20C.glLinkProgram(this.program);
if (GL20C.glGetProgrami(this.program, 35714) == 0) {
System.err.println(GL20C.glGetProgramInfoLog(this.program));
throw new AssertionError("Unable to create shader program");
}
GL20C.glValidateProgram(this.program);
if (GL20C.glGetProgrami(this.program, 35715) == 0) {
System.err.println(GL20C.glGetProgramInfoLog(this.program));
throw new AssertionError("Unable to create shader program");
}
}
public void bind() {
GL20C.glUseProgram(this.program);
}
public void close() {
GL20C.glDeleteProgram(this.program);
this.vertexShader.close();
this.fragmentShader.close();
}
public void unbind() {
GL20C.glUseProgram(0);
}
}

View File

@ -0,0 +1,71 @@
package me.srvstr.textures;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL30C;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidParameterException;
public class Texture implements AutoCloseable {
private int textureHandle;
public Texture(String resource) throws Exception {
final BufferedImage image = loadImageDataAsARGB(resource);
final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
// generate OpenGL texture buffer
this.textureHandle = GL11C.glGenTextures();
GL11C.glBindTexture(GL11C.GL_TEXTURE_2D, this.textureHandle);
GL11C.glPixelStorei(3317, 1);
GL11C.glTexParameteri(3553, 10241, 9987);
GL11C.glTexParameteri(3553, 10240, 9729);
GL11C.glTexParameteri(3553, 10242, 10497);
GL11C.glTexParameteri(3553, 10243, 10497);
GL11C.glTexImage2D(3553, 0, 6408, image.getWidth(), image.getHeight(), 0, 6408, 5121, pixels);
GL30C.glGenerateMipmap(3553);
GL11C.glBindTexture(3553, 0);
}
/**
* Load image from disk as array of colors in ARGB format
*
* @param resource file path to load
* @return array of ARGB values
*/
private BufferedImage loadImageDataAsARGB(String resource) throws Exception {
InputStream stream = Texture.class.getClassLoader().getResourceAsStream(resource);
if (stream == null)
throw new InvalidParameterException("Resource not found: " + resource);
// buffer raw image data
BufferedImage rawData = ImageIO.read(stream);
// create buffer of fixed color layout of ARGB-Bytes
BufferedImage layoutedData = new BufferedImage(rawData.getWidth(), rawData.getHeight(),
BufferedImage.TYPE_INT_ARGB);
// write raw image data into buffer with known color format
layoutedData.createGraphics().drawImage(rawData, 0, 0, null);
return layoutedData;
}
public final int getHandle() {
return this.textureHandle;
}
public void close() {
GL11C.glDeleteTextures(this.textureHandle);
}
}

View File

@ -0,0 +1,54 @@
package me.srvstr.ui;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
public class Documentation
extends JFrame {
private static final long serialVersionUID = 4741160972916811991L;
private JEditorPane textPane;
public Documentation() {
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
this.textPane = new JEditorPane();
this.textPane.setContentType("text/html");
this.textPane.setEditable(false);
loadDocsFromFile();
setTitle("RTX-GYTEBOT - Documentation (also README)");
getContentPane().add(new JScrollPane(this.textPane));
setSize(size.width * 3 >> 2, size.height * 3 >> 2);
setLocationRelativeTo(null);
setVisible(true);
}
private void loadDocsFromFile() {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(getClass().getResourceAsStream("/data/docs.html")));
this.textPane.setText(reader.lines().reduce("", (A, B) -> String.valueOf(A) + B + "\n"));
reader.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Could not open or read the deocumentation", "Error - documentation", 0);
e.printStackTrace();
}
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/Documentation.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,84 @@
package me.srvstr.ui;
import com.formdev.flatlaf.FlatDarkLaf;
import me.srvstr.renderer.PostProcessConfig;
import me.srvstr.ui.editors.code.CodeEditor;
import me.srvstr.ui.editors.map.MapEditor;
import me.srvstr.ui.icons.IconLoader;
import me.srvstr.world.World;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class UIAccess
implements AutoCloseable {
private JFrame startUpWindow;
private JProgressBar infoLog;
private Documentation docs;
private MapEditor mapEditor;
private CodeEditor codeEditor;
private BufferedImage windowIcon;
public UIAccess() {
try {
this.windowIcon = IconLoader.loadWindowIcon();
if (!FlatDarkLaf.setup()) {
}
this.infoLog = new JProgressBar(0, 0, 100);
this.infoLog.setStringPainted(true);
this.startUpWindow = new JFrame("RTX-GYTEBOT");
this.startUpWindow.setIconImage(this.windowIcon);
this.startUpWindow.setUndecorated(true);
this.startUpWindow.setDefaultCloseOperation(0);
this.startUpWindow.getContentPane().setLayout(new BorderLayout());
this.startUpWindow.getContentPane().add(
new JLabel(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/data/icons/startup.png")))), "Center");
this.startUpWindow.getContentPane().add(this.infoLog, "South");
this.startUpWindow.pack();
this.startUpWindow.setLocationRelativeTo(null);
this.startUpWindow.setVisible(true);
} catch (IOException | NullPointerException e) {
this.startUpWindow.dispose();
throw new AssertionError("Unable to load or find startup image");
}
}
public final boolean windowCloseRequest() {
return !(!this.mapEditor.getWindowCloseRequest() && !this.codeEditor.getWindowCloseRequest());
}
public final void apply(World world, PostProcessConfig postProcessConfig) {
this.mapEditor = new MapEditor(world);
this.mapEditor.setIconImage(this.windowIcon);
this.codeEditor = new CodeEditor(world, postProcessConfig);
this.codeEditor.setIconImage(this.windowIcon);
}
public final void openDocs() {
this.docs = new Documentation();
}
public void putInfoLoadingMessage(String message, int progress) {
this.infoLog.setString(message);
this.infoLog.setValue(progress);
}
public final void close() {
this.startUpWindow.setVisible(false);
this.startUpWindow.dispose();
}
public BufferedImage getWindowIcon() {
return this.windowIcon;
}
}

View File

@ -0,0 +1,18 @@
package me.srvstr.ui;
import java.awt.Color;
public class UIConfig {
public static final int GUI_SCALE = 28;
public static final int MAP_FONT_SIZE = 24;
public static final int CODE_FONT_SIZE = 16;
public static final int CONSOLE_FONT_SIZE = 14;
public static final int INFORMATION_FONT_SIZE = 12;
public static final String DEFAULT_FONT = "Consolas";
public static final String DEFAULT_WINDOW_TITLE = "RTX-GYTEBOT";
public static final int CONSOLE_QUEUE_SIZE = 36;
public static final int CONSOLE_ENTRY_SIZE = 48;
public static final long MIN_FRAME_TIME_LIMIT = 16L;
public static final Color CONTENT_BACKGROUND = new Color(15921131);
}

View File

@ -0,0 +1,30 @@
package me.srvstr.ui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class UICreator {
public static JButton createIconifiedButton(char iconCharacterCode) {
final JButton button = new JButton(String.valueOf(iconCharacterCode));
button.setFont(new Font("RTX-GYTEBOT-ICONS", 0, 28));
button.setFocusPainted(false);
button.setContentAreaFilled(false);
button.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 10));
button.setOpaque(false);
button.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent event) {
button.setCursor(new Cursor(12));
}
public void mouseExited(MouseEvent event) {
button.setCursor(new Cursor(0));
}
});
return button;
}
}

View File

@ -0,0 +1,164 @@
package me.srvstr.ui.debug;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.io.PrintStream;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import me.srvstr.ui.UICreator;
public class Console
extends JPanel {
private static final long serialVersionUID = -1800165403047521827L;
private JPanel consoleLogger;
private JScrollPane scrollPane;
private JPanel toolBar;
private JButton clear;
private JLabel queueSize;
private JLabel info;
private ConsoleWriteStream stdout;
private ConsoleWriteStream stderr;
private Entry lastEntry = Entry.NORMAL;
public Console() {
setLayout(new BorderLayout());
createUI();
setupUI();
createListener();
createWriteStreams();
add(this.scrollPane, "Center");
add(this.toolBar, "North");
createLog("Console was created successfully\n", Entry.INFORMATION);
}
private void createListener() {
this.clear.addActionListener(e -> {
this.consoleLogger.removeAll();
this.consoleLogger.revalidate();
this.consoleLogger.repaint();
this.queueSize.setText("| Elements: (none)");
this.info.setText((String) null);
});
}
private void setupUI() {
this.consoleLogger.setLayout(new BoxLayout(this.consoleLogger, 1));
this.info.setForeground(Color.YELLOW);
this.clear.setToolTipText(
"Clear the console logger's buffer.\nThis means deleting all current log entries in the console.");
this.scrollPane.setVerticalScrollBarPolicy(22);
this.scrollPane.setHorizontalScrollBarPolicy(30);
this.scrollPane.setAutoscrolls(true);
this.toolBar.add(new JLabel("Console"));
this.toolBar.add(this.clear);
this.toolBar.add(this.queueSize);
this.toolBar.add(this.info);
}
private void createUI() {
this.toolBar = new JPanel(new FlowLayout(0, 4, 0));
this.consoleLogger = new JPanel();
this.scrollPane = new JScrollPane(this.consoleLogger);
this.clear = UICreator.createIconifiedButton('c');
this.queueSize = new JLabel();
this.info = new JLabel();
}
private void createWriteStreams() {
this.stdout = new ConsoleWriteStream(this, Entry.NORMAL);
this.stderr = new ConsoleWriteStream(this, Entry.ERROR);
}
public final synchronized void createLog(String message, Entry entryType) {
JTextArea lastLog = getLastEntryLog();
if (this.lastEntry == entryType && lastLog != null && (int) lastLog.getText().lines().count() < 48) {
lastLog.setText(String.format("%s%s", new Object[] { lastLog.getText(), message }));
this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
this.scrollPane.repaint();
} else {
boolean isQueueFull = ((this.consoleLogger.getComponents()).length > 36);
this.info.setText(isQueueFull ? "Elements were deleted form Console buffer due to limited queue size" : null);
if (isQueueFull) {
this.consoleLogger.remove(this.consoleLogger.getComponents()[0]);
}
createBasicConsoleLog(message, Entry.getColorByEnum(entryType));
}
this.lastEntry = entryType;
}
private JTextArea getLastEntryLog() {
int elementIndex = (this.consoleLogger.getComponents()).length - 1;
if (elementIndex < 0) {
return null;
}
return (JTextArea) this.consoleLogger.getComponents()[elementIndex];
}
private void createBasicConsoleLog(String message, Color color) {
JTextArea messageBlock = new JTextArea(message);
messageBlock.setBorder(BorderFactory.createEmptyBorder());
messageBlock.setFont(new Font("Consolas", 0, 14));
messageBlock.setEditable(false);
messageBlock.setBackground(new Color(1579032));
messageBlock.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.DARK_GRAY));
messageBlock.setForeground(color);
this.consoleLogger.add(messageBlock);
this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
this.queueSize.setText(
String.format("Elements: (%d)", new Object[] { Integer.valueOf((this.consoleLogger.getComponents()).length) }));
}
public PrintStream getStdOut() {
return new PrintStream(this.stdout);
}
public PrintStream getStdErr() {
return new PrintStream(this.stderr);
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/debug/Console.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,42 @@
package me.srvstr.ui.debug;
import java.io.IOException;
import java.io.OutputStream;
public class ConsoleWriteStream
extends OutputStream {
private Console parentConsole;
private String streamBuffer;
private Entry entryType;
public ConsoleWriteStream(Console parentConsole, Entry entryType) {
this.parentConsole = parentConsole;
this.entryType = entryType;
this.streamBuffer = new String();
}
public void write(int b) throws IOException {
this.streamBuffer = String.valueOf(this.streamBuffer) + (char) b;
}
public void write(byte[] b, int off, int len) throws IOException {
for (int i = off; i < off + len; i++) {
this.streamBuffer = String.valueOf(this.streamBuffer) + (char) b[i];
}
this.parentConsole.createLog(this.streamBuffer, this.entryType);
this.streamBuffer = new String();
}
public void flush() {
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/debug/ConsoleWriteStream.
* class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,28 @@
package me.srvstr.ui.debug;
import java.awt.Color;
public enum Entry {
INFORMATION, NORMAL, ERROR, WARNING;
public static final Color getColorByEnum(Entry entryType) {
switch (entryType) {
case INFORMATION:
return new Color(5355775);
case ERROR:
return new Color(16729156);
case WARNING:
return new Color(16772433);
default:
return new Color(14935011);
}
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/debug/Entry.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,347 @@
package me.srvstr.ui.editors.code;
import me.srvstr.renderer.PostProcessConfig;
import me.srvstr.run.GyteCompiler;
import me.srvstr.ui.UICreator;
import me.srvstr.ui.debug.Console;
import me.srvstr.world.World;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.util.Formatter;
public class CodeEditor extends JFrame {
private static final long serialVersionUID = -5830316930709180479L;
private volatile boolean closeRequest;
private JSplitPane consoleSplitter;
private JPanel editorPane;
private JScrollPane scrollPane;
private JLineNumberTextPane lineNumbers;
private JPanel editorBase;
private JPanel controlPanel;
private JLabel programStatus;
private GraphicsConfig configs;
private JTextPane codeEditor;
private Console console;
private JButton run;
private JButton stop;
private JButton load;
private JButton save;
private JButton settings;
private JavaSyntaxHighlighter highligher;
private GyteCompiler compiler;
public CodeEditor(World world, PostProcessConfig postProcessConfig) {
setOpacity(1.0f);
setBackground(Color.BLACK);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.configs = new GraphicsConfig(postProcessConfig);
createUIComponents();
setupUIComponents();
createUIListener(world);
this.compiler = new GyteCompiler(world, this.console, this);
setTitle("RTX-GYTEBOT - Logic Editor");
getContentPane().add(this.consoleSplitter);
setSize(screenSize.width / 2, screenSize.height);
setLocation(screenSize.width / 2, 0);
setVisible(true);
this.consoleSplitter.setDividerLocation(0.7D);
}
private void createUIComponents() {
this.codeEditor = new JTextPane();
this.lineNumbers = new JLineNumberTextPane(this.codeEditor);
this.highligher = new JavaSyntaxHighlighter(this.codeEditor, 16);
this.console = new Console();
this.controlPanel = new JPanel(new FlowLayout(0, 6, 4));
this.editorBase = new JPanel(new BorderLayout());
this.consoleSplitter = new JSplitPane(0);
this.editorPane = new JPanel(new BorderLayout());
this.run = UICreator.createIconifiedButton('e');
this.run.setToolTipText("Compile and run the program.");
this.stop = UICreator.createIconifiedButton('d');
this.stop.setToolTipText("Kill the current running program");
this.load = UICreator.createIconifiedButton('a');
this.load.setToolTipText("Import an external file of code");
this.save = UICreator.createIconifiedButton('b');
this.save.setToolTipText("Save the current code to disk");
this.settings = UICreator.createIconifiedButton('i');
this.settings.setToolTipText("Open settings");
this.programStatus = new JLabel();
}
private void setupUIComponents() {
this.editorBase.add(this.codeEditor, "Center");
this.editorBase.add(this.lineNumbers, "West");
this.codeEditor.setText(getDefaultCode());
this.codeEditor.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 16));
this.highligher.updateSource();
this.lineNumbers.updateLineNumbers();
this.programStatus.setOpaque(true);
this.programStatus.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(1, 1, 1, 1, Color.GRAY),
BorderFactory.createEmptyBorder(4, 8, 4, 16)));
this.programStatus.setText("Off");
this.consoleSplitter.setTopComponent(this.editorPane);
this.consoleSplitter.setBottomComponent((Component) this.console);
this.scrollPane = new JScrollPane(this.editorBase);
this.scrollPane.getVerticalScrollBar().setUnitIncrement(16);
this.editorPane.add(this.controlPanel, "North");
this.editorPane.add(this.scrollPane, "Center");
this.controlPanel.add(Box.createHorizontalStrut(12));
this.controlPanel.add(this.settings);
this.controlPanel.add(Box.createHorizontalStrut(8));
this.controlPanel.add(this.load);
this.controlPanel.add(this.save);
this.controlPanel.add(Box.createHorizontalStrut(8));
this.controlPanel.add(this.run);
this.controlPanel.add(this.stop);
this.controlPanel.add(Box.createHorizontalStrut(8));
this.controlPanel.add(this.programStatus);
}
private void createUIListener(World world) {
this.settings.addActionListener(e -> this.configs.open());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
CodeEditor.this.closeRequest = true;
}
});
this.save.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(1);
int value = chooser.showDialog(null, "Choose File to Save to");
if (value == 0) {
saveCodeToFile(chooser.getSelectedFile());
}
});
this.load.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(0);
int value = chooser.showDialog(null, "Choose File to Load");
if (value == 0) {
try {
BufferedReader reader = new BufferedReader(new FileReader(chooser.getSelectedFile()));
this.codeEditor.setText(reader.lines().reduce("", (a, b) -> a + b));
this.highligher.updateSource();
this.lineNumbers.updateLineNumbers();
reader.close();
} catch (Exception e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "Unable to find/open/read selected file", "Error - loading file", 0);
}
}
});
this.codeEditor.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent event) {
final int scrollValue = CodeEditor.this.scrollPane.getVerticalScrollBar().getValue();
CodeEditor.this.highligher.updateSource();
CodeEditor.this.lineNumbers.updateLineNumbers();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
scrollPane.getVerticalScrollBar().setValue(scrollValue);
}
});
}
});
this.stop.addActionListener(e -> {
if (this.compiler.getProcessor() != null) {
this.compiler.getProcessor().halt();
}
});
this.run.addActionListener(e -> {
if (world.getGytebot() != null) {
SwingUtilities.invokeLater(() -> this.compiler.compileAndRunProgram(this.codeEditor.getText()));
} else {
JOptionPane.showMessageDialog(null, "No GYTEBOT is associated with the current code",
"Exception - Headless processor", 0);
}
});
}
private void saveCodeToFile(File saveFile) {
try {
Formatter formatter = new Formatter(saveFile);
formatter.format("%s", new Object[] { this.codeEditor.getText() });
formatter.close();
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Could not save code to file: " + saveFile.toURI(), "Error - saving code", 0);
e.printStackTrace();
}
}
public final void markLine(int lineNumber) {
try {
String text = this.codeEditor.getStyledDocument().getText(0, this.codeEditor.getStyledDocument().getLength());
int lineCounter = lineNumber - 1;
int start = 0;
int end = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n') {
lineCounter--;
if (lineCounter == 0) {
start = i;
for (int k = i + 1; k < text.length(); k++) {
if (text.charAt(k) == '\n') {
end = k;
break;
}
}
break;
}
}
}
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Background, new Color(16537688));
this.codeEditor.getStyledDocument().setCharacterAttributes(start, end - start, aset, false);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
public void setProgramStatus(boolean isRunning) {
this.programStatus.setText(isRunning ? "Running..." : "Off");
this.programStatus.setBackground(isRunning ? Color.GREEN : Color.LIGHT_GRAY);
}
private String getDefaultCode() {
try {
return new String(getClass().getResourceAsStream("/data/defaultCode.java.example").readAllBytes());
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Unable to read or open default code template",
"Error - loading default code template", 0);
return null;
}
}
public boolean getWindowCloseRequest() {
return this.closeRequest;
}
}

View File

@ -0,0 +1,55 @@
package me.srvstr.ui.editors.code;
import me.srvstr.renderer.PostProcessConfig;
import javax.swing.*;
import java.awt.*;
public class GraphicsConfig {
private Box base;
private JLabel title;
private JCheckBox dof;
private JCheckBox fxaa;
private JCheckBox grain;
private PostProcessConfig postProcessConfig;
public GraphicsConfig(PostProcessConfig postProcessConfig) {
this.postProcessConfig = postProcessConfig;
}
public final void open() {
this.base = Box.createVerticalBox();
this.title = new JLabel("Settings");
this.title.setFont(new Font("Dialog", 0, 24));
this.title.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
this.fxaa = new JCheckBox("Toggle Fast approXimate Anti Aliasing");
this.fxaa.setSelected(this.postProcessConfig.isFilterFXAA());
this.fxaa.addActionListener(e -> this.postProcessConfig.setFilterFXAA(this.fxaa.isSelected()));
this.dof = new JCheckBox("Toggle Depth of Field");
this.dof.setSelected(this.postProcessConfig.isFilterDoF());
this.dof.addActionListener(e -> this.postProcessConfig.setFilterDoF(this.dof.isSelected()));
this.grain = new JCheckBox("Toggle Film Grain");
this.grain.setSelected(this.postProcessConfig.isFilterGrain());
this.grain.addActionListener(e -> this.postProcessConfig.setFilterGrain(this.grain.isSelected()));
this.base.add(this.title);
this.base.add(this.fxaa);
this.base.add(this.grain);
this.base.add(this.dof);
JOptionPane.showConfirmDialog(null, this.base, "RTX-GYTEBOT - Settings", 0);
}
}

View File

@ -0,0 +1,38 @@
package me.srvstr.ui.editors.code;
import javax.swing.*;
import javax.swing.text.Element;
import java.awt.*;
public class JLineNumberTextPane extends JTextArea {
private static final long serialVersionUID = -2596467098026617439L;
private JTextPane textPane;
public JLineNumberTextPane(JTextPane textPane) {
this.textPane = textPane;
setFont(new Font("Consolas", 0, 16));
setEditable(false);
setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, getBackground().darker()),
BorderFactory.createEmptyBorder(0, 12, 0, 16)));
}
public final void updateLineNumbers() {
setText(getLineNumbersText());
}
private String getLineNumbersText() {
Integer caretPosition = Integer.valueOf(this.textPane.getDocument().getLength());
Element root = this.textPane.getDocument().getDefaultRootElement();
StringBuilder textBuilder = new StringBuilder();
textBuilder.append("1").append(System.lineSeparator());
for (int elementIndex = 2; elementIndex < root.getElementIndex(caretPosition.intValue()) + 2; elementIndex++) {
textBuilder.append(elementIndex).append(System.lineSeparator());
}
return textBuilder.toString();
}
}

View File

@ -1,13 +1,12 @@
package org.ui.editors.code; package me.srvstr.ui.editors.code;
import java.awt.Color; import java.awt.Color;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import org.ui.syntaxes.CharAttrib; import me.srvstr.ui.syntaxes.CharAttrib;
import org.ui.syntaxes.SyntaxHighlighter; import me.srvstr.ui.syntaxes.SyntaxHighlighter;
public class JavaSyntaxHighlighter public class JavaSyntaxHighlighter
extends SyntaxHighlighter extends SyntaxHighlighter {
{
private static final String OPERATOR_REGEX = "[\\+\\-\\*/!&|\\^~.:?=]"; private static final String OPERATOR_REGEX = "[\\+\\-\\*/!&|\\^~.:?=]";
private static final String DELEMITER_REGEX = "[\\[\\]\\(\\)\\{\\},;]"; private static final String DELEMITER_REGEX = "[\\[\\]\\(\\)\\{\\},;]";
private static final String KEYWORD_REGEX = "\\W?(\\bextends|implements|this|super|import|package|public|private|throws|throw|protected|void|class|static|volatile|const|final|break|continue|while|for|do|switch|case|default|if|else\\b)\\W"; private static final String KEYWORD_REGEX = "\\W?(\\bextends|implements|this|super|import|package|public|private|throws|throw|protected|void|class|static|volatile|const|final|break|continue|while|for|do|switch|case|default|if|else\\b)\\W";

View File

@ -0,0 +1,174 @@
package me.srvstr.ui.editors.map;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileNotFoundException;
import java.util.Formatter;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import me.srvstr.ui.UICreator;
import me.srvstr.world.World;
public class MapEditor
extends JFrame {
private static final long serialVersionUID = -6076124740248473039L;
private volatile boolean closeRequest;
private JPanel buttonPane;
private JButton updateWorld;
private JButton reset;
private JButton load;
private JButton save;
private JButton info;
private JLabel infoLabel;
private JTextPane preview;
private MapTextHighlighter highlighter;
public MapEditor(World world) {
setOpacity(1.0f);
setBackground(Color.BLACK);
createUIComponents();
setupUIComponents(world);
createListener(world);
this.buttonPane.add(Box.createHorizontalStrut(12));
this.buttonPane.add(this.updateWorld);
this.buttonPane.add(this.reset);
this.buttonPane.add(Box.createHorizontalStrut(6));
this.buttonPane.add(this.load);
this.buttonPane.add(this.save);
this.buttonPane.add(Box.createHorizontalStrut(6));
this.buttonPane.add(this.infoLabel);
this.buttonPane.add(this.info);
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new JScrollPane(this.preview), "Center");
getContentPane().add(this.buttonPane, "South");
setTitle("RTX-GYTEBOT - Map Editor");
setSize(size.width >> 1, size.height >> 1);
setLocation(0, size.height >> 1);
setVisible(true);
}
private void createListener(World world) {
this.preview.addKeyListener(new KeyAdapter() {
public final void keyReleased(KeyEvent event) {
MapEditor.this.highlighter.highlight();
}
});
this.reset.addActionListener(e -> {
this.preview.setText(world.toString());
this.highlighter.highlight();
});
this.updateWorld.addActionListener(e -> world.setDataString(this.preview.getText()));
this.load.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(0);
int value = chooser.showDialog(null, "Choose File");
if (value == 0) {
world.setWorld(chooser.getSelectedFile().getAbsolutePath());
}
this.preview.setText(world.toString());
this.infoLabel.setText(String.format("Size: %d %d Coins: %d", new Object[] { Integer.valueOf(world.getWidth()),
Integer.valueOf(world.getHeight()), Integer.valueOf(world.getCoinCount()) }));
this.highlighter.highlight();
});
this.info.addActionListener(e -> {
});
this.save.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(1);
int value = chooser.showDialog(null, "Choose File to save to");
if (value == 0) {
try {
Formatter formatter = new Formatter(chooser.getSelectedFile());
formatter.format("%s", new Object[] { world.toString() });
formatter.close();
} catch (FileNotFoundException e1) {
String errorMessage = String.format("Could not save current map to file: %s",
new Object[] { chooser.getSelectedFile().toURI() });
JOptionPane.showMessageDialog(null, errorMessage, "Error - saving map", 0);
e1.printStackTrace();
}
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
MapEditor.this.closeRequest = true;
}
});
}
private void setupUIComponents(World world) {
this.preview.setText(world.toString());
this.highlighter.highlight();
}
private void createUIComponents() {
this.preview = new JTextPane();
this.highlighter = new MapTextHighlighter(this.preview);
this.buttonPane = new JPanel(new FlowLayout(0, 4, 2));
this.updateWorld = UICreator.createIconifiedButton('g');
this.reset = UICreator.createIconifiedButton('f');
this.load = UICreator.createIconifiedButton('a');
this.save = UICreator.createIconifiedButton('b');
this.info = UICreator.createIconifiedButton('h');
this.infoLabel = new JLabel();
}
public boolean getWindowCloseRequest() {
return this.closeRequest;
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/editors/map/MapEditor.
* class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,62 @@
package me.srvstr.ui.editors.map;
import java.awt.Font;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import me.srvstr.world.World;
public class MapInformation {
private Box content;
private JLabel title;
private JLabel nameLabel;
private JLabel authorLabel;
private JLabel dateLabel;
private JLabel versionLabel;
private JLabel sizeLabel;
private JLabel coinsLabel;
public MapInformation(World world) {
this.content = Box.createVerticalBox();
this.content.setAlignmentX(0.0F);
this.title = new JLabel("Map information");
this.title.setFont(new Font("Verdana", 0, 12));
this.title.setAlignmentX(0.0F);
this.nameLabel = new JLabel("Map: " + world.getName());
this.authorLabel = new JLabel("Author: " + world.getAuthor());
this.dateLabel = new JLabel("Date: " + world.getDate());
this.versionLabel = new JLabel("Version: " + world.getVersion());
this.sizeLabel = new JLabel("Size: " + world.getWidth() + "x" + world.getHeight());
this.coinsLabel = new JLabel("Coins(total) : " + world.getCoinCount());
this.nameLabel.setAlignmentX(0.0F);
this.authorLabel.setAlignmentX(0.0F);
this.dateLabel.setAlignmentX(0.0F);
this.versionLabel.setAlignmentX(0.0F);
this.content.add(Box.createVerticalStrut(12));
this.content.add(this.title);
this.content.add(Box.createVerticalStrut(6));
this.content.add(this.nameLabel);
this.content.add(Box.createVerticalStrut(4));
this.content.add(this.sizeLabel);
this.content.add(Box.createVerticalStrut(6));
this.content.add(this.coinsLabel);
this.content.add(Box.createVerticalStrut(6));
this.content.add(this.authorLabel);
this.content.add(Box.createVerticalStrut(4));
this.content.add(this.dateLabel);
this.content.add(Box.createVerticalStrut(4));
this.content.add(this.versionLabel);
JOptionPane.showInternalConfirmDialog(null, this.content, "RTX-GYTEBOT - map information", 0);
}
}

View File

@ -0,0 +1,32 @@
package me.srvstr.ui.editors.map;
import java.awt.Color;
import javax.swing.JTextPane;
import me.srvstr.ui.syntaxes.CharAttrib;
import me.srvstr.ui.syntaxes.SyntaxHighlighter;
public class MapTextHighlighter
extends SyntaxHighlighter {
private static final String WALL_REGEX = "[#]";
private static final String BOT_REGEX = "[<^>vV]";
private static final String COIN_REGEX = "[€$]";
private static final String TAG_REGEX = "\\b|@date|@author|@version|@name\\b";
private static final String DATA_REGEX = "@[^\\n]*";
private static final String COMMENT_REGEX = "//[^\\n]*";
public MapTextHighlighter(JTextPane textPane) {
super(textPane, 1.0F, 24);
createHighlightPattern("[#]", new CharAttrib(false, false, Color.DARK_GRAY));
createHighlightPattern("[<^>vV]", new CharAttrib(false, true, Color.RED));
createHighlightPattern("[€$]", new CharAttrib(true, false, Color.ORANGE));
createHighlightPattern("\\b|@date|@author|@version|@name\\b", new CharAttrib(true, false, Color.GRAY));
createHighlightPattern("@[^\\n]*", new CharAttrib(true, false, Color.GRAY));
createHighlightPattern("//[^\\n]*", new CharAttrib(true, false, Color.LIGHT_GRAY));
}
}

View File

@ -0,0 +1,40 @@
package me.srvstr.ui.icons;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
public class IconLoader {
public static final char LOAD_ICON_CODE_POINT = 'a';
public static final char SAVE_ICON_CODE_POINT = 'b';
public static final char CLEAR_ICON_CODE_POINT = 'c';
public static final char STOP_ICON_CODE_POINT = 'd';
public static final char RUN_ICON_CODE_POINT = 'e';
public static final char RESET_ICON_CODE_POINT = 'f';
public static final char APPLY_ICON_CODE_POINT = 'g';
public static final char INFO_ICON_CODE_POINT = 'h';
public static final char OPTIONS_ICON_CODE_POINT = 'i';
private static final String FONT_FILE_NAME = "data/icons/RTX-GYTEBOT-ICONS.ttf";
private static final String ICON_FILE_NAME = "data/icons/gytebotIcon.png";
public static final void loadIcons() throws AssertionError {
try {
Font iconFont = Font.createFont(0, (IconLoader.class.getClassLoader().getResourceAsStream(FONT_FILE_NAME)));
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(iconFont);
} catch (FontFormatException e) {
throw new AssertionError("Unable to register icon font");
} catch (Exception e) {
throw new AssertionError("Unable to find or load icon font file:" + FONT_FILE_NAME);
}
}
public static final BufferedImage loadWindowIcon() throws AssertionError {
try {
return ImageIO.read(IconLoader.class.getClassLoader().getResourceAsStream(ICON_FILE_NAME));
} catch (Exception e) {
throw new AssertionError("Unable to find or load image file:" + ICON_FILE_NAME);
}
}
}

View File

@ -0,0 +1,56 @@
package me.srvstr.ui.syntaxes;
import java.awt.Color;
public class CharAttrib {
private boolean bold;
private boolean italic;
private Color color;
private Color backgroundColor;
public CharAttrib(boolean bold, boolean italic, Color color) {
this.bold = bold;
this.italic = italic;
this.color = color;
this.backgroundColor = Color.WHITE;
}
public final boolean isBold() {
return this.bold;
}
public final void setBold(boolean bold) {
this.bold = bold;
}
public final boolean isItalic() {
return this.italic;
}
public final void setItalic(boolean italic) {
this.italic = italic;
}
public final Color getColor() {
return this.color;
}
public final void setColor(Color color) {
this.color = color;
}
public final Color getBackgroundColor() {
return this.backgroundColor;
}
public final void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/syntaxes/CharAttrib.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,26 @@
package me.srvstr.ui.syntaxes;
public class Pair<A, B> {
private A a;
private B b;
public Pair(A a, B b) {
this.a = a;
this.b = b;
}
public final A getA() {
return this.a;
}
public final B getB() {
return this.b;
}
}
/*
* Location:
* /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/syntaxes/Pair.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -0,0 +1,105 @@
package me.srvstr.ui.syntaxes;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SyntaxHighlighter {
private final CharAttrib defaultCharAttribs;
protected JTextPane textPane;
protected TabSet tabset;
private final List<Pair<String, CharAttrib>> elements;
private int selectionStart;
private int selectionLength;
private final int fontSize;
public SyntaxHighlighter(JTextPane textPane, float tabSize, int fontSize) {
this.textPane = textPane;
this.fontSize = fontSize;
this.elements = new ArrayList<>();
this.defaultCharAttribs = new CharAttrib(false, false, textPane.getForeground());
createTabset(tabSize);
}
public SyntaxHighlighter(JTextPane textPane, float tabSize, int fontSize, Color backgroundColor) {
this.textPane = textPane;
this.fontSize = fontSize;
this.elements = new ArrayList<>();
this.defaultCharAttribs = new CharAttrib(false, false, textPane.getForeground());
this.defaultCharAttribs.setBackgroundColor(backgroundColor);
createTabset(tabSize);
}
protected void createHighlightPattern(String regex, CharAttrib attribs) {
this.elements.add(new Pair<>(regex, attribs));
}
private void createTabset(float tabSize) {
TabStop[] tabs = new TabStop[8];
for (int i = 0; i < tabs.length; i++) {
tabs[i] = new TabStop(tabSize * i + tabSize, 0, 0);
}
this.tabset = new TabSet(tabs);
}
public final void highlight() {
this.selectionStart = 0;
this.selectionLength = this.textPane.getDocument().getLength();
createHighlight(this.defaultCharAttribs);
try {
for (Pair<String, CharAttrib> entry : this.elements) {
Matcher matcher = Pattern.compile(entry.getA(), Pattern.MULTILINE | Pattern.DOTALL).matcher(
this.textPane.getDocument().getText(0, this.textPane.getDocument().getLength()));
while (matcher.find()) {
this.selectionStart = matcher.start();
this.selectionLength = matcher.end() - this.selectionStart;
createHighlight(entry.getB());
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
private void createHighlight(CharAttrib attribs) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Background,
this.defaultCharAttribs.getBackgroundColor());
aset = sc.addAttribute(aset, StyleConstants.FontFamily, new Font("Monospaced", Font.PLAIN, 16).getFamily());
aset = sc.addAttribute(aset, StyleConstants.FontSize, this.fontSize);
aset = sc.addAttribute(aset, StyleConstants.Bold, attribs.isBold());
aset = sc.addAttribute(aset, StyleConstants.Italic, attribs.isItalic());
aset = sc.addAttribute(aset, StyleConstants.TabSet, this.tabset);
if (attribs.getColor() == null) {
Color foregroundColor = (Color) this.textPane.getStyledDocument()
.getCharacterElement(this.selectionStart).getAttributes()
.getAttribute(StyleConstants.Foreground);
aset = sc.addAttribute(aset, StyleConstants.Foreground, foregroundColor.darker());
} else {
aset = sc.addAttribute(aset, StyleConstants.Foreground, attribs.getColor());
}
this.textPane.getStyledDocument().setCharacterAttributes(this.selectionStart, this.selectionLength, aset, false);
}
}

View File

@ -0,0 +1,106 @@
package me.srvstr.view;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWCursorPosCallback;
import org.lwjgl.glfw.GLFWCursorPosCallbackI;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
import org.lwjgl.glfw.GLFWScrollCallback;
import org.lwjgl.glfw.GLFWScrollCallbackI;
import org.lwjgl.glfw.GLFWVidMode;
public class Camera
implements AutoCloseable {
private static final float MIN_CAMERA_ZOOM = -8.0F;
private static final float MAX_CAMERA_ZOOM = -0.5F;
private static final float MAX_CAMERA_ROT_Y = -1.5707964F;
private static final float MIN_CAMERA_ROT_Y = -3.1415927F;
private GLFWCursorPosCallback cursorPosCallback;
private GLFWMouseButtonCallback mouseButtonCallback;
private GLFWScrollCallback scrollCallback;
private boolean isMouseButton1Down;
private float cameraZoom = -0.5F;
private float cameraRotationX = 1.3F;
private float cameraRotationY = -2.3F;
private float deltaRotationX;
private float deltaRotationY;
private float cameraRotationVelocityX;
private float cameraRotationVelocityY;
private float cameraZoomVelocity;
public Camera(long windowHandle) {
GLFW.glfwSetMouseButtonCallback(windowHandle,
(GLFWMouseButtonCallbackI) (this.mouseButtonCallback = new GLFWMouseButtonCallback() {
public void invoke(long arg0, int arg1, int arg2, int arg3) {
Camera.this.isMouseButton1Down = ((arg1 == 0)) ^ ((arg2 == 0));
}
}));
GLFW.glfwSetScrollCallback(windowHandle, (GLFWScrollCallbackI) (this.scrollCallback = new GLFWScrollCallback() {
public void invoke(long window, double dx, double dy) {
Camera.this.cameraZoomVelocity = (float) (Camera.this.cameraZoomVelocity + dy * 0.019999999552965164D);
}
}));
GLFW.glfwSetCursorPosCallback(windowHandle,
(GLFWCursorPosCallbackI) (this.cursorPosCallback = new GLFWCursorPosCallback() {
public void invoke(long window, double cursorX, double cursorY) {
GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
float rotationDifferenceX = (float) (cursorX / vidmode.width());
float rotationDifferenceY = (float) (cursorY / vidmode.height());
if (Camera.this.isMouseButton1Down) {
Camera.this.cameraRotationVelocityX = (Camera.this.deltaRotationX - rotationDifferenceX) * 2.0F;
Camera.this.cameraRotationVelocityY = (Camera.this.deltaRotationY - rotationDifferenceY) * 1.8F;
}
Camera.this.deltaRotationX = rotationDifferenceX;
Camera.this.deltaRotationY = rotationDifferenceY;
}
}));
}
public void update(float elapsedTime) {
float timeStep = elapsedTime * 100.0F;
this.cameraRotationY = Math
.min(Math.max(this.cameraRotationY + this.cameraRotationVelocityY * timeStep, -3.1415927F), -1.5707964F);
this.cameraRotationX += this.cameraRotationVelocityX * timeStep;
this.cameraRotationVelocityX += -this.cameraRotationVelocityX * 0.08F * timeStep;
this.cameraRotationVelocityY += -this.cameraRotationVelocityY * 0.05F * timeStep;
this.cameraZoom = Math.max(Math.min(this.cameraZoom + this.cameraZoomVelocity, -0.5F), -8.0F);
this.cameraZoomVelocity += -this.cameraZoomVelocity * 0.04F * timeStep * Math.abs(2.0F / this.cameraZoom);
}
public final void close() {
this.cursorPosCallback.free();
this.mouseButtonCallback.free();
this.scrollCallback.free();
}
public final float getCameraZoom() {
return this.cameraZoom;
}
public final float getCameraRotationX() {
return this.cameraRotationX;
}
public final float getCameraRotationY() {
return this.cameraRotationY;
}
}

View File

@ -0,0 +1,397 @@
package me.srvstr.world;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JOptionPane;
import me.srvstr.bot.Direction;
import me.srvstr.bot.Gytebot;
import me.srvstr.objects.Coin;
import me.srvstr.objects.Wall;
import me.srvstr.objects.WorldObject;
public class World {
public static final int MAP_SIZE = 32;
private List<String> rawMapData;
private int rawDataWidth;
private int coinCount;
private String author;
private String version;
private String name;
private String date;
private String mapPath;
private volatile WorldObject[][] objects;
private volatile Gytebot gytebot;
private boolean updateCoinBuffer;
private int[] coinBufferData;
private boolean updateWallBufferData;
private float[] wallBufferData;
public World() {
this.rawMapData = new LinkedList<>();
this.coinBufferData = new int[1024];
this.wallBufferData = new float[1024];
setWorld("/data/standardlevel.map");
}
public final void setWorld(String fileName) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(fileName)));
} catch (Exception e1) {
try {
reader = new BufferedReader(new FileReader(new File(fileName)));
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "Unable to open Map: " + fileName, "Error - opening map", 0);
}
}
if (reader != null) {
try {
this.gytebot = null;
this.rawDataWidth = 0;
this.rawMapData.clear();
try {
reader.lines().forEachOrdered(line -> parseLine(line));
if (this.rawDataWidth > 0 && this.rawMapData.size() > 0) {
this.objects = new WorldObject[this.rawDataWidth][this.rawMapData.size()];
createWorldData();
updateTransferBuffers();
this.mapPath = fileName;
} else {
setWorld(this.mapPath);
JOptionPane.showMessageDialog(null, "Unable to open Map: " + fileName, "Error - opening map", 0);
}
} catch (Error e) {
setWorld(this.mapPath);
JOptionPane.showMessageDialog(null, "Unable to open Map: " + fileName, "Error - opening map", 0);
} finally {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public final void setDataString(String data) {
this.gytebot = null;
this.rawDataWidth = 0;
this.rawMapData.clear();
try {
Arrays.<String>asList(data.split("(?=\\n)")).forEach(line -> parseLine(line));
if (this.rawDataWidth > 0 && this.rawMapData.size() > 0) {
this.objects = new WorldObject[this.rawDataWidth][this.rawMapData.size()];
createWorldData();
updateTransferBuffers();
} else {
setWorld(this.mapPath);
JOptionPane.showMessageDialog(null, "The map was not properly loaded", "Error - converting map", 0);
}
} catch (Error e) {
setWorld(this.mapPath);
JOptionPane.showMessageDialog(null, "Unable to convert Map: " + e.getMessage(),
"Error - converting map", 0);
}
}
private void parseLine(String line) throws Error {
String trimed = line.trim();
if (trimed.length() != 0) {
String[] splitted = trimed.split("[/](?=/)|(?=[@])");
String rawMapLine = new String();
byte b;
int i;
String[] arrayOfString1;
for (i = (arrayOfString1 = splitted).length, b = 0; b < i;) {
String content = arrayOfString1[b];
if (content.startsWith("/")) {
break;
}
if (content.startsWith("@")) {
String[] tag = content.split("\\s+");
if (tag.length > 2) {
throw new AssertionError("To many arguments provided for tag: " + content);
}
String str;
switch ((str = tag[0]).hashCode()) {
case -440667701:
if (str.equals("@author")) {
this.author = tag[1];
break;
}
case 62181358:
if (str.equals("@date")) {
this.date = tag[1];
break;
}
case 62479051:
if (str.equals("@name")) {
this.name = tag[1];
break;
}
case 222319768:
if (str.equals("@version")) {
this.version = tag[1];
break;
}
default:
throw new AssertionError("Unknown tag found: " + tag[0]);
}
} else {
rawMapLine = String.valueOf(rawMapLine) + content;
}
b++;
}
if (rawMapLine.length() > 0) {
this.rawMapData.add(rawMapLine);
}
this.rawDataWidth = Math.max(this.rawDataWidth, rawMapLine.length());
if (this.rawDataWidth > 32) {
throw new AssertionError("Map size exceeds valid map bounds of 32x32! It is to wide");
}
if (this.rawMapData.size() > 32) {
throw new AssertionError("Map size exceeds valid map bounds of 32x32! It is to large");
}
}
}
private void createWorldData() {
this.coinCount = 0;
for (int y = 0; y < this.rawMapData.size(); y++) {
for (int x = 0; x < ((String) this.rawMapData.get(y)).length(); x++) {
char current = ((String) this.rawMapData.get(y)).charAt(x);
if (current == '#') {
this.objects[x][y] = (WorldObject) new Wall(new Point2D.Float(x, y));
} else if (current == '€' || current == '$') {
this.objects[x][y] = (WorldObject) new Coin(new Point2D.Float(x, y));
this.coinCount++;
} else if (current == '^' || current == '>' || current == 'v' || current == 'V' || current == '<') {
if (this.gytebot != null) {
System.err.println("Conflicting world rule: There is already a gytebot!");
JOptionPane.showMessageDialog(null, "Conflicting world rule: There is already a gytebot",
"Error - converting map", 0);
} else if (x < ((String) this.rawMapData.get(0)).length() && y < this.rawMapData.size()) {
this.gytebot = new Gytebot(new Point2D.Float(x, y), Direction.directionFromCodePoint(current));
} else {
this.gytebot = null;
JOptionPane.showMessageDialog(null, "Gytebot is placed outside Map", "Error - converting map", 0);
}
} else if (current != ' ') {
System.err.println("Unkown map entity: " + current);
}
}
}
}
private void updateTransferBuffers() {
Arrays.fill(this.coinBufferData, 0);
Arrays.fill(this.wallBufferData, 0.0F);
for (int y = 0; y < (this.objects[0]).length; y++) {
for (int x = 0; x < this.objects.length; x++) {
if (this.objects[x][y] instanceof Coin) {
this.coinBufferData[x + y * this.objects.length] = 1;
} else if (this.objects[x][y] instanceof Wall) {
this.wallBufferData[x + y * 32] = 1.0F;
}
}
}
this.updateCoinBuffer = true;
this.updateWallBufferData = true;
}
public final void setWall(int x, int y) {
setObject(x, y, (WorldObject) new Wall(new Point2D.Float(x, y)));
}
public final void setCoin(int x, int y) {
setObject(x, y, (WorldObject) new Coin(new Point2D.Float(x, y)));
}
public final void removeObject(int x, int y) {
if (this.objects[x][y] != null) {
this.objects[x][y] = null;
updateTransferBuffers();
} else {
JOptionPane.showMessageDialog(null, "Index to remove object from is already empty", "Exception", 0);
}
}
private void setObject(int x, int y, WorldObject object) {
if (x >= 0 && x < this.objects.length && y >= 0 && y < (this.objects[0]).length) {
this.objects[x][y] = object;
updateTransferBuffers();
} else {
JOptionPane.showMessageDialog(null, "The requested object placement occured outside of valid bounds!",
"Exception", 0);
}
}
public boolean isLocationObstructed(Point point) {
if (point.x < 0 || point.y < 0 || point.x >= getWidth() || point.y >= getHeight()) {
return true;
}
if (this.objects[point.x][point.y] instanceof Wall) {
return true;
}
return false;
}
public boolean isCoinPlacedHere(Point2D.Float location) {
if (location.x < 0.0F || location.y < 0.0F || location.x >= getWidth() || location.y >= getHeight()) {
return false;
}
if (this.objects[Math.round(location.x)][Math.round(location.y)] instanceof Coin) {
return true;
}
return false;
}
public final String toString() {
return this.rawMapData.stream().reduce("", (A, B) -> String.valueOf(A) + B + System.lineSeparator());
}
public boolean updateWallBufferData() {
if (this.updateWallBufferData) {
this.updateWallBufferData = false;
return true;
}
return false;
}
public boolean updateCoinTextureData() {
if (this.updateCoinBuffer) {
this.updateCoinBuffer = false;
return true;
}
return false;
}
public final int getCoinCount() {
return this.coinCount;
}
public final String getAuthor() {
return this.author;
}
public final String getVersion() {
return this.version;
}
public final String getName() {
return this.name;
}
public final String getDate() {
return this.date;
}
public final synchronized Gytebot getGytebot() {
return this.gytebot;
}
public final int[] getCoinBufferData() {
return this.coinBufferData;
}
public final int getWidth() {
return this.objects.length;
}
public final int getHeight() {
return (this.objects[0]).length;
}
public int getDrawGytebotAsInt() {
return (this.gytebot == null) ? 0 : 1;
}
public int[] getCoinTextureData() {
return this.coinBufferData;
}
public float[] getWallBufferData() {
return this.wallBufferData;
}
}

View File

@ -1,20 +0,0 @@
package org.bot;
public enum Direction {
NORTH, SOUTH, WEST, EAST;
public static Direction directionFromCodePoint(char current) {
switch (current) {
case '^':
return NORTH;
case '>':
return WEST;
case 'V':
case 'v':
return SOUTH;
case '<':
return EAST;
}
return NORTH;
}
}

View File

@ -1,11 +0,0 @@
package org.bot;
public class FloatUtils {
public static final float PI = 3.1415927F;
public static final float PI_HALF = 1.5707964F;
private static final float EPSILON = 0.001F;
public static final boolean isZeroWithTolerance(float x) {
return (Math.abs(x) < 0.001F);
}
}

View File

@ -1,172 +0,0 @@
package org.bot;
import org.objects.WorldObject;
import java.awt.*;
import java.awt.geom.Point2D;
public class Gytebot extends WorldObject {
private static final float RCP_FORCE_DAMPING = 8.0F;
private Direction direction;
private Point2D.Float velocity;
private float angleVelocity;
private float viewAngle;
private boolean isReady;
public Gytebot(Point2D.Float position, Direction direction) {
super(position);
this.direction = direction;
this.velocity = new Point2D.Float();
convertDirectionToAngle(direction);
}
public Gytebot(Gytebot gytebot) {
super(new Point2D.Float());
if (gytebot != null) {
this.direction = gytebot.getDirection();
this.viewAngle = gytebot.getViewAngle();
this.angleVelocity = gytebot.getViewAngleVelocity();
this.position.x = (gytebot.getPosition()).x;
this.position.y = (gytebot.getPosition()).y;
}
}
private float getViewAngleVelocity() {
return this.angleVelocity;
}
public void updateRotation(float elapsedTime) {
this.viewAngle += this.angleVelocity * elapsedTime * 8.0F;
this.angleVelocity += -this.angleVelocity * elapsedTime * 8.0F;
this.position.x += this.velocity.x * elapsedTime * 8.0F;
this.position.y += this.velocity.y * elapsedTime * 8.0F;
this.velocity.x += -this.velocity.x * elapsedTime * 8.0F;
this.velocity.y += -this.velocity.y * elapsedTime * 8.0F;
this.isReady = (FloatUtils.isZeroWithTolerance(this.angleVelocity) && FloatUtils.isZeroWithTolerance(this.velocity.x) && FloatUtils.isZeroWithTolerance(this.velocity.y));
}
public void turnRight() {
switch (this.direction) {
case NORTH:
this.direction = Direction.WEST;
break;
case WEST:
this.direction = Direction.SOUTH;
break;
case SOUTH:
this.direction = Direction.EAST;
break;
case EAST:
this.direction = Direction.NORTH;
break;
default:
break;
}
this.angleVelocity = 1.5707964F;
this.isReady = false;
}
public void turnLeft() {
switch (this.direction) {
case NORTH:
this.direction = Direction.EAST;
break;
case EAST:
this.direction = Direction.SOUTH;
break;
case SOUTH:
this.direction = Direction.WEST;
break;
case WEST:
this.direction = Direction.NORTH;
default:
break;
}
this.angleVelocity = -1.5707964F;
this.isReady = false;
}
private void convertDirectionToAngle(Direction direction) {
switch (direction) {
case NORTH:
this.viewAngle = 1.5707964F;
break;
case SOUTH:
this.viewAngle = -1.5707964F;
break;
case EAST:
this.viewAngle = 0.0F;
break;
case WEST:
this.viewAngle = 3.1415927F;
default:
break;
}
}
public void goForward() {
switch (this.direction) {
case NORTH:
this.velocity = new Point2D.Float(0.0F, -1.0F);
break;
case SOUTH:
this.velocity = new Point2D.Float(0.0F, 1.0F);
break;
case EAST:
this.velocity = new Point2D.Float(-1.0F, 0.0F);
break;
case WEST:
this.velocity = new Point2D.Float(1.0F, 0.0F);
break;
default:
this.velocity = new Point2D.Float();
break;
}
this.isReady = false;
}
public Point getForwardLocation() {
switch (this.direction) {
case NORTH:
return new Point(Math.round(this.position.x), Math.round(this.position.y) - 1);
case SOUTH:
return new Point(Math.round(this.position.x), Math.round(this.position.y) + 1);
case EAST:
return new Point(Math.round(this.position.x) - 1, Math.round(this.position.y));
case WEST:
return new Point(Math.round(this.position.x) + 1, Math.round(this.position.y));
default:
break;
}
return null;
}
public final Direction getDirection() {
return this.direction;
}
public final float getViewAngle() {
return this.viewAngle;
}
public boolean isReady() {
return this.isReady;
}
}

View File

@ -1,155 +0,0 @@
package org.engine;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
import org.lwjgl.glfw.GLFWImage;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class Display implements AutoCloseable {
private final long handle;
private final Dimension size;
private GLFWFramebufferSizeCallback framebufferSizeCallback;
private volatile boolean requiredRebuild;
public Display(BufferedImage icon) {
this.size = Toolkit.getDefaultToolkit().getScreenSize();
this.size.width >>= 1;
this.size.height >>= 1;
GLFW.glfwDefaultWindowHints();
GLFW.glfwWindowHint(131076, 0);
GLFW.glfwWindowHint(131075, 1);
this.handle = GLFW.glfwCreateWindow(this.size.width, this.size.height, "RTX-GYTEBOT", 0L, 0L);
setWindowIcon(icon);
if (this.handle == 0L) {
throw new AssertionError("Failed to create the GLFW window!");
}
orientateWindow();
GLFW.glfwMakeContextCurrent(this.handle);
Exception exception1 = null, exception2 = null;
try {
MemoryStack frame = MemoryStack.stackPush();
try {
IntBuffer framebufferSize = frame.mallocInt(2);
GLFW.nglfwGetFramebufferSize(this.handle, MemoryUtil.memAddress(framebufferSize), MemoryUtil.memAddress(framebufferSize) + 4L);
this.size.width = framebufferSize.get(0);
this.size.height = framebufferSize.get(1);
} finally {
if (frame != null) frame.close();
}
} finally {
exception2 = null;
if (exception1 == null) {
exception1 = exception2;
} else if (exception1 != exception2) {
exception1.addSuppressed(exception2);
}
}
}
private void setWindowIcon(BufferedImage icon) {
byte[] data = ((DataBufferByte) icon.getRaster().getDataBuffer()).getData();
ByteBuffer pixels = BufferUtils.createByteBuffer(data.length);
pixels.put(data);
pixels.flip();
GLFWImage.Buffer gb = GLFWImage.create(1);
GLFWImage image = GLFWImage.create().set(icon.getWidth(), icon.getHeight(), pixels);
gb.put(0, image);
GLFW.glfwSetWindowIcon(this.handle, gb);
}
private void orientateWindow() {
int[] left = new int[1];
int[] top = new int[1];
int[] right = new int[1];
int[] bottom = new int[1];
GLFW.glfwGetWindowFrameSize(this.handle, left, top, right, bottom);
this.size.width = this.size.width - left[0] - right[0];
this.size.height = this.size.height - bottom[0] - top[0];
GLFW.glfwSetWindowSize(this.handle, this.size.width, this.size.height);
GLFW.glfwSetWindowPos(this.handle, right[0], top[0]);
}
public final void close() {
//this.framebufferSizeCallback.free();
GLFW.glfwDestroyWindow(this.handle);
}
public final void show() {
GLFW.glfwShowWindow(this.handle);
}
public final boolean shouldNotClose() {
return !GLFW.glfwWindowShouldClose(this.handle);
}
public final void swapBuffers() {
GLFW.glfwSwapBuffers(this.handle);
}
public final long getWindowHandle() {
return this.handle;
}
public final int getWidth() {
return this.size.width;
}
public final int getHeight() {
return this.size.height;
}
public final Dimension getSize() {
return this.size;
}
public boolean wasScaled() {
if (this.requiredRebuild) {
this.requiredRebuild = false;
return true;
}
return false;
}
}

View File

@ -1,172 +0,0 @@
/* */ package org.engine;
/* */
/* */ import org.lwjgl.glfw.GLFW;
/* */ import org.lwjgl.glfw.GLFWErrorCallback;
/* */ import org.lwjgl.glfw.GLFWErrorCallbackI;
/* */ import org.lwjgl.opengl.GL;
/* */ import org.ui.UIAccess;
/* */ import org.ui.icons.IconLoader;
/* */ import org.view.Camera;
/* */ import org.world.World;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Engine
/* */ {
/* */ private GLFWErrorCallback errorCallback;
/* */ private Display display;
/* */ private Renderer renderer;
/* */ private Camera camera;
/* */ private UIAccess ui;
/* */ private World world;
/* */ private float globalTime;
/* */ private float elapsedTime;
/* */
/* */ public Engine() {
/* */ try {
/* 40 */ this.ui = new UIAccess();
/* */
/* 42 */ this.ui.putInfoLoadingMessage("Loading Icon set...", 10);
/* */
/* 44 */ IconLoader.loadIcons();
/* */
/* 46 */ GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)(this.errorCallback = GLFWErrorCallback.createPrint(System.err)));
/* */
/* 48 */ this.ui.putInfoLoadingMessage("Initalizing GLFW...", 25);
/* */
/* 50 */ if (!GLFW.glfwInit()) {
/* 51 */ throw new AssertionError("Could not initalize GLFW!");
/* */ }
/* 53 */ this.ui.putInfoLoadingMessage("Creating GLFW window...", 50);
/* */
/* 55 */ this.display = new Display(this.ui.getWindowIcon());
/* */
/* */
/* 58 */ GLFW.glfwSwapInterval(1);
/* */
/* 60 */ GL.createCapabilities();
/* */
/* 62 */ this.ui.putInfoLoadingMessage("Creating Shaders...", 65);
/* */
/* 64 */ this.renderer = new Renderer(this.display.getSize());
/* */
/* 66 */ this.ui.putInfoLoadingMessage("Setting up window callbacks", 80);
/* */
/* 68 */ this.camera = new Camera(this.display.getWindowHandle());
/* */
/* 70 */ this.ui.putInfoLoadingMessage("Creating World...", 90);
/* */
/* 72 */ this.world = new World();
/* */
/* 74 */ this.ui.putInfoLoadingMessage("Done", 100);
/* */ }
/* 76 */ catch (Exception e) {
/* 77 */ e.printStackTrace();
/* */ } finally {
/* */
/* 80 */ this.ui.close();
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void run() {
/* */ try {
/* 94 */ this.ui.apply(this.world, this.renderer.getPpConfig());
/* */
/* 96 */ this.display.show();
/* */
/* 98 */ // this.ui.openDocs();
/* */
/* 101 */ while (this.display.shouldNotClose() && !this.ui.windowCloseRequest()) {
/* */
/* 103 */ long startTime = System.currentTimeMillis();
/* */
/* 105 */ GLFW.glfwPollEvents();
/* */
/* 107 */ if (this.world.getGytebot() != null)
/* */ {
/* 109 */ this.world.getGytebot().updateRotation(this.elapsedTime);
/* */ }
/* */
/* 112 */ this.camera.update(this.elapsedTime);
/* */
/* 114 */ this.renderer.update(this.display.getSize(), this.globalTime, this.camera, this.world, this.display.wasScaled());
/* */
/* 116 */ this.renderer.render();
/* */
/* 118 */ this.display.swapBuffers();
/* */
/* */
/* 121 */ long passedTime = System.currentTimeMillis() - startTime;
/* */
/* 123 */ if (passedTime < 16L) {
/* 124 */ Thread.sleep(16L - passedTime);
/* */ }
/* */
/* 127 */ this.elapsedTime = (float)(System.currentTimeMillis() - startTime) * 0.001F;
/* */
/* 129 */ this.globalTime += this.elapsedTime;
/* */ }
/* 131 */ } catch (InterruptedException e) {
/* */
/* 133 */ e.printStackTrace();
/* */ } finally {
/* */
/* 136 */ close();
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */ private final void close() {
/* */ try {
/* 145 */ this.errorCallback.free();
/* */
/* 147 */ this.camera.close();
/* 148 */ this.display.close();
/* 149 */ this.renderer.close();
/* 150 */ } catch (Exception e) {
/* 151 */ e.printStackTrace();
/* */ } finally {
/* */
/* 154 */ GLFW.glfwTerminate();
/* 155 */ System.exit(0);
/* */ }
/* */ }
/* */
/* */
/* */ public static void main(String[] args) {
/* 161 */ (new Engine()).run();
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/engine/Engine.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,202 +0,0 @@
/* */ package org.engine;
/* */
/* */ import java.awt.Dimension;
/* */ import java.nio.FloatBuffer;
/* */ import org.lwjgl.BufferUtils;
/* */ import org.lwjgl.opengl.GL11;
/* */ import org.lwjgl.opengl.GL15;
/* */ import org.lwjgl.opengl.GL20;
/* */ import org.lwjgl.opengl.GL30C;
/* */ import org.renderer.FBO;
/* */ import org.renderer.PostProcessConfig;
/* */ import org.renderer.PostProcessor;
/* */ import org.renderer.SceneRenderer;
/* */ import org.view.Camera;
/* */ import org.world.World;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Renderer
/* */ implements AutoCloseable
/* */ {
/* 26 */ private static final float[] QUAD_VERTICES = new float[] { -1.0F, 1.0F, 1.0F, 1.0F, 1.0F, -1.0F, 1.0F, -1.0F, -1.0F, -1.0F, -1.0F, 1.0F };
/* 27 */ private static final int DRAW_COUNT = QUAD_VERTICES.length >> 1;
/* */
/* */
/* */
/* */ private int arrayBufferHandle;
/* */
/* */
/* */
/* */ private PostProcessConfig ppConfig;
/* */
/* */
/* */
/* */ private PostProcessor postProcessor;
/* */
/* */
/* */ private SceneRenderer sceneRenderer;
/* */
/* */
/* */ private FBO fbo;
/* */
/* */
/* */ private Dimension size;
/* */
/* */
/* */
/* */ public Renderer(Dimension size) throws AssertionError {
/* 53 */ this.ppConfig = new PostProcessConfig();
/* */
/* 55 */ createQuadGeometry();
/* */
/* 57 */ GL11.glEnable(3553);
/* */
/* 59 */ this.sceneRenderer = new SceneRenderer();
/* 60 */ this.postProcessor = new PostProcessor();
/* */
/* 62 */ this.fbo = new FBO(size);
/* */
/* */
/* 65 */ this.size = size;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ private void createQuadGeometry() {
/* 73 */ this.arrayBufferHandle = GL15.glGenBuffers();
/* */
/* */
/* 76 */ FloatBuffer buffer = BufferUtils.createFloatBuffer(QUAD_VERTICES.length);
/* 77 */ buffer.put(QUAD_VERTICES);
/* 78 */ buffer.flip();
/* */
/* */
/* 81 */ GL15.glBindBuffer(34962, this.arrayBufferHandle);
/* 82 */ GL15.glBufferData(34962, buffer, 35044);
/* 83 */ GL15.glBindBuffer(34962, 0);
/* */
/* */
/* 86 */ buffer.clear();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void update(Dimension size, float globalTime, Camera camera, World world, boolean rebuildFBO) {
/* 100 */ if (rebuildFBO) {
/* 101 */ this.fbo.recreate(size);
/* */ }
/* */
/* 104 */ this.sceneRenderer.bind();
/* */
/* 106 */ this.sceneRenderer.loadUniformData(size, globalTime, camera, world);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final void render() {
/* 114 */ renderSceneToFBO();
/* */
/* 116 */ renderFBOtoScreen();
/* */ }
/* */
/* */
/* */
/* */
/* */ private void renderFBOtoScreen() {
/* 123 */ GL11.glEnableClientState(32884);
/* */
/* */
/* 126 */ GL15.glBindBuffer(34962, this.arrayBufferHandle);
/* */
/* 128 */ GL11.glVertexPointer(2, 5126, 0, 0L);
/* */
/* */
/* 131 */ this.postProcessor.bind();
/* */
/* 133 */ this.postProcessor.loadData(this.size, this.fbo, this.ppConfig);
/* */
/* */
/* 136 */ GL11.glDrawArrays(4, 0, DRAW_COUNT);
/* */
/* 138 */ this.postProcessor.unbind();
/* */
/* */
/* */
/* 142 */ GL15.glBindBuffer(34962, 0);
/* 143 */ GL30C.glBindVertexArray(0);
/* */
/* */
/* 146 */ GL11.glDisableClientState(32884);
/* */ }
/* */
/* */
/* */
/* */
/* */ private void renderSceneToFBO() {
/* 153 */ GL11.glEnableClientState(32884);
/* */
/* */
/* 156 */ GL15.glBindBuffer(34962, this.arrayBufferHandle);
/* */
/* 158 */ GL11.glVertexPointer(2, 5126, 0, 0L);
/* */
/* 160 */ this.fbo.bind();
/* */
/* */
/* 163 */ GL11.glDrawArrays(4, 0, DRAW_COUNT);
/* */
/* */
/* 166 */ this.fbo.unbind();
/* */
/* */
/* 169 */ GL15.glBindBuffer(34962, 0);
/* 170 */ GL30C.glBindVertexArray(0);
/* */
/* 172 */ GL20.glUseProgram(0);
/* */
/* */
/* 175 */ GL11.glDisableClientState(32884);
/* */ }
/* */
/* */
/* */
/* */ public void close() throws Exception {
/* 181 */ GL15.glDeleteBuffers(this.arrayBufferHandle);
/* */
/* 183 */ this.sceneRenderer.close();
/* 184 */ this.postProcessor.close();
/* 185 */ this.fbo.close();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final PostProcessConfig getPpConfig() {
/* 194 */ return this.ppConfig;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/engine/Renderer.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,166 +0,0 @@
/* */ package org.logic;
/* */
/* */ import org.run.ForcedStopException;
/* */ import org.world.World;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class GyteController
/* */ {
/* */ private World world;
/* */ private int coinCount;
/* */
/* */ public GyteController(World world) {
/* 26 */ this.world = world;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void turnRight() throws ForcedStopException {
/* 35 */ this.world.getGytebot().turnRight();
/* */
/* 37 */ waitForGytebotApprove();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void turnLeft() throws ForcedStopException {
/* 46 */ this.world.getGytebot().turnLeft();
/* */
/* 48 */ waitForGytebotApprove();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void goForward() throws ForcedStopException {
/* 57 */ if (!this.world.isLocationObstructed(this.world.getGytebot().getForwardLocation())) {
/* 58 */ this.world.getGytebot().goForward();
/* */ }
/* 60 */ waitForGytebotApprove();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void pickup() throws ForcedStopException {
/* 72 */ if (this.world.isCoinPlacedHere(this.world.getGytebot().getPosition())) {
/* */
/* */
/* 75 */ this.world.removeObject(Math.round((this.world.getGytebot().getPosition()).x), Math.round((this.world.getGytebot().getPosition()).y));
/* 76 */ this.coinCount++;
/* */ }
/* */
/* 79 */ delay();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void delay() throws ForcedStopException {
/* */ try {
/* 92 */ Thread.sleep(250L);
/* 93 */ } catch (InterruptedException e) {
/* */
/* 95 */ throw new ForcedStopException();
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void place() throws ForcedStopException {
/* 107 */ if (this.coinCount > 0) {
/* */
/* */
/* 110 */ this.world.setCoin(Math.round((this.world.getGytebot().getPosition()).x), Math.round((this.world.getGytebot().getPosition()).y));
/* 111 */ this.coinCount--;
/* */ }
/* 113 */ delay();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void waitForGytebotApprove() throws ForcedStopException {
/* 123 */ while (!this.world.getGytebot().isReady()) {
/* */ try {
/* 125 */ Thread.sleep(30L);
/* */ }
/* 127 */ catch (InterruptedException e) {
/* */
/* 129 */ throw new ForcedStopException();
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final boolean hasWallFront() throws ForcedStopException {
/* 141 */ return this.world.isLocationObstructed(this.world.getGytebot().getForwardLocation());
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final boolean isOnCoin() throws ForcedStopException {
/* 151 */ return this.world.isCoinPlacedHere(this.world.getGytebot().getPosition());
/* */ }
/* */
/* */
/* */
/* */
/* */ public final int getCoinCount() throws ForcedStopException {
/* 158 */ return this.coinCount;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/logic/GyteController.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,111 +0,0 @@
/* */ package org.logic;
/* */
/* */ import java.lang.reflect.InvocationTargetException;
/* */ import javax.swing.JOptionPane;
/* */ import org.ui.editors.code.CodeEditor;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class GyteProcessor
/* */ extends Thread
/* */ {
/* */ private GyteController gyteController;
/* */ private CodeEditor editor;
/* */ private Program program;
/* */
/* */ public GyteProcessor(GyteController gyteController, CodeEditor editor) {
/* 32 */ this.gyteController = gyteController;
/* 33 */ this.editor = editor;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void run() {
/* 45 */ this.editor.setProgramStatus(true);
/* */
/* */ try {
/* 48 */ this.program.getMainMethod().invoke(this.program.getProgram(), new Object[] { this.gyteController });
/* */ }
/* 50 */ catch (IllegalAccessException e) {
/* 51 */ e.printStackTrace();
/* 52 */ } catch (IllegalArgumentException e) {
/* 53 */ e.printStackTrace();
/* 54 */ } catch (InvocationTargetException e) {
/* 55 */ if (!(e.getCause() instanceof org.run.ForcedStopException))
/* */ {
/* */
/* */
/* 59 */ System.err.println("The Gyte-Processors Thread did not respond in time and killed");
/* */ }
/* */ }
/* 62 */ System.out.println("> Gyte-Processor has finished");
/* 63 */ this.editor.setProgramStatus(false);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void dispatchProgram(Program program) {
/* 72 */ this.program = program;
/* */
/* 74 */ synchronized (this) {
/* */
/* 76 */ start();
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void halt() {
/* 89 */ interrupt();
/* */
/* */
/* */
/* 93 */ try { join(2000L);
/* */
/* */
/* 96 */ if (isAlive()) {
/* 97 */ stop();
/* */ } }
/* 99 */ catch (InterruptedException interruptedException) { }
/* 100 */ catch (SecurityException death)
/* */
/* 102 */ { JOptionPane.showMessageDialog(null, "The Thread running GYTEBOTS code needed to be stopped by ThreadDeath", "Error - stopping Thread", 0); }
/* */
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/logic/GyteProcessor.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,48 +0,0 @@
/* */ package org.logic;
/* */
/* */ import java.lang.reflect.Method;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Program
/* */ {
/* */ private Object program;
/* */ private Method mainMethod;
/* */
/* */ public Program(Object program, Method mainMethod) {
/* 25 */ this.program = program;
/* 26 */ this.mainMethod = mainMethod;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final Object getProgram() {
/* 33 */ return this.program;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final Method getMainMethod() {
/* 40 */ return this.mainMethod;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/logic/Program.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,28 +0,0 @@
/* */ package org.objects;
/* */
/* */ import java.awt.geom.Point2D;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Coin
/* */ extends WorldObject
/* */ {
/* */ public Coin(Point2D.Float position) {
/* 20 */ super(position);
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/objects/Coin.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,27 +0,0 @@
/* */ package org.objects;
/* */
/* */ import java.awt.geom.Point2D;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Wall
/* */ extends WorldObject
/* */ {
/* */ public Wall(Point2D.Float position) {
/* 19 */ super(position);
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/objects/Wall.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,50 +0,0 @@
/* */ package org.objects;
/* */
/* */ import java.awt.geom.Point2D;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public abstract class WorldObject
/* */ {
/* */ protected Point2D.Float position;
/* */
/* */ public WorldObject(Point2D.Float position) {
/* 24 */ this.position = position;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final Point2D.Float getPosition() {
/* 33 */ return this.position;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void setPosition(Point2D.Float position) {
/* 42 */ this.position = position;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/objects/WorldObject.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,130 +0,0 @@
/* */ package org.renderer;
/* */
/* */ import java.awt.Dimension;
import java.nio.ByteBuffer;
/* */ import org.lwjgl.opengl.GL11C;
/* */ import org.lwjgl.opengl.GL30C;
/* */ import org.lwjgl.opengl.GL32C;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class FBO
/* */ implements AutoCloseable
/* */ {
/* */ private int fboHandle;
/* */ private int fboTexture;
/* */
/* */ public FBO(Dimension size) {
/* 45 */ generate(size);
/* */
/* 47 */ unbind();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void generate(Dimension size) {
/* 57 */ this.fboHandle = GL30C.glGenFramebuffers();
/* */
/* 59 */ this.fboTexture = GL11C.glGenTextures();
/* */
/* */
/* 62 */ GL11C.glBindTexture(3553, this.fboTexture);
/* */
/* */
/* 65 */ GL11C.glTexImage2D(3553, 0, 34836, size.width, size.height, 0, 6408, 5126, (ByteBuffer) null);
/* */
/* */
/* 68 */ GL11C.glTexParameteri(3553, 10240, 9729);
/* 69 */ GL11C.glTexParameteri(3553, 10241, 9729);
/* */
/* */
/* 72 */ GL30C.glBindFramebuffer(36160, this.fboHandle);
/* */
/* 74 */ GL32C.glFramebufferTexture(36160, 36064, this.fboTexture, 0);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void recreate(Dimension size) {
/* 84 */ GL30C.glDeleteFramebuffers(this.fboHandle);
/* 85 */ GL11C.glDeleteTextures(this.fboTexture);
/* */
/* 87 */ generate(size);
/* */ }
/* */
/* */
/* */
/* */
/* */ public final void bind() {
/* 94 */ GL11C.glBindTexture(3553, 0);
/* 95 */ GL30C.glBindFramebuffer(36160, this.fboHandle);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final void unbind() {
/* 103 */ GL30C.glBindFramebuffer(36160, 0);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public int getTextureHandle() {
/* 112 */ return this.fboTexture;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final void close() {
/* 120 */ GL30C.glDeleteFramebuffers(this.fboHandle);
/* 121 */ GL11C.glDeleteTextures(this.fboTexture);
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/renderer/FBO.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,104 +0,0 @@
/* */ package org.renderer;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class PostProcessConfig
/* */ {
/* */ private boolean filterDoF = true;
/* */ private boolean filterFXAA = true;
/* */ private boolean filterGrain = true;
/* */
/* */ public final boolean isFilterGrain() {
/* 34 */ return this.filterGrain;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final void setFilterGrain(boolean filterGrain) {
/* 41 */ this.filterGrain = filterGrain;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final boolean isFilterDoF() {
/* 48 */ return this.filterDoF;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final void setFilterDoF(boolean filterDoF) {
/* 56 */ this.filterDoF = filterDoF;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final boolean isFilterFXAA() {
/* 64 */ return this.filterFXAA;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final void setFilterFXAA(boolean filterFXAA) {
/* 72 */ this.filterFXAA = filterFXAA;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public int getFilterFXAAAsInteger() {
/* 80 */ return this.filterFXAA ? 1 : 0;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public int getFilterGrainAsInteger() {
/* 88 */ return this.filterGrain ? 1 : 0;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public int getFilterDoFAsInteger() {
/* 96 */ return this.filterDoF ? 1 : 0;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/renderer/PostProcessConfig.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,79 +0,0 @@
/* */ package org.renderer;
/* */
/* */ import java.awt.Dimension;
/* */ import org.lwjgl.opengl.GL11C;
/* */ import org.lwjgl.opengl.GL13C;
/* */ import org.lwjgl.opengl.GL20C;
/* */ import org.shader.ShaderProgram;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class PostProcessor
/* */ extends ShaderProgram
/* */ {
/* */ private int fboTextureLocation;
/* */ private int resolutionLocation;
/* */ private int useFXAALocation;
/* */ private int useDoFLocation;
/* */ private int useGrainLocation;
/* */
/* */ public PostProcessor() throws AssertionError {
/* 34 */ super("/data/shader/PostProcessor");
/* */
/* */
/* */
/* 38 */ this.fboTextureLocation = GL20C.glGetUniformLocation(this.program, "fboTexture");
/* 39 */ this.resolutionLocation = GL20C.glGetUniformLocation(this.program, "resolution");
/* */
/* */
/* 42 */ this.useFXAALocation = GL20C.glGetUniformLocation(this.program, "boolFilterFXAA");
/* 43 */ this.useDoFLocation = GL20C.glGetUniformLocation(this.program, "boolFilterDoF");
/* 44 */ this.useGrainLocation = GL20C.glGetUniformLocation(this.program, "boolFilterGrain");
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void loadData(Dimension size, FBO fbo, PostProcessConfig config) {
/* 53 */ GL20C.glUniform2f(this.resolutionLocation, size.width, size.height);
/* */
/* */
/* 56 */ GL20C.glUniform1i(this.useFXAALocation, config.getFilterFXAAAsInteger());
/* 57 */ GL20C.glUniform1i(this.useDoFLocation, config.getFilterDoFAsInteger());
/* 58 */ GL20C.glUniform1i(this.useGrainLocation, config.getFilterGrainAsInteger());
/* */
/* */
/* 61 */ GL13C.glActiveTexture(33984);
/* 62 */ GL11C.glBindTexture(3553, fbo.getTextureHandle());
/* 63 */ GL20C.glUniform1i(this.fboTextureLocation, 0);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final void close() {
/* 71 */ super.close();
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/renderer/PostProcessor.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,255 +0,0 @@
/* */ package org.renderer;
/* */
/* */ import java.awt.Dimension;
/* */ import java.nio.IntBuffer;
/* */ import java.util.HashMap;
/* */ import java.util.Map;
/* */ import javax.swing.JOptionPane;
/* */ import org.lwjgl.BufferUtils;
/* */ import org.lwjgl.opengl.GL11C;
/* */ import org.lwjgl.opengl.GL13C;
/* */ import org.lwjgl.opengl.GL15C;
/* */ import org.lwjgl.opengl.GL20C;
/* */ import org.lwjgl.opengl.GL30C;
/* */ import org.lwjgl.opengl.GL43C;
/* */ import org.shader.ShaderProgram;
/* */ import org.textures.Texture;
/* */ import org.view.Camera;
/* */ import org.world.World;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class SceneRenderer
/* */ extends ShaderProgram
/* */ {
/* 50 */ public static final String[] UNIFORM_NAMES = new String[] {
/* 51 */ "resolution",
/* 52 */ "time",
/* 53 */ "cameraRotation",
/* 54 */ "cameraZoom",
/* 55 */ "worldTexture",
/* 56 */ "environmentTexture",
/* 57 */ "coinTexture",
/* 58 */ "width",
/* 59 */ "height",
/* 60 */ "drawGytebot",
/* 61 */ "gytebotLocation",
/* 62 */ "gytebotRotation" };
/* */
/* */
/* */ private Texture worldTexture;
/* */
/* */
/* */ private Texture environmentTexture;
/* */
/* */
/* */ private Texture coinTexture;
/* */
/* */
/* */ private Texture testTexture;
/* */
/* */ private int coinBuffer;
/* */
/* */ private int coinSsbo;
/* */
/* */ private int wallBuffer;
/* */
/* */ private int wallSsbo;
/* */
/* */ private Map<String, Integer> uniformLocations;
/* */
/* */
/* */ public SceneRenderer() throws AssertionError {
/* 88 */ super("/data/shader/SceneRenderer");
/* */
/* 90 */ this.uniformLocations = new HashMap<>();
/* */
/* */
/* 93 */ this.coinSsbo = GL15C.glGenBuffers();
/* 94 */ this.wallSsbo = GL15C.glGenBuffers();
/* */
/* 96 */ createUniforms();
/* */
/* */
/* */ try {
/* 100 */ createTextures();
/* */ }
/* 102 */ catch (Exception e) {
/* */
/* */
/* 105 */ JOptionPane.showMessageDialog(null, "Unable to load texture(s)", "Error - loading textures", 0);
/* 106 */ e.printStackTrace();
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void createTextures() throws Exception {
/* 116 */ this.worldTexture = new Texture("data/icons/atlas.png");
/* 117 */ this.environmentTexture = new Texture("data/icons/environment.png");
/* 118 */ this.coinTexture = new Texture("data/icons/coin.png");
/* 119 */ this.testTexture = new Texture("data/icons/test.png");
/* */ }
/* */
/* */
/* */ private void createUniforms() {
/* */ byte b;
/* */ int i;
/* */ String[] arrayOfString;
/* 127 */ for (i = (arrayOfString = UNIFORM_NAMES).length, b = 0; b < i; ) { String uniformName = arrayOfString[b];
/* */
/* 129 */ int location = GL20C.glGetUniformLocation(this.program, uniformName);
/* */
/* 131 */ if (location == -1)
/* */ {
/* 133 */ System.err.println("Unable to find uniform: " + uniformName);
/* */ }
/* */
/* */
/* 137 */ this.uniformLocations.put(uniformName, Integer.valueOf(location));
/* */
/* */ b++; }
/* */
/* 141 */ GL20C.glUseProgram(this.program);
/* */
/* */
/* 144 */ IntBuffer props = BufferUtils.createIntBuffer(1);
/* 145 */ IntBuffer params = BufferUtils.createIntBuffer(1);
/* 146 */ props.put(0, 37634);
/* */
/* */
/* 149 */ int coinBufferResourceIndex = GL43C.glGetProgramResourceIndex(this.program, 37606, "CoinBuffer");
/* 150 */ int wallBufferResourceIndex = GL43C.glGetProgramResourceIndex(this.program, 37606, "WallBuffer");
/* */
/* */
/* 153 */ GL43C.glGetProgramResourceiv(this.program, 37606, coinBufferResourceIndex, props, null, params);
/* 154 */ this.coinBuffer = params.get(0);
/* */
/* */
/* 157 */ GL43C.glGetProgramResourceiv(this.program, 37606, wallBufferResourceIndex, props, null, params);
/* 158 */ this.wallBuffer = params.get(0);
/* */
/* 160 */ GL20C.glUseProgram(0);
/* */ }
/* */
/* */
/* */
/* */ public void loadUniformData(Dimension size, float globalTime, Camera camera, World world) {
/* 166 */ if (world.updateCoinTextureData()) {
/* */
/* 168 */ GL15C.glBindBuffer(34962, this.coinSsbo);
/* 169 */ GL15C.glBufferData(34962, world.getCoinTextureData(), 35044);
/* 170 */ GL15C.glBindBuffer(34962, 0);
/* */ }
/* */
/* */
/* 174 */ if (world.updateWallBufferData()) {
/* */
/* 176 */ GL15C.glBindBuffer(34962, this.wallSsbo);
/* 177 */ GL15C.glBufferData(34962, world.getWallBufferData(), 35044);
/* 178 */ GL15C.glBindBuffer(34962, 0);
/* */ }
/* */
/* */
/* */
/* */
/* 184 */ GL20C.glUniform2f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[0])).intValue(), size.width, size.height);
/* 185 */ GL20C.glUniform1f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[1])).intValue(), globalTime);
/* */
/* 187 */ GL20C.glUniform2f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[2])).intValue(), camera.getCameraRotationX(), camera.getCameraRotationY());
/* 188 */ GL20C.glUniform1f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[3])).intValue(), camera.getCameraZoom());
/* */
/* 190 */ GL13C.glActiveTexture(33984);
/* 191 */ GL11C.glBindTexture(3553, this.worldTexture.getHandle());
/* 192 */ GL20C.glUniform1i(((Integer)this.uniformLocations.get(UNIFORM_NAMES[4])).intValue(), 0);
/* */
/* 194 */ GL13C.glActiveTexture(33985);
/* 195 */ GL11C.glBindTexture(3553, this.environmentTexture.getHandle());
/* 196 */ GL20C.glUniform1i(((Integer)this.uniformLocations.get(UNIFORM_NAMES[5])).intValue(), 1);
/* */
/* 198 */ GL13C.glActiveTexture(33986);
/* 199 */ GL11C.glBindTexture(3553, this.coinTexture.getHandle());
/* 200 */ GL20C.glUniform1i(((Integer)this.uniformLocations.get(UNIFORM_NAMES[6])).intValue(), 2);
/* */
/* 202 */ GL13C.glActiveTexture(33987);
/* 203 */ GL11C.glBindTexture(3553, this.testTexture.getHandle());
/* 204 */ GL20C.glUniform1i(GL20C.glGetUniformLocation(this.program, "testTexture"), 3);
/* */
/* 206 */ GL20C.glUniform1f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[7])).intValue(), world.getWidth());
/* 207 */ GL20C.glUniform1f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[8])).intValue(), world.getHeight());
/* */
/* 209 */ GL20C.glUniform1i(((Integer)this.uniformLocations.get(UNIFORM_NAMES[9])).intValue(), world.getDrawGytebotAsInt());
/* */
/* */
/* 212 */ if (world.getGytebot() != null) {
/* */
/* 214 */ GL20C.glUniform2f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[10])).intValue(), (world.getGytebot().getPosition()).x, (world.getGytebot().getPosition()).y);
/* 215 */ GL20C.glUniform1f(((Integer)this.uniformLocations.get(UNIFORM_NAMES[11])).intValue(), world.getGytebot().getViewAngle());
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void bind() {
/* 225 */ super.bind();
/* 226 */ GL30C.glBindBufferBase(37074, this.coinBuffer, this.coinSsbo);
/* 227 */ GL30C.glBindBufferBase(37074, this.wallBuffer, this.wallSsbo);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void unbind() {
/* 236 */ super.unbind();
/* 237 */ GL30C.glBindBufferBase(37074, this.coinBuffer, 0);
/* 238 */ GL30C.glBindBufferBase(37074, this.wallBuffer, 0);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final void close() {
/* 246 */ super.close();
/* */
/* 248 */ GL15C.glDeleteBuffers(this.coinSsbo);
/* 249 */ GL15C.glDeleteBuffers(this.coinSsbo);
/* */
/* 251 */ this.worldTexture.close();
/* 252 */ this.environmentTexture.close();
/* 253 */ this.coinTexture.close();
/* */ }
/* */ }

View File

@ -1,26 +0,0 @@
/* */ package org.run;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class ForcedStopException
/* */ extends Exception
/* */ {
/* */ private static final long serialVersionUID = -5622884875009979898L;
/* */
/* */ public ForcedStopException() {
/* 18 */ super("The running thread needed to be stopped violently, no excusses");
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/run/ForcedStopException.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,252 +0,0 @@
/* */ package org.run;
/* */
/* */ import java.io.File;
/* */ import java.io.IOException;
/* */ import java.lang.reflect.InvocationTargetException;
/* */ import java.lang.reflect.Method;
/* */ import java.net.MalformedURLException;
/* */ import java.net.URL;
/* */ import java.net.URLClassLoader;
/* */ import java.nio.file.Files;
/* */ import java.nio.file.Path;
/* */ import java.nio.file.Paths;
/* */ import java.nio.file.attribute.FileAttribute;
/* */ import java.util.Arrays;
/* */ import javax.tools.Diagnostic;
/* */ import javax.tools.DiagnosticCollector;
/* */ import javax.tools.JavaCompiler;
/* */ import javax.tools.JavaFileObject;
/* */ import javax.tools.StandardJavaFileManager;
/* */ import javax.tools.ToolProvider;
/* */ import org.logic.GyteController;
/* */ import org.logic.GyteProcessor;
/* */ import org.logic.Program;
/* */ import org.ui.debug.Console;
/* */ import org.ui.debug.Entry;
/* */ import org.ui.editors.code.CodeEditor;
/* */ import org.world.World;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class GyteCompiler
/* */ {
/* */ private static final String CLASS_NAME = "GyteProgram";
/* */ private static final String METHOD_NAME = "run";
/* */ private static final boolean SUCCESS = true;
/* */ private volatile GyteProcessor processor;
/* */ private World world;
/* */ private CodeEditor editor;
/* */ private Console console;
/* */ private File[] file;
/* */ private JavaCompiler compiler;
/* */ private StandardJavaFileManager fileManager;
/* */ private Iterable<? extends JavaFileObject> compilationUnits;
/* */ private DiagnosticCollector<JavaFileObject> diagnostics;
/* */ private boolean isCompilerInstalled;
/* */
/* */ public GyteCompiler(World world, Console console, CodeEditor editor) {
/* 73 */ this.world = world;
/* 74 */ this.console = console;
/* 75 */ this.editor = editor;
/* */
/* */
/* 78 */ this.compiler = ToolProvider.getSystemJavaCompiler();
/* */
/* 80 */ this.isCompilerInstalled = (this.compiler != null);
/* */
/* 82 */ if (this.isCompilerInstalled) {
/* */
/* 84 */ this.fileManager = this.compiler.getStandardFileManager(null, null, null);
/* */
/* */ }
/* */ else {
/* */
/* 89 */ console.createLog("No Java Compiler could be found on this system\n", Entry.WARNING);
/* 90 */ console.createLog("See README.MD for futher instructions/help\n", Entry.WARNING);
/* */ }
/* */
/* */
/* 94 */ System.setOut(console.getStdOut());
/* 95 */ System.setErr(console.getStdErr());
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void compileAndRunProgram(String source) {
/* 104 */ this.console.createLog("Compiling source...\n", Entry.INFORMATION);
/* */
/* */
/* 107 */ Path temp = Paths.get(System.getProperty("java.io.tmpdir"), new String[] { "GyteProgram" });
/* */
/* */
/* */ try {
/* 111 */ Files.createDirectories(temp, (FileAttribute<?>[])new FileAttribute[0]);
/* */
/* */
/* 114 */ Path javaSourceFile = Paths.get(temp.normalize().toAbsolutePath().toString(), new String[] { "GyteProgram.java" });
/* */
/* */
/* 117 */ Files.write(javaSourceFile, source.getBytes(), new java.nio.file.OpenOption[0]);
/* */
/* */
/* 120 */ compile(javaSourceFile, temp);
/* */
/* 122 */ Path classFile = Paths.get(temp.normalize().toAbsolutePath().toString(), new String[] { "GyteProgram.class" });
/* */
/* */
/* 125 */ if (Files.exists(classFile, new java.nio.file.LinkOption[0])) {
/* 126 */ Files.delete(classFile);
/* */ }
/* */
/* 129 */ Files.delete(javaSourceFile);
/* */
/* 131 */ Files.delete(temp);
/* */ }
/* 133 */ catch (IOException e1) {
/* 134 */ this.console.createLog("Unable to find or edit \"java.io.tmpdir\": " + temp.toString() + "\n", Entry.ERROR);
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void compile(Path javaSourceFile, Path temp) {
/* 145 */ this.file = new File[] { javaSourceFile.toFile() };
/* 146 */ this.compilationUnits = this.fileManager.getJavaFileObjectsFromFiles(Arrays.asList(this.file));
/* 147 */ this.diagnostics = new DiagnosticCollector<>();
/* */
/* */
/* 150 */ JavaCompiler.CompilationTask task = this.compiler.getTask(null, this.fileManager, this.diagnostics, null, null, this.compilationUnits);
/* */
/* */
/* 153 */ boolean compilationStatus = task.call().booleanValue();
/* */
/* */
/* 156 */ for (Diagnostic<?> diagnostic : this.diagnostics.getDiagnostics()) {
/* */
/* 158 */ this.console.createLog(String.format("Error in line: %d\nat: %s\n%s\n\n", new Object[] { Long.valueOf(diagnostic.getLineNumber()), diagnostic.getSource(), diagnostic.getMessage(null) }), Entry.ERROR);
/* */
/* 160 */ this.editor.markLine((int)diagnostic.getLineNumber());
/* */ }
/* */
/* */
/* 164 */ if (compilationStatus) {
/* 165 */ runProgram(temp);
/* */ }
/* */
/* */ try {
/* 169 */ this.fileManager.close();
/* 170 */ } catch (IOException e) {
/* 171 */ this.console.createLog("The compiler's file resources could not be deleted\n", Entry.ERROR);
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void runProgram(Path temp) {
/* */ try {
/* 184 */ ClassLoader classLoader = getClass().getClassLoader();
/* 185 */ URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { temp.toUri().toURL() }, classLoader);
/* */
/* */
/* */
/* */
/* */
/* */ try {
/* 192 */ Class<?> javaDemoClass = urlClassLoader.loadClass("GyteProgram");
/* */
/* */ try {
/* 195 */ Object instance = javaDemoClass.getConstructor(new Class[0]).newInstance(new Object[0]);
/* 196 */ Method method = instance.getClass().getMethod("run", new Class[] { GyteController.class });
/* */
/* 198 */ if (this.processor != null && this.processor.isAlive()) {
/* */
/* */
/* 201 */ this.processor.halt();
/* 202 */ this.console.createLog("A processor was still running, an was thus shutdown\n", Entry.WARNING);
/* */ }
/* */
/* */
/* 206 */ this.processor = new GyteProcessor(new GyteController(this.world), this.editor);
/* */
/* 208 */ this.processor.dispatchProgram(new Program(instance, method));
/* */
/* 210 */ this.console.createLog("Dispatching program...\n", Entry.INFORMATION);
/* */ }
/* 212 */ catch (InstantiationException e) {
/* 213 */ e.printStackTrace();
/* 214 */ } catch (IllegalAccessException e) {
/* 215 */ e.printStackTrace();
/* 216 */ } catch (IllegalArgumentException e) {
/* 217 */ e.printStackTrace();
/* 218 */ } catch (InvocationTargetException e) {
/* 219 */ e.printStackTrace();
/* */ }
/* */
/* 222 */ urlClassLoader.close();
/* */ }
/* 224 */ catch (ClassNotFoundException e1) {
/* 225 */ this.console.createLog("The required Class \"GyteProgram\" was not defined or could not be compiled.\n", Entry.ERROR);
/* 226 */ } catch (NoSuchMethodException e1) {
/* 227 */ this.console.createLog("The required Method \"run\"\nin type \"GyteProgram\" was not defined.\n", Entry.ERROR);
/* 228 */ } catch (SecurityException e1) {
/* 229 */ this.console.createLog("Security violation detected.", Entry.ERROR);
/* 230 */ } catch (IOException e) {
/* 231 */ this.console.createLog("Unable to close class loader", Entry.ERROR);
/* */ }
/* 233 */ } catch (MalformedURLException e) {
/* 234 */ this.console.createLog("The class file(s) URL was invalid!\n", Entry.ERROR);
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final GyteProcessor getProcessor() {
/* 244 */ return this.processor;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/run/GyteCompiler.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,84 +0,0 @@
/* */ package org.shader;
/* */
/* */ import java.io.BufferedReader;
/* */ import java.io.InputStreamReader;
/* */ import org.lwjgl.opengl.GL20C;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Shader
/* */ implements AutoCloseable
/* */ {
/* */ private int shaderHandle;
/* */
/* */ public Shader(String fileName, int shaderType) throws AssertionError {
/* 28 */ this.shaderHandle = GL20C.glCreateShader(shaderType);
/* */
/* 30 */ GL20C.glShaderSource(this.shaderHandle, getSource(fileName));
/* 31 */ GL20C.glCompileShader(this.shaderHandle);
/* */
/* 33 */ if (GL20C.glGetShaderi(this.shaderHandle, 35713) == 0) {
/* */
/* 35 */ System.err.println(GL20C.glGetShaderInfoLog(this.shaderHandle));
/* 36 */ throw new AssertionError("Could not compile Shader: " + fileName);
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private String getSource(String fileName) {
/* */ try {
/* 49 */ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResource(fileName).openStream()));
/* */
/* 51 */ String result = reader.lines().reduce("", (A, B) -> String.valueOf(A) + B + System.lineSeparator());
/* */
/* 53 */ reader.close();
/* */
/* 55 */ return result;
/* 56 */ } catch (Exception e) {
/* 57 */ e.printStackTrace();
/* 58 */ return null;
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final int getHandle() {
/* 68 */ return this.shaderHandle;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public void close() {
/* 76 */ GL20C.glDeleteShader(this.shaderHandle);
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/shader/Shader.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,85 +0,0 @@
/* */ package org.shader;
/* */
/* */ import org.lwjgl.opengl.GL20C;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class ShaderProgram
/* */ implements AutoCloseable
/* */ {
/* */ protected int program;
/* */ private Shader vertexShader;
/* */ private Shader fragmentShader;
/* */
/* */ public ShaderProgram(String shaderName) throws AssertionError {
/* 28 */ this.program = GL20C.glCreateProgram();
/* */
/* */
/* 31 */ this.vertexShader = new Shader(String.valueOf(shaderName) + ".vsh.glsl", 35633);
/* 32 */ this.fragmentShader = new Shader(String.valueOf(shaderName) + ".fsh.glsl", 35632);
/* */
/* */
/* 35 */ GL20C.glAttachShader(this.program, this.vertexShader.getHandle());
/* 36 */ GL20C.glAttachShader(this.program, this.fragmentShader.getHandle());
/* */
/* 38 */ GL20C.glBindAttribLocation(this.program, 0, "vertexPosition");
/* */
/* 40 */ GL20C.glLinkProgram(this.program);
/* 41 */ if (GL20C.glGetProgrami(this.program, 35714) == 0) {
/* */
/* 43 */ System.err.println(GL20C.glGetProgramInfoLog(this.program));
/* 44 */ throw new AssertionError("Unable to create shader program");
/* */ }
/* */
/* 47 */ GL20C.glValidateProgram(this.program);
/* 48 */ if (GL20C.glGetProgrami(this.program, 35715) == 0) {
/* */
/* 50 */ System.err.println(GL20C.glGetProgramInfoLog(this.program));
/* 51 */ throw new AssertionError("Unable to create shader program");
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */ public void bind() {
/* 59 */ GL20C.glUseProgram(this.program);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public void close() {
/* 67 */ GL20C.glDeleteProgram(this.program);
/* */
/* 69 */ this.vertexShader.close();
/* 70 */ this.fragmentShader.close();
/* */ }
/* */
/* */
/* */
/* */
/* */ public void unbind() {
/* 77 */ GL20C.glUseProgram(0);
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/shader/ShaderProgram.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,72 +0,0 @@
package org.textures;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL30C;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidParameterException;
public class Texture implements AutoCloseable {
private int textureHandle;
public Texture(String resource) throws Exception {
final BufferedImage image = loadImageDataAsARGB(resource);
final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
// generate OpenGL texture buffer
this.textureHandle = GL11C.glGenTextures();
GL11C.glBindTexture(GL11C.GL_TEXTURE_2D, this.textureHandle);
GL11C.glPixelStorei(3317, 1);
GL11C.glTexParameteri(3553, 10241, 9987);
GL11C.glTexParameteri(3553, 10240, 9729);
GL11C.glTexParameteri(3553, 10242, 10497);
GL11C.glTexParameteri(3553, 10243, 10497);
GL11C.glTexImage2D(3553, 0, 6408, image.getWidth(), image.getHeight(), 0, 6408, 5121, pixels);
GL30C.glGenerateMipmap(3553);
GL11C.glBindTexture(3553, 0);
}
/**
* Load image from disk as array of colors in ARGB format
*
* @param resource file path to load
* @return array of ARGB values
*/
private BufferedImage loadImageDataAsARGB(String resource) throws Exception {
InputStream stream = Texture.class.getClassLoader().getResourceAsStream(resource);
if (stream == null)
throw new InvalidParameterException("Resource not found: " + resource);
// buffer raw image data
BufferedImage rawData = ImageIO.read(stream);
// create buffer of fixed color layout of ARGB-Bytes
BufferedImage layoutedData = new BufferedImage(rawData.getWidth(), rawData.getHeight(), BufferedImage.TYPE_INT_ARGB);
// write raw image data into buffer with known color format
layoutedData.createGraphics().drawImage(rawData, 0, 0, null);
return layoutedData;
}
public final int getHandle() {
return this.textureHandle;
}
public void close() {
GL11C.glDeleteTextures(this.textureHandle);
}
}

View File

@ -1,74 +0,0 @@
/* */ package org.ui;
/* */
/* */ import java.awt.Dimension;
/* */ import java.awt.Toolkit;
/* */ import java.io.BufferedReader;
/* */ import java.io.InputStreamReader;
/* */ import javax.swing.JEditorPane;
/* */ import javax.swing.JFrame;
/* */ import javax.swing.JOptionPane;
/* */ import javax.swing.JScrollPane;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Documentation
/* */ extends JFrame
/* */ {
/* */ private static final long serialVersionUID = 4741160972916811991L;
/* */ private JEditorPane textPane;
/* */
/* */ public Documentation() {
/* 33 */ Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
/* */
/* */
/* 36 */ this.textPane = new JEditorPane();
/* 37 */ this.textPane.setContentType("text/html");
/* 38 */ this.textPane.setEditable(false);
/* */
/* 40 */ loadDocsFromFile();
/* */
/* */
/* 43 */ setTitle("RTX-GYTEBOT - Documentation (also README)");
/* 44 */ getContentPane().add(new JScrollPane(this.textPane));
/* 45 */ setSize(size.width * 3 >> 2, size.height * 3 >> 2);
/* 46 */ setLocationRelativeTo(null);
/* 47 */ setVisible(true);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ private void loadDocsFromFile() {
/* */ try {
/* 56 */ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/data/docs.html")));
/* */
/* */
/* 59 */ this.textPane.setText(reader.lines().reduce("", (A, B) -> String.valueOf(A) + B + "\n"));
/* */
/* 61 */ reader.close();
/* 62 */ } catch (Exception e) {
/* */
/* 64 */ JOptionPane.showMessageDialog(null, "Could not open or read the deocumentation", "Error - documentation", 0);
/* 65 */ e.printStackTrace();
/* */ }
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/Documentation.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,95 +0,0 @@
package org.ui;
import com.formdev.flatlaf.FlatDarkLaf;
import org.renderer.PostProcessConfig;
import org.ui.editors.code.CodeEditor;
import org.ui.editors.map.MapEditor;
import org.ui.icons.IconLoader;
import org.world.World;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class UIAccess
implements AutoCloseable {
private JFrame startUpWindow;
private JProgressBar infoLog;
private Documentation docs;
private MapEditor mapEditor;
private CodeEditor codeEditor;
private BufferedImage windowIcon;
public UIAccess() {
try {
this.windowIcon = IconLoader.loadWindowIcon();
if (!FlatDarkLaf.setup()) {
}
this.infoLog = new JProgressBar(0, 0, 100);
this.infoLog.setStringPainted(true);
this.startUpWindow = new JFrame("RTX-GYTEBOT");
this.startUpWindow.setIconImage(this.windowIcon);
this.startUpWindow.setUndecorated(true);
this.startUpWindow.setDefaultCloseOperation(0);
this.startUpWindow.getContentPane().setLayout(new BorderLayout());
this.startUpWindow.getContentPane().add(new JLabel(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/data/icons/startup.png")))), "Center");
this.startUpWindow.getContentPane().add(this.infoLog, "South");
this.startUpWindow.pack();
this.startUpWindow.setLocationRelativeTo(null);
this.startUpWindow.setVisible(true);
} catch (IOException | NullPointerException e) {
this.startUpWindow.dispose();
throw new AssertionError("Unable to load or find startup image");
}
}
public final boolean windowCloseRequest() {
return !(!this.mapEditor.getWindowCloseRequest() && !this.codeEditor.getWindowCloseRequest());
}
public final void apply(World world, PostProcessConfig postProcessConfig) {
this.mapEditor = new MapEditor(world);
this.mapEditor.setIconImage(this.windowIcon);
this.codeEditor = new CodeEditor(world, postProcessConfig);
this.codeEditor.setIconImage(this.windowIcon);
}
public final void openDocs() {
this.docs = new Documentation();
}
public void putInfoLoadingMessage(String message, int progress) {
this.infoLog.setString(message);
this.infoLog.setValue(progress);
}
public final void close() {
this.startUpWindow.setVisible(false);
this.startUpWindow.dispose();
}
public BufferedImage getWindowIcon() {
return this.windowIcon;
}
}

View File

@ -1,29 +0,0 @@
/* */ package org.ui;
/* */
/* */ import java.awt.Color;
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class UIConfig
/* */ {
/* */ public static final int GUI_SCALE = 28;
/* */ public static final int MAP_FONT_SIZE = 24;
/* */ public static final int CODE_FONT_SIZE = 16;
/* */ public static final int CONSOLE_FONT_SIZE = 14;
/* */ public static final int INFORMATION_FONT_SIZE = 12;
/* */ public static final String DEFAULT_FONT = "Consolas";
/* */ public static final String DEFAULT_WINDOW_TITLE = "RTX-GYTEBOT";
/* */ public static final int CONSOLE_QUEUE_SIZE = 36;
/* */ public static final int CONSOLE_ENTRY_SIZE = 48;
/* */ public static final long MIN_FRAME_TIME_LIMIT = 16L;
/* 22 */ public static final Color CONTENT_BACKGROUND = new Color(15921131);
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/UIConfig.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,32 +0,0 @@
package org.ui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class UICreator {
public static JButton createIconifiedButton(char iconCharacterCode) {
final JButton button = new JButton(String.valueOf(iconCharacterCode));
button.setFont(new Font("RTX-GYTEBOT-ICONS", 0, 28));
button.setFocusPainted(false);
button.setContentAreaFilled(false);
button.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 10));
button.setOpaque(false);
button.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent event) {
button.setCursor(new Cursor(12));
}
public void mouseExited(MouseEvent event) {
button.setCursor(new Cursor(0));
}
});
return button;
}
}

View File

@ -1,258 +0,0 @@
/* */ package org.ui.debug;
/* */
/* */ import java.awt.BorderLayout;
/* */ import java.awt.Color;
/* */ import java.awt.FlowLayout;
/* */ import java.awt.Font;
/* */ import java.awt.event.ActionEvent;
/* */ import java.io.PrintStream;
/* */ import javax.swing.BorderFactory;
/* */ import javax.swing.BoxLayout;
/* */ import javax.swing.JButton;
/* */ import javax.swing.JLabel;
/* */ import javax.swing.JPanel;
/* */ import javax.swing.JScrollPane;
/* */ import javax.swing.JTextArea;
/* */ import org.ui.UICreator;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Console
/* */ extends JPanel
/* */ {
/* */ private static final long serialVersionUID = -1800165403047521827L;
/* */ private JPanel consoleLogger;
/* */ private JScrollPane scrollPane;
/* */ private JPanel toolBar;
/* */ private JButton clear;
/* */ private JLabel queueSize;
/* */ private JLabel info;
/* */ private ConsoleWriteStream stdout;
/* */ private ConsoleWriteStream stderr;
/* 50 */ private Entry lastEntry = Entry.NORMAL;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public Console() {
/* 59 */ setLayout(new BorderLayout());
/* */
/* 61 */ createUI();
/* */
/* 63 */ setupUI();
/* */
/* 65 */ createListener();
/* */
/* 67 */ createWriteStreams();
/* */
/* */
/* 70 */ add(this.scrollPane, "Center");
/* 71 */ add(this.toolBar, "North");
/* */
/* */
/* 74 */ createLog("Console was created successfully\n", Entry.INFORMATION);
/* */ }
/* */
/* */
/* */
/* */
/* */ private void createListener() {
/* 81 */ this.clear.addActionListener(e -> {
/* */ this.consoleLogger.removeAll();
/* */ this.consoleLogger.revalidate();
/* */ this.consoleLogger.repaint();
/* */ this.queueSize.setText("| Elements: (none)");
/* */ this.info.setText((String)null);
/* */ });
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void setupUI() {
/* 97 */ this.consoleLogger.setLayout(new BoxLayout(this.consoleLogger, 1));
/* 98 */ this.info.setForeground(Color.YELLOW);
/* */
/* */
/* 101 */ this.clear.setToolTipText("Clear the console logger's buffer.\nThis means deleting all current log entries in the console.");
/* */
/* 103 */ this.scrollPane.setVerticalScrollBarPolicy(22);
/* 104 */ this.scrollPane.setHorizontalScrollBarPolicy(30);
/* 105 */ this.scrollPane.setAutoscrolls(true);
/* */
/* */
/* 108 */ this.toolBar.add(new JLabel("Console"));
/* 109 */ this.toolBar.add(this.clear);
/* 110 */ this.toolBar.add(this.queueSize);
/* 111 */ this.toolBar.add(this.info);
/* */ }
/* */
/* */
/* */
/* */
/* */ private void createUI() {
/* 118 */ this.toolBar = new JPanel(new FlowLayout(0, 4, 0));
/* */
/* 120 */ this.consoleLogger = new JPanel();
/* */
/* 122 */ this.scrollPane = new JScrollPane(this.consoleLogger);
/* */
/* 124 */ this.clear = UICreator.createIconifiedButton('c');
/* 125 */ this.queueSize = new JLabel();
/* 126 */ this.info = new JLabel();
/* */ }
/* */
/* */
/* */
/* */
/* */ private void createWriteStreams() {
/* 133 */ this.stdout = new ConsoleWriteStream(this, Entry.NORMAL);
/* 134 */ this.stderr = new ConsoleWriteStream(this, Entry.ERROR);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final synchronized void createLog(String message, Entry entryType) {
/* 148 */ JTextArea lastLog = getLastEntryLog();
/* */
/* */
/* */
/* 152 */ if (this.lastEntry == entryType && lastLog != null && (int)lastLog.getText().lines().count() < 48) {
/* */
/* */
/* 155 */ lastLog.setText(String.format("%s%s", new Object[] { lastLog.getText(), message }));
/* */
/* */
/* 158 */ this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
/* 159 */ this.scrollPane.repaint();
/* */
/* */ }
/* */ else {
/* */
/* 164 */ boolean isQueueFull = ((this.consoleLogger.getComponents()).length > 36);
/* */
/* */
/* 167 */ this.info.setText(isQueueFull ? "Elements were deleted form Console buffer due to limited queue size" : null);
/* */
/* */
/* 170 */ if (isQueueFull)
/* */ {
/* */
/* 173 */ this.consoleLogger.remove(this.consoleLogger.getComponents()[0]);
/* */ }
/* */
/* */
/* 177 */ createBasicConsoleLog(message, Entry.getColorByEnum(entryType));
/* */ }
/* */
/* 180 */ this.lastEntry = entryType;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private JTextArea getLastEntryLog() {
/* 190 */ int elementIndex = (this.consoleLogger.getComponents()).length - 1;
/* */
/* 192 */ if (elementIndex < 0)
/* */ {
/* 194 */ return null;
/* */ }
/* */
/* */
/* 198 */ return (JTextArea)this.consoleLogger.getComponents()[elementIndex];
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void createBasicConsoleLog(String message, Color color) {
/* 211 */ JTextArea messageBlock = new JTextArea(message);
/* */
/* */
/* */
/* */
/* 216 */ messageBlock.setBorder(BorderFactory.createEmptyBorder());
/* */
/* 218 */ messageBlock.setFont(new Font("Consolas", 0, 14));
/* */
/* 220 */ messageBlock.setEditable(false);
/* */
/* 222 */ messageBlock.setBackground(new Color(1579032));
/* */
/* 224 */ messageBlock.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.DARK_GRAY));
/* 225 */ messageBlock.setForeground(color);
/* */
/* */
/* */
/* 229 */ this.consoleLogger.add(messageBlock);
/* 230 */ this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
/* */
/* 232 */ this.queueSize.setText(String.format("Elements: (%d)", new Object[] { Integer.valueOf((this.consoleLogger.getComponents()).length) }));
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public PrintStream getStdOut() {
/* 241 */ return new PrintStream(this.stdout);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public PrintStream getStdErr() {
/* 250 */ return new PrintStream(this.stderr);
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/debug/Console.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,59 +0,0 @@
/* */ package org.ui.debug;
/* */
/* */ import java.io.IOException;
/* */ import java.io.OutputStream;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class ConsoleWriteStream
/* */ extends OutputStream
/* */ {
/* */ private Console parentConsole;
/* */ private String streamBuffer;
/* */ private Entry entryType;
/* */
/* */ public ConsoleWriteStream(Console parentConsole, Entry entryType) {
/* 30 */ this.parentConsole = parentConsole;
/* 31 */ this.entryType = entryType;
/* 32 */ this.streamBuffer = new String();
/* */ }
/* */
/* */
/* */ public void write(int b) throws IOException {
/* 37 */ this.streamBuffer = String.valueOf(this.streamBuffer) + (char)b;
/* */ }
/* */
/* */
/* */
/* */ public void write(byte[] b, int off, int len) throws IOException {
/* 43 */ for (int i = off; i < off + len; i++) {
/* 44 */ this.streamBuffer = String.valueOf(this.streamBuffer) + (char)b[i];
/* */ }
/* */
/* 47 */ this.parentConsole.createLog(this.streamBuffer, this.entryType);
/* */
/* 49 */ this.streamBuffer = new String();
/* */ }
/* */
/* */ public void flush() {}
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/debug/ConsoleWriteStream.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,46 +0,0 @@
/* */ package org.ui.debug;
/* */
/* */ import java.awt.Color;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public enum Entry
/* */ {
/* 14 */ INFORMATION, NORMAL, ERROR, WARNING;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public static final Color getColorByEnum(Entry entryType) {
/* 32 */ switch (entryType) { case INFORMATION:
/* 33 */ return new Color(5355775);
/* 34 */ case ERROR: return new Color(16729156);
/* 35 */ case WARNING: return new Color(16772433);
default: return new Color(14935011);
}
/* */
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/debug/Entry.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,393 +0,0 @@
/* */
package org.ui.editors.code;
import org.renderer.PostProcessConfig;
import org.run.GyteCompiler;
import org.ui.UICreator;
import org.ui.debug.Console;
import org.world.World;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.util.Formatter;
public class CodeEditor extends JFrame {
private static final long serialVersionUID = -5830316930709180479L;
private volatile boolean closeRequest;
private JSplitPane consoleSplitter;
private JPanel editorPane;
private JScrollPane scrollPane;
private JLineNumberTextPane lineNumbers;
private JPanel editorBase;
private JPanel controlPanel;
private JLabel programStatus;
private GraphicsConfig configs;
private JTextPane codeEditor;
private Console console;
private JButton run;
private JButton stop;
private JButton load;
private JButton save;
private JButton settings;
private JavaSyntaxHighlighter highligher;
private GyteCompiler compiler;
public CodeEditor(World world, PostProcessConfig postProcessConfig) {
setOpacity(1.0f);
setBackground(Color.BLACK);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.configs = new GraphicsConfig(postProcessConfig);
createUIComponents();
setupUIComponents();
createUIListener(world);
this.compiler = new GyteCompiler(world, this.console, this);
setTitle("RTX-GYTEBOT - Logic Editor");
getContentPane().add(this.consoleSplitter);
setSize(screenSize.width / 2, screenSize.height);
setLocation(screenSize.width / 2, 0);
setVisible(true);
this.consoleSplitter.setDividerLocation(0.7D);
}
private void createUIComponents() {
/* 120 */
this.codeEditor = new JTextPane();
/* 121 */
this.lineNumbers = new JLineNumberTextPane(this.codeEditor);
/* 122 */
this.highligher = new JavaSyntaxHighlighter(this.codeEditor, 16);
/* 123 */
this.console = new Console();
this.controlPanel = new JPanel(new FlowLayout(0, 6, 4));
/* 127 */
this.editorBase = new JPanel(new BorderLayout());
/* 128 */
this.consoleSplitter = new JSplitPane(0);
/* 129 */
this.editorPane = new JPanel(new BorderLayout());
this.run = UICreator.createIconifiedButton('e');
/* 133 */
this.run.setToolTipText("Compile and run the program.");
/* 134 */
this.stop = UICreator.createIconifiedButton('d');
/* 135 */
this.stop.setToolTipText("Kill the current running program");
/* 136 */
this.load = UICreator.createIconifiedButton('a');
/* 137 */
this.load.setToolTipText("Import an external file of code");
this.save = UICreator.createIconifiedButton('b');
this.save.setToolTipText("Save the current code to disk");
this.settings = UICreator.createIconifiedButton('i');
this.settings.setToolTipText("Open settings");
this.programStatus = new JLabel();
}
private void setupUIComponents() {
/* 152 */
this.editorBase.add(this.codeEditor, "Center");
/* 153 */
this.editorBase.add(this.lineNumbers, "West");
this.codeEditor.setText(getDefaultCode());
this.codeEditor.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 16));
this.highligher.updateSource();
this.lineNumbers.updateLineNumbers();
this.programStatus.setOpaque(true);
/* 167 */
this.programStatus.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(1, 1, 1, 1, Color.GRAY),
BorderFactory.createEmptyBorder(4, 8, 4, 16)));
this.programStatus.setText("Off");
this.consoleSplitter.setTopComponent(this.editorPane);
this.consoleSplitter.setBottomComponent((Component) this.console);
this.scrollPane = new JScrollPane(this.editorBase);
this.scrollPane.getVerticalScrollBar().setUnitIncrement(16);
this.editorPane.add(this.controlPanel, "North");
/* 183 */
this.editorPane.add(this.scrollPane, "Center");
this.controlPanel.add(Box.createHorizontalStrut(12));
/* 187 */
this.controlPanel.add(this.settings);
/* 188 */
this.controlPanel.add(Box.createHorizontalStrut(8));
/* 189 */
this.controlPanel.add(this.load);
/* 190 */
this.controlPanel.add(this.save);
/* 191 */
this.controlPanel.add(Box.createHorizontalStrut(8));
/* 192 */
this.controlPanel.add(this.run);
/* 193 */
this.controlPanel.add(this.stop);
/* 194 */
this.controlPanel.add(Box.createHorizontalStrut(8));
/* 195 */
this.controlPanel.add(this.programStatus);
}
private void createUIListener(World world) {
this.settings.addActionListener(e -> this.configs.open());
addWindowListener(new WindowAdapter()
/* */ {
/* */
/* */
public void windowClosing(WindowEvent event)
/* */ {
CodeEditor.this.closeRequest = true;
}
/* */
});
this.save.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(1);
int value = chooser.showDialog(null, "Choose File to Save to");
if (value == 0) {
saveCodeToFile(chooser.getSelectedFile());
}
});
this.load.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(0);
int value = chooser.showDialog(null, "Choose File to Load");
if (value == 0) {
try {
BufferedReader reader = new BufferedReader(new FileReader(chooser.getSelectedFile()));
this.codeEditor.setText(reader.lines().reduce("", (a, b) -> a + b));
this.highligher.updateSource();
this.lineNumbers.updateLineNumbers();
reader.close();
} catch (Exception e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "Unable to find/open/read selected file", "Error - loading file", 0);
}
}
});
/* */
/* 267 */
this.codeEditor.addKeyListener(new KeyAdapter()
/* */ {
/* */
/* */
/* */
public void keyReleased(KeyEvent event)
/* */ {
final int scrollValue = CodeEditor.this.scrollPane.getVerticalScrollBar().getValue();
CodeEditor.this.highligher.updateSource();
CodeEditor.this.lineNumbers.updateLineNumbers();
SwingUtilities.invokeLater(new Runnable()
/* */ {
/* */
public void run()
/* */ {
scrollPane.getVerticalScrollBar().setValue(scrollValue);
/* */
}
/* */
});
/* */
}
/* */
});
/* */
/* */
/* 290 */
this.stop.addActionListener(e -> {
/* */
if (this.compiler.getProcessor() != null) {
/* */
this.compiler.getProcessor().halt();
/* */
}
/* */
});
/* */
/* */
/* */
/* 298 */
this.run.addActionListener(e -> {
if (world.getGytebot() != null) {
SwingUtilities.invokeLater(() -> this.compiler.compileAndRunProgram(this.codeEditor.getText()));
} else {
JOptionPane.showMessageDialog(null, "No GYTEBOT is associated with the current code", "Exception - Headless processor", 0);
}
/* */
});
/* */
}
private void saveCodeToFile(File saveFile) {
/* */
try {
/* 319 */
Formatter formatter = new Formatter(saveFile);
/* */
/* 321 */
formatter.format("%s", new Object[]{this.codeEditor.getText()});
/* */
/* 323 */
formatter.close();
/* 324 */
} catch (FileNotFoundException e) {
/* */
/* 326 */
JOptionPane.showMessageDialog(null, "Could not save code to file: " + saveFile.toURI(), "Error - saving code", 0);
/* 327 */
e.printStackTrace();
/* */
}
/* */
}
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
public final void markLine(int lineNumber) {
/* */
try {
/* 339 */
String text = this.codeEditor.getStyledDocument().getText(0, this.codeEditor.getStyledDocument().getLength());
/* */
/* 341 */
int lineCounter = lineNumber - 1;
/* */
/* */
/* 344 */
int start = 0;
/* 345 */
int end = 0;
/* */
/* */
/* 348 */
for (int i = 0; i < text.length(); i++) {
/* 349 */
if (text.charAt(i) == '\n') {
/* */
/* */
/* 352 */
lineCounter--;
/* */
/* */
/* 355 */
if (lineCounter == 0) {
/* */
/* 357 */
start = i;
/* */
/* */
/* 360 */
for (int k = i + 1; k < text.length(); k++) {
/* 361 */
if (text.charAt(k) == '\n') {
/* */
/* 363 */
end = k;
/* */
/* */
break;
/* */
}
/* */
}
/* */
/* */
break;
/* */
}
/* */
}
/* */
}
/* */
/* 374 */
StyleContext sc = StyleContext.getDefaultStyleContext();
/* */
/* */
/* 377 */
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Background, new Color(16537688));
/* */
/* 379 */
this.codeEditor.getStyledDocument().setCharacterAttributes(start, end - start, aset, false);
/* 380 */
} catch (BadLocationException e) {
/* 381 */
e.printStackTrace();
/* */
}
/* */
}
public void setProgramStatus(boolean isRunning) {
/* 391 */
this.programStatus.setText(isRunning ? "Running..." : "Off");
/* 392 */
this.programStatus.setBackground(isRunning ? Color.GREEN : Color.LIGHT_GRAY);
/* */
}
private String getDefaultCode() {
/* */
try {
/* 403 */
return new String(getClass().getResourceAsStream("/data/defaultCode.java.example").readAllBytes());
/* 404 */
} catch (IOException e) {
/* 405 */
JOptionPane.showMessageDialog(null, "Unable to read or open default code template", "Error - loading default code template", 0);
/* */
/* 407 */
return null;
/* */
}
/* */
}
public boolean getWindowCloseRequest() {
/* 417 */
return this.closeRequest;
/* */
}
/* */
}

View File

@ -1,84 +0,0 @@
/* */
package org.ui.editors.code;
/* */
/* */
import org.renderer.PostProcessConfig;
import javax.swing.*;
import java.awt.*;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class GraphicsConfig
/* */ {
/* */ private Box base;
private JLabel title;
private JCheckBox dof;
private JCheckBox fxaa;
private JCheckBox grain;
private PostProcessConfig postProcessConfig;
public GraphicsConfig(PostProcessConfig postProcessConfig) {
this.postProcessConfig = postProcessConfig;
}
public final void open() {
this.base = Box.createVerticalBox();
this.title = new JLabel("Settings");
this.title.setFont(new Font("Dialog", 0, 24));
this.title.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
this.fxaa = new JCheckBox("Toggle Fast approXimate Anti Aliasing");
this.fxaa.setSelected(this.postProcessConfig.isFilterFXAA());
this.fxaa.addActionListener(e -> this.postProcessConfig.setFilterFXAA(this.fxaa.isSelected()));
this.dof = new JCheckBox("Toggle Depth of Field");
this.dof.setSelected(this.postProcessConfig.isFilterDoF());
this.dof.addActionListener(e -> this.postProcessConfig.setFilterDoF(this.dof.isSelected()));
this.grain = new JCheckBox("Toggle Film Grain");
this.grain.setSelected(this.postProcessConfig.isFilterGrain());
this.grain.addActionListener(e -> this.postProcessConfig.setFilterGrain(this.grain.isSelected()));
this.base.add(this.title);
this.base.add(this.fxaa);
this.base.add(this.grain);
this.base.add(this.dof);
JOptionPane.showConfirmDialog(null, this.base, "RTX-GYTEBOT - Settings", 0);
}
}

View File

@ -1,37 +0,0 @@
package org.ui.editors.code;
import javax.swing.*;
import javax.swing.text.Element;
import java.awt.*;
public class JLineNumberTextPane extends JTextArea {
private static final long serialVersionUID = -2596467098026617439L;
private JTextPane textPane;
public JLineNumberTextPane(JTextPane textPane) {
this.textPane = textPane;
setFont(new Font("Consolas", 0, 16));
setEditable(false);
setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, getBackground().darker()), BorderFactory.createEmptyBorder(0, 12, 0, 16)));
}
public final void updateLineNumbers() {
setText(getLineNumbersText());
}
private String getLineNumbersText() {
Integer caretPosition = Integer.valueOf(this.textPane.getDocument().getLength());
Element root = this.textPane.getDocument().getDefaultRootElement();
StringBuilder textBuilder = new StringBuilder();
textBuilder.append("1").append(System.lineSeparator());
for (int elementIndex = 2; elementIndex < root.getElementIndex(caretPosition.intValue()) + 2; elementIndex++) {
textBuilder.append(elementIndex).append(System.lineSeparator());
}
return textBuilder.toString();
}
}

View File

@ -1,238 +0,0 @@
/* */ package org.ui.editors.map;
/* */
/* */ import java.awt.*;
/* */
/* */
/* */
/* */ import java.awt.event.ActionEvent;
/* */ import java.awt.event.KeyAdapter;
/* */ import java.awt.event.KeyEvent;
/* */ import java.awt.event.WindowAdapter;
/* */ import java.awt.event.WindowEvent;
/* */ import java.io.FileNotFoundException;
/* */ import java.util.Formatter;
/* */ import javax.swing.Box;
/* */ import javax.swing.JButton;
/* */ import javax.swing.JFileChooser;
/* */ import javax.swing.JFrame;
/* */ import javax.swing.JLabel;
/* */ import javax.swing.JOptionPane;
/* */ import javax.swing.JPanel;
/* */ import javax.swing.JScrollPane;
/* */ import javax.swing.JTextPane;
/* */ import org.ui.UICreator;
/* */ import org.world.World;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class MapEditor
/* */ extends JFrame
/* */ {
/* */ private static final long serialVersionUID = -6076124740248473039L;
/* */ private volatile boolean closeRequest;
/* */ private JPanel buttonPane;
/* */ private JButton updateWorld;
/* */ private JButton reset;
/* */ private JButton load;
/* */ private JButton save;
/* */ private JButton info;
/* */ private JLabel infoLabel;
/* */ private JTextPane preview;
/* */ private MapTextHighlighter highlighter;
/* */
/* */ public MapEditor(World world) {
setOpacity(1.0f);
setBackground(Color.BLACK);
/* 64 */ createUIComponents();
/* */
/* 66 */ setupUIComponents(world);
/* */
/* 68 */ createListener(world);
/* */
/* */
/* */
/* 72 */ this.buttonPane.add(Box.createHorizontalStrut(12));
/* 73 */ this.buttonPane.add(this.updateWorld);
/* 74 */ this.buttonPane.add(this.reset);
/* 75 */ this.buttonPane.add(Box.createHorizontalStrut(6));
/* 76 */ this.buttonPane.add(this.load);
/* 77 */ this.buttonPane.add(this.save);
/* 78 */ this.buttonPane.add(Box.createHorizontalStrut(6));
/* 79 */ this.buttonPane.add(this.infoLabel);
/* 80 */ this.buttonPane.add(this.info);
/* */
/* */
/* */
/* */
/* 85 */ Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
/* */
/* */
/* */
/* */
/* */
/* 91 */ getContentPane().setLayout(new BorderLayout());
/* 92 */ getContentPane().add(new JScrollPane(this.preview), "Center");
/* 93 */ getContentPane().add(this.buttonPane, "South");
/* */
/* */
/* 96 */ setTitle("RTX-GYTEBOT - Map Editor");
/* */
/* 98 */ setSize(size.width >> 1, size.height >> 1);
/* */
/* 100 */ setLocation(0, size.height >> 1);
/* */
/* 102 */ setVisible(true);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void createListener(World world) {
/* 112 */ this.preview.addKeyListener(new KeyAdapter()
/* */ {
/* */ public final void keyReleased(KeyEvent event)
/* */ {
/* 116 */ MapEditor.this.highlighter.highlight();
/* */ }
/* */ });
/* */
/* */
/* 121 */ this.reset.addActionListener(e -> {
/* */ this.preview.setText(world.toString());
/* */
/* */
/* */ this.highlighter.highlight();
/* */ });
/* */
/* 128 */ this.updateWorld.addActionListener(e -> world.setDataString(this.preview.getText()));
/* */
/* */
/* 131 */ this.load.addActionListener(e -> {
/* */ JFileChooser chooser = new JFileChooser();
/* */
/* */
/* */ chooser.setDialogType(0);
/* */
/* */
/* */ int value = chooser.showDialog(null, "Choose File");
/* */
/* */ if (value == 0) {
/* */ world.setWorld(chooser.getSelectedFile().getAbsolutePath());
/* */ }
/* */
/* */ this.preview.setText(world.toString());
/* */
/* */ this.infoLabel.setText(String.format("Size: %d %d Coins: %d", new Object[] { Integer.valueOf(world.getWidth()), Integer.valueOf(world.getHeight()), Integer.valueOf(world.getCoinCount()) }));
/* */
/* */ this.highlighter.highlight();
/* */ });
/* */
/* 151 */ this.info.addActionListener(e -> {
/* */
/* */ });
/* 154 */ this.save.addActionListener(e -> {
/* */ JFileChooser chooser = new JFileChooser();
/* */
/* */
/* */ chooser.setDialogType(1);
/* */
/* */
/* */ int value = chooser.showDialog(null, "Choose File to save to");
/* */
/* */
/* */ if (value == 0) {
/* */ try {
/* */ Formatter formatter = new Formatter(chooser.getSelectedFile());
/* */
/* */
/* */ formatter.format("%s", new Object[] { world.toString() });
/* */
/* */
/* */ formatter.close();
/* 173 */ } catch (FileNotFoundException e1) {
/* */ String errorMessage = String.format("Could not save current map to file: %s", new Object[] { chooser.getSelectedFile().toURI() });
/* */
/* */ JOptionPane.showMessageDialog(null, errorMessage, "Error - saving map", 0);
/* */
/* */ e1.printStackTrace();
/* */ }
/* */ }
/* */ });
/* */
/* 183 */ addWindowListener(new WindowAdapter()
/* */ {
/* */ public void windowClosing(WindowEvent event)
/* */ {
/* 187 */ MapEditor.this.closeRequest = true;
/* */ }
/* */ });
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void setupUIComponents(World world) {
/* 198 */ this.preview.setText(world.toString());
/* */
/* 200 */ this.highlighter.highlight();
/* */ }
/* */
/* */
/* */
/* */
/* */ private void createUIComponents() {
/* 207 */ this.preview = new JTextPane();
/* 208 */ this.highlighter = new MapTextHighlighter(this.preview);
/* */
/* */
/* 211 */ this.buttonPane = new JPanel(new FlowLayout(0, 4, 2));
/* */
/* */
/* 214 */ this.updateWorld = UICreator.createIconifiedButton('g');
/* 215 */ this.reset = UICreator.createIconifiedButton('f');
/* 216 */ this.load = UICreator.createIconifiedButton('a');
/* 217 */ this.save = UICreator.createIconifiedButton('b');
/* 218 */ this.info = UICreator.createIconifiedButton('h');
/* */
/* 220 */ this.infoLabel = new JLabel();
/* */ }
/* */
/* */
/* */
/* */
/* */ public boolean getWindowCloseRequest() {
/* 227 */ return this.closeRequest;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/editors/map/MapEditor.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,94 +0,0 @@
/* */ package org.ui.editors.map;
/* */
/* */ import java.awt.Font;
/* */ import javax.swing.Box;
/* */ import javax.swing.JLabel;
/* */ import javax.swing.JOptionPane;
/* */ import org.world.World;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class MapInformation
/* */ {
/* */ private Box content;
/* */ private JLabel title;
/* */ private JLabel nameLabel;
/* */ private JLabel authorLabel;
/* */ private JLabel dateLabel;
/* */ private JLabel versionLabel;
/* */ private JLabel sizeLabel;
/* */ private JLabel coinsLabel;
/* */
/* */ public MapInformation(World world) {
/* 38 */ this.content = Box.createVerticalBox();
/* 39 */ this.content.setAlignmentX(0.0F);
/* */
/* */
/* 42 */ this.title = new JLabel("Map information");
/* 43 */ this.title.setFont(new Font("Verdana", 0, 12));
/* 44 */ this.title.setAlignmentX(0.0F);
/* */
/* */
/* */
/* */
/* 49 */ this.nameLabel = new JLabel("Map: " + world.getName());
/* */
/* 51 */ this.authorLabel = new JLabel("Author: " + world.getAuthor());
/* */
/* 53 */ this.dateLabel = new JLabel("Date: " + world.getDate());
/* */
/* 55 */ this.versionLabel = new JLabel("Version: " + world.getVersion());
/* */
/* 57 */ this.sizeLabel = new JLabel("Size: " + world.getWidth() + "x" + world.getHeight());
/* */
/* 59 */ this.coinsLabel = new JLabel("Coins(total) : " + world.getCoinCount());
/* */
/* */
/* */
/* 63 */ this.nameLabel.setAlignmentX(0.0F);
/* 64 */ this.authorLabel.setAlignmentX(0.0F);
/* 65 */ this.dateLabel.setAlignmentX(0.0F);
/* 66 */ this.versionLabel.setAlignmentX(0.0F);
/* */
/* */
/* */
/* 70 */ this.content.add(Box.createVerticalStrut(12));
/* 71 */ this.content.add(this.title);
/* 72 */ this.content.add(Box.createVerticalStrut(6));
/* 73 */ this.content.add(this.nameLabel);
/* 74 */ this.content.add(Box.createVerticalStrut(4));
/* 75 */ this.content.add(this.sizeLabel);
/* 76 */ this.content.add(Box.createVerticalStrut(6));
/* 77 */ this.content.add(this.coinsLabel);
/* 78 */ this.content.add(Box.createVerticalStrut(6));
/* 79 */ this.content.add(this.authorLabel);
/* 80 */ this.content.add(Box.createVerticalStrut(4));
/* 81 */ this.content.add(this.dateLabel);
/* 82 */ this.content.add(Box.createVerticalStrut(4));
/* 83 */ this.content.add(this.versionLabel);
/* */
/* */
/* 86 */ JOptionPane.showInternalConfirmDialog(null, this.content, "RTX-GYTEBOT - map information", 0);
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/editors/map/MapInformation.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,50 +0,0 @@
/* */ package org.ui.editors.map;
/* */
/* */ import java.awt.Color;
/* */ import javax.swing.JTextPane;
/* */ import org.ui.syntaxes.CharAttrib;
/* */ import org.ui.syntaxes.SyntaxHighlighter;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class MapTextHighlighter
/* */ extends SyntaxHighlighter
/* */ {
/* */ private static final String WALL_REGEX = "[#]";
/* */ private static final String BOT_REGEX = "[<^>vV]";
/* */ private static final String COIN_REGEX = "[€$]";
/* */ private static final String TAG_REGEX = "\\b|@date|@author|@version|@name\\b";
/* */ private static final String DATA_REGEX = "@[^\\n]*";
/* */ private static final String COMMENT_REGEX = "//[^\\n]*";
/* */
/* */ public MapTextHighlighter(JTextPane textPane) {
/* 28 */ super(textPane, 1.0F, 24);
/* */
/* */
/* */
/* 32 */ createHighlightPattern("[#]", new CharAttrib(false, false, Color.DARK_GRAY));
/* */
/* 34 */ createHighlightPattern("[<^>vV]", new CharAttrib(false, true, Color.RED));
/* */
/* 36 */ createHighlightPattern("[€$]", new CharAttrib(true, false, Color.ORANGE));
/* */
/* 38 */ createHighlightPattern("\\b|@date|@author|@version|@name\\b", new CharAttrib(true, false, Color.GRAY));
/* */
/* 40 */ createHighlightPattern("@[^\\n]*", new CharAttrib(true, false, Color.GRAY));
/* */
/* 42 */ createHighlightPattern("//[^\\n]*", new CharAttrib(true, false, Color.LIGHT_GRAY));
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/editors/map/MapTextHighlighter.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,40 +0,0 @@
/* */
package org.ui.icons;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
public class IconLoader {
public static final char LOAD_ICON_CODE_POINT = 'a';
public static final char SAVE_ICON_CODE_POINT = 'b';
public static final char CLEAR_ICON_CODE_POINT = 'c';
public static final char STOP_ICON_CODE_POINT = 'd';
public static final char RUN_ICON_CODE_POINT = 'e';
public static final char RESET_ICON_CODE_POINT = 'f';
public static final char APPLY_ICON_CODE_POINT = 'g';
public static final char INFO_ICON_CODE_POINT = 'h';
public static final char OPTIONS_ICON_CODE_POINT = 'i';
private static final String FONT_FILE_NAME = "data/icons/RTX-GYTEBOT-ICONS.ttf";
private static final String ICON_FILE_NAME = "data/icons/gytebotIcon.png";
public static final void loadIcons() throws AssertionError {
try {
Font iconFont = Font.createFont(0, (IconLoader.class.getClassLoader().getResourceAsStream(FONT_FILE_NAME)));
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(iconFont);
} catch (FontFormatException e) {
throw new AssertionError("Unable to register icon font");
} catch (Exception e) {
throw new AssertionError("Unable to find or load icon font file:" + FONT_FILE_NAME);
}
}
public static final BufferedImage loadWindowIcon() throws AssertionError {
try {
return ImageIO.read(IconLoader.class.getClassLoader().getResourceAsStream(ICON_FILE_NAME));
} catch (Exception e) {
throw new AssertionError("Unable to find or load image file:" + ICON_FILE_NAME);
}
}
}

View File

@ -1,98 +0,0 @@
/* */ package org.ui.syntaxes;
/* */
/* */ import java.awt.Color;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class CharAttrib
/* */ {
/* */ private boolean bold;
/* */ private boolean italic;
/* */ private Color color;
/* */ private Color backgroundColor;
/* */
/* */ public CharAttrib(boolean bold, boolean italic, Color color) {
/* 31 */ this.bold = bold;
/* 32 */ this.italic = italic;
/* 33 */ this.color = color;
/* 34 */ this.backgroundColor = Color.WHITE;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final boolean isBold() {
/* 41 */ return this.bold;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final void setBold(boolean bold) {
/* 48 */ this.bold = bold;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final boolean isItalic() {
/* 55 */ return this.italic;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final void setItalic(boolean italic) {
/* 62 */ this.italic = italic;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final Color getColor() {
/* 69 */ return this.color;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final void setColor(Color color) {
/* 76 */ this.color = color;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final Color getBackgroundColor() {
/* 83 */ return this.backgroundColor;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final void setBackgroundColor(Color backgroundColor) {
/* 90 */ this.backgroundColor = backgroundColor;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/syntaxes/CharAttrib.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,52 +0,0 @@
/* */ package org.ui.syntaxes;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Pair<A, B>
/* */ {
/* */ private A a;
/* */ private B b;
/* */
/* */ public Pair(A a, B b) {
/* 29 */ this.a = a;
/* 30 */ this.b = b;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final A getA() {
/* 37 */ return this.a;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final B getB() {
/* 44 */ return this.b;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/syntaxes/Pair.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,104 +0,0 @@
package org.ui.syntaxes;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SyntaxHighlighter {
private final CharAttrib defaultCharAttribs;
protected JTextPane textPane;
protected TabSet tabset;
private final List<Pair<String, CharAttrib>> elements;
private int selectionStart;
private int selectionLength;
private final int fontSize;
public SyntaxHighlighter(JTextPane textPane, float tabSize, int fontSize) {
this.textPane = textPane;
this.fontSize = fontSize;
this.elements = new ArrayList<>();
this.defaultCharAttribs = new CharAttrib(false, false, textPane.getForeground());
createTabset(tabSize);
}
public SyntaxHighlighter(JTextPane textPane, float tabSize, int fontSize, Color backgroundColor) {
this.textPane = textPane;
this.fontSize = fontSize;
this.elements = new ArrayList<>();
this.defaultCharAttribs = new CharAttrib(false, false, textPane.getForeground());
this.defaultCharAttribs.setBackgroundColor(backgroundColor);
createTabset(tabSize);
}
protected void createHighlightPattern(String regex, CharAttrib attribs) {
this.elements.add(new Pair<>(regex, attribs));
}
private void createTabset(float tabSize) {
TabStop[] tabs = new TabStop[8];
for (int i = 0; i < tabs.length; i++) {
tabs[i] = new TabStop(tabSize * i + tabSize, 0, 0);
}
this.tabset = new TabSet(tabs);
}
public final void highlight() {
this.selectionStart = 0;
this.selectionLength = this.textPane.getDocument().getLength();
createHighlight(this.defaultCharAttribs);
try {
for (Pair<String, CharAttrib> entry : this.elements) {
Matcher matcher = Pattern.compile(entry.getA(), Pattern.MULTILINE | Pattern.DOTALL).matcher(
this.textPane.getDocument().getText(0, this.textPane.getDocument().getLength()));
while (matcher.find()) {
this.selectionStart = matcher.start();
this.selectionLength = matcher.end() - this.selectionStart;
createHighlight(entry.getB());
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
private void createHighlight(CharAttrib attribs) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Background, this.defaultCharAttribs.getBackgroundColor());
aset = sc.addAttribute(aset, StyleConstants.FontFamily, new Font("Monospaced", Font.PLAIN, 16).getFamily());
aset = sc.addAttribute(aset, StyleConstants.FontSize, this.fontSize);
aset = sc.addAttribute(aset, StyleConstants.Bold, attribs.isBold());
aset = sc.addAttribute(aset, StyleConstants.Italic, attribs.isItalic());
aset = sc.addAttribute(aset, StyleConstants.TabSet, this.tabset);
if (attribs.getColor() == null) {
Color foregroundColor = (Color) this.textPane.getStyledDocument()
.getCharacterElement(this.selectionStart).getAttributes()
.getAttribute(StyleConstants.Foreground);
aset = sc.addAttribute(aset, StyleConstants.Foreground, foregroundColor.darker());
} else {
aset = sc.addAttribute(aset, StyleConstants.Foreground, attribs.getColor());
}
this.textPane.getStyledDocument().setCharacterAttributes(this.selectionStart, this.selectionLength, aset, false);
}
}

View File

@ -1,159 +0,0 @@
/* */ package org.view;
/* */
/* */ import org.lwjgl.glfw.GLFW;
/* */ import org.lwjgl.glfw.GLFWCursorPosCallback;
/* */ import org.lwjgl.glfw.GLFWCursorPosCallbackI;
/* */ import org.lwjgl.glfw.GLFWMouseButtonCallback;
/* */ import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
/* */ import org.lwjgl.glfw.GLFWScrollCallback;
/* */ import org.lwjgl.glfw.GLFWScrollCallbackI;
/* */ import org.lwjgl.glfw.GLFWVidMode;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Camera
/* */ implements AutoCloseable
/* */ {
/* */ private static final float MIN_CAMERA_ZOOM = -8.0F;
/* */ private static final float MAX_CAMERA_ZOOM = -0.5F;
/* */ private static final float MAX_CAMERA_ROT_Y = -1.5707964F;
/* */ private static final float MIN_CAMERA_ROT_Y = -3.1415927F;
/* */ private GLFWCursorPosCallback cursorPosCallback;
/* */ private GLFWMouseButtonCallback mouseButtonCallback;
/* */ private GLFWScrollCallback scrollCallback;
/* */ private boolean isMouseButton1Down;
/* 37 */ private float cameraZoom = -0.5F;
/* */
/* 39 */ private float cameraRotationX = 1.3F;
/* 40 */ private float cameraRotationY = -2.3F;
/* */
/* */
/* */ private float deltaRotationX;
/* */
/* */
/* */ private float deltaRotationY;
/* */
/* */
/* */ private float cameraRotationVelocityX;
/* */
/* */ private float cameraRotationVelocityY;
/* */
/* */ private float cameraZoomVelocity;
/* */
/* */
/* */ public Camera(long windowHandle) {
/* 57 */ GLFW.glfwSetMouseButtonCallback(windowHandle, (GLFWMouseButtonCallbackI)(this.mouseButtonCallback = new GLFWMouseButtonCallback()
/* */ {
/* */
/* */ public void invoke(long arg0, int arg1, int arg2, int arg3)
/* */ {
/* 62 */ Camera.this.isMouseButton1Down = ((arg1 == 0)) ^ ((arg2 == 0));
/* */ }
/* */ }));
/* */
/* */
/* 67 */ GLFW.glfwSetScrollCallback(windowHandle, (GLFWScrollCallbackI)(this.scrollCallback = new GLFWScrollCallback()
/* */ {
/* */ public void invoke(long window, double dx, double dy)
/* */ {
/* 71 */ Camera.this.cameraZoomVelocity = (float)(Camera.this.cameraZoomVelocity + dy * 0.019999999552965164D);
/* */ }
/* */ }));
/* */
/* */
/* 76 */ GLFW.glfwSetCursorPosCallback(windowHandle, (GLFWCursorPosCallbackI)(this.cursorPosCallback = new GLFWCursorPosCallback()
/* */ {
/* */
/* */ public void invoke(long window, double cursorX, double cursorY)
/* */ {
/* 81 */ GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
/* */
/* 83 */ float rotationDifferenceX = (float)(cursorX / vidmode.width());
/* 84 */ float rotationDifferenceY = (float)(cursorY / vidmode.height());
/* */
/* */
/* 87 */ if (Camera.this.isMouseButton1Down) {
/* */
/* */
/* 90 */ Camera.this.cameraRotationVelocityX = (Camera.this.deltaRotationX - rotationDifferenceX) * 2.0F;
/* */
/* 92 */ Camera.this.cameraRotationVelocityY = (Camera.this.deltaRotationY - rotationDifferenceY) * 1.8F;
/* */ }
/* */
/* 95 */ Camera.this.deltaRotationX = rotationDifferenceX;
/* 96 */ Camera.this.deltaRotationY = rotationDifferenceY;
/* */ }
/* */ }));
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void update(float elapsedTime) {
/* 108 */ float timeStep = elapsedTime * 100.0F;
/* */
/* */
/* */
/* */
/* 113 */ this.cameraRotationY = Math.min(Math.max(this.cameraRotationY + this.cameraRotationVelocityY * timeStep, -3.1415927F), -1.5707964F);
/* 114 */ this.cameraRotationX += this.cameraRotationVelocityX * timeStep;
/* */
/* */
/* 117 */ this.cameraRotationVelocityX += -this.cameraRotationVelocityX * 0.08F * timeStep;
/* 118 */ this.cameraRotationVelocityY += -this.cameraRotationVelocityY * 0.05F * timeStep;
/* */
/* */
/* 121 */ this.cameraZoom = Math.max(Math.min(this.cameraZoom + this.cameraZoomVelocity, -0.5F), -8.0F);
/* */
/* 123 */ this.cameraZoomVelocity += -this.cameraZoomVelocity * 0.04F * timeStep * Math.abs(2.0F / this.cameraZoom);
/* */ }
/* */
/* */
/* */ public final void close() {
/* 128 */ this.cursorPosCallback.free();
/* 129 */ this.mouseButtonCallback.free();
/* 130 */ this.scrollCallback.free();
/* */ }
/* */
/* */
/* */
/* */
/* */ public final float getCameraZoom() {
/* 137 */ return this.cameraZoom;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final float getCameraRotationX() {
/* 144 */ return this.cameraRotationX;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final float getCameraRotationY() {
/* 151 */ return this.cameraRotationY;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/view/Camera.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -1,603 +0,0 @@
/* */ package org.world;
/* */
/* */ import java.awt.Point;
/* */ import java.awt.geom.Point2D;
/* */ import java.io.BufferedReader;
/* */ import java.io.File;
/* */ import java.io.FileReader;
/* */ import java.io.IOException;
/* */ import java.io.InputStreamReader;
/* */ import java.util.Arrays;
/* */ import java.util.LinkedList;
/* */ import java.util.List;
/* */ import javax.swing.JOptionPane;
/* */ import org.bot.Direction;
/* */ import org.bot.Gytebot;
/* */ import org.objects.Coin;
/* */ import org.objects.Wall;
/* */ import org.objects.WorldObject;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class World
/* */ {
/* */ public static final int MAP_SIZE = 32;
/* */ private List<String> rawMapData;
/* */ private int rawDataWidth;
/* */ private int coinCount;
/* */ private String author;
/* */ private String version;
/* */ private String name;
/* */ private String date;
/* */ private String mapPath;
/* */ private volatile WorldObject[][] objects;
/* */ private volatile Gytebot gytebot;
/* */ private boolean updateCoinBuffer;
/* */ private int[] coinBufferData;
/* */ private boolean updateWallBufferData;
/* */ private float[] wallBufferData;
/* */
/* */ public World() {
/* 71 */ this.rawMapData = new LinkedList<>();
/* */
/* 73 */ this.coinBufferData = new int[1024];
/* 74 */ this.wallBufferData = new float[1024];
/* */
/* */
/* 77 */ setWorld("/data/standardlevel.map");
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void setWorld(String fileName) {
/* 88 */ BufferedReader reader = null;
/* */
/* */
/* */
/* */ try {
/* 93 */ reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(fileName)));
/* 94 */ } catch (Exception e1) {
/* */
/* */ try {
/* 97 */ reader = new BufferedReader(new FileReader(new File(fileName)));
/* 98 */ } catch (Exception e2) {
/* */
/* 100 */ JOptionPane.showMessageDialog(null, "Unable to open Map: " + fileName, "Error - opening map", 0);
/* */ }
/* */ }
/* */
/* 104 */ if (reader != null) {
/* */
/* */ try {
/* */
/* */
/* */
/* 110 */ this.gytebot = null;
/* 111 */ this.rawDataWidth = 0;
/* 112 */ this.rawMapData.clear();
/* */
/* */
/* */ try {
/* 116 */ reader.lines().forEachOrdered(line -> parseLine(line));
/* */
/* */
/* 119 */ if (this.rawDataWidth > 0 && this.rawMapData.size() > 0) {
/* */
/* */
/* */
/* 123 */ this.objects = new WorldObject[this.rawDataWidth][this.rawMapData.size()];
/* */
/* 125 */ createWorldData();
/* */
/* 127 */ updateTransferBuffers();
/* */
/* 129 */ this.mapPath = fileName;
/* */
/* */ }
/* */ else {
/* */
/* 134 */ setWorld(this.mapPath);
/* */
/* 136 */ JOptionPane.showMessageDialog(null, "Unable to open Map: " + fileName, "Error - opening map", 0);
/* */ }
/* 138 */ } catch (Error e) {
/* */
/* 140 */ setWorld(this.mapPath);
/* */
/* 142 */ JOptionPane.showMessageDialog(null, "Unable to open Map: " + fileName, "Error - opening map", 0);
/* */ } finally {
/* */
/* 145 */ reader.close();
/* */ }
/* 147 */ } catch (IOException e) {
/* 148 */ e.printStackTrace();
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void setDataString(String data) {
/* 161 */ this.gytebot = null;
/* 162 */ this.rawDataWidth = 0;
/* 163 */ this.rawMapData.clear();
/* */
/* */
/* */ try {
/* 167 */ Arrays.<String>asList(data.split("(?=\\n)")).forEach(line -> parseLine(line));
/* */
/* */
/* 170 */ if (this.rawDataWidth > 0 && this.rawMapData.size() > 0) {
/* */
/* */
/* 173 */ this.objects = new WorldObject[this.rawDataWidth][this.rawMapData.size()];
/* */
/* 175 */ createWorldData();
/* */
/* 177 */ updateTransferBuffers();
/* */
/* */ }
/* */ else {
/* */
/* */
/* 183 */ setWorld(this.mapPath);
/* 184 */ JOptionPane.showMessageDialog(null, "The map was not properly loaded", "Error - converting map", 0);
/* */ }
/* 186 */ } catch (Error e) {
/* */
/* 188 */ setWorld(this.mapPath);
/* 189 */ JOptionPane.showMessageDialog(null, "Unable to convert Map: " + e.getMessage(), "Error - converting map", 0);
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void parseLine(String line) throws Error {
/* 201 */ String trimed = line.trim();
/* */
/* */
/* 204 */ if (trimed.length() != 0) {
/* */
/* */
/* 207 */ String[] splitted = trimed.split("[/](?=/)|(?=[@])");
/* */
/* 209 */ String rawMapLine = new String(); byte b;
/* */ int i;
/* */ String[] arrayOfString1;
/* 212 */ for (i = (arrayOfString1 = splitted).length, b = 0; b < i; ) { String content = arrayOfString1[b];
/* */
/* 214 */ if (content.startsWith("/")) {
/* */ break;
/* */ }
/* */
/* */
/* 219 */ if (content.startsWith("@")) {
/* */
/* */
/* 222 */ String[] tag = content.split("\\s+");
/* */
/* */
/* 225 */ if (tag.length > 2)
/* */ {
/* */
/* 228 */ throw new AssertionError("To many arguments provided for tag: " + content);
/* */ }
/* */
/* */
/* */ String str;
/* */
/* 234 */ switch ((str = tag[0]).hashCode()) { case -440667701: if (str.equals("@author")) {
/* 235 */ this.author = tag[1]; break;
/* */ }
/* */ case 62181358:
/* 238 */ if (str.equals("@date")) { this.date = tag[1]; break; } case 62479051: if (str.equals("@name")) { this.name = tag[1]; break; } case 222319768: if (str.equals("@version")) { this.version = tag[1]; break; }
/* 239 */ default: throw new AssertionError("Unknown tag found: " + tag[0]); }
/* */
/* */
/* */
/* */ } else {
/* 244 */ rawMapLine = String.valueOf(rawMapLine) + content;
/* */ } b++; }
/* */
/* 247 */ if (rawMapLine.length() > 0) {
/* 248 */ this.rawMapData.add(rawMapLine);
/* */ }
/* */
/* 251 */ this.rawDataWidth = Math.max(this.rawDataWidth, rawMapLine.length());
/* */
/* */
/* 254 */ if (this.rawDataWidth > 32)
/* */ {
/* 256 */ throw new AssertionError("Map size exceeds valid map bounds of 32x32! It is to wide");
/* */ }
/* 258 */ if (this.rawMapData.size() > 32)
/* */ {
/* 260 */ throw new AssertionError("Map size exceeds valid map bounds of 32x32! It is to large");
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void createWorldData() {
/* 272 */ this.coinCount = 0;
/* */
/* */
/* 275 */ for (int y = 0; y < this.rawMapData.size(); y++) {
/* */
/* 277 */ for (int x = 0; x < ((String)this.rawMapData.get(y)).length(); x++) {
/* */
/* 279 */ char current = ((String)this.rawMapData.get(y)).charAt(x);
/* */
/* 281 */ if (current == '#') {
/* */
/* */
/* 284 */ this.objects[x][y] = (WorldObject)new Wall(new Point2D.Float(x, y));
/* */ }
/* 286 */ else if (current == '€' || current == '$') {
/* */
/* */
/* 289 */ this.objects[x][y] = (WorldObject)new Coin(new Point2D.Float(x, y));
/* */
/* 291 */ this.coinCount++;
/* */ }
/* 293 */ else if (current == '^' || current == '>' || current == 'v' || current == 'V' || current == '<') {
/* */
/* */
/* 296 */ if (this.gytebot != null) {
/* */
/* 298 */ System.err.println("Conflicting world rule: There is already a gytebot!");
/* 299 */ JOptionPane.showMessageDialog(null, "Conflicting world rule: There is already a gytebot", "Error - converting map", 0);
/* */
/* */
/* */
/* */
/* */ }
/* 305 */ else if (x < ((String)this.rawMapData.get(0)).length() && y < this.rawMapData.size()) {
/* */
/* 307 */ this.gytebot = new Gytebot(new Point2D.Float(x, y), Direction.directionFromCodePoint(current));
/* */ } else {
/* */
/* 310 */ this.gytebot = null;
/* 311 */ JOptionPane.showMessageDialog(null, "Gytebot is placed outside Map", "Error - converting map", 0);
/* */ }
/* */
/* */ }
/* 315 */ else if (current != ' ') {
/* */
/* */
/* 318 */ System.err.println("Unkown map entity: " + current);
/* */ }
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void updateTransferBuffers() {
/* 332 */ Arrays.fill(this.coinBufferData, 0);
/* 333 */ Arrays.fill(this.wallBufferData, 0.0F);
/* */
/* */
/* 336 */ for (int y = 0; y < (this.objects[0]).length; y++) {
/* 337 */ for (int x = 0; x < this.objects.length; x++) {
/* */
/* 339 */ if (this.objects[x][y] instanceof Coin) {
/* */
/* */
/* 342 */ this.coinBufferData[x + y * this.objects.length] = 1;
/* */ }
/* 344 */ else if (this.objects[x][y] instanceof Wall) {
/* */
/* */
/* 347 */ this.wallBufferData[x + y * 32] = 1.0F;
/* */ }
/* */ }
/* */ }
/* */
/* 352 */ this.updateCoinBuffer = true;
/* 353 */ this.updateWallBufferData = true;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void setWall(int x, int y) {
/* 364 */ setObject(x, y, (WorldObject)new Wall(new Point2D.Float(x, y)));
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void setCoin(int x, int y) {
/* 375 */ setObject(x, y, (WorldObject)new Coin(new Point2D.Float(x, y)));
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final void removeObject(int x, int y) {
/* 385 */ if (this.objects[x][y] != null) {
/* */
/* */
/* 388 */ this.objects[x][y] = null;
/* */
/* 390 */ updateTransferBuffers();
/* */
/* */ }
/* */ else {
/* */
/* 395 */ JOptionPane.showMessageDialog(null, "Index to remove object from is already empty", "Exception", 0);
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void setObject(int x, int y, WorldObject object) {
/* 410 */ if (x >= 0 && x < this.objects.length && y >= 0 && y < (this.objects[0]).length) {
/* */
/* */
/* 413 */ this.objects[x][y] = object;
/* */
/* 415 */ updateTransferBuffers();
/* */ }
/* */ else {
/* */
/* 419 */ JOptionPane.showMessageDialog(null, "The requested object placement occured outside of valid bounds!", "Exception", 0);
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public boolean isLocationObstructed(Point point) {
/* 432 */ if (point.x < 0 || point.y < 0 || point.x >= getWidth() || point.y >= getHeight())
/* */ {
/* 434 */ return true;
/* */ }
/* 436 */ if (this.objects[point.x][point.y] instanceof Wall)
/* */ {
/* 438 */ return true;
/* */ }
/* */
/* */
/* */
/* 443 */ return false;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public boolean isCoinPlacedHere(Point2D.Float location) {
/* 455 */ if (location.x < 0.0F || location.y < 0.0F || location.x >= getWidth() || location.y >= getHeight())
/* */ {
/* 457 */ return false;
/* */ }
/* 459 */ if (this.objects[Math.round(location.x)][Math.round(location.y)] instanceof Coin)
/* */ {
/* 461 */ return true;
/* */ }
/* */
/* */
/* */
/* 466 */ return false;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public final String toString() {
/* 476 */ return this.rawMapData.stream().reduce("", (A, B) -> String.valueOf(A) + B + System.lineSeparator());
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public boolean updateWallBufferData() {
/* 486 */ if (this.updateWallBufferData) {
/* */
/* 488 */ this.updateWallBufferData = false;
/* 489 */ return true;
/* */ }
/* */
/* */
/* 493 */ return false;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public boolean updateCoinTextureData() {
/* 504 */ if (this.updateCoinBuffer) {
/* */
/* 506 */ this.updateCoinBuffer = false;
/* 507 */ return true;
/* */ }
/* */
/* 510 */ return false;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public final int getCoinCount() {
/* 518 */ return this.coinCount;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final String getAuthor() {
/* 525 */ return this.author;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final String getVersion() {
/* 532 */ return this.version;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final String getName() {
/* 539 */ return this.name;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final String getDate() {
/* 546 */ return this.date;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final synchronized Gytebot getGytebot() {
/* 553 */ return this.gytebot;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final int[] getCoinBufferData() {
/* 560 */ return this.coinBufferData;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final int getWidth() {
/* 567 */ return this.objects.length;
/* */ }
/* */
/* */
/* */
/* */
/* */ public final int getHeight() {
/* 574 */ return (this.objects[0]).length;
/* */ }
/* */
/* */
/* */
/* */
/* */ public int getDrawGytebotAsInt() {
/* 581 */ return (this.gytebot == null) ? 0 : 1;
/* */ }
/* */
/* */
/* */
/* */
/* */ public int[] getCoinTextureData() {
/* 588 */ return this.coinBufferData;
/* */ }
/* */
/* */
/* */
/* */
/* */ public float[] getWallBufferData() {
/* 595 */ return this.wallBufferData;
/* */ }
/* */ }
/* Location: /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/world/World.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/

View File

@ -24,51 +24,51 @@ out vec4 fragColor;
// screen resolution in pixels // screen resolution in pixels
uniform vec2 resolution; uniform vec2 resolution;
// fbo texture sampler // fbo texture sampler
uniform sampler2D fboTexture; // RGB-components store pixel color, alpha holds linear world scene depth from the camera's origin uniform sampler2D fboTexture; // RGB-components store pixel color, alpha holds linear world scene depth from the camera's origin
uniform int boolFilterDoF; // enabled Depth of Field uniform int boolFilterDoF; // enabled Depth of Field
uniform int boolFilterFXAA; // enabled Fast Approximate Anti Aliasing uniform int boolFilterFXAA; // enabled Fast Approximate Anti Aliasing
uniform int boolFilterGrain;// enable some graininess to add to every pixels uniform int boolFilterGrain; // enable some graininess to add to every pixels
// normalized fragment coordinates // normalized fragment coordinates
const vec2 fragCoords = gl_FragCoord.xy / resolution; vec2 fragCoords = gl_FragCoord.xy / resolution;
// texel size // texel size
const vec2 fboTexelSize = 1.0 / resolution; vec2 fboTexelSize = 1.0 / resolution;
#define true 1 // true is not natively defined #define true 1 // true is not natively defined
// FXAA implementation from: https://catlikecoding.com/unity/tutorials/advanced-rendering/fxaa/ // FXAA implementation from: https://catlikecoding.com/unity/tutorials/advanced-rendering/fxaa/
// with some minor optimizations regarding branches and texture lookups // with some minor optimizations regarding branches and texture lookups
struct LuminanceData { struct LuminanceData {
// stores information about luminance // stores information about luminance
float max, min, diff; // maximum, minimum and luminance difference between max/min float max, min, diff; // maximum, minimum and luminance difference between max/min
// fragment values and its neighboors // fragment values and its neighboors
float texels[3][3]; float texels[3][3];
// field names // field names
#define lumSouthWest lumData.texels[0][0] #define lumSouthWest lumData.texels[0][0]
#define lumSouth lumData.texels[1][0] #define lumSouth lumData.texels[1][0]
#define lumSouthEast lumData.texels[2][0] #define lumSouthEast lumData.texels[2][0]
#define lumWest lumData.texels[0][1] #define lumWest lumData.texels[0][1]
#define lumMiddle lumData.texels[1][1] #define lumMiddle lumData.texels[1][1]
#define lumEast lumData.texels[2][1] #define lumEast lumData.texels[2][1]
#define lumNorthWest lumData.texels[0][2] #define lumNorthWest lumData.texels[0][2]
#define lumNorth lumData.texels[1][2] #define lumNorth lumData.texels[1][2]
#define lumNorthEast lumData.texels[2][2] #define lumNorthEast lumData.texels[2][2]
}; };
float luminanceFromLinearRgb(in vec3 linearRgb) float luminanceFromLinearRgb(in vec3 linearRgb)
{ {
// relative luminance coefficent factors // relative luminance coefficent factors
const vec3 luminanceFactors = vec3(0.2126729, 0.7151522, 0.0721750); const vec3 luminanceFactors = vec3(0.2126729, 0.7151522, 0.0721750);
// compute luminance // compute luminance
return dot(linearRgb, luminanceFactors); return dot(linearRgb, luminanceFactors);
} }
float texelLuminosity(in vec2 pixelOffset) float texelLuminosity(in vec2 pixelOffset)
{ {
vec3 linearRgb = texture2D(fboTexture, fragCoords + pixelOffset * fboTexelSize).rgb; vec3 linearRgb = texture(fboTexture, fragCoords + pixelOffset * fboTexelSize).rgb;
return luminanceFromLinearRgb(linearRgb); return luminanceFromLinearRgb(linearRgb);
} }
// clamp between [0, 1] // clamp between [0, 1]
@ -77,90 +77,90 @@ float texelLuminosity(in vec2 pixelOffset)
// collect luminance data and fill struct // collect luminance data and fill struct
void collectLuminance(inout LuminanceData lumData) void collectLuminance(inout LuminanceData lumData)
{ {
// collect data // collect data
for (int x = -1; x < 2; x++) { for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) { for (int y = -1; y < 2; y++) {
lumData.texels[x + 1][y + 1] = texelLuminosity(vec2(float(x), float(y) ) ); lumData.texels[x + 1][y + 1] = texelLuminosity(vec2(float(x), float(y)));
} }
} }
// calculate highest and lowest + difference i.e the contrast // calculate highest and lowest + difference i.e the contrast
lumData.max = max(max(max(max(lumEast, lumWest), lumSouth), lumNorth), lumMiddle); lumData.max = max(max(max(max(lumEast, lumWest), lumSouth), lumNorth), lumMiddle);
lumData.min = min(min(min(min(lumEast, lumWest), lumSouth), lumNorth), lumMiddle); lumData.min = min(min(min(min(lumEast, lumWest), lumSouth), lumNorth), lumMiddle);
// compute difference // compute difference
lumData.diff = lumData.max - lumData.min; lumData.diff = lumData.max - lumData.min;
} }
// apply a basic tent blur filter, to average the fragments luminance // apply a basic tent blur filter, to average the fragments luminance
float fragBlendFactor(in LuminanceData lumData) float fragBlendFactor(in LuminanceData lumData)
{ {
// these should matter more, so double their influence // these should matter more, so double their influence
float fac = 2.0 * (lumNorth + lumSouth + lumWest + lumEast); float fac = 2.0 * (lumNorth + lumSouth + lumWest + lumEast);
fac += lumNorthWest + lumNorthEast + lumSouthWest + lumSouthEast; fac += lumNorthWest + lumNorthEast + lumSouthWest + lumSouthEast;
fac /= 12.0; // scale down fac /= 12.0; // scale down
fac = abs(fac - lumMiddle);
fac = saturate(fac / lumData.diff);
float blendFac = smoothstep(0.0, 1.0, fac); fac = abs(fac - lumMiddle);
fac = saturate(fac / lumData.diff);
return blendFac * blendFac; float blendFac = smoothstep(0.0, 1.0, fac);
return blendFac * blendFac;
} }
// determine the edge type // determine the edge type
bool determineEdge(in LuminanceData lumData) bool determineEdge(in LuminanceData lumData)
{ {
// change in horizontal pixels // change in horizontal pixels
float hori = float hori =
abs(lumNorth + lumSouth - 2.0 * lumMiddle) * 2.0 + abs(lumNorth + lumSouth - 2.0 * lumMiddle) * 2.0 +
abs(lumNorthEast + lumSouthEast - 2.0 * lumEast) + abs(lumNorthEast + lumSouthEast - 2.0 * lumEast) +
abs(lumNorthWest + lumSouthWest - 2.0 * lumWest); abs(lumNorthWest + lumSouthWest - 2.0 * lumWest);
// change in vertical pixels // change in vertical pixels
float veri = float veri =
abs(lumEast + lumWest - 2.0 * lumMiddle) * 2.0 + abs(lumEast + lumWest - 2.0 * lumMiddle) * 2.0 +
abs(lumNorthEast + lumNorthWest - 2.0 * lumNorth) + abs(lumNorthEast + lumNorthWest - 2.0 * lumNorth) +
abs(lumSouthEast + lumSouthWest - 2.0 * lumSouth); abs(lumSouthEast + lumSouthWest - 2.0 * lumSouth);
return hori >= veri; return hori >= veri;
} }
vec3 filterFXAA() vec3 filterFXAA()
{ {
// collect luminance data off current fragment // collect luminance data off current fragment
LuminanceData lumData; LuminanceData lumData;
collectLuminance(lumData); collectLuminance(lumData);
vec2 st = fragCoords; vec2 st = fragCoords;
if (lumData.diff > max(contrastThreshold, relativeThreshold * lumData.max) ) if (lumData.diff > max(contrastThreshold, relativeThreshold * lumData.max))
{ {
float fac = fragBlendFactor(lumData); float fac = fragBlendFactor(lumData);
bool edge = determineEdge(lumData); bool edge = determineEdge(lumData);
float pixelStep = edge ? fboTexelSize.y : fboTexelSize.x; float pixelStep = edge ? fboTexelSize.y : fboTexelSize.x;
float pLum = edge ? lumNorth : lumEast; float pLum = edge ? lumNorth : lumEast;
float nLum = edge ? lumSouth : lumWest; float nLum = edge ? lumSouth : lumWest;
float pGrad = abs(pLum - lumMiddle); float pGrad = abs(pLum - lumMiddle);
float nGrad = abs(nLum - lumMiddle); float nGrad = abs(nLum - lumMiddle);
pixelStep = pixelStep * sign(pGrad - nGrad); pixelStep = pixelStep * sign(pGrad - nGrad);
st += edge ? vec2(0, pixelStep * fac) : vec2(pixelStep * fac, 0); st += edge ? vec2(0, pixelStep * fac) : vec2(pixelStep * fac, 0);
} }
return texture2D(fboTexture, st).rgb; return texture(fboTexture, st).rgb;
} }
// apply gamma correctio to linear RGB color // apply gamma correctio to linear RGB color
vec3 gamma(in vec3 linearRgb) vec3 gamma(in vec3 linearRgb)
{ {
return pow(linearRgb, vec3(epsilon) ); return pow(linearRgb, vec3(epsilon));
} }
// de-gamma linear RGB color // de-gamma linear RGB color
// degamma() is the inverse function of gamma() // degamma() is the inverse function of gamma()
vec3 degamma(in vec3 linearRgb) vec3 degamma(in vec3 linearRgb)
{ {
return pow(linearRgb, vec3(1.0 / epsilon) ); return pow(linearRgb, vec3(1.0 / epsilon));
} }
// Gold Noise ©2015 dcerisano@standard3d.com // Gold Noise ©2015 dcerisano@standard3d.com
@ -168,136 +168,135 @@ vec3 degamma(in vec3 linearRgb)
// - uniform normalized distribution // - uniform normalized distribution
// - (fastest?) static noise generator function (also runs at low precision) // - (fastest?) static noise generator function (also runs at low precision)
// generate some 1D noise // generate some 1D noise
// no seed required // no seed required
float goldNoise(in vec2 xy) float goldNoise(in vec2 xy)
{ {
const float phi = 1.61803398874989484820459; // Φ = Golden Ratio const float phi = 1.61803398874989484820459; // Φ = Golden Ratio
return fract(tan(distance(xy * phi, xy) ) * xy.x) * 2.0 - 1.0; return fract(tan(distance(xy * phi, xy)) * xy.x) * 2.0 - 1.0;
} }
// gamma corrected bokeh down sampling filter as DoF blur // gamma corrected bokeh down sampling filter as DoF blur
vec3 bokeh(in float bokehSize) vec3 bokeh(in float bokehSize)
{ {
// if sampling rate is low enough, clamp it to use FXAA instead of a single unfiltered texture lookup // if sampling rate is low enough, clamp it to use FXAA instead of a single unfiltered texture lookup
if (bokehSize < 2.0) if (bokehSize < 2.0)
{ {
if (boolFilterFXAA == true) if (boolFilterFXAA == true)
{ {
// if filter FXAA // if filter FXAA
return filterFXAA(); return filterFXAA();
} }
else else
{ {
// if no DoF and no FXAA, do nearly nothing // if no DoF and no FXAA, do nearly nothing
return texture2D(fboTexture, fragCoords).rgb; return texture(fboTexture, fragCoords).rgb;
} }
} }
vec3 color = vec3(0); vec3 color = vec3(0);
const int steps = 8; // samples to take per axis {x,y} const int steps = 8; // samples to take per axis {x,y}
const int stepsHalf = steps / 2; const int stepsHalf = steps / 2;
const float stepSize = bokehSize / steps; const float stepSize = bokehSize / steps;
float samples = 0.0; // samples actually taken float samples = 0.0; // samples actually taken
for (int i = -stepsHalf; i < stepsHalf; i++) { for (int i = -stepsHalf; i < stepsHalf; i++) {
float u = stepSize * float(i) * fboTexelSize.x; float u = stepSize * float(i) * fboTexelSize.x;
for (int j = -stepsHalf; j < stepsHalf; j++) { for (int j = -stepsHalf; j < stepsHalf; j++) {
float v = stepSize * float(j) * fboTexelSize.y; float v = stepSize * float(j) * fboTexelSize.y;
// calculate sample effectiveness, as circle for perfect bokeh // calculate sample effectiveness, as circle for perfect bokeh
float shape = 1.0 - step(stepsHalf, length(vec2(i, j) ) ); float shape = 1.0 - step(stepsHalf, length(vec2(i, j)));
// if we have enough effectiveness, take a sample // if we have enough effectiveness, take a sample
if (shape > 0.5) { if (shape > 0.5) {
// calculate offset coordinates for sample, and add some noise to break of grid patterns when using low amount of samples // calculate offset coordinates for sample, and add some noise to break of grid patterns when using low amount of samples
float noiseX = goldNoise(vec2(i, j) + gl_FragCoord.xy + 1.0); float noiseX = goldNoise(vec2(i, j) + gl_FragCoord.xy + 1.0);
float noiseY = goldNoise(vec2(i, j) + gl_FragCoord.xy + 4.0); float noiseY = goldNoise(vec2(i, j) + gl_FragCoord.xy + 4.0);
vec2 coords = vec2(noiseX, noiseY) * fboTexelSize + fragCoords + vec2(u, v); vec2 coords = vec2(noiseX, noiseY) * fboTexelSize + fragCoords + vec2(u, v);
// gamma correct texture lookup and contribute // gamma correct texture lookup and contribute
color += gamma(texture2D(fboTexture, coords).rgb * shape); color += gamma(texture(fboTexture, coords).rgb * shape);
samples += shape; // we have taken a sample, so remember for normalization later samples += shape; // we have taken a sample, so remember for normalization later
} }
} }
} }
// de-gamma correct and normalize // de-gamma correct and normalize
return degamma(color / samples); return degamma(color / samples);
} }
vec3 filterDoF() vec3 filterDoF()
{ {
// get scene depth // get scene depth
float depth = texture2D(fboTexture, fragCoords).a; float depth = texture(fboTexture, fragCoords).a;
// Circle of Confusion // Circle of Confusion
float CoC = clamp( (depth - focusDistance) / focusRange, -1, 1) * 16.0; float CoC = clamp((depth - focusDistance) / focusRange, -1, 1) * 16.0;
// compute bokeh blur // compute bokeh blur
return bokeh(abs(CoC) ); return bokeh(abs(CoC));
} }
void filmGrain(inout vec3 color) void filmGrain(inout vec3 color)
{ {
float noiseRed = goldNoise(gl_FragCoord.xy + 1.0); float noiseRed = goldNoise(gl_FragCoord.xy + 1.0);
float noiseGreen = goldNoise(gl_FragCoord.xy + 16.0); float noiseGreen = goldNoise(gl_FragCoord.xy + 16.0);
float noiseBlue = goldNoise(gl_FragCoord.xy + 32.0); float noiseBlue = goldNoise(gl_FragCoord.xy + 32.0);
vec3 noise = vec3(noiseRed, noiseGreen, noiseBlue); vec3 noise = vec3(noiseRed, noiseGreen, noiseBlue);
float intensity = 1.0 - sqrt(texelLuminosity(vec2(0) ) ); float intensity = 1.0 - sqrt(texelLuminosity(vec2(0)));
color = color + color * noise * intensity * 0.2; color = color + color * noise * intensity * 0.2;
} }
void sampleColorTexture(inout vec3 color) void sampleColorTexture(inout vec3 color)
{ {
if (boolFilterDoF == true) if (boolFilterDoF == true)
{ {
// apply DoF // apply DoF
color = filterDoF(); color = filterDoF();
} }
else if (boolFilterFXAA == true) else if (boolFilterFXAA == true)
{ {
// if no DoF, filter FXAA // if no DoF, filter FXAA
color = filterFXAA(); color = filterFXAA();
} }
else else
{ {
// if no DoF and no FXAA, do nearly nothing // if no DoF and no FXAA, do nearly nothing
color = texture2D(fboTexture, fragCoords).rgb; color = texture(fboTexture, fragCoords).rgb;
} }
} }
void main() void main()
{ {
vec3 color; vec3 color;
// get primary scene color // get primary scene color
sampleColorTexture(color); sampleColorTexture(color);
// adjust contrast and brightness // adjust contrast and brightness
color = (color - 0.5) * (1.0 + contrast) + 0.5 + brightness; color = (color - 0.5) * (1.0 + contrast) + 0.5 + brightness;
// vignette // vignette
// falloff // falloff
float falloff = distance(fragCoords, vec2(0.5, 0.5) ); float falloff = distance(fragCoords, vec2(0.5, 0.5));
// adjust falloff and darken // adjust falloff and darken
color = color * (1.0 - falloff * falloff * falloff * 0.2); color = color * (1.0 - falloff * falloff * falloff * 0.2);
// tone map // tone map
color = clamp(color, 0.0, 1.0); color = clamp(color, 0.0, 1.0);
color = 1.0 - pow(1.0 - color, vec3(epsilon) ); color = 1.0 - pow(1.0 - color, vec3(epsilon));
if (boolFilterGrain == true) if (boolFilterGrain == true)
{ {
// add some film grain // add some film grain
filmGrain(color); filmGrain(color);
} }
fragColor = vec4(color, 1); fragColor = vec4(color, 1);
} }

View File

@ -3,32 +3,32 @@
out vec4 fragColor; out vec4 fragColor;
// input variables // input variables
uniform vec2 resolution; // screen resolution uniform vec2 resolution; // screen resolution
uniform float time; // global time uniform float time; // global time
uniform vec2 cameraRotation; // rotation of camera in x and y uniform vec2 cameraRotation; // rotation of camera in x and y
uniform float cameraZoom; // zoom of camera uniform float cameraZoom; // zoom of camera
uniform sampler2D worldTexture; // stone uniform sampler2D worldTexture; // stone
uniform sampler2D environmentTexture; // texture of background as environemnt uniform sampler2D environmentTexture; // texture of background as environemnt
uniform sampler2D coinTexture; // texture of coins uniform sampler2D coinTexture; // texture of coins
uniform sampler2D testTexture; // test uniform sampler2D testTexture; // test
uniform float width; uniform float width;
uniform float height; uniform float height;
uniform int drawGytebot; uniform int drawGytebot;
uniform vec2 gytebotLocation; uniform vec2 gytebotLocation;
uniform float gytebotRotation; uniform float gytebotRotation;
layout(std430, binding = 0) readonly buffer CoinBuffer layout(std430, binding = 0) readonly buffer CoinBuffer
{ {
int coinBuffer[]; int coinBuffer[];
}; };
layout(std430, binding = 1) readonly buffer WallBuffer layout(std430, binding = 1) readonly buffer WallBuffer
{ {
float wallBuffer[]; float wallBuffer[];
}; };
// material indexes // material indexes
@ -57,61 +57,61 @@ const float PI = 3.14159265359;
const int mapBounds = 32; const int mapBounds = 32;
const float nearPlane = 1e-3; // camera near plane const float nearPlane = 1e-3; // camera near plane
const float farPlane = 1e3; // camera far plane const float farPlane = 1e3; // camera far plane
const float wallHeight = 0.05; // height of walls. NOTE: if raised or lowered coins and the bot may float or sink into the ground const float wallHeight = 0.05; // height of walls. NOTE: if raised or lowered coins and the bot may float or sink into the ground
// TODO: adjust coin and bot elevation by wallHeight // TODO: adjust coin and bot elevation by wallHeight
const float borderSize = 0.03; // extended border for map const float borderSize = 0.03; // extended border for map
// recommend values: [ 0.015, 0.030, 0.04 ] // recommend values: [ 0.015, 0.030, 0.04 ]
const vec2 epsilon = vec2(1e-3, 0); // small value for creating tiny gaps to prevent errors, not recommend to change const vec2 epsilon = vec2(1e-3, 0); // small value for creating tiny gaps to prevent errors, not recommend to change
// gytebot exceeds width of 1.0, so adjust scale factor to make him fit in! // gytebot exceeds width of 1.0, so adjust scale factor to make him fit in!
const float gytebotScale = (mapBounds + 18); float gytebotScale = (mapBounds + 18);
const float invGytebotScale = 1.0 / gytebotScale; float invGytebotScale = 1.0 / gytebotScale;
// boundary of walls // boundary of walls
const vec3 wallBounding = vec3(width/mapBounds + epsilon.x, wallHeight + epsilon.x, height/mapBounds + epsilon.x); vec3 wallBounding = vec3(width / mapBounds + epsilon.x, wallHeight + epsilon.x, height / mapBounds + epsilon.x);
// ^ add some space on top for cleaner normal calculations // ^ add some space on top for cleaner normal calculations
const float gytebotElevation = -invGytebotScale - 0.02; float gytebotElevation = -invGytebotScale - 0.02;
// create a "3D" texture lookup by blending all 3 different sides of an cube together // create a "3D" texture lookup by blending all 3 different sides of an cube together
// TODO: Replace with biplanar-mapping // TODO: Replace with biplanar-mapping
vec3 textureBox2D(in sampler2D sampler, in vec3 normal, in vec3 point) vec3 textureBox2D(in sampler2D sampler, in vec3 normal, in vec3 point)
{ {
vec3 x = texture2D(sampler, point.yz).bgr; vec3 x = texture(sampler, point.yz).bgr;
vec3 y = texture2D(sampler, point.zx).bgr; vec3 y = texture(sampler, point.zx).bgr;
vec3 z = texture2D(sampler, point.xy).bgr; vec3 z = texture(sampler, point.xy).bgr;
vec3 blend = pow(abs(normal), vec3(0.5) ); vec3 blend = pow(abs(normal), vec3(0.5));
return (x * blend.x + y * blend.y + z * blend.z) / (blend.x + blend.y + blend.z); return (x * blend.x + y * blend.y + z * blend.z) / (blend.x + blend.y + blend.z);
} }
float sampleWallMap(in vec2 point) float sampleWallMap(in vec2 point)
{ {
vec2 f = fract(point * vec2(width, height) ); vec2 f = fract(point * vec2(width, height));
int x = int(point.x * width); int x = int(point.x * width);
int y = int(point.y * height); int y = int(point.y * height);
// cubic hermite curve to smooth interpolation factors
f = f * f * (3.0 - 2.0 * f);
// apply mix factor transformation to 'harden' edges
f = pow(f, vec2(16.0) );
float s00 = wallBuffer[(x + 0) + (y + 0) * mapBounds]; // cubic hermite curve to smooth interpolation factors
float s10 = wallBuffer[(x + 1) + (y + 0) * mapBounds]; f = f * f * (3.0 - 2.0 * f);
float s01 = wallBuffer[(x + 0) + (y + 1) * mapBounds]; // apply mix factor transformation to 'harden' edges
float s11 = wallBuffer[(x + 1) + (y + 1) * mapBounds]; f = pow(f, vec2(16.0));
// mix top and bottom samples from left to right float s00 = wallBuffer[(x + 0) + (y + 0) * mapBounds];
float south = mix(s00, s10, f.x); float s10 = wallBuffer[(x + 1) + (y + 0) * mapBounds];
float north = mix(s01, s11, f.x); float s01 = wallBuffer[(x + 0) + (y + 1) * mapBounds];
float s11 = wallBuffer[(x + 1) + (y + 1) * mapBounds];
// mix top and bottom together and invert
return 1.0 - mix(south, north, f.y); // mix top and bottom samples from left to right
float south = mix(s00, s10, f.x);
float north = mix(s01, s11, f.x);
// mix top and bottom together and invert
return 1.0 - mix(south, north, f.y);
} }
// extrude a 2D sdf (on x,z) to 3D (x,y,z) // extrude a 2D sdf (on x,z) to 3D (x,y,z)
@ -119,39 +119,39 @@ float sampleWallMap(in vec2 point)
float extrudeSdf(in vec3 position, in float sdf) float extrudeSdf(in vec3 position, in float sdf)
{ {
vec2 w = vec2(sdf, abs(position.y) - wallHeight); vec2 w = vec2(sdf, abs(position.y) - wallHeight);
return min(max(w.x, w.y), 0.0) + length(max(w, 0.0) ); return min(max(w.x, w.y), 0.0) + length(max(w, 0.0));
} }
// wall sdf // wall sdf
float sdfMap(in vec3 position) float sdfMap(in vec3 position)
{ {
// sample flat 2D-walls // sample flat 2D-walls
float sdfWall = sampleWallMap( (position.xz + wallBounding.xz) / (2.0 * wallBounding.xz) - vec2(0.11/vec2(width, height) ) ) * 0.01 - 0.002; float sdfWall = sampleWallMap((position.xz + wallBounding.xz) / (2.0 * wallBounding.xz) - vec2(0.11 / vec2(width, height))) * 0.01 - 0.002;
// extrude 2D-walls to 3D // extrude 2D-walls to 3D
return extrudeSdf(position, sdfWall); return extrudeSdf(position, sdfWall);
} }
float sdfBox(vec3 p, vec3 b) float sdfBox(vec3 p, vec3 b)
{ {
vec3 q = abs(p) - b; vec3 q = abs(p) - b;
return length(max(q, 0.0) ) + min(max(q.x, max(q.y, q.z) ), 0.0); return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
} }
float borderBox(in vec3 position) float borderBox(in vec3 position)
{ {
// compute bounding container, by cutting out a small box out of a big box via boolean difference // compute bounding container, by cutting out a small box out of a big box via boolean difference
return max( return max(
sdfBox(position, wallBounding + vec3(borderSize, 0.02, borderSize) ), // big box sdfBox(position, wallBounding + vec3(borderSize, 0.02, borderSize)), // big box
-sdfBox(position + vec3(0, 0.1, 0), wallBounding - vec3(0.01, -0.05, 0.01) ) // small box -sdfBox(position + vec3(0, 0.1, 0), wallBounding - vec3(0.01, -0.05, 0.01)) // small box
); );
} }
// AABB ray-intersection algorithm // AABB ray-intersection algorithm
// by Inigo Quilez: https://iquilezles.org/www/articles/intersectors/intersectors.htm // by Inigo Quilez: https://iquilezles.org/www/articles/intersectors/intersectors.htm
vec2 boxIntersection(in vec3 origin, in vec3 direction, inout vec3 normal, in vec3 boxSize) vec2 boxIntersection(in vec3 origin, in vec3 direction, inout vec3 normal, in vec3 boxSize)
{ {
vec3 m = 1.0 / direction; vec3 m = 1.0 / direction;
vec3 n = m * origin; // can precompute if traversing a set of aligned boxes vec3 n = m * origin; // can precompute if traversing a set of aligned boxes
vec3 k = abs(m) * boxSize; vec3 k = abs(m) * boxSize;
vec3 t1 = -n - k; vec3 t1 = -n - k;
vec3 t2 = -n + k; vec3 t2 = -n + k;
@ -159,8 +159,8 @@ vec2 boxIntersection(in vec3 origin, in vec3 direction, inout vec3 normal, in ve
float tN = max(max(t1.x, t1.y), t1.z); float tN = max(max(t1.x, t1.y), t1.z);
float tF = min(min(t2.x, t2.y), t2.z); float tF = min(min(t2.x, t2.y), t2.z);
if(tN > tF || tF < 0.0) if (tN > tF || tF < 0.0)
return vec2(-1.0); // no intersection return vec2(-1.0); // no intersection
normal = -sign(direction) * step(t1.yzx, t1.xyz) * step(t1.zxy, t1.xyz); normal = -sign(direction) * step(t1.yzx, t1.xyz) * step(t1.zxy, t1.xyz);
@ -169,7 +169,7 @@ vec2 boxIntersection(in vec3 origin, in vec3 direction, inout vec3 normal, in ve
SDF3D sdfUnion(in SDF3D a, in SDF3D b) SDF3D sdfUnion(in SDF3D a, in SDF3D b)
{ {
return a.x < b.x ? a : b; return a.x < b.x ? a : b;
} }
float smoothmin(in float d1, in float d2, in float k) float smoothmin(in float d1, in float d2, in float k)
@ -180,49 +180,49 @@ float smoothmin(in float d1, in float d2, in float k)
SDF3D sdfGytebot(in vec3 position) SDF3D sdfGytebot(in vec3 position)
{ {
return sdfUnion( return sdfUnion(
SDF3D( SDF3D(
// wheels // wheels
min( min(
length(position - vec3( 0, 1.5, 1) ) - 0.58, length(position - vec3(0, 1.5, 1)) - 0.58,
min( min(
length(position - vec3( 0.75, 1.5, -0.5) ) - 0.58, length(position - vec3(0.75, 1.5, -0.5)) - 0.58,
length(position - vec3(-0.75, 1.5, -0.5) ) - 0.58 length(position - vec3(-0.75, 1.5, -0.5)) - 0.58
) )
), MaterialDark), ), MaterialDark),
sdfUnion( sdfUnion(
// eye // eye
SDF3D( (length( (position + vec3(0, 0, 0.7) ) * vec3(1, 1, 2.0) ) - 0.5) * 0.5, MaterialEyes), SDF3D((length((position + vec3(0, 0, 0.7)) * vec3(1, 1, 2.0)) - 0.5) * 0.5, MaterialEyes),
SDF3D( SDF3D(
min( min(
// head as sliced sphere shell // head as sliced sphere shell
max(-dot(position, vec3(0, 0, 1) ) - 0.7, abs(length(position) - 1.0) - 0.05 ), max(-dot(position, vec3(0, 0, 1)) - 0.7, abs(length(position) - 1.0) - 0.05),
max( max(
-dot(position, vec3(0, -1, 0) ) - 1.8, // slice -dot(position, vec3(0, -1, 0)) - 1.8, // slice
smoothmin( smoothmin(
length(position - vec3(0,1,0)) - 0.6, // body, will connect three wheels length(position - vec3(0, 1, 0)) - 0.6, // body, will connect three wheels
min( min(
length(position - vec3( 0, 1.5, 1) ) - 0.6, // back wheel length(position - vec3(0, 1.5, 1)) - 0.6, // back wheel
min( min(
length(position - vec3( 0.75, 1.5, -0.5) ) - 0.6, // right wheel length(position - vec3(0.75, 1.5, -0.5)) - 0.6, // right wheel
length(position - vec3(-0.75, 1.5, -0.5) ) - 0.6 // left wheel length(position - vec3(-0.75, 1.5, -0.5)) - 0.6 // left wheel
) )
), 0.2 ), 0.2
) )
) )
), MaterialBlue) ), MaterialBlue)
) )
); );
} }
mat2 constructRotationMatrix(float theta) mat2 constructRotationMatrix(float theta)
{ {
float sinTheta = sin(theta); // sine of theta float sinTheta = sin(theta); // sine of theta
float cosTheta = cos(theta); // cosine of theta float cosTheta = cos(theta); // cosine of theta
mat2 matrix = mat2(sinTheta, -cosTheta, cosTheta, sinTheta); // construct rotation matrix mat2 matrix = mat2(sinTheta, -cosTheta, cosTheta, sinTheta); // construct rotation matrix
return matrix; return matrix;
} }
// standard arguments required for composing a mesh // standard arguments required for composing a mesh
@ -235,325 +235,326 @@ mat2 constructRotationMatrix(float theta)
float sdfCoin(in vec3 position) float sdfCoin(in vec3 position)
{ {
vec2 d = abs(vec2(length(position.xy), position.z) ) - vec2(0.43, 0.0001); vec2 d = abs(vec2(length(position.xy), position.z)) - vec2(0.43, 0.0001);
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0) ) / 64.0; return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)) / 64.0;
} }
vec2 coinUv; vec2 coinUv;
void renderMap(stdArgs) void renderMap(stdArgs)
{ {
// get intersection distances with box containing the map // get intersection distances with box containing the map
vec2 bound = boxIntersection(viewPosition, viewDirection, normal, wallBounding); vec2 bound = boxIntersection(viewPosition, viewDirection, normal, wallBounding);
if (bound.y > 0.0) // if we hit, i.e tFar is greater than 0 or not behind the camera if (bound.y > 0.0) // if we hit, i.e tFar is greater than 0 or not behind the camera
{ {
float rayLength = max(bound.x, epsilon.x); float rayLength = max(bound.x, epsilon.x);
vec3 intersection = viewPosition + viewDirection * rayLength; vec3 intersection = viewPosition + viewDirection * rayLength;
float maxDist = distance(intersection, viewPosition + viewDirection * bound.y); float maxDist = distance(intersection, viewPosition + viewDirection * bound.y);
float map; float map;
// march through cube // march through cube
for (float dist = epsilon.x; dist < maxDist; dist += map) { for (float dist = epsilon.x; dist < maxDist; dist += map) {
vec3 location = intersection + viewDirection * dist; vec3 location = intersection + viewDirection * dist;
map = sdfMap(location); map = sdfMap(location);
if (map < epsilon.x) if (map < epsilon.x)
{ {
// set material data // set material data
depth = max(bound.x, epsilon.x) + dist; depth = max(bound.x, epsilon.x) + dist;
position = location; position = location;
normal = normalize(map.x - vec3( normal = normalize(map.x - vec3(
sdfMap(location + epsilon.xyy).x, sdfMap(location + epsilon.xyy).x,
sdfMap(location + epsilon.yxy).x, sdfMap(location + epsilon.yxy).x,
sdfMap(location + epsilon.yyx).x ) ); sdfMap(location + epsilon.yyx).x));
materialIndex = MaterialRockDef; materialIndex = MaterialRockDef;
break; // were done, break out break; // were done, break out
} }
} }
// traverse a grid of 2D cells via bransham // traverse a grid of 2D cells via bransham
// if we enter a cell check if there is coin in it, if not continue, if yes, render coin. // if we enter a cell check if there is coin in it, if not continue, if yes, render coin.
// in case there was a coin, but it has no effect, meaning we missed it, continue // in case there was a coin, but it has no effect, meaning we missed it, continue
// calculate start- and end-points of bounding box containing the cells // calculate start- and end-points of bounding box containing the cells
vec2 endPoint = vec3(viewPosition + viewDirection * bound.y).xz; vec2 endPoint = vec3(viewPosition + viewDirection * bound.y).xz;
vec2 startPoint = vec3(viewPosition + viewDirection * max(bound.x, epsilon.x) ).xz; vec2 startPoint = vec3(viewPosition + viewDirection * max(bound.x, epsilon.x)).xz;
// remap to [0, width/height] // remap to [0, width/height]
endPoint = (endPoint / wallBounding.xz * 0.5 + 0.5) * vec2(width, height); endPoint = (endPoint / wallBounding.xz * 0.5 + 0.5) * vec2(width, height);
startPoint = (startPoint / wallBounding.xz * 0.5 + 0.5) * vec2(width, height); startPoint = (startPoint / wallBounding.xz * 0.5 + 0.5) * vec2(width, height);
vec2 diff = endPoint - startPoint; vec2 diff = endPoint - startPoint;
// number of steps we need to travel // number of steps we need to travel
float dist = abs(diff.x) + abs(diff.y); float dist = abs(diff.x) + abs(diff.y);
// amount of space we need to travel for each cell // amount of space we need to travel for each cell
vec2 delta = diff / dist; vec2 delta = diff / dist;
// traverse grid // traverse grid
for (float i = 0.0; i < ceil(dist); i += 1.0) { for (float i = 0.0; i < ceil(dist); i += 1.0) {
// position in grid // position in grid
vec2 pos = floor(startPoint + delta * i); vec2 pos = floor(startPoint + delta * i);
// index of coin // index of coin
int index = int(pos.x + pos.y * width); int index = int(pos.x + pos.y * width);
int isCoin = coinBuffer[index]; int isCoin = coinBuffer[index];
// do we have a coin? // do we have a coin?
if (isCoin == 1) if (isCoin == 1)
{ {
mat2 coinRotation = constructRotationMatrix(time); mat2 coinRotation = constructRotationMatrix(time);
// transform local cell space to world space // transform local cell space to world space
vec2 localSpace = (pos / vec2(width, height) * 2.0 - 1.0) * wallBounding.xz; vec2 localSpace = (pos / vec2(width, height) * 2.0 - 1.0) * wallBounding.xz;
// construct world space translation // construct world space translation
vec3 translation = vec3(localSpace.x, 0, localSpace.y) + vec3(1.0 / mapBounds, -0.03, 1.0 / mapBounds); vec3 translation = vec3(localSpace.x, 0, localSpace.y) + vec3(1.0 / mapBounds, -0.03, 1.0 / mapBounds);
float t = epsilon.x; float t = epsilon.x;
// march a cylinder as a coin
for (int x = 0; x < 80; x++) {
vec3 location = (intersection - translation + viewDirection * t) * mapBounds;
location.xz *= coinRotation; // march a cylinder as a coin
for (int x = 0; x < 80; x++) {
vec3 location = (intersection - translation + viewDirection * t) * mapBounds;
float h = sdfCoin(location); location.xz *= coinRotation;
if (h < epsilon.x)
{
// hit it!
position = intersection + viewDirection * t;
depth = t + rayLength;
normal = normalize(h - vec3(
sdfCoin(location + epsilon.xyy).x,
sdfCoin(location + epsilon.yxy).x,
sdfCoin(location + epsilon.yyx).x ) );
normal.xz *= inverse(coinRotation);
materialIndex = MaterialCoin; float h = sdfCoin(location);
coinUv = location.xy - vec2(0, 0.5); if (h < epsilon.x)
{
// hit it!
position = intersection + viewDirection * t;
depth = t + rayLength;
normal = normalize(h - vec3(
sdfCoin(location + epsilon.xyy).x,
sdfCoin(location + epsilon.yxy).x,
sdfCoin(location + epsilon.yyx).x));
normal.xz *= inverse(coinRotation);
i = 100.0; materialIndex = MaterialCoin;
break;
} coinUv = location.xy - vec2(0, 0.5);
t += h;
i = 100.0;
// view is obstructed, break up break;
if (t + rayLength > depth) }
break; t += h;
}
} // view is obstructed, break up
} if (t + rayLength > depth)
} break;
}
}
}
}
} }
void renderBoundingBox(stdArgs) void renderBoundingBox(stdArgs)
{ {
float dist = nearPlane; float dist = nearPlane;
for (int i = 0; i < 128; i++) { for (int i = 0; i < 128; i++) {
vec3 location = viewPosition + viewDirection * dist; vec3 location = viewPosition + viewDirection * dist;
float map = borderBox(location); float map = borderBox(location);
dist += map; dist += map;
if (dist > depth) if (dist > depth)
break; break;
else if (map < epsilon.x * dist) else if (map < epsilon.x * dist)
{ {
depth = dist; depth = dist;
position = location; position = location;
normal = normalize(map.x - vec3( normal = normalize(map.x - vec3(
borderBox(location + epsilon.xyy).x, borderBox(location + epsilon.xyy).x,
borderBox(location + epsilon.yxy).x, borderBox(location + epsilon.yxy).x,
borderBox(location + epsilon.yyx).x ) ); borderBox(location + epsilon.yyx).x));
materialIndex = MaterialRockExt; materialIndex = MaterialRockExt;
break; break;
} }
} }
} }
float gytebotOcclusion = 0.0; float gytebotOcclusion = 0.0;
int renderGytebot(stdArgs, in vec2 worldGytebotLocation) int renderGytebot(stdArgs, in vec2 worldGytebotLocation)
{ {
float dist = nearPlane; float dist = nearPlane;
vec3 gytebotPosition = viewPosition - vec3(worldGytebotLocation.x, gytebotElevation, worldGytebotLocation.y); vec3 gytebotPosition = viewPosition - vec3(worldGytebotLocation.x, gytebotElevation, worldGytebotLocation.y);
for (int i = 0; i < 80; i++) { for (int i = 0; i < 80; i++) {
vec3 location = gytebotPosition + viewDirection * dist; vec3 location = gytebotPosition + viewDirection * dist;
vec3 scaledLocation = location * gytebotScale; vec3 scaledLocation = location * gytebotScale;
SDF3D map = sdfGytebot(scaledLocation) * vec2(invGytebotScale, 1); SDF3D map = sdfGytebot(scaledLocation) * vec2(invGytebotScale, 1);
if (map.x < epsilon.x) if (map.x < epsilon.x)
{ {
depth = dist; depth = dist;
position = location; position = location;
// compute normal // compute normal
normal = normalize(sdfGytebot(scaledLocation).x * invGytebotScale - vec3( normal = normalize(sdfGytebot(scaledLocation).x * invGytebotScale - vec3(
sdfGytebot(scaledLocation + epsilon.xyy).x * invGytebotScale, sdfGytebot(scaledLocation + epsilon.xyy).x * invGytebotScale,
sdfGytebot(scaledLocation + epsilon.yxy).x * invGytebotScale, sdfGytebot(scaledLocation + epsilon.yxy).x * invGytebotScale,
sdfGytebot(scaledLocation + epsilon.yyx).x * invGytebotScale) ); sdfGytebot(scaledLocation + epsilon.yyx).x * invGytebotScale));
materialIndex = int(map.y); materialIndex = int(map.y);
return 1; return 1;
} }
dist += map.x; dist += map.x;
if (dist > depth) if (dist > depth)
break; break;
} }
gytebotOcclusion = min(sdfGytebot( (gytebotPosition + viewDirection * depth) * gytebotScale).x * 0.6 + 0.4, 1.0); gytebotOcclusion = min(sdfGytebot((gytebotPosition + viewDirection * depth) * gytebotScale).x * 0.6 + 0.4, 1.0);
return 0; return 0;
} }
const vec2 invAtan = vec2(0.1591, 0.3183); const vec2 invAtan = vec2(0.1591, 0.3183);
vec2 getSphericalSt(in vec3 direction) vec2 getSphericalSt(in vec3 direction)
{ {
vec2 uv = vec2(atan(direction.z, direction.x), asin(direction.y) ); vec2 uv = vec2(atan(direction.z, direction.x), asin(direction.y));
uv *= invAtan; uv *= invAtan;
uv += 0.5; uv += 0.5;
return uv; return uv;
} }
vec3 shadeMaterial(in vec3 incoming, in vec3 position, in vec3 normal, in vec3 albedo, in float roughness) vec3 shadeMaterial(in vec3 incoming, in vec3 position, in vec3 normal, in vec3 albedo, in float roughness)
{ {
vec2 uv = getSphericalSt(normal); vec2 uv = getSphericalSt(normal);
vec3 irradiance = textureGrad(environmentTexture, uv, vec2(0.05), vec2(0.05) ).bgr; vec3 irradiance = textureGrad(environmentTexture, uv, vec2(0.05), vec2(0.05)).bgr;
float lod = pow(roughness, 4.0); float lod = pow(roughness, 4.0);
vec2 specUv = getSphericalSt(reflect(incoming, normal) ); vec2 specUv = getSphericalSt(reflect(incoming, normal));
vec3 specular = textureGrad(environmentTexture, specUv, vec2(lod), vec2(lod) ).bgr; vec3 specular = textureGrad(environmentTexture, specUv, vec2(lod), vec2(lod)).bgr;
float R = min(pow(1.0 - dot(incoming, normal), 2.0) * (1.0 - roughness * roughness), 1.0); float R = min(pow(1.0 - dot(incoming, normal), 2.0) * (1.0 - roughness * roughness), 1.0);
return mix(irradiance * albedo, specular, R); return mix(irradiance * albedo, specular, R);
} }
void main() void main()
{ {
// create rotation matracies // create rotation matracies
mat2 horizontalCamerRotation = constructRotationMatrix(cameraRotation.x); mat2 horizontalCamerRotation = constructRotationMatrix(cameraRotation.x);
mat2 verticalCamerRotation = constructRotationMatrix(cameraRotation.y); mat2 verticalCamerRotation = constructRotationMatrix(cameraRotation.y);
mat2 gytebotRotationMat = constructRotationMatrix(gytebotRotation ); mat2 gytebotRotationMat = constructRotationMatrix(gytebotRotation);
// create camera untransformed data // create camera untransformed data
vec2 screenCoords = (gl_FragCoord.xy - 0.5 * resolution.xy) / resolution.y; // re-map fragment coordinates to [-1, 1] vec2 screenCoords = (gl_FragCoord.xy - 0.5 * resolution.xy) / resolution.y; // re-map fragment coordinates to [-1, 1]
vec3 viewDirection = normalize(vec3(screenCoords, 1) ); // construct origin vec3 viewDirection = normalize(vec3(screenCoords, 1)); // construct origin
vec3 viewPosition = vec3(0, 0, cameraZoom); vec3 viewPosition = vec3(0, 0, cameraZoom);
vec3 normal; vec3 normal;
vec3 position; vec3 position;
int materialIndex = MaterialNone; int materialIndex = MaterialNone;
// camera view depth // camera view depth
// initially set to the farthest // initially set to the farthest
float depth = farPlane; float depth = farPlane;
// rotate camera on y // rotate camera on y
viewPosition.yz *= verticalCamerRotation; viewPosition.yz *= verticalCamerRotation;
viewDirection.yz *= verticalCamerRotation; viewDirection.yz *= verticalCamerRotation;
// rotate camera on x // rotate camera on x
viewPosition.xz *= horizontalCamerRotation; viewPosition.xz *= horizontalCamerRotation;
viewDirection.xz *= horizontalCamerRotation; viewDirection.xz *= horizontalCamerRotation;
// compose the maps walls and coins // compose the maps walls and coins
renderMap(viewPosition, viewDirection, position, normal, depth, materialIndex); renderMap(viewPosition, viewDirection, position, normal, depth, materialIndex);
// compose a bounding box // compose a bounding box
renderBoundingBox(viewPosition, viewDirection, position, normal, depth, materialIndex); renderBoundingBox(viewPosition, viewDirection, position, normal, depth, materialIndex);
vec3 cameraDirection = viewDirection; vec3 cameraDirection = viewDirection;
vec2 worldGytebotLocation = (gytebotLocation / vec2(width, height) * 2.0 - 1.0) * wallBounding.xz + vec2(0.03); vec2 worldGytebotLocation = (gytebotLocation / vec2(width, height) * 2.0 - 1.0) * wallBounding.xz + vec2(0.03);
viewPosition.xz -= worldGytebotLocation; // move camera to origin, to not have the rotation affect the translation viewPosition.xz -= worldGytebotLocation; // move camera to origin, to not have the rotation affect the translation
// rotate camera, to "fake" a gytebot rotation // rotate camera, to "fake" a gytebot rotation
viewPosition.xz *= gytebotRotationMat; viewPosition.xz *= gytebotRotationMat;
viewDirection.xz *= gytebotRotationMat; viewDirection.xz *= gytebotRotationMat;
viewPosition.xz += worldGytebotLocation; // move camera back viewPosition.xz += worldGytebotLocation; // move camera back
if (drawGytebot == 1) if (drawGytebot == 1)
{ {
if (renderGytebot(viewPosition, viewDirection, position, normal, depth, materialIndex, worldGytebotLocation) == 1) if (renderGytebot(viewPosition, viewDirection, position, normal, depth, materialIndex, worldGytebotLocation) == 1)
{ {
// rotate normal back to world space // rotate normal back to world space
normal.xz *= inverse(gytebotRotationMat); normal.xz *= inverse(gytebotRotationMat);
} }
} }
vec3 color; vec3 color;
if (materialIndex == MaterialNone) if (materialIndex == MaterialNone)
{ {
// sample environment texture + gamma correction // sample environment texture + gamma correction
color = texture2D(environmentTexture, getSphericalSt(cameraDirection) ).bgr; color = texture(environmentTexture, getSphericalSt(cameraDirection)).bgr;
} else if (depth < nearPlane) } else if (depth < nearPlane)
{ {
color = vec3(0); color = vec3(0);
} else } else
{ {
vec3 albedo; vec3 albedo;
switch(materialIndex) { switch (materialIndex) {
#define stdParams cameraDirection, position, normal, albedo #define stdParams cameraDirection, position, normal, albedo
case MaterialRockDef: case MaterialRockDef:
albedo = textureBox2D(worldTexture, normal, position * 5.0); albedo = textureBox2D(worldTexture, normal, position * 5.0);
color = shadeMaterial(stdParams, 0.85); color = shadeMaterial(stdParams, 0.85);
color *= min(pow(abs(position.y), 0.5) * 8, 1); color *= min(pow(abs(position.y), 0.5) * 8, 1);
break; break;
case MaterialRockExt: case MaterialRockExt:
albedo = textureBox2D(worldTexture, normal, position * 5.0); albedo = textureBox2D(worldTexture, normal, position * 5.0);
color = shadeMaterial(stdParams, 0.85); color = shadeMaterial(stdParams, 0.85);
if (normal.x < 1e-2 && normal.z < 1e-2 && normal.y > 0.99 && position.y > -wallHeight * 0.4) if (normal.x < 1e-2 && normal.z < 1e-2 && normal.y > 0.99 && position.y > -wallHeight * 0.4)
{ {
// paint ambient occlusion // paint ambient occlusion
vec2 point = (position.xz + wallBounding.xz) / (2.0 * wallBounding.xz); vec2 point = (position.xz + wallBounding.xz) / (2.0 * wallBounding.xz);
color *= vec3(sampleWallMap(point - vec2(0.11/vec2(width, height) ) ) ); color *= vec3(sampleWallMap(point - vec2(0.11 / vec2(width, height))));
color *= vec3(gytebotOcclusion); color *= vec3(gytebotOcclusion);
// paint grid lines // paint grid lines
point *= vec2(width, height); point *= vec2(width, height);
color += vec3(step(0.95, fract(point.x) ) + step(0.95, fract(point.y) ) ) * pow(texture2D(worldTexture, position.xz).g, 2.0); color += vec3(step(0.95, fract(point.x)) + step(0.95, fract(point.y))) * pow(texture(worldTexture, position.xz).g, 2.0);
color *= 1.0 - vec3(step(0.0, sin(point.x * PI) * sin(point.y * PI) ) ) * 0.1; color *= 1.0 - vec3(step(0.0, sin(point.x * PI) * sin(point.y * PI))) * 0.1;
} }
break; break;
case MaterialBlue: case MaterialBlue:
albedo = vec3(0.275, 0.796, 1); albedo = vec3(0.275, 0.796, 1);
color = shadeMaterial(stdParams, 0.1); color = shadeMaterial(stdParams, 0.1);
break; break;
case MaterialDark: case MaterialDark:
albedo = vec3(0.1); albedo = vec3(0.1);
color = shadeMaterial(stdParams, 0.6); color = shadeMaterial(stdParams, 0.6);
break; break;
case MaterialEyes: case MaterialEyes:
albedo = vec3(0.1); albedo = vec3(0.1);
color = shadeMaterial(stdParams, 0.1); color = shadeMaterial(stdParams, 0.1);
color += smoothstep(0.97, 1.0, dot(normal, vec3(cos(gytebotRotation), 0, sin(gytebotRotation) ) ) ); // emission color += smoothstep(0.97, 1.0, dot(normal, vec3(cos(gytebotRotation), 0, sin(gytebotRotation)))); // emission
break; break;
case MaterialCoin: case MaterialCoin:
albedo = texture2D(coinTexture, coinUv).bgr; albedo = texture(coinTexture, coinUv).bgr;
color = shadeMaterial(stdParams, 0.2); color = shadeMaterial(stdParams, 0.2);
break; break;
default: break; default:
} break;
} }
}
// color += texture2D(testTexture, screenCoords).rgb; // color += texture(testTexture, screenCoords).rgb;
fragColor = vec4(color, depth); fragColor = vec4(color, depth);
} }