Skip to content
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

Make GFX match physics speed #3138

Closed
wants to merge 2 commits into from

Conversation

Miner34dev
Copy link

@Miner34dev Miner34dev commented Mar 8, 2024

Progress:

  • HydraX waves
  • Particles (WIP)
  • Other effects (like water godrays)
  • Cleanup

@Miner34dev
Copy link
Author

Miner34dev commented Mar 10, 2024

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
Copy link
Member

ohlidalp commented Mar 11, 2024

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
Copy link
Author

Miner34dev commented Mar 15, 2024

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
Copy link
Member

ohlidalp commented Mar 24, 2024

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
Copy link
Author

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
Copy link
Author

Miner34dev commented Apr 28, 2024

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.

ohlidalp added a commit to ohlidalp/rigs-of-rods that referenced this pull request Jul 30, 2024
I noticed beacons run when game is paused and also ignore simulation speed, always running at wall time. I remembered there are multiple other issues like this (props/water waves moving when paused) and I figured a way to tackle everything at once - I changed the time input for the entire scene update code (which is already consolidated into `GfxScene::UpdateScene()`) - instead of inputting wall time, I now input the adjusted simulation time, and I input zero if the game is paused or physics are globally paused.

The particles had a custom code to correctly calc. sim. time and skip the update entirely when paused. I reverted all that, expecting the adjusted time input to fix particles, but that didn't work. I already researched this at RigsOfRods#3138 and figured to use `Ogre::ParticleSystem::setSpeedFactor()` - that did the trick.
ohlidalp added a commit to ohlidalp/rigs-of-rods that referenced this pull request Jul 30, 2024
I noticed beacons run when game is paused and also ignore simulation speed, always running at wall time. I remembered there are multiple other issues like this (props/water waves moving when paused) and I figured a way to tackle everything at once - I changed the time input for the entire scene update code (which is already consolidated into `GfxScene::UpdateScene()`) - instead of inputting wall time, I now input the adjusted simulation time, and I input zero if the game is paused or physics are globally paused.

The particles had a custom code to correctly calc. sim. time and skip the update entirely when paused. I reverted all that, expecting the adjusted time input to fix particles, but that didn't work. I already researched this at RigsOfRods#3138 and figured to use `Ogre::ParticleSystem::setSpeedFactor()` - that did the trick.
@ohlidalp
Copy link
Member

ohlidalp commented Aug 4, 2024

Closing in favor of #3170

@ohlidalp ohlidalp closed this Aug 4, 2024
@Miner34dev Miner34dev deleted the gfx-speed-fix branch August 5, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants