From 28e10dde63a85bb28401c929d5be9a1d3feba6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Piliszek?= Date: Fri, 15 Nov 2024 21:48:41 +0100 Subject: [PATCH] Use only BSP-rendered faces in Vis::PickIndoorFaces_Mouse This requires clearing the BSP renderer when loading a new level as this function gets triggered before it gets called to render. --- src/Engine/Graphics/BspRenderer.cpp | 9 ++++++-- src/Engine/Graphics/BspRenderer.h | 3 ++- src/Engine/Graphics/Indoor.cpp | 3 ++- src/Engine/Graphics/Vis.cpp | 34 ++++++++++++++--------------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Engine/Graphics/BspRenderer.cpp b/src/Engine/Graphics/BspRenderer.cpp index 71e101d5a627..f9b3fef3b3cc 100644 --- a/src/Engine/Graphics/BspRenderer.cpp +++ b/src/Engine/Graphics/BspRenderer.cpp @@ -196,12 +196,17 @@ void BspRenderer::AddSector(int sectorId) { } -//----- (0043F953) -------------------------------------------------------- -void BspRenderer::Init() { +void BspRenderer::Clear() { // reset lists num_faces = 0; num_nodes = 0; uNumVisibleNotEmptySectors = 0; +} + + +//----- (0043F953) -------------------------------------------------------- +void BspRenderer::Render() { + Clear(); if (pBLVRenderParams->uPartySectorID) { // set to current sector - using eye sector here because feet can be in other sector on horizontal portal diff --git a/src/Engine/Graphics/BspRenderer.h b/src/Engine/Graphics/BspRenderer.h index a1a66219457d..e5293e03c6cd 100644 --- a/src/Engine/Graphics/BspRenderer.h +++ b/src/Engine/Graphics/BspRenderer.h @@ -27,7 +27,8 @@ struct BspFace { struct BspRenderer { public: - void Init(); + void Clear(); + void Render(); // TODO(yoctozepto): hide these unsigned int num_faces = 0; diff --git a/src/Engine/Graphics/Indoor.cpp b/src/Engine/Graphics/Indoor.cpp index 5bc24881ad20..ba190519a3d4 100644 --- a/src/Engine/Graphics/Indoor.cpp +++ b/src/Engine/Graphics/Indoor.cpp @@ -146,7 +146,7 @@ void PrepareDrawLists_BLV() { //pStationaryLightsStack->uNumLightsActive = 0; engine->StackPartyTorchLight(); - pBspRenderer->Init(); + pBspRenderer->Render(); render->DrawSpriteObjects(); pOutdoor->PrepareActorsDrawList(); @@ -945,6 +945,7 @@ void loadAndPrepareBLV(MapId mapid, bool bLoading) { uCurrentlyLoadedLevelType = LEVEL_INDOOR; pBLVRenderParams->uPartySectorID = 0; pBLVRenderParams->uPartyEyeSectorID = 0; + pBspRenderer->Clear(); engine->SetUnderwater(isMapUnderwater(mapid)); diff --git a/src/Engine/Graphics/Vis.cpp b/src/Engine/Graphics/Vis.cpp index e49684d55f8e..6633cff97e75 100644 --- a/src/Engine/Graphics/Vis.cpp +++ b/src/Engine/Graphics/Vis.cpp @@ -285,19 +285,21 @@ void Vis::PickIndoorFaces_Mouse(float fDepth, const Vec3f &rayOrigin, const Vec3 Vis_SelectionFilter *filter) { RenderVertexSoft a1; - // TODO(yoctozepto): this should rather use faces rendered by BSP - for (int faceindex = 0; faceindex < (int)pIndoor->pFaces.size(); ++faceindex) { - BLVFace *face = &pIndoor->pFaces[faceindex]; - face->uAttributes &= ~FACE_OUTLINED; + // clear the debug attribute + for (auto &face : pIndoor->pFaces) { + face.uAttributes &= ~FACE_OUTLINED; + } + + for (int i = 0; i < pBspRenderer->num_faces; ++i) { + int faceId = pBspRenderer->faces[i].uFaceID; + BLVFace *face = &pIndoor->pFaces[faceId]; if (isFacePartOfSelection(nullptr, face, filter)) { - if (pCamera3D->is_face_faced_to_cameraBLV(face)) { - if (Intersect_Ray_Face(rayOrigin, rayStep, &a1, face, 0xFFFFFFFFu)) { - pCamera3D->ViewTransform(&a1, 1); - list->AddObject(VisObjectType_Face, a1.vWorldViewPosition.x, Pid(OBJECT_Face, faceindex)); - if (engine->config->debug.ShowPickedFace.value()) - face->uAttributes |= FACE_OUTLINED; - } + if (Intersect_Ray_Face(rayOrigin, rayStep, &a1, face, 0xFFFFFFFFu)) { + pCamera3D->ViewTransform(&a1, 1); + list->AddObject(VisObjectType_Face, a1.vWorldViewPosition.x, Pid(OBJECT_Face, faceId)); + if (engine->config->debug.ShowPickedFace.value()) + face->uAttributes |= FACE_OUTLINED; } } } @@ -895,12 +897,10 @@ void Vis::PickIndoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vi for (int i = 0; i < pBspRenderer->num_faces; ++i) { int pFaceID = pBspRenderer->faces[i].uFaceID; BLVFace *pFace = &pIndoor->pFaces[pFaceID]; - if (pCamera3D->is_face_faced_to_cameraBLV(pFace)) { - if (isFacePartOfSelection(nullptr, pFace, filter)) { - Vis_ObjectInfo *v8 = DetermineFacetIntersection(pFace, Pid(OBJECT_Face, pFaceID), pick_depth); - if (v8) - list->AddObject(v8->object_type, v8->depth, v8->object_pid); - } + if (isFacePartOfSelection(nullptr, pFace, filter)) { + Vis_ObjectInfo *v8 = DetermineFacetIntersection(pFace, Pid(OBJECT_Face, pFaceID), pick_depth); + if (v8) + list->AddObject(v8->object_type, v8->depth, v8->object_pid); } } }