Batch #10262 by ragnarok-clanker: forced by an admin (1 lower score(s), 22 changed function(s)); checked with 170 compiled unit(s), including every includer of Source/Contents/Ground/GroundGeometry.h, Source/Contents/Ground/GroundRendering.h, Source/Contents/Ground/GroundSpatial.h, Source/Contents/World/WorldModelView.h, Source/Contents/World/WorldSpatialInitialization.h, Source/Contents/World/WorldSpatialTree.h.
72 lines
2 KiB
C++
72 lines
2 KiB
C++
#include "Contents/Ground/GroundGeometry.h"
|
|
#include "Contents/Models/ModelActor.h"
|
|
#include "Contents/World/WorldSpatialInitialization.h"
|
|
#include "Contents/World/WorldSpatialTree.h"
|
|
#include "Resource/World/TerrainResource.h"
|
|
|
|
#include <atomic>
|
|
|
|
// OFFSET: 0x00AC79C0
|
|
// FUNCTION: fn_17660
|
|
void InitializeWorldSpatial(
|
|
WorldSpatialTree& root, GroundGeometry& ground, C3dAttr& terrain, std::span<C3dActor* const> models, const WorldSpatialTree* serialized
|
|
) {
|
|
root.ClearChildren();
|
|
const int halfWidth = ground.width / 2;
|
|
const int halfHeight = ground.height / 2;
|
|
root.minimum[0] = static_cast<float>(ground.width / -2) * ground.cellSize;
|
|
root.maximum[0] = static_cast<float>(ground.width - halfWidth) * ground.cellSize - 1.0f;
|
|
root.minimum[2] = static_cast<float>(ground.height / -2) * ground.cellSize;
|
|
root.maximum[2] = static_cast<float>(ground.height - halfHeight) * ground.cellSize - 1.0f;
|
|
root.halfSize[0] = 0;
|
|
root.halfSize[2] = 0;
|
|
root.Subdivide(0);
|
|
|
|
for (C3dActor* model : models) {
|
|
for (WorldSpatialTree* child : root.children) {
|
|
if (model->oriented.Intersects(child->minimum)) {
|
|
child->InsertModel(*model, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
root.BindGround(ground, 0);
|
|
root.BindTerrain(terrain, 0);
|
|
|
|
if (serialized) {
|
|
root.CopyBounds(0, *serialized);
|
|
} else {
|
|
root.dirty = 0;
|
|
|
|
for (WorldSpatialTree* child : root.children) {
|
|
if (child->dirty) {
|
|
child->RefreshBounds(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// INLINED
|
|
void PublishWorldModels(WorldSpatialTree& root, C3dActor* const* models, int& published, int& pending) {
|
|
std::atomic_ref<int> count(pending);
|
|
const int ready = count.load(std::memory_order_acquire);
|
|
|
|
if (ready == 0) {
|
|
return;
|
|
}
|
|
|
|
const int end = published + ready;
|
|
|
|
while (published < end) {
|
|
C3dActor& model = *models[published];
|
|
|
|
for (WorldSpatialTree* child : root.children) {
|
|
if (model.oriented.Intersects(child->minimum)) {
|
|
child->InsertModel(model, 1);
|
|
}
|
|
}
|
|
|
|
count.fetch_sub(1, std::memory_order_seq_cst);
|
|
++published;
|
|
}
|
|
}
|