From 59ee7caf427f20adbac45428604d3584e516e466 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 27 Mar 2022 19:29:28 +0200 Subject: [PATCH] Cleanup --- src/client/component/chat.cpp | 95 --------------------- src/client/component/chat.hpp | 6 -- src/client/component/command.cpp | 10 +-- src/client/component/config.cpp | 24 ------ src/client/component/fps.cpp | 1 - src/client/component/gui_asset_list.cpp | 31 ++++--- src/client/component/gui_console.cpp | 17 ++-- src/client/component/gui_debug.cpp | 9 +- src/client/component/gui_entity_list.cpp | 10 ++- src/client/component/gui_script_console.cpp | 4 +- src/client/component/ui_scripting.cpp | 1 - src/client/component/updater.cpp | 10 --- src/client/game/scripting/lua/context.cpp | 4 +- 13 files changed, 41 insertions(+), 181 deletions(-) delete mode 100644 src/client/component/chat.cpp delete mode 100644 src/client/component/chat.hpp delete mode 100644 src/client/component/config.cpp diff --git a/src/client/component/chat.cpp b/src/client/component/chat.cpp deleted file mode 100644 index 4520436a..00000000 --- a/src/client/component/chat.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include "loader/component_loader.hpp" - -#include "game/game.hpp" -#include "game/dvars.hpp" - -#include "chat.hpp" -#include "scheduler.hpp" - -#include -#include - -#define chat_font game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25) - -namespace chat -{ - namespace - { - struct message - { - std::string text; - std::chrono::steady_clock::time_point time; - }; - - std::deque history; - - float color_white[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - - float screen_max[2]; - - void check_resize() - { - screen_max[0] = game::ScrPlace_GetViewPlacement()->realViewportSize[0]; - screen_max[1] = game::ScrPlace_GetViewPlacement()->realViewportSize[1]; - } - - float relative(float value) - { - const auto ratio = screen_max[0] / 2560.f; - - return value * ratio; - } - - void draw_chat() - { - check_resize(); - - const auto now = std::chrono::high_resolution_clock::now(); - - for (auto i = 0; i < std::min(15, (int)history.size()); i++) - { - if (now - history[i].time > 11s) - { - return; - } - - const auto diff = now - history[i].time; - - float color[4] = { color_white[0], color_white[1], color_white[2], 1.f }; - - if (diff > 10.5s) - { - const auto milliseconds = (float)(11000 - std::chrono::duration_cast(diff).count()); - - color[3] = (float)(milliseconds / 500.f); - } - - game::R_AddCmdDrawText(history[i].text.data(), 0x7FFFFFFF, chat_font, relative(15.f), relative(600.f + i * 25), 1.f, 1.f, 0.f, color, 0); - } - } - } - - void print(const std::string& msg) - { - message m; - m.text = msg; - m.time = std::chrono::high_resolution_clock::now(); - - history.push_front(m); - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - scheduler::loop([]() - { - draw_chat(); - }, scheduler::pipeline::renderer); - } - }; -} - -REGISTER_COMPONENT(chat::component) diff --git a/src/client/component/chat.hpp b/src/client/component/chat.hpp deleted file mode 100644 index d1428459..00000000 --- a/src/client/component/chat.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace chat -{ - void print(const std::string& msg); -} \ No newline at end of file diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index d5737946..6fba69f6 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -9,7 +9,6 @@ #include "command.hpp" #include "scheduler.hpp" #include "game_console.hpp" -#include "chat.hpp" #include "fastfiles.hpp" #include @@ -116,7 +115,9 @@ namespace command const auto command = utils::string::to_lower(name); if (handlers.find(command) == handlers.end()) + { add_raw(name, main_handler); + } handlers[command] = callback; } @@ -168,11 +169,6 @@ namespace command utils::hook::invoke(0x1406B3AA0, map, 0, 0, 0, 0); }); - add("say", [](const params& params) - { - chat::print(params.join(1)); - }); - add("listassetpool", [](const params& params) { if (params.size() < 2) @@ -408,7 +404,7 @@ namespace command try { - const scripting::entity player = scripting::call("getentbynum", {0}).as(); + const auto player = scripting::call("getentbynum", {0}).as(); if (weapon == "all"s) { player.call("takeallweapons"); diff --git a/src/client/component/config.cpp b/src/client/component/config.cpp deleted file mode 100644 index 26ecc7b6..00000000 --- a/src/client/component/config.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include "loader/component_loader.hpp" - -#include "game/game.hpp" -#include "game/dvars.hpp" - -#include "command.hpp" -#include "game_console.hpp" - -#include - -namespace config -{ - class component final : public component_interface - { - public: - void post_unpack() override - { - dvars::register_bool("cg_autoUpdate", true, game::DvarFlags::DVAR_FLAG_SAVED); - } - }; -} - -REGISTER_COMPONENT(config::component) diff --git a/src/client/component/fps.cpp b/src/client/component/fps.cpp index e2761b29..8233908e 100644 --- a/src/client/component/fps.cpp +++ b/src/client/component/fps.cpp @@ -4,7 +4,6 @@ #include "game/game.hpp" #include "game/dvars.hpp" -#include "chat.hpp" #include "scheduler.hpp" #include "command.hpp" diff --git a/src/client/component/gui_asset_list.cpp b/src/client/component/gui_asset_list.cpp index b8a02ef3..c4989191 100644 --- a/src/client/component/gui_asset_list.cpp +++ b/src/client/component/gui_asset_list.cpp @@ -22,32 +22,31 @@ namespace asset_list void on_frame() { - if (!gui::enabled_menus["asset_list"]) + static auto* enabled = &gui::enabled_menus["asset_list"]; + if (!*enabled) { return; } + ImGui::Begin("Asset list", enabled); + + ImGui::InputText("asset type", &asset_type_filter); + ImGui::BeginChild("asset type list"); + + for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++) { - ImGui::Begin("Asset list", &gui::enabled_menus["asset_list"]); + const auto name = game::g_assetNames[i]; + const auto type = static_cast(i); - ImGui::InputText("asset type", &asset_type_filter); - ImGui::BeginChild("asset type list"); - - for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++) + if (utils::string::find_lower(name, asset_type_filter)) { - const auto name = game::g_assetNames[i]; - const auto type = static_cast(i); - - if (utils::string::find_lower(name, asset_type_filter)) - { - ImGui::Checkbox(name, &shown_assets[type]); - } + ImGui::Checkbox(name, &shown_assets[type]); } - - ImGui::EndChild(); - ImGui::End(); } + ImGui::EndChild(); + ImGui::End(); + for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++) { const auto name = game::g_assetNames[i]; diff --git a/src/client/component/gui_console.cpp b/src/client/component/gui_console.cpp index 452bf557..13943c7a 100644 --- a/src/client/component/gui_console.cpp +++ b/src/client/component/gui_console.cpp @@ -13,7 +13,7 @@ #include #include -namespace gui_console +namespace gui::console { namespace { @@ -52,7 +52,7 @@ namespace gui_console } case ImGuiInputTextFlags_CallbackHistory: { - const auto history = game_console::get_history(); + const auto& history = game_console::get_history(); if (data->EventKey == ImGuiKey_UpArrow) { @@ -96,7 +96,7 @@ namespace gui_console { std::string text{}; - const auto output = game_console::get_output(); + const auto& output = game_console::get_output(); for (const auto& line : output) { if (utils::string::find_lower(line, filter)) @@ -116,7 +116,8 @@ namespace gui_console void on_frame() { - if (!gui::enabled_menus["console"]) + static auto* enabled = &gui::enabled_menus["console"]; + if (!*enabled) { return; } @@ -126,7 +127,7 @@ namespace gui_console static const auto input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; - ImGui::Begin("Console", &gui::enabled_menus["console"]); + ImGui::Begin("Console", enabled); if (ImGui::BeginPopup("Options")) { @@ -159,7 +160,7 @@ namespace gui_console ImGui::BeginChild("console_scroll", ImVec2(0, -footer_height_to_reserve), false); - const auto output = game_console::get_output(); + const auto& output = game_console::get_output(); for (const auto& line : output) { if (utils::string::find_lower(line, filter)) @@ -177,7 +178,7 @@ namespace gui_console if (ImGui::InputText("Input", &input, input_text_flags, input_text_edit)) { - auto history = game_console::get_history(); + auto& history = game_console::get_history(); if (history_index != -1) { @@ -209,4 +210,4 @@ namespace gui_console }; } -REGISTER_COMPONENT(gui_console::component) +REGISTER_COMPONENT(gui::console::component) diff --git a/src/client/component/gui_debug.cpp b/src/client/component/gui_debug.cpp index 18062b8a..80233264 100644 --- a/src/client/component/gui_debug.cpp +++ b/src/client/component/gui_debug.cpp @@ -16,7 +16,7 @@ #include #include -namespace gui_debug +namespace gui::debug { namespace { @@ -403,12 +403,13 @@ namespace gui_debug void draw_window() { - if (!gui::enabled_menus["debug"]) + static auto* enabled = &gui::enabled_menus["debug"]; + if (!*enabled) { return; } - ImGui::Begin("Debug", &gui::enabled_menus["debug"]); + ImGui::Begin("Debug", enabled); if (ImGui::TreeNode("Path nodes")) { @@ -724,4 +725,4 @@ namespace gui_debug }; } -REGISTER_COMPONENT(gui_debug::component) +REGISTER_COMPONENT(gui::debug::component) diff --git a/src/client/component/gui_entity_list.cpp b/src/client/component/gui_entity_list.cpp index 40eddb62..cd991e8c 100644 --- a/src/client/component/gui_entity_list.cpp +++ b/src/client/component/gui_entity_list.cpp @@ -15,7 +15,7 @@ #include #include -namespace entity_list +namespace gui::entity_list { namespace { @@ -593,8 +593,9 @@ namespace entity_list void show_entity_list_window(data_t& data) { + static auto* enabled = &gui::enabled_menus["entity_list"]; ImGui::SetNextWindowSizeConstraints(ImVec2(500, 500), ImVec2(1000, 1000)); - ImGui::Begin("Entity list", &gui::enabled_menus["entity_list"]); + ImGui::Begin("Entity list", enabled); if (ImGui::Button("Update list")) { @@ -808,7 +809,8 @@ namespace entity_list void on_frame() { - if (!gui::enabled_menus["entity_list"]) + static auto* enabled = &gui::enabled_menus["entity_list"]; + if (!*enabled) { return; } @@ -858,4 +860,4 @@ namespace entity_list }; } -REGISTER_COMPONENT(entity_list::component) +REGISTER_COMPONENT(gui::entity_list::component) diff --git a/src/client/component/gui_script_console.cpp b/src/client/component/gui_script_console.cpp index ca4442ce..4d667de5 100644 --- a/src/client/component/gui_script_console.cpp +++ b/src/client/component/gui_script_console.cpp @@ -15,7 +15,7 @@ #include #include -namespace gui_script_console +namespace gui::script_console { namespace { @@ -228,4 +228,4 @@ namespace gui_script_console }; } -REGISTER_COMPONENT(gui_script_console::component) +REGISTER_COMPONENT(gui::script_console::component) diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 862277e7..ee6d4831 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -4,7 +4,6 @@ #include "game/game.hpp" #include "game/dvars.hpp" -#include "chat.hpp" #include "scheduler.hpp" #include "command.hpp" diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index fe6ac7e4..2bb6e19e 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -70,16 +70,6 @@ namespace updater return main; } - std::string get_data_path() - { - if (GIT_BRANCH == "develop"s) - { - return DATA_PATH_DEV; - } - - return DATA_PATH; - } - void set_update_check_status(bool done, bool success, const std::string& error = {}) { update_data.access([done, success, error](update_data_t& data_) diff --git a/src/client/game/scripting/lua/context.cpp b/src/client/game/scripting/lua/context.cpp index 06b61680..f35bf522 100644 --- a/src/client/game/scripting/lua/context.cpp +++ b/src/client/game/scripting/lua/context.cpp @@ -9,7 +9,6 @@ #include "../../../component/notifies.hpp" #include "../../../component/scripting.hpp" #include "../../../component/command.hpp" -#include "../../../component/chat.hpp" #include "../../../component/fastfiles.hpp" #include @@ -377,9 +376,8 @@ namespace scripting::lua command::execute(utils::string::va("setdiscordstate %s", state.data()), false); }; - game_type["say"] = [](const game&, const std::string& msg) + game_type["say"] = [](const game&) { - chat::print(msg); }; game_type["detour"] = [](const game&, const sol::this_state s, const std::string& filename,