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
+55 -15
View File
@@ -4,6 +4,7 @@
#include "src/eter_image/GrpExpandedImageInstance.h"
#include "src/eter_image/GrpMarkInstance.h"
#include "python_runtime.h"
#include "python_minimap.h"
#include "quest_state.h"
#include "guild_state.h"
#include "battlepass_state.h"
@@ -39,22 +40,31 @@ std::filesystem::path resolve(const char* name) {
std::filesystem::path rel(normalized);
if(rel.is_absolute()) throw std::invalid_argument("pack path must be relative");
for(const auto& part:rel) if(part=="..") throw std::invalid_argument("pack traversal rejected");
auto current=pack_root;
for(const auto& part:rel) {
if(part=="." || part.empty()) continue;
auto wanted=part.string();std::transform(wanted.begin(),wanted.end(),wanted.begin(),[](unsigned char c){return std::tolower(c);});
bool found=false; std::filesystem::path match;
if(!std::filesystem::is_directory(current)) throw std::runtime_error("pack path not found");
for(const auto& entry:std::filesystem::directory_iterator(current)) {
auto candidate=entry.path().filename().string();std::transform(candidate.begin(),candidate.end(),candidate.begin(),[](unsigned char c){return std::tolower(c);});
if(candidate==wanted) { if(found) throw std::runtime_error("ambiguous case-insensitive pack path");match=entry.path();found=true; }
std::vector<std::filesystem::path> mounts{pack_root};
// The bundle keeps scripts in root/ and the other virtual packs beside it.
if (pack_root.filename()=="root" && std::filesystem::is_regular_file(pack_root.parent_path()/"asset_manifest.json"))
mounts.push_back(pack_root.parent_path());
for (const auto& mount:mounts) {
auto current=mount;
bool missing=false;
for(const auto& part:rel) {
if(part=="." || part.empty()) continue;
if(!std::filesystem::is_directory(current)) {missing=true;break;}
auto wanted=part.string();std::transform(wanted.begin(),wanted.end(),wanted.begin(),[](unsigned char c){return std::tolower(c);});
bool found=false;std::filesystem::path match;
for(const auto& entry:std::filesystem::directory_iterator(current)) {
auto candidate=entry.path().filename().string();std::transform(candidate.begin(),candidate.end(),candidate.begin(),[](unsigned char c){return std::tolower(c);});
if(candidate==wanted) {if(found) throw std::runtime_error("ambiguous case-insensitive pack path");match=entry.path();found=true;}
}
if(!found) {missing=true;break;}
current=match;
}
if(!found) throw std::runtime_error("pack path not found");
current=match;
if(missing) continue;
auto canonical=std::filesystem::canonical(current);auto relative=canonical.lexically_relative(mount);
if(relative.empty() || *relative.begin()=="..") throw std::runtime_error("pack path escapes mount");
return canonical;
}
auto canonical=std::filesystem::canonical(current);auto relative=canonical.lexically_relative(pack_root);
if(relative.empty() || *relative.begin()=="..") throw std::runtime_error("pack path escapes mount");
return canonical;
throw std::runtime_error("pack path not found");
}
PyObject* pack_exist(PyObject*,PyObject* args) {
const char* name=nullptr;if(!PyArg_ParseTuple(args,"s",&name)) return nullptr;
@@ -247,12 +257,14 @@ sys.meta_path.insert(0, _AVA2PackImporter())
// The event sets hold weak references to Python objects.
CPythonEventManager::Instance().Destroy();CPythonChat::Instance().Destroy();CPythonSystem::Instance().Clear();
CPythonEventManager::Instance().SetInterfaceWindow(nullptr);
clear_compiled_code();
Py_Finalize();
if (m_windowManager)
{
m_windowManager->Destroy();
m_windowManager.reset();
}
CPythonMiniMap::Instance().Destroy();
CGraphicExpandedImageInstance::DestroySystem();
CGraphicImageInstance::DestroySystem();
CGraphicMarkInstance::DestroySystem();
@@ -278,12 +290,14 @@ PythonRuntime::~PythonRuntime() {
// The event sets hold weak references to Python objects.
CPythonEventManager::Instance().Destroy();CPythonChat::Instance().Destroy();CPythonSystem::Instance().Clear();
CPythonEventManager::Instance().SetInterfaceWindow(nullptr);
clear_compiled_code();
Py_Finalize();
if (m_windowManager)
{
m_windowManager->Destroy();
m_windowManager.reset();
}
CPythonMiniMap::Instance().Destroy();
CGraphicExpandedImageInstance::DestroySystem();
CGraphicImageInstance::DestroySystem();
CGraphicMarkInstance::DestroySystem();
@@ -294,7 +308,33 @@ PythonRuntime::~PythonRuntime() {
}
pack_root.clear();
}
void PythonRuntime::execute(const std::string& code) { if(PyRun_SimpleString(code.c_str())!=0) throw std::runtime_error("embedded Python execution failed (see traceback)"); }
void PythonRuntime::clear_compiled_code() {
for(auto& entry:m_compiledCode)Py_DECREF(entry.object);
m_compiledCode.clear();m_compiledBytes=0;
}
void PythonRuntime::execute(const std::string& source) {
PyObject* code=nullptr;
for(auto it=m_compiledCode.begin();it!=m_compiledCode.end();++it) {
if(it->source!=source)continue;
code=it->object;Py_INCREF(code);m_compiledCode.splice(m_compiledCode.begin(),m_compiledCode,it);break;
}
if(!code) {
code=Py_CompileString(source.c_str(),"<string>",Py_file_input);++m_compileCount;
if(!code){PyErr_Print();throw std::runtime_error("embedded Python execution failed (see traceback)");}
if(source.size()<=16u*1024u) {
Py_INCREF(code);m_compiledCode.push_front({source,code});m_compiledBytes+=source.size();
while(m_compiledCode.size()>64 || m_compiledBytes>128u*1024u) {
auto& entry=m_compiledCode.back();m_compiledBytes-=entry.source.size();Py_DECREF(entry.object);m_compiledCode.pop_back();
}
}
}
auto* module=PyImport_AddModule("__main__");
auto* globals=module ? PyModule_GetDict(module) : nullptr;
auto* result=globals ? PyEval_EvalCode(reinterpret_cast<PyCodeObject*>(code),globals,globals) : nullptr;
Py_DECREF(code);
if(!result){PyErr_Print();throw std::runtime_error("embedded Python execution failed (see traceback)");}
Py_DECREF(result);
}
}
namespace ava2 {