Book Image

Mastering Android NDK

Book Image

Mastering Android NDK

Overview of this book

Android NDK is used for multimedia applications that require direct access to system resources. NDK is also the key for portability, which in turn allows a reasonably comfortable development and debugging process using familiar tools such as GCC and Clang toolchains. This is a hands-on guide to extending your game development skills with Android NDK. The book takes you through many clear, step-by-step example applications to help you further explore the features of Android NDK and some popular C++ libraries and boost your productivity by debugging the development process. Through the course of this book, you will learn how to write portable multi-threaded native code, use HTTP networking in C++, play audio files, use OpenGL ES 3, and render high-quality text. Each chapter aims to take you one step closer to building your application. By the end of this book, you will be able to create an engaging, complete gaming application.
Table of Contents (17 chapters)
Mastering Android NDK
About the Authors
About the Reviewers

Portable multithreading primitives

The long-awaited std::thread from the C++11 standard is not (yet) available in MinGW toolchain at the time of writing, and it does not possess capabilities necessary to adjust thread priorities, which is important for networking. So, we implement a simple class iThread with the virtual method Run() to allow portable multithreading in our code:

class iThread

An internal LPriority enumeration defines thread priority classes:

  enum LPriority
    Priority_Idle         = 0,
    Priority_Lowest       = 1,
    Priority_Low          = 2,
    Priority_Normal       = 3,
    Priority_High         = 4,
    Priority_Highest      = 5,
    Priority_TimeCritical = 6

The code for constructor and destructor is simple:

  iThread(): FThreadHandle( 0 ), FPendingExit( false )
  virtual ~iThread()

The Start() method creates an OS-specific thread handle and starts execution. In all of the samples for this book, we do not need to postpone thread execution...