New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Codechange] Reworked the sleeping mechanism #1187

Merged
merged 1 commit into from Oct 18, 2016

Conversation

Projects
None yet
2 participants
@ulteq
Contributor

ulteq commented Oct 18, 2016

  • Trucks now stay active for at least 10 seconds before they go sleeping again.
  • Trucks won't go sleeping if another SIMULATED truck is nearby.

But it also brings back parts of the 0.38.67 sleeping behavior:

  • Sets of SIMULATED trucks can go sleeping if neither of them is active (player in them)
[Codechange] Reworked the sleeping mechanism
Trucks now stay active for at least 10 seconds before they go sleeping again

Brings back some of the 0.38 sleeping behaviour (sets of 'SIMULATED' trucks sleep if neither of them is active (player in them))
@only-a-ptr

Now that you touched this area...

for (int t=0; t < m_free_truck; t++)
{
if (t == j || !m_trucks[t]) continue;
if (predictTruckIntersectionCollAABB(t, j))
if (t == j || !m_trucks[t] || visited[t]) continue;

This comment has been minimized.

@only-a-ptr

only-a-ptr Oct 18, 2016

Member

Doesn't this completely defeat the point of the recursion? Unless I'm missing something, this means each truck will be evaluated exactly 1x no matter how many trucks may actually intersect with it, and that's a broken design.

@only-a-ptr

only-a-ptr Oct 18, 2016

Member

Doesn't this completely defeat the point of the recursion? Unless I'm missing something, this means each truck will be evaluated exactly 1x no matter how many trucks may actually intersect with it, and that's a broken design.

This comment has been minimized.

@ulteq

ulteq Oct 18, 2016

Contributor

Doesn't this completely defeat the point of the recursion?

It prevents creating a cyclic graph.

this means each truck will be evaluated exactly 1x

That's what we want. We want to call RecursiveActivation at most one times per truck. Which will only happen if all trucks can be reached from the current_truck.

@ulteq

ulteq Oct 18, 2016

Contributor

Doesn't this completely defeat the point of the recursion?

It prevents creating a cyclic graph.

this means each truck will be evaluated exactly 1x

That's what we want. We want to call RecursiveActivation at most one times per truck. Which will only happen if all trucks can be reached from the current_truck.

@ulteq

This comment has been minimized.

Show comment
Hide comment
@ulteq

ulteq Oct 18, 2016

Contributor

BeamFactory::UpdateSleepingState runs once per frame. It creates a directed acyclic graph. The vertices equate to trucks and the edges to bounding box intersections.

The current truck (the one the player sits in) is the only root of the graph.

Now that you touched this area...

It's not the first time I touched it. I've already simplified it greatly in this PR: a0a85c8

Our sleep mechanism doesn't cache AABB intersections.

It doesn't need to cache them, because we never check the same edge twice.

Also, performance; Ogre's AABBs are slow

It's not worth to mess with them before we upgrade Ogre in my opinion.

Contributor

ulteq commented Oct 18, 2016

BeamFactory::UpdateSleepingState runs once per frame. It creates a directed acyclic graph. The vertices equate to trucks and the edges to bounding box intersections.

The current truck (the one the player sits in) is the only root of the graph.

Now that you touched this area...

It's not the first time I touched it. I've already simplified it greatly in this PR: a0a85c8

Our sleep mechanism doesn't cache AABB intersections.

It doesn't need to cache them, because we never check the same edge twice.

Also, performance; Ogre's AABBs are slow

It's not worth to mess with them before we upgrade Ogre in my opinion.

@only-a-ptr

This comment has been minimized.

Show comment
Hide comment
@only-a-ptr

only-a-ptr Oct 18, 2016

Member

It's not the first time I touched it. I've already simplified it greatly in this PR: a0a85c8

That was a big win indeed.

a directed acyclic graph. ...The current truck is the only root of the graph.

I'm afraid that's not an universal solution. It works for the most stereotypical RoR scenario. But what if you build a tower of paper boxes and then shoot it with a tennis-ball cannon?

The graph is still fine, but you'll need one per each moving element. Falling boxes may wake up other boxes. Under these circumstances, both caching and AABB efficiency come back to play.

It's not worth to mess with them before we upgrade Ogre in my opinion.

Agreed. And nobody implemented anything like the tennis-ball scenario so far. But it'll come (I hope!). It's something to keep in mind.

:shipit:

Member

only-a-ptr commented Oct 18, 2016

It's not the first time I touched it. I've already simplified it greatly in this PR: a0a85c8

That was a big win indeed.

a directed acyclic graph. ...The current truck is the only root of the graph.

I'm afraid that's not an universal solution. It works for the most stereotypical RoR scenario. But what if you build a tower of paper boxes and then shoot it with a tennis-ball cannon?

The graph is still fine, but you'll need one per each moving element. Falling boxes may wake up other boxes. Under these circumstances, both caching and AABB efficiency come back to play.

It's not worth to mess with them before we upgrade Ogre in my opinion.

Agreed. And nobody implemented anything like the tennis-ball scenario so far. But it'll come (I hope!). It's something to keep in mind.

:shipit:

@ulteq ulteq merged commit ee547f6 into RigsOfRods:master Oct 18, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@ulteq ulteq deleted the ulteq:reworked-sleeping-mechanism branch Oct 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment