commit 4fc8077

uint  ·  2026-08-03 12:56:23 +0000 UTC
parent 08bfa97
remove SDL dependancy from main

added:
  platform_get_mouse_state
  platform_set_mouse_relative
  platform_wait
4 files changed,  +27, -5
+9, -0
 1@@ -24,6 +24,9 @@ typedef struct {
 2 /* get drawable screen size. usually different due to hi-dpi options */
 3 void platform_get_drawable_size(MGContext* ctx, i32* width, i32* height);
 4 
 5+/* store mouse position in x and y */
 6+void platform_get_mouse_state(i32* x, i32* y);
 7+
 8 /* get time from initialisation of windowing backend */
 9 u64 platform_get_ticks(void);
10 
11@@ -39,10 +42,16 @@ i32 platform_poll(MGContext* ctx);
12 /* present next buffer to screen */
13 void platform_present(MGContext* ctx);
14 
15+/* enable or disable relative mouse mode */
16+void platform_set_mouse_relative(i8 enabled);
17+
18 /* shutdown `ctx` */
19 void platform_shutdown(MGContext* ctx);
20 
21 /* create window */
22 void platform_window_create(MGContext* ctx);
23 
24+/* delay for specified ms */
25+void platform_wait(u32 ms);
26+
27 #endif /* PLATFORM_H */
+0, -2
1@@ -1,5 +1,3 @@
2-#include <SDL2/SDL.h>
3-
4 #include "mgmath.h"
5 #include "util.h"
6 #include "client/player.h"
+3, -3
 1@@ -53,7 +53,7 @@ static void input(void)
 2 
 3 	move = MG_MulV3F(move, mg_config.temp_movement_speed * dt);
 4 	camera_move(&cam, move);
 5-	SDL_GetRelativeMouseState(&mx, &my);
 6+	platform_get_mouse_state(&mx, &my);
 7 	camera_rotate(&cam, mx * sensitivity, -my * sensitivity);
 8 }
 9 
10@@ -87,7 +87,7 @@ int main(int argc, char** argv)
11 	platform_window_create(&ctx);
12 	renderer_create(&ctx);
13 	test_scene_create(&player, client != NULL);
14-	SDL_SetRelativeMouseMode(SDL_TRUE);
15+	platform_set_mouse_relative(1);
16 
17 	while (platform_poll(&ctx)) {
18 		if (client) {
19@@ -128,7 +128,7 @@ int main(int argc, char** argv)
20 
21 		renderer_end();
22 		platform_present(&ctx);
23-		SDL_Delay(1); /* TODO: replace with target fps */
24+		platform_wait(1);
25 	}
26 
27 	if (client)
+15, -0
 1@@ -41,6 +41,11 @@ void platform_get_drawable_size(MGContext* ctx, i32* width, i32* height)
 2 #endif
 3 }
 4 
 5+void platform_get_mouse_state(i32* x, i32* y)
 6+{
 7+	SDL_GetRelativeMouseState(x, y);
 8+}
 9+
10 u64 platform_get_ticks(void)
11 {
12 	return SDL_GetTicks64();
13@@ -115,6 +120,11 @@ void platform_present(MGContext* ctx)
14 #endif
15 }
16 
17+void platform_set_mouse_relative(i8 enabled)
18+{
19+	SDL_SetRelativeMouseMode(enabled);
20+}
21+
22 void platform_shutdown(MGContext* ctx)
23 {
24 	if (!ctx)
25@@ -173,3 +183,8 @@ void platform_window_create(MGContext* ctx)
26 	SDL_GL_SetSwapInterval(1);
27 #endif
28 }
29+
30+void platform_wait(u32 ms)
31+{
32+	SDL_Delay(ms);
33+}