From 73ea9efb7b4e9a634bf6fdad6091a63ed27e4d21 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Wed, 27 Sep 2023 10:02:16 +0200 Subject: [PATCH] WIP --- mangoconfig/main.cpp | 3 +- mangoconfig/meson.build | 2 +- meson.build | 2 +- meson_options.txt | 3 +- src/faker.cpp | 0 src/faker.h | 111 ++++++++++++++++++++++++++++++++++++++++ src/meson.build | 7 ++- src/overlay.cpp | 13 +++-- src/vulkan.cpp | 3 +- 9 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/faker.cpp create mode 100644 src/faker.h diff --git a/mangoconfig/main.cpp b/mangoconfig/main.cpp index 5c142eab..99db5f1d 100644 --- a/mangoconfig/main.cpp +++ b/mangoconfig/main.cpp @@ -16,6 +16,7 @@ #include "hud_elements.h" #include "overlay.h" #include "font_default.h" +#include "faker.h" GLFWwindow* g_window; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -133,11 +134,11 @@ int init_imgui() // Setup style // ImGui::StyleColorsDark(); - ImGuiIO& io = ImGui::GetIO(); create_fonts(nullptr, params, sw_stats.font1, sw_stats.font_text); parse_overlay_config(¶ms, "MANGOHUD_CONFIG", false); HUDElements.convert_colors(params); sw_stats.engine = EngineTypes::VULKAN; + faker = std::make_unique(sw_stats, params, vendorID); resizeCanvas(); return 0; diff --git a/mangoconfig/meson.build b/mangoconfig/meson.build index 46ae145e..9e7051aa 100644 --- a/mangoconfig/meson.build +++ b/mangoconfig/meson.build @@ -52,7 +52,7 @@ cxx_flags = [ '-s', 'USE_PTHREADS=1', ] -libs = ['-lGL'] +libs = ['-lGL', '-gsource-map', '-sDISABLE_EXCEPTION_CATCHING=1', '-g'] spdlog_dep = mangohud_sp.get_variable('spdlog_dep') executable('imgui', sources, diff --git a/meson.build b/meson.build index 1d615ca8..c0de27ae 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,7 @@ project('MangoHud', version : 'v0.7.0', license : 'MIT', meson_version: '>=0.60.0', - default_options : ['buildtype=release', 'c_std=c99', 'cpp_std=c++14', 'warning_level=2'] + default_options : ['buildtype=release', 'c_std=c99', 'cpp_std=c++20', 'warning_level=2'] ) cc = meson.get_compiler('c') diff --git a/meson_options.txt b/meson_options.txt index 369b0a86..7a5cd024 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -12,4 +12,5 @@ option('mangoapp', type: 'boolean', value : false) option('mangohudctl', type: 'boolean', value : false) option('mangoapp_layer', type: 'boolean', value : false) option('tests', type: 'feature', value: 'auto', description: 'Run tests') -option('with_spdlog', type: 'feature', value: 'enabled') \ No newline at end of file +option('with_spdlog', type: 'feature', value: 'enabled') +option('with_faker', type: 'feature', value: 'disabled') \ No newline at end of file diff --git a/src/faker.cpp b/src/faker.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/faker.h b/src/faker.h new file mode 100644 index 00000000..219b2bcb --- /dev/null +++ b/src/faker.h @@ -0,0 +1,111 @@ +#include +#include +#include +#include "overlay.h" +#include "gpu.h" +#ifdef __EMSCRIPTEN__ +#include +#include +#endif + +#include + +class SmoothNumberGenerator { + private: + std::default_random_engine generator; + std::uniform_real_distribution distribution; + float previous; + float minRange, maxRange; + float delta; + + public: + SmoothNumberGenerator(float min = 16.3f, float max = 17.4f, float optional_delta = 1.f) + : distribution(min, max), + minRange(min), + maxRange(max), + delta(optional_delta) { + unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); + generator.seed(seed); + previous = distribution(generator); + } + + float next() { + float lower_bound = std::max(minRange, previous - delta); + float upper_bound = std::min(maxRange, previous + delta); + + // We temporarily adjust the distribution's parameters to generate within our desired range + distribution.param(std::uniform_real_distribution::param_type(lower_bound, upper_bound)); + previous = distribution(generator); + + return previous; + } +}; + +class fakeCPU { + public: + + +}; + +class fakeGPU { + private: + SmoothNumberGenerator gpuLoad; + SmoothNumberGenerator fanSpeed; + SmoothNumberGenerator temp; + SmoothNumberGenerator powerUsage; + + public: + fakeGPU() : gpuLoad(90, 95), + fanSpeed(2000, 2500), + temp(85,90), + powerUsage(150,200) {} + + void update() { + gpuInfo gpu; + gpu.load = gpuLoad.next(); + gpu.CoreClock = 2800; + gpu.fan_speed = fanSpeed.next(); + gpu.is_current_throttled = false; + gpu.is_other_throttled = false; + gpu.is_power_throttled = false; + gpu.is_temp_throttled = true; + gpu.MemClock = 1250; + gpu.memory_temp = temp.next(); + gpu.memoryUsed = 3242; + gpu.powerUsage = powerUsage.next(); + gpu.temp = temp.next(); + + gpu_info = gpu; + }; + +}; + +class Faker { + private: + swapchain_stats sw_stats; + overlay_params params; + uint32_t vendorID; + fakeGPU gpu; + + public: + Faker(swapchain_stats sw_stats, overlay_params params, uint32_t vendorID) + : sw_stats(sw_stats), params(params), vendorID(vendorID) {} + + void update_frametime() { + update_hud_info_with_frametime(sw_stats, params, vendorID, 16.6f); + } + + void update() { + // update_frametime(); + gpu.update(); + } + + uint64_t now() { + auto now = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(now.time_since_epoch()); + auto ret = duration.count(); + return ret; + } +}; + +extern std::unique_ptr faker; \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 45711525..241a12b1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -82,7 +82,8 @@ if is_unixy or cpp.get_id() == 'emscripten' 'control.cpp', 'device.cpp', 'amdgpu.cpp', - 'intel.cpp' + 'intel.cpp', + 'faker.cpp' ) if cpp.get_id() != 'emscripten' @@ -90,6 +91,10 @@ if is_unixy or cpp.get_id() == 'emscripten' vklayer_files += 'notify.cpp' endif + if get_option('with_faker').enabled() + vklayer_files += 'faker.cpp' + endif + opengl_files = files( 'gl/glad.c', 'gl/gl_renderer.cpp', diff --git a/src/overlay.cpp b/src/overlay.cpp index 9562794a..4cac8844 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -26,7 +26,7 @@ #include "pci_ids.h" #include "iostats.h" #include "amdgpu.h" - +#include "faker.h" #ifdef __linux__ #include @@ -55,6 +55,7 @@ int fan_speed; fcatoverlay fcatstatus; std::string drm_dev; int current_preset; +std::unique_ptr faker = nullptr; void init_spdlog() { @@ -135,6 +136,7 @@ void update_hw_info(const struct overlay_params& params, uint32_t vendorID) if (vendorID== 0x8086) getIntelGpuInfo(); #endif + faker->update(); } #ifdef __linux__ @@ -238,7 +240,10 @@ void stop_hw_updater() void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, const struct overlay_params& params, uint32_t vendorID, uint64_t frametime_ns){ uint32_t f_idx = sw_stats.n_frames % ARRAY_SIZE(sw_stats.frames_stats); - uint64_t now = os_time_get_nano(); /* ns */ + uint64_t now; + // now = os_time_get_nano(); /* ns */ + if (faker) + now = faker->now(); /* ns */ auto elapsed = now - sw_stats.last_fps_update; /* ns */ float frametime_ms = frametime_ns / 1000000.f; @@ -256,9 +261,11 @@ void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, const stru fps = double(1000 / frametime_ms); if (elapsed >= params.fps_sampling_period) { +#ifndef __EMSCRIPTEN__ if (!hw_update_thread) hw_update_thread = std::make_unique(); hw_update_thread->update(¶ms, vendorID); +#endif sw_stats.fps = 1000000000.0 * sw_stats.n_frames_since_update / elapsed; @@ -294,7 +301,7 @@ void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, const stru } void update_hud_info(struct swapchain_stats& sw_stats, const struct overlay_params& params, uint32_t vendorID){ - uint64_t now = os_time_get_nano(); /* ns */ + uint64_t now = faker->now(); /* ns */ uint64_t frametime_ns = now - sw_stats.last_present_time; if (!params.no_display || logger->is_active()) update_hud_info_with_frametime(sw_stats, params, vendorID, frametime_ns); diff --git a/src/vulkan.cpp b/src/vulkan.cpp index 98297979..7e383bcb 100644 --- a/src/vulkan.cpp +++ b/src/vulkan.cpp @@ -54,7 +54,7 @@ #ifdef __linux__ #include "implot.h" #endif - +#include "faker.h" using namespace std; float offset_x, offset_y, hudSpacing; @@ -457,6 +457,7 @@ static void snapshot_swapchain_frame(struct swapchain_data *data) { struct device_data *device_data = data->device; struct instance_data *instance_data = device_data->instance; + faker = std::make_unique(data->sw_stats, instance_data->params, device_data->properties.vendorID); update_hud_info(data->sw_stats, instance_data->params, device_data->properties.vendorID); check_keybinds(instance_data->params, device_data->properties.vendorID); #ifdef __linux__