Skip to content

Commit

Permalink
version gui and minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
valoeghese committed May 19, 2020
1 parent e461b9d commit 27f461c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 14 deletions.
12 changes: 11 additions & 1 deletion src/main/java/tk/valoeghese/fc0/client/Client2fc.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.lwjgl.glfw.GLFWCursorPosCallbackI;
import tk.valoeghese.fc0.client.gui.Crosshair;
import tk.valoeghese.fc0.client.gui.GUI;
import tk.valoeghese.fc0.client.gui.Version;
import tk.valoeghese.fc0.client.keybind.KeybindManager;
import tk.valoeghese.fc0.client.keybind.MousebindManager;
import tk.valoeghese.fc0.client.model.Shaders;
Expand Down Expand Up @@ -45,6 +46,7 @@ public Client2fc() {
private ClientPlayer player;
private long nextUpdate = 0;
private GUI crosshair;
private GUI version;

@Override
public void run() {
Expand Down Expand Up @@ -86,17 +88,24 @@ private void init() {
this.prevYPos = this.window.height / 2;
this.prevXPos = this.window.width / 2;
this.crosshair = new Crosshair();
this.version = new Version();
this.world.populateChunks();
}

private void updateMovement() {
final float yaw = this.player.getCamera().getYaw();
float slowness = this.player.getHorizontalSlowness();
boolean lr = Keybinds.MOVE_LEFT.isPressed() || Keybinds.MOVE_RIGHT.isPressed();
boolean fb = Keybinds.MOVE_BACKWARDS.isPressed() || Keybinds.MOVE_FOWARDS.isPressed();

if (Keybinds.RUN.isPressed()) {
slowness /= 1.67;
}

if (lr && fb) {
slowness = org.joml.Math.sqrt(2 * (slowness * slowness));
}

if (Keybinds.MOVE_BACKWARDS.isPressed()) {
this.player.addVelocity(-sin(yaw) / slowness, 0.0f, cos(yaw) / slowness);
} else if (Keybinds.MOVE_FOWARDS.isPressed()) {
Expand Down Expand Up @@ -133,7 +142,7 @@ private void updateMovement() {
}

if (Keybinds.RESPAWN.hasBeenPressed() || this.player.getTilePos().y < -20) {
player.setPos(new Pos(0, 60, 0));
player.setPos(new Pos(0, this.world.getHeight(0, 0) + 1, 0));
}
}

Expand All @@ -145,6 +154,7 @@ private void render() {
// projection
Shaders.gui.uniformMat4f("projection", this.guiProjection);
// render gui
this.version.render();
this.crosshair.render();
// bind shader
Shaders.terrain.bind();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tk/valoeghese/fc0/client/ClientPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ClientPlayer(Camera camera, World world) {
this.camera = camera;
this.camera.translateScene(new Vector3f(0, -1.8f, 0)); // 2 blocks tall, camera at head
this.world = world;
this.move(0, world.getHeight(0, 0) + 2, 0);
this.move(0, world.getHeight(0, 0) + 1, 0);
}

private final MutablePos pos;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/tk/valoeghese/fc0/client/gui/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tk.valoeghese.fc0.client.gui;

import tk.valoeghese.fc0.client.model.Textures;

public class Version extends GUI {
public Version() {
super(Textures.VERSION);

int tl = this.vertex(-1.0f, 1.0f, 0, 1);
int bl = this.vertex(-1.0f, -1.0f, 0, 0);
int tr = this.vertex(1.0f, 1.0f, 1, 1);
int br = this.vertex(1.0f, -1.0f, 1, 0);

this.tri(tl, bl, br);
this.tri(tl, tr, br);

this.generateBuffers();
}
}
17 changes: 12 additions & 5 deletions src/main/java/tk/valoeghese/fc0/client/model/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
import java.io.UncheckedIOException;

public class Textures {
public static final int TILE_ATLAS;

static {
private static int load(String arg0, boolean fallbackToNull) {
try {
TILE_ATLAS = TextureLoader.textureARGB(ImageIO.read(Resources.loadURL("assets/texture/tile_atlas.png")));
return TextureLoader.textureARGB(ImageIO.read(Resources.loadURL("assets/texture/" + arg0 + ".png")));
} catch (IOException e) {
throw new UncheckedIOException("Error loading Tile Atlas", e);
e.printStackTrace();

if (fallbackToNull) {
return 0;
} else {
throw new UncheckedIOException("Error loading Tile Atlas", e);
}
}
}

public static final int TILE_ATLAS = load("tile_atlas", false);
public static final int VERSION = load("version", true);
}
5 changes: 3 additions & 2 deletions src/main/java/tk/valoeghese/fc0/world/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class Chunk implements World {
public Chunk(int x, int z, byte[] tiles) {
Expand Down Expand Up @@ -94,10 +95,10 @@ public boolean isInWorld(int x, int y, int z) {
}

@Override
public int getHeight(int x, int z) {
public int getHeight(int x, int z, Predicate<Tile> solid) {
for (int y = 127; y >= 0; --y) {
if (this.heightsToRender.contains(y)) {
if (Tile.BY_ID[this.readTile(x, y, z)].shouldRender()) {
if (solid.test(Tile.BY_ID[this.readTile(x, y, z)])) {
return y;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/tk/valoeghese/fc0/world/ChunkSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import tk.valoeghese.fc0.util.ChunkPos;
import tk.valoeghese.fc0.util.OrderedList;
import tk.valoeghese.fc0.util.TilePos;
import tk.valoeghese.fc0.world.tile.Tile;

import java.util.*;
import java.util.function.Predicate;

public class ChunkSelection implements World {
public ChunkSelection(long seed) {
Expand Down Expand Up @@ -90,8 +92,8 @@ public void writeTile(int x, int y, int z, byte tile) {
}

@Override
public int getHeight(int x, int z) {
return this.getChunk(x >> 4, z >> 4).getHeight(x & 0xF, z & 0xF);
public int getHeight(int x, int z, Predicate<Tile> solid) {
return this.getChunk(x >> 4, z >> 4).getHeight(x & 0xF, z & 0xF, solid);
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/tk/valoeghese/fc0/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import tk.valoeghese.fc0.client.ClientPlayer;
import tk.valoeghese.fc0.util.TilePos;
import tk.valoeghese.fc0.world.tile.Tile;

import java.util.function.Predicate;

public interface World {
default byte readTile(TilePos pos) {
Expand All @@ -16,10 +19,14 @@ default boolean isInWorld(TilePos pos) {
return this.isInWorld(pos.x, pos.y, pos.z);
}

default int getHeight(int x, int z) {
return this.getHeight(x, z, Tile::shouldRender);
}

byte readTile(int x, int y, int z);
void writeTile(int x, int y, int z, byte tile);
boolean isInWorld(int x, int y, int z);
int getHeight(int x, int z);
int getHeight(int x, int z, Predicate<Tile> solid);

default void updateChunkOf(ClientPlayer clientPlayer) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void generate(int startX, int startZ, Random rand, World world) {
for (int i = 0; i < count; ++i) {
int x = startX + rand.nextInt(16);
int z = startZ + rand.nextInt(16);
int y = world.getHeight(x, z) + 1;
int y = world.getHeight(x, z, tile -> tile.isOpaque() && tile != Tile.LOG) + 1;
int height = 3 + rand.nextInt(3);

for (int xo = -2; xo <= 2; ++xo) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/shader/gui_v.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ out vec2 uvPass;
uniform mat4 projection;

void main() {
gl_Position = projection * vec4(rawPos, -0.9, 1.0);
gl_Position = projection * vec4(rawPos, 0.999, 1.0);
uvPass = rawUV;
}
Binary file added src/main/resources/assets/texture/version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 27f461c

Please sign in to comment.