summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlightlessMango <flightlessmangoyt@gmail.com>2023-09-27 10:02:16 +0200
committerFlightlessMango <flightlessmangoyt@gmail.com>2023-10-06 02:20:00 +0200
commit73ea9efb7b4e9a634bf6fdad6091a63ed27e4d21 (patch)
tree367c38b0d80de1651d4485c224c3e2da24bce58b
parent2254f3c1d1416031f4ce4e20d13a1d3152a56826 (diff)
-rw-r--r--mangoconfig/main.cpp3
-rw-r--r--mangoconfig/meson.build2
-rw-r--r--meson.build2
-rw-r--r--meson_options.txt3
-rw-r--r--src/faker.cpp0
-rw-r--r--src/faker.h111
-rw-r--r--src/meson.build7
-rw-r--r--src/overlay.cpp13
-rw-r--r--src/vulkan.cpp3
9 files changed, 135 insertions, 9 deletions
diff --git a/mangoconfig/main.cpp b/mangoconfig/main.cpp
index 5c142ea..99db5f1 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(&params, "MANGOHUD_CONFIG", false);
HUDElements.convert_colors(params);
sw_stats.engine = EngineTypes::VULKAN;
+ faker = std::make_unique<Faker>(sw_stats, params, vendorID);
resizeCanvas();
return 0;
diff --git a/mangoconfig/meson.build b/mangoconfig/meson.build
index 46ae145..9e7051a 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 1d615ca..c0de27a 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 369b0a8..7a5cd02 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 0000000..e69de29
--- /dev/null
+++ b/src/faker.cpp
diff --git a/src/faker.h b/src/faker.h
new file mode 100644
index 0000000..219b2bc
--- /dev/null
+++ b/src/faker.h
@@ -0,0 +1,111 @@
+#include <iostream>
+#include <random>
+#include <cmath>
+#include "overlay.h"
+#include "gpu.h"
+#ifdef __EMSCRIPTEN__
+#include <emscripten.h>
+#include <emscripten/html5.h>
+#endif
+
+#include <random>
+
+class SmoothNumberGenerator {
+ private:
+ std::default_random_engine generator;
+ std::uniform_real_distribution<float> 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<float>::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<std::chrono::nanoseconds>(now.time_since_epoch());
+ auto ret = duration.count();
+ return ret;
+ }
+};
+
+extern std::unique_ptr<Faker> faker; \ No newline at end of file
diff --git a/src/meson.build b/src/meson.build
index 4571152..241a12b 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 9562794..4cac884 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 <libgen.h>
@@ -55,6 +55,7 @@ int fan_speed;
fcatoverlay fcatstatus;
std::string drm_dev;
int current_preset;
+std::unique_ptr<Faker> 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_info_updater>();
hw_update_thread->update(&params, 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 9829797..7e383bc 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<Faker>(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__