Triforce v0.9.0

Character tab, faster renderer defaults, HD rumble shipped, and the 11-30 bug pass: ending softlock below 60 fps, adult first-night lock, Intel Arc robust buffers, adult map, randomizer load order.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-30 20:55:14 -06:00
parent 8cb23131f9
commit 822ee913bc
86 changed files with 8128 additions and 438 deletions

View File

@@ -90,6 +90,168 @@ inline std::vector<int> pair_by_place(const std::vector<Placed>& now, const std:
return pairs;
}
/// (Triforce) The most copies of one model paired by place: pair_by_place and ambiguous_by_place cost copies x copies a model
/// (1000 copies took 11 ms a frame). A model with more has all its copies get the camera's motion (unsure_copies), as before
/// copies were paired by place. 256: the key's n-th stops at 255 (key())
constexpr size_t kCopyCap = 256;
/// (Triforce) How near another copy has to be to leave a pair in doubt, in ambiguous_by_place: within kTieFactor times the
/// distance the copy itself moved since the frame before, plus kTieSlack. Both in world units, as a copy's own move since the
/// frame before is, so it is not tuned to a screen (a copy that moved far among static ones is sure; one that moved little
/// beside another about as near is not)
constexpr double kTieFactor = 2.0, kTieSlack = 0.05;
/// (Triforce) Which of this frame's copies, paired by place (pairs: pair_by_place's), have no sure pair: another copy of the
/// frame before is about as near (within kTieFactor times the distance moved, plus kTieSlack), or another copy of this frame is about as near
/// that same copy of the frame before. A copy that moved on its own among static ones is sure (its own old place is nearest by
/// far); copies at one place (the origin of every copy of a piece of ground, or of a model whose place is not what was read)
/// are never sure. Those take the camera's motion. Copies without a pair are not flagged (they have none: the camera's)
inline std::vector<char> ambiguous_by_place(const std::vector<Placed>& now, const std::vector<Placed>& then,
const std::vector<int>& pairs) {
std::vector<char> out(now.size(), 0);
const auto distance = [&](const Placed& a, const Placed& b) {
double d = 0.0;
for (int c = 0; c < 3; c++) {
const double e = (double)a.place[c] - (double)b.place[c];
d += e * e;
}
return std::sqrt(d);
};
for (size_t i = 0; i < now.size() && i < pairs.size(); i++) {
const int j = pairs[i];
if (j < 0 || j >= (int)then.size()) continue;
const double limit = kTieFactor * distance(now[i], then[j]) + kTieSlack;
for (size_t k = 0; k < then.size() && !out[i]; k++)
if ((int)k != j && distance(now[i], then[k]) <= limit) out[i] = 1;
for (size_t m = 0; m < now.size() && !out[i]; m++)
if (m != i && distance(now[m], then[j]) <= limit) out[i] = 1;
}
return out;
}
/// (Triforce) For RX_VK_DLSS_TRACE: how a model's copies are spread: how many differ from all before them (by over 0.001), and the
/// least (over 0.001) and greatest distance between two of them. Tells whether what was read as a place is one
struct Spread {
int distinct = 0;
float min_gap = 0.0f, max_gap = 0.0f;
};
inline Spread origin_spread(const std::vector<Placed>& copies) {
Spread s;
double lo = 0.0, hi = 0.0;
for (size_t i = 0; i < copies.size(); i++) {
bool fresh = true;
for (size_t j = 0; j < i; j++) {
double d = 0.0;
for (int c = 0; c < 3; c++) {
const double e = (double)copies[i].place[c] - (double)copies[j].place[c];
d += e * e;
}
d = std::sqrt(d);
if (!std::isfinite(d)) continue;
if (d > 0.001) {
lo = lo > 0.0 ? std::min(lo, d) : d;
hi = std::max(hi, d);
} else fresh = false;
}
s.distinct += fresh;
}
s.min_gap = (float)lo, s.max_gap = (float)hi;
return s;
}
/// (Triforce) Which of this frame's scene draws have no sure draw of their own the frame before: a copy without a place (not
/// skinned, so pair_by_place can't tell it apart) of a model drawn more than once this frame, or the frame before (had: the
/// frame before drew that key; asked for the model's second draw, n-th 1). Its n-th draw the frame before is then only a
/// guess: the game draws a model's copies (trees, rocks, pieces of ground) in another order as the camera turns, and a copy
/// paired by n-th takes its neighbour's positions as its own frame before. Frame generation then draws it part way to the
/// neighbour (a tree's afterimage beside another tree, ground smeared along outlines). Those get the camera's motion
/// instead, as the draws with no frame before do. keys: this frame's scene draws (key()); placed[i]: it has a place
template <class Had>
std::vector<char> unsure_copies(const std::vector<uint64_t>& keys, const std::vector<char>& placed, Had&& had) {
std::vector<char> out(keys.size(), 0);
std::vector<uint64_t> models(keys.size());
for (size_t i = 0; i < keys.size(); i++) models[i] = keys[i] >> 8;
std::vector<uint64_t> sorted = models;
std::sort(sorted.begin(), sorted.end());
for (size_t i = 0; i < keys.size(); i++) {
if (placed[i]) continue;
const auto r = std::equal_range(sorted.begin(), sorted.end(), models[i]);
out[i] = r.second - r.first > 1 || had((keys[i] & ~0xffull) | 1);
}
return out;
}
/// (Triforce) Limits for object_place, from the 2026-11-28 in-game diagnostic (62 models: every object buffer's 3x3 was
/// rotation-scale, its axes well over kAxisMin long, pairwise |cos| near 0): a translation beyond kPlaceMax, or a 3x3 whose
/// rows and whose columns are both short or far from orthogonal, is not a world matrix
constexpr float kPlaceMax = 1e5f, kAxisMin = 1e-4f, kAxisCosMax = 0.05f;
/// (Triforce) True if the three vectors of the 3x3 of m (a 3x4 row-major matrix) taken along rows (step 4, next 1) or columns
/// (step 1, next 4) are all over kAxisMin long and pairwise |cos| under kAxisCosMax
inline bool orthogonal_axes(const float m[12], int step, int next) {
double len[3];
for (int r = 0; r < 3; r++) {
double d = 0.0;
for (int c = 0; c < 3; c++) d += (double)m[r * step + c * next] * m[r * step + c * next];
len[r] = std::sqrt(d);
if (!(len[r] > kAxisMin)) return false;
}
for (int r = 0; r < 3; r++) {
const int q = (r + 1) % 3;
double dot = 0.0;
for (int c = 0; c < 3; c++) dot += (double)m[r * step + c * next] * m[q * step + c * next];
if (!(std::fabs(dot) / (len[r] * len[q]) < kAxisCosMax)) return false;
}
return true;
}
/// (Triforce) The place a non-skinned draw's object buffer holds: m, its first 12 floats, a 3x4 row-major world matrix (rows at
/// +0x00, +0x10, +0x20 of 4 floats, the translation last in each: m[3], m[7], m[11]; the floats at +0x40 are not a place).
/// Taken only if all 12 are finite (infinities and NaN would otherwise pass the comparisons' edge cases), the translation is
/// under kPlaceMax, and the 3x3 is rotation-scale: its rows or its columns are orthogonal (R*diag(s) has orthogonal columns,
/// diag(s)*R orthogonal rows). Else false and out is untouched
inline bool object_place(const float m[12], float out[3]) {
for (int i = 0; i < 12; i++)
if (!std::isfinite(m[i])) return false;
const int t[3] = {3, 7, 11};
for (int a = 0; a < 3; a++)
if (!(std::fabs(m[t[a]]) < kPlaceMax)) return false;
if (!orthogonal_axes(m, 4, 1) && !orthogonal_axes(m, 1, 4)) return false;
for (int a = 0; a < 3; a++) out[a] = m[t[a]];
return true;
}
/// (Triforce) Which of this frame's scene draws without a skin are placed by their object's origin: those whose origin was read
/// (readable[i]) of a model with copies (drawn 2+ times this frame, or its 2nd the frame before: had(key of its 2nd)), and not
/// over kCopyCap of them, whose copies keep the camera's motion by unsure_copies instead
template <class Had>
std::vector<char> place_by_origin(const std::vector<uint64_t>& keys, const std::vector<char>& readable, Had&& had) {
std::vector<char> out(keys.size(), 0);
std::vector<uint64_t> sorted;
for (size_t i = 0; i < keys.size(); i++)
if (readable[i]) sorted.push_back(keys[i] >> 8);
std::sort(sorted.begin(), sorted.end());
for (size_t i = 0; i < keys.size(); i++) {
if (!readable[i]) continue;
const auto r = std::equal_range(sorted.begin(), sorted.end(), keys[i] >> 8);
const size_t n = (size_t)(r.second - r.first);
out[i] = n <= kCopyCap && (n > 1 || had((keys[i] & ~0xffull) | 1));
}
return out;
}
/// (Triforce) Which draws placed by origin (by_origin) had a second copy the frame before (had) that was not placed (placed:
/// its origin was not readable, so nothing to pair it by): their pair is a guess, flagged as unsure_copies flagged it
template <class Had, class Placed>
std::vector<char> lost_second_copy(const std::vector<uint64_t>& keys, const std::vector<char>& by_origin, Had&& had, Placed&& placed) {
std::vector<char> out(keys.size(), 0);
for (size_t i = 0; i < keys.size(); i++) {
const uint64_t second = (keys[i] & ~0xffull) | 1;
out[i] = by_origin[i] && had(second) && !placed(second);
}
return out;
}
/// (Triforce) Where a skinned draw is, to tell copies of one model apart: its origin (3 floats) plus the mean of its bones'
/// translations (nbones 3 x 4 row-major matrices: world = sum(w B p) + origin). A model placed by its origin differs there;
/// copies placed by their bones at one origin (the game's copies of one model share an origin, the Gossip Stones among them)