Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 7 ■ IntroduCtIon to JavaFX 9: overvIew oF the JavaFX new MedIa engIne

The Quantum toolkit that is connected to the JavaFX API ties together all of the powerful new media–
related engines that I’m going to talk about next. The Quantum toolkit handles thread management for
all these engines so that your game code, which is on the JavaFX primary (main) thread, and your game’s
new media assets (audio, video, 3D vector, 2D vector), which are on their own thread (A/V uses a dedicated
thread, as does WebKit, Windowing, or 3D rendering), can use separate processors via separate threads (or
processes) on those dual-core, quad-core, hexa-core and octa-core CPUs, which are now commonplace in
today’s computers and embedded consumer electronics devices. I have shown new media engines that are
important enough to have their own threads in the fourth tier of Figure 7-1.
The Glass Windowing Toolkit controls window management for JavaFX. This is responsible for the
control of any discrete areas of your display, such as your Stage or Popup windows, such as dialogs. Glass
also manages the events processing queue and passes events up to JavaFX for processing, and it also sets up
timers, which you will learn about later in the book when we get into gameplay and how pulse milliseconds
can control the timing for your games.
As you can see in the middle of Figure 7-1, there is also a WebKit engine and a Media Player engine.
These are also managed by the Quantum toolkit. The WebKit engine can render HTML5, CSS3/4, and
JavaScript content. This means you can create web content that runs seamlessly inside your JavaFX games.
The Media Player media playback engine offloads (handles) the playback, UI controls for, and navigation of
your Digital Audio and Digital Video assets.
The most important new media engine underneath the Quantum toolkit is the PRISM engine, which
I like to call the “Prism Game Engine,” as it renders 2D content using Java2D and renders 3D content using
either OpenGL (Macintosh, Linux, or Embedded OS) or DirectX if users are using the Windows 7, 8, or 10
platforms. I use Windows 7.2 and 10 on some of my production workstations. Windows XP and Vista support
was discontinued, as most of the computers and consumer electronics devices are now 64-bit capable
(Windows XP is 32-bit and only addresses 3.24 GB of memory).
What PRISM does is to “bridge” the powerful game engines (DirectX and OpenGL) that are on the major
OS platforms, as well as on consumer electronics embedded devices so that JavaFX can “offload” complex
rendering task processing to GPU hardware from nVidia (GeForce), AMD (Radeon), ARM, Qualcomm,
or Intel. This makes JavaFX/Java games faster and allows games to use less of the CPU processing power
for rendering game assets to the screen. This in turn allows more of the CPU processing power to be used
for gameplay logic, such as AI or collision detection. We’ll be getting into these areas of game design after
we master the JavaFX engine features and its Scene Graph Hierarchy and Architecture during the next two
chapters of the book, this JavaFX primer, and Chapter 8 on Scene Graph design.
It is important to note that game developers do not need to understand the inner workings of the
Quantum (threading), Glass (windowing), or Prism (rendering) engines to be able to leverage their powerful
new media features. Throughout this book, you are going to be focusing on the top-level Scene Graph
Architecture, as well as the JavaFX and Java API levels of this diagram. You’ll also be covering the NetBeans
9 IDE level, which we just took care of in Chapter 6 , but whose features we will also be exploring in further
detail throughout the remainder of this book.
As far as the lower levels of the diagram in Figure 7-1 are concerned, NetBeans 9.0 will generate a Java
ByteCode file that is read by the custom JVM or Java 9 Virtual Machine, for each of the OS platforms. This
JVM, shown at the bottom of Figure 7-1, can be installed for any given OS platform by downloading the Java
9 Java Runtime Engine (JRE), which you have already encountered in Chapter 1 , when you installed it as
part of your Java 9 JDK installation.
This JVM layer allows your game to be installed as an application across all popular OS platforms, as
well as on embedded devices, which will also be moving to support JavaFX. You should also generate your
pro Java game as a Java “applet” that can be embedded into a web site, and there’s even a deployment model
where the application can be dragged out of the web site and onto the desktop, where it is then installed as a
full-fledged Java game application.
There is also already a work process used to run JavaFX apps on iOS 8 and Android 8, although the
support is not “native” as yet, so JavaFX applications can’t yet run directly inside those OSs. If you are
interested in the latest information regarding this, simply Google “JavaFX on Android” or “JavaFX on

Free download pdf