The following blog post, unless otherwise noted, was written by a member of Gamasutras community.

The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

Who: Fredrik Ludvigsen, programmer; Eduardo Garabito, press & community coordinator at Rain.

More than a year ago we announced the PS Vita version for Teslagrad, and sadly we haven’t been able to deliver it yet. But this time has definitely not been wasted; apart from the Wii version, both PS3 and PS4 owners can download and play our game now in Europe, North America and Japan. Furthermore, during this period we’ve got to know the PlayStation platforms fairly well; we’ve solved a couple of issues (or a hundred), and considering Vita’s popularity among indie developers (and how much indie game fans appreciate that console) we’re glad to share our experience, hopefully saving other developer's time. We wish someone had told us what we are about to tell!

What is like to port a heavy physics-based game to several consoles?

As you can read in these lines written by our past selves, we were more than confident in being able to complete the task, that was to bring Teslagrad to PlayStation 3, PlayStation 4, and PlayStation Vita in a relatively quick and easy manner. We were mostly worrying about having to “shrink” and optimize the game to make it fit on Vita, and with everything more or less working out of the box, optimization looked like the major beast we had to face. Improving loading times proved essential, and we thought that threading optimization would counteract the incredibly high demands of our custom physics system. And that’s precisely the underestimation that costed us the most.

Let us add a small disclaimer here: even though we’re now far more experienced in this porting subject, we’ve also learned that we’re as likely to point out the wrong things this time as we were the last time. We’re smarter, but still can't look into the future. However, we can look into the present and recent past, a past in which we realized that magnetism calculations stood as a total resource drain in a physics-dependant game as Teslagrad certainly is. Trying to take advantage of multicore architectures, our lead programmer had to write his own framework, mainly to see it overwhelmed by calculations. All the math behind magnetism behavior in Teslagrad is customized, or hand-made if you prefer, with a physicist and a mathematician ultimately involved in it. Take a look at the screenshot below to get a grip on the importance of physics in Teslagrad’s performance.

Working on PlayStation

The screenshot belongs to an actually optimized build using our custom physics system at 120hz refresh rate in Unity 4, showing how physics calculations themselves (orange segment) can bring the game from the smooth 30 frames per second to choppy 15 FPS. As stated, optimization has been the biggest development time consumer, and indeed we have seen Teslagrad builds that could run 15-30 frames per second for a long time by just taking our PS3/PS4 projects and converting them to Vita. A year ago, about the time on which the aforementioned interview with our past selves was published, we were optimistic. Every week we kept trying new thing… just to get those last 15 frames per second back. And oh, weeks went by. At a certain point, we had been optimizing for a long time already, and no more low hanging fruit would available, you could say. With one programmer devoting himself to Wii U and another to all PlayStation 3, 4 and Vita versions, we got the feeling that we were under some time pressure. So we decided to focus. PlayStation 3 version was chosen to be delivered first.

Fortunately the PlayStation 3 builds were very much more doable. In those we only needed to handle the 256MB memory issues, and PlayStation 4 handled anything the PS3 could do... so it almost didn't require any changes to the game at all but a few controller changes. Two birds with one stone! Later in 2014 we actually arrived at the point where the PS3 build was shippable, and we shipped in Europe on our own. This is the first time we delivered anything on any Sony platform ever, so we used a long time familiarizing ourselves with the process, and also a long time trying again and again to get Sony QA to accept our builds. We went through several attempts before we got the PS3 build accepted in Europe, and it’s interesting to note that each attempt implies 1~2 weeks of waiting.

This process we have went through ~8-10 times counting physical and downloadable builds in Europe, America and Japan. Sometime in February this year, Teslagrad was released in Japan, and for our Playstation programmer, that meant he could finally dedicate himself to working with the Vita again. By that time, he finally spotted the next step that would allow him to push optimization a bit further, and it was scene loading. It wasn’t minor changes, though: Fredrik already managed to change the whole scene loading model for it (our idea was to have no loading screens on any platform) so that it worked on Vita.

The new system features explicit loading of scenes, taking a few seconds for loading purpuses every 3-4 scenes. The player will actually walk beyond the screen edge, and the next couple of scenes will load before he can continue, taking no more than a few seconds. With this model (and only if necessary) we can take a demanding boss scene, and make sure that nothing else is loaded or running while the you're there. Most other games do this kind of loading, and for us it suddenly became a very attractive option considering current, and unknown future problems with memory and frame rate challenges. It's a hard earned conclusion that seamless loading is very challenging on certain consoles with Unity while others (such as PS4) doesn't seem to twitch.

Moving on to a different aspect, we’ve rebuilt our own area detection system from the ground up so that we could bypass the internal physics in Unity, which is still there for the stuff that you can see, but it is not detecting that the player went to a certain place for example. That system is helping us reach stable framerate... but represents a tremendous amount of work so far, and also a lot going forward. As a result, Teslagrad actually feels smooth most of the time, in contrast with the old builds that we had a year ago.

Unity 5, a light at the end of the Vita tunnel

With Unity 5 came a better and faster physics engine, which helped us reach the desired framerate stability, but as usual it also required a lot of extra work. For instance, In Unity 4 we could put two colliders (floor pieces in this case) right next to each other, and they would seem like a smooth surface; but in Unity 5 those pieces will have to become one piece entirely, or the player would stumble on the edge between them. That's weeks worth of work, just finding those piecing and merging them together so that players won’t experience weird collisions or falls through the floor. The new physics system indirectly pointed out another issue with the refresh rates that were making things more difficult than expected. Since the launch of the game, the physics engine refresh rate had been 150hz, but it really should have been something divisible with the screen framerate. We chose it as suggested by the old documentation, which lead us in the wrong direction. When later tested on PS3 and PS4 it became evident to us that we needed to go with 120hz physics, and even more importantly, that working on Vita we could benefit from going way down to just 30hz, providing we work on finding and fixing all the colliders. By the way, Unity default value for physics is 50hz, and as far as we know many don’t ever change that. Be warned!

And that’s how we’ve come to this point. After slating the game for release, being perhaps too optimistic and re-scheduling once again, we’ve learned that there’s a lot of things which could and will go wrong even when everything seems nice and easy on a first step of the port. There were major problems and changes that we couldn’t anticipate, and a little million tasks in the many-other-thing box that can be anticipated but are often underestimated. Teslagrad is being rebuilt scene by scene, and performance- wise, rebuilt scenes are working on PC-like solid 30 FPS. In any event we’ve learned to stay conservative about future announcements, in line with our under-promise policy as a studio (and believe us when we say that we have had tough times telling our fans about delays and problems).

The Vita version is resulting the most demanding version so far, but all this chaos offer a bright side too: this version benefits from optimizations made for the PS3 and PS4 platforms, and Vita’s release will at last bring cross-buy for all the three platforms.This ordeal has been a product of a mixture of our own mistakes and bad luck, but there’s something for sure: if we decided to keep fighting it has been so that we made Teslagrad equally playable and enjoyable in every platform. That’s the whole reason we do it, and the model (with several improvements) will be kept in our next game yet to be officially announced, World to the West.