| F | Toggle flight |
| C | Toggle collision |
| F11 | Toggle fullscreen |
+| F3 | Toggle debug info |
| ESC | Pause / unpause game |
## Dependencies
client/client_node.c
client/client_player.c
client/cube.c
+ client/debug_menu.c
client/facecache.c
client/font.c
client/game.c
sqlite3
)
+execute_process(COMMAND git tag --points-at HEAD
+ OUTPUT_VARIABLE GIT_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+if ("${GIT_VERSION}" STREQUAL "")
+ execute_process(COMMAND git rev-parse --short HEAD
+ OUTPUT_VARIABLE GIT_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+endif()
+
+add_compile_definitions(DRAGONBLOCKS_VERSION="${GIT_VERSION}")
+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_definitions(RELEASE)
endif()
#include "client/client_map.h"
#include "client/client_player.h"
#include "client/cube.h"
+#include "client/debug_menu.h"
#include "client/texture.h"
struct ClientPlayer client_player;
client_player.obj->pos = (v3f32) {client_player.pos.x, client_player.pos.y, client_player.pos.z};
object_transform(client_player.obj);
- client_player_update_info();
+ debug_menu_update_pos();
+ debug_menu_update_humidity();
+ debug_menu_update_temperature();
}
// get absolute player bounding box
}
}
- client_player.info_hud = hud_add((HUDElementDefinition) {
- .type = HUD_TEXT,
- .pos = {-1.0f, -1.0f, 0.0f},
- .offset = {2, 2 + 16 + 2 + 16 + 2},
- .type_def = {
- .text = {
- .text = "",
- .color = {1.0f, 1.0f, 1.0f},
- },
- },
- });
-
pthread_rwlock_rdlock(&client_player.rwlock);
update_pos();
pthread_rwlock_unlock(&client_player.rwlock);
+
+ debug_menu_update_yaw();
+ debug_menu_update_pitch();
}
// jump if possible
pthread_rwlock_unlock(&client_player.rwlock);
}
-
-// update HUD info text
-void client_player_update_info()
-{
- v3s32 node_pos = {client_player.pos.x, client_player.pos.y, client_player.pos.z};
-
- char info_text[BUFSIZ];
- sprintf(info_text, "(%.1f %.1f %.1f) humidity: %.2f temperature: %.2f flight: %s collision: %s", client_player.pos.x, client_player.pos.y, client_player.pos.z, get_humidity(node_pos), get_temperature(node_pos), client_player.fly ? "enabled" : "disabled", client_player.collision ? "enabled" : "disabled");
-
- hud_change_text(client_player.info_hud, info_text);
-}
--- /dev/null
+#include <stdio.h>
+#include <GL/glew.h>
+#include <GL/gl.h>
+#include "environment.h"
+#include "client/client_player.h"
+#include "client/debug_menu.h"
+#include "client/hud.h"
+#include "client/window.h"
+
+typedef enum
+{
+ DME_VERSION,
+ DME_FPS,
+ DME_POS,
+ DME_YAW,
+ DME_PITCH,
+ DME_HUMIDITY,
+ DME_TEMPERATURE,
+ DME_FLIGHT,
+ DME_COLLISION,
+ DME_FULLSCREEN,
+ DME_OPENGL,
+ DME_GPU,
+ DME_GLSL,
+ DME_COUNT,
+} DebugMenuEntry;
+
+static HUDElement *huds[DME_COUNT] = {NULL};
+
+static bool debug_menu_enabled = true;
+static DebugMenuEntry last_always_visible = DME_POS;
+
+void debug_menu_init()
+{
+ s32 offset = -16;
+
+ for (DebugMenuEntry i = 0; i < DME_COUNT; i++) {
+ huds[i] = hud_add((HUDElementDefinition) {
+ .type = HUD_TEXT,
+ .pos = {-1.0f, -1.0f, 0.0f},
+ .offset = {2, offset += 18},
+ .type_def = {
+ .text = {
+ .text = "",
+ .color = {1.0f, 1.0f, 1.0f},
+ },
+ },
+ });
+ }
+}
+
+void debug_menu_toggle()
+{
+ debug_menu_enabled = ! debug_menu_enabled;
+
+ for (DebugMenuEntry i = 0; i < DME_COUNT; i++)
+ huds[i]->visible = debug_menu_enabled || i <= last_always_visible;
+}
+
+void debug_menu_update_version()
+{
+ hud_change_text(huds[DME_VERSION], "Dragonblocks Alpha " DRAGONBLOCKS_VERSION);
+}
+
+void debug_menu_update_fps(int fps)
+{
+ char text[BUFSIZ];
+ sprintf(text, "%d FPS", fps);
+ hud_change_text(huds[DME_FPS], text);
+}
+
+void debug_menu_update_pos()
+{
+ char text[BUFSIZ];
+ sprintf(text, "(%.1f %.1f %.1f)", client_player.pos.x, client_player.pos.y, client_player.pos.z);
+ hud_change_text(huds[DME_POS], text);
+}
+
+void debug_menu_update_yaw()
+{
+ char text[BUFSIZ];
+ sprintf(text, "yaw = %.1f", client_player.yaw / M_PI * 180.0);
+ hud_change_text(huds[DME_YAW], text);
+}
+
+void debug_menu_update_pitch()
+{
+ char text[BUFSIZ];
+ sprintf(text, "pitch = %.1f", client_player.pitch / M_PI * 180.0);
+ hud_change_text(huds[DME_PITCH], text);
+}
+
+void debug_menu_update_humidity()
+{
+ char text[BUFSIZ];
+ sprintf(text, "humidity = %.2f", get_humidity((v3s32) {client_player.pos.x, client_player.pos.y, client_player.pos.z}));
+ hud_change_text(huds[DME_HUMIDITY], text);
+}
+
+void debug_menu_update_temperature()
+{
+ char text[BUFSIZ];
+ sprintf(text, "temperature = %.2f", get_temperature((v3s32) {client_player.pos.x, client_player.pos.y, client_player.pos.z}));
+ hud_change_text(huds[DME_TEMPERATURE], text);
+}
+
+void debug_menu_update_flight()
+{
+ char text[BUFSIZ];
+ sprintf(text, "flight: %s", client_player.fly ? "enabled" : "disabled");
+ hud_change_text(huds[DME_FLIGHT], text);
+}
+
+void debug_menu_update_collision()
+{
+ char text[BUFSIZ];
+ sprintf(text, "collision: %s", client_player.collision ? "enabled" : "disabled");
+ hud_change_text(huds[DME_COLLISION], text);
+}
+
+void debug_menu_update_fullscreen()
+{
+ char text[BUFSIZ];
+ sprintf(text, "fullscreen: %s", window.fullscreen ? "enabled" : "disabled");
+ hud_change_text(huds[DME_FULLSCREEN], text);
+}
+
+void debug_menu_update_opengl()
+{
+ char text[BUFSIZ];
+ sprintf(text, "OpenGL %s", glGetString(GL_VERSION));
+ hud_change_text(huds[DME_OPENGL], text);
+}
+
+void debug_menu_update_gpu()
+{
+ char text[BUFSIZ];
+ sprintf(text, "%s", glGetString(GL_RENDERER));
+ hud_change_text(huds[DME_GPU], text);
+}
+
+void debug_menu_update_glsl()
+{
+ char text[BUFSIZ];
+ sprintf(text, "GLSL %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
+ hud_change_text(huds[DME_GLSL], text);
+}
+
--- /dev/null
+#ifndef _DEBUG_MENU_H_
+#define _DEBUG_MENU_H_
+
+#include <stdbool.h>
+
+void debug_menu_init();
+void debug_menu_toggle();
+
+void debug_menu_update_version();
+void debug_menu_update_fps(int fps);
+void debug_menu_update_pos();
+void debug_menu_update_yaw();
+void debug_menu_update_pitch();
+void debug_menu_update_humidity();
+void debug_menu_update_temperature();
+void debug_menu_update_flight();
+void debug_menu_update_collision();
+void debug_menu_update_fullscreen();
+void debug_menu_update_opengl();
+void debug_menu_update_gpu();
+void debug_menu_update_glsl();
+
+#endif
}
}
-Font *font_create(char *text)
+Font *font_create(const char *text)
{
Font *fnt = malloc(sizeof(fnt));
bool font_init();
void font_deinit();
-Font *font_create(char *text);
+Font *font_create(const char *text);
void font_delete(Font *fnt);
void font_render(Font *fnt);
#include "client/client_map.h"
#include "client/client_node.h"
#include "client/client_player.h"
+#include "client/debug_menu.h"
#include "client/hud.h"
#include "client/input.h"
#include "client/font.h"
#include "client/window.h"
#include "signal_handlers.h"
-static void game_loop(Client *client)
+static void crosshair_init()
{
- HUDElement *fps_hud = hud_add((HUDElementDefinition) {
- .type = HUD_TEXT,
- .pos = {-1.0f, -1.0f, 0.0f},
- .offset = {2, 2 + 16 + 2},
+ hud_add((HUDElementDefinition) {
+ .type = HUD_IMAGE,
+ .pos = {0.0f, 0.0f, 0.0f},
+ .offset = {0, 0},
.type_def = {
- .text = {
- .text = "",
- .color = {1.0f, 1.0f, 1.0f},
+ .image = {
+ .texture = texture_get(RESSOURCEPATH "textures/crosshair.png"),
+ .scale = {1.0f, 1.0f},
+ .scale_type = HUD_SCALE_TEXTURE,
},
},
});
+}
+static void game_loop(Client *client)
+{
f64 fps_update_timer = 1.0f;
int frames = 0;
ts_old = ts;
if ((fps_update_timer -= dtime) <= 0.0) {
- char fps[((int) log10(frames) + 1) + 1 + 3 + 1];
- sprintf(fps, "%d FPS", frames);
- hud_change_text(fps_hud, fps);
+ debug_menu_update_fps(frames);
fps_update_timer += 1.0;
frames = 0;
}
hud_on_resize(width, height);
- hud_add((HUDElementDefinition) {
- .type = HUD_IMAGE,
- .pos = {0.0f, 0.0f, 0.0f},
- .offset = {0, 0},
- .type_def = {
- .image = {
- .texture = texture_get(RESSOURCEPATH "textures/crosshair.png"),
- .scale = {1.0f, 1.0f},
- .scale_type = HUD_SCALE_TEXTURE,
- },
- },
- });
-
- hud_add((HUDElementDefinition) {
- .type = HUD_TEXT,
- .pos = {-1.0f, -1.0f, 0.0f},
- .offset = {2, 2},
- .type_def = {
- .text = {
- .text = "Dragonblocks Alpha", // ToDo: add version
- .color = {1.0f, 1.0f, 1.0f},
- },
- },
- });
+ debug_menu_init();
+ debug_menu_toggle();
+ debug_menu_update_fps(0);
+ debug_menu_update_version();
+ debug_menu_update_flight();
+ debug_menu_update_collision();
+ debug_menu_update_fullscreen();
+ debug_menu_update_opengl();
+ debug_menu_update_gpu();
+ debug_menu_update_glsl();
+
+ crosshair_init();
input_init();
return element;
}
-void hud_change_text(HUDElement *element, char *text)
+void hud_change_text(HUDElement *element, const char *text)
{
if (strcmp(element->def.type_def.text.text, text)) {
element->def.type_def.text.text = strdup(text);
void hud_on_resize(int width, int height);
void hud_render();
HUDElement *hud_add(HUDElementDefinition def);
-void hud_change_text(HUDElement *element, char *text);
+void hud_change_text(HUDElement *element, const char *text);
#endif
#include "client/camera.h"
#include "client/client.h"
#include "client/client_player.h"
+#include "client/debug_menu.h"
#include "client/hud.h"
#include "client/input.h"
#include "client/window.h"
KeyListener fullscreen_listener;
KeyListener fly_listener;
KeyListener collision_listener;
+ KeyListener debug_menu_listener;
} input;
void input_on_cursor_pos(double current_x, double current_y)
client_player.yaw += (f32) delta_x * M_PI / 180.0f / 8.0f;
client_player.pitch -= (f32) delta_y * M_PI / 180.0f / 8.0f;
+ client_player.yaw = fmod(client_player.yaw + M_PI * 2.0f, M_PI * 2.0f);
client_player.pitch = fmax(fmin(client_player.pitch, M_PI / 2.0f - 0.01f), -M_PI / 2.0f + 0.01f);
camera_set_angle(client_player.yaw, client_player.pitch);
+
+ debug_menu_update_yaw();
+ debug_menu_update_pitch();
}
static bool move(int forward, int backward, vec3 dir)
{
do_key_listener(&input.pause_listener);
do_key_listener(&input.fullscreen_listener);
- do_key_listener(&input.fly_listener);
- do_key_listener(&input.collision_listener);
if (input.pause_listener.fired) {
input.paused = ! input.paused;
window_enter_fullscreen();
}
- if (input.fly_listener.fired) {
- client_player.fly = ! client_player.fly;
- client_player_update_info();
- }
+ if (! input.paused) {
+ do_key_listener(&input.fly_listener);
+ do_key_listener(&input.collision_listener);
+ do_key_listener(&input.debug_menu_listener);
+
+ if (input.fly_listener.fired) {
+ client_player.fly = ! client_player.fly;
+ debug_menu_update_flight();
+ }
+
+ if (input.collision_listener.fired) {
+ client_player.collision = ! client_player.collision;
+ debug_menu_update_collision();
+ }
- if (input.collision_listener.fired) {
- client_player.collision = ! client_player.collision;
- client_player_update_info();
+ if (input.debug_menu_listener.fired)
+ debug_menu_toggle();
}
client_player.velocity.x = 0.0f;
input.fullscreen_listener = create_key_listener(GLFW_KEY_F11);
input.fly_listener = create_key_listener(GLFW_KEY_F);
input.collision_listener = create_key_listener(GLFW_KEY_C);
+ input.debug_menu_listener = create_key_listener(GLFW_KEY_F3);
input.pause_menu_hud = hud_add((HUDElementDefinition) {
.type = HUD_IMAGE,
#include <stdio.h>
#include <GL/glew.h>
#include <GL/gl.h>
+#include "client/debug_menu.h"
#include "client/hud.h"
#include "client/input.h"
#include "client/scene.h"
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
+
+ debug_menu_update_fullscreen();
}
void window_exit_fullscreen()
{
window.fullscreen = false;
glfwSetWindowMonitor(window.handle, NULL, window.small_bounds.x, window.small_bounds.y, window.small_bounds.width, window.small_bounds.height, 0);
+
+ debug_menu_update_fullscreen();
}
bool window_init(int width, int height)