summaryrefslogtreecommitdiffstats
path: root/game/client/toggles.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-03-21 18:16:40 +0500
committeruntodesu <kirill@untode.su>2025-03-21 18:16:40 +0500
commit9f80a278a6f188c8e9131df0684bad14a07491ee (patch)
tree067c6ad4b892a34c3c03e3ecdbe312453bd46ea4 /game/client/toggles.cc
parentfddd7f761176bb45cfdd41eeccaeadac22d33ddf (diff)
downloadvoxelius-9f80a278a6f188c8e9131df0684bad14a07491ee.tar.bz2
voxelius-9f80a278a6f188c8e9131df0684bad14a07491ee.zip
Toggles system rework, added flight pmove mode
- Reworked toggles to use a constant-styled enumerations - Added TOGGLE_PM_FLIGHT and an according movement mode. Now server-side just doesn't simulate gravity altogether for players, instead relying on whatever the client provides which works fine for now. Closes #12
Diffstat (limited to 'game/client/toggles.cc')
-rw-r--r--game/client/toggles.cc140
1 files changed, 96 insertions, 44 deletions
diff --git a/game/client/toggles.cc b/game/client/toggles.cc
index 7e20875..105b0d2 100644
--- a/game/client/toggles.cc
+++ b/game/client/toggles.cc
@@ -10,38 +10,37 @@
#include "client/globals.hh"
#include "client/language.hh"
-bool toggles::is_sequence_await = false;
+struct ToggleInfo final {
+ const char *description;
+ int glfw_keycode;
+ bool is_enabled;
+};
-bool toggles::draw_chunk_borders = false;
-bool toggles::render_fullbright = false;
-bool toggles::render_wireframe = false;
+bool toggles::is_sequence_await = false;
-#if defined(NDEBUG)
-bool toggles::draw_metrics = false;
-#else
-bool toggles::draw_metrics = true;
-#endif
+static ToggleInfo toggle_infos[TOGGLE_COUNT];
-static void toggle_value(bool *value, const char *description)
+static void print_toggle_state(const ToggleInfo &info)
{
- value[0] = !value[0];
-
- if(description) {
- if(value[0])
- client_chat::print(fmt::format("[debug] {} ON", description));
- else client_chat::print(fmt::format("[debug] {} OFF", description));
+ if(info.description) {
+ if(info.is_enabled)
+ client_chat::print(fmt::format("[toggles] {} ON", info.description));
+ else client_chat::print(fmt::format("[toggles] {} OFF", info.description));
}
}
-static void toggle_value_config(ConfigBoolean &value, const char *description)
+static void toggle_value(ToggleInfo &info, toggle_type type)
{
- value.set_value(!value.get_value());
-
- if(description) {
- if(value.get_value())
- client_chat::print(fmt::format("[debug] {} ON", description));
- else client_chat::print(fmt::format("[debug] {} OFF", description));
+ if(info.is_enabled) {
+ info.is_enabled = false;
+ globals::dispatcher.trigger(ToggleDisabledEvent {type});
}
+ else {
+ info.is_enabled = true;
+ globals::dispatcher.trigger(ToggleEnabledEvent {type});
+ }
+
+ print_toggle_state(info);
}
static void on_glfw_key(const GlfwKeyEvent &event)
@@ -55,43 +54,96 @@ static void on_glfw_key(const GlfwKeyEvent &event)
if(event.key == DEBUG_KEY) {
if(event.action == GLFW_PRESS) {
toggles::is_sequence_await = true;
+ ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
return;
}
if(event.action == GLFW_RELEASE) {
toggles::is_sequence_await = false;
+ ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
return;
}
}
if((event.action == GLFW_PRESS) && toggles::is_sequence_await) {
- switch(event.key) {
- case GLFW_KEY_G:
- toggle_value(&toggles::draw_chunk_borders, "chunk borders");
- return;
- case GLFW_KEY_V:
- toggle_value(&toggles::draw_metrics, nullptr);
- return;
- case GLFW_KEY_J:
- toggle_value(&toggles::render_fullbright, nullptr);
- return;
- case GLFW_KEY_Z:
- toggle_value(&toggles::render_wireframe, "wireframe");
- return;
- case GLFW_KEY_P:
- toggle_value_config(gamepad::active, "gamepad input");
- return;
- case GLFW_KEY_L:
- // This causes the language subsystem
- // to re-parse the JSON file essentially
- // causing the game to soft-reload language
- language::set(language::get_current());
+ if(event.key == GLFW_KEY_L) {
+ // This causes the language subsystem
+ // to re-parse the JSON file essentially
+ // causing the game to soft-reload language
+ language::set(language::get_current());
+ return;
+ }
+
+ for(toggle_type i = 0; i < TOGGLE_COUNT; ++i) {
+ if(event.key == toggle_infos[i].glfw_keycode) {
+ toggle_value(toggle_infos[i], i);
return;
+ }
}
}
}
void toggles::init(void)
{
+ toggle_infos[TOGGLE_WIREFRAME].description = "wireframe";
+ toggle_infos[TOGGLE_WIREFRAME].glfw_keycode = GLFW_KEY_Z;
+ toggle_infos[TOGGLE_WIREFRAME].is_enabled = false;
+
+ toggle_infos[TOGGLE_FULLBRIGHT].description = "fullbright";
+ toggle_infos[TOGGLE_FULLBRIGHT].glfw_keycode = GLFW_KEY_J;
+ toggle_infos[TOGGLE_FULLBRIGHT].is_enabled = false;
+
+ toggle_infos[TOGGLE_CHUNK_AABB].description = "chunk Borders";
+ toggle_infos[TOGGLE_CHUNK_AABB].glfw_keycode = GLFW_KEY_G;
+ toggle_infos[TOGGLE_CHUNK_AABB].is_enabled = false;
+
+ toggle_infos[TOGGLE_METRICS_UI].description = nullptr;
+ toggle_infos[TOGGLE_METRICS_UI].glfw_keycode = GLFW_KEY_V;
+ toggle_infos[TOGGLE_METRICS_UI].is_enabled = false;
+
+ toggle_infos[TOGGLE_USE_GAMEPAD].description = "gamepad input";
+ toggle_infos[TOGGLE_USE_GAMEPAD].glfw_keycode = GLFW_KEY_P;
+ toggle_infos[TOGGLE_USE_GAMEPAD].is_enabled = false;
+
+ toggle_infos[TOGGLE_PM_FLIGHT].description = "flight mode";
+ toggle_infos[TOGGLE_PM_FLIGHT].glfw_keycode = GLFW_KEY_F;
+ toggle_infos[TOGGLE_PM_FLIGHT].is_enabled = false;
+
+#ifndef NDEBUG
+ toggle_infos[TOGGLE_WIREFRAME].is_enabled = true;
+#endif
+
globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
}
+
+void toggles::init_late(void)
+{
+ for(toggle_type i = 0; i < TOGGLE_COUNT; ++i) {
+ if(toggle_infos[i].is_enabled)
+ globals::dispatcher.trigger(ToggleEnabledEvent {i});
+ else globals::dispatcher.trigger(ToggleDisabledEvent {i});
+ }
+}
+
+bool toggles::get(toggle_type type)
+{
+ if(type < TOGGLE_COUNT)
+ return toggle_infos[type].is_enabled;
+ return false;
+}
+
+void toggles::set(toggle_type type, bool value)
+{
+ if(type < TOGGLE_COUNT) {
+ if(value) {
+ toggle_infos[type].is_enabled = true;
+ globals::dispatcher.trigger(ToggleEnabledEvent {type});
+ }
+ else {
+ toggle_infos[type].is_enabled = false;
+ globals::dispatcher.trigger(ToggleDisabledEvent {type});
+ }
+
+ print_toggle_state(toggle_infos[type]);
+ }
+}