C-Compliant clipmap trigger conversion

This commit is contained in:
rackover 2021-04-04 18:04:00 +02:00
parent f851a0a3a9
commit d610e85176
2 changed files with 31 additions and 19 deletions

View File

@ -587,12 +587,12 @@ namespace Assets
Game::clipMap_t* orgClipMap = nullptr; Game::clipMap_t* orgClipMap = nullptr;
Game::DB_EnumXAssets(Game::XAssetType::ASSET_TYPE_CLIPMAP_MP, [](Game::XAssetHeader header, void* clipMap) Game::DB_EnumXAssets(Game::XAssetType::ASSET_TYPE_CLIPMAP_MP, [](Game::XAssetHeader header, void* clipMap)
{
if (!*reinterpret_cast<void**>(clipMap))
{ {
*reinterpret_cast<Game::clipMap_t**>(clipMap) = header.clipMap; if (!*reinterpret_cast<void**>(clipMap))
} {
}, &orgClipMap, false); *reinterpret_cast<Game::clipMap_t**>(clipMap) = header.clipMap;
}
}, &orgClipMap, false);
if (orgClipMap) std::memcpy(clipMap, orgClipMap, sizeof Game::clipMap_t); if (orgClipMap) std::memcpy(clipMap, orgClipMap, sizeof Game::clipMap_t);
@ -887,13 +887,18 @@ namespace Assets
// add triggers to mapEnts // add triggers to mapEnts
std::vector<Game::TriggerSlab> slabs;
std::vector<Game::TriggerHull> hulls;
std::vector<Game::TriggerModel> models;
clipMap->mapEnts->trigger.count = clipMap->numSubModels; clipMap->mapEnts->trigger.count = clipMap->numSubModels;
clipMap->mapEnts->trigger.hullCount = clipMap->numSubModels; clipMap->mapEnts->trigger.hullCount = clipMap->numSubModels;
clipMap->mapEnts->trigger.slabCount = 0; clipMap->mapEnts->trigger.slabCount = clipMap->numSubModels * 1000;
Game::TriggerHull* hulls = builder->getAllocator()->allocateArray<Game::TriggerHull>(clipMap->mapEnts->trigger.hullCount * sizeof(Game::TriggerHull));
Game::TriggerModel* models = builder->getAllocator()->allocateArray<Game::TriggerModel>(clipMap->mapEnts->trigger.count * sizeof(Game::TriggerModel));
Game::TriggerSlab* slabs = builder->getAllocator()->allocateArray<Game::TriggerSlab>(clipMap->mapEnts->trigger.slabCount * sizeof(Game::TriggerSlab));
int hullCountSoFar = 0;
int slabCountSoFar = 0;
for (int i = 0; i < clipMap->numSubModels; ++i) for (int i = 0; i < clipMap->numSubModels; ++i)
{ {
@ -910,12 +915,12 @@ namespace Assets
if (!node->leafBrushCount) continue; // skip empty brushes if (!node->leafBrushCount) continue; // skip empty brushes
int baseHull = hulls.size(); int baseHull = hullCountSoFar;
for (int j = 0; j < node->leafBrushCount; ++j) for (int j = 0; j < node->leafBrushCount; ++j)
{ {
auto* brush = &clipMap->brushes[node->data.leaf.brushes[j]]; auto* brush = &clipMap->brushes[node->data.leaf.brushes[j]];
auto baseSlab = slabs.size(); auto baseSlab = slabCountSoFar;
for (int k = 0; k < brush->numsides; ++k) for (int k = 0; k < brush->numsides; ++k)
{ {
Game::TriggerSlab curSlab; Game::TriggerSlab curSlab;
@ -925,23 +930,23 @@ namespace Assets
curSlab.halfSize = brush->sides[k].plane->dist; curSlab.halfSize = brush->sides[k].plane->dist;
curSlab.midPoint = 0.0f; // ?? curSlab.midPoint = 0.0f; // ??
slabs.emplace_back(curSlab); slabs[slabCountSoFar] = curSlab;
clipMap->mapEnts->trigger.slabCount++; slabCountSoFar++;
} }
trigHull.firstSlab = baseSlab; trigHull.firstSlab = baseSlab;
trigHull.slabCount = slabs.size() - baseSlab; trigHull.slabCount = slabCountSoFar - baseSlab;
} }
models.emplace_back(trigMod); models[i] = trigMod;
hulls.emplace_back(trigHull); hulls[i] = trigHull;
hullCountSoFar++;
} }
clipMap->mapEnts->trigger.models = &models[0]; clipMap->mapEnts->trigger.models = &models[0];;
clipMap->mapEnts->trigger.hulls = &hulls[0]; clipMap->mapEnts->trigger.hulls = &hulls[0];
clipMap->mapEnts->trigger.slabs = &slabs[0]; clipMap->mapEnts->trigger.slabs = &slabs[0];
// This mustn't be null and has to have at least 1 'valid' entry. // This mustn't be null and has to have at least 1 'valid' entry.
if (!clipMap->smodelNodeCount || !clipMap->smodelNodes) if (!clipMap->smodelNodeCount || !clipMap->smodelNodes)
{ {

View File

@ -1071,7 +1071,7 @@ namespace Components
if(ent->r.isInUse) if(ent->r.isInUse)
{ {
auto b = ent->r.box; Game::Bounds b = ent->r.box;
b.midPoint[0] += ent->r.currentOrigin[0]; b.midPoint[0] += ent->r.currentOrigin[0];
b.midPoint[1] += ent->r.currentOrigin[1]; b.midPoint[1] += ent->r.currentOrigin[1];
b.midPoint[2] += ent->r.currentOrigin[2]; b.midPoint[2] += ent->r.currentOrigin[2];
@ -1098,6 +1098,13 @@ namespace Components
break; break;
default: default:
float rv = std::min((float)ent->handler, (float)5) / 5;
float gv = std::clamp((float)ent->handler-5, (float)0, (float)5) / 5;
float bv = std::clamp((float)ent->handler - 10, (float)0, (float)5) / 5;
float color[4] = { rv, gv, bv, 1.0f };
Game::R_AddDebugBounds(color, &b);
break; break;
} }
} }