Skip to content

Commit

Permalink
Eventbox perf workaround: ignore cabnodes farther than 15m
Browse files Browse the repository at this point in the history
    // To avoid performance choking by overstretched bounding box (happens when vehicle drops some nodes),
    // we set a maximum distance limit from the main camera.
    const float CABNODE_MAX_CAMDIST = 15.f;
  • Loading branch information
ohlidalp committed Sep 3, 2023
1 parent ba2a2c3 commit 836e3c9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/main/physics/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,11 @@ void Actor::UpdateBoundingBoxes()
ar_predicted_coll_bounding_boxes[i] = AxisAlignedBox::BOX_NULL;
}

// To avoid performance choking by overstretched bounding box (happens when vehicle drops some nodes),
// we set a maximum distance limit from the main camera.
const float CABNODE_MAX_CAMDIST = 15.f;
const Ogre::Vector3 mainCamPos = ar_nodes[ar_main_camera_node_pos].RelPosition;

// Update
for (int i = 0; i < ar_num_nodes; i++)
{
Expand All @@ -1130,8 +1135,11 @@ void Actor::UpdateBoundingBoxes()
int16_t cid = ar_nodes[i].nd_coll_bbox_id;

ar_bounding_box.merge(pos); // Current box
if (ar_nodes[i].nd_cab_node) // Current cab-nodes box (for eventbox collisions)
if (ar_nodes[i].nd_cab_node // Current cab-nodes box (for eventbox collisions)
&& (mainCamPos.squaredDistance(ar_nodes[i].RelPosition)) < (CABNODE_MAX_CAMDIST*CABNODE_MAX_CAMDIST)) // ... we compare squared distance for performance
{
ar_cabnodes_bounding_box.merge(pos);
}
ar_predicted_bounding_box.merge(pos); // Predicted box (current position)
ar_predicted_bounding_box.merge(pos + vel); // Predicted box (future position)
if (cid != node_t::INVALID_BBOX)
Expand Down

0 comments on commit 836e3c9

Please sign in to comment.