Best optimization practices

Some defined and logical optimization techniques are available. We will discuss the major scopes and fields that are related to Android game development:

  • Game design constraints
  • Game development optimization
  • Game data structure model
  • Using game assets
  • Handling cache data

Design constraints

It is always a best practice to define the target hardware platforms and acknowledge the limitation. Technical design can structure the development constraints according to it.

The scalability and portability should also be decided at the time of designing the game. This should give the developer a tentative platform limitation along with other constraints. We have already discussed design optimization. All those segments should be evaluated before going into development.

Targeting screen size and resolution has to be fixed when designing the game along with creating layouts, which will fit in multiple resolutions. This is because Android has many screen sizes as discussed earlier.

Selecting the minimum Android version and the target Android version gives the developer an advantage when structuring the development project, as supported API levels and platform features are already defined.

Development optimization

This is one of the most important segments of optimization. Here are some tips to carry out the development process successfully with optimization:

  • Using as many as possible folder structures provided by Android for project scalability.
  • Using resource formats according to the dpi list provided by Android.
  • The developer should avoid scaling images. This effectively reduces memory and processing overhead.
  • Using sprites for multiple purposes is also a good practice to create animations.
  • The tiling technique is very useful in terms of reducing memory consumption.
  • Overriding the onDraw() method is always a good practice to flush the old rendering pipeline and to use a systematic draw order with absolute requirement.
  • Use XML-based layout wherever possible; however, games have very limited scope for this Android feature.

Data structure model

Data structures are one of the inevitable parts of game program design since the beginning, irrespective of the scale of the game. Each game always processes data for various purposes such as sorting, searching, storing, and so on.

There are many data structure models available for various operations. Each operation has its own advantages and disadvantages. The developer must choose the most efficient one depending on the requirement.

Let's take an example of data storing comparison between an array and a linked list. Effectively, linked lists are more flexible and dynamic in nature than arrays. However, this feature comes at a cost of slow processing and higher memory consumption.

The developer might not always require to store dynamic data. For example, if cricket team data needs to be stored, then an array is sufficient, because there will always be 11 players on each side, and that cannot be modified during gameplay. It will make the process much faster and more efficient than using a linked list in this particular case.

In another case, for a shooting game, the developer cannot predict the number of bullets the user may fire during gameplay. So, a queue data structure will be most efficient in order to process all the fired bullets.

Similarly, stacks and tree structures can be chosen whenever they fit the purpose. The same approach may be taken for sort and search algorithms.

Asset-using techniques

We have already categorized assets for games. Let's discuss them from the perspective of optimization techniques and best practices.

Art assets

A separate optimization technique can be applied to a set of art assets. Art assets are the face of games. So, it is necessary that the visuals are attractive enough to start gameplay.

As we have discussed already, better art assets cost memory and performance. However, this can be minimized to a certain level. There are several tools for art asset optimization. However, using inappropriate tools can cause data loss, which eventually results in poor visual quality.

Art should never compromise from the perspective of visual quality. Often, artists develop assets that do not reflect perfectly in games because of inappropriate optimization.

We have already discussed how art assets should be made. Now, let's assume that some art is using only 8-bit data space as raw format, but the same is exported in a 24-bit format. Then, the developer can use tools to optimize the asset to a typical 8-bit format without affecting the visual quality.

This rule also applies for complete opaque assets. The developer can get rid of the transparency information in order to have optimized art assets.

Audio assets

Audio assets are standalone assets too. Audio has become a very important asset for extended user experience. Audio configuration can vary with a wide range of frequency, bit depth, and compression techniques. Each variation in configuration has a different level of processing and memory consumption.

So, audio optimization is also a very important part of the optimization process. Regular practice in the Android game development industry is to choose two different formats of audio for SFX and music files.

One thing that developers generally ignore is audio information data. Few Android devices have a certain frequency cap, but sounds are usually good when more frequencies are used. So, it is a technical design level step to determine the cap for Android game sounds. So, every sound should be made within the proximity.

Sound designers need to keep up the quality within the limit. In this way, audio assets can be optimized at the time of development.

Other assets

Besides art and audio, there may be other data assets used in games. The data format can be anything, such as binary, text, XML, JSON, or custom. Custom formats are basically the same as binary format, with some encryption.

It is a common practice in game development to use data sets separately. A separate data set helps structure the project and give flexibility to use the same code for a different output. Often, the developer updates data source to update the complete game experience without creating a new APK. This reduces development time in the longer run in order to maintain the game and do easy updates.

From the optimization point of view, these data sources should be optimized enough to get processed quickly and not consume too much memory. However, reading and writing an external file takes time. Normally, binary files are the fastest to be processed and smallest in size. However, after reading the binary data, it has to be parsed to be used in games, which eventually increases processing.

The most commonly used data formats are XML and JSON. The Android library has support for both of them, which includes a generic parser. The developer can have readily available data without making extra processing effort. However, the data can be manipulated during gameplay, depending on the game's requirements.

Handling cache data

A cache is a memory segment that is similar to RAM from a functionality point of view, but acts faster than conventional RAM. The processor can access this segment much faster. So, logically, a cache should only store data that is being used frequently.

The best possible way to handle cache data is to keep a check on the application memory usage. Generally, there should be at least 10 % of free memory available for the operating system. It is tested that an application can use an average of 2% of the total free memory.

However, the developer cannot control the cache technically. They can only make sure that the most commonly used elements are optimized in a perfect way so that the executer automatically uses cache memory for them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.152.136