"""Synthetic tests for tools/navmesh_nodes.py. No game files are read or needed. python -I tests/test_navmesh_nodes.py The navmesh tile comes from the builder in tests/test_navmesh_decode.py with its vertices and polygon flags filled in here, and the lane graph from the node-list builder in tests/test_world_lights_paths.py. """ import json import math import os import struct import subprocess import sys import tempfile import unittest ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(ROOT, "tools")) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import navmesh_decode as nd # noqa: E402 import navmesh_nodes as nn # noqa: E402 from test_navmesh_decode import build_0drp, build_navmesh, make_rpf # noqa: E402 from test_world_lights_paths import GRAPH_NODES, node_resource, write_rpf # noqa: E402 TOOL = os.path.join(ROOT, "tools", "navmesh_nodes.py") ROAD, OTHER = 0x2100, 0x1000 # +0x18 words of the two synthetic polygons (bits 8 + 13, and bit 12) MARK = 1 << 17 # +0x28 word of the first polygon def build_tile(squares, sector=(256 << 9) | 256, flags=1): """One navmesh tile whose polygons are axis-aligned squares. squares: [(x0, y0, x1, y1, z, flags18, flags28)] in metres from the tile's minimum corner (height 0..16). """ tile = bytearray(build_navmesh(flags=flags, sector=sector, n_verts=4 * len(squares), poly_sizes=(4,) * len(squares), n_links=0, n_link_idx=0, n_volumes=0)[0]) (vertex_at, _count), = nd.split_array(tile, 0x70, 6, 4 * len(squares)) (polygon_at, _count), = nd.split_array(tile, 0x98, 44, len(squares)) def q(value, extent): return round(value / extent * 65535) for i, (x0, y0, x1, y1, z, flags18, flags28) in enumerate(squares): for k, (x, y) in enumerate(((x0, y0), (x1, y0), (x1, y1), (x0, y1))): struct.pack_into("<3H", tile, vertex_at + 6 * (4 * i + k), q(x, 128.0), q(y, 128.0), q(z, 16.0)) struct.pack_into("