Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/CockpitMeshLayoutTests.py

Source at documentation-generation time. See Test catalog for fixture associations.

1"""Check the production loader's vertex strides against every shipped cockpit."""
2from pathlib import Path
3import math
4import re
5import struct
6
7root = Path(__file__).resolve().parents[1]
8source = (root / "Viewscreen/cockpit.cpp").read_text()
9loader = source[source.index("int stride = 32L;"):source.index("// Vertices ---")]
10cases = re.findall(
11 r'case VehicleType::(\w+):.*?"(Meshes\\\\[^"\r\n]+\.DAW)"(.*?break;)',
12 loader, re.S)
13texture_limit = int(re.search(r"#define\s+cockpittextureC\s+(\d+)", (root / "Viewscreen/globals.h").read_text())[1])
14assert len(cases) == 18, "Cockpit loader cases changed; update layout coverage"
15
16for kind, filename, body in cases:
17 path = root / filename.replace("\\\\", "/")
18 data = path.read_bytes()
19 vertices, = struct.unpack_from("<H", data)
20 override = re.search(r"stride = (\d+)", body)
21 stride = int(override[1]) if override else 32
22 assert vertices > 0 and vertices % 3 == 0, (kind, "invalid triangle count")
23 # These cockpit exports contain a vertex count, packed vertices, and a
24 # trailing zero light count. A stale stride silently scrambles geometry.
25 assert len(data) == 4 + vertices * stride, (
26 kind, "DAW stride mismatch", stride, len(data), vertices)
27 assert data[-2:] == b"\0\0", (kind, "unexpected embedded lights")
28 for index in range(vertices):
29 assert all(map(math.isfinite, struct.unpack_from("<6f", data, 2 + index * stride))), (
30 kind, "non-finite position or normal", index)
31 dix = path.with_suffix(".dix").read_bytes()
32 components, = struct.unpack_from("<h", dix)
33 for index in range(components):
34 start, triangles = struct.unpack_from("<hh", dix, 99 + index * 100)
35 assert triangles >= 0 and (triangles == 0 or (start >= 0 and start + 3 * triangles <= vertices)), (
36 kind, "component outside vertex buffer", index, start, triangles)
37 texture, = struct.unpack_from("<h", dix, 143 + index * 100)
38 assert -1 <= texture < texture_limit, (kind, "component outside cockpit texture table", index, texture)
39 print(f"PASS: {kind}: {vertices} vertices, {stride}-byte stride, {components} bounded components")
SCRIPT_CONTROL SCRIPT_STATE const void int