Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit a0167a7

Browse files
committed
Quality of life (camera, hand and cross platform)
1 parent d8def6d commit a0167a7

File tree

19 files changed

+328
-112
lines changed

19 files changed

+328
-112
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TODO.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ Key:
1515
## Gameplay
1616
- [x] Player entity with physics
1717
- [x] Block building and destruction
18+
- [ ] Block inventory
19+
- [ ] Partial blocks (e.g. slabs)
1820
- [ ] World saving and loading
19-
- [ ] 🤔 Block ID flattening? It takes up more memory, but it should not affect performance much.
21+
- [ ] 🤔 Block ID flattening?
22+
23+
## Bugs
24+
- [ ] Fix raycasts
25+
- [ ] Fix player animation jitter
26+
- [ ] Fix distance jitter

client/build.gradle.kts

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,105 @@ import java.text.SimpleDateFormat
22
import java.util.*
33

44
plugins {
5+
id("com.github.johnrengelman.shadow") version "8.1.1"
56
application
67
}
78

89
val lwjglVersion = "3.3.2"
910
val jomlVersion = "1.10.5"
10-
val lwjglNatives = "natives-windows"
11+
12+
val platforms = arrayOf(
13+
"linux",
14+
"linux-arm64",
15+
"linux-arm32",
16+
"macos",
17+
"macos-arm64",
18+
"windows",
19+
"windows-x86",
20+
"windows-arm64"
21+
);
22+
23+
val lwjglModules = arrayOf(
24+
"glfw",
25+
"openal",
26+
"opengl",
27+
"stb"
28+
)
29+
30+
var platform = providers.gradleProperty("voxelthing.client.platform").getOrElse(Pair(
31+
System.getProperty("os.name")!!,
32+
System.getProperty("os.arch")!!
33+
).let { (name, arch) ->
34+
when {
35+
arrayOf("Linux", "FreeBSD", "SunOS", "Unit").any { name.startsWith(it) } ->
36+
if (arrayOf("arm", "aarch64").any { arch.startsWith(it) })
37+
"linux${if (arch.contains("64") || arch.startsWith("armv8")) "-arm64" else "-arm32"}"
38+
else
39+
"linux"
40+
41+
arrayOf("Mac OS X", "Darwin").any { name.startsWith(it) } ->
42+
"macos${if (arch.startsWith("aarch64")) "-arm64" else ""}"
43+
44+
arrayOf("Windows").any { name.startsWith(it) } ->
45+
if (arch.contains("64"))
46+
"windows${if (arch.startsWith("aarch64")) "-arm64" else ""}"
47+
else
48+
"windows-x86"
49+
50+
else -> throw Error("Unrecognized or unsupported platform. Please set \"lwjglNatives\" manually")
51+
}
52+
})
1153

1254
repositories {
1355
mavenCentral()
1456
}
1557

1658
dependencies {
17-
implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))
59+
implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))
60+
61+
implementation("org.lwjgl:lwjgl")
62+
for (m in lwjglModules) {
63+
implementation("org.lwjgl:lwjgl-$m")
64+
}
65+
implementation("org.joml:joml:${jomlVersion}")
1866

19-
implementation("org.lwjgl:lwjgl")
20-
implementation("org.lwjgl:lwjgl-assimp")
21-
implementation("org.lwjgl:lwjgl-glfw")
22-
implementation("org.lwjgl:lwjgl-openal")
23-
implementation("org.lwjgl:lwjgl-opengl")
24-
implementation("org.lwjgl:lwjgl-stb")
25-
runtimeOnly("org.lwjgl:lwjgl::$lwjglNatives")
26-
runtimeOnly("org.lwjgl:lwjgl-assimp::$lwjglNatives")
27-
runtimeOnly("org.lwjgl:lwjgl-glfw::$lwjglNatives")
28-
runtimeOnly("org.lwjgl:lwjgl-openal::$lwjglNatives")
29-
runtimeOnly("org.lwjgl:lwjgl-opengl::$lwjglNatives")
30-
runtimeOnly("org.lwjgl:lwjgl-stb::$lwjglNatives")
31-
implementation("org.joml:joml:${jomlVersion}")
67+
for (p in platforms.filter { platform == "all" || it == platform }) {
68+
runtimeOnly("org.lwjgl:lwjgl::natives-$p")
69+
for (m in lwjglModules) {
70+
runtimeOnly("org.lwjgl:lwjgl-$m::natives-$p")
71+
}
72+
}
3273

33-
implementation(project(":shared"))
74+
implementation(project(":shared"))
3475
}
3576

3677
application {
3778
mainClass.set("io.bluestaggo.voxelthing.Game")
3879
}
3980

4081
tasks.compileJava {
41-
dependsOn("genMetadata")
82+
dependsOn("genMetadata")
83+
}
84+
85+
tasks.withType<Jar> {
86+
manifest {
87+
attributes["Main-Class"] = "io.bluestaggo.voxelthing.Game"
88+
}
89+
90+
archiveBaseName.set("voxelthing")
4291
}
4392

4493
task("genMetadata") {
45-
val resources = sourceSets.main.get().output.resourcesDir
46-
resources?.mkdirs()
94+
val resources = sourceSets.main.get().output.resourcesDir
95+
resources?.mkdirs()
4796

48-
val versionFile = file("$resources/version.txt")
49-
versionFile.createNewFile()
50-
versionFile.writeText(getaVersion())
97+
val versionFile = file("$resources/version.txt")
98+
versionFile.createNewFile()
99+
versionFile.writeText(getaVersion())
51100
}
52101

53102
fun getaVersion(): String {
54103
var version = providers.gradleProperty("voxelthing.version").get();
55-
version = version.replace("dev", "dev ${SimpleDateFormat("yyyyMMdd").format(Date())}");
56-
return version;
104+
version = version.replace("dev", "dev ${SimpleDateFormat("yyyyMMdd").format(Date())}");
105+
return version;
57106
}

client/src/main/java/io/bluestaggo/voxelthing/Game.java

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.bluestaggo.voxelthing;
22

3+
import io.bluestaggo.voxelthing.gui.DebugGui;
34
import io.bluestaggo.voxelthing.gui.GuiScreen;
45
import io.bluestaggo.voxelthing.gui.IngameGui;
56
import io.bluestaggo.voxelthing.renderer.MainRenderer;
67
import io.bluestaggo.voxelthing.window.ClientPlayerController;
78
import io.bluestaggo.voxelthing.window.Window;
89
import io.bluestaggo.voxelthing.world.BlockRaycast;
910
import io.bluestaggo.voxelthing.world.ClientWorld;
10-
import io.bluestaggo.voxelthing.world.Direction;
1111
import io.bluestaggo.voxelthing.world.World;
1212
import io.bluestaggo.voxelthing.world.entity.IPlayerController;
1313
import io.bluestaggo.voxelthing.world.entity.Player;
@@ -48,9 +48,11 @@ public class Game {
4848
"floof",
4949
"talon"
5050
};
51-
private int currentSkin = VERSION.contains("dev") ? 1 : 0;
51+
private int currentSkin = VERSION.contains("dev") || VERSION.equals("???") ? 1 : 0;
5252
private boolean thirdPerson;
5353
private boolean debugMenu = true;
54+
private boolean drawGui = true;
55+
private boolean viewBobbing = true;
5456

5557
private static Game instance;
5658

@@ -61,6 +63,7 @@ public class Game {
6163
public Player player;
6264
public IPlayerController playerController;
6365

66+
private final GuiScreen debugGui;
6467
private final GuiScreen inGameGui;
6568

6669
private BlockRaycast blockRaycast;
@@ -83,6 +86,7 @@ public Game() {
8386
world = new ClientWorld(this);
8487
player = new Player(world, playerController);
8588

89+
debugGui = new DebugGui(this);
8690
inGameGui = new IngameGui(this);
8791

8892
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -124,22 +128,33 @@ private void update(double delta) {
124128
if (world != null) {
125129
world.partialTick = partialTick;
126130
}
127-
renderer.camera.setPosition((float) player.getPartialX(), (float) (player.getPartialY() + player.height - 0.3), (float) player.getPartialZ());
128-
renderer.camera.setRotation((float) player.rotYaw, (float) player.rotPitch);
129131

130-
if (thirdPerson) {
131-
renderer.camera.moveForward(-4.0f);
132+
float px = (float) player.getPartialX();
133+
float py = (float) player.getPartialY();
134+
float pz = (float) player.getPartialZ();
135+
float yaw = (float) player.rotYaw;
136+
float pitch = (float) player.rotPitch;
137+
138+
py += player.height - 0.3;
139+
if (viewBobbing) {
140+
if (thirdPerson) {
141+
py -= player.getPartialVelY() * 0.2;
142+
}
143+
pitch += player.getPartialVelY() * 2.5f;
132144
}
133145

146+
renderer.camera.setPosition(px, py, pz);
147+
renderer.camera.setRotation(yaw, pitch);
148+
134149
if (world != null) {
135150
blockRaycast = renderer.camera.getRaycast(5.0f);
136-
if (world.doRaycast(blockRaycast)) {
137-
int x = blockRaycast.getHitX();
138-
int y = blockRaycast.getHitY();
139-
int z = blockRaycast.getHitZ();
140-
int block = world.getBlockId(x, y, z);
141-
Direction face = blockRaycast.getHitFace();
142-
}
151+
world.doRaycast(blockRaycast);
152+
}
153+
154+
if (thirdPerson) {
155+
renderer.camera.moveForward(-4.0f);
156+
} else if (viewBobbing) {
157+
renderer.camera.setPosition((float) player.getRenderX(), (float) (player.getRenderY() + player.height - 0.3), (float) player.getRenderZ());
143158
}
144159

145160
if (window.isKeyJustPressed(GLFW_KEY_F)) {
@@ -173,10 +188,18 @@ private void update(double delta) {
173188
renderer.screen.scale += 0.5f;
174189
}
175190

191+
if (window.isKeyJustPressed(GLFW_KEY_F1)) {
192+
drawGui = !drawGui;
193+
}
194+
176195
if (window.isKeyJustPressed(GLFW_KEY_F3)) {
177196
debugMenu = !debugMenu;
178197
}
179198

199+
if (window.isKeyJustPressed(GLFW_KEY_F4)) {
200+
viewBobbing = !viewBobbing;
201+
}
202+
180203
if (window.isKeyJustPressed(GLFW_KEY_F5)) {
181204
thirdPerson = !thirdPerson;
182205
}
@@ -192,7 +215,13 @@ private void update(double delta) {
192215

193216
private void draw() {
194217
renderer.draw();
195-
inGameGui.draw();
218+
219+
if (drawGui) {
220+
if (debugMenu) {
221+
debugGui.draw();
222+
}
223+
inGameGui.draw();
224+
}
196225
}
197226

198227
public String getSkin() {
@@ -203,10 +232,6 @@ public boolean showThirdPerson() {
203232
return thirdPerson;
204233
}
205234

206-
public boolean showDebug() {
207-
return debugMenu;
208-
}
209-
210235
public double getPartialTick() {
211236
return partialTick;
212237
}
@@ -215,6 +240,10 @@ public BlockRaycast getBlockRaycast() {
215240
return blockRaycast;
216241
}
217242

243+
public boolean viewBobbingEnabled() {
244+
return viewBobbing;
245+
}
246+
218247
public static void main(String[] args) {
219248
System.setProperty("java.awt.headless", "true");
220249
new Game().run();

client/src/main/java/io/bluestaggo/voxelthing/assets/TextureManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private Texture getTextureFromMap(Map<String, Texture> map, String path) {
2323
return getTextureFromMap(map, "/assets/missing.png");
2424
}
2525

26-
if (!textures.containsKey(path)) {
26+
if (!map.containsKey(path)) {
2727
try {
2828
Texture texture = loadTexture(path);
2929
map.put(path, texture);
@@ -36,7 +36,7 @@ private Texture getTextureFromMap(Map<String, Texture> map, String path) {
3636
}
3737
}
3838

39-
return textures.get(path);
39+
return map.get(path);
4040
}
4141

4242
public Texture getTexture(String path) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.bluestaggo.voxelthing.gui;
2+
3+
import io.bluestaggo.voxelthing.Game;
4+
import io.bluestaggo.voxelthing.assets.FontManager;
5+
import io.bluestaggo.voxelthing.renderer.screen.Screen;
6+
7+
public class DebugGui extends GuiScreen {
8+
public DebugGui(Game game) {
9+
super(game);
10+
}
11+
12+
@Override
13+
public void draw() {
14+
FontManager fonts = game.renderer.fonts;
15+
Screen screen = game.renderer.screen;
16+
17+
fonts.outlined.print("§00ffffVOXEL THING §00ff00" + Game.VERSION, 5, 5, 1.0f, 1.0f, 1.0f);
18+
19+
long freeMB = Runtime.getRuntime().freeMemory() / 1000000L;
20+
long totalMB = Runtime.getRuntime().totalMemory() / 1000000L;
21+
long maxMB = Runtime.getRuntime().maxMemory() / 1000000L;
22+
23+
String[] lines = {
24+
"Speed", (int)(game.window.getDeltaTime() * 1000.0D) + "ms",
25+
"Memory", (totalMB - freeMB) + " / " + maxMB + " MB",
26+
"Render Distance", String.valueOf(game.renderer.worldRenderer.renderDistance),
27+
"GUI Scale", String.valueOf(screen.scale <= 0.0f ? "auto" : screen.scale)
28+
};
29+
30+
StringBuilder debugBuilder = new StringBuilder();
31+
32+
for (int i = 0; i < lines.length / 2; i++) {
33+
String label = lines[i * 2];
34+
String value = lines[i * 2 + 1];
35+
36+
if (!debugBuilder.isEmpty()) {
37+
debugBuilder.append('\n');
38+
}
39+
40+
debugBuilder.append("§ffff7f");
41+
debugBuilder.append(label);
42+
debugBuilder.append(": §ffffff");
43+
debugBuilder.append(value);
44+
}
45+
46+
fonts.shadowed.print(debugBuilder.toString(), 5, 15);
47+
}
48+
}

0 commit comments

Comments
 (0)