mirror of
https://git.triforceproject.com/triforce/source
synced 2026-12-01 05:18:50 -04:00
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:
@@ -3,6 +3,7 @@
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#define CHECK(name, condition) do { if (!(condition)) { std::fprintf(stderr, "FAIL %s at line %d\n", name, __LINE__); return 1; } } while (0)
|
||||
|
||||
@@ -133,6 +134,151 @@ int main() {
|
||||
CHECK("none then, none now", da::pair_by_place(stones, {}, 1.0f) == std::vector<int>(4, -1) &&
|
||||
da::pair_by_place({}, stones, 1.0f).empty());
|
||||
|
||||
// copies without a place: their n-th draw the frame before is a guess when the model is drawn more than once (a row of
|
||||
// trees drawn in another order as the camera turns: a tree's motion pointed at its neighbour)
|
||||
{
|
||||
const uint64_t t0 = da::key(0x5000, 0x6000, 300, 0, 0x77, 0), t1 = da::key(0x5000, 0x6000, 300, 0, 0x77, 1);
|
||||
const uint64_t hill = da::key(0x7000, 0x8000, 9000, 0, 0x77, 0);
|
||||
const auto none = [](uint64_t) { return false; };
|
||||
const auto had_second = [&](uint64_t k) { return k == t1; };
|
||||
const auto same_c = [](const std::vector<char>& a, std::vector<char> b) { return a == b; };
|
||||
CHECK("a model drawn once, now and before: sure", same_c(da::unsure_copies({hill}, {0}, none), {0}));
|
||||
CHECK("two copies now, no place: both unsure", same_c(da::unsure_copies({t0, t1, hill}, {0, 0, 0}, none), {1, 1, 0}));
|
||||
CHECK("one copy now, two the frame before: unsure", same_c(da::unsure_copies({t0, hill}, {0, 0}, had_second), {1, 0}));
|
||||
CHECK("copies with a place pair by it: sure", same_c(da::unsure_copies({t0, t1}, {1, 1}, none), {0, 0}));
|
||||
CHECK("one copy with a place, one without: the one without unsure",
|
||||
same_c(da::unsure_copies({t0, t1}, {1, 0}, none), {0, 1}));
|
||||
CHECK("none", da::unsure_copies({}, {}, none).empty());
|
||||
}
|
||||
|
||||
// copies without a skin placed by their object's origin (a rock a trail of its kind): a copy that moved among static ones
|
||||
// keeps its own pairing, static copies whose draw order swapped are not mixed up, and copies that can't be told apart
|
||||
// (one place, or about equally near) are flagged for the camera's motion
|
||||
{
|
||||
const std::vector<P> row_then = {{{0, 0, 0}, 0}, {{10, 0, 0}, 1}, {{20, 0, 0}, 2}};
|
||||
const auto same_c = [](const std::vector<char>& a, std::vector<char> b) { return a == b; };
|
||||
// (1) the middle one moves 0.5 (a rock carried), the others stand
|
||||
const std::vector<P> moved_now = {{{0, 0, 0}, 0}, {{10.5f, 0, 0}, 1}, {{20, 0, 0}, 2}};
|
||||
const auto p1 = da::pair_by_place(moved_now, row_then, 1.0f);
|
||||
CHECK("a moving copy among static ones: its own pairing", same(p1, {0, 1, 2}));
|
||||
CHECK("a moving copy among static ones: sure", same_c(da::ambiguous_by_place(moved_now, row_then, p1), {0, 0, 0}));
|
||||
// (2) the same copies drawn in another order, none moved
|
||||
const std::vector<P> swapped_now = {{{20, 0, 0}, 0}, {{0, 0, 0}, 1}, {{10, 0, 0}, 2}};
|
||||
const auto p2 = da::pair_by_place(swapped_now, row_then, 1.0f);
|
||||
CHECK("static copies, draw order swapped: each its own", same(p2, {2, 0, 1}));
|
||||
CHECK("static copies, draw order swapped: sure", same_c(da::ambiguous_by_place(swapped_now, row_then, p2), {0, 0, 0}));
|
||||
// ... and with one of them moving too
|
||||
const std::vector<P> both_now = {{{20, 0, 0}, 0}, {{0.4f, 0, 0}, 1}, {{10, 0, 0}, 2}};
|
||||
const auto p2b = da::pair_by_place(both_now, row_then, 1.0f);
|
||||
CHECK("swapped and one moving: its own", same(p2b, {2, 0, 1}) &&
|
||||
same_c(da::ambiguous_by_place(both_now, row_then, p2b), {0, 0, 0}));
|
||||
// (3) the ambiguous cases: copies at one place; one in the middle of two; two now at one place of one before
|
||||
const std::vector<P> stacked = {{{5, 5, 5}, 0}, {{5, 5, 5}, 1}};
|
||||
CHECK("copies at one place: both flagged",
|
||||
same_c(da::ambiguous_by_place(stacked, stacked, da::pair_by_place(stacked, stacked, 1.0f)), {1, 1}));
|
||||
const std::vector<P> two_then = {{{0, 0, 0}, 0}, {{0.3f, 0, 0}, 1}}, middle_now = {{{0.15f, 0, 0}, 0}};
|
||||
CHECK("about equally near two before: flagged",
|
||||
same_c(da::ambiguous_by_place(middle_now, two_then, da::pair_by_place(middle_now, two_then, 1.0f)), {1}));
|
||||
const std::vector<P> one_then = {{{5, 5, 5}, 0}};
|
||||
CHECK("two now at the place of one before: the paired one flagged",
|
||||
same_c(da::ambiguous_by_place(stacked, one_then, da::pair_by_place(stacked, one_then, 1.0f)), {1, 0}));
|
||||
CHECK("no pair, nothing to flag", same_c(da::ambiguous_by_place(moved_now, {}, {-1, -1, -1}), {0, 0, 0}) &&
|
||||
da::ambiguous_by_place({}, {}, {}).empty());
|
||||
// the doubt limit's factor (kTieFactor 2): a near tie, flagged at 2 and not at 1; a far second copy, never flagged
|
||||
const std::vector<P> tie_then = {{{0, 0, 0}, 0}, {{2.8f, 0, 0}, 1}}, tie_now = {{{1, 0, 0}, 0}};
|
||||
const auto p_tie = da::pair_by_place(tie_now, tie_then, 3.0f);
|
||||
CHECK("a near tie (1.0 moved, another 1.8 away): flagged",
|
||||
same(p_tie, {0}) && same_c(da::ambiguous_by_place(tie_now, tie_then, p_tie), {1}));
|
||||
const std::vector<P> far_then = {{{0, 0, 0}, 0}, {{11, 0, 0}, 1}};
|
||||
const auto p_far = da::pair_by_place(tie_now, far_then, 3.0f);
|
||||
CHECK("a far second copy (1.0 moved, another 10 away): sure",
|
||||
same(p_far, {0}) && same_c(da::ambiguous_by_place(tie_now, far_then, p_far), {0}));
|
||||
// a model over the cap: none placed by origin (all its copies take the camera's motion by unsure_copies), at the cap: placed
|
||||
{
|
||||
const auto no_before = [](uint64_t) { return false; };
|
||||
const auto build = [&](size_t n) {
|
||||
std::vector<uint64_t> keys;
|
||||
for (size_t i = 0; i < n; i++) keys.push_back(da::key(0x1000, 0x2000, 96, 0, 0xabc, (int)i % 256));
|
||||
return keys;
|
||||
};
|
||||
const auto count = [](const std::vector<char>& v) { size_t n = 0; for (char c : v) n += c != 0; return n; };
|
||||
const auto at_cap = build(da::kCopyCap), over_cap = build(da::kCopyCap + 1);
|
||||
CHECK("a model at the cap: all placed by origin",
|
||||
count(da::place_by_origin(at_cap, std::vector<char>(at_cap.size(), 1), no_before)) == at_cap.size());
|
||||
const auto over_placed = da::place_by_origin(over_cap, std::vector<char>(over_cap.size(), 1), no_before);
|
||||
CHECK("a model over the cap: none placed by origin", count(over_placed) == 0);
|
||||
const auto flagged = da::unsure_copies(over_cap, over_placed, no_before);
|
||||
CHECK("a model over the cap: all its copies flagged for the camera's motion", count(flagged) == over_cap.size());
|
||||
// (a single copy whose 2nd the frame before existed is placed; one whose origin is unreadable is not)
|
||||
const std::vector<uint64_t> one = {da::key(0x1000, 0x2000, 96, 0, 0xabc, 0)};
|
||||
const auto had_second = [&](uint64_t k) { return k == da::key(0x1000, 0x2000, 96, 0, 0xabc, 1); };
|
||||
CHECK("a lone copy with a 2nd before: placed", count(da::place_by_origin(one, {1}, had_second)) == 1);
|
||||
CHECK("a lone copy, no 2nd before: not", count(da::place_by_origin(one, {1}, no_before)) == 0);
|
||||
CHECK("an unreadable origin: not placed", count(da::place_by_origin(one, {0}, had_second)) == 0);
|
||||
// the frame before's 2nd copy was not placed (origin unreadable): its copy is flagged, as without origins
|
||||
const auto not_placed = [](uint64_t) { return false; };
|
||||
const auto placed_second = [&](uint64_t k) { return had_second(k); };
|
||||
CHECK("a 2nd before that was not placed: flagged",
|
||||
same_c(da::lost_second_copy(one, {1}, had_second, not_placed), {1}));
|
||||
CHECK("a 2nd before that was placed: not flagged",
|
||||
same_c(da::lost_second_copy(one, {1}, had_second, placed_second), {0}));
|
||||
CHECK("no 2nd before, or not placed by origin: not flagged",
|
||||
same_c(da::lost_second_copy(one, {1}, no_before, not_placed), {0}) &&
|
||||
same_c(da::lost_second_copy(one, {0}, had_second, not_placed), {0}));
|
||||
}
|
||||
// the trace's numbers
|
||||
const da::Spread constant = da::origin_spread(stacked), spread = da::origin_spread(row_then);
|
||||
CHECK("origin spread: one place", constant.distinct == 1 && constant.max_gap == 0.0f);
|
||||
CHECK("origin spread: a row", spread.distinct == 3 && spread.min_gap == 10.0f && spread.max_gap == 20.0f);
|
||||
}
|
||||
|
||||
// a non-skinned draw's place: the translation of its 3x4 row-major world matrix, if that is one
|
||||
{
|
||||
const float good[12] = {0, 2, 0, 10, -2, 0, 0, 20, 0, 0, 3, 30}; // rotation-scale (rows 2, 2, 3 long)
|
||||
float o[3] = {-1, -1, -1};
|
||||
CHECK("a world matrix: its translation", da::object_place(good, o) && o[0] == 10 && o[1] == 20 && o[2] == 30);
|
||||
float m[12];
|
||||
const auto refused = [&](const char* name, int at, float v) {
|
||||
std::memcpy(m, good, sizeof m);
|
||||
m[at] = v;
|
||||
float r[3] = {-1, -1, -1};
|
||||
const bool no = !da::object_place(m, r) && r[0] == -1;
|
||||
if (!no) std::fprintf(stderr, "not refused: %s\n", name);
|
||||
return no;
|
||||
};
|
||||
CHECK("NaN refused", refused("nan", 1, std::nanf("")) && refused("nan translation", 7, std::nanf("")));
|
||||
CHECK("infinity refused", refused("inf", 11, INFINITY));
|
||||
CHECK("a huge translation refused", refused("huge", 3, 2e5f) && refused("huge neg", 11, -2e5f));
|
||||
std::memcpy(m, good, sizeof m);
|
||||
m[4] = m[5] = m[6] = 0;
|
||||
float r[3];
|
||||
CHECK("a zero row refused", !da::object_place(m, r));
|
||||
std::memcpy(m, good, sizeof m);
|
||||
m[0] = m[1] = m[2] = 0;
|
||||
m[0] = 1, m[1] = 1.0f; // row 0 (1,1,0) against row 1 (-2,0,0): 45 degrees
|
||||
CHECK("skewed rows refused", !da::object_place(m, r));
|
||||
const float k = 0.70710678f;
|
||||
const float rs[12] = {k, -3 * k, 0, 10, k, 3 * k, 0, 20, 0, 0, 1, 30}; // R(45 deg) * diag(1,3,1): columns orthogonal, rows skewed
|
||||
const float sr[12] = {k, -k, 0, 10, 3 * k, 3 * k, 0, 20, 0, 0, 1, 30}; // diag(1,3,1) * R: rows orthogonal, columns skewed
|
||||
CHECK("R*S (orthogonal columns) accepted", da::object_place(rs, r) && r[0] == 10 && r[1] == 20 && r[2] == 30);
|
||||
CHECK("S*R (orthogonal rows) accepted", da::object_place(sr, r) && r[2] == 30);
|
||||
const float both[12] = {1, 1, 0, 10, 0, 1, 0, 20, 0, 0, 1, 30}; // rows and columns both skewed 45 degrees
|
||||
CHECK("skewed in rows and columns refused", !da::object_place(both, r));
|
||||
// (a short axis alone, kAxisMin: a diagonal matrix is orthogonal both ways, so only the length refuses it)
|
||||
const float tiny[12] = {0, 2, 0, 10, -2, 0, 0, 20, 0, 0, 1e-5f, 30};
|
||||
CHECK("a 1e-5 row and column refused for length only", !da::object_place(tiny, r));
|
||||
const float shortrow[12] = {2, 0, 0, 10, 0, 1e-5f, 0, 20, 0, 0, 2, 30};
|
||||
CHECK("a short axis refused", !da::object_place(shortrow, r));
|
||||
const float okdiag[12] = {2, 0, 0, 10, 0, 1e-3f, 0, 20, 0, 0, 2, 30};
|
||||
CHECK("the same with the axis over kAxisMin accepted", da::object_place(okdiag, r));
|
||||
// (copies sharing one matrix have one place: stacked, so none is sure and all keep the camera's motion)
|
||||
std::vector<da::Placed> same(3);
|
||||
for (auto& c : same) da::object_place(good, c.place);
|
||||
const auto pr = da::pair_by_place(same, same, 1.0f);
|
||||
const auto amb = da::ambiguous_by_place(same, same, pr);
|
||||
CHECK("identical origins: unsure", amb.size() == 3 && amb[0] && amb[1] && amb[2]);
|
||||
}
|
||||
|
||||
// a draw's place: its origin plus its bones' mean translation (copies at one origin, placed by their bones, differ)
|
||||
const auto pose_of = [](float ox, float oy, float oz, std::vector<std::array<float, 3>> moves) {
|
||||
std::vector<uint8_t> p(16 + moves.size() * 48, 0);
|
||||
|
||||
Reference in New Issue
Block a user