Skip to content

Commit 089f62b

Browse files
committed
Multithreaded see casting
1 parent 522445e commit 089f62b

16 files changed

+28
-12
lines changed

Source/Entities/Actor.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,18 +1090,9 @@ void Actor::Update() {
10901090
// Update the viewpoint to be at least what the position is
10911091
m_ViewPoint = m_Pos;
10921092

1093-
// "See" the location and surroundings of this actor on the unseen map
1094-
// Todo - split MT safe and potentially expensive stuff like this in a seperate ThreadedUpdate for the C++ side
1095-
if (m_Status != Actor::INACTIVE) {
1096-
const int lookIterations = 6; // How many see rays to cast per frame
1097-
for (int i = 0; i < lookIterations; ++i) {
1098-
Look(45 * m_Perceptiveness, g_FrameMan.GetPlayerScreenWidth() * 0.51 * m_Perceptiveness);
1099-
}
1100-
}
1101-
11021093
// Check if the MO we're following still exists, and if not, then clear the destination
11031094
if (m_pMOMoveTarget && !g_MovableMan.ValidMO(m_pMOMoveTarget)) {
1104-
m_pMOMoveTarget = 0;
1095+
m_pMOMoveTarget = nullptr;
11051096
}
11061097

11071098
///////////////////////////////////////////////////////////////////////////////
@@ -1275,6 +1266,16 @@ void Actor::Update() {
12751266
}
12761267
}
12771268

1269+
void RTE::Actor::CastSeeRays() {
1270+
// "See" the location and surroundings of this actor on the unseen map
1271+
if (m_Status != Actor::INACTIVE) {
1272+
const int lookIterations = 6; // How many see rays to cast per frame
1273+
for (int i = 0; i < lookIterations; ++i) {
1274+
Look(45 * m_Perceptiveness, g_FrameMan.GetPlayerScreenWidth() * 0.51 * m_Perceptiveness);
1275+
}
1276+
}
1277+
}
1278+
12781279
void Actor::FullUpdate() {
12791280
PreControllerUpdate();
12801281
m_Controller.Update();

Source/Entities/Actor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ namespace RTE {
664664
/// Updates this MovableObject. Supposed to be done every frame.
665665
void Update() override;
666666

667+
/// Cast see rays for this actor.
668+
void CastSeeRays();
669+
667670
/// Updates the full state of this object in one call. (PreControllerUpdate(), Controller::Update(), and Update())
668671
virtual void FullUpdate() override;
669672

Source/Managers/MovableMan.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,14 @@ void MovableMan::Update() {
13671367
g_PerformanceMan.StopPerformanceMeasurement(PerformanceMan::ScriptsUpdate);
13681368

13691369
{
1370+
auto actorsSeeFuture = g_ThreadMan.GetPriorityThreadPool().parallelize_loop(m_Actors.size(),
1371+
[&](int start, int end) {
1372+
ZoneScopedN("Actors See");
1373+
for (int i = start; i < end; ++i) {
1374+
m_Actors[i]->CastSeeRays();
1375+
}
1376+
});
1377+
13701378
{
13711379
ZoneScopedN("Actors Update");
13721380

@@ -1438,6 +1446,8 @@ void MovableMan::Update() {
14381446
particle->PostUpdate();
14391447
}
14401448
}
1449+
1450+
actorsSeeFuture.wait();
14411451
} // namespace RTE
14421452

14431453
//////////////////////////////////////////////////////////////////////
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)