Skip to content

Commit

Permalink
🐛 Fixed cars without coll. cabs not activating eventboxes (i.e. race …
Browse files Browse the repository at this point in the history
…checkpoints)

Fixes RigsOfRods#3121
Fixes RigsOfRods#3097

This partially reverts d4ec0a0
* the "is a cabnode" node filter condition was dropped, see `Actor::UpdateBoundingBoxes()`.
* The `ar_cabnodes_bounding_box` got renamed to `ar_evboxes_bounding_box`.
  • Loading branch information
ohlidalp committed Mar 25, 2024
1 parent 6719338 commit ddd2025
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions source/main/physics/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ void Actor::UpdateBoundingBoxes()
// Reset
ar_bounding_box = AxisAlignedBox::BOX_NULL;
ar_predicted_bounding_box = AxisAlignedBox::BOX_NULL;
ar_cabnodes_bounding_box = AxisAlignedBox::BOX_NULL;
ar_evboxes_bounding_box = AxisAlignedBox::BOX_NULL;
for (size_t i = 0; i < ar_collision_bounding_boxes.size(); ++i)
{
ar_collision_bounding_boxes[i] = AxisAlignedBox::BOX_NULL;
Expand All @@ -1137,10 +1137,9 @@ 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)
&& (mainCamPos.squaredDistance(ar_nodes[i].RelPosition)) < (CABNODE_MAX_CAMDIST*CABNODE_MAX_CAMDIST)) // ... we compare squared distance for performance
if (mainCamPos.squaredDistance(ar_nodes[i].RelPosition) < (CABNODE_MAX_CAMDIST*CABNODE_MAX_CAMDIST))
{
ar_cabnodes_bounding_box.merge(pos);
ar_evboxes_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)
Expand Down
2 changes: 1 addition & 1 deletion source/main/physics/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Actor : public RefCountingObject<Actor>
std::vector<Airbrake*> ar_airbrakes;
CmdKeyArray ar_command_key; //!< BEWARE: commandkeys are indexed 1-MAX_COMMANDS!
Ogre::AxisAlignedBox ar_bounding_box; //!< standard bounding box (surrounds all nodes of an actor)
Ogre::AxisAlignedBox ar_cabnodes_bounding_box; //!< bounding box around cab-triangle nodes only
Ogre::AxisAlignedBox ar_evboxes_bounding_box; //!< bounding box around nodes eligible for eventbox triggering
Ogre::AxisAlignedBox ar_predicted_bounding_box;
float ar_initial_total_mass = 0.f;
std::vector<float> ar_initial_node_masses;
Expand Down
6 changes: 3 additions & 3 deletions source/main/physics/collision/Collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,11 +1088,11 @@ bool Collisions::nodeCollision(node_t *node, float dt)

void Collisions::findPotentialEventBoxes(Actor* actor, CollisionBoxPtrVec& out_boxes)
{
// NOTE: Only collision-cab nodes are considered for eventbox triggering!
// Find collision cells occupied by the actor (remember 'Y' is 'up').
// Remember there's a dedicated bounding box `ar_evboxes_bounding_box`.
// ----------------------------------------------------------------------

// Find collision cells occupied by the actor (remember 'Y' is 'up').
const AxisAlignedBox aabb = actor->ar_cabnodes_bounding_box;
const AxisAlignedBox aabb = actor->ar_evboxes_bounding_box;
const int cell_lo_x = (int)(aabb.getMinimum().x / (float)CELL_SIZE);
const int cell_lo_z = (int)(aabb.getMinimum().z / (float)CELL_SIZE);
const int cell_hi_x = (int)(aabb.getMaximum().x / (float)CELL_SIZE);
Expand Down

0 comments on commit ddd2025

Please sign in to comment.