celechii

known cat petter

  • they/she

genderfluid dumbass full of love amongst other things

i make games at ko_op :)

cat counter: 291 (record: 523)


game makin streams
twitch.tv/celechii
@chocolatinebabe (ffxiv account (fishing))
cohost.org/chocolatinebabe

ok so i'm implementing this now cause it's piqued my interest again and is one of those things that's made SO much harder with rollback considerations that ya just wouldn't think about so i'm gonna talk about it!!

#1: we gotta handle multiple calls to play audio

so one of the big issues main issue for rollback and audio is unsurprisingly that the game state has to roll back and re-simulate the same game logic sometimes several times over. this includes situations like frame 5 saying "hey play this sound effect", then on frame 6 we get remote input for frame 3, and then re-simulate frames 3, 4, 5, and 6, where frame 5 still says "hey play this sound effect", and then frame 7 we get input for frame 4 and re-simulate frames 4, 5, 6, and 7, and you get the point. we've gotta have some kinda system in our sound player that knows when it's being asked to play a sound it's already started playing!

but surely we can just ignore calls to play sounds when we're re-simulating, right?

#2: nah we gotta handle playing sounds that we didn't know started playing earlier, too

say on frame 5 our opponent throws a punch and that plays a sound effect. when we get that punch input on frame 8 and roll back to frame 5 to re-simulate, we now know a sound effect should have been playing 3 frames ago, so now our sound player needs to know when a sound should have been played, and play it starting 3/60ths in (idk if i'll bother doing this part cause it might just sound weird at that small of a delay?)

#3: stop playing sounds we thought would exist but actually don't

another scenario is say you start a big attack that plays a sound effect for it's whole duration, so as soon as you start that attack, the sound effect starts. and THEN you get a rollback with old inputs that say that actually the opponent hit you before you could start that attack so you should have never been able to start it and it now needs to stop playing. you've gotta be checking that while you're in re-simulation that all the sounds you were playing in that time frame ARE requested to be played again, otherwise it means that they weren't actually supposed to play in the first place and need to be stopped. which sounds like no big deal, but

#4: sound playing instances can't be referenced by the game simulation cause everything's just a bunch of structs that get modified by systems but can't in themselves hold any persistence over time

yea :/

ok so how do u do it

this is me saying this before i've implemented it and worked it all out 100% but the way i'm going to approach it is by keeping track of all Play() requests with a struct containing the entity ID that called it, the frame it was requested to play on, and a reference to the sound's data. by default, any request to play a sound will just be played or stopped at the end of the frame, unless a rollback has happened, in which case we compile a list of all the sounds asked to play during any of the re-simulation frames, and as we get calls to play them again, remove them from the list. any sounds left in the list at the end will be stopped. any sounds asked to play that weren't part of that list will play anyways, taking into account the frame they were supposed to start playing vs the current frame (maybe, if this doesn't end up sounding weird)

and that's all i've been thinking about!! this is only part of the audio system as it relates to the rollback part of the game, so i've still gotta make the whole sound effect data scriptable object tools, and the audio source object pooling system, maybe dynamic left/right panning relative to the camera? idk sounds fun but i'm sleepy so see ya next time

:eggbug-asleep:


You must log in to comment.

in reply to @celechii's post:

i am!! but thankfully the rest of my pseudo ecs structure handles that kinda thing a lot easier since all of this special audio work is to get around the fact that audio is the one thing part of the engine that can't just move forwards and backwards in the simulation due to needing to be routed through unity's audio system ehe

if it's tied to the frame, what about situations where an event still happens, just slightly later/earlier than it had been simulated to? like a hit thwack that presumed the opponent stood still, but actually they started dodging, but they were late enough to dodging that the hit still connected anyway, just a few frames later than it was simulated to

in that case itd stop the first sound and restart it a bit later! if the frames they were asked to play aren't the same then they could just be different sounds, but id imagine that could definitely create some strange audio artifacts so maybe it should be checking for the frames to be the same with a 1-2 frame tolerance?

good luck with the game! that's pretty much how i did the audio in my previous game with rollback (chessplosion), and i don't bother skipping past the first few 60ths of a second when i realize i should have started playing a sound 3/60ths of a second ago or whatever. i told myself that hearing a sound cue a couple of frames late would be less jarring than skipping past the first part of the sound, but in truth i was just too lazy to try it out.

thank u!! and yeee that's my intuition too, but in order to support longer sounds with that need to be synced up with the whole animation im gonna give it a shot and see how it goes!

i've seen other fighting games handle that sort of thing by splitting the sound into multiple parts if possible. such as having separate "falcon" and "punch!" sounds instead of one long "falcon........punch!" sound. so if there's a high ping, you'll hear "falcon...punch!" with a smaller gap between the two words than usual, instead of "-alcon........punch!"

but a) splitting a long sound into multiple parts might not be feasible for whatever you're doing, and b) you might prefer how the latter option sounds anyway. good luck!

also if you start a sound late or cut it off early, make sure your sound engine fades it in or out quickly rather than completely stop right in the middle, to avoid popping sounds (your game engine might already handle this for you)