From f4e7bbfbb5ae5660e7d11b30ea0b6e17065518ad Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 5 Nov 2026 03:24:34 +0000 Subject: [PATCH] Decompile 2 functions in Source/Contents/World/WorldSpatialInitialization.cpp, Source/Contents/World/WorldSpatialInitialization.h, ... Batch #11543 by cremane: 0 byte-identical, 2 confirmed by peer review. - fn_17660 CWorld::InitializeSpatial: logic confirmed by peer review - fn_17684 CWorld::InitWorld: logic confirmed by peer review Peer-reviewed-by: Yommy, KWDev Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Contents/World/World.h | 1 + Source/Contents/World/WorldModelLoading.cpp | 2 +- .../World/WorldSpatialInitialization.cpp | 45 ++++++++++--------- .../World/WorldSpatialInitialization.h | 4 -- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Source/Contents/World/World.h b/Source/Contents/World/World.h index 896b5dbc..c91ef20d 100644 --- a/Source/Contents/World/World.h +++ b/Source/Contents/World/World.h @@ -56,6 +56,7 @@ public: void AddPcPosFromCell(std::uint32_t aid, const int* cell); void AddPcPosUnindexed(std::uint32_t aid, const CellFloatPos& cell); void InitWorld(); + void InitializeSpatial(); void RemoveObject(CRenderObject* object); void SendObjectMessage(CGameObject* sender, std::uint64_t identity, int message, int a, int b, int c, int d); static unsigned long __stdcall LoadDeferredModels(void* parameter); diff --git a/Source/Contents/World/WorldModelLoading.cpp b/Source/Contents/World/WorldModelLoading.cpp index 603244d5..3d027e28 100644 --- a/Source/Contents/World/WorldModelLoading.cpp +++ b/Source/Contents/World/WorldModelLoading.cpp @@ -271,7 +271,7 @@ void CWorld::InitWorld() { } } - InitializeWorldSpatial(this->spatial, *this->ground, *this->terrain, this->models, this->serializedSpatial); + this->InitializeSpatial(); this->LoadMapEffects(); reinterpret_cast(groundVtbl[11])(this->ground); diff --git a/Source/Contents/World/WorldSpatialInitialization.cpp b/Source/Contents/World/WorldSpatialInitialization.cpp index ce0913ee..1e91acf4 100644 --- a/Source/Contents/World/WorldSpatialInitialization.cpp +++ b/Source/Contents/World/WorldSpatialInitialization.cpp @@ -1,5 +1,6 @@ #include "Contents/Ground/GroundGeometry.h" #include "Contents/Models/ModelActor.h" +#include "Contents/World/World.h" #include "Contents/World/WorldSpatialInitialization.h" #include "Contents/World/WorldSpatialTree.h" #include "Resource/World/TerrainResource.h" @@ -8,37 +9,39 @@ // OFFSET: 0x00AC79C0 // FUNCTION: fn_17660 -void InitializeWorldSpatial( - WorldSpatialTree& root, GroundGeometry& ground, C3dAttr& terrain, std::span models, const WorldSpatialTree* serialized -) { - root.ClearChildren(); - const int halfWidth = ground.width / 2; - const int halfHeight = ground.height / 2; - root.minimum[0] = static_cast(ground.width / -2) * ground.cellSize; - root.maximum[0] = static_cast(ground.width - halfWidth) * ground.cellSize - 1.0f; - root.minimum[2] = static_cast(ground.height / -2) * ground.cellSize; - root.maximum[2] = static_cast(ground.height - halfHeight) * ground.cellSize - 1.0f; - root.halfSize[0] = 0; - root.halfSize[2] = 0; - root.Subdivide(0); +void CWorld::InitializeSpatial() { + this->spatial.ClearChildren(); + const int halfWidth = this->ground->width / 2; + const int halfHeight = this->ground->height / 2; + this->spatial.minimum[0] = static_cast(-halfWidth) * this->ground->cellSize; + this->spatial.maximum[0] = static_cast(this->ground->width - halfWidth) * this->ground->cellSize - 1.0f; + this->spatial.minimum[2] = static_cast(-halfHeight) * this->ground->cellSize; + this->spatial.maximum[2] = static_cast(this->ground->height - halfHeight) * this->ground->cellSize - 1.0f; + this->spatial.center[0] = 0; + this->spatial.center[2] = 0; + this->spatial.Subdivide(0); - for (C3dActor* model : models) { - for (WorldSpatialTree* child : root.children) { + for (auto it = this->models.begin(); it != this->models.end(); ++it) { + C3dActor* model = *it; + + for (int i = 0; i < 4; ++i) { + WorldSpatialTree* child = this->spatial.children[i]; if (model->oriented.Intersects(child->minimum)) { child->InsertModel(*model, 1); } } } - root.BindGround(ground, 0); - root.BindTerrain(terrain, 0); + this->spatial.BindGround(*this->ground, 0); + this->spatial.BindTerrain(*this->terrain, 0); - if (serialized) { - root.CopyBounds(0, *serialized); + if (this->serializedSpatial) { + this->spatial.CopyBounds(0, *this->serializedSpatial); } else { - root.dirty = 0; + this->spatial.dirty = 0; - for (WorldSpatialTree* child : root.children) { + for (int i = 0; i < 4; ++i) { + WorldSpatialTree* child = this->spatial.children[i]; if (child->dirty) { child->RefreshBounds(1); } diff --git a/Source/Contents/World/WorldSpatialInitialization.h b/Source/Contents/World/WorldSpatialInitialization.h index f922d97b..55c21581 100644 --- a/Source/Contents/World/WorldSpatialInitialization.h +++ b/Source/Contents/World/WorldSpatialInitialization.h @@ -8,10 +8,6 @@ class GroundGeometry; class C3dAttr; class C3dActor; -void InitializeWorldSpatial( - WorldSpatialTree& root, GroundGeometry& ground, C3dAttr& terrain, std::span models, const WorldSpatialTree* serialized -); - void PublishWorldModels(WorldSpatialTree& root, C3dActor* const* models, int& published, int& pending); #endif