5 #include <GLFW/glfw3.h>
6 #include "client/camera.h"
7 #include "client/client.h"
8 #include "client/client_map.h"
9 #include "client/client_node.h"
10 #include "client/client_player.h"
11 #include "client/debug_menu.h"
12 #include "client/hud.h"
13 #include "client/input.h"
14 #include "client/font.h"
15 #include "client/window.h"
16 #include "signal_handlers.h"
18 static void crosshair_init()
20 hud_add((HUDElementDefinition) {
22 .pos = {0.0f, 0.0f, 0.0f},
26 .texture = texture_get(RESSOURCEPATH "textures/crosshair.png"),
27 .scale = {1.0f, 1.0f},
28 .scale_type = HUD_SCALE_TEXTURE,
34 static void game_loop(Client *client)
36 f64 fps_update_timer = 1.0f;
39 struct timespec ts, ts_old;
40 clock_gettime(CLOCK_REALTIME, &ts_old);
42 while (! glfwWindowShouldClose(window.handle) && client->state != CS_DISCONNECTED && ! interrupted) {
43 clock_gettime(CLOCK_REALTIME, &ts);
44 f64 dtime = (f64) (ts.tv_sec - ts_old.tv_sec) + (f64) (ts.tv_nsec - ts_old.tv_nsec) / 1.0e9;
47 if ((fps_update_timer -= dtime) <= 0.0) {
48 debug_menu_update_fps(frames);
49 fps_update_timer += 1.0;
55 glEnable(GL_DEPTH_TEST);
56 glEnable(GL_ALPHA_TEST);
58 glEnable(GL_MULTISAMPLE);
59 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
60 glAlphaFunc(GL_GREATER, 0.0f);
61 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
62 glClearColor(0.52941176470588f, 0.8078431372549f, 0.92156862745098f, 1.0f);
65 client_player_tick(dtime);
70 glfwSwapBuffers(window.handle);
75 bool game(Client *client)
81 if (! window_init(width, height))
90 scene_on_resize(width, height);
95 camera_set_position((v3f32) {0.0f, 0.0f, 0.0f});
96 camera_set_angle(0.0f, 0.0f);
101 hud_on_resize(width, height);
105 debug_menu_update_fps(0);
106 debug_menu_update_version();
107 debug_menu_update_flight();
108 debug_menu_update_collision();
109 debug_menu_update_fullscreen();
110 debug_menu_update_opengl();
111 debug_menu_update_gpu();
112 debug_menu_update_glsl();
118 client_player_add_to_scene();