commit baa5105

shrub  ·  2026-07-31 17:40:56 +0000 UTC
parents 4e37d92, 34021a9
Merge remote-tracking branch 'origin/master' into protocol

# Conflicts:
#	meson.build
#	source/main.c
8 files changed,  +76, -10
M TODO
+1, -0
1@@ -1,3 +1,4 @@
2+AlignConsecutiveDeclarations: Consecutive
3 AlignEscapedNewlines: DontAlign
4 AlignTrailingComments: false
5 BreakBeforeBraces: Linux
M TODO
+4, -4
 1@@ -1,7 +1,7 @@
 2 uint:
 3-[-] Wireframe
 4-[-] Face hiding
 5-[-] Chunk meshing
 6+[ ] Wireframe
 7+[-] Face Hiding
 8+[X] Chunk meshing
 9 	[-] Greedily
10-[-] Fonts
11+[ ] Fonts
12 
+33, -0
 1@@ -0,0 +1,33 @@
 2+#ifndef CONFIG_H
 3+#define CONFIG_H
 4+
 5+#include "types.h"
 6+
 7+typedef struct {
 8+	/* display */
 9+	i32 display_width;
10+	i32 display_height;
11+	i32 display_fps_target;
12+	i8  display_fullscreen;
13+	i8  display_vsync;
14+
15+	/* input */
16+	float input_sensitivity;
17+
18+	/* camera */
19+	float camera_fov;
20+
21+	/* game */
22+	i32 game_render_distance;
23+
24+	/* temp */
25+	float temp_movement_speed;
26+} MGConfig;
27+
28+extern MGConfig mg_config;
29+
30+/* fill config with default config values */
31+void config_default(void);
32+
33+#endif /* CONFIG_H */
34+
+3, -2
 1@@ -33,10 +33,11 @@ BlockType chunk_get(const Chunk* chunk, i32 x, i32 y, i32 z);
 2          the future? who knows */
 3 void chunk_set(Chunk* chunk, i32 x, i32 y, i32 z, BlockType block);
 4 
 5-/**/
 6+/* create a mesh for chunk by generating vertices
 7+   and indices for each (visible) face */
 8 i8 chunk_mesh_create(Chunk* chunk);
 9 
10-/**/
11+/* destroy a chunks mesh */
12 void chunk_mesh_destroy(Chunk* chunk);
13 
14 #endif /* CHUNK_H */
+1, -0
1@@ -19,6 +19,7 @@ renderer_backend = get_option('renderer')
2 sources = [
3 	'source/main.c',
4 	'source/mg_random.c',
5+	'source/config.c',
6 	'source/util.c',
7 	'source/world/chunk.c',
8 	'source/client/camera.c',
+26, -0
 1@@ -0,0 +1,26 @@
 2+#include "config.h"
 3+
 4+MGConfig mg_config;
 5+
 6+void config_default(void)
 7+{
 8+	/* display */
 9+	mg_config.display_width = 800;
10+	mg_config.display_height = 600;
11+	mg_config.display_fps_target = 60;
12+	mg_config.display_fullscreen = 0;
13+	mg_config.display_vsync = 1;
14+
15+	/* input */
16+	mg_config.input_sensitivity = 0.0025;
17+
18+	/* camera */
19+	mg_config.camera_fov = 70.0f;
20+
21+	/* game */
22+	mg_config.game_render_distance = 32;
23+
24+	/* temp */
25+	mg_config.temp_movement_speed = 4.0f;
26+}
27+
+8, -2
 1@@ -4,6 +4,7 @@
 2 
 3 #include "SDL_keyboard.h"
 4 #include "SDL_timer.h"
 5+#include "config.h"
 6 #include "mcproto/mcproto.h"
 7 #include "util.h"
 8 #include "platform/platform.h"
 9@@ -27,7 +28,7 @@ static void input(void)
10 	const u8* keys = SDL_GetKeyboardState(NULL);
11 	MGVec3 move = MG_V3(0.0f, 0.0f, 0.0f);
12 	u32 now = SDL_GetTicks();
13-	float sensitivity = 0.0025f; /* arbritrary sensitivity */
14+	float sensitivity = mg_config.input_sensitivity;
15 	float dt;
16 	i32 mx;
17 	i32 my;
18@@ -53,7 +54,7 @@ static void input(void)
19 	if (keys[SDL_SCANCODE_LCTRL])
20 		move.y -= 1.0f;
21 
22-	move = MG_MulV3F(move, 8.0f * dt); /* arbritrary movement speed */
23+	move = MG_MulV3F(move, mg_config.temp_movement_speed * dt);
24 	camera_move(&cam, move);
25 	SDL_GetRelativeMouseState(&mx, &my);
26 	camera_rotate(&cam, mx * sensitivity, -my * sensitivity);
27@@ -109,6 +110,11 @@ int main(int argc, char** argv)
28 	if (argc == 3)
29 		return protocol_poc(argv[1], argv[2]);
30 
31+	config_default();
32+
33+	ctx.width = mg_config.display_width;
34+	ctx.height = mg_config.display_height;
35+
36 	platform_init(&ctx);
37 	platform_window_create(&ctx);
38 	renderer_create(&ctx);
+0, -2
1@@ -144,8 +144,6 @@ void chunk_set(Chunk* chunk, i32 x, i32 y, i32 z, BlockType block)
2 	chunk->blocks[x][y][z] = block;
3 }
4 
5-/* create a mesh for chunk by generating vertices
6-   and indices for each (visible) face */
7 i8 chunk_mesh_create(Chunk* chunk)
8 {
9 	MGVertex* vertices[BLOCK_LAST];