Skip to content

Commit f80c9cd

Browse files
video memory checks to set settings automatically
1 parent c43ffd8 commit f80c9cd

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
},
5454
"history-length": {
5555
"name": "History length",
56-
"description": "The length of rewind history stored, in capture frame count.",
56+
"description": "The length of rewind history stored, in capture frame count. This will be attempted to be automatically populated on windows machines with Nvidia or AMD graphics cards by the amount of video memory available.",
5757
"type": "int",
5858
"min": 20,
59-
"max": 400,
59+
"max": 500,
6060
"default": {
6161
"android": 140,
6262
"ios": 140,

src/hooks/MenuLayer.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifdef GEODE_IS_WINDOWS
2+
#include "MenuLayer.hpp"
3+
#include <Geode/cocos/platform/third_party/win32/OGLES/GL/glew.h>
4+
5+
// populate defaults by getting amount of system vram
6+
bool HookedMenuLayer::init() {
7+
if (!MenuLayer::init()) return false;
8+
9+
auto mod = geode::Mod::get();
10+
11+
bool hasSetRecommended = mod->getSavedValue<bool>("has-set-recommended", false);
12+
if (hasSetRecommended) return true;
13+
mod->setSavedValue<bool>("has-set-recommended", true);
14+
15+
// https://stackoverflow.com/a/5695427
16+
// no intel support very sad
17+
int values[4] = {};
18+
glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, values); // nvidia
19+
glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, values); // amd (ati)
20+
21+
if (values[0] == 0) {
22+
geode::log::info("No data returned from vram checks :( ({}, {}, {}, {})", values[0], values[1], values[2], values[3]);
23+
return true;
24+
}
25+
26+
int kb = values[0];
27+
int frames = (kb / 42000) + 80; // https://www.desmos.com/calculator/m2hlel1fjj
28+
29+
geode::log::info("Video memory checks returned {}kb (approx), mapped to {} frames", kb, frames);
30+
31+
frames = std::max(20, std::min(frames, 500));
32+
33+
mod->setSettingValue<int64_t>("history-length", frames);
34+
35+
auto pop = FLAlertLayer::create(
36+
"Rewind",
37+
fmt::format(
38+
"Rewind has automagically detected <cy>{}GB</c> of video memory free, and "
39+
"has set the <cj>max history length</c> to <cy>{}</c>, which can be customised in "
40+
"the <co>mod settings</c>.",
41+
kb / 1000000, frames
42+
).c_str(),
43+
"ok"
44+
);
45+
pop->m_scene = this;
46+
pop->show();
47+
48+
return true;
49+
}
50+
#endif

src/hooks/MenuLayer.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#ifdef GEODE_IS_WINDOWS
3+
#include <Geode/modify/MenuLayer.hpp>
4+
5+
class $modify(HookedMenuLayer, MenuLayer) {
6+
bool init();
7+
};
8+
9+
#endif

src/settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
fields->m_resolutionMultiplier = geode::Mod::get()->getSettingValue<double>("resolution-multiplier");
1919
}
2020
});
21-
};
21+
}

0 commit comments

Comments
 (0)