This week was more random work! I did more audio, finished my Steam store page, and prepared all the levels for co-op play. Woohoo! Yesterday, I decided to poke around everyone’s favourite topic — please join me for one more ride on the magical replay unicorn!
In case you’re not interested, I’m peppering this long article with assets from this week.
Random Number Generation
Things were looking great the last time I worked on replays, but they were woefully un-tested. All that I knew for sure was that I could record a replay and play it back on the same computer. A better test would be to try playing it back on other computers — so I did that, and it worked great… until I tried playing it back on a Mac.
For a quick, simple refresher: a random number generator (RNG) is like a math formula. You give the formula a starting number, called a ‘seed’, and it spits out an endless series of random numbers for you! Since the numbers are being created by a math formula, though, starting with the same seed always produces the same series of numbers. So the RNG makes Bleed *seem* random, but if you were to play the exact same way, using the same seed, the random numbers would always be the same, making the game always play the same, making things like replays possible.
So. The PC version of Bleed 2 is made using XNA, which comes with an RNG built-in. My dirty Mac port was made using MonoGame, which has its own, different RNG. The RNGs are using different formulas, meaning the game behaves differently on each computer, breaking the replays.
It turns out actually making an RNG — a GOOD one, where you can’t see any pattern and the numbers are evenly distributed between high and low, etc — is really, really complex and hard (who knew, right?) Fortunately I managed to find a great, free-to-use one online. I changed the PC and Mac versions to use my RNG instead of their built-in ones, and everything started playing back great. Yay.
I still had issues, though, because I hadn’t made weapon switching part of replays yet. Weapon switching is tricky, because the player and the replay file control weapons differently.
The replay file only knows the weapon Wryn is using each frame, and just assigns her that weapon. The player, on the other hand, chooses a list of weapons for Wryn to use, and they can press buttons to go forward or backward in the list, or even bring up the pause menu and swap out the list entirely.
Basically what it amounts to is this: any weapon switching done by the player won’t take effect until the next frame, which gives the replay time to record the change. Otherwise, pressing the “fire weapon” and “switch weapon” buttons at the same time would cause a switch-then-fire during gameplay, and a fire-then-switch during playback, breaking the replay. Similar things had to be taken into account for changing air-dodge styles.
I’m happy to say that I’ve basically solved the puzzle now — though untested, replays are 99% working. The only question is whether I actually ship them with the game or not.
It might seem stupid to put all this work in and then not include it in the final product (and maybe it is) but consider this. If I include replays at launch, the core game can never be changed — if a game-breaking bug is found, and I fix it, I’ve likely altered the way the game plays, and broken every replay on the leaderboards in the process. What do I do then, clear the leaderboards? Or leave them full of invalid replays?
The game is also fairly long, for a run and gun. I haven’t gotten into speedrunning it yet, but let’s pretend a speedrun takes 30mins — how many people actually want to watch a 30min replay? What about everyone else, who isn’t a speedrunner — who wants to watch their 60min replays? Why wouldn’t they just use YouTube, which has rewind and fast forward? Then again, I did a Twitter poll and a surprising number of people seemed interested, so maybe I’m being too harsh here.
Finally, it’s an intimidating feature that I’ll have to thoroughly, thoroughly test if I’m going to be comfortable putting in — perhaps time that could be better spent elsewhere.
So, that’s where replays are at right now. I guess their inclusion will depend on how confident I am in them, in the core game, and how much time I get to test them before release. Maybe, if they don’t make it for launch, I can test and include them after a few months, once I know the game is solid and not in need of changes.
Thanks for reading!