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
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
"""Bundle non-system dylibs recursively, including optional font dependencies."""
import pathlib
import shutil
import subprocess
import sys
bundle = pathlib.Path(sys.argv[1]).resolve()
executable = bundle / "Contents/MacOS/ava2_client"
frameworks = bundle / "Contents/Frameworks"
frameworks.mkdir(parents=True, exist_ok=True)
pending = [executable]
copied = {}
while pending:
binary = pending.pop()
lines = subprocess.check_output(["otool", "-L", str(binary)], text=True).splitlines()[1:]
for line in lines:
library = line.strip().split(" (", 1)[0]
if not library.startswith(("/opt/homebrew/", "/usr/local/")):
continue
source = pathlib.Path(library)
target = frameworks / source.name
# otool includes a dylib's own install ID; it is handled by -id below.
if source.name == binary.name:
continue
if source.name not in copied:
if target.exists():
target.chmod(target.stat().st_mode | 0o200)
shutil.copy2(source, target)
copied[source.name] = source.resolve()
pending.append(target)
elif copied[source.name] != source.resolve():
raise RuntimeError(f"Conflicting library names: {source.name}")
subprocess.run(["install_name_tool", "-change", library,
"@executable_path/../Frameworks/" + source.name, str(binary)], check=True)
if binary != executable:
subprocess.run(["install_name_tool", "-id", "@executable_path/../Frameworks/" + binary.name,
str(binary)], check=True)
for binary in [*frameworks.glob("*.dylib"), executable]:
subprocess.run(["codesign", "-f", "-s", "-", str(binary)], check=True)
subprocess.run(["codesign", "-f", "-s", "-", str(bundle)], check=True)
subprocess.run(["codesign", "--verify", "--deep", str(bundle)], check=True)
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
"""Rebuild the embedded Vulkan shaders with glslc; Metal uses the same source semantics."""
from pathlib import Path
import subprocess
import tempfile
root = Path(__file__).resolve().parents[1]
parts = ['// Generated by tools/compile_scene_shaders.py; do not edit.\n#pragma once\n']
with tempfile.TemporaryDirectory() as tmp:
for stage in ('vert', 'frag'):
source = root / 'src/eter_render/shaders' / ('scene.' + stage)
binary = Path(tmp) / stage
subprocess.run(['glslc', str(source), '-o', str(binary)], check=True)
data = binary.read_bytes()
parts.append('alignas(4) inline constexpr unsigned char scene_' + stage + '_spv[] = {\n')
for start in range(0, len(data), 24):
parts.append(','.join(str(v) for v in data[start:start+24]) + ',\n')
parts.append('};\n')
(root / 'src/eter_render/shaders/SceneSpirv.h').write_text(''.join(parts))
+77 -58
View File
@@ -11,7 +11,8 @@ import json
import hashlib
import shutil
import argparse
from pathlib import Path
from pathlib import Path, PurePosixPath
from make_test_rundir import pack_manifests, MANIFEST_ENTRY, archived_root_path
DEFAULT_ASSET_DIRS = [
"mark",
@@ -20,6 +21,14 @@ DEFAULT_ASSET_DIRS = [
"textureset",
"sound",
"runtime",
"icon",
"flag",
"Dialog",
"Itemshop",
"Modulo",
"System",
"battlepass",
"season1",
"upstream/python-root",
]
@@ -36,71 +45,80 @@ def compute_sha256(filepath):
h.update(chunk)
return h.hexdigest()
def package_assets(source_dir, output_dir, manifest_path=None, include_heavy=False):
def package_assets(source_dir, output_dir, manifest_path=None, include_heavy=False, pack_maker=None):
source_path = Path(source_dir).resolve()
dest_path = Path(output_dir).resolve()
dest_path.mkdir(parents=True, exist_ok=True)
if pack_maker is None:
candidate = source_path.parent / "AVA2" / "1. Client DEV" / "pack_maker"
pack_maker = candidate if candidate.is_dir() else None
entries = {}
scan_dirs = list(DEFAULT_ASSET_DIRS)
if include_heavy:
scan_dirs.extend(OPTIONAL_ASSET_DIRS)
manifest = {
"version": "1.0.0",
"source": str(source_path),
"total_files": 0,
"total_bytes": 0,
"files": {}
}
print(f"[*] Packaging assets from {source_path} -> {dest_path}")
packaged_count = 0
total_bytes = 0
def add(rel, source, override=False):
rel = archived_root_path(str(rel))
parts = PurePosixPath(rel).parts
if not parts or rel.startswith("/") or any(part in ("..", ".") or ":" in part for part in parts):
raise ValueError(f"Invalid virtual asset path: {rel}")
if not include_heavy and parts[0].lower() in ("ymir work", "bgm"):
return
if rel.endswith((".pyc", ".tmp")):
return
key = rel.lower()
if override or key not in entries:
if not source.is_file():
raise FileNotFoundError(f"Required asset {rel}: {source}")
# Canonical casing also works on Android/Linux.
# Python imports are case-sensitive on Android/Linux (e.g. uiCommon).
entries[key] = (rel if parts[0] == "root" and len(parts) == 2 and rel.endswith(".py") else key, source)
if pack_maker is not None:
pack_maker = Path(pack_maker).resolve()
for xml in pack_manifests(pack_maker):
for rel, source in MANIFEST_ENTRY.findall(xml.read_text(encoding="latin-1")):
add(rel, pack_maker.parent / source)
# Some custom UI images ship loose beside the Windows executable, outside every pack.
# Copy resource formats only; scripts/configuration continue to come from the port.
resource_extensions = {".png", ".jpg", ".jpeg", ".tga", ".dds", ".sub", ".wav", ".ogg", ".mp3", ".gr2", ".spt", ".mse", ".msa", ".msm"}
excluded = {"pack", "pack_maker", "lib", "miles", "mark", "screenshot", "screenshots", "logs"}
for directory, dirs, files in os.walk(pack_maker.parent):
dirs[:] = [d for d in dirs if not d.startswith(".") and d.lower() not in excluded]
for name in files:
source = Path(directory) / name
if source.suffix.lower() in resource_extensions and source.is_file():
add(source.relative_to(pack_maker.parent).as_posix(), source)
scan_dirs = DEFAULT_ASSET_DIRS + (["map", "property", "rework_inv"] if pack_maker is None else [])
if include_heavy and pack_maker is None:
scan_dirs += OPTIONAL_ASSET_DIRS
for rel_dir in scan_dirs:
src_dir_path = source_path / rel_dir
if not src_dir_path.exists():
base = source_path / rel_dir
if not base.exists():
continue
for directory, dirs, files in os.walk(base):
dirs[:] = [d for d in dirs if not d.startswith(".") and d not in ("__pycache__", "build")]
for name in files:
if not name.startswith("."):
source = Path(directory) / name
if source.is_file():
rel = source.relative_to(source_path).as_posix()
if rel.startswith("upstream/python-root/"):
rel = "root/" + rel[len("upstream/python-root/"):]
add(rel, source, True)
print(f" -> Scanning {rel_dir}...")
for root, dirs, files in os.walk(src_dir_path):
# Exclude build and hidden artifacts
dirs[:] = [d for d in dirs if not d.startswith(".") and d not in ("__pycache__", "build", ".git")]
for file in files:
if file.startswith(".") or file.endswith(".pyc") or file.endswith(".tmp"):
continue
full_path = Path(root) / file
rel_to_source = full_path.relative_to(source_path)
target_file = dest_path / rel_to_source
target_file.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(full_path, target_file)
file_size = full_path.stat().st_size
file_hash = compute_sha256(full_path)
manifest["files"][str(rel_to_source).replace("\\", "/")] = {
"size": file_size,
"sha256": file_hash
}
packaged_count += 1
total_bytes += file_size
manifest["total_files"] = packaged_count
manifest["total_bytes"] = total_bytes
if manifest_path:
out_manifest = Path(manifest_path)
else:
out_manifest = dest_path / "asset_manifest.json"
manifest = {"version": "2.0.0", "source": str(source_path),
"total_files": 0, "total_bytes": 0, "files": {}}
print(f"[*] Packaging {len(entries)} virtual assets into {dest_path}")
for rel, source in entries.values():
target = dest_path / rel
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, target)
size = source.stat().st_size
manifest["files"][rel] = {"size": size, "sha256": compute_sha256(source)}
manifest["total_bytes"] += size
manifest["total_files"] = len(entries)
out_manifest = Path(manifest_path) if manifest_path else dest_path / "asset_manifest.json"
out_manifest.parent.mkdir(parents=True, exist_ok=True)
with open(out_manifest, "w", encoding="utf-8") as f:
json.dump(manifest, f, indent=2, sort_keys=True)
print(f"[+] Packaged {packaged_count} files ({total_bytes / (1024*1024):.2f} MB)")
print(f"[+] Manifest written to {out_manifest}")
out_manifest.write_text(json.dumps(manifest, indent=2, sort_keys=True), encoding="utf-8")
print(f"[+] Packaged {len(entries)} files ({manifest['total_bytes'] / (1024*1024):.2f} MB)")
return manifest
def verify_assets(manifest_path, target_dir):
@@ -144,6 +162,7 @@ def main():
parser.add_argument("--source", default=".", help="Source client directory")
parser.add_argument("--output", default="dist/assets", help="Output packaged directory")
parser.add_argument("--manifest", default=None, help="Manifest output path")
parser.add_argument("--pack-maker", default=None, help="Original pack_maker manifests and decoded files")
parser.add_argument("--include-heavy", action="store_true", help="Include large 3D models and BGM")
parser.add_argument("--verify", default=None, help="Verify target directory against specified manifest")
@@ -153,7 +172,7 @@ def main():
success = verify_assets(args.verify, args.output)
sys.exit(0 if success else 1)
else:
package_assets(args.source, args.output, args.manifest, args.include_heavy)
package_assets(args.source, args.output, args.manifest, args.include_heavy, args.pack_maker)
if __name__ == "__main__":
main()
+54 -21
View File
@@ -3,7 +3,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
BUILD_DIR="${ROOT_DIR}/build/dev"
BUILD_DIR="${ROOT_DIR}/build/release"
DIST_DIR="${ROOT_DIR}/dist"
APP_NAME="AVA2"
BUNDLE_DIR="${DIST_DIR}/${APP_NAME}.app"
@@ -19,6 +19,7 @@ echo ""
# 1. Compile client targets if needed
echo "[1/5] Building native targets..."
cmake -S "${ROOT_DIR}" -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build "${BUILD_DIR}" --target ava2_client -j8
# 2. Setup bundle structure
@@ -31,40 +32,72 @@ mkdir -p "${BUNDLE_DIR}/Contents/Frameworks"
# 3. Copy binary
echo "[3/5] Installing executable and Info.plist..."
cp "${BUILD_DIR}/ava2_client" "${BUNDLE_DIR}/Contents/MacOS/ava2_client"
ln -sf "ava2_client" "${BUNDLE_DIR}/Contents/MacOS/AVA2"
chmod +x "${BUNDLE_DIR}/Contents/MacOS/ava2_client"
if [ -f "${ROOT_DIR}/support/mac/Info.plist.in" ]; then
cp "${ROOT_DIR}/support/mac/Info.plist.in" "${BUNDLE_DIR}/Contents/Info.plist"
fi
if [ -f "${ROOT_DIR}/support/mac/AppIcon.icns" ]; then
cp "${ROOT_DIR}/support/mac/AppIcon.icns" "${BUNDLE_DIR}/Contents/Resources/AppIcon.icns"
fi
# 4. Package core game assets into Bundle Resources
echo "[4/5] Packaging client assets into bundle..."
EXTRA_PACK_ARGS=""
if [ "${1:-}" = "--full" ] || [ "${1:-}" = "--include-heavy" ]; then
echo " (Including heavy 3D assets & BGM)"
EXTRA_PACK_ARGS="--include-heavy"
fi
python3 "${SCRIPT_DIR}/pack_assets.py" \
--source "${ROOT_DIR}" \
--output "${BUNDLE_DIR}/Contents/Resources" \
--manifest "${BUNDLE_DIR}/Contents/Resources/asset_manifest.json"
--manifest "${BUNDLE_DIR}/Contents/Resources/asset_manifest.json" \
${EXTRA_PACK_ARGS}
# Symlink resources relative to MacOS folder for direct path resolution
cd "${BUNDLE_DIR}/Contents/MacOS"
ln -sf "../Resources/mark" mark
ln -sf "../Resources/locale" locale
ln -sf "../Resources/uiscript" uiscript
ln -sf "../Resources/textureset" textureset
ln -sf "../Resources/sound" sound
ln -sf "../Resources/runtime" runtime
ln -sf "../Resources/upstream" upstream
# Install Python runtime & script root
if [ -f "${BUILD_DIR}/python27.zip" ]; then
echo " Installing python27.zip standard library..."
cp "${BUILD_DIR}/python27.zip" "${BUNDLE_DIR}/Contents/Resources/python27.zip"
fi
echo " Python script root installed through the resource manifest."
if [ -f "${ROOT_DIR}/runtime/login_view.py" ]; then
cp "${ROOT_DIR}/runtime/login_view.py" "${BUNDLE_DIR}/Contents/Resources/login_view.py"
fi
# Resolve every virtual resource directory, including patch-pack directories.
# All links stay inside the bundle; --full copies heavy assets as well.
python3 - "${BUNDLE_DIR}" "${ROOT_DIR}" <<'PYLINK'
from pathlib import Path
import sys
bundle, source = map(Path, sys.argv[1:])
resources = bundle / "Contents/Resources"
macos = bundle / "Contents/MacOS"
for item in resources.iterdir():
link = macos / item.name
if not link.exists() and not link.is_symlink():
link.symlink_to(Path("../Resources") / item.name)
for name in ("ymir work", "bgm"):
if not (resources / name).exists() and (source / name).is_dir():
(resources / name).symlink_to(source / name)
(macos / name).symlink_to(Path("../Resources") / name)
if not (resources / "UIScript").exists():
(resources / "UIScript").symlink_to("uiscript")
if not (resources / "root/UIScript").exists():
(resources / "root/UIScript").symlink_to("uiscript")
(resources / "upstream").mkdir(exist_ok=True)
link = resources / "upstream/python-root"
if not link.exists():
link.symlink_to("../root")
PYLINK
cd "${ROOT_DIR}"
# Bundle and relocate SDL3 dylib for self-contained deployment
if [ -f "/opt/homebrew/opt/sdl3/lib/libSDL3.0.dylib" ]; then
echo "[4.1/5] Bundling SDL3.0.dylib into Frameworks..."
cp "/opt/homebrew/opt/sdl3/lib/libSDL3.0.dylib" "${BUNDLE_DIR}/Contents/Frameworks/"
install_name_tool -change "/opt/homebrew/opt/sdl3/lib/libSDL3.0.dylib" "@executable_path/../Frameworks/libSDL3.0.dylib" "${BUNDLE_DIR}/Contents/MacOS/ava2_client"
install_name_tool -id "@executable_path/../Frameworks/libSDL3.0.dylib" "${BUNDLE_DIR}/Contents/Frameworks/libSDL3.0.dylib"
echo "[4.2/5] Ad-hoc signing bundle binaries for macOS arm64..."
codesign -f -s - "${BUNDLE_DIR}/Contents/Frameworks/libSDL3.0.dylib"
codesign -f -s - "${BUNDLE_DIR}/Contents/MacOS/ava2_client"
fi
# Include SDL3 and all optional font libraries, with their transitive dependencies.
python3 "${SCRIPT_DIR}/bundle_macos_libraries.py" "${BUNDLE_DIR}"
# 5. Create Distribution Archive
echo "[5/5] Creating release distribution tarball..."