浏览代码

Catch up with latest changes on Android. Also fix touch input.

Joachim Meyer 9 年之前
父节点
当前提交
f580821ddb

+ 6 - 0
build/android/.idea/encodings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="PROJECT" charset="UTF-8" />
+  </component>
+</project>

+ 1 - 1
build/android/.idea/misc.xml

@@ -37,7 +37,7 @@
     <ConfirmationsSetting value="0" id="Add" />
     <ConfirmationsSetting value="0" id="Remove" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 1 - 2
build/android/Polycore/AndroidManifest.xml

@@ -5,8 +5,7 @@
         android:versionCode="1"
         android:versionName="1.0">
 
-    <!-- This is the platform API where NativeActivity was introduced. -->
-    <uses-sdk android:minSdkVersion="14" />
+    <uses-sdk android:minSdkVersion="21" />
 
     <!-- This .apk has no Java code itself, so set hasCode to false. -->
     <application android:label="Polycore" android:hasCode="false">

+ 7 - 8
build/android/Polycore/build.gradle

@@ -4,10 +4,9 @@ apply plugin: 'com.android.application'
 android {
     compileSdkVersion 23
     buildToolsVersion "23.0.2"
-
     defaultConfig {
         applicationId "org.polycode.polycore"
-        minSdkVersion 14
+        minSdkVersion 21
         targetSdkVersion 23
         versionCode 1
         versionName "1.0"
@@ -17,14 +16,16 @@ android {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
+        debug {
+            debuggable true
+            jniDebuggable true
+        }
     }
-
     sourceSets.main {
         manifest.srcFile 'AndroidManifest.xml'
         //jniLibs.srcDir '../../../lib/android/' //set libs as .so's location instead of jniLibs
         jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
     }
-
     // call regular ndk-build(.cmd) script from app directory
     task ndkBuild(type: Exec) {
         if (Os.isFamily(Os.FAMILY_WINDOWS)) {
@@ -33,14 +34,12 @@ android {
             commandLine 'ndk-build'
         }
     }
-
     tasks.withType(JavaCompile) {
         compileTask -> compileTask.dependsOn ndkBuild
     }
+    productFlavors {
+    }
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
-    testCompile 'junit:junit:4.12'
-    compile 'com.android.support:appcompat-v7:23.1.1'
 }

文件差异内容过多而无法显示
+ 0 - 0
build/android/Polycore/jni/Android.mk


+ 1 - 1
build/android/Polycore/jni/Application.mk

@@ -1,4 +1,4 @@
-APP_PLATFORM := android-14
+APP_PLATFORM := android-21
 APP_ABI := armeabi x86
 APP_STL := gnustl_static
 APP_CPPFLAGS += -std=c++11

+ 1 - 1
build/android/TemplateApp/AndroidManifest.xml

@@ -3,7 +3,7 @@
     android:versionCode="1"
     android:versionName="1.0">
 
-    <uses-sdk android:minSdkVersion="14" />
+    <uses-sdk android:minSdkVersion="21" />
 
     <application android:label="TemplateApp">
 

+ 5 - 11
build/android/TemplateApp/build.gradle

@@ -4,11 +4,10 @@ apply plugin: 'com.android.application'
 
 android {
     compileSdkVersion 23
-    buildToolsVersion "23.0.2"
-
+    buildToolsVersion '23.0.2'
     defaultConfig {
         applicationId "org.polycode.templateapp"
-        minSdkVersion 14
+        minSdkVersion 21
         targetSdkVersion 23
         versionCode 1
         versionName "1.0"
@@ -18,17 +17,15 @@ android {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
-        debug{
+        debug {
             jniDebuggable = true
         }
     }
-
     sourceSets.main {
         manifest.srcFile 'AndroidManifest.xml'
         jniLibs.srcDir 'libs' //set libs as .so's location instead of jniLibs
         jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
     }
-
     // call regular ndk-build(.cmd) script from app directory
     task ndkBuild(type: Exec) {
         if (Os.isFamily(Os.FAMILY_WINDOWS)) {
@@ -37,19 +34,16 @@ android {
             commandLine 'ndk-build'
         }
     }
-
     task copyAssets(type: Copy) {
         from '../../../assets/default/default'
         into 'src/main/assets/default'
     }
-
     tasks.withType(JavaCompile) {
         compileTask -> compileTask.dependsOn ndkBuild, copyAssets
     }
+    productFlavors {
+    }
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
-    testCompile 'junit:junit:4.12'
-    compile 'com.android.support:appcompat-v7:23.1.1'
 }

+ 6 - 1
build/android/TemplateApp/jni/Android.mk

@@ -17,6 +17,11 @@ LOCAL_MODULE := ogg
 LOCAL_SRC_FILES := $(LIBDIR)/libogg.so
 include $(PREBUILT_SHARED_LIBRARY)
 
+include $(CLEAR_VARS)
+LOCAL_MODULE := lua
+LOCAL_SRC_FILES := $(LIBDIR)/liblua.a
+include $(PREBUILT_STATIC_LIBRARY)
+
 include $(CLEAR_VARS)
 LOCAL_MODULE := vorbis
 LOCAL_SRC_FILES := $(LIBDIR)/libvorbis.so
@@ -25,7 +30,7 @@ include $(PREBUILT_SHARED_LIBRARY)
 include $(CLEAR_VARS)
 LOCAL_MODULE := TemplateApp
 LOCAL_LDLIBS := -landroid -lEGL -lGLESv2 -lOpenSLES -lz -llog
-LOCAL_STATIC_LIBRARIES := Polycore freetype
+LOCAL_STATIC_LIBRARIES := Polycore freetype lua
 LOCAL_SHARED_LIBRARIES := ogg vorbis
 LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../include -DUSE_EGL -DSTRICT_OPENGLES2
 LOCAL_SRC_FILES := PolycodeTemplate.cpp PolycodeTemplateApp.cpp

+ 1 - 1
build/android/TemplateApp/jni/Application.mk

@@ -1,4 +1,4 @@
-APP_PLATFORM := android-14
+APP_PLATFORM := android-21
 APP_ABI := armeabi x86
 APP_STL := gnustl_static
 APP_CPPFLAGS += -std=c++11

+ 9 - 2
build/android/TemplateApp/jni/PolycodeTemplateApp.cpp

@@ -14,11 +14,11 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
 
 	// Write your code here!
     srand(time(NULL));
-    Scene *scene = new Scene(Scene::SCENE_2D);
+    scene = new Scene(Scene::SCENE_2D);
     scene->useClearColor = true;
     scene->clearColor.setColor(1.0f / (float)(rand() % 5),1.0f / (float)(rand()%5),1.0f / (float)(rand() % 5),1.0f);
 
-    ScenePrimitive *test = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.5, 0.5);
+    test = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.5, 0.5);
     scene->addChild(test);
     test->setPositionY(0.2);
     test->setMaterialByName("Unlit");
@@ -49,6 +49,7 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
     Services()->getInput()->addEventListener(this, InputEvent::EVENT_TOUCHES_BEGAN);
     Services()->getInput()->addEventListener(this, InputEvent::EVENT_TOUCHES_ENDED);
     Services()->getInput()->addEventListener(this, InputEvent::EVENT_TOUCHES_MOVED);
+    
 }
 
 void PolycodeTemplateApp::handleEvent(Event *event) {
@@ -67,10 +68,16 @@ void PolycodeTemplateApp::handleEvent(Event *event) {
         }
     } else if (inputEvent->getEventCode() == InputEvent::EVENT_TOUCHES_BEGAN){
         Logger::log("Touch began: %f, %f", inputEvent->touch.position.x, inputEvent->touch.position.y);
+        Ray r = scene->projectRayFromCameraAndViewportCoordinate(scene->getActiveCamera(),inputEvent->touch.position);
+        test->setPosition(r.origin.x, r.origin.y);
     } else if(inputEvent->getEventCode() == InputEvent::EVENT_TOUCHES_ENDED){
         Logger::log("Touch ended: %f, %f", inputEvent->touch.position.x, inputEvent->touch.position.y);
+        Ray r = scene->projectRayFromCameraAndViewportCoordinate(scene->getActiveCamera(),inputEvent->touch.position);
+        test->setPosition(r.origin.x, r.origin.y);
     } else if(inputEvent->getEventCode() == InputEvent::EVENT_TOUCHES_MOVED){
         Logger::log("Touch moved: %f, %f", inputEvent->touch.position.x, inputEvent->touch.position.y);
+        Ray r = scene->projectRayFromCameraAndViewportCoordinate(scene->getActiveCamera(),inputEvent->touch.position);
+        test->setPosition(r.origin.x, r.origin.y);
     }
 }
 

+ 4 - 1
build/android/TemplateApp/jni/PolycodeTemplateApp.h

@@ -22,6 +22,9 @@ private:
     Sound *sound1;
     Sound *sound2;
     Sound *sound3;
-    
+
+    ScenePrimitive *test;
+    Scene *scene;
+
     Core *core;
 };

+ 1 - 1
build/android/build.gradle

@@ -5,7 +5,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.0.0-beta7'
+        classpath 'com.android.tools.build:gradle:2.1.0'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files

+ 1 - 0
include/polycode/core/PolyAndroidCore.h

@@ -29,6 +29,7 @@
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
 #include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
 
 #include <android/native_activity.h>
 

+ 1 - 0
include/polycode/core/PolyOpenGLGraphicsInterface.h

@@ -58,6 +58,7 @@ THE SOFTWARE.
 		#include <EGL/egl.h>
 		#include <EGL/eglext.h>
 		#include <GLES2/gl2.h>
+		#include <GLES2/gl2ext.h>
 	#else
 		#ifdef EMSCRIPTEN
 			#include "SDL/SDL_opengl.h"

+ 0 - 1
src/core/PolyAndroidCore.cpp

@@ -71,7 +71,6 @@ AndroidCore::AndroidCore(PolycodeView *view, int xRes, int yRes, bool fullScreen
 	
 	this->view = view;
 	core = this;
-	
 }
 
 AndroidCore::~AndroidCore() {

+ 1 - 1
src/core/PolyCoreInput.cpp

@@ -288,7 +288,7 @@ namespace Polycode {
 		InputEvent *evt = new InputEvent();
 		evt->touch = touch;
 		evt->touches = touches;
-		evt->timestamp = ticks;		
+		evt->timestamp = ticks;
 		dispatchEvent(evt, InputEvent::EVENT_TOUCHES_MOVED);
 		if(simulateMouseWithTouch) {
 			setMousePosition(touch.position.x, touch.position.y, ticks);

+ 20 - 17
src/core/PolyRenderer.cpp

@@ -86,7 +86,26 @@ void RenderThread::updateRenderThread() {
 	while (jobQueue.size() > 0) {
 		RendererThreadJob nextJob = jobQueue.front();
 		jobQueue.pop();
-		processJob(nextJob);
+#if PLATFORM == PLATFORM_ANDROID
+		if (!core->isWindowInitialized() && nextJob.jobType != JOB_REQUEST_CONTEXT_CHANGE) {
+			jobQueue.push(nextJob);
+			for (int i = 0; i < jobQueue.size() - 1; i++) {
+				RendererThreadJob fJob = jobQueue.front();
+				if (fJob.jobType != JOB_REQUEST_CONTEXT_CHANGE) {
+					jobQueue.push(fJob);
+				} else {
+					processJob(fJob);
+					i--;
+				}
+				jobQueue.pop();
+			}
+			break;
+		} else {
+#endif
+			processJob(nextJob);
+#if PLATFORM == PLATFORM_ANDROID
+		}
+#endif
 	}
 
 	RenderFrame *nextFrame = NULL;
@@ -332,22 +351,6 @@ void RenderThread::clearFrameQueue() {
 
 void RenderThread::processJob(const RendererThreadJob &job) {
 	lockRenderMutex();
-#if PLATFORM == PLATFORM_ANDROID
-	if(!core->isWindowInitialized() && job.jobType != JOB_REQUEST_CONTEXT_CHANGE){
-		jobQueue.push(job);
-		for(int i = 0; i < jobQueue.size()-1; i++){
-			RendererThreadJob fJob = jobQueue.front();
-			if (fJob.jobType != JOB_REQUEST_CONTEXT_CHANGE) {
-				jobQueue.push(fJob);
-			} else {
-				processJob(fJob);
-				i--;
-			}
-			jobQueue.pop();
-		}
-		return;
-	}
-	#endif
 
 	switch(job.jobType) {
 		case JOB_REQUEST_CONTEXT_CHANGE:

+ 71 - 41
src/view/android/PolycodeView.cpp

@@ -76,7 +76,7 @@ void onPause(ANativeActivity* activity){
 }
 
 void* onSaveInstanceState(ANativeActivity* activity, size_t *outSize){
-	
+	Logger::log("onSaveInstanceState");
 }
 
 void onStop(ANativeActivity* activity){
@@ -127,11 +127,11 @@ void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow *window){
 }
 
 void onNativeWindowResized(ANativeActivity* activity, ANativeWindow *window){
-	
+	Logger::log("onNativeWindowResized");
 }
 
 void onNativeWindowRedrawNeeded(ANativeActivity* activity, ANativeWindow *window){
-	
+	Logger::log("onNativeWindowRedrawNeeded");
 }
 
 void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow *window){
@@ -146,6 +146,9 @@ void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow *window){
 
 void onInputQueueCreated(ANativeActivity* activity, AInputQueue *queue){
 	Logger::log("onInputQueueCreated");
+	if (((PolycodeView*)activity->instance)->native_input != NULL) {
+		AInputQueue_detachLooper(((PolycodeView*)activity->instance)->native_input);
+	}
 	((PolycodeView*)activity->instance)->native_input = queue;
 	ALooper *loop = ALooper_prepare(0);
 	AInputQueue_attachLooper(((PolycodeView*)activity->instance)->native_input, loop, ALOOPER_EVENT_INPUT, inputLoop, ((PolycodeView*)activity->instance)->native_input);
@@ -158,15 +161,15 @@ void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue *queue){
 }
 
 void onContentRectChanged(ANativeActivity* activity, const ARect *rect){
-	
+	Logger::log("onContentRectChanged");
 }
 
 void onConfiguartionChanged(ANativeActivity* activity){
-	
+	Logger::log("onConfiguartionChanged");
 }
 
 void onLowMemory(ANativeActivity* activity){
-	
+	Logger::log("onLowMemory");
 }
 
 int inputLoop(int fd, int events, void* data){
@@ -180,10 +183,10 @@ int inputLoop(int fd, int events, void* data){
 	while(AInputQueue_hasEvents(native_input)>0){
 		if(AInputQueue_getEvent(native_input, &aev)>=0){
 			event = AndroidEvent();
-			event.eventTime = AKeyEvent_getEventTime(aev);
 			event.eventGroup = AndroidEvent::INPUT_EVENT;
 			type = AInputEvent_getType(aev);
 			if(type == AINPUT_EVENT_TYPE_KEY){
+				event.eventTime = AKeyEvent_getEventTime(aev);
 				action = AKeyEvent_getAction(aev);
 				if(action == AKEY_EVENT_ACTION_DOWN){
 					event.eventCode = InputEvent::EVENT_KEYDOWN;
@@ -192,51 +195,78 @@ int inputLoop(int fd, int events, void* data){
 				}
 				
 			} else if(type == AINPUT_EVENT_TYPE_MOTION){
+				event.eventTime = AMotionEvent_getEventTime(aev);
 				int evSource = AInputEvent_getSource(aev);
+				
 				if (evSource & AINPUT_SOURCE_CLASS_POINTER){
-					std::vector<TouchInfo> touches;
+					action = AMotionEvent_getAction(aev);
 					int count = AMotionEvent_getPointerCount(aev);
-					for (int i = 0; i <count; i++){
-						TouchInfo ti;
-						ti.position = Vector2(AMotionEvent_getX(aev,i), AMotionEvent_getY(aev,i));
-						if(evSource & AINPUT_SOURCE_TOUCHSCREEN){
-							ti.type = TouchInfo::TYPE_TOUCH;
-						} else {
-							ti.type = TouchInfo::TYPE_PEN;
+					
+					if (action == AMOTION_EVENT_ACTION_MOVE){
+						AndroidEvent hEvent;
+						int history = AMotionEvent_getHistorySize(aev);
+						
+						for (int j = 0; j<history; j++){
+							hEvent = AndroidEvent();
+							hEvent.eventTime = AMotionEvent_getHistoricalEventTime(aev, j);
+							hEvent.eventGroup = AndroidEvent::INPUT_EVENT;
+							
+							std::vector<TouchInfo> touches;
+							
+							for (int i = 0; i <count; i++){
+								TouchInfo ti;
+								ti.position = Vector2(AMotionEvent_getHistoricalX(aev,i,j), AMotionEvent_getHistoricalY(aev,i,j));
+								if(evSource & AINPUT_SOURCE_TOUCHSCREEN){
+									ti.type = TouchInfo::TYPE_TOUCH;
+								} else {
+									ti.type = TouchInfo::TYPE_PEN;
+								}
+								ti.id = AMotionEvent_getPointerId(aev, i);
+								if(ti.id == (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) || AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT){
+									hEvent.touch = ti;
+								}
+								touches.push_back(ti);
+							}
+							hEvent.eventCode = InputEvent::EVENT_TOUCHES_MOVED;
+							hEvent.touches = touches;
+							
+							core->handleSystemEvent(hEvent);
+						}
+					} else {
+						std::vector<TouchInfo> touches;
+						for (int i = 0; i <count; i++){
+							TouchInfo ti;
+							ti.position = Vector2(AMotionEvent_getX(aev,i), AMotionEvent_getY(aev,i));
+							if(evSource & AINPUT_SOURCE_TOUCHSCREEN){
+								ti.type = TouchInfo::TYPE_TOUCH;
+							} else {
+								ti.type = TouchInfo::TYPE_PEN;
+							}
+							ti.id = AMotionEvent_getPointerId(aev, i);
+							if(ti.id == (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) || AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT){
+								event.touch = ti;
+							}
+							touches.push_back(ti);
 						}
-						ti.id = AMotionEvent_getPointerId(aev, i);
 						
-						touches.push_back(ti);
-					}
-					event.touches = touches;
-					
-					action = AMotionEvent_getAction(aev);
-					if (action == AMOTION_EVENT_ACTION_UP){
-						event.eventCode = InputEvent::EVENT_TOUCHES_ENDED;
-						event.touch = touches[0];
-						core->handleSystemEvent(event);
-					} else if (action == AMOTION_EVENT_ACTION_DOWN){
-						event.eventCode = InputEvent::EVENT_TOUCHES_BEGAN;
-						event.touch = touches[0];
-						core->handleSystemEvent(event);
-					} else if (action == AMOTION_EVENT_ACTION_MOVE){
-						event.eventCode = InputEvent::EVENT_TOUCHES_MOVED;
-						event.touch = touches[action | AMOTION_EVENT_ACTION_POINTER_INDEX_MASK];
-						core->handleSystemEvent(event);
-					} else if (action == AMOTION_EVENT_ACTION_POINTER_DOWN){
-						event.eventCode = InputEvent::EVENT_TOUCHES_BEGAN;
-						event.touch = touches[action | AMOTION_EVENT_ACTION_POINTER_INDEX_MASK];
-						core->handleSystemEvent(event);
-					} else if (action == AMOTION_EVENT_ACTION_POINTER_UP){
-						event.eventCode = InputEvent::EVENT_TOUCHES_ENDED;
-						event.touch = touches[action | AMOTION_EVENT_ACTION_POINTER_INDEX_MASK];
+						if (action == AMOTION_EVENT_ACTION_UP){
+							event.eventCode = InputEvent::EVENT_TOUCHES_ENDED;
+							event.touch = touches[0];
+						} else if (action == AMOTION_EVENT_ACTION_DOWN){
+							event.eventCode = InputEvent::EVENT_TOUCHES_BEGAN;
+							event.touch = touches[0];
+						} else if (action == AMOTION_EVENT_ACTION_POINTER_DOWN){
+							event.eventCode = InputEvent::EVENT_TOUCHES_BEGAN;
+						} else if (action == AMOTION_EVENT_ACTION_POINTER_UP){
+							event.eventCode = InputEvent::EVENT_TOUCHES_ENDED;
+						}
 						core->handleSystemEvent(event);
 					}
-					
 				} else if (evSource & AINPUT_SOURCE_CLASS_POSITION){
 					
 				}
 			}
+			AInputQueue_finishEvent(native_input, aev, 1);
 		}
 	}
 }

部分文件因为文件数量过多而无法显示