1
0
mirror of synced 2024-09-24 11:38:26 +02:00

impr: Optimize includes in often used header files

This commit is contained in:
WerWolv 2023-11-18 14:34:33 +01:00
parent 98e0a62e6e
commit 1249eb3261
29 changed files with 123 additions and 81 deletions

View File

@ -4,8 +4,6 @@
#include <hex/helpers/concepts.hpp>
#include <pl/pattern_language.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <functional>
#include <map>
@ -27,6 +25,7 @@ namespace hex {
class View;
class LanguageDefinition;
class Shortcut;
namespace dp {
class Node;
@ -625,7 +624,8 @@ namespace hex {
struct MenuItem {
std::vector<std::string> unlocalizedNames;
Shortcut shortcut;
std::unique_ptr<Shortcut> shortcut;
View *view;
MenuCallback callback;
EnabledCallback enabledCallback;
};
@ -734,6 +734,9 @@ namespace hex {
void addProviderName(const std::string &unlocalizedName);
using ProviderCreationFunction = prv::Provider*(*)();
void add(const std::string &typeName, ProviderCreationFunction creationFunction);
std::vector<std::string> &getEntries();
}
@ -747,15 +750,8 @@ namespace hex {
void add(bool addToList = true) {
auto typeName = T().getTypeName();
(void)EventManager::subscribe<RequestCreateProvider>([expectedName = typeName](const std::string &name, bool skipLoadInterface, bool selectProvider, prv::Provider **provider) {
if (name != expectedName) return;
prv::Provider *newProvider = new T();
ImHexApi::Provider::add(newProvider, skipLoadInterface, selectProvider);
if (provider != nullptr)
*provider = newProvider;
impl::add(typeName, [] -> prv::Provider* {
return new T();
});
if (addToList)

View File

@ -7,8 +7,6 @@
#include <vector>
#include <map>
#include <hex/api/keybinding.hpp>
#include <wolv/io/fs.hpp>
using ImGuiID = unsigned int;

View File

@ -443,12 +443,12 @@ namespace hex {
static void resumeShortcuts();
static void pauseShortcuts();
static std::optional<Shortcut> getPreviousShortcut();
[[nodiscard]] static std::optional<Shortcut> getPreviousShortcut();
static std::vector<ShortcutEntry> getGlobalShortcuts();
static std::vector<ShortcutEntry> getViewShortcuts(View *view);
[[nodiscard]] static std::vector<ShortcutEntry> getGlobalShortcuts();
[[nodiscard]] static std::vector<ShortcutEntry> getViewShortcuts(View *view);
static void updateShortcut(const Shortcut &oldShortcut, const Shortcut &newShortcut, View *view = nullptr);
[[nodiscard]] static bool updateShortcut(const Shortcut &oldShortcut, const Shortcut &newShortcut, View *view = nullptr);
};
}

View File

@ -1,10 +1,5 @@
#pragma once
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/tar.hpp>
/**
@ -16,6 +11,10 @@
*/
namespace hex {
namespace prv {
class Provider;
}
class ProjectFile {
public:
struct Handler {

View File

@ -7,7 +7,6 @@
#include <set>
#include <span>
#include <string_view>
#include <vector>
#include <nlohmann/json_fwd.hpp>

View File

@ -7,7 +7,7 @@
#include <vector>
#include <span>
#include <wolv/io/file.hpp>
#include <wolv/io/fs.hpp>
namespace hex {

View File

@ -7,11 +7,8 @@
#include <string>
#include <vector>
#include <hex/helpers/fmt.hpp>
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
#include <wolv/utils/string.hpp>
#if defined(OS_WEB)
#include <emscripten/fetch.h>

View File

@ -6,6 +6,9 @@
#include <curl/curl.h>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/fmt.hpp>
#include <wolv/utils/string.hpp>
namespace hex {
@ -34,22 +37,22 @@ namespace hex {
curl_mime_data_cb(part, file.getSize(),
[](char *buffer, size_t size, size_t nitems, void *arg) -> size_t {
auto file = static_cast<FILE*>(arg);
auto handle = static_cast<FILE*>(arg);
return fread(buffer, size, nitems, file);
return fread(buffer, size, nitems, handle);
},
[](void *arg, curl_off_t offset, int origin) -> int {
auto file = static_cast<FILE*>(arg);
auto handle = static_cast<FILE*>(arg);
if (fseek(file, offset, origin) != 0)
if (fseek(handle, offset, origin) != 0)
return CURL_SEEKFUNC_CANTSEEK;
else
return CURL_SEEKFUNC_OK;
},
[](void *arg) {
auto file = static_cast<FILE*>(arg);
auto handle = static_cast<FILE*>(arg);
fclose(file);
fclose(handle);
},
file.getHandle());
curl_mime_filename(part, fileName.c_str());

View File

@ -1,13 +1,13 @@
#pragma once
#include <hex.hpp>
#include <hex/api/plugin_manager.hpp>
#include <string>
#include <imgui.h>
#include <imgui_internal.h>
#include <hex.hpp>
#include <hex/api/plugin_manager.hpp>
#include <wolv/utils/string.hpp>
#include <wolv/utils/preproc.hpp>

View File

@ -9,7 +9,6 @@
#include <variant>
#include <vector>
#include <hex/api/imhex_api.hpp>
#include <hex/providers/overlay.hpp>
#include <hex/helpers/fs.hpp>

View File

@ -2,13 +2,16 @@
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/providers/provider.hpp>
#include <map>
#include <utility>
namespace hex {
namespace prv {
class Provider;
}
template<typename T>
class PerProvider {
public:
@ -16,7 +19,7 @@ namespace hex {
PerProvider(const PerProvider&) = delete;
PerProvider(PerProvider&&) = delete;
PerProvider& operator=(const PerProvider&) = delete;
PerProvider& operator=(PerProvider&&) = delete;
PerProvider& operator=(PerProvider &&) = delete;
PerProvider(T data) : m_data({ { ImHexApi::Provider::get(), std::move(data) } }) { this->onCreate(); }

View File

@ -8,9 +8,9 @@
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <hex/helpers/utils.hpp>
#include <hex/api/task.hpp>
#include <hex/helpers/utils.hpp>
namespace hex {

View File

@ -10,6 +10,7 @@
#include <fonts/codicons_font.h>
#include <hex/api/imhex_api.hpp>
#include <hex/api/keybinding.hpp>
#include <hex/api/event.hpp>
#include <hex/providers/provider.hpp>
#include <hex/providers/provider_data.hpp>
@ -19,8 +20,6 @@
#include <functional>
#include <string>
#include <vector>
namespace hex {

View File

@ -1,4 +1,5 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/keybinding.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
@ -711,7 +712,7 @@ namespace hex {
log::debug("Added new menu item to menu {} with priority {}", wolv::util::combineStrings(unlocalizedMainMenuNames, " -> "), priority);
impl::getMenuItems().insert({
priority, { unlocalizedMainMenuNames, shortcut, function, enabledCallback }
priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique<Shortcut>(shortcut), view, function, enabledCallback }
});
if (shortcut != Shortcut::None) {
@ -727,14 +728,14 @@ namespace hex {
unlocalizedMainMenuNames.emplace_back(impl::SubMenuValue);
impl::getMenuItems().insert({
priority, { unlocalizedMainMenuNames, {}, function, enabledCallback }
priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique<Shortcut>(), nullptr, function, enabledCallback }
});
}
void addMenuItemSeparator(std::vector<std::string> unlocalizedMainMenuNames, u32 priority) {
unlocalizedMainMenuNames.emplace_back(impl::SeparatorValue);
impl::getMenuItems().insert({
priority, { unlocalizedMainMenuNames, {}, []{}, []{ return true; } }
priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique<Shortcut>(), nullptr, []{}, []{ return true; } }
});
}
@ -803,21 +804,33 @@ namespace hex {
namespace ContentRegistry::Provider {
void impl::addProviderName(const std::string &unlocalizedName) {
log::debug("Registered new provider: {}", unlocalizedName);
getEntries().push_back(unlocalizedName);
}
namespace impl {
void add(const std::string &typeName, ProviderCreationFunction creationFunction) {
(void)EventManager::subscribe<RequestCreateProvider>([expectedName = typeName, creationFunction](const std::string &name, bool skipLoadInterface, bool selectProvider, prv::Provider **provider) {
if (name != expectedName) return;
prv::Provider *newProvider = creationFunction();
ImHexApi::Provider::add(newProvider, skipLoadInterface, selectProvider);
if (provider != nullptr)
*provider = newProvider;
});
}
std::vector<std::string> &getEntries() {
static std::vector<std::string> providerNames;
return providerNames;
}
void addProviderName(const std::string &unlocalizedName) {
log::debug("Registered new provider: {}", unlocalizedName);
getEntries().push_back(unlocalizedName);
}
}

View File

@ -1,6 +1,6 @@
#include <hex/helpers/fs.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/project_file_manager.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/fmt.hpp>

View File

@ -2,6 +2,7 @@
#include <imgui.h>
#include <imgui_internal.h>
#include <imgui_impl_opengl3_loader.h>
#undef IMGUI_DEFINE_MATH_OPERATORS
#define STB_IMAGE_IMPLEMENTATION

View File

@ -32,6 +32,8 @@
#ifndef __gl3w_h_
#define __gl3w_h_
#include <GL/gl.h>
#if __has_include(<KHR/khrplatform.h>)
#include <KHR/khrplatform.h>
#else

View File

@ -6,6 +6,7 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/layout_manager.hpp>
#include <hex/api/keybinding.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fs.hpp>
@ -559,8 +560,8 @@ namespace hex {
}
for (auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMenuItems()) {
const auto &[unlocalizedNames, shortcut, callback, enabledCallback] = menuItem;
createNestedMenu(unlocalizedNames, shortcut, callback, enabledCallback);
const auto &[unlocalizedNames, shortcut, view, callback, enabledCallback] = menuItem;
createNestedMenu(unlocalizedNames, *shortcut, callback, enabledCallback);
}
};
@ -790,10 +791,10 @@ namespace hex {
// Draw main menu popups
for (auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMenuItems()) {
const auto &[unlocalizedNames, shortcut, callback, enabledCallback] = menuItem;
const auto &[unlocalizedNames, shortcut, view, callback, enabledCallback] = menuItem;
if (ImGui::BeginPopup(unlocalizedNames.front().c_str())) {
createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, shortcut, callback, enabledCallback);
createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, *shortcut, callback, enabledCallback);
ImGui::EndPopup();
}
}

View File

@ -5,13 +5,14 @@
#include <imgui.h>
#include <implot.h>
#include <hex/providers/provider.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/localization.hpp>
#include <hex/providers/provider.hpp>
#include <hex/providers/buffered_reader.hpp>
#include <imgui_internal.h>
#include <hex/helpers/logger.hpp>
#include <random>
namespace hex {
@ -114,7 +115,8 @@ namespace hex {
if (!this->m_processing)
for (size_t i = 0; i < (this->m_buffer.empty() ? 0 : this->m_buffer.size() - 1); i++) {
const auto &[x, y] = std::pair { this->m_buffer[i] * xStep, this->m_buffer[i + 1] * yStep };
auto x = this->m_buffer[i] * xStep;
auto y = this->m_buffer[i + 1] * yStep;
auto color = ImLerp(ImColor(0xFF, 0x6D, 0x01).Value, ImColor(0x01, 0x93, 0xFF).Value, float(i) / this->m_buffer.size()) + ImVec4(this->m_glowBuffer[i], this->m_glowBuffer[i], this->m_glowBuffer[i], 0.0F);
color.w = this->m_opacity;
@ -209,7 +211,8 @@ namespace hex {
if (!this->m_processing)
for (size_t i = 0; i < (this->m_buffer.empty() ? 0 : this->m_buffer.size()); i++) {
const auto &[x, y] = std::pair { this->m_buffer[i] * xStep, yStep * ((float(i) / this->m_buffer.size()) * 0xFF) };
auto x = this->m_buffer[i] * xStep;
auto y = yStep * ((float(i) / this->m_buffer.size()) * 0xFF);
auto color = ImLerp(ImColor(0xFF, 0x6D, 0x01).Value, ImColor(0x01, 0x93, 0xFF).Value, float(i) / this->m_buffer.size()) + ImVec4(this->m_glowBuffer[i], this->m_glowBuffer[i], this->m_glowBuffer[i], 0.0F);
color.w = this->m_opacity;
@ -549,29 +552,29 @@ namespace hex {
// Variables used to store the parameters to process
// Chunk's size for entropy analysis
u64 m_chunkSize;
u64 m_startAddress;
u64 m_endAddress;
u64 m_chunkSize = 0;
u64 m_startAddress = 0x00;
u64 m_endAddress = 0x00;
// Start / size of the file
u64 m_baseAddress;
u64 m_fileSize;
u64 m_baseAddress = 0x00;
u64 m_fileSize = 0;
// The size of the blocks (for diagram drawing)
u64 m_blockSize;
u64 m_blockSize = 0;
// Position of the handle inside the plot
double m_handlePosition = 0.0;
// Hold the number of blocks that have been processed
// during the chunk-based entropy analysis
u64 m_blockCount;
u64 m_blockCount = 0;
// Hold the number of bytes that have been processed
// during the analysis (useful for the iterative analysis)
u64 m_byteCount;
u64 m_byteCount = 0;
// Array used to hold the occurrences of each byte
// (useful for the iterative analysis)
std::array<ImU64, 256> m_blockValueCounts;
std::array<ImU64, 256> m_blockValueCounts = {};
// Variable to hold the result of the chunk-based
// entropy analysis
@ -580,7 +583,7 @@ namespace hex {
// Sampling size, number of elements displayed in the plot,
// avoid showing to many data because it decreased the frame rate
size_t m_sampleSize;
size_t m_sampleSize = 0;
std::atomic<bool> m_processing = false;
};
@ -950,7 +953,7 @@ namespace hex {
// Array used to hold the occurrences of each byte
// (useful for the iterative analysis)
std::array<ImU64, 256> m_blockValueCounts;
std::array<ImU64, 256> m_blockValueCounts = {};
// The m_xBlockTypeDistributions attributes are used to specify the position of
// the values in the plot when the Y axis doesn't start at 0

View File

@ -2,6 +2,7 @@
#include <hex/ui/popup.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/localization.hpp>
#include <functional>

View File

@ -11,6 +11,8 @@
#include <hex/providers/provider.hpp>
#include <set>
struct ImGuiTableSortSpecs;
namespace hex::plugin::builtin::ui {

View File

@ -69,7 +69,7 @@ namespace hex::plugin::builtin {
if (auto combined = wolv::util::combineStrings(names, " -> "); hex::containsIgnoreCase(combined, input) && !combined.contains(ContentRegistry::Interface::impl::SeparatorValue) && !combined.contains(ContentRegistry::Interface::impl::SubMenuValue)) {
result.emplace_back(ContentRegistry::CommandPaletteCommands::impl::QueryResult {
std::move(combined),
[entry](const auto&) { entry.callback(); }
[&entry](const auto&) { entry.callback(); }
});
}
}

View File

@ -1,4 +1,5 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/event.hpp>
#include <nlohmann/json.hpp>

View File

@ -1,3 +1,4 @@
#include <hex/api/imhex_api.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/providers/provider.hpp>

View File

@ -1,3 +1,4 @@
#include <hex/api/imhex_api.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/magic.hpp>

View File

@ -2,10 +2,10 @@
#include <hex/api/localization.hpp>
#include <hex/api/task.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/disassembler.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/opengl.hpp>
#include <hex/helpers/http_requests.hpp>
#include <imgui.h>
#include <implot.h>

View File

@ -2,6 +2,8 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/localization.hpp>
#include <hex/api/theme_manager.hpp>
#include <hex/api/keybinding.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/utils.hpp>
@ -190,7 +192,7 @@ namespace hex::plugin::builtin {
class KeybindingWidget : public ContentRegistry::Settings::Widgets::Widget {
public:
KeybindingWidget(View *view, Shortcut shortcut) : m_view(view), m_shortcut(std::move(shortcut)) {}
KeybindingWidget(View *view, const Shortcut &shortcut) : m_view(view), m_shortcut(shortcut), m_defaultShortcut(shortcut) {}
bool draw(const std::string &name) override {
std::string label;
@ -203,8 +205,12 @@ namespace hex::plugin::builtin {
if (label.empty())
label = "???";
if (this->m_hasDuplicate)
ImGui::PushStyleColor(ImGuiCol_Text, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerError));
ImGui::PushID(this);
if (ImGui::Button(label.c_str(), ImVec2(150_scaled, 0))) {
if (ImGui::Button(label.c_str(), ImVec2(250_scaled, 0))) {
this->m_editing = !this->m_editing;
if (this->m_editing)
@ -212,7 +218,18 @@ namespace hex::plugin::builtin {
else
ShortcutManager::resumeShortcuts();
}
ImGui::PopID();
ImGui::SameLine();
if (this->m_hasDuplicate)
ImGui::PopStyleColor();
ImGui::BeginDisabled(this->m_shortcut == this->m_defaultShortcut);
if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, this->m_defaultShortcut, this->m_view);
this->m_shortcut = this->m_defaultShortcut;
}
ImGui::EndDisabled();
if (!ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
this->m_editing = false;
@ -223,6 +240,8 @@ namespace hex::plugin::builtin {
ImGuiExt::TextFormatted("{}", name);
ImGui::PopID();
if (this->m_editing) {
if (this->detectShortcut()) {
this->m_editing = false;
@ -245,7 +264,7 @@ namespace hex::plugin::builtin {
return;
auto newShortcut = Shortcut(keys);
ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
this->m_shortcut = std::move(newShortcut);
}
@ -274,7 +293,7 @@ namespace hex::plugin::builtin {
}
auto newShortcut = Shortcut(std::move(keys));
ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
this->m_shortcut = std::move(newShortcut);
return true;
@ -285,8 +304,9 @@ namespace hex::plugin::builtin {
private:
View *m_view = nullptr;
Shortcut m_shortcut;
Shortcut m_shortcut, m_defaultShortcut;
bool m_editing = false;
bool m_hasDuplicate = false;
};
}

View File

@ -6,6 +6,8 @@
#include <hex/ui/popup.hpp>
#include <hex/helpers/utils.hpp>
using namespace hex;
#define VERSION V1

View File

@ -10,6 +10,7 @@
#include <hex/helpers/utils.hpp>
#include <string_view>
#include <set>
namespace hex::plugin::windows {