AVA2 client Windows parity passes (gr2 BitKnit2/64-bit, GamePhase handlers, python modules)

- gr2: BitKnit2 decompression, 64-bit LE files, compressed curves
- net: remaining GamePhase handlers, generated GC packet table
- python: event/chat/chr/minimap/guild/quest/messenger/shop-search and
  other native modules ported against the AVA2 Windows client
- render: D3D8 fixed-function lighting in Gr2ModelRenderer, terrain
  without baked shade; cape/NPC equipment attachment
- tests + audits updated; docs/PORT-PLAN.md and WINDOWS-PARITY.md

Batch 4 (render pipeline: background.*, app.RenderGame/UpdateGame,
camera bindings, main.cpp fake-content removal) is still in progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-08 10:43:01 +09:00
co-authored by Claude Opus 5.5
parent 9f748eb05a
commit 9077aa389a
145 changed files with 22692 additions and 6584 deletions
+97 -27
View File
@@ -148,6 +148,51 @@ void Gr2ModelInstance::AttachPart(std::shared_ptr<Gr2ModelInstance> part) {
if (part) m_attached_parts.push_back(part);
}
void Gr2ModelInstance::DetachModel(const std::string& bone_name) {
m_attached_models.erase(std::remove_if(m_attached_models.begin(), m_attached_models.end(),
[&](const AttachedModel& am) { return am.bone_name == bone_name; }), m_attached_models.end());
}
void Gr2ModelInstance::DetachPart(const std::shared_ptr<Gr2ModelInstance>& part) {
m_attached_parts.erase(std::remove(m_attached_parts.begin(), m_attached_parts.end(), part), m_attached_parts.end());
}
void Gr2ModelInstance::SetAttachmentAnimated(const std::string& bone_name, bool animated) {
for (auto& am : m_attached_models)
if (am.bone_name == bone_name) am.animated = animated;
}
void Gr2ModelInstance::SetAttachmentScale(const std::string& bone_name, float sx, float sy, float sz) {
for (auto& am : m_attached_models) {
if (am.bone_name != bone_name) continue;
am.scaled = true;
am.scale[0] = sx; am.scale[1] = sy; am.scale[2] = sz;
}
}
namespace {
// CFileNameHelper::StringPath (lower case, '\\' -> '/'), the form CGrannyMaterial::IsIn compares.
std::string SkinKey(std::string path) {
for (auto& c : path) {
if (c == '\\') c = '/';
else if (static_cast<unsigned char>(c) < 128) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
}
return path;
}
} // namespace
void Gr2ModelInstance::SetSkin(const std::string& src_file_name, const std::string& dst_file_name) {
m_skins[SkinKey(src_file_name)] = dst_file_name;
}
void Gr2ModelInstance::ApplySkins(std::vector<Render3DDraw>& draws, size_t first) const {
if (m_skins.empty()) return;
for (size_t i = first; i < draws.size(); ++i) {
auto it = m_skins.find(SkinKey(draws[i].texture0));
if (it != m_skins.end()) draws[i].texture0 = it->second;
}
}
void Gr2ModelInstance::DetachAll() {
m_attached_models.clear();
m_attached_parts.clear();
@@ -306,6 +351,7 @@ std::vector<Render3DDraw> Gr2ModelInstance::BuildDrawCommandsWithPalette(const s
}
}
}
ApplySkins(draws, 0);
return draws;
}
@@ -435,6 +481,8 @@ std::vector<Render3DDraw> Gr2ModelInstance::BuildDrawCommands(float animation_ti
}
}
ApplySkins(draws, 0);
// 2. Build attached skinning parts (e.g. hair, armor) using current skin matrices
for (const auto& part : m_attached_parts) {
if (!part) continue;
@@ -461,6 +509,10 @@ std::vector<Render3DDraw> Gr2ModelInstance::BuildDrawCommands(float animation_ti
const auto& B = world_pose[bone_idx];
float attached_local[16];
MultiplyMat4(am.offset, B.data(), attached_local);
if (am.scaled) {
const float S[16] = {am.scale[0], 0, 0, 0, 0, am.scale[1], 0, 0, 0, 0, am.scale[2], 0, 0, 0, 0, 1};
MultiplyMat4(attached_local, S, attached_local);
}
float attached_engine[16];
MultiplyMat4(attached_local, R_GRANNY_TO_ENGINE, attached_engine);
float final_world[16];
@@ -470,7 +522,12 @@ std::vector<Render3DDraw> Gr2ModelInstance::BuildDrawCommands(float animation_ti
std::copy(attached_engine, attached_engine + 16, final_world);
}
auto attach_draws = am.model->BuildDrawCommands(-1.0f, nullptr);
float attach_time = -1.0f;
if (am.animated && animation_time >= 0.0f) {
float duration = am.model->GetAnimationDuration();
attach_time = duration > 0.0f ? std::fmod(animation_time, duration) : 0.0f;
}
auto attach_draws = am.model->BuildDrawCommands(attach_time, nullptr);
for (auto& ad : attach_draws) {
std::copy(final_world, final_world + 16, ad.world);
draws.push_back(std::move(ad));
@@ -630,6 +687,16 @@ void Gr2SceneRenderer::SetCameraLookAt(float eyeX, float eyeY, float eyeZ,
m_view[15]= 1.0f;
}
void Gr2SceneRenderer::SetCameraLookAtRH(float eyeX, float eyeY, float eyeZ,
float targetX, float targetY, float targetZ,
float upX, float upY, float upZ) {
SetCameraLookAt(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, upX, upY, upZ);
m_view[0] = -m_view[0];
m_view[4] = -m_view[4];
m_view[8] = -m_view[8];
m_view[12] = -m_view[12];
}
void Gr2SceneRenderer::SetPerspective(float fovYDegrees, float aspect, float zNear, float zFar) {
float fovRad = fovYDegrees * 3.1415926535f / 180.0f;
float h = 1.0f / std::tan(fovRad * 0.5f);
@@ -710,9 +777,11 @@ void Gr2SceneRenderer::RenderDraw(SDL_Surface* targetSurface, const Render3DDraw
}
if (i * 3 + 2 < draw.normals.size()) {
xverts[i].nx = draw.normals[i * 3 + 0];
xverts[i].ny = draw.normals[i * 3 + 1];
xverts[i].nz = draw.normals[i * 3 + 2];
// Lit normals are transformed by the world 3x3 (D3DTS_WORLD) before N.L.
float on0 = draw.normals[i * 3 + 0], on1 = draw.normals[i * 3 + 1], on2 = draw.normals[i * 3 + 2];
xverts[i].nx = on0 * draw.world[0] + on1 * draw.world[4] + on2 * draw.world[8];
xverts[i].ny = on0 * draw.world[1] + on1 * draw.world[5] + on2 * draw.world[9];
xverts[i].nz = on0 * draw.world[2] + on1 * draw.world[6] + on2 * draw.world[10];
} else {
xverts[i].nx = 0.0f; xverts[i].ny = 1.0f; xverts[i].nz = 0.0f;
}
@@ -750,11 +819,6 @@ void Gr2SceneRenderer::RenderDraw(SDL_Surface* targetSurface, const Render3DDraw
}
std::size_t num_tris = draw.indices.size() / 3;
for (std::size_t t = 0; t < num_tris; ++t) {
uint32_t i0 = draw.indices[t * 3 + 0];
uint32_t i1 = draw.indices[t * 3 + 1];
uint32_t i2 = draw.indices[t * 3 + 2];
if (i0 >= num_verts || i1 >= num_verts || i2 >= num_verts) continue;
auto make_screen_vertex = [&](TransformedVertex& v) {
if (v.w_clip > 1e-5f) {
@@ -865,7 +929,6 @@ void Gr2SceneRenderer::RenderDraw(SDL_Surface* targetSurface, const Render3DDraw
if (nlen > 1e-5f) { nx /= nlen; ny /= nlen; nz /= nlen; }
float ndotl = std::max(0.0f, nx * lx + ny * ly + nz * lz);
float light_intensity = 0.52f + 0.58f * ndotl;
float pr = 255.0f, pg = 255.0f, pb = 255.0f;
float frag_alpha = 255.0f;
@@ -897,9 +960,13 @@ void Gr2SceneRenderer::RenderDraw(SDL_Surface* targetSurface, const Render3DDraw
float vb = (b0 * (d0 & 0xFF) + b1 * (d1 & 0xFF) + b2 * (d2 & 0xFF)) / 255.0f;
float va = (b0 * ((d0 >> 24) & 0xFF) + b1 * ((d1 >> 24) & 0xFF) + b2 * ((d2 >> 24) & 0xFF)) / 255.0f;
if (draw.lighting) {
pr = std::clamp(pr * vr * 1.4f, 0.0f, 255.0f);
pg = std::clamp(pg * vg * 1.4f, 0.0f, 255.0f);
pb = std::clamp(pb * vb * 1.4f, 0.0f, 255.0f);
// D3D8 fixed-function: Emissive + MatAmb*LightAmb + Diffuse*LightDiff*N.L.
float lr = std::clamp(draw.material_emissive[0] + draw.material_ambient[0] * draw.light_ambient[0] + vr * draw.light_diffuse[0] * ndotl, 0.0f, 1.0f);
float lg = std::clamp(draw.material_emissive[1] + draw.material_ambient[1] * draw.light_ambient[1] + vg * draw.light_diffuse[1] * ndotl, 0.0f, 1.0f);
float lb = std::clamp(draw.material_emissive[2] + draw.material_ambient[2] * draw.light_ambient[2] + vb * draw.light_diffuse[2] * ndotl, 0.0f, 1.0f);
pr = std::clamp(pr * lr, 0.0f, 255.0f);
pg = std::clamp(pg * lg, 0.0f, 255.0f);
pb = std::clamp(pb * lb, 0.0f, 255.0f);
} else {
pr = std::clamp(pr * vr, 0.0f, 255.0f);
pg = std::clamp(pg * vg, 0.0f, 255.0f);
@@ -913,12 +980,11 @@ void Gr2SceneRenderer::RenderDraw(SDL_Surface* targetSurface, const Render3DDraw
pg = b0 * ((d0 >> 8) & 0xFF) + b1 * ((d1 >> 8) & 0xFF) + b2 * ((d2 >> 8) & 0xFF);
pb = b0 * (d0 & 0xFF) + b1 * (d1 & 0xFF) + b2 * (d2 & 0xFF);
frag_alpha = b0 * ((d0 >> 24) & 0xFF) + b1 * ((d1 >> 24) & 0xFF) + b2 * ((d2 >> 24) & 0xFF);
}
if (draw.lighting) {
pr = std::clamp(pr * light_intensity, 0.0f, 255.0f);
pg = std::clamp(pg * light_intensity, 0.0f, 255.0f);
pb = std::clamp(pb * light_intensity, 0.0f, 255.0f);
if (draw.lighting) {
pr = 255.0f * std::clamp(draw.material_emissive[0] + draw.material_ambient[0] * draw.light_ambient[0] + pr / 255.0f * draw.light_diffuse[0] * ndotl, 0.0f, 1.0f);
pg = 255.0f * std::clamp(draw.material_emissive[1] + draw.material_ambient[1] * draw.light_ambient[1] + pg / 255.0f * draw.light_diffuse[1] * ndotl, 0.0f, 1.0f);
pb = 255.0f * std::clamp(draw.material_emissive[2] + draw.material_ambient[2] * draw.light_ambient[2] + pb / 255.0f * draw.light_diffuse[2] * ndotl, 0.0f, 1.0f);
}
}
if (m_fog_enabled && draw.fog) {
@@ -1012,7 +1078,6 @@ void Gr2SceneRenderer::RenderDraw(SDL_Surface* targetSurface, const Render3DDraw
rasterize_triangle(*vin2, vnew2, vnew1);
}
}
}
}
void Gr2SceneRenderer::RenderScene(SDL_Surface* targetSurface, const std::vector<Render3DDraw>& draws) {
@@ -1199,15 +1264,20 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<
va *= ((d >> 24) & 0xFF) / 255.0f;
}
// D3D8 fixed-function vertex lighting with one directional light (D3DRS_AMBIENT 0):
// Emissive + Material.Ambient*Light.Ambient + Diffuse*Light.Diffuse*max(0, N.L), clamped.
// Normals go through the world matrix like D3DTS_WORLD does for lit vertices.
if (draw.lighting && i * 3 + 2 < draw.normals.size()) {
float nx = draw.normals[i * 3 + 0];
float ny = draw.normals[i * 3 + 1];
float nz = draw.normals[i * 3 + 2];
float on[3] = {draw.normals[i * 3 + 0], draw.normals[i * 3 + 1], draw.normals[i * 3 + 2]};
float nx = on[0] * draw.world[0] + on[1] * draw.world[4] + on[2] * draw.world[8];
float ny = on[0] * draw.world[1] + on[1] * draw.world[5] + on[2] * draw.world[9];
float nz = on[0] * draw.world[2] + on[1] * draw.world[6] + on[2] * draw.world[10];
float nlen = std::sqrt(nx * nx + ny * ny + nz * nz);
if (nlen > 1e-5f) { nx /= nlen; ny /= nlen; nz /= nlen; }
float ndotl = std::max(0.0f, nx * lx + ny * ly + nz * lz);
float light_intensity = 0.52f + 0.58f * ndotl;
vr = std::clamp(vr * light_intensity, 0.0f, 1.0f);
vg = std::clamp(vg * light_intensity, 0.0f, 1.0f);
vb = std::clamp(vb * light_intensity, 0.0f, 1.0f);
vr = std::clamp(draw.material_emissive[0] + draw.material_ambient[0] * draw.light_ambient[0] + vr * draw.light_diffuse[0] * ndotl, 0.0f, 1.0f);
vg = std::clamp(draw.material_emissive[1] + draw.material_ambient[1] * draw.light_ambient[1] + vg * draw.light_diffuse[1] * ndotl, 0.0f, 1.0f);
vb = std::clamp(draw.material_emissive[2] + draw.material_ambient[2] * draw.light_ambient[2] + vb * draw.light_diffuse[2] * ndotl, 0.0f, 1.0f);
}
if (m_fog_enabled && draw.fog && clip[3] > 0.0f) {