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
+219 -3
View File
@@ -1,6 +1,8 @@
#include "ActorInstance.h"
#include "MapObjectManager.h"
#include "CRenderTarget.h"
#include "RaceData.h"
#include "src/eter_resource/ResourceManager.h"
#include <filesystem>
#include <cmath>
#include <algorithm>
@@ -21,9 +23,186 @@ std::string ActorInstance::ResolvePath(const std::string& path) const {
if (std::filesystem::exists(clean)) return clean;
if (std::filesystem::exists("build/dev/" + clean)) return "build/dev/" + clean;
if (std::filesystem::exists("../" + clean)) return "../" + clean;
// Pack paths ("d:/ymir work/...", mixed case) go through the CResourceManager candidates.
std::error_code error;
for (const auto& candidate : CResourceManager::GetCandidatePaths(CResourceManager::NormalizePath(path.c_str())))
if (std::filesystem::is_regular_file(candidate, error)) return candidate;
return clean;
}
std::shared_ptr<Gr2ModelInstance> ActorInstance::LoadPartModel(const std::string& path) const {
if (path.empty()) return nullptr;
std::string resolved = ResolvePath(path);
std::error_code error;
if (!std::filesystem::is_regular_file(resolved, error)) {
std::cerr << "ActorInstance: model not found: " << path << std::endl;
return nullptr;
}
return std::shared_ptr<Gr2ModelInstance>(Gr2ModelInstance::Load(resolved));
}
void ActorInstance::SetMainModel(std::shared_ptr<Gr2ModelInstance> model, const std::string& path) {
m_model = std::move(model);
m_modelPath = m_model ? path : std::string();
RebindParts();
// A new PART_MAIN instance restarts the current motion on it.
if (m_model) {
auto it = m_motionPaths.find(m_currentMotion);
if (it != m_motionPaths.end()) {
std::string resolved = ResolvePath(it->second);
if (m_model->LoadExternalAnimation(resolved))
m_motionDuration = std::max(0.1f, m_model->GetAnimationDuration());
}
}
}
// Re-attaches the part slots to PART_MAIN: hair deforms with the main skeleton, the others follow
// their attaching bone; PART_SASH also takes the ENABLE_OBJ_SCALLING scale matrix.
void ActorInstance::RebindParts() {
if (!m_model) return;
m_model->DetachAll();
for (uint32_t part = 1; part < kPartCount; ++part) {
const auto& slot = m_parts[part];
if (!slot.model) continue;
if (slot.bone.empty()) {
m_model->AttachPart(slot.model);
continue;
}
m_model->AttachModel(slot.bone, slot.model);
if (part == RaceData::PART_SASH) {
m_model->SetAttachmentAnimated(slot.bone, true);
if (m_hasSashScale) m_model->SetAttachmentScale(slot.bone, m_sashScale[0], m_sashScale[1], m_sashScale[2]);
}
}
}
bool ActorInstance::SetRace(uint32_t race) {
RaceData* raceData = RaceManager::Instance().GetRaceDataPointer(race);
if (!raceData) {
m_race = 0;
m_raceData = nullptr;
return false;
}
m_race = race;
m_raceData = raceData;
// memset(m_adwPartItemID) + CGraphicThingInstance::Clear(): every part model is dropped.
std::fill(std::begin(m_partItemID), std::end(m_partItemID), 0u);
for (auto& slot : m_parts) slot = SPartSlot{};
m_model.reset();
m_modelPath.clear();
m_shapeFile.clear();
// SetMotionIndex(eRace): the race's GENERAL motion set (motlist.txt for NPC races, the
// chrmgr.RegisterMotionData calls for races built from Python).
m_motionPaths.clear();
m_motionQueue.clear();
{
static const RaceData::EMotion kNames[] = {
RaceData::NAME_WAIT, RaceData::NAME_WALK, RaceData::NAME_RUN, RaceData::NAME_CHANGE_WEAPON,
RaceData::NAME_DAMAGE, RaceData::NAME_DEAD, RaceData::NAME_NORMAL_ATTACK,
RaceData::NAME_COMBO_ATTACK_1, RaceData::NAME_COMBO_ATTACK_2, RaceData::NAME_COMBO_ATTACK_3,
};
for (auto name : kNames) {
const auto* motions = raceData->GetMotions(name);
if (!motions || motions->empty()) continue;
// The percent-weighted random pick of CActorInstance is not ported: the first entry plays.
std::string gr2 = ReadMotionFileName(motions->front().fileName);
if (!gr2.empty()) RegisterMotion(static_cast<MotionType>(name), gr2);
}
}
return true;
}
void ActorInstance::SetShape(uint32_t shape, float specular) {
(void)specular; // SMaterialData specular / sphere map: not rendered by the port yet.
m_shape = shape;
RaceData* raceData = RaceManager::Instance().GetRaceDataPointer(m_race);
if (!raceData) return;
const RaceData::Shape* pkShape = raceData->FindShape(shape);
if (pkShape) {
const std::string& file = pkShape->model.empty() ? raceData->GetBaseModelFileName() : pkShape->model;
// The _lod_01.._03 LOD things are not ported: LOD 0 always draws.
auto model = LoadPartModel(file);
if (model) {
for (const auto& skin : pkShape->skins) model->SetSkin(skin.srcFileName, skin.dstFileName);
}
m_shapeFile = file;
SetMainModel(std::move(model), file);
} else if (raceData->IsTree()) {
// __CreateTree (SpeedTree actors) is not ported.
m_shapeFile.clear();
SetMainModel(nullptr, std::string());
} else {
const std::string& file = raceData->GetBaseModelFileName();
m_shapeFile = file;
SetMainModel(LoadPartModel(file), file);
}
}
void ActorInstance::SetHair(uint32_t hair) {
m_hair = hair;
RaceData* raceData = RaceManager::Instance().GetRaceDataPointer(m_race);
if (!raceData) return;
const RaceData::Shape* pkHair = raceData->FindHair(hair);
if (!pkHair) return; // the previous hair instance stays
if (!pkHair->model.empty()) {
m_parts[RaceData::PART_HAIR].model = LoadPartModel(pkHair->model);
m_parts[RaceData::PART_HAIR].file = pkHair->model;
m_parts[RaceData::PART_HAIR].bone.clear();
}
if (auto& model = m_parts[RaceData::PART_HAIR].model)
for (const auto& skin : pkHair->skins) model->SetSkin(skin.srcFileName, skin.dstFileName);
RebindParts();
}
void ActorInstance::AttachWeaponPart(uint32_t part, const SPartItem& item) {
std::string bone;
if (!m_raceData || !m_raceData->GetAttachingBoneName(part, &bone)) return;
// PART_WEAPON_LEFT registers GetSubModelThing(), which is the same model file.
m_parts[part].model = LoadPartModel(item.model);
m_parts[part].file = item.model;
m_parts[part].bone = bone;
// USE_WEAPON_SPECULAR sphere map and CWeaponTrace are not ported.
}
void ActorInstance::AttachWeapon(uint32_t itemIndex, const SPartItem* item, bool isMountingHorse) {
enum { WEAPON_DAGGER = 1, WEAPON_BOW = 2, WEAPON_FAN = 5 };
m_partItemID[RaceData::PART_WEAPON] = itemIndex;
if (!item) {
m_parts[RaceData::PART_WEAPON] = SPartSlot{};
m_parts[RaceData::PART_WEAPON_LEFT] = SPartSlot{};
RebindParts();
return;
}
const uint32_t type = item->weaponType;
const bool dual = type == WEAPON_DAGGER || (type == WEAPON_FAN && isMountingHorse);
// __IsRightHandWeapon / __IsLeftHandWeapon. A slot that is not re-attached keeps its old model
// (e.g. a dagger's left blade stays after switching to a sword), as on Windows.
if (dual || type != WEAPON_BOW) AttachWeaponPart(RaceData::PART_WEAPON, *item);
if (dual || type == WEAPON_BOW) AttachWeaponPart(RaceData::PART_WEAPON_LEFT, *item);
RebindParts();
}
void ActorInstance::AttachSash(const SPartItem* item, float specular) {
(void)specular; // sphere-map specular not rendered.
if (!item) {
m_parts[RaceData::PART_SASH] = SPartSlot{};
} else {
m_parts[RaceData::PART_SASH].model = LoadPartModel(item->model);
m_parts[RaceData::PART_SASH].file = item->model;
m_parts[RaceData::PART_SASH].bone = "Bip01 Spine2";
}
RebindParts();
}
void ActorInstance::SetSashScale(float sx, float sy, float sz) {
m_hasSashScale = true;
m_sashScale[0] = sx; m_sashScale[1] = sy; m_sashScale[2] = sz;
RebindParts();
}
bool ActorInstance::SetModel(const std::string& modelPath) {
std::string resolved = ResolvePath(modelPath);
if (!std::filesystem::exists(resolved)) {
@@ -101,12 +280,44 @@ bool ActorInstance::PlayMotion(MotionType type, bool loop) {
return true;
}
bool ActorInstance::PlayMotionIndex(uint32_t index, bool loop) {
uint16_t keyMode;
if (!m_raceData || !m_raceData->GetMotionKey(uint16_t(m_motionMode), uint16_t(index), &keyMode)) return false;
const auto* motions = m_raceData->GetMotions(keyMode, index);
if (!motions || motions->empty()) return false;
const std::string gr2 = ReadMotionFileName(motions->front().fileName);
if (gr2.empty()) return false;
RegisterMotion(static_cast<MotionType>(index), gr2);
return PlayMotion(static_cast<MotionType>(index), loop);
}
bool ActorInstance::SetLoopMotionIndex(uint32_t index) {
uint16_t keyMode;
if (!m_raceData || !m_raceData->GetMotionKey(uint16_t(m_motionMode), uint16_t(index), &keyMode)) return false;
m_motionQueue.clear(); // __ClearMotion
return PlayMotionIndex(index, true);
}
bool ActorInstance::InterceptMotionIndex(uint32_t index, bool loop) {
uint16_t keyMode;
if (!m_raceData || !m_raceData->GetMotionKey(uint16_t(m_motionMode), uint16_t(index), &keyMode)) return false;
m_motionQueue.clear(); // __ClearMotion
return PlayMotionIndex(index, loop);
}
bool ActorInstance::PushMotionIndex(uint32_t index, bool loop) {
uint16_t keyMode;
if (!m_raceData || !m_raceData->GetMotionKey(uint16_t(m_motionMode), uint16_t(index), &keyMode)) return false;
m_motionQueue.emplace_back(index, loop);
return true;
}
bool ActorInstance::IsMotionFinished() const {
if (m_loopMotion) return false;
return m_animTime >= m_motionDuration;
}
void ActorInstance::MoveInDirection(float moveYaw, float dt, const TerrainHeightmap* terrain, const MapObjectManager* mapObjects) {
void ActorInstance::MoveInDirection(float moveYaw, float dt, const TerrainHeightSource* terrain, const MapObjectManager* mapObjects) {
if (dt <= 0.0f) return;
float rad = moveYaw * DEG_TO_RAD;
m_yaw = moveYaw;
@@ -170,7 +381,7 @@ void ActorInstance::StopMoving() {
}
}
void ActorInstance::Update(float dt, const TerrainHeightmap* terrain, const MapObjectManager* mapObjects) {
void ActorInstance::Update(float dt, const TerrainHeightSource* terrain, const MapObjectManager* mapObjects) {
if (dt <= 0.0f) return;
// 0. Click-to-Move destination pathing (aligned with 40250 CPythonPlayer)
@@ -231,7 +442,12 @@ void ActorInstance::Update(float dt, const TerrainHeightmap* terrain, const MapO
// Advance animation time
m_animTime += dt;
if (m_loopMotion) {
if (!m_motionQueue.empty() && m_animTime >= m_motionDuration) {
// ReservingMotionProcess: the next pushed motion takes over when the current one ends.
const auto next = m_motionQueue.front();
m_motionQueue.pop_front();
PlayMotionIndex(next.first, next.second);
} else if (m_loopMotion) {
if (m_motionDuration > 0.001f && m_animTime >= m_motionDuration) {
m_animTime = std::fmod(m_animTime, m_motionDuration);
}