RigsOfRods / rigs-of-rods

Main development repository for Rigs of Rods soft-body physics simulator
https://www.rigsofrods.org
GNU General Public License v3.0
990 stars 175 forks source link

Make GFX match physics speed #3138

Open Miner34dev opened 3 months ago

Miner34dev commented 3 months ago

Progress:

Miner34dev commented 3 months ago

This may take a bit more than i expected since dustpool.cpp seems to not be able to be slowed down/sped up at all and may require some extensive modification.

ohlidalp commented 3 months ago

Hello there, this is an unusually ambitious project for a guest developer, I like it.

To be honest I don't know how OGRE's particle system is used properly - our dustpool seems to literally reserve a pool of 100 Ogre::ParticleSystem instances and then 'allocate' them as needed. However, this might do the trick: https://ogrecave.github.io/ogre/api/1.11/class_ogre_1_1_particle_system.html#afd8ec707603e16d1b0eec2e734486947 - basically it should be an one-liner inside the DustPool::update() loop:

pss[i]->setSpeedFactor(App::GetGameContext()->GetActorManager()->GetSimulationSpeed());

If you use Discord, come visit our #dev channel: https://discord.com/channels/136544456244461568/189904947649708032

Miner34dev commented 3 months ago

However, this might do the trick: https://ogrecave.github.io/ogre/api/1.11/class_ogre_1_1_particle_system.html#afd8ec707603e16d1b0eec2e734486947 - basically it should be an one-liner inside the DustPool::update() loop:

pss[i]->setSpeedFactor(App::GetGameContext()->GetActorManager()->GetSimulationSpeed());

As i expected, it works only partially. The smoke follows physics speed but doesn't stop when you stop them, sparks seem to be slowed down but something looks wrong (don't know what exactly) and all the other particles are completely unaffected. I'm trying to figure out why.

ohlidalp commented 3 months ago

Hmm, I guess we must do this:

const float speedFactor = (App::sim_state->GetEnum<SimState>() == SimState::PAUSED) 
    ? 0.f 
    : App::GetGameContext()->GetActorManager()->GetSimulationSpeed();
// ~~~~~~~
pss[i]->setSpeedFactor(speedFactor);

or just pss[i]->setSpeedFactor(0.f); once when pausing.

Miner34dev commented 2 months ago

Hmm, I guess we must do this:

const float speedFactor = (App::sim_state->GetEnum<SimState>() == SimState::PAUSED) 
    ? 0.f 
    : App::GetGameContext()->GetActorManager()->GetSimulationSpeed();
// ~~~~~~~
pss[i]->setSpeedFactor(speedFactor);

or just pss[i]->setSpeedFactor(0.f); once when pausing.

I have no idea why, but it has no effect.

Miner34dev commented 2 months ago

Found the problem. GFXScene only updates the particles if the physics aren't stopped. EDIT: I fixed it. now smoke is working correctly. Sparks stop moving but disappear shortly (now i have to fix this one) Also there are a few more problems like with paused vehicles, game paused (esc) and replay mode but will fix those later.