Fix cross-platform rendering and optimize frame performance

Correct selection orientation, game-entry lifecycle, mounted NPCs, labels and skill panels. Add the native GPU scene path, resident geometry, bounded texture and Python caches, and collision broad phase.

Pin the independently maintained Metin2 SDK through a submodule and document reproducible setup. Include rendering regressions and macOS packaging improvements.

Validation: client Debug build and 12 targeted client tests passed; SDK build and all 14 SDK tests passed.
This commit is contained in:
shen
2026-10-11 17:55:53 -07:00
parent 08cc8865be
commit 281418f351
101 changed files with 6244 additions and 1877 deletions
+48 -7
View File
@@ -42,6 +42,7 @@ std::shared_ptr<Gr2ModelInstance> ActorInstance::LoadPartModel(const std::string
}
void ActorInstance::SetMainModel(std::shared_ptr<Gr2ModelInstance> model, const std::string& path) {
m_boundsModel = nullptr;
m_model = std::move(model);
m_modelPath = m_model ? path : std::string();
RebindParts();
@@ -209,6 +210,7 @@ bool ActorInstance::SetModel(const std::string& modelPath) {
std::cerr << "ActorInstance::SetModel file not found: " << modelPath << std::endl;
return false;
}
m_boundsModel = nullptr;
m_model = Gr2ModelInstance::Load(resolved);
if (!m_model) return false;
m_modelPath = modelPath;
@@ -254,9 +256,21 @@ bool ActorInstance::PlayMotion(MotionType type, bool loop) {
it = m_motionPaths.find(MotionType::Attack);
}
}
if (it == m_motionPaths.end()) return false;
std::string resolved = ResolvePath(it->second);
std::string motionPath;
// Resolve the active mode at playback time; SetRace/armor rebuilds must not
// silently replace riding motions with GENERAL standing/walking motions.
if (m_raceData && m_motionMode != 1) {
uint16_t actualMode = uint16_t(m_motionMode);
if (m_raceData->GetMotionKey(actualMode, uint16_t(type), &actualMode)) {
const auto* entries = m_raceData->GetMotions(actualMode, uint32_t(type));
if (entries && !entries->empty()) motionPath = ReadMotionFileName(entries->front().fileName);
}
}
if (motionPath.empty()) {
if (it == m_motionPaths.end()) return false;
motionPath = it->second;
}
std::string resolved = ResolvePath(motionPath);
if (!std::filesystem::exists(resolved)) return false;
bool loaded = m_model->LoadExternalAnimation(resolved);
@@ -568,11 +582,11 @@ bool ActorInstance::IsTargetInAttackRange(const ActorInstance& target, float max
return diff <= maxAngleDeg;
}
std::vector<Render3DDraw> ActorInstance::BuildDrawCommands() {
std::vector<Render3DDraw> ActorInstance::BuildDrawCommands(const float* worldOverride) {
if (!m_model) return {};
float world[16];
MakeTransformMatrix(m_yaw + 180.0f, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, world);
auto draws = m_model->BuildDrawCommands(m_animTime, world);
MakeTransformMatrix(m_yaw, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, world);
auto draws = m_model->BuildDrawCommands(m_animTime, worldOverride ? worldOverride : world);
// Shining system (ENABLE_SHINING_SYSTEM): weapon aura / glow
if (m_weaponShining > 0) {
@@ -647,6 +661,26 @@ std::vector<Render3DDraw> ActorInstance::BuildDrawCommands() {
return draws;
}
bool ActorInstance::IsVisible(const float* view, const float* proj) const {
if (!view || !proj || !m_model) return true;
if (m_boundsModel != m_model.get()) {
float loX,loY,loZ,hiX,hiY,hiZ;
m_boundsRadius = 500.f;
if (m_model->GetLocalBounds(loX,loY,loZ,hiX,hiY,hiZ)) {
const float x=std::max(std::abs(loX),std::abs(hiX));
const float y=std::max(std::abs(loY),std::abs(hiY));
const float z=std::max(std::abs(loZ),std::abs(hiZ));
m_boundsRadius = std::sqrt(x*x+y*y+z*z)*2.f + 300.f;
}
m_boundsModel=m_model.get();
}
const float r=m_boundsRadius*std::abs(m_scale);
const float y=m_posY+m_modelYOffset*m_scale;
const float lo[3]={m_posX-r,y-r,m_posZ-r};
const float hi[3]={m_posX+r,y+r,m_posZ+r};
return IsBoundsVisible(lo,hi,view,proj);
}
bool ActorInstance::HitTestScreen(float clickX, float clickY, const Gr2SceneRenderer& renderer, float tolerancePx) const {
if (m_curHP <= 0) return false;
float bx = 0.0f, by = 0.0f, hx = 0.0f, hy = 0.0f;
@@ -673,8 +707,15 @@ bool ActorInstance::GetBoneWorldTransform(const std::string& boneName, float* ou
if (!m_model->GetBoneWorldTransform(boneName, localBone, m_animTime)) {
return false;
}
// Bone poses are still Granny Z-up, just like the mesh vertices. Convert
// before composing with the engine world matrix (SDK R_GRANNY_TO_ENGINE).
for (int row=0;row<4;++row) {
const float y=localBone[row*4+1], z=localBone[row*4+2];
localBone[row*4+1]=z;
localBone[row*4+2]=-y;
}
float actorWorld[16];
MakeTransformMatrix(m_yaw + 180.0f, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, actorWorld);
MakeTransformMatrix(m_yaw, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, actorWorld);
for (int r = 0; r < 4; ++r) {
for (int c = 0; c < 4; ++c) {