mirror of
https://git.triforceproject.com/triforce/source
synced 2026-12-02 05:48:50 -04:00
Triforce v0.9.1
The 16 GB update: idle memory unlocked and handed back to Windows while playing, empty pages under freed locks returned, and a page-file check at launch that warns before a too-small page file can crash the game.
This commit is contained in:
97
host/pagefile_rule.h
Normal file
97
host/pagefile_rule.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* (Triforce, 12-01) Whether this PC's commit limit (RAM + page file) can ever hold the game: the page file's settings read at
|
||||
the start, and a warning when they cannot (mkw_glue.c hos_pagefile_check). Apart from Windows so that
|
||||
tests/test_pagefile_rule.py runs it on many made-up PCs.
|
||||
|
||||
Why: 16 GB players crash when Windows runs out of commit ("Windows is out of memory", mkw_glue.c hos_out_of_memory_box, shown
|
||||
only once it has happened). Eleven 16 GB players' logs of 11-19 had commit limits of 29 to 58 GB, set by their page files,
|
||||
and five of them were within 1.5 GB of theirs. The game itself takes some 23.5-24.5 GB of commit at its peak on a lab tour of
|
||||
eleven areas (12-01, v0.9.0 + the RAM work: the game's own memory ~9.4 GB, the graphics memory's charge ~8.4, the renderer's
|
||||
~5.6), and none of that could be cut without hitches. A page file Windows manages grows as it is needed, up to three times
|
||||
the RAM, while its drive has room; a fixed one never passes its maximum; none at all leaves the RAM alone.
|
||||
|
||||
The rule: the most the limit can reach (RAM + the page file at its largest: a fixed one's maximum; a managed one's size now
|
||||
grown by what its drive has free, keeping 2 GB, up to three times the RAM, or 4 GB on a small PC) against what is needed (the
|
||||
commit in use before the game, plus the game's peak and a margin: 26 GB; never under 36 GB). Short: a warning, which names
|
||||
what to change. */
|
||||
#ifndef PAGEFILE_RULE_H
|
||||
#define PAGEFILE_RULE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
enum { PF_KIND_NONE = 0, PF_KIND_MANAGED = 1, PF_KIND_FIXED = 2 };
|
||||
enum { PF_OK = 0, PF_SHORT_NONE = 1, PF_SHORT_FIXED = 2, PF_SHORT_DISK = 3 };
|
||||
|
||||
typedef struct {
|
||||
int kind; /* PF_KIND_*: managed wins when one file of several is managed */
|
||||
char drive; /* the managed file's drive letter ('C'), or the first fixed file's; 0 when none */
|
||||
double fixed_max_gb; /* the fixed files' maximum sizes, summed */
|
||||
} PfSettings;
|
||||
|
||||
/* The registry's PagingFiles value (REG_MULTI_SZ: strings one after another, each ended by a 0, an empty one at the end), n
|
||||
bytes: "?:\pagefile.sys" (every drive, Windows manages it), "C:\pagefile.sys 0 0" (managed, on C:), "C:\pagefile.sys 4096 8192"
|
||||
(fixed: initial and maximum in MB), or nothing (no page file) */
|
||||
static inline PfSettings pf_parse(const char *multi, size_t n) {
|
||||
PfSettings s = {PF_KIND_NONE, 0, 0.0};
|
||||
size_t at = 0;
|
||||
while (multi && at < n && multi[at]) {
|
||||
const char *e = multi + at;
|
||||
size_t len = 0;
|
||||
while (at + len < n && e[len]) len++;
|
||||
char one[300];
|
||||
const size_t k = len < sizeof one - 1 ? len : sizeof one - 1;
|
||||
memcpy(one, e, k);
|
||||
one[k] = 0;
|
||||
at += len + 1;
|
||||
if (k < 2) continue;
|
||||
char *sp = strchr(one, ' ');
|
||||
long long init = 0, max = 0;
|
||||
int sizes = 0;
|
||||
if (sp) {
|
||||
char *end = NULL;
|
||||
init = strtoll(sp + 1, &end, 10);
|
||||
if (end && *end == ' ') max = strtoll(end + 1, NULL, 10), sizes = 1;
|
||||
}
|
||||
const char d = one[0] >= 'a' && one[0] <= 'z' ? (char)(one[0] - 32) : one[0];
|
||||
if (one[0] == '?' || !sizes || (init == 0 && max == 0)) { /* (managed: every drive, or a drive with no sizes) */
|
||||
s.kind = PF_KIND_MANAGED;
|
||||
s.drive = one[0] == '?' ? 'C' : d;
|
||||
} else if (s.kind != PF_KIND_MANAGED) {
|
||||
if (s.kind == PF_KIND_NONE) s.drive = d;
|
||||
s.kind = PF_KIND_FIXED;
|
||||
s.fixed_max_gb += (double)(max > init ? max : init) / 1024.0;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
double reach_gb; /* the most the commit limit can reach */
|
||||
double need_gb; /* what the game needs it to reach */
|
||||
int verdict; /* PF_OK, or why it is short */
|
||||
} PfVerdict;
|
||||
|
||||
/* ram_gb: the PC's RAM; limit_gb: the commit limit now (RAM + the page file as it is now); in_use_gb: the commit in use now,
|
||||
before the game's own; disk_free_gb: free space on the managed file's drive (unused otherwise) */
|
||||
static inline PfVerdict pf_decide(const PfSettings *s, double ram_gb, double limit_gb, double in_use_gb, double disk_free_gb) {
|
||||
PfVerdict v;
|
||||
const double now_file = limit_gb > ram_gb ? limit_gb - ram_gb : 0.0;
|
||||
if (s->kind == PF_KIND_MANAGED) {
|
||||
const double cap = ram_gb * 3 > 4 ? ram_gb * 3 : 4;
|
||||
double grown = now_file + (disk_free_gb > 2 ? disk_free_gb - 2 : 0);
|
||||
if (grown > cap) grown = cap;
|
||||
if (grown < now_file) grown = now_file;
|
||||
v.reach_gb = ram_gb + grown;
|
||||
} else if (s->kind == PF_KIND_FIXED) {
|
||||
v.reach_gb = ram_gb + (s->fixed_max_gb > now_file ? s->fixed_max_gb : now_file);
|
||||
} else {
|
||||
v.reach_gb = limit_gb > ram_gb ? limit_gb : ram_gb;
|
||||
}
|
||||
v.need_gb = in_use_gb + 26 > 36 ? in_use_gb + 26 : 36;
|
||||
v.verdict = v.reach_gb >= v.need_gb ? PF_OK
|
||||
: s->kind == PF_KIND_NONE ? PF_SHORT_NONE
|
||||
: s->kind == PF_KIND_FIXED ? PF_SHORT_FIXED : PF_SHORT_DISK;
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user