├── bin ├── WHater.apk ├── classes.dex ├── resources.ap_ ├── res │ ├── drawable │ │ └── football.png │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ └── drawable-xhdpi │ │ └── ic_launcher.png ├── classes │ └── com │ │ └── wheelly │ │ └── whater │ │ ├── R.class │ │ ├── Main.class │ │ ├── R$attr.class │ │ ├── R$layout.class │ │ ├── R$string.class │ │ ├── Rippler.class │ │ ├── WaterView.class │ │ ├── BallBounces.class │ │ ├── BuildConfig.class │ │ ├── JavaRippler.class │ │ ├── R$drawable.class │ │ ├── WaterView$1.class │ │ ├── NativeRippler.class │ │ ├── SurfaceViewActivity.class │ │ ├── WaterView$GameThread.class │ │ └── BallBounces$GameThread.class └── jarlist.cache ├── libs └── armeabi │ └── librippler.so ├── res ├── drawable │ ├── football.png │ └── sky_bgr.jpg ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-ldpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── values │ └── strings.xml └── layout │ └── main.xml ├── obj └── local │ └── armeabi │ ├── librippler.so │ ├── libwater.so │ └── objs │ ├── water │ ├── water.o │ └── water.o.d │ └── rippler │ ├── rippler.o │ └── rippler.o.d ├── jni ├── Android.mk ├── com_wheelly_whater_NativeRippler.h └── rippler.c ├── gen └── com │ └── wheelly │ └── whater │ ├── BuildConfig.java │ └── R.java ├── src └── com │ └── wheelly │ └── whater │ ├── Main.java │ ├── Rippler.java │ ├── NativeRippler.java │ ├── JavaRippler.java │ ├── WaterView.java │ └── SurfaceViewActivity.java ├── .classpath ├── project.properties ├── proguard-project.txt ├── AndroidManifest.xml └── .project /bin/WHater.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/WHater.apk -------------------------------------------------------------------------------- /bin/classes.dex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes.dex -------------------------------------------------------------------------------- /bin/resources.ap_: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/resources.ap_ -------------------------------------------------------------------------------- /libs/armeabi/librippler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/libs/armeabi/librippler.so -------------------------------------------------------------------------------- /res/drawable/football.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/res/drawable/football.png -------------------------------------------------------------------------------- /res/drawable/sky_bgr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/res/drawable/sky_bgr.jpg -------------------------------------------------------------------------------- /bin/res/drawable/football.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/res/drawable/football.png -------------------------------------------------------------------------------- /obj/local/armeabi/librippler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/obj/local/armeabi/librippler.so -------------------------------------------------------------------------------- /obj/local/armeabi/libwater.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/obj/local/armeabi/libwater.so -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /obj/local/armeabi/objs/water/water.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/obj/local/armeabi/objs/water/water.o -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/R.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/R.class -------------------------------------------------------------------------------- /bin/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/Main.class -------------------------------------------------------------------------------- /obj/local/armeabi/objs/rippler/rippler.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/obj/local/armeabi/objs/rippler/rippler.o -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/R$attr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/R$attr.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/R$layout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/R$layout.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/R$string.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/R$string.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/Rippler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/Rippler.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/WaterView.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/WaterView.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/BallBounces.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/BallBounces.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/BuildConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/BuildConfig.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/JavaRippler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/JavaRippler.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/R$drawable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/R$drawable.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/WaterView$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/WaterView$1.class -------------------------------------------------------------------------------- /bin/jarlist.cache: -------------------------------------------------------------------------------- 1 | # cache for current jar dependecy. DO NOT EDIT. 2 | # format is 3 | # Encoding is UTF-8 4 | -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/NativeRippler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/NativeRippler.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/SurfaceViewActivity.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/SurfaceViewActivity.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/WaterView$GameThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/WaterView$GameThread.class -------------------------------------------------------------------------------- /bin/classes/com/wheelly/whater/BallBounces$GameThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esteewhy/whater/HEAD/bin/classes/com/wheelly/whater/BallBounces$GameThread.class -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := rippler 6 | LOCAL_SRC_FILES := rippler.c 7 | 8 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World, Main! 5 | WHater 6 | 7 | -------------------------------------------------------------------------------- /gen/com/wheelly/whater/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package com.wheelly.whater; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /src/com/wheelly/whater/Main.java: -------------------------------------------------------------------------------- 1 | package com.wheelly.whater; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | public class Main extends Activity { 7 | @Override 8 | public void onCreate(Bundle savedInstanceState) { 9 | super.onCreate(savedInstanceState); 10 | setContentView(new WaterView(this)); 11 | } 12 | } -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/com/wheelly/whater/Rippler.java: -------------------------------------------------------------------------------- 1 | package com.wheelly.whater; 2 | 3 | public interface Rippler { 4 | 5 | public abstract void transformRipples(final int _height, final int _width, 6 | short[] rippleMap, short[] lastMap, final int[] textureBitmap, 7 | int[] rippleBitmap, final boolean flip); 8 | 9 | public abstract void disturb(int dx, int dy, 10 | final int width, final int height, final short riprad, 11 | short[] ripplemap, final boolean flip); 12 | } -------------------------------------------------------------------------------- /src/com/wheelly/whater/NativeRippler.java: -------------------------------------------------------------------------------- 1 | package com.wheelly.whater; 2 | 3 | public class NativeRippler implements Rippler { 4 | static { 5 | System.loadLibrary("rippler"); 6 | } 7 | 8 | @Override 9 | public native void transformRipples(final int _height, final int _width, 10 | short[] rippleMap, short[] lastMap, 11 | final int[] textureBitmap, int[] rippleBitmap, 12 | final boolean flip); 13 | 14 | @Override 15 | public native void disturb(int dx, int dy, 16 | final int width, final int height, final short riprad, 17 | short[] ripplemap, final boolean flip); 18 | } -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-7 15 | -------------------------------------------------------------------------------- /gen/com/wheelly/whater/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package com.wheelly.whater; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class drawable { 14 | public static final int football=0x7f020000; 15 | public static final int ic_launcher=0x7f020001; 16 | public static final int sky_bgr=0x7f020002; 17 | } 18 | public static final class layout { 19 | public static final int main=0x7f030000; 20 | } 21 | public static final class string { 22 | public static final int app_name=0x7f040001; 23 | public static final int hello=0x7f040000; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | WHater 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /jni/com_wheelly_whater_NativeRippler.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_wheelly_whater_NativeRippler */ 4 | 5 | #ifndef _Included_com_wheelly_whater_NativeRippler 6 | #define _Included_com_wheelly_whater_NativeRippler 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_wheelly_whater_NativeRippler 12 | * Method: transformRipples 13 | * Signature: (II[S[S[I[IZ)V 14 | */ 15 | JNIEXPORT void JNICALL Java_com_wheelly_whater_NativeRippler_transformRipples 16 | (JNIEnv *, jobject, jint, jint, jshortArray, jshortArray, jintArray, jintArray, jboolean); 17 | 18 | /* 19 | * Class: com_wheelly_whater_NativeRippler 20 | * Method: disturb 21 | * Signature: (IIIIS[SZ)V 22 | */ 23 | JNIEXPORT void JNICALL Java_com_wheelly_whater_NativeRippler_disturb 24 | (JNIEnv *, jobject, jint, jint, jint, jint, jshort, jshortArray, jboolean); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /src/com/wheelly/whater/JavaRippler.java: -------------------------------------------------------------------------------- 1 | package com.wheelly.whater; 2 | 3 | public class JavaRippler implements Rippler { 4 | /* (non-Javadoc) 5 | * @see com.wheelly.whater.Rippler#transformRipples(int, int, short[], short[], int[], int[], boolean) 6 | */ 7 | @Override 8 | public void transformRipples(final int _height, final int _width, 9 | short[] rippleMap, short[] lastMap, 10 | final int[] textureBitmap, int[] rippleBitmap, 11 | final boolean flip) { 12 | int i = 0; 13 | final int half_width = _width / 2; 14 | final int half_height = _height / 2; 15 | 16 | final int mapIndex = flip ? _width : _width * (_height + 3); 17 | final int newIndex = !flip ? _width : _width * (_height + 3); 18 | 19 | for (int y = _height; y > 0; y--) { 20 | for (int x = _width; x > 0; x--) { 21 | int _mapIndex = mapIndex + i; 22 | int _newIndex = newIndex + i; 23 | int data = ( 24 | rippleMap[_mapIndex - _width] + 25 | rippleMap[_mapIndex + _width] + 26 | rippleMap[_mapIndex - 1] + 27 | rippleMap[_mapIndex + 1]) >> 1; 28 | 29 | data -= rippleMap[_newIndex]; 30 | data -= data >> 5; 31 | 32 | rippleMap[_newIndex] = (short)data; 33 | 34 | //where data=0 then still, where data>0 then wave 35 | data = 1024 - data; 36 | 37 | int old_data = lastMap[i]; 38 | lastMap[i] = (short)data; 39 | 40 | if (old_data != data) { 41 | //offsets 42 | int a = (((x - half_width) * data / 1024) << 0) + half_width; 43 | int b = (((y - half_height) * data / 1024) << 0) + half_height; 44 | 45 | //bounds check 46 | if (a >= _width) a = _width - 1; 47 | if (a < 0) a = 0; 48 | if (b >= _height) b = _height - 1; 49 | if (b < 0) b = 0; 50 | 51 | int new_pixel = (a + (b * _width)); 52 | int cur_pixel = i; 53 | 54 | rippleBitmap[cur_pixel] = textureBitmap[new_pixel]; 55 | } 56 | ++i; 57 | } 58 | } 59 | } 60 | 61 | @Override 62 | public void disturb(int dx, int dy, 63 | final int width, final int height, final short riprad, 64 | short[] ripplemap, final boolean flip) { 65 | dx <<= 0; 66 | dy <<= 0; 67 | int offset = !flip ? width : width * (height + 3); 68 | for (int j = dy - riprad; j < dy + riprad; j++) { 69 | for (int k = dx - riprad; k < dx + riprad; k++) { 70 | ripplemap[offset + (j * width) + k] += 128; 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /jni/rippler.c: -------------------------------------------------------------------------------- 1 | #include "com_wheelly_whater_NativeRippler.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #define PIN(array) (*env)->GetShortArrayElements(env, array, NULL) 14 | #define UNPIN(array, data) (*env)->ReleaseShortArrayElements(env, array, data, JNI_ABORT) 15 | 16 | #define PIN_INT(array) (*env)->GetIntArrayElements(env, array, NULL) 17 | #define UNPIN_INT(array, data) (*env)->ReleaseIntArrayElements(env, array, data, JNI_ABORT) 18 | 19 | JNIEXPORT void JNICALL Java_com_wheelly_whater_NativeRippler_transformRipples( 20 | JNIEnv *env, jobject obj, 21 | jint _height, 22 | jint _width, 23 | jshortArray rippleMap, 24 | jshortArray lastMap, 25 | jintArray td, 26 | jintArray rd, 27 | jboolean flip) { 28 | jshort* ripple_map = PIN(rippleMap); 29 | jshort* last_map = PIN(lastMap); 30 | jint* _td = PIN_INT(td); 31 | jint* _rd = PIN_INT(rd); 32 | int half_width = _width >> 1, half_height = _height >> 1; 33 | 34 | int mapind = flip ? _width : _width * (_height + 3); 35 | int newind = !flip ? _width : _width * (_height + 3); 36 | int x, y, i =0; 37 | for (y = 0; y < _height; y++) { 38 | for (x = 0; x < _width; x++) { 39 | int _mapind = mapind + i; 40 | int _newind = newind + i; 41 | int data = ( 42 | ripple_map[_mapind - _width] 43 | + ripple_map[_mapind + _width] 44 | + ripple_map[_mapind - 1] 45 | + ripple_map[_mapind + 1]) >> 1; 46 | data -= ripple_map[_newind]; 47 | data -= data >> 5; 48 | ripple_map[_newind] = (short)data; 49 | 50 | //where data=0 then still, where data>0 then wave 51 | data = 1024 - data; 52 | 53 | short old_data = last_map[i]; 54 | last_map[i] = data; 55 | 56 | if (old_data != data) { 57 | //offsets 58 | int a = (x - half_width) * data >> 10 + half_width; 59 | int b = (y - half_height) * data >> 10 + half_height; 60 | 61 | //bounds check 62 | if (a >= _width) a = _width - 1; 63 | if (a < 0) a = 0; 64 | if (b >= _height) b = _height - 1; 65 | if (b < 0) b = 0; 66 | 67 | int new_pixel = a + (b * _width); 68 | _rd[i] = _td[new_pixel]; 69 | } 70 | 71 | ++i; 72 | } 73 | } 74 | 75 | UNPIN_INT(td, _td); 76 | UNPIN_INT(rd, _rd); 77 | UNPIN(rippleMap, ripple_map); 78 | UNPIN(lastMap, last_map); 79 | } 80 | 81 | JNIEXPORT void JNICALL Java_com_wheelly_whater_NativeRippler_disturb( 82 | JNIEnv *env, jobject obj, 83 | jint dx, jint dy, 84 | jint width, jint height, jshort riprad, 85 | jshortArray rippleMap, jboolean flip) { 86 | dx <<= 0; 87 | dy <<= 0; 88 | int offset = !flip ? width : width * (height + 3); 89 | jshort* ripple_map = PIN(rippleMap); 90 | 91 | int j, k; 92 | for (j = dy - riprad; j < dy + riprad; j++) { 93 | for (k = dx - riprad; k < dx + riprad; k++) { 94 | ripple_map[offset + (j * width) + k] += 512; 95 | } 96 | } 97 | UNPIN(rippleMap, ripple_map); 98 | } 99 | -------------------------------------------------------------------------------- /src/com/wheelly/whater/WaterView.java: -------------------------------------------------------------------------------- 1 | package com.wheelly.whater; 2 | 3 | import java.util.Random; 4 | 5 | import android.content.Context; 6 | import android.graphics.Bitmap; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.os.Handler; 11 | import android.view.MotionEvent; 12 | import android.view.SurfaceHolder; 13 | import android.view.SurfaceView; 14 | 15 | public class WaterView extends SurfaceView implements SurfaceHolder.Callback { 16 | GameThread thread; 17 | 18 | //Measure frames per second. 19 | long now; 20 | int framesCount=0; 21 | int framesCountAvg=0; 22 | long framesTimer=0; 23 | Paint fpsPaint=new Paint(); 24 | 25 | //Frame speed 26 | long timeNow; 27 | long timePrev = 0; 28 | long timePrevFrame = 0; 29 | long timeDelta; 30 | 31 | private int width = 400; 32 | private int height = 400; 33 | private short riprad = 3; 34 | boolean flip; 35 | private short[] ripplemap, last_map; 36 | Bitmap ripple; 37 | private static final int line_width = 20; 38 | private static final int step = line_width * 2; 39 | 40 | private Rippler rippler; 41 | 42 | public WaterView(Context context) { 43 | super(context); 44 | initialize(); 45 | } 46 | 47 | void initialize() { 48 | rippler = new NativeRippler(); 49 | reinitgGlobals(); 50 | fpsPaint.setTextSize(30); 51 | 52 | //Set thread 53 | getHolder().addCallback(this); 54 | 55 | setFocusable(true); 56 | } 57 | 58 | void reinitgGlobals() { 59 | int size = width * (height + 2) * 2; 60 | ripplemap = new short[size]; 61 | last_map = new short[size]; 62 | Bitmap texture = createBackground(width, height); // this creates a MUTABLE bitmap 63 | ripple = texture; 64 | _td = new int[width * height]; 65 | texture.getPixels(_td, 0, width, 0, 0, width, height); 66 | _rd = new int[width * height]; 67 | } 68 | 69 | void randomizer() { 70 | final Random rnd = new Random(); 71 | final Handler disHAndler = new Handler(); 72 | final Runnable disturbWater = new Runnable() { 73 | @Override 74 | public void run() { 75 | disturb(rnd.nextInt(width), rnd.nextInt(height)); 76 | disHAndler.postDelayed(this, 7000); 77 | } 78 | }; 79 | disHAndler.post(disturbWater); 80 | } 81 | 82 | private static Bitmap createBackground(int width, int height) { 83 | Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 84 | Canvas c = new Canvas(bm); 85 | c.drawColor(Color.parseColor("#a2ddf8")); 86 | c.save(); 87 | c.rotate(-45); 88 | Paint p = new Paint(); 89 | p.setColor(Color.parseColor("#0077bb")); 90 | for (int i = 0; i < height / line_width; i++) { 91 | c.drawRect(-width, i * step, width * 3, i * step + line_width, p); 92 | } 93 | 94 | c.restore(); 95 | return bm; 96 | } 97 | 98 | @Override 99 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 100 | super.onSizeChanged(w, h, oldw, oldh); 101 | width = w; 102 | height = h; 103 | reinitgGlobals(); 104 | } 105 | 106 | @Override 107 | protected void onDraw(android.graphics.Canvas canvas) { 108 | super.onDraw(canvas); 109 | newframe(); 110 | canvas.drawBitmap(ripple, 0, 0, null); 111 | 112 | //Measure frame rate (unit: frames per second). 113 | now=System.currentTimeMillis(); 114 | canvas.drawText(framesCountAvg+" fps", 40, 70, fpsPaint); 115 | framesCount++; 116 | if(now-framesTimer>1000) { 117 | framesTimer=now; 118 | framesCountAvg=framesCount; 119 | framesCount=0; 120 | } 121 | } 122 | 123 | /** 124 | * Disturb water at specified point 125 | */ 126 | private void disturb(int dx, int dy) { 127 | rippler.disturb(dx, dy, width, height, riprad, ripplemap, flip); 128 | } 129 | 130 | int[] _td; 131 | int[] _rd; 132 | 133 | /** 134 | * Generates new ripples 135 | */ 136 | private void newframe() { 137 | System.arraycopy(_td, 0, _rd, 0, width * height); 138 | flip = !flip; 139 | rippler.transformRipples(height, width, ripplemap, last_map, _td, _rd, flip); 140 | ripple.setPixels(_rd, 0, width, 0, 0, width, height); 141 | } 142 | 143 | 144 | @Override 145 | public synchronized boolean onTouchEvent(MotionEvent event) { 146 | //switch(event.getAction()) { 147 | //case MotionEvent.ACTION_MOVE: 148 | disturb((int)event.getX(), (int)event.getY()); 149 | return true; 150 | //} 151 | //return super.onTouchEvent(event); 152 | } 153 | 154 | @Override 155 | public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { 156 | } 157 | 158 | @Override 159 | public void surfaceCreated(SurfaceHolder arg0) { 160 | thread = new GameThread(getHolder(), this); 161 | thread.setRunning(true); 162 | thread.start(); 163 | } 164 | 165 | @Override 166 | public void surfaceDestroyed(SurfaceHolder arg0) { 167 | boolean retry = true; 168 | thread.setRunning(false); 169 | while (retry) { 170 | try { 171 | thread.join(); 172 | retry = false; 173 | } catch (InterruptedException e) { 174 | 175 | } 176 | } 177 | } 178 | 179 | class GameThread extends Thread { 180 | private SurfaceHolder surfaceHolder; 181 | private WaterView gameView; 182 | private boolean run = false; 183 | 184 | public GameThread(SurfaceHolder surfaceHolder, WaterView gameView) { 185 | this.surfaceHolder = surfaceHolder; 186 | this.gameView = gameView; 187 | } 188 | 189 | public void setRunning(boolean run) { 190 | this.run = run; 191 | } 192 | 193 | public SurfaceHolder getSurfaceHolder() { 194 | return surfaceHolder; 195 | } 196 | 197 | @Override 198 | public void run() { 199 | Canvas c; 200 | while (run) { 201 | c = null; 202 | 203 | //limit frame rate to max 60fps 204 | timeNow = System.currentTimeMillis(); 205 | timeDelta = timeNow - timePrevFrame; 206 | if ( timeDelta < 16) { 207 | try { 208 | Thread.sleep(16 - timeDelta); 209 | } 210 | catch(InterruptedException e) { 211 | 212 | } 213 | } 214 | timePrevFrame = System.currentTimeMillis(); 215 | 216 | try { 217 | c = surfaceHolder.lockCanvas(null); 218 | synchronized (surfaceHolder) { 219 | //call methods to draw and process next fame 220 | gameView.onDraw(c); 221 | } 222 | } finally { 223 | if (c != null) { 224 | surfaceHolder.unlockCanvasAndPost(c); 225 | } 226 | } 227 | } 228 | } 229 | } 230 | } -------------------------------------------------------------------------------- /obj/local/armeabi/objs/water/water.o.d: -------------------------------------------------------------------------------- 1 | D:/usr/src/android/whater//obj/local/armeabi/objs/water/water.o: \ 2 | D:/usr/src/android/whater//jni/water.c \ 3 | D:/usr/src/android/whater//jni/com_wheelly_whater_NativeWater.h \ 4 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/jni.h \ 5 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/errno.h \ 6 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs.h \ 7 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs_elf.h \ 8 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/api-level.h \ 9 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/errno.h \ 10 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/errno.h \ 11 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno.h \ 12 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno-base.h \ 13 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/time.h \ 14 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/types.h \ 15 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdint.h \ 16 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/_types.h \ 17 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/_types.h \ 18 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/posix_types.h \ 19 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/stddef.h \ 20 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/compiler.h \ 21 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/posix_types.h \ 22 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/types.h \ 23 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/types.h \ 24 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/kernel.h \ 25 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/sysmacros.h \ 26 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/time.h \ 27 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/time.h \ 28 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/siginfo.h \ 29 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/siginfo.h \ 30 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/log.h \ 31 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdio.h \ 32 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdlib.h \ 33 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/string.h \ 34 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/malloc.h \ 35 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/alloca.h \ 36 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/strings.h \ 37 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/memory.h \ 38 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/math.h \ 39 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/limits.h \ 40 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/limits.h \ 41 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/limits.h \ 42 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/internal_types.h \ 43 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/limits.h \ 44 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/syslimits.h 45 | 46 | D:/usr/src/android/whater//jni/com_wheelly_whater_NativeWater.h: 47 | 48 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/jni.h: 49 | 50 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/errno.h: 51 | 52 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs.h: 53 | 54 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs_elf.h: 55 | 56 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/api-level.h: 57 | 58 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/errno.h: 59 | 60 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/errno.h: 61 | 62 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno.h: 63 | 64 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno-base.h: 65 | 66 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/time.h: 67 | 68 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/types.h: 69 | 70 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdint.h: 71 | 72 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/_types.h: 73 | 74 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/_types.h: 75 | 76 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/posix_types.h: 77 | 78 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/stddef.h: 79 | 80 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/compiler.h: 81 | 82 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/posix_types.h: 83 | 84 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/types.h: 85 | 86 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/types.h: 87 | 88 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/kernel.h: 89 | 90 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/sysmacros.h: 91 | 92 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/time.h: 93 | 94 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/time.h: 95 | 96 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/siginfo.h: 97 | 98 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/siginfo.h: 99 | 100 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/log.h: 101 | 102 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdio.h: 103 | 104 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdlib.h: 105 | 106 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/string.h: 107 | 108 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/malloc.h: 109 | 110 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/alloca.h: 111 | 112 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/strings.h: 113 | 114 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/memory.h: 115 | 116 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/math.h: 117 | 118 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/limits.h: 119 | 120 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/limits.h: 121 | 122 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/limits.h: 123 | 124 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/internal_types.h: 125 | 126 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/limits.h: 127 | 128 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/syslimits.h: 129 | -------------------------------------------------------------------------------- /obj/local/armeabi/objs/rippler/rippler.o.d: -------------------------------------------------------------------------------- 1 | D:/usr/src/android/whater//obj/local/armeabi/objs/rippler/rippler.o: \ 2 | D:/usr/src/android/whater//jni/rippler.c \ 3 | D:/usr/src/android/whater//jni/com_wheelly_whater_NativeRippler.h \ 4 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/jni.h \ 5 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/errno.h \ 6 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs.h \ 7 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs_elf.h \ 8 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/api-level.h \ 9 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/errno.h \ 10 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/errno.h \ 11 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno.h \ 12 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno-base.h \ 13 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/time.h \ 14 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/types.h \ 15 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdint.h \ 16 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/_types.h \ 17 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/_types.h \ 18 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/posix_types.h \ 19 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/stddef.h \ 20 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/compiler.h \ 21 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/posix_types.h \ 22 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/types.h \ 23 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/types.h \ 24 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/kernel.h \ 25 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/sysmacros.h \ 26 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/time.h \ 27 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/time.h \ 28 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/siginfo.h \ 29 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/siginfo.h \ 30 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/log.h \ 31 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdio.h \ 32 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdlib.h \ 33 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/string.h \ 34 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/malloc.h \ 35 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/alloca.h \ 36 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/strings.h \ 37 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/memory.h \ 38 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/math.h \ 39 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/limits.h \ 40 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/limits.h \ 41 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/limits.h \ 42 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/internal_types.h \ 43 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/limits.h \ 44 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/syslimits.h 45 | 46 | D:/usr/src/android/whater//jni/com_wheelly_whater_NativeRippler.h: 47 | 48 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/jni.h: 49 | 50 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/errno.h: 51 | 52 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs.h: 53 | 54 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/cdefs_elf.h: 55 | 56 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/api-level.h: 57 | 58 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/errno.h: 59 | 60 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/errno.h: 61 | 62 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno.h: 63 | 64 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/errno-base.h: 65 | 66 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/time.h: 67 | 68 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/types.h: 69 | 70 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdint.h: 71 | 72 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/_types.h: 73 | 74 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/_types.h: 75 | 76 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/posix_types.h: 77 | 78 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/stddef.h: 79 | 80 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/compiler.h: 81 | 82 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/posix_types.h: 83 | 84 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/types.h: 85 | 86 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/types.h: 87 | 88 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/kernel.h: 89 | 90 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/sysmacros.h: 91 | 92 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/time.h: 93 | 94 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/time.h: 95 | 96 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm/siginfo.h: 97 | 98 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/asm-generic/siginfo.h: 99 | 100 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/android/log.h: 101 | 102 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdio.h: 103 | 104 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/stdlib.h: 105 | 106 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/string.h: 107 | 108 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/malloc.h: 109 | 110 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/alloca.h: 111 | 112 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/strings.h: 113 | 114 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/memory.h: 115 | 116 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/math.h: 117 | 118 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/limits.h: 119 | 120 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/limits.h: 121 | 122 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/linux/limits.h: 123 | 124 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/internal_types.h: 125 | 126 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/machine/limits.h: 127 | 128 | D:/usr/android-ndk-r8/platforms/android-3/arch-arm/usr/include/sys/syslimits.h: 129 | -------------------------------------------------------------------------------- /src/com/wheelly/whater/SurfaceViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.wheelly.whater; 2 | import android.app.Activity; 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Matrix; 8 | import android.graphics.Paint; 9 | import android.graphics.Rect; 10 | import android.os.Bundle; 11 | import android.view.MotionEvent; 12 | import android.view.SurfaceHolder; 13 | import android.view.SurfaceView; 14 | 15 | public class SurfaceViewActivity extends Activity { 16 | BallBounces ball; 17 | 18 | @Override 19 | public void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | ball = new BallBounces(this); 22 | setContentView(ball); 23 | } 24 | } 25 | 26 | 27 | class BallBounces extends SurfaceView implements SurfaceHolder.Callback { 28 | GameThread thread; 29 | int screenW; //Device's screen width. 30 | int screenH; //Devices's screen height. 31 | int ballX; //Ball x position. 32 | int ballY; //Ball y position. 33 | int initialY ; 34 | float dY; //Ball vertical speed. 35 | int ballW; 36 | int ballH; 37 | int bgrW; 38 | int bgrH; 39 | int angle; 40 | int bgrScroll; 41 | int dBgrY; //Background scroll speed. 42 | float acc; 43 | Bitmap ball, bgr, bgrReverse; 44 | boolean reverseBackroundFirst; 45 | boolean ballFingerMove; 46 | 47 | //Measure frames per second. 48 | long now; 49 | int framesCount=0; 50 | int framesCountAvg=0; 51 | long framesTimer=0; 52 | Paint fpsPaint=new Paint(); 53 | 54 | //Frame speed 55 | long timeNow; 56 | long timePrev = 0; 57 | long timePrevFrame = 0; 58 | long timeDelta; 59 | 60 | 61 | public BallBounces(Context context) { 62 | super(context); 63 | ball = BitmapFactory.decodeResource(getResources(),R.drawable.football); //Load a ball image. 64 | bgr = BitmapFactory.decodeResource(getResources(),R.drawable.sky_bgr); //Load a background. 65 | ballW = ball.getWidth(); 66 | ballH = ball.getHeight(); 67 | 68 | //Create a flag for the onDraw method to alternate background with its mirror image. 69 | reverseBackroundFirst = false; 70 | 71 | //Initialise animation variables. 72 | acc = 0.2f; //Acceleration 73 | dY = 0; //vertical speed 74 | initialY = 100; //Initial vertical position 75 | angle = 0; //Start value for the rotation angle 76 | bgrScroll = 0; //Background scroll position 77 | dBgrY = 1; //Scrolling background speed 78 | 79 | fpsPaint.setTextSize(30); 80 | 81 | //Set thread 82 | getHolder().addCallback(this); 83 | 84 | setFocusable(true); 85 | } 86 | 87 | @Override 88 | public void onSizeChanged (int w, int h, int oldw, int oldh) { 89 | super.onSizeChanged(w, h, oldw, oldh); 90 | //This event-method provides the real dimensions of this custom view. 91 | screenW = w; 92 | screenH = h; 93 | 94 | bgr = Bitmap.createScaledBitmap(bgr, w, h, true); //Scale background to fit the screen. 95 | bgrW = bgr.getWidth(); 96 | bgrH = bgr.getHeight(); 97 | 98 | //Create a mirror image of the background (horizontal flip) - for a more circular background. 99 | Matrix matrix = new Matrix(); //Like a frame or mould for an image. 100 | matrix.setScale(-1, 1); //Horizontal mirror effect. 101 | bgrReverse = Bitmap.createBitmap(bgr, 0, 0, bgrW, bgrH, matrix, true); //Create a new mirrored bitmap by applying the matrix. 102 | 103 | ballX = (int) (screenW /2) - (ballW / 2) ; //Centre ball X into the centre of the screen. 104 | ballY = -50; //Centre ball height above the screen. 105 | } 106 | 107 | //*************************************** 108 | //************* TOUCH ***************** 109 | //*************************************** 110 | @Override 111 | public synchronized boolean onTouchEvent(MotionEvent ev) { 112 | 113 | switch (ev.getAction()) { 114 | case MotionEvent.ACTION_DOWN: { 115 | ballX = (int) ev.getX() - ballW/2; 116 | ballY = (int) ev.getY() - ballH/2; 117 | 118 | ballFingerMove = true; 119 | break; 120 | } 121 | 122 | case MotionEvent.ACTION_MOVE: { 123 | ballX = (int) ev.getX() - ballW/2; 124 | ballY = (int) ev.getY() - ballH/2; 125 | 126 | break; 127 | } 128 | 129 | case MotionEvent.ACTION_UP: 130 | ballFingerMove = false; 131 | dY = 0; 132 | break; 133 | } 134 | return true; 135 | } 136 | 137 | @Override 138 | public void onDraw(Canvas canvas) { 139 | super.onDraw(canvas); 140 | 141 | //Draw scrolling background. 142 | Rect fromRect1 = new Rect(0, 0, bgrW - bgrScroll, bgrH); 143 | Rect toRect1 = new Rect(bgrScroll, 0, bgrW, bgrH); 144 | 145 | Rect fromRect2 = new Rect(bgrW - bgrScroll, 0, bgrW, bgrH); 146 | Rect toRect2 = new Rect(0, 0, bgrScroll, bgrH); 147 | 148 | if (!reverseBackroundFirst) { 149 | canvas.drawBitmap(bgr, fromRect1, toRect1, null); 150 | canvas.drawBitmap(bgrReverse, fromRect2, toRect2, null); 151 | } 152 | else{ 153 | canvas.drawBitmap(bgr, fromRect2, toRect2, null); 154 | canvas.drawBitmap(bgrReverse, fromRect1, toRect1, null); 155 | } 156 | 157 | //Next value for the background's position. 158 | if ( (bgrScroll += dBgrY) >= bgrW) { 159 | bgrScroll = 0; 160 | reverseBackroundFirst = !reverseBackroundFirst; 161 | } 162 | 163 | //Compute roughly the ball's speed and location. 164 | if (!ballFingerMove) { 165 | ballY += (int) dY; //Increase or decrease vertical position. 166 | if (ballY > (screenH - ballH)) { 167 | dY=(-1)*dY; //Reverse speed when bottom hit. 168 | } 169 | dY+= acc; //Increase or decrease speed. 170 | } 171 | 172 | //Increase rotating angle 173 | if (angle++ >360) 174 | angle =0; 175 | 176 | //DRAW BALL 177 | //Rotate method one 178 | /* 179 | Matrix matrix = new Matrix(); 180 | matrix.postRotate(angle, (ballW / 2), (ballH / 2)); //Rotate it. 181 | matrix.postTranslate(ballX, ballY); //Move it into x, y position. 182 | canvas.drawBitmap(ball, matrix, null); //Draw the ball with applied matrix. 183 | 184 | */// Rotate method two 185 | 186 | canvas.save(); //Save the position of the canvas matrix. 187 | canvas.rotate(angle, ballX + (ballW / 2), ballY + (ballH / 2)); //Rotate the canvas matrix. 188 | canvas.drawBitmap(ball, ballX, ballY, null); //Draw the ball by applying the canvas rotated matrix. 189 | canvas.restore(); //Rotate the canvas matrix back to its saved position - only the ball bitmap was rotated not all canvas. 190 | 191 | //*/ 192 | 193 | //Measure frame rate (unit: frames per second). 194 | now=System.currentTimeMillis(); 195 | canvas.drawText(framesCountAvg+" fps", 40, 70, fpsPaint); 196 | framesCount++; 197 | if(now-framesTimer>1000) { 198 | framesTimer=now; 199 | framesCountAvg=framesCount; 200 | framesCount=0; 201 | } 202 | } 203 | 204 | @Override 205 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 206 | } 207 | 208 | @Override 209 | public void surfaceCreated(SurfaceHolder holder) { 210 | thread = new GameThread(getHolder(), this); 211 | thread.setRunning(true); 212 | thread.start(); 213 | } 214 | 215 | @Override 216 | public void surfaceDestroyed(SurfaceHolder holder) { 217 | boolean retry = true; 218 | thread.setRunning(false); 219 | while (retry) { 220 | try { 221 | thread.join(); 222 | retry = false; 223 | } catch (InterruptedException e) { 224 | 225 | } 226 | } 227 | } 228 | 229 | 230 | class GameThread extends Thread { 231 | private SurfaceHolder surfaceHolder; 232 | private BallBounces gameView; 233 | private boolean run = false; 234 | 235 | public GameThread(SurfaceHolder surfaceHolder, BallBounces gameView) { 236 | this.surfaceHolder = surfaceHolder; 237 | this.gameView = gameView; 238 | } 239 | 240 | public void setRunning(boolean run) { 241 | this.run = run; 242 | } 243 | 244 | public SurfaceHolder getSurfaceHolder() { 245 | return surfaceHolder; 246 | } 247 | 248 | @Override 249 | public void run() { 250 | Canvas c; 251 | while (run) { 252 | c = null; 253 | 254 | //limit frame rate to max 60fps 255 | timeNow = System.currentTimeMillis(); 256 | timeDelta = timeNow - timePrevFrame; 257 | if ( timeDelta < 16) { 258 | try { 259 | Thread.sleep(16 - timeDelta); 260 | } 261 | catch(InterruptedException e) { 262 | 263 | } 264 | } 265 | timePrevFrame = System.currentTimeMillis(); 266 | 267 | try { 268 | c = surfaceHolder.lockCanvas(null); 269 | synchronized (surfaceHolder) { 270 | //call methods to draw and process next fame 271 | gameView.onDraw(c); 272 | } 273 | } finally { 274 | if (c != null) { 275 | surfaceHolder.unlockCanvasAndPost(c); 276 | } 277 | } 278 | } 279 | } 280 | } 281 | } --------------------------------------------------------------------------------