commit f4c5c63

uint  ·  2026-08-05 00:44:33 +0000 UTC
parent 877d445
give all protoytpes comments and return info (if applicable)
15 files changed,  +85, -26
M TODO
M TODO
+3, -0
1@@ -1,5 +1,8 @@
2 uint:
3 [ ] Clean up test_scene.h
4+[ ] Consolidate variable initaliasation methods
5+[ ] mc_proto, mg_random type cleanup (int->i8 on bool)
6+[ ] Review `block`
7 
8 [-] Face Hiding
9 [-] Chunk meshing
+8, -4
 1@@ -23,16 +23,20 @@ void camera_move(MGCamera* cam, MGVec3 offset);
 2 /* rotate camera by pitch and yaw deltas */
 3 void camera_rotate(MGCamera* cam, float dyaw, float dpitch);
 4 
 5-/* get cameras forward direction */
 6+/* get cameras forward direction
 7+   returns normalized forward vector */
 8 MGVec3 camera_get_forward(const MGCamera* cam);
 9 
10-/* get cameras right direction */
11+/* get cameras right direction
12+   returns normalized right vector */
13 MGVec3 camera_get_right(const MGCamera* cam);
14 
15-/* get cameras view matrix */
16+/* get cameras view matrix
17+   returns view matrix */
18 MGMat4 camera_get_view(const MGCamera* cam);
19 
20-/* get cameras projection matrix */
21+/* get cameras projection matrix
22+   returns projection matrix */
23 MGMat4 camera_get_proj(const MGCamera* cam, float aspect);
24 
25 #endif /* CLIENT_CAMERA_H */
+3, -0
 1@@ -16,7 +16,10 @@ typedef struct {
 2 	i8 positioned;
 3 } Player;
 4 
 5+/* handle position packet from server */
 6 void player_server_send_position(Player* player, MGCamera* cam, MCClient* client);
 7+
 8+/* send player position and rotations to server */
 9 void player_server_handle_position(Player* player, MGCamera* cam, const MCPacket* packet);
10 
11 #endif /* PLAYER_H */
+2, -1
 1@@ -19,7 +19,8 @@ void world_destroy(ClientWorld* world);
 2 /* remove chunk from  world (clears data, marks unsued) */
 3 void world_remove_chunk(ClientWorld* world, i32 x, i32 z);
 4 
 5-/* update chunk with data from server */
 6+/* update chunk with data from server
 7+   returns 1 on success, 0 on failure */
 8 i8 world_update_chunk(ClientWorld* world, const MCChunkUpdate* update, const u8* data);
 9 
10 #endif /* WORLD_H */
+2, -0
1@@ -5,6 +5,8 @@
2 
3 #include "types.h"
4 
5+/* fill buffer with random bytes
6+   returns 1 on success, 0 on failure */
7 int mg_random_bytes(u8* data, size_t size);
8 
9 #endif /* MG_RANDOM_H */
+6, -2
 1@@ -26,13 +26,17 @@ typedef struct {
 2 	i32            unload_z;
 3 } MCChunkPacket;
 4 
 5-/* general decode chunk data from packet */
 6+/*
 7+   general decode chunk data from packet
 8+   returns 1 on success, 0 on failure */
 9 i8 mc_chunk_decode(MCChunkPacket* chunk, const MCPacket* packet);
10 
11 /* destroy chunk data */
12 void mc_chunk_destroy(MCChunkPacket* chunk);
13 
14-/* calculate size of chunk data */
15+/*
16+   calculate size of chunk data
17+   returns size in bytes */
18 size_t mc_chunk_update_size(u16 mask, u8 skylight, i8 bulk);
19 
20 #endif /* MC_CHUNK_H */
+25, -6
 1@@ -54,27 +54,46 @@ typedef enum {
 2 	MC_EC_LAST
 3 } MCErrorCode;
 4 
 5-int  mc_client_login(MCClient** out, const char* address, const MCAccount* account, char* error, size_t error_size);
 6+/* log in to minecraft server
 7+   returns 1 on success, 0 on failure */
 8+int mc_client_login(MCClient** out, const char* address, const MCAccount* account, char* error, size_t error_size);
 9+
10+/* interrupt blocking client operations */
11 void mc_client_interrupt(MCClient* client);
12+
13+/* destroy minecraft client */
14 void mc_client_destroy(MCClient* client);
15 
16+/* read next packet from client
17+   returns 1 on success, 0 on failure */
18 int mc_client_read(MCClient* client, MCPacket* packet, char* error, size_t error_size);
19+
20+/* write packet to client
21+   returns 1 on success, 0 on failure */
22 int mc_client_write(MCClient* client, i32 packet_id, const void* data, size_t size);
23 
24-/* poll for packets.
25-   returns 1: packet recieved,
26-   0: no packet awaiting,
27-   -1: connection error */
28+/* poll for packets
29+   returns 1: packet recieved, 0: no packet awaiting, -1: connection error */
30 int mc_client_poll(MCClient* client, MCPacket* packet, char* error, size_t error_size);
31 
32+/* free packet data */
33 void mc_packet_free(MCPacket* packet);
34 
35-/* send server player look data */
36+/* send server player look data
37+   returns 1 on success, 0 on failure */
38 int mc_client_send_position_look(MCClient* client, double x, double feet_y, double z, float yaw, float pitch,
39                                  i8 grounded);
40 
41+/* get client username
42+   returns username, or empty string for null client */
43 const char* mc_client_username(const MCClient* client);
44+
45+/* get client uuid
46+   returns uuid, or empty string for null client */
47 const char* mc_client_uuid(const MCClient* client);
48+
49+/* get last minecraft client error code
50+   returns last error code */
51 MCErrorCode mc_last_error_code(void);
52 
53 #endif /* MC_PROTO_H */
+2, -1
 1@@ -29,7 +29,8 @@ void platform_get_drawable_size(MGContext* ctx, i32* width, i32* height);
 2 /* store mouse position in x and y */
 3 void platform_get_mouse_state(i32* x, i32* y);
 4 
 5-/* get time from initialisation of windowing backend */
 6+/* get time from initialisation of windowing backend
 7+   returns time in ms */
 8 u64 platform_get_ticks(void);
 9 
10 /* initialise resources */
+6, -3
 1@@ -48,7 +48,8 @@ void renderer_end(void);
 2 /* destroy renderer resources */
 3 void renderer_destroy(void);
 4 
 5-/* create mesh from descriptor */
 6+/* create mesh from descriptor
 7+   returns mesh handle, or MGMESH_INVALID on failure */
 8 MGMesh renderer_mesh_create(const MGMeshDesc* desc);
 9 
10 /* draws mesh using specified texture and mat */
11@@ -57,10 +58,12 @@ void renderer_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mvp);
12 /* destroy mesh */
13 void renderer_mesh_destroy(MGMesh id);
14 
15-/* load texture from file */
16+/* load texture from file
17+   returns texture handle, or MGTEXTURE_INVALID on failure */
18 MGTexture renderer_texture_load(const char* path);
19 
20-/* create an RGBA8 texture from pixels */
21+/* create an RGBA8 texture from pixels
22+   returns texture handle, or MGTEXTURE_INVALID on failure */
23 MGTexture renderer_texture_create(const MGTextureDesc* desc);
24 
25 /* destroy texture */
+3, -0
 1@@ -47,7 +47,10 @@ typedef enum {
 2 	LOG_DBG /* debug */
 3 } LogType;
 4 
 5+/* log message and exit with error code */
 6 void mg_die(MGErrorCodes ec, const char* fmt, ...);
 7+
 8+/* log message */
 9 void mg_log(LogType lt, const char* fmt, ...);
10 
11 #endif /* UTIL_H */
+17, -4
 1@@ -20,10 +20,23 @@ typedef struct {
 2 	i32      cullface;
 3 } BlockFace;
 4 
 5-i8               block_textures_create(const char* path);
 6-void             block_textures_destroy(void);
 7+/* create block textures from resource pack
 8+   returns 1 on success, 0 on failure */
 9+i8 block_textures_create(const char* path);
10+
11+/* destroy block textures */
12+void block_textures_destroy(void);
13+
14+/* get model faces for block
15+   returns block face array */
16 const BlockFace* block_model_faces(BlockType block, i32* count);
17-i8               block_model_occludes(BlockType block);
18-MGTexture        block_texture_get(i32 index);
19+
20+/* check whether block model occludes all cube faces
21+   returns 1 if block occludes, 0 otherwise */
22+i8 block_model_occludes(BlockType block);
23+
24+/* get block texture by index
25+   returns texture handle, or MGTEXTURE_INVALID on failure */
26+MGTexture block_texture_get(i32 index);
27 
28 #endif /* WORLD_BLOCK_H */
+6, -3
 1@@ -38,16 +38,19 @@ void chunk_remove(Chunk* chunk);
 2    TODO: make it general not only for test world */
 3 void chunk_section_create(ChunkSection* section);
 4 
 5-/* decode packed block states into a chunk section */
 6+/* decode packed block states into a chunk section
 7+   returns 1 on success, 0 on failure */
 8 i8 chunk_section_decode(ChunkSection* section, const u8* data, size_t size);
 9 
10-/* get the block at specified coordinate in chunk section */
11+/* get the block at specified coordinate in chunk section
12+   returns block type, or BLOCK_AIR on invalid input */
13 BlockType chunk_section_get(const ChunkSection* section, i32 x, i32 y, i32 z);
14 
15 /* set the block at specified coordinate in chunk section */
16 void chunk_section_set(ChunkSection* section, i32 x, i32 y, i32 z, BlockType block);
17 
18-/* create a mesh for a chunk section */
19+/* create a mesh for a chunk section
20+   returns 1 on success, 0 on failure */
21 i8 chunk_section_mesh_create(ChunkSection* section);
22 
23 /* destroy a chunk sections mesh */
+1, -1
1@@ -35,7 +35,7 @@ sources = [
2 	'source/net/mc_buffer.c',
3 	'source/net/mc_client.c',
4 	'source/net/mc_crypto.c',
5-	'source/net/mc_packet.c',
6+	'source/net/packet.c',
7 	'vendor/stb_image_c89.c',
8 	'vendor/json.c',
9 ]
+1, -1
1@@ -52,7 +52,7 @@ void player_server_handle_position(Player* player, MGCamera* cam, const MCPacket
2 	cam->yaw = MG_AngleDeg(player->yaw - 180.0f);
3 	cam->pitch = MG_AngleDeg(-player->pitch);
4 }
5-
6+ 
7 void player_server_send_position(Player* player, MGCamera* cam, MCClient* client)
8 {
9 	static u32 last_send;
R source/net/mc_packet.c => source/net/packet.c
+0, -0