mirror of
https://git.triforceproject.com/triforce/source
synced 2026-12-01 05:18:50 -04:00
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.
310 lines
24 KiB
C++
310 lines
24 KiB
C++
#include "../gpu/vk/dlss_actor.h"
|
|
|
|
#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)
|
|
|
|
int main() {
|
|
namespace da = dlss_actor;
|
|
// names: the same draw keeps its name, another draw of the same model is the next one, another model another name
|
|
const uint64_t a0 = da::key(0x1000, 0x2000, 9702, 0, 0xabc, 0), a1 = da::key(0x1000, 0x2000, 9702, 0, 0xabc, 1);
|
|
CHECK("the same draw, the same name", a0 == da::key(0x1000, 0x2000, 9702, 0, 0xabc, 0));
|
|
CHECK("the second draw of a model is another", a0 != a1 && da::same_model(a0, a1));
|
|
CHECK("another model", !da::same_model(a0, da::key(0x1000, 0x2000, 9702, 3, 0xabc, 0)) &&
|
|
!da::same_model(a0, da::key(0x1040, 0x2000, 9702, 0, 0xabc, 0)) &&
|
|
!da::same_model(a0, da::key(0x1000, 0x2000, 9702, 0, 0xabd, 0)));
|
|
CHECK("many draws of one model", da::same_model(a0, da::key(0x1000, 0x2000, 9702, 0, 0xabc, 900)));
|
|
|
|
// where a draw's indices start for the shader, which reads 32-bit words: the address 4-aligned down, the first index in it
|
|
uint64_t at = 0;
|
|
uint32_t first = 0;
|
|
da::index_start(0x10002, 1, &at, &first);
|
|
CHECK("16-bit at +2: the second half of the word", at == 0x10000 && first == 1);
|
|
da::index_start(0x10003, 0, &at, &first);
|
|
CHECK("8-bit at +3: the fourth byte", at == 0x10000 && first == 3);
|
|
da::index_start(0x10008, 2, &at, &first);
|
|
CHECK("32-bit, aligned", at == 0x10008 && first == 0);
|
|
da::index_start(0x10004, 1, &at, &first);
|
|
CHECK("16-bit, aligned", at == 0x10004 && first == 0);
|
|
// (a set's joint and weight count in Push::formats: Link's four, five or six bones a vertex, two, and rigid parts)
|
|
const uint32_t five = da::count_code(4) << da::kCountShift | da::count_code(1) << (da::kCountShift + 2);
|
|
CHECK("four, then one", da::set_count(five, 0) == 4 && da::set_count(five, 1) == 1);
|
|
const uint32_t two = da::kByteJoints | da::count_code(2) << da::kCountShift;
|
|
CHECK("two, 8-bit joints", da::set_count(two, 0) == 2 && (two & da::kByteJoints));
|
|
CHECK("the count bits clear of the others",
|
|
!((da::count_code(2) << da::kCountShift | da::count_code(2) << (da::kCountShift + 2)) &
|
|
(da::kHalfPosition | da::kByteJoints | da::kByteJoints << 1 | da::kRigid)));
|
|
CHECK("no other counts", da::count_code(3) == 3 && da::set_count(3u << da::kCountShift, 0) == 0);
|
|
|
|
// capture motion: an indexed draw's vertices are its least index to its greatest (the restart index none of them)
|
|
uint32_t lo = 0, hi = 0;
|
|
const uint16_t strip[] = {7, 3, 9, 0xffff, 4, 12};
|
|
CHECK("16-bit, restart on", da::index_range(strip, 6, 1, true, &lo, &hi) && lo == 3 && hi == 12);
|
|
CHECK("16-bit, restart off: all ones is a vertex", da::index_range(strip, 6, 1, false, &lo, &hi) && lo == 3 && hi == 0xffff);
|
|
const uint8_t bytes[] = {200, 5, 255, 17};
|
|
CHECK("8-bit", da::index_range(bytes, 4, 0, true, &lo, &hi) && lo == 5 && hi == 200);
|
|
const uint32_t words[] = {100000, 99999, 0xffffffffu};
|
|
CHECK("32-bit", da::index_range(words, 3, 2, true, &lo, &hi) && lo == 99999 && hi == 100000);
|
|
const uint16_t cuts[] = {0xffff, 0xffff};
|
|
CHECK("only restarts: none", !da::index_range(cuts, 2, 1, true, &lo, &hi) && !da::index_range(strip, 0, 1, true, &lo, &hi));
|
|
CHECK("no such index type", !da::index_range(strip, 6, 3, true, &lo, &hi));
|
|
// its slots: from base vertex + least index, as many as the indices span; a vertex array's from its first, count of them
|
|
uint32_t n = 0;
|
|
CHECK("indexed", da::capture_span(1, 6, 1000, 3, 12, 1u << 20, &first, &n) && first == 1003 && n == 10);
|
|
CHECK("a vertex array", da::capture_span(da::kNoIndices, 36, 250, 0, 0, 1u << 20, &first, &n) && first == 250 && n == 36);
|
|
CHECK("too many", !da::capture_span(2, 3, 0, 0, 1u << 20, 1u << 20, &first, &n));
|
|
CHECK("nothing", !da::capture_span(da::kNoIndices, 0, 0, 0, 0, 1u << 20, &first, &n) &&
|
|
!da::capture_span(1, 6, 0, 5, 4, 1u << 20, &first, &n));
|
|
CHECK("a negative base vertex", da::capture_span(1, 3, -4, 6, 9, 64, &first, &n) && first == 2 && n == 4);
|
|
// a vertex's slot, as the stages take it: VertexIndex - first, unsigned, below the count
|
|
uint32_t slot = 0;
|
|
CHECK("the first and the last", da::capture_slot(1003, 1003, 10, &slot) && slot == 0 && da::capture_slot(1012, 1003, 10, &slot) &&
|
|
slot == 9);
|
|
CHECK("past the last", !da::capture_slot(1013, 1003, 10, &slot));
|
|
CHECK("before the first wraps past the count", !da::capture_slot(1002, 1003, 10, &slot));
|
|
CHECK("index 9 with base vertex -4: the last slot", da::capture_slot(-4 + 9, (uint32_t)(-4 + 6), 4, &slot) && slot == 3);
|
|
// the frame before's position without its jitter: the jitter is the projection's, x + jitter * w
|
|
float p[4] = {0.5f + 0.01f * 2.0f, -0.25f - 0.02f * 2.0f, 0.7f, 2.0f};
|
|
const float jitter[2] = {0.01f, -0.02f};
|
|
da::unjitter_position(p, jitter);
|
|
CHECK("unjittered", p[0] > 0.4999f && p[0] < 0.5001f && p[1] > -0.2501f && p[1] < -0.2499f && p[2] == 0.7f && p[3] == 2.0f);
|
|
CHECK("the push constants", sizeof(da::CapturePush) == 48 && sizeof(da::CapturePush) <= sizeof(da::Push));
|
|
// a draw's own camera's jitter: the projection's third column, negated; none from what is not a perspective projection
|
|
float proj[16] = {1.5f, 0, -0.0004f, 0, 0, 2.6f, 0.0007f, 0, 0, 0, -1.0002f, -0.2f, 0, 0, -1, 0};
|
|
float own[2] = {9, 9};
|
|
CHECK("a jittered projection", da::camera_jitter(proj, own) && own[0] == 0.0004f && own[1] == -0.0007f);
|
|
proj[2] = proj[6] = 0.0f;
|
|
CHECK("one without jitter", da::camera_jitter(proj, own) && own[0] == 0.0f && own[1] == 0.0f);
|
|
proj[14] = 0.0f, proj[15] = 1.0f;
|
|
CHECK("an orthographic one: not taken", !da::camera_jitter(proj, own));
|
|
proj[14] = -1.0f, proj[15] = 0.0f, proj[2] = 0.5f;
|
|
CHECK("an off-centre one: not a jitter", !da::camera_jitter(proj, own));
|
|
CHECK("the cameras' buffer holds its words", da::kJitterBeforeWord + 2 <= da::kHeadWords && da::kToleranceWord < da::kJitterBeforeWord);
|
|
|
|
// copies of a model pair with the frame before's copies by place, all at once, the nearest pairs first, within a reach
|
|
using P = da::Placed;
|
|
const auto same = [](const std::vector<int>& a, std::vector<int> b) { return a == b; };
|
|
// (the four Gossip Stones: 2.3 units apart in a row, still)
|
|
const std::vector<P> stones = {{{39.4f, 102.8f, -11.9f}, 0}, {{39.4f, 102.8f, -9.6f}, 1}, {{39.4f, 102.8f, -7.3f}, 2},
|
|
{{39.4f, 102.8f, -5.0f}, 3}};
|
|
CHECK("still copies in the same order: themselves", same(da::pair_by_place(stones, stones, 1.0f), {0, 1, 2, 3}));
|
|
const std::vector<P> turned = {stones[2], stones[0], stones[3], stones[1]};
|
|
CHECK("still copies drawn in another order: themselves", same(da::pair_by_place(turned, stones, 1.0f), {2, 0, 3, 1}));
|
|
// (run C, 19.58 s: the first stone comes into view; the frame before had the other three only)
|
|
const std::vector<P> three = {{{39.4f, 102.8f, -9.6f}, 0}, {{39.4f, 102.8f, -7.3f}, 1}, {{39.4f, 102.8f, -5.0f}, 2}};
|
|
CHECK("a copy new in view takes no neighbour's place", same(da::pair_by_place(stones, three, 1.0f), {-1, 0, 1, 2}));
|
|
CHECK("... nor with a reach wider than the row", same(da::pair_by_place(stones, three, 100.0f), {-1, 0, 1, 2}));
|
|
// (a stone drawn by the other model in the frame before: this model's only copy then is another stone)
|
|
const std::vector<P> lone_now = {stones[3]}, lone_then = {stones[1]};
|
|
CHECK("a lone copy further than the reach: none", same(da::pair_by_place(lone_now, lone_then, 1.0f), {-1}));
|
|
const std::vector<P> moved = {{{39.9f, 102.8f, -5.2f}, 0}};
|
|
CHECK("a lone copy that moved a little: it", same(da::pair_by_place(moved, lone_now, 1.0f), {0}));
|
|
// (two of one model passing each other, drawn in the other order than the frame before)
|
|
const std::vector<P> walkers_then = {{{0.1f, 0, 0}, 0}, {{0.4f, 0, 0}, 1}}, walkers_now = {{{0.5f, 0, 0}, 0}, {{0.0f, 0, 0}, 1}};
|
|
CHECK("two passing each other: each itself", same(da::pair_by_place(walkers_now, walkers_then, 1.0f), {1, 0}));
|
|
// (two of one model 0.6 apart, both moving 0.35 and drawn in the same order: the first's new place is nearest the
|
|
// second's old one, and nearest first alone would swap them. By draw order 0.35 each, against 0.25 and 0.95)
|
|
const std::vector<P> pair_then = {{{0.0f, 0, 0}, 0}, {{0.6f, 0, 0}, 1}}, pair_now = {{{0.35f, 0, 0}, 0}, {{0.95f, 0, 0}, 1}};
|
|
CHECK("two moving fast for their spacing, in draw order: each itself",
|
|
same(da::pair_by_place(pair_now, pair_then, 1.0f), {0, 1}));
|
|
// (0.9 apart, both moving 0.5: nearest first pairs only one, the first's new place with the second's old one at 0.4,
|
|
// and leaves the other 1.4 away, past the reach. Draw order pairs both at 0.5: more pairs win over a smaller total)
|
|
const std::vector<P> wide_then = {{{0.0f, 0, 0}, 0}, {{0.9f, 0, 0}, 1}}, wide_now = {{{0.5f, 0, 0}, 0}, {{1.4f, 0, 0}, 1}};
|
|
CHECK("draw order pairing more copies wins over nearest first's smaller total",
|
|
same(da::pair_by_place(wide_now, wide_then, 1.0f), {0, 1}));
|
|
// (a stone changes model: the frame before's copies of this model were the first two stones, this frame's are the second
|
|
// and third. Within the reach actor_motion keeps at the most (2), the second stone is itself and the third has none; with
|
|
// a reach past the stones' 2.3, draw order pairs two to nearest first's one and moves both toward their neighbour)
|
|
const std::vector<P> row_then = {stones[0], stones[1]}, row_now = {{{39.4f, 102.8f, -9.6f}, 0}, {{39.4f, 102.8f, -7.3f}, 1}};
|
|
CHECK("a row whose model changed, within a reach of 2: itself and none",
|
|
same(da::pair_by_place(row_now, row_then, 2.0f), {1, -1}));
|
|
CHECK("... and past the stones' spacing, each takes its neighbour (why the reach is capped)",
|
|
same(da::pair_by_place(row_now, row_then, 3.3f), {0, 1}));
|
|
// (the same geometry drawn twice for one object: both copies at one place, each keeps its own n-th)
|
|
const std::vector<P> twice = {{{5, 5, 5}, 0}, {{5, 5, 5}, 1}}, twice_swapped = {{{5, 5, 5}, 1}, {{5, 5, 5}, 0}};
|
|
CHECK("a tie at one place: the same n-th", same(da::pair_by_place(twice, twice, 1.0f), {0, 1}) &&
|
|
same(da::pair_by_place(twice, twice_swapped, 1.0f), {1, 0}));
|
|
const std::vector<P> once = {{{5, 5, 5}, 0}};
|
|
CHECK("a tie at one place, its own n-th gone: the other", same(da::pair_by_place(once, {twice[1]}, 1.0f), {0}));
|
|
const std::vector<P> lost = {{{std::nanf(""), 0, 0}, 0}};
|
|
CHECK("a place that is not finite: none", same(da::pair_by_place(lost, once, 1.0f), {-1}));
|
|
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);
|
|
const float o[4] = {ox, oy, oz, 0.0f};
|
|
std::memcpy(p.data(), o, sizeof o);
|
|
for (size_t b = 0; b < moves.size(); b++) {
|
|
const float m[12] = {1, 0, 0, moves[b][0], 0, 1, 0, moves[b][1], 0, 0, 1, moves[b][2]};
|
|
std::memcpy(p.data() + 16 + b * 48, m, sizeof m);
|
|
}
|
|
return p;
|
|
};
|
|
float place[3];
|
|
const auto by_origin = pose_of(100, 0, 5, {{0, 0, 0}, {0, 2, 0}});
|
|
da::place_of(by_origin.data(), by_origin.data() + 16, 2, place);
|
|
CHECK("placed by its origin", place[0] == 100 && place[1] == 1 && place[2] == 5);
|
|
const auto by_bones = pose_of(0, 0, 0, {{300, 0, 7}, {300, 4, 7}});
|
|
da::place_of(by_bones.data(), by_bones.data() + 16, 2, place);
|
|
CHECK("placed by its bones, at a shared origin", place[0] == 300 && place[1] == 2 && place[2] == 7);
|
|
auto bad = pose_of(10, 0, 0, {{2, 0, 0}, {0, 0, 0}});
|
|
const float nan = std::nanf("");
|
|
std::memcpy(bad.data() + 16 + 48 + 3 * 4, &nan, 4);
|
|
da::place_of(bad.data(), bad.data() + 16, 2, place);
|
|
CHECK("a bone that is not finite is left out", place[0] == 12 && place[1] == 0);
|
|
da::place_of(by_origin.data(), by_origin.data() + 16, 0, place);
|
|
CHECK("no bones: the origin", place[0] == 100 && place[1] == 0 && place[2] == 5);
|
|
std::puts("dlss_actor: ok");
|
|
return 0;
|
|
}
|