feat: complete native client rendering parity updates
This commit is contained in:
@@ -369,6 +369,9 @@ const Metin2World::Chunk *Metin2World::chunk_at(int tx, int ty) const {
|
||||
}
|
||||
|
||||
bool Metin2World::build_chunk(int tx, int ty) {
|
||||
const bool profile_map = std::getenv("MT_PROFILE_MAP") != nullptr;
|
||||
const auto ticks = [] { return Time::get_singleton()->get_ticks_usec(); };
|
||||
const double profile_start = profile_map ? ticks() : 0;
|
||||
const std::string dir =
|
||||
std::string(map_dir().utf8().get_data()) + "/" + fmt::m2coord::tile_dir(tx, ty);
|
||||
auto hm = std::make_shared<fmt::HeightMap>();
|
||||
@@ -378,12 +381,15 @@ bool Metin2World::build_chunk(int tx, int ty) {
|
||||
++chunks_failed;
|
||||
return false;
|
||||
}
|
||||
const double profile_height = profile_map ? ticks() : 0;
|
||||
auto am = std::make_shared<fmt::AttrMap>();
|
||||
if (!fmt::load_attr_map(dir + "/attr.atr", *am, &err))
|
||||
am.reset(); // 非致命:attr 缺失 -> 该区块无阻挡
|
||||
const double profile_attr = profile_map ? ticks() : 0;
|
||||
|
||||
fmt::TerrainMesh tmesh;
|
||||
fmt::build_terrain_mesh(*hm, tx, ty, setting.height_scale, tmesh);
|
||||
const double profile_terrain = profile_map ? ticks() : 0;
|
||||
|
||||
Ref<Material> mat;
|
||||
{
|
||||
@@ -394,19 +400,26 @@ bool Metin2World::build_chunk(int tx, int ty) {
|
||||
}
|
||||
|
||||
bool splatted = false;
|
||||
double profile_tile_ms = 0, profile_alpha_ms = 0, profile_material_ms = 0;
|
||||
if (splat_ready && resolver) {
|
||||
fmt::TileMap tile;
|
||||
std::string e2;
|
||||
const double tile_start = profile_map ? ticks() : 0;
|
||||
if (fmt::load_tile_map(dir + "/tile.raw", tile, &e2)) {
|
||||
if (profile_map) profile_tile_ms = (ticks() - tile_start) / 1000.0;
|
||||
fmt::SplatSet ss;
|
||||
const double alpha_start = profile_map ? ticks() : 0;
|
||||
fmt::build_splat(tile, texture_set.runtime_count(), ss);
|
||||
if (profile_map) profile_alpha_ms = (ticks() - alpha_start) / 1000.0;
|
||||
if (!ss.layers.empty()) {
|
||||
String smpath;
|
||||
String sm = String(dir.c_str()) + "/shadowmap.dds";
|
||||
if (mtgodot::file_exists(sm))
|
||||
smpath = sm;
|
||||
const double material_start = profile_map ? ticks() : 0;
|
||||
Ref<ShaderMaterial> tm = build_chunk_terrain_material(
|
||||
ss, texture_set, *resolver, smpath);
|
||||
if (profile_map) profile_material_ms = (ticks() - material_start) / 1000.0;
|
||||
if (tm.is_valid()) {
|
||||
mat = tm;
|
||||
splatted = true;
|
||||
@@ -416,6 +429,7 @@ bool Metin2World::build_chunk(int tx, int ty) {
|
||||
}
|
||||
if (splatted)
|
||||
++chunks_splatted;
|
||||
const double profile_splat = profile_map ? ticks() : 0;
|
||||
|
||||
// 该区块的场景根 —— terrain / water / 对象 / 树都挂它下面,卸载 = free 它
|
||||
Node3D *croot = memnew(Node3D);
|
||||
@@ -483,6 +497,7 @@ bool Metin2World::build_chunk(int tx, int ty) {
|
||||
}
|
||||
}
|
||||
++chunks_built;
|
||||
const double profile_godot_mesh = profile_map ? ticks() : 0;
|
||||
|
||||
// 地形碰撞(W1 item 6):HeightMapShape3D,129×129,格距 = CELL_M(缩放承载)
|
||||
if (collision_enabled) {
|
||||
@@ -545,6 +560,18 @@ bool Metin2World::build_chunk(int tx, int ty) {
|
||||
objects_placed += ck.objects;
|
||||
trees_placed += ck.trees;
|
||||
chunks.push_back(std::move(ck));
|
||||
if (profile_map) {
|
||||
const double profile_end = ticks();
|
||||
UtilityFunctions::print(vformat("MAP_PROFILE %d,%d height=%.3f attr=%.3f terrain_cpu=%.3f splat=%.3f tile=%.3f alpha=%.3f material=%.3f godot_mesh=%.3f rest=%.3f total=%.3f",
|
||||
tx, ty, (profile_height - profile_start) / 1000.0,
|
||||
(profile_attr - profile_height) / 1000.0,
|
||||
(profile_terrain - profile_attr) / 1000.0,
|
||||
(profile_splat - profile_terrain) / 1000.0,
|
||||
profile_tile_ms, profile_alpha_ms, profile_material_ms,
|
||||
(profile_godot_mesh - profile_splat) / 1000.0,
|
||||
(profile_end - profile_godot_mesh) / 1000.0,
|
||||
(profile_end - profile_start) / 1000.0));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user