johanhelsing / johanhelsing.github.io

Johan Helsings github page
1 stars 0 forks source link

Cargo Space Devlog #4 #28

Open johanhelsing opened 1 year ago

johanhelsing commented 1 year ago

https://johanhelsing.studio/posts/cargo-space-devlog-4

mikeder commented 1 year ago

Awesome write-up on handling rollback audio, I found it super helpful and have implemented most of your examples into the game I'm currently working on - hope you don't mind!

I did notice a typo in this block of code:

fn remove_finished_sounds(
    frame: Res<FrameCount>,
    query: Query<(Entity, &RollbackSound)>,
    mut commands: Commands,
    audio_sources: Res<Assets<AudioSource>>,
) {
    for (entity, rollback_sound) in query.iter() {

        if let Some(audio_source) = audio_sources.get(&sfx.clip) { // << sfx should be "rollback_sound"
            let frames_played = **frame - rollback_sound.start_frame;
            let seconds_to_play = audio_source.sound.duration().as_secs_f64();
            let frames_to_play = (seconds_to_play * ROLLBACK_FPS as f64) as usize;

            if frames_played >= frames_to_play {
                commands.entity(entity).despawn();
            }
        }
    }
}

I was also curious if you could talk about the performance hit, if there is one, for increasing the max prediction window and frames behind config here:

let mut session_builder = SessionBuilder::<GGRSConfig>::new()
    .with_max_prediction_window(40)
    .with_max_frames_behind(42)
    .unwrap()

Thanks again for the detailed post!

johanhelsing commented 10 months ago

@mikeder thanks, nice catch :)

And super inspiring that you find the tutorial useful. Makes me more motivated to keep writing!

PraxTube commented 8 months ago

Thank you for writing such detailed (almost tutorial like) dev logs, you have no idea how helpful they are!

I noticed that the sub_key with the id (renamed to index by now) doesn't work quite well when a lot of the same sounds are spawned but the corresponding entity that spawns them doesn't live as long as the sound.

To counter that I added the current frame to the sub_key.

sub_key: (explosion_entity.index() + frame.0) as usize,

It's not a great solution, but it works fairly well.