LiquidFun Paint
Create art that moves, shakes, and delights.
Introduction

About
Prerequisites
About this manual
Feedback and reporting bugs
Core concepts
Modules


About

LiquidFun Paint is a simple painting game that showcases the fluid simulation in LiquidFun, with a polished look. The primary interaction of the player with the game is through the touch screen and the accelerometer built into the Android device.

With the touch screen, the player can draw multiple types of fluid particles, erase drawn particles, and move the particles around.

With the accelerometer, the player can tilt the device and change the perceived gravity, which will then cause the fluids to react and move towards the gravity pull.

The game is written in Java, using the SWIG component of LiquidFun. The SWIG component will generate JNI (Java Native Interface) functions to facilitate communication between C++ and Java. LiquidFun Paint also utilizes Eclipse, and the Android SDK and Android NDK, for UX design and for building the various Java and C++ components.


Prerequisites

LiquidFun Paint is based on LiquidFun, a 2D fluid simulation library. Please refer to the LiquidFun site for more information and a tutorial on the library.

LiquidFun Paint is written in Java, and we recommend a working knowledge of the language before attempting to use the source code. In addition, if you choose to delve more into LiquidFun, you will need to have additional knowledge in C++ and SWIG. LiquidFun Paint should not be your first Android programming project! You should be comfortable with compiling, linking, and debugging.

Caution

LiquidFun Paint should not be your first Android or Java project. Please learn Java programming, compiling, linking, and debugging, especially for Android, before working with LiquidFun Paint. There are many resources for this on the Internet.


About this manual

This manual covers the basics of the LiquidFun Paint's code components. For anything that this manual does not cover, please refer to the comments in the source code.

This manual is only updated with new releases. The version in source control may be out of date.


Feedback and Reporting Bugs

If you have a question or feedback about LiquidFun Paint, please leave a comment in the Google group. This is also a great place for community discussion.

LiquidFun Paint issues are tracked using GitHub.

Please file bugs and feature requests here: https://github.com/google/liquidfunpaint/issues

Please provide as much detail as you can when posting.


Core Concepts

LiquidFun Paint uses a model-view-controller model.

Both the model and the view components are owned by the Renderer class. We need to synchronize between the physics simulation and the rendering. In order to keep a simple structure, whenever onDrawFrame() is called from OpenGL, we run the update/render loop.

The controller component is split into two classes - Controller and MainActivity. Controller implements listeners that respond to touch and accelerometer events, and those will in turn be used to manipulate LiquidFun. MainActivity is an Android activity which listens to Android UI components, and updates the Controller accordingly.

Threading

As LiquidFun is not reentrant, we need to ensure thread safety from the application itself. We initialize only one instance of b2World from LiquidFun, and within that, only one instance of b2ParticleSystem. We use ReentrantLocks to ensure safe access to both instances from other threads.

Memory Management

All LiquidFun objects are allocated through the C++ allocator. As a result, they should be properly cleaned up when they are not in use anymore. Please refer to the LiquidFun SWIG documentation for more details.


Modules

Renderer

We have multiple renderers for different rendering purposes.

Controller

The controller component is split into two classes.