port 2A step 4: platform skeleton + rest of the 2V3 header closure

- Mirror the remaining non-Python 2V3 closure headers (98 more, 173 total): EffectLib,
  EterGrnLib, SpeedTreeLib, SphereLib, PRTerrainLib, EterImageLib, EterBase/Poly, cipher/tea,
  EterLib Grp*/IME/Input/MSWindow/StateManager, GameLib actor/map/race headers, EterPack.
- SDK shims: granny.h, SpeedTreeRT.h, imm.h, Dimm.h (the SDK MIDL header, not mirrored),
  dinput/d3dx8 additions; D3D8 render-state enums, FVF macros and the COM resource hierarchy;
  more Win32 GDI/handle types with layout static_asserts.
- PORT edits for MSVC-permissive code (typename, friend visibility, <algorithm>, pointer→uintptr_t)
  and PRTerrainLib/StdAfx.h dropping the ScriptLib/Python include.
- port_logic links the vendored cryptopp/minilzo.
- extension/src/platform: port_platform target with 103 generated stub files (1917 function
  stubs, 146 static members) from the new platform_stub.py (clang -ast-dump-filter);
  MT_PLATFORM_STUB() marks every unimplemented body. libmtgodot links port_platform and
  port_gate.sh builds it.

Gate: macOS, Android, iOS, Windows (mingw) PASS; Linux BLOCKED (no toolchain).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-22 21:46:24 +09:00
co-authored by Claude Opus 5
parent fc47582017
commit 9a8e11f3dd
220 changed files with 24287 additions and 25 deletions
+35 -10
View File
@@ -80,7 +80,7 @@ extension/third_party/cpython-2.7.18/ # 静态库(2P 批次
| 0 | 工具:参考根解析、`port_map.py`、构建/测试入口 | 完成(55f733fd、5afd5a4f |
| 1 | 删除运行时不加载的 106 个 `*_system.gd` 及其测试 | 完成(a989b8f1 |
| — | 定下目录结构,评估内嵌 Python;Android 独立程序验证 | 完成(9d0e50de、b02c49bb |
| **2A** | 基础:Win32 类型层、参考公共头的最小闭包、`port_logic` CMake 目标、platform 接口骨架、头文件可编译门禁、port-map 重新基线 | **下一步** |
| **2A** | 基础:Win32 类型层、参考公共头的最小闭包、`port_logic` CMake 目标、platform 接口骨架、头文件可编译门禁、port-map 重新基线 | **进行中**(剩 Python 库闭包头、port-map 基线) |
| **2R** | 资源包能力盘点:EPK 类型/密钥/覆盖顺序/路径大小写/移动端交付 | **下一步**,可与 2A 并行(只读分析 + 独立工具) |
| 2P | CPython 2.7.18 编进 libmtgodot,五个平台分别配置和验证 | 2A 之后 |
| 2D | 数据源切到 40250msm 路径、proto、资源根、严格资源测试) | proto 部分在 2A 之后;资源根在 2R 之后 |
@@ -142,25 +142,50 @@ extension/third_party/cpython-2.7.18/ # 静态库(2P 批次
后续单元用到新函数时再按需补。
测试在 `port.common` 里。
- 已完成(步骤 2,不含依赖 Python 的库):闭包头文件照抄,76 个,覆盖 EterBase、EterLocale、EterPack、EterLib
GameLib、MilesLib、EffectLib、SphereLib、EterImageLib
- 已完成(步骤 2,不含依赖 Python 的库):2V3 切片闭包里的头文件照抄,共 173 个,覆盖 EterBase(含 `Poly/`
EterLocale、EterPack、EterLib、GameLib、MilesLib、EffectLib、EterGrnLib、SpeedTreeLib、SphereLib、PRTerrainLib
EterImageLib。
- 门禁中每个头文件前先 include 本库的 `StdAfx.h`40250 把它作为预编译头)。
- D3D8 的值类型(`D3DFORMAT``D3DCAPS8``D3DLIGHT8``D3DMATERIAL8` 等,按 SDK 取值和布局并加 `static_assert`
放在 `port/common/D3D8Types.h`COM 接口(`IDirect3DDevice8` 等)只做不透明声明,由 platform 持有。
- 手工 `// PORT:` 修改共 6 个文件:
- D3D8 的值类型(`D3DFORMAT``D3DCAPS8``D3DLIGHT8``D3DMATERIAL8`、渲染状态/变换/纹理阶段枚举、`D3DFVF_*` 等,
按 SDK 取值和布局并加 `static_assert`放在 `port/common/D3D8Types.h`COM 接口(`IDirect3DDevice8`、纹理/表面/
缓冲区的继承层次等)只做不透明声明,由 platform 持有。
- 第三方 SDK 头由 `shim/sdk/` 提供不透明替身:`granny.h`Granny 2.11 的标量和 `granny_data_type_definition`)、
`SpeedTreeRT.h``CSpeedTreeRT` 只声明头文件里用到的嵌套类型和方法)、`d3dx8.h`(加 `ID3DXMatrixStack`
`D3DX_FILTER_*`)。`EterLib/Dimm.h` 是 SDK `dimm.h` 的 MIDL 输出,按 SDK 头处理:不进镜像,由 `shim/win32/Dimm.h`
(连同 `imm.h``dinput.h`)提供。
- `EterBase/cipher.h` 用 Crypto++`EterBase/lzo.h` 用 LZO`port_logic` 链接已 vendor 的 `mt3p::cryptopp`
`mt3p::minilzo`;单独构建时顶层 CMake 先加入 `extension/third_party`
- 手工 `// PORT:` 修改共 10 个文件(`port_copy.py diff` 列出):
- `Random.h``random`/`srandom` 与 POSIX 重名,改名;
- `Singleton.h``(int)` 指针运算改为 `intptr_t`
- `Pool.h``operator new(unsigned int)` 改为 `size_t`
- `Pool.h``operator new(unsigned int)` 改为 `size_t``<algorithm>`MSVC 头文件间接带入 `std::find`);
- `Stl.h``<SSTREAM>` 改为小写;
- `Utils.h`:补 `<math.h>`
- `FlyTarget.h`:补 `CFlyTarget` 前置声明(MSVC 会让 friend 声明可见)
- `FlyTarget.h``EffectLib/ParticleSystemInstance.h`:补前置声明(MSVC 会让 friend 声明可见)
- `EffectLib/Type.h`:依赖名前补 `typename`
- `EffectLib/EffectUpdateDecorator.h`:指针转 `(DWORD)` 改为 `(uintptr_t)`
- `PRTerrainLib/StdAfx.h`:去掉 `#include "../ScriptLib/StdAfx.h"`PRTerrainLib 不用 Python,否则每个地形编译单元
都要 CPython 头)。
- 40250 StdAfx 里有影响语义的宏,移植逻辑时要注意:
- EterBase 的 `#define atoi _atoi64`
- UserInterface 的 `_USE_32BIT_TIME_T`
- `EterBase/ServiceDefs.h``_IMPROVED_PACKET_ENCRYPTION_`
- 工程字符集是 MultiByte,所以 `TCHAR` 就是 `char`
- 工程字符集是 MultiByte,所以 `TCHAR` 就是 `char`
- 非 Windows 上 `WCHAR` 是 32 位 `wchar_t`(Win32 是 16 位),只影响 IME 路径,移植 IME 时按 UTF-16 处理。
- ScriptLib、EterPythonLib、UserInterface 的 StdAfx 会 include Python 头,要等 2P 把 CPython 加进来之后再照抄。
- 完成:platform 接口骨架(步骤 4);依赖 Python 的三个库的闭包头(等 2P)。
- 完成(步骤 4platform 骨架 `extension/src/platform/`,目标 `port_platform`(静态库,链接 `port_logic`
libmtgodot 改为链接它;从 `port/CMakeLists.txt` 加入以共用每个库的编译宏;`port_gate.sh` 构建它)。
- 平台层头文件(同名 40250 `.cpp` 属于 platform 层,见 `port_map.py``LAYER_PATTERNS`)共 118 个,对应
`platform/<Lib>/<File>.cpp` 103 个(其余 15 个没有需要定义的东西),1917 个函数桩、146 个静态成员。
-`platform_stub.py gen` 生成:用 clang 对门禁编译单元按类名/函数名 `-ast-dump-filter` 导出声明,定义头文件里
声明了但没有定义的成员函数、构造/析构、自由函数和静态成员;返回类型写成尾置形式,使类内嵌套类型在类作用域里解析,
静态成员写成 `decltype(C::x) C::x{};`。已存在的文件不覆盖(除非 `--force`)。
- 函数体是 `MT_PLATFORM_STUB()` 加默认返回值(`platform/PlatformStub.h`);`grep -r MT_PLATFORM_STUB` 就是还没实现的
平台函数清单,设置环境变量 `MT_PLATFORM_STUB_TRACE` 后每个桩第一次被调用时打印到 stderr。
- 6 个构造函数手工补了与 40250 相同的初始化列表(基类 `CResource(c_szFileName)``CDecal` 的 const 成员)。
- 未覆盖:platform 层 `.cpp` 定义的**逻辑层头文件**成员(`GameLib/MapOutdoorRender*.cpp``MapOutdoorWater.cpp` 定义
`MapOutdoor.h` 的方法等)。这些在对应逻辑单元移植时手工补桩。
- 未完成:依赖 Python 的三个库的闭包头(等 2P);port-map 重新基线(步骤 6)。
| 平台 | port_gate |
| --- | --- |