diff --git a/game/bin/x64/benchmark_cpu.ps1 b/game/bin/x64/benchmark_cpu.ps1 old mode 100644 new mode 100755 diff --git a/game/bin/x64/bsp_reader.py b/game/bin/x64/bsp_reader.py index d582017d..51b4c732 100644 --- a/game/bin/x64/bsp_reader.py +++ b/game/bin/x64/bsp_reader.py @@ -657,14 +657,13 @@ def read_face_side_ids(self) -> Optional[List[List[int]]]: # Each index entry is 8 bytes: int32 firstId, int32 numIds num_faces = len(idx_data) // 8 result: List[List[int]] = [] - for i in range(num_faces): - first_id, num_ids = struct.unpack_from(' List[BSPTexInfo]: @@ -703,8 +702,7 @@ def read_material_names(self) -> List[str]: """Read material names via texdata → string table → string data chain.""" table_data = self._get_lump_data(LUMP_TEXDATA_STRING_TABLE) table_count = len(table_data) // 4 - offsets = [struct.unpack_from(' Optional[Tuple[int, List[Tuple[int, int]], bytes]]: num_clusters = struct.unpack_from(' len(data): - break - pvs_ofs, pas_ofs = struct.unpack_from('<2i', data, ofs) - offsets.append((pvs_ofs, pas_ofs)) + + # Truncate to available cluster definitions in case of bad header + cluster_bytes = num_clusters * 8 + if 4 + cluster_bytes > len(data): + cluster_bytes = ((len(data) - 4) // 8) * 8 + num_clusters = cluster_bytes // 8 + + offsets = [ + (pvs_ofs, pas_ofs) + for pvs_ofs, pas_ofs in struct.iter_unpack('<2i', data[4:4 + cluster_bytes]) + ] return (num_clusters, offsets, data) def get_face_vertices(self, face: BSPFace, diff --git a/game/bin/x64/run_vrad_tests.ps1 b/game/bin/x64/run_vrad_tests.ps1 old mode 100644 new mode 100755 diff --git a/game/bin/x64/run_vvis_tests.ps1 b/game/bin/x64/run_vvis_tests.ps1 old mode 100644 new mode 100755 diff --git a/game/bin/x64/test_world_shadows.ps1 b/game/bin/x64/test_world_shadows.ps1 old mode 100644 new mode 100755 diff --git a/game/bin/x64/vrad_test_harness.ps1 b/game/bin/x64/vrad_test_harness.ps1 old mode 100644 new mode 100755 diff --git a/game/bin/x64/vvis_test_harness.ps1 b/game/bin/x64/vvis_test_harness.ps1 old mode 100644 new mode 100755 diff --git a/test_unpack_perf.py b/test_unpack_perf.py deleted file mode 100644 index 701aa67f..00000000 --- a/test_unpack_perf.py +++ /dev/null @@ -1,68 +0,0 @@ -import time -import struct -import random - -# Generate 1M bytes of fake lighting data -data = bytearray(random.getrandbits(8) for _ in range(1_000_000)) -luxel_count = 100_000 - -print("Benchmarking struct unpacking...") - -start = time.time() -sample_ofs = 0 -luminances = [] -lighting_slice = data[sample_ofs : sample_ofs + luxel_count * 4] -luminances = [ - (0.2126 * r + 0.7152 * g + 0.0722 * b) * (2.0 ** exp) - for r, g, b, exp in struct.iter_unpack('BBBb', lighting_slice) -] -end = time.time() -print(f"List comprehension + iter_unpack: {end-start:.4f}s") - - -start = time.time() -luminances2 = [] -for i in range(luxel_count): - ofs = sample_ofs + i * 4 - r, g, b, exp = struct.unpack_from('BBBb', data, ofs) - lum = (0.2126 * r + 0.7152 * g + 0.0722 * b) * (2.0 ** exp) - luminances2.append(lum) -end = time.time() -print(f"For loop + unpack_from: {end-start:.4f}s") - -# Test struct.unpack_from for nodes -node_count = 50000 -node_data = bytearray(random.getrandbits(8) for _ in range(node_count * 32)) - -start = time.time() -nodes = [] -for i in range(node_count): - ofs = i * 32 - vals = struct.unpack_from('<3i3h3h2Hh2x', node_data, ofs) - nodes.append({ - 'planenum': vals[0], - 'children': (vals[1], vals[2]), - 'mins': (vals[3], vals[4], vals[5]), - 'maxs': (vals[6], vals[7], vals[8]), - 'firstface': vals[9], - 'numfaces': vals[10], - 'area': vals[11], - }) -end = time.time() -print(f"Nodes For loop + unpack_from: {end-start:.4f}s") - -start = time.time() -nodes2 = [ - { - 'planenum': v[0], - 'children': (v[1], v[2]), - 'mins': (v[3], v[4], v[5]), - 'maxs': (v[6], v[7], v[8]), - 'firstface': v[9], - 'numfaces': v[10], - 'area': v[11], - } - for v in struct.iter_unpack('<3i3h3h2Hh2x', node_data) -] -end = time.time() -print(f"Nodes List comp + iter_unpack: {end-start:.4f}s")