Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

© Wallace Jackson 2017 603
W. Jackson, Pro Java 9 Games Development, https://doi.org/10.1007/978-1-4842-0973-8_24


CHAPTER 24


Optimizing Game Assets and Code,


and Game Profiling Using NetBeans


Now that your game is working and the players are using it one click (turn) at a time, we can look at how
much memory it is using and how large all these assets are. We can also look at ways to make the digital
audio and imaging assets two to four times smaller. The data footprint optimization will be done first using
GIMP, and the profiling will be done next using NetBeans 9 Profiler on the current 24-bit image assets and
the CD-quality 16-bit 44.1KHz audio assets. In this way, we can see if the high-end multimedia assets are
taking up too much memory and CPU overhead or if these are being handled well by my development
system, which is an old 4GB Win7 Acer QuadCore mini-tower from Walmart ($300 several years ago). I have
been developing Java 9 using NetBeans 9 on this system without incident. Current systems are hexa-core or
octa-core with 8MB or 16MB of memory, so Java 9 development can be done easily on older systems and
does not require cutting-edge systems as other i3D platforms such as Unity, Android or Lumberyard do.
During this chapter, we’ll convert your digital image assets to use 8-bit (indexed) color rather than the
24-bit “true” color for your texture maps, and we’ll run the NetBeans Profiler to see how much memory and
CPU processing your Java code is using to run your game.


Optimizing Texture Maps: Converting to 8-Bit Color


Currently the digital image assets in your source (/src/) folder are at about 24MB, or 24,000,000 bytes,
which is actually quite good for an i3D board game with 120 different images (about 200KB per image on
average). However, if we could get this to about 10MB (84KB per image), it would reduce the size of our game
distribution package quite a bit. The way to achieve a 300 percent to 400 percent reduction in image “weight”
or size is to use 8-bit color (indexed color) along with “dithering” or dot patterns used to simulate more
colors than the 256 maximum used to represent an indexed image. Small to medium texture maps, which
is exactly what we are using for our game board squares and quadrants, work well with indexed color. The
reason for this is because the dithering can be seen zoomed in (up close), but this visual effect disappears
when the images are viewed farther away (from a distance or zoomed out). I will show you this in this section
of the chapter, where we will turn all 120 of our image assets from 24-bit into 8-bit indexed color.


Creating Indexed Color Textures: Changing Color Mode in GIMP


Let’s optimize our image assets in such a way that we do not have to make any significant changes to our Java
code. To keep our Java code the same, we are going to use the same file names and put them in a different
folder, under /src/ called /8bit/. Thus, we will then have the /src/8bit/ path to the indexed color assets and
the /filename path to the 24-bit high-quality assets. Use your OS file management utility to create a folder

Free download pdf