feat(assets): read retail assets through the vendored libra3assets library

Vendor libra3assets (C++26 modules: BIG4, RefPack, BinaryAsset, CSF, CkMp map)
under third_party/ and add the ra3_assets target. ra3.fs, ra3.map and ra3.terrain
become thin adapters over it:

- ra3.fs delegates RefPack and the BIG4 index/payload reads (index-only, payloads
  read on demand).
- ra3.map decodes ObjectsList and CSF via map_document/csf_table; starts come from
  player_starts(), replacing the off-by-one whole-buffer scan.
- ra3.terrain takes the CkMp container and HeightMapData from map_document, with
  BlendTileData (not modelled by the library) parsed from the chunk payload.

Adds an opt-in real-asset check (OPENRA3_TEST_ASSETS) plus the library's own unit
suite as ra3assets_unit.
This commit is contained in:
EnderTheCoder
2026-09-29 23:58:13 +08:00
parent 8047e80ed6
commit 23f8be394c
17 changed files with 3078 additions and 519 deletions
+35 -4
View File
@@ -196,6 +196,25 @@ target_sources(ra3_enderlog PUBLIC FILE_SET CXX_MODULES FILES third_party/libend
target_compile_features(ra3_enderlog PUBLIC cxx_std_26)
openra3_target_defaults(ra3_enderlog)
# --- RA3 built-in asset containers (vendored libra3assets) --------------------
# Reader/writer for the files the retail game ships: `BIG4` archives, the EA
# RefPack codec, SAGE `.csf` string tables and `.map` (`CkMp`) containers, plus
# the compiled `BinaryAsset` streams. A sibling of libenderlog: C++26 modules
# (`import ra3.assets;`) importing the standard library. It owns the on-disk
# format knowledge, so `ra3.fs` / `ra3.map` / `ra3.terrain` become thin adapters.
add_library(ra3_assets STATIC)
target_sources(ra3_assets PUBLIC FILE_SET CXX_MODULES FILES
third_party/libra3assets/src/assets.cppm
third_party/libra3assets/src/error.cppm
third_party/libra3assets/src/bytes.cppm
third_party/libra3assets/src/refpack.cppm
third_party/libra3assets/src/big.cppm
third_party/libra3assets/src/binary.cppm
third_party/libra3assets/src/csf.cppm
third_party/libra3assets/src/map.cppm)
target_compile_features(ra3_assets PUBLIC cxx_std_26)
openra3_target_defaults(ra3_assets)
# --- engine core -------------------------------------------------------------
add_library(ra3_core STATIC)
target_sources(ra3_core PUBLIC FILE_SET CXX_MODULES FILES src/core/ra3.core.cppm)
@@ -225,16 +244,16 @@ target_sources(ra3_game PUBLIC FILE_SET CXX_MODULES FILES src/game/ra3.game.cppm
target_link_libraries(ra3_game PUBLIC ra3_core ra3_logic)
openra3_target_defaults(ra3_game)
# --- filesystem: BIG4 + RefPack ---------------------------------------------
# --- filesystem: BIG4 + RefPack (adapter over libra3assets) -------------------
add_library(ra3_fs STATIC)
target_sources(ra3_fs PUBLIC FILE_SET CXX_MODULES FILES src/fs/ra3.fs.cppm)
target_link_libraries(ra3_fs PUBLIC ra3_core)
target_link_libraries(ra3_fs PUBLIC ra3_core ra3_assets)
openra3_target_defaults(ra3_fs)
# --- map discovery/loading ---------------------------------------------------
add_library(ra3_map STATIC)
target_sources(ra3_map PUBLIC FILE_SET CXX_MODULES FILES src/map/ra3.map.cppm)
target_link_libraries(ra3_map PUBLIC ra3_core ra3_fs)
target_link_libraries(ra3_map PUBLIC ra3_core ra3_fs ra3_assets)
openra3_target_defaults(ra3_map)
# --- minimal skirmish simulation --------------------------------------------
@@ -252,7 +271,7 @@ openra3_target_defaults(ra3_render)
# --- real map terrain (HeightMapData / BlendTileData) ------------------------
add_library(ra3_terrain STATIC)
target_sources(ra3_terrain PUBLIC FILE_SET CXX_MODULES FILES src/terrain/ra3.terrain.cppm)
target_link_libraries(ra3_terrain PUBLIC ra3_core ra3_fs ra3_render)
target_link_libraries(ra3_terrain PUBLIC ra3_core ra3_fs ra3_render ra3_assets)
openra3_target_defaults(ra3_terrain)
# --- map static art (compiled W3D meshes) ------------------------------------
@@ -580,3 +599,15 @@ add_executable(ra3_tests tests/ra3_tests.cpp)
target_link_libraries(ra3_tests PRIVATE ra3)
openra3_target_defaults(ra3_tests)
add_test(NAME ra3_tests COMMAND ra3_tests)
# libra3assets' own dependency-free unit tests (RefPack + BIG4 + BinaryAsset +
# CSF + CkMp round-trips), built against the vendored copy so the upstream
# suite keeps guarding the readers OpenRA3 now relies on.
add_executable(ra3assets_unit
third_party/libra3assets/tests/test_main.cpp
third_party/libra3assets/tests/test_assets.cpp)
target_include_directories(ra3assets_unit PRIVATE third_party/libra3assets/tests)
target_link_libraries(ra3assets_unit PRIVATE ra3_assets)
target_compile_features(ra3assets_unit PRIVATE cxx_std_26)
openra3_target_defaults(ra3assets_unit)
add_test(NAME ra3assets_unit COMMAND ra3assets_unit)