]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/debug_menu.c
59002563acebd797f10a0059d5be4379e0dd162a
[dragonblocks_alpha.git] / src / client / debug_menu.c
1 #include <stdio.h>
2 #include <GL/glew.h>
3 #include <GL/gl.h>
4 #include "client/client_player.h"
5 #include "client/debug_menu.h"
6 #include "client/gui.h"
7 #include "client/window.h"
8 #include "day.h"
9 #include "environment.h"
10 #include "perlin.h"
11 #include "version.h"
12
13 typedef enum
14 {
15         DME_VERSION,
16         DME_FPS,
17         DME_POS,
18         DME_YAW,
19         DME_PITCH,
20         DME_TIME,
21         DME_DAYLIGHT,
22         DME_SUN_ANGLE,
23         DME_HUMIDITY,
24         DME_TEMPERATURE,
25         DME_SEED,
26         DME_FLIGHT,
27         DME_COLLISION,
28         DME_TIMELAPSE,
29         DME_FULLSCREEN,
30         DME_OPENGL,
31         DME_GPU,
32         DME_COUNT,
33 } DebugMenuEntry;
34
35 static GUIElement *gui_elements[DME_COUNT] = {NULL};
36
37 static bool debug_menu_enabled = true;
38 static DebugMenuEntry last_always_visible = DME_POS;
39
40 void debug_menu_init()
41 {
42         s32 offset = -16;
43
44         for (DebugMenuEntry i = 0; i < DME_COUNT; i++) {
45                 gui_elements[i] = gui_add(&gui_root, (GUIElementDefinition) {
46                         .pos = {0.0f, 0.0f},
47                         .z_index = 0.1f,
48                         .offset = {2, offset += 18},
49                         .margin = {2, 2},
50                         .align = {0.0f, 0.0f},
51                         .scale = {1.0f, 1.0f},
52                         .scale_type = GST_TEXT,
53                         .affect_parent_scale = false,
54                         .text = "",
55                         .image = NULL,
56                         .text_color = (v4f32) {1.0f, 1.0f, 1.0f, 1.0f},
57                         .bg_color = (v4f32) {0.0f, 0.0f, 0.0f, 0.0f},
58                 });
59         }
60 }
61
62 void debug_menu_toggle()
63 {
64         debug_menu_enabled = ! debug_menu_enabled;
65
66         for (DebugMenuEntry i = 0; i < DME_COUNT; i++) {
67                 gui_elements[i]->visible = debug_menu_enabled || i <= last_always_visible;
68                 gui_elements[i]->def.bg_color.w = debug_menu_enabled ? 0.5f : 0.0f;
69         }
70 }
71
72 void debug_menu_update_version()
73 {
74         char text[BUFSIZ];
75         sprintf(text, "Dragonblocks Alpha %s", VERSION);
76         gui_set_text(gui_elements[DME_VERSION], text);
77 }
78
79 void debug_menu_update_fps(int fps)
80 {
81         char text[BUFSIZ];
82         sprintf(text, "%d FPS", fps);
83         gui_set_text(gui_elements[DME_FPS], text);
84 }
85
86 void debug_menu_update_pos()
87 {
88         char text[BUFSIZ];
89         sprintf(text, "(%.1f %.1f %.1f)", client_player.pos.x, client_player.pos.y, client_player.pos.z);
90         gui_set_text(gui_elements[DME_POS], text);
91 }
92
93 void debug_menu_update_yaw()
94 {
95         char text[BUFSIZ];
96         sprintf(text, "yaw = %.1f", client_player.yaw / M_PI * 180.0);
97         gui_set_text(gui_elements[DME_YAW], text);
98 }
99
100 void debug_menu_update_pitch()
101 {
102         char text[BUFSIZ];
103         sprintf(text, "pitch = %.1f", client_player.pitch / M_PI * 180.0);
104         gui_set_text(gui_elements[DME_PITCH], text);
105 }
106
107 void debug_menu_update_time()
108 {
109         int hours, minutes;
110         split_time_of_day(&hours, &minutes);
111
112         char text[BUFSIZ];
113         sprintf(text, "%02d:%02d", hours, minutes);
114         gui_set_text(gui_elements[DME_TIME], text);
115 }
116
117 void debug_menu_update_daylight()
118 {
119         char text[BUFSIZ];
120         sprintf(text, "daylight = %.2f", get_daylight());
121         gui_set_text(gui_elements[DME_DAYLIGHT], text);
122 }
123
124 void debug_menu_update_sun_angle()
125 {
126         char text[BUFSIZ];
127         sprintf(text, "sun angle = %.1f", fmod(get_sun_angle() / M_PI * 180.0, 360.0));
128         gui_set_text(gui_elements[DME_SUN_ANGLE], text);
129 }
130
131 void debug_menu_update_humidity()
132 {
133         char text[BUFSIZ];
134         sprintf(text, "humidity = %.2f", get_humidity((v3s32) {client_player.pos.x, client_player.pos.y, client_player.pos.z}));
135         gui_set_text(gui_elements[DME_HUMIDITY], text);
136 }
137
138 void debug_menu_update_temperature()
139 {
140         char text[BUFSIZ];
141         sprintf(text, "temperature = %.2f", get_temperature((v3s32) {client_player.pos.x, client_player.pos.y, client_player.pos.z}));
142         gui_set_text(gui_elements[DME_TEMPERATURE], text);
143 }
144
145 void debug_menu_update_seed()
146 {
147         char text[BUFSIZ];
148         sprintf(text, "seed = %d", seed);
149         gui_set_text(gui_elements[DME_SEED], text);
150 }
151
152 void debug_menu_update_flight()
153 {
154         char text[BUFSIZ];
155         sprintf(text, "flight: %s", client_player.fly ? "enabled" : "disabled");
156         gui_set_text(gui_elements[DME_FLIGHT], text);
157 }
158
159 void debug_menu_update_collision()
160 {
161         char text[BUFSIZ];
162         sprintf(text, "collision: %s", client_player.collision ? "enabled" : "disabled");
163         gui_set_text(gui_elements[DME_COLLISION], text);
164 }
165
166 void debug_menu_update_timelapse()
167 {
168         char text[BUFSIZ];
169         sprintf(text, "timelapse: %s", timelapse ? "enabled" : "disabled");
170         gui_set_text(gui_elements[DME_TIMELAPSE], text);
171 }
172
173 void debug_menu_update_fullscreen()
174 {
175         char text[BUFSIZ];
176         sprintf(text, "fullscreen: %s", window.fullscreen ? "enabled" : "disabled");
177         gui_set_text(gui_elements[DME_FULLSCREEN], text);
178 }
179
180 void debug_menu_update_opengl()
181 {
182         char text[BUFSIZ];
183         sprintf(text, "OpenGL %s", glGetString(GL_VERSION));
184         gui_set_text(gui_elements[DME_OPENGL], text);
185 }
186
187 void debug_menu_update_gpu()
188 {
189         char text[BUFSIZ];
190         sprintf(text, "%s", glGetString(GL_RENDERER));
191         gui_set_text(gui_elements[DME_GPU], text);
192 }