Skip to content

Commit

Permalink
NVidia compatibility issue fix, structure spawning refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jheller9 committed Jul 28, 2020
1 parent df88e3b commit e65e763
Show file tree
Hide file tree
Showing 98 changed files with 586 additions and 353 deletions.
2 changes: 2 additions & 0 deletions Engine/core/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

import audio.AudioHandler;
import dev.Console;
Expand Down
1 change: 1 addition & 0 deletions Engine/dev/CommandData.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum CommandData {
god(true),
hp(true),
kill(false),
fill(true, "id/item"),

// Getters
version("VERSION", Application.class, GETTER, false),
Expand Down
34 changes: 32 additions & 2 deletions Engine/dev/CommandMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import map.Chunk;
import map.Enviroment;
import map.Terrain;
import map.tile.Tile;
import map.weather.Weather;
import procedural.structures.Structure;
import procedural.terrain.GenTerrain;
Expand All @@ -25,6 +26,7 @@
import scene.overworld.inventory.Inventory;
import scene.overworld.inventory.Item;
import scene.overworld.inventory.ItemData;
import scene.overworld.inventory.tool.EditorBoundsTool;

public class CommandMethods {
public static void logMessage(String msg) {
Expand Down Expand Up @@ -250,13 +252,41 @@ public static void give(String item, int amount) {

ItemData itemData = Item.get(item);



if (itemData.getId() != 0) {
inv.addItem(itemData, amount);
}
}

public static void fill(String item) {
if (!(Application.scene instanceof Overworld)) {
Console.log("Cannot use this command outside gameplay");
return;
}

Overworld overworld = (Overworld) Application.scene;
ItemData itemData = Item.get(item);

Terrain terrain = overworld.getEnviroment().getTerrain();

if (itemData.getId() != 0 || item.equals("air")) {
int fill = 0;
final Vector3f p1 = new Vector3f(Math.min(EditorBoundsTool.p1.x, EditorBoundsTool.p2.x), Math.min(EditorBoundsTool.p1.y, EditorBoundsTool.p2.y), Math.min(EditorBoundsTool.p1.z, EditorBoundsTool.p2.z));
final Vector3f p2 = new Vector3f(Math.max(EditorBoundsTool.p1.x, EditorBoundsTool.p2.x), Math.max(EditorBoundsTool.p1.y, EditorBoundsTool.p2.y), Math.max(EditorBoundsTool.p1.z, EditorBoundsTool.p2.z));
byte wall = overworld.getCamFacingByte();

for(int x = ((int)p1.x); x <= p2.x; x++) {
for(int y = ((int)p1.y); y <= p2.y; y++) {
for(int z = ((int)p1.z); z <= p2.z; z++) {
terrain.getChunkAt(x, z).setTile(Math.floorMod(x, Chunk.CHUNK_SIZE), y, Math.floorMod(z, Chunk.CHUNK_SIZE), wall, itemData.getMaterial(), (byte) 0);
fill++;
}
}
}

Console.log("filled " + fill + " tiles");
}
}

public static void fov(int fov) {
Camera.fov = fov;
Application.scene.getCamera().updateProjection();
Expand Down
8 changes: 6 additions & 2 deletions Engine/dev/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static void toggle() {
input = "";
predictions.clear();

playerWasAlreadyDisabled = false;// TODO: THIS
playerWasAlreadyDisabled = false;

if (visible) {
Input.requestMouseRelease();
Expand Down Expand Up @@ -392,7 +392,7 @@ public static void update() {

String[] inputSpace = input.split(" ");

if (input.indexOf("give") == 0 && inputSpace.length >= 1 && inputSpace.length < 3) {
if ((input.indexOf("give") == 0 || input.indexOf("fill") == 0) && inputSpace.length >= 1 && inputSpace.length < 3) {
predictEnum(inputSpace.length == 2 ? inputSpace[1] : "", Item.names());
}

Expand Down Expand Up @@ -435,6 +435,10 @@ public static void update() {
if (Input.isPressed(Keyboard.KEY_GRAVE)) {
toggle();
}

if (visible && Input.isPressed(Keyboard.KEY_ESCAPE)) {
toggle();
}
}

private static void predictEnum(String string, Set<String> values) {
Expand Down
46 changes: 46 additions & 0 deletions Engine/dev/Debug.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package dev;

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL15;

import core.Application;
Expand Down Expand Up @@ -85,4 +89,46 @@ public static void uiDebugInfo(Overworld overworld) {
+ "facing: " + overworld.getCamFacingByte()
, 5, 5, .25f, false);
}

public static void testGLError() {
try {
if (!Display.isCurrent())
return;
} catch (LWJGLException e) {
e.printStackTrace();
return;
}
String AllErrors = "";
int GL_Error;
do {
GL_Error = glGetError();
switch (GL_Error) {
case GL_NO_ERROR:
break;
case GL_INVALID_ENUM:
AllErrors += "GL_INVALID_ENUM";
break;
case GL_INVALID_VALUE:
AllErrors += "GL_INVALID_VALUE";
break;
case GL_INVALID_OPERATION:
AllErrors += "GL_INVALID_OPERATION";
break;
case GL_STACK_OVERFLOW:
AllErrors += "GL_STACK_OVERFLOW";
break;
case GL_STACK_UNDERFLOW:
AllErrors += "GL_STACK_UNDERFLOW";
break;
case GL_OUT_OF_MEMORY:
AllErrors += "GL_OUT_OF_MEMORY";
break;
default:
AllErrors += "unknown gl error";
break;
}
} while (GL_Error != GL_NO_ERROR);

System.err.println(AllErrors);
}
}
6 changes: 0 additions & 6 deletions Engine/dev/tracers/LineRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static void render(Camera cam) {
GL11.glDisable(GL11.GL_CULL_FACE);
shader.start();
line.bind();
GL20.glEnableVertexAttribArray(0);
shader.projectionViewMatrix.loadMatrix(cam.getProjectionViewMatrix());
int j = 0;
for (int i = 0; i < points.size(); i += 2) {
Expand All @@ -73,7 +72,6 @@ public static void render(Camera cam) {
}
// GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GL11.glEnable(GL11.GL_CULL_FACE);
GL20.glDisableVertexAttribArray(0);
line.unbind();
shader.stop();
}
Expand All @@ -87,15 +85,13 @@ public static void render(Camera cam, Vector3f p1, Vector3f p2) {
GL11.glDisable(GL11.GL_CULL_FACE);
shader.start();
line.bind();
GL20.glEnableVertexAttribArray(0);
shader.projectionViewMatrix.loadMatrix(cam.getProjectionViewMatrix());
shader.color.loadVec3(1, 0, 1);
shader.point1.loadVec3(p1);
shader.point2.loadVec3(p2);
GL11.glDrawArrays(GL11.GL_LINE_STRIP, 0, 2);
// GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GL11.glEnable(GL11.GL_CULL_FACE);
GL20.glDisableVertexAttribArray(0);
line.unbind();
GL11.glEnable(GL11.GL_DEPTH_TEST);
shader.stop();
Expand All @@ -109,7 +105,6 @@ public static void render(Camera cam, Vector3f p1, Vector3f p2, Vector3f color)
GL11.glDisable(GL11.GL_CULL_FACE);
shader.start();
line.bind();
GL20.glEnableVertexAttribArray(0);
shader.projectionViewMatrix.loadMatrix(cam.getProjectionViewMatrix());
shader.color.loadVec3(color);
shader.point1.loadVec3(p1);
Expand All @@ -127,7 +122,6 @@ public static void render(Camera camera, Vector4f p1, Vector4f p2) {
GL11.glDisable(GL11.GL_CULL_FACE);
shader.start();
line.bind();
GL20.glEnableVertexAttribArray(0);
shader.projectionViewMatrix.loadMatrix(camera.getProjectionViewMatrix());
shader.color.loadVec3(1, 0, 1);
shader.point1.loadVec3(p1.x, p1.y, p1.z);
Expand Down
4 changes: 2 additions & 2 deletions Engine/gl/Render.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gl;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

import core.Resources;
import gl.fbo.FrameBuffer;
Expand Down Expand Up @@ -78,7 +80,5 @@ public static void render(Scene scene) {
ParticleHandler.render(scene.getCamera());
ow.getInventory().render(camera, e.getLightDirection());
}


}
}
5 changes: 3 additions & 2 deletions Engine/gl/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public static void create() {

try {
System.setProperty("org.lwjgl.opengl.Window.undecorated", hasBorder ? "true" : "false");
ContextAttribs attribs = new ContextAttribs(3,3).withProfileCore(true).withForwardCompatible(true);
Display.create(new PixelFormat().withDepthBits(24), attribs);
//ContextAttribs attribs = new ContextAttribs(3,3).withProfileCore(true).withForwardCompatible(true);
//Display.create(new PixelFormat().withDepthBits(24), attribs);
Display.create();
Display.setTitle(windowTitle);
Display.setInitialBackground(1, 1, 1);
Display.setVSyncEnabled(false);
Expand Down
10 changes: 0 additions & 10 deletions Engine/gl/building/BuildingRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

public class BuildingRender {
private static Texture materialTexture = null;
private static Matrix4f ZERO_MATRIX = new Matrix4f();

public static int materialTextureScale = 32;
public static float materialAtlasSize;
Expand Down Expand Up @@ -60,9 +59,6 @@ public static void render(Camera camera, Vector3f lightDir, Vector3f selectionPo
shader.projectionViewMatrix.loadMatrix(camera.getProjectionViewMatrix());
shader.lightDirection.loadVec3(lightDir);

GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);
materialTexture.bind(0);
for (int i = 0; i < Terrain.size; i++) {
for (int j = 0; j < Terrain.size; j++) {
Expand All @@ -86,9 +82,6 @@ public static void render(Camera camera, Vector3f lightDir, Vector3f selectionPo
meshShader.projectionViewMatrix.loadMatrix(camera.getProjectionViewMatrix());
meshShader.lightDirection.loadVec3(lightDir);

GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);
selectorMatrix.identity();
selectorMatrix.translate(selectionPoint);

Expand Down Expand Up @@ -136,9 +129,6 @@ public static void render(Camera camera, Vector3f lightDir, Vector3f selectionPo
}
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(2);
GL30.glBindVertexArray(0);

meshShader.stop();
Expand Down
5 changes: 0 additions & 5 deletions Engine/gl/entity/item/ItemRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;

import core.Resources;
import gl.Camera;
Expand Down Expand Up @@ -42,8 +41,6 @@ public void render(PlayableScene scene, Camera camera, Vector3f lightDirection,
shader.diffuse.loadTexUnit(0);

texture.bind(0);
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
Resources.QUAD2D.bind(0, 1);

final float size = Inventory.itemAtlasSize;
Expand All @@ -66,8 +63,6 @@ public void render(PlayableScene scene, Camera camera, Vector3f lightDirection,
}

Resources.QUAD2D.unbind(0, 1);
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
texture.unbind();
shader.stop();
}
Expand Down
3 changes: 0 additions & 3 deletions Engine/gl/shadow/ShadowMeshRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ protected ShadowMeshRender(ShadowShader shader) {
}

protected void render(Matrix4f projectionViewMatrix, List<Entity> entities, List<Chunk> chunks) {

for (Entity entity : entities) {
Model model = entity.getModel();
model.bind(0, 1);
Expand All @@ -56,8 +55,6 @@ protected void render(Matrix4f projectionViewMatrix, List<Entity> entities, List
GL11.GL_UNSIGNED_INT, 0);
}
}
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
GL30.glBindVertexArray(0);
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/gl/shadow/shadow.frag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 330
#version 150

in vec2 pass_uvs;
out vec4 out_colour;
Expand Down
4 changes: 0 additions & 4 deletions Engine/gl/skybox/entity/SkyboxEntityRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public void render(Camera camera, Vector3f lightDirection, List<SkyboxEntity> li
shader.projectionViewMatrix.loadMatrix(buildProjViewMatrix(camera));
shader.diffuse.loadTexUnit(0);

GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Resources.QUAD2D.bind(0, 1);
Expand All @@ -44,8 +42,6 @@ public void render(Camera camera, Vector3f lightDirection, List<SkyboxEntity> li
}

Resources.QUAD2D.unbind(0, 1);
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
Expand Down
Loading

0 comments on commit e65e763

Please sign in to comment.