Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 24 ■ Optimizing game assets and COde, and game prOfiling Using netBeans

We have reduced your data footprint for the game board quadrant texture maps from 17,041,285 bytes
to 6,208,570 bytes, which is a reduction of 10,832,715 bytes. That’s a 65 percent (two-thirds) reduction in
data footprint for your quadrant images. These are 512 pixels square, which is fairly large (high quality) for
an i3D game, so 6MB for 60 images is good quality and around 100KB per quadrant image, as you saw in
GIMP already in Figure 24-7.
We have also reduced the data footprint for the game board square texture maps from 4,516,845 bytes
size to 1,701,334 bytes, which is a reduction of 2,815,511 bytes. That is a 63 percent reduction in data
footprint for game board square imagery. These are 256 pixels square, which is mainstream (high quality) for
i3D games, so 1.7MB for 60 images is good quality and around 28KB per game board square image, or about
128KB of image data per game topic selection.
To reference these optimized assets, simply add the /8bit/ path before the file name in the Java code,
which we’ll be doing later, after I profile the current code using the pristine 24-bit digital image assets and
CD-quality digital audio assets. Always profile your code using the highest-quality assets so that you can see
whether the memory and CPU cycles are being affected by new media elements that are too large
(data-footprint-wise). As far as pro Java games are concerned, this is a large part of what the NetBeans
profiler will tell you. Yes, your Java logic is important. Infinite loop problems will show up very quickly in the
profiler, but so will nonoptimal Animation object constructs, texture maps that are too large, digital audio
sound effects that are too long, digital video that is not well optimized, and i3D assets that use too many
polygons (too much geometry). This is why we looked at all the various new media concepts and principles
during the first third of this book, as the new media optimization affects how the game plays.


NetBeans 9 Profiler: Testing Memory and CPU Usage


To invoke the NetBeans 9 Profiler, simply use the Profile menu and the Profile Project (JavaFXGame)
option, located at the top of that menu, as shown in Figure 24-12. Also shown are the 40 custom methods,
the required start() and main() methods, and the 1,700 lines of Java 9 code that we have added since
we created your JavaFXGame bootstrap application. A NetBeans 9 profiling session can show a great
many complicated “under the hood” operations that are happening with your computer during program
execution, as well as interactions with servers and even SQL database access patterns. Therefore, we will not
touch on all of the NetBeans 9 profiling system’s features during this chapter; however, if you are interested
in Java software profiling, you should certainly explore and experiment with the profiler options on your own
time, using your other Java 9 software development projects on your various 64-bit workstations.


Figure 24-11. Right-click the selected square and quadrant images in both folders; use Properties to preview
the optimization

Free download pdf