📜 ⬆️ ⬇️

Android "Evolution": how it was



Hello! My name is Alexander Grishin, I work in the studio IT-Territory (Mail.Ru Group) as a testing specialist. I am developing the Android version of Evolution: The Battle for Utopia. The iOS audience greeted the novelty with interest this spring, and we are already preparing for the first impressions of Android users. In the article I will talk about how we ported the game to Android and what difficulties and nuances we encountered in the process.

Evolution on iOS

If you look at mobile games in general, now there are few projects on the market that are similar to Evolution - large, complex, costly, requiring a large team to be developed. Creating games with so many mechanics, each of which, in fact, is a separate minigame, the process is long and painstaking: you need not only to do them, but then also to connect, grind to each other, to make everything work together as it should and caused the user interest, not bewilderment. There are few such games even on iOS, for which studios are more willing to create games, and almost none on Android.

Lyrical digression
Evolution was released in Russia on January 31, 2014, on March 19 it was presented to a global audience at the Game Developers Conference, which was held this spring in San Francisco, and on April 2 an international release took place. The game entered the top ten games for the iPad in 30 countries - and this despite the fact that Evolution entered the market almost simultaneously with Hearthstone from Blizzard Entertainment, which the fans were looking forward to. Today more than 73,000 players from 198 countries of the world come to our game every day. More than 41% of the players live in Russia, more than 20% in the USA, and another 5.7% are in the UK.


')

Complex diversity

Android is a specific platform. To begin with at least the fact that iOS has only five screen resolutions, which, of course, makes the development of the application easier. In Android, the number of permissions goes to hundreds, if not thousands. From a technical point of view, when drawing a graphical interface for this platform, it is tied to the corners. But sometimes it is stretched, rather than drawing a pixel into a pixel - for example, backgrounds, why the graphics suffer or the proportions are violated. In iOS, we always know how the picture will look like; in Android, things are not so simple.

On the market of Android devices there are a lot of different models with different performance, but here it is easier to control the installation on various devices; for example, in iOS it is difficult to limit the devices on which the application can run. You can note in the description of the application that the fourth-generation iPhone does not support it. In this case, it runs on these devices, you can play it, but, in principle, no one guarantees that it will not fly out or do something else not according to plan. In Android, you can specify specific devices for which people download the game, and upload a lot of distributions for different graphics chips.

For iOS, we lay out a single distribution. Some post two, one for tablets and another for smartphones. Android needs different distros, which are built depending on the chip, texture compression and other parameters. In some games it is necessary to make about 5-6 different assemblies, which, of course, complicates the application deployment process. When several distributions are made for different GPUs, we upload them to Google Play; when the client downloads the application, the digital store itself selects the build for the device's GPU and issues it.

All iPhone graphics chips belong to the same PowerVR family, so we can always predict game performance very accurately. There are four common graphics chips on Android that work quite differently. We were faced with the fact that the application on this platform was so slow that we had to redo the shaders, reduce their quality or disable them altogether. In Android, the speculator is considered to be in the vertex shader, and in iOS it is considered in pixel. So we used the standard method of increasing the performance at the cost of some deterioration of the picture - transferring the calculations from the pixel shader to the vertex one.

Another difficulty that we encountered when porting Evolution: on Android, there is no alpha-compatible texture compression format compatible with all devices (ETC1 (4bit) vs PVRTC4 / 2 (4/2 bit with alpha). Uncompressed textures are not just extra memory waste and increased application size, but also longer application loading and performance loss. From a technical point of view, the lack of texture compression with the alpha channel is a very, very big limitation of the Android platform.The standard graphics API OpenGL ES 2.0. single format ET C1, which is already out of date and does not contain an alpha channel. On iOS there is a very good graphics chip: in addition to the fact that textures with it take up less memory, they also load faster. When you overload scenes with a lot of textures in the game, on iOS it happens instantly, and on Android with a noticeable delay, which in our case reached 1.5 seconds, but, alas, we had to work with what we have, or use compression formats specific for a specific hardware platform: PVRTC, DXT, ATC, ETC. In principle, the problem of compression with the alpha channel Android developers are planning to solve in the following standard OpenGL ES 3.0: there will appear a good advanced compression format (ASTC), and it will immediately become easier for everyone to live.

These are the main difficulties when porting an application from iOS to Android. There were other problems, such as the size limit APK. In Android, this figure is 50 Mb, while on iOS, restrictions exist only for cellular downloads. The iOS version of the game is a single file of approximately 420 MB; On Android, the game is broken down into a small APK file, which subsequently loads the large OBB file that contains the game. However, Unity does most of the work for you.



How was it with us

We can say, historically, that first of all we are developing a game for Apple devices and then porting it. Of course, you can develop the game immediately under the two platforms, and you can under the three. "Juggernaut: Revenge of Sovering", for example, we also released just under the desktop MAC or OSX.

Porting from iOS to Android is greatly simplified if the game is made under Unity. It is enough just to run it on a new platform - and it becomes immediately obvious where you need to go through the file and what needs to be completed so that the result looks normal. If the game is not under Unity, then I have bad news: in fact, you have to re-write it.

It took us about two months to port “Evolution” to Android. As I said, the game is very difficult, both for development and porting. The fact is that several different gameplays are combined in it. Characters move around the map, fight monsters, solve riddles - each of these activities has its own interface, its own mechanics. And, of course, all this stuff is loaded right during the game session - that is, it was important for us that Evolution continued to “fly” after being transferred to a new platform.

The biggest problem we faced was sustaining the same combat performance that the game had on iOS. To achieve this, we wrote new shaders, which gave the necessary increase in speed, slightly worsening the picture. We even managed to save the “honest” shadows from the characters! There was practically no need to redo graphic assets (scenes, models, animations).

The second large (and even more labor-intensive) part of the work is the 2D part of the game, which in Evolution is even more than 3D. Thousands of Android screen resolutions (against just a few for iOS) and the absence of such a wonderful texture compression format as PVRTC (available on any iOS device), lead to a lot of hard work. In the "Evolution" dozens of screens, backgrounds, flipbook-animations (flip book) and thousands of sprites, packed in dozens of atlases. Then I had to compress something, stretch something, repack something.

With all the changes that the graphics undergoes during the porting, the weight of the game changes - for the worse for Android. On iOS, the graphics are compressed 8 times. There is a completely wonderful algorithm PVRTC4, which allows you to make very decent 4-bit quality from 32-bit graphics with alpha channel. Since not all graphics on Android manage to compress as well as on iOS, it takes up more disk space.

Many where manual tuning was required; in spite of the fact that we chose a certain general solution, we had to do a lot of things with our own hands. For example, the already mentioned problem with different screens: I had to take into account this feature of Android and somehow solve the situation. Of course, it was not necessary to rewrite everything for every possible small screen. On iOS, we had only two scales, both multiples of two - that is why we didn’t have any particular problems with violation of proportions and blurring of graphics. As a rule, Android takes some kind of medium resolution, and everything else scales under it. The change in resolution primarily affects the two-dimensional graphics: we have to include various interface elements, buttons, and so on. I had to sort through these parts manually, pinch the textures, resize the graphic elements in the main interface.

In total, we made four distros for Evolution. In this case, we later had to abandon one of them - the game does not yet support Tegra. In general, the porting on Tegra, especially the older generations, is a whole adventure. As a rule, when people can port a graphically intensive 3D game to Tegra, they then go somewhere to a professional conference and make a report about it. This is a jewelry and specific work, when the developer is trying to increase fps from 10 to 30, simply by changing the order of drawing different objects on the screen.



Modern mobile GPU aerial view

All GPUs on the mobile market work a little differently. They can be divided into 3 classes: tile-based deferred rendering (TBDR) - PowerVR; tile-based rendering (TBR) - Adreno, Mali and immediate mode rendering (IMR) - Tegra.

PowerVR with its TBDR is the most different from IMR, which is the usual solution for desktops. PowerVR works like this: it breaks the entire screen into small tiles of 16x16 pixels and draws all the geometry that fell into this tile. This happens in ultrafast memory inside the chip. In the process of drawing, it discards all the pixels that will not be visible in the final image (for example, overlapped by other opaque objects), and then textures and calculates the lighting only for those pixels that are exactly visible on the screen. To date, this is one of the most economical and fast solutions, and although it has its own set of drawbacks, from the point of view of mobile game developers, it is the most optimal. Of the obvious advantages, it very quickly does alpha blending, anti-aliasing, texture filtering and is completely insensitive to the order of rendering opaque objects, mip mapping and so on, and the wonderful compression format PVRTC further reduces the load on the memory. In other words, developers do not need to optimize anything - you just need to stick to a certain budget for the number of vertices, not to overuse transparency and not to use an alpha test that breaks the entire TBDR process.

IMR draws everything using only approximate optimization of cutting off invisible surfaces (Early Z-cull), therefore it is very sensitive to the order of rendering opaque objects. Unity here, unfortunately, cannot help anything - the developer must figure out which objects on the stage will take up more screen space, and tell Unity to draw them first (render queue). As all pixels are shaded, pixel shaders get more work.

TBR chips work in much the same way as IMR, but they break the screen into tiles to reduce the memory load.

NVIDIA continues to release new types, soon there will be Tegra K1, so this is quite an interesting direction, but, unfortunately, there is a completely different approach, and because of this there will still be some difference when porting. From the small details: for example, if you disable mipmap on all textures in iOS, then performance drops by 2-3 fps. If this is done on Android, then the performance drops by a whole order. There are a lot of these subtleties: if you are going to optimize the game for each of the chips, then be ready to study thicker manuals on optimization from the manufacturers, long profiling and experiments. Someone does this work and then reads a report at the conference; we decided not to dig so deep, but simply chose a list of devices for which we were going to develop distributions, tested the result and uploaded the successful versions to the store. Alas, not everyone with Android devices will be able to play Evolution, but we “covered up” the maximum possible number of devices. In general, the game supports approximately 1000 mobile devices with Android.

That's the whole story. Thank you for your attention, if you have questions - ask in the comments, with pleasure I will answer them.

Source: https://habr.com/ru/post/229773/


All Articles