Skip to content

Commit

Permalink
Merge pull request OpenEnroth#1884 from yoctozepto/bsppick
Browse files Browse the repository at this point in the history
Use only BSP-rendered faces in Vis::PickIndoorFaces_Mouse
  • Loading branch information
captainurist authored Nov 16, 2024
2 parents 96c6e93 + 28e10dd commit 17627ec
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
9 changes: 7 additions & 2 deletions src/Engine/Graphics/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Engine/Graphics/BspRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ struct BspFace {

struct BspRenderer {
public:
void Init();
void Clear();
void Render();

// TODO(yoctozepto): hide these
unsigned int num_faces = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/Engine/Graphics/Indoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void PrepareDrawLists_BLV() {
//pStationaryLightsStack->uNumLightsActive = 0;
engine->StackPartyTorchLight();

pBspRenderer->Init();
pBspRenderer->Render();

render->DrawSpriteObjects();
pOutdoor->PrepareActorsDrawList();
Expand Down Expand Up @@ -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));

Expand Down
34 changes: 17 additions & 17 deletions src/Engine/Graphics/Vis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 17627ec

Please sign in to comment.