Game Development Reference
In-Depth Information
There's more…
Our new approach is much more robust. However, the touch event timestamps generated inside
GestureHandler_SendMotion() are slightly robust and do not correspond to the actual time
of touches any more. This introduces a delay approximately equal to a single frame rendering
time and can become an issue in multiplayer games. We leave the exercise of adding genuine
timestamps to the reader. This can be done by extending the sSendMotionData struct with
a timestamp ield, which is assigned inside the JNI callback SendMotion() .
See also
F The Processing multi-touch events on Android recipe in Chapter 7 , Cross-platform UI
and Input Systems
Improving the audio playback mechanism
In the previous chapters we learned how to play audio using OpenAL on Android. Our basic
audio subsystem implementation in Chapter 5 , Cross-platform Audio Streaming, lacked
automatic management of audio sources; we had to control them manually on a separate
thread. Now, we will put all of that code into a new audio subsystem usable in a real game.
Getting ready
The complete source code for this recipe is integrated in the example 1_Game and can be
found in the iles sound/Audio.h and sound/Audio.cpp . Other iles in the sound folder
provide decoding capabilities for different audio formats—check them out.
How to do it…
1.
We need our clAudioThread class to take care of active audio sources. Let's
extend it with methods responsible for their registration:
class clAudioThread: public iThread
{
public:
void RegisterSource( clAudioSource* Src );
void UnRegisterSource( clAudioSource* Src );
2.
We also need a container for active sources as well as mutex to control the access to
it:
private:
 
Search WWH ::




Custom Search