skip to content
==> tests/doom.c <==
1/* A golden digest from the Rust (mesh-ref lib.rs): the map; 2000 keys from the start pose (each pose,
2 * and every column's ray and height every 50 keys); 5000 odd rays (random spots, any directions
3 * including NaN and subnormal ones, short step limits), heights and walkable tests. */
4#include "mesh/ref/doom.h"
5
6#include "mesh/abi/view_doom.h"
7#include "mesh/ftz.h"
8
9#include <stdio.h>
10
11static uint64_t fh(uint64_t h, uint64_t w) { return (h ^ w) * 0x100000001b3ull; }
12
13static uint32_t mix(uint32_t x) {
14    x ^= x >> 16;
15    x *= 0x7feb352du;
16    x ^= x >> 15;
17    x *= 0x846ca68bu;
18    return x ^ (x >> 16);
19}
20
21static uint32_t gen(uint32_t m, uint32_t i) {
22    uint32_t h = mix((i * 0x9e3779b9u) ^ (m * 0x85ebca6bu));
23    uint32_t h2 = mix(h ^ 0x27d4eb2fu);
24    if (m == 0) return h;
25    if (m == 1) return (h & 0x80000000u) | ((h2 % 41) << 23) | (h & 0x007fffffu);
26    return (h & 0x80000000u) | ((50 + h2 % 31) << 23) | (h & 0x007fffffu);
27}
28
29int main(void) {
30    uint64_t h = 0xcbf29ce484222325ull;
31    uint32_t map[256], side;
32    float d;
33    mesh_doom_map(map);
34    for (int c = 0; c < 256; c++) h = fh(h, map[c]);
35    static const char keys[] = "wsadqe";
36    mesh_doom_pose pose = mesh_doom_pose_start();
37    for (uint32_t i = 0; i < 2000; i++) {
38        uint8_t key = mix(i) % 7 == 6 ? 'x' : (uint8_t)keys[(mix(i) % 7) % 6];
39        mesh_doom_pose_apply(&pose, key);
40        for (int k = 0; k < 6; k++) h = fh(h, mesh_ftz_bits(pose.p[k]));
41        if (i % 50 == 0)
42            for (uint32_t c = 0; c < MESH_DOOM_WIDTH; c++) {
43                uint32_t k = mesh_doom_cast(map, pose.p[0], pose.p[1], pose.p[2], pose.p[3], pose.p[4], pose.p[5], c,
44                                            MESH_DOOM_MAX_STEPS, &side, &d);
45                h = fh(fh(fh(h, k), side), mesh_ftz_bits(d));
46                h = fh(h, mesh_ftz_bits(mesh_doom_height(k, d)));
47            }
48    }
49    for (uint32_t i = 0; i < 5000; i++) {
50        float r[8];
51        for (uint32_t j = 0; j < 8; j++) r[j] = mesh_ftz_from_bits(gen(j % 3, i * 8 + j));
52        float px = (float)(mix(i) % 1600) / 100.0f, py = (float)(mix(i ^ 77) % 1600) / 100.0f;
53        uint32_t k = mesh_doom_cast(map, px, py, r[2], r[3], r[4], r[5], mix(i) % 130, mix(i) % 70, &side, &d);
54        h = fh(fh(fh(h, k), side), mesh_ftz_bits(d));
55        h = fh(h, mesh_ftz_bits(mesh_doom_height(k, mesh_ftz_from_bits(gen(i % 3, i)))));
56        h = fh(h, (uint64_t)mesh_doom_walkable(r[6], r[7]) + 2 * (uint64_t)mesh_doom_walkable(px, py));
57    }
58    if (h != 0xe1672eb4fa54e885ull) {
59        fprintf(stderr, "doom %#018llx, want 0xe1672eb4fa54e885\n", (unsigned long long)h);
60        return 1;
61    }
62    return 0;
63}