Chris
Introduce the talk and Ben
Talk about our ambition to put a lot of game onto a mobile device
We wanted to bring a Starcraft-like RTS experience to mobile
We quickly found out why there are not many RTS-like games on mobile
We are going to go through our process of getting this big game on a device and all the problems we encountered and subsequent solutions we came up with
Chris
Talk about the founding of the company, how it grew and why it was founded:
Alex, Jamie and Chris wanted to run our own company and make our own products
Saw a market for mid core games on mobile and it was more inline with what we like to play
Started with myself and 2 developers
Grew in early 2014 when we hired 10 more employees to go for it
Chris and Ben
Making games is a challenging task to begin with and you are constantly battle 3 core bottlenecks.
From the technical side system resource management is one of the top priorities
Without managing these resources you get a crappy game performance with low FPS and poor responsiveness
Unfortunately modern Mobile devices still have less power than a desktop computer, making the problem worse
Draw Calls and Overdraw correlate directly to FPS, to much of either and your frame rate plummets making the game unplayable
Memory, both CPU and GPU, is very finite in mobile devices. Once you go over your CPU memory limit your game just crashes…no warning or recovery
CPU is the second factor in your FPS but also determines how much AI you can process. Games that try and do a lot of smart things burn through your CPU quickly creating lag
an iPhone 5 has 1GB of RAM.
iOS only lets you use 250-350 MB of that for your app
an iPhone 4 or iPad Mini has half of those resources
As you build your game you quickly realize you are playing Wack-a-Mole with these constraints because as you fix one problem area another pops up.
Ben
Describe:
Quads
Texture
Material
Mesh
Drawing Process:
Create game objects and attach texture & material
Place the sprites in the world on a plane with a camera
Objects move around the screen with code
Wireframes
Overdraw Image
Ben
Talk about the naive approach of one texture per sprite
Need to manage thousands of separate texture files and objects
Unity 2D animation support was unusable at the time, making animated sprites a challenge
We only had 1/4 of the assets in the game and we were already struggling
Ben
Describe what it is:
3rd party plugin for Unity from the Unity Asset Store
Creates custom sprite collections with tools for packing individual textures, scaling them, trimming them, rotating them, tinting them and rendering them
Has an animation tool to easily create key frame sprite animations with code triggers
Talk about the main problems solved: Draw Calls and Organization - Scalability
Each combination of a mesh and a texture is a draw call
Manages the limited number of texture units that a GPU has to work with
Once you exceed the texture units you need to load textures from CPU memory which murders frame rate
Provides a system managing, packing and drawing sprites
Provided us with a tool and system for doing 2d animations
Automatically batches draw calls for game objects using the same sprite collections
Introduce “layers of abstraction” for drawing
Sprite Batching
Sprite batching is a way to combine multiple textures/objects into a single object that only requires one draw call:
It is faster to combine many meshes into one (up to a point) and use texture offsets than to draw each mesh individually
Only works for combining textures from the same sprite collection
Still need to be careful with draw calls when multiple sandwiched objects overlap from different sprite collections
Chris
Tiny Realms has a lot of content.
4 factions each with 17 unique buildings and 8 different units
Each building has 10 upgrade levels, some with custom animations and banners
Each Unit has 8 directions of animation for walking, attacking, idle, dying
10-60 frames each
Total Building sprite sheet size per faction: 100 MB
Size of all unit textures per faction: 140 MB
A significant battle between 2 different factions required over 400 MB of memory just to render the sprites…
And we still need more memory for code, services, networking, particle effects
A 1st generation iPad Mini only has 150 MB of memory to work with
Chris and Ben
We needed to massively cut back our assets
Units
Cut out frames from animation cycles - 60 frames became 12
Removed many animation cycles completely
Used sprite mirroring to eliminate duplicates
Buildings
Replaced many animations with particle effects
Remove all firing animations from cannons and mortars
Faked it out with particle effects
Compression
Switched all textures to PVRTC
Optimized for iOS and works best when the textures are square
Introduced compression “fixers” into the texture files to aid with compression (I forgot to ask Tobyn how this works)
Result:
Memory requirements for textures dropped by nearly an order of magnitude
The game now loads into memory on a device…Huzzah!
asdfasdfa
Ben
TinyRealms is a 2D Isometric Projection game
Sprites are layer on top of each other from back to front to create the illusion of depth
All our sprites have alpha transparency
We are using dozens of sprite sheets
Explain how Draw calls and depth buffering work
An now our 100s of draw calls were destroying our FPS
Ben
To fix this problem Tony developed a system to dynamically create a sprite sheets for buildings when you load a level (aka realm)
The realm is evaluated and only the buildings needed are copied from their source sheets into one or two custom collections
The system also keeps track of all animations and maintains links
Combining this assets into one of two textures instead of dozen has a massive effect on the # of draw calls
The con of this approach is that it adds 2-5 seconds to the load of each realm in the game
Chris
Summarize the Successes
We put int an architecture to manage asset and use sprite sheets
We trimmed down the content to fit the game into memory
We optimized the CPU and Draw calls to allow the game to run at 60 FPS
Everything works, time to ship it to the Apple App Store
Chris
With 3+ factions and plenty of high quality art our game is almost 300Mb
On iOS you can only download apps over a cell network that are <100MB
Apps that are >100MB have a significant drop off in player installs because they can’t or won’t download over WiFi
How to reach our 100MB goal without sacrificing quality?
Chris
Asset bundles are just zip files that contain Unity assets like objects, art and sound
The Unity engine can load these files at runtime from the Internet or local file system
We packaged a bunch of our assets into these bundles to make them downloadable at runtime
AssetBundles are loaded directly into memory at runtime so we need to use a lot of granularity (~100 files) to avoid wasting memory
Pros
Reduced the install size to < 95.6 MB
Lets us deliver new content to a live game without pushing an update through Apple
Cons
The game has to download dozens of files when the game starts
Slows down the game experience when switching between scenes
Ben
Even after all our performance improvements, low end devices still struggled to play the game well (or at all)
The game uses an average of 200 MB of memory
iPhone 4/4s & iPad Mini only provide 170 MB
Ran out of ways to optimize the game
The high res textures we use for Retina devices are just too big
Ben
Our next step was to reduce the texture quality of game assets for low end devices
2D Toolkit provides a way to automatically create full resolution textures and half resolution textures for different platforms
CON
game looked slightly worse on low end devices
PRO
game actually works on low end devices