We Put Fighting Game Netcode in Brood War
Comments
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
LAGGY PROTOSS!
YOU SEE THIS? DO YOU SEE THIS? >> [screaming]
>> IF YOU'VE PLAYED STARCRAFT ONLINE IN THE LAST, WELL, EVER, I'm sure you know this feeling. You take a fight mid-game, you're splitting your units to avoid damage, and then the game just freezes. Or your units take just a bit too long to listen. Or maybe your supply depot doesn't make. Lag has always been a factor in online Brood War, until now.
>> [music]
[music]
[music] >> This is rollback netcode, and it's live on Shield Battery today. [music] Your units respond on the very next frame, and the lag that used to freeze the game turns into a tiny hop you'll barely notice. And the trick behind it is surprisingly simple. Your game has a good guess of what your opponent is going to do before they [music] do it. And it's right 90% of the time. >> [music]
>> To see why that works, we need to take a look at how Brood War plays a game over the internet in the first place. In Brood War, every player's computer runs the entire game simulation on its own. Unit positions, resource counts, fog of war, none of these things are sent over the network. Instead, each player sends only the commands they want to perform. Things like move here, attack that, cast this spell. Everyone starts from the same state and applies the same commands on the same frames. So, everyone ends up with exactly the same game. >> [music] >> Moving in step like this is called lockstep networking.
>> [music] >> Every frame, each player sends a turn with the commands they just gave, even if it's empty. >> [music] >> Your computer only runs a frame once it has every player's turns for it. This all works great, except for one big problem. I can't apply your commands until I know what they are. And that means waiting for your commands to reach me over the network. The time it takes for these to travel over the network is called latency. And it can be anywhere from almost instantaneous, like in a LAN environment, to a quarter of a second, or even worse, if you're really far from your opponent.
So, to make that work, the game adds delay to every command you sent. >> [music] >> To avoid freezing, this needs to be at least as long as it takes for the packets to travel between you and your opponent. To play it safe, modern Battle.net always adds at least two frames of delay, 84 milliseconds. It's roughly long enough to travel between the West Coast of the United States and the western part of Europe. But, it does get adjusted higher as needed. In the worst cases, it can add almost half a second of delay to every command you sent. And man, you feel that.
So, even on your own screen, your marine waits a little bit before it moves.
But, what happens when a turn arrives late, or a packet gets lost? Nobody can run that frame yet, so the game freezes until it shows up. If it's only missing a short time, this shows up as a stutter, a small hitch in the gameplay. That's what throws off your timing. If it takes multiple seconds to show up, the game shows the drop screen for that player until it does. This balance between delay and responsiveness is lockstep's fundamental tradeoff. We can add delay to keep things feeling smooth without freezes, but more delay means less responsive units.
But, what if we didn't have to make that tradeoff? What if there was a way that we could keep moving forward with the game, even if we didn't have our opponent's commands yet? That's where rollback netcode comes in. >> [music] >> Rollback has transformed online fighting games in the last few years, and technique can be summed up in a simple phrase, act now, apologize later. >> [music] >> The key insight is, most of the time, a player's input on this frame is exactly the same as the last one. In fighting games, this means holding the same buttons or directions. But in RTS games like Brood War, it means something a little different. It means no new commands.
And if you look at real StarCraft games, we see this is true. Even when players have over 300 APM, they're only giving new orders on about one frame in 10. On the other nine frames, their units keep doing what they've already been told. So, nothing new is a really good guess.
>> [music] >> With rollback, the game no longer waits. It runs every frame on time with whatever turns it has. Your own commands can take effect on the very next frame, just like if you were playing single player. If your opponent's turn hasn't arrived yet, the game guesses that they didn't do anything new and keeps going. Most of the time, that guess is right, and there's nothing to fix. But sometimes, they did do something. Here, a command arrives three frames late for a frame we already showed. So, the game finds the last frame where it had everyone's turns and rolls back to a snapshot of it.
Then, it adds the late commands and quickly reruns all the frames up to now.
At full speed, all that happens in under a millisecond, within a single frame. What you actually see is the Zergling hopping a little to where it really is. For most corrections, you won't even notice.
Rollback and delay work together. When commands are only a small number of frames late, rollback hides it. The hops are small enough that you barely notice. This lets us make many games perform even better than the best latency you could get before, >> [music] >> bringing single player responsiveness to online games. And if you have a short burst of lag or packet loss, then that code can roll back further instead of freezing the game. But these larger roll backs are noticeable, so we avoid doing them for too long. For prolonged slow connections, we add delay on top just like before, but only the part the roll back can't cover.
Here's the same few seconds over the same connection side by side.
With lockstep, every click waits out the delay. And when the connection hiccups, the game freezes. With roll back, your marine responds right away. The hiccup just shows up as a few small hops, and the game keeps going. On Shield Battery, we have another nice benefit. You pay only for your own connection. If your opponent's on laggy Wi-Fi halfway across the world, that's their delay, not yours. We adjust each player's connection separately, and players with better quality connections will get a better experience as a result. No more 3 V 3 games with five people held hostage by one person with a bad connection. >> [music] >> So, let's recap. Here's what roll back gets you.
Your commands can respond on the very next frame. >> [music] >> Late commands become a small hop instead of a freeze. And delay is only added when your connection needs it, and only [music] for you. Roll back net code for Brood War, available now only on Shield Battery.
>> [music]