port 2D step 5b: PackInitialize + pack:// asset_io backend over the ported EterPackManager

Platform UserInterface PackInitialize/PackSingletons (40250 bootstrap, on-disk dbname
resolution), EterBase/FileLoader.cpp mirror, mtpack40250 backend behind asset_io's
pack:// scheme and a Metin2Pack node. port_eterpack_test now registers through
PackInitialize. Nothing reads pack:// at runtime yet; port-map stays TODO.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-23 01:31:17 +09:00
co-authored by Claude Opus 5
parent 1f1004da79
commit 5a26e93f07
13 changed files with 574 additions and 91 deletions
+32
View File
@@ -2,19 +2,51 @@
#include <godot_cpp/classes/file_access.hpp>
#include "platform/PackBackend.h"
#include <cstring>
#include <string>
#include <vector>
using namespace godot;
namespace mtgodot {
namespace {
bool pack_name(const String &path, std::string &name) {
if (!path.begins_with(PACK_SCHEME)) {
return false;
}
name = path.substr(String(PACK_SCHEME).length()).utf8().get_data();
return true;
}
} // namespace
PackedByteArray read_file(const String &path) {
if (path.is_empty()) {
return PackedByteArray();
}
std::string name;
if (pack_name(path, name)) {
std::vector<uint8_t> bytes;
PackedByteArray out;
if (mtpack40250::read(name, bytes)) {
out.resize((int64_t)bytes.size());
if (!bytes.empty()) {
std::memcpy(out.ptrw(), bytes.data(), bytes.size());
}
}
return out;
}
// FileAccess::get_file_as_bytes handles res:// / user:// / absolute OS paths.
return FileAccess::get_file_as_bytes(path);
}
bool file_exists(const String &path) {
std::string name;
if (pack_name(path, name)) {
return mtpack40250::exists(name);
}
return !path.is_empty() && FileAccess::file_exists(path);
}