Daniele Bartolini 11 лет назад
Родитель
Сommit
aa2d8ec7c2

+ 3 - 3
engine/Android.mk

@@ -96,7 +96,7 @@ PhysX_libraries :=\
 ###############################################################################
 include $(CLEAR_VARS)
 
-LOCAL_MODULE    := crown
+LOCAL_MODULE := crown
 LOCAL_SRC_FILES :=\
 \
 	audio/backend/SLESSoundWorld.cpp\
@@ -251,8 +251,6 @@ LOCAL_C_INCLUDES	:=\
 	$(LOCAL_PATH)/third/ARMv7/physx/include/vehicle\
 	
 LOCAL_CPPFLAGS :=\
-	-fno-rtti\
-	-fno-exceptions 
 	-std=c++03\
 	-ansi\
 	-Wall\
@@ -264,6 +262,8 @@ LOCAL_CPPFLAGS :=\
 	-Wno-unknown-pragmas\
 	-Wno-format\
 	-Wno-unused-but-set-variable\
+	-fno-rtti\
+	-fno-exceptions\
 
 LOCAL_LDLIBS := -L$(LOCAL_PATH) -Wl,--start-group $(addprefix -l, $(PhysX_libraries)) -Wl,--end-group -llog -landroid -lEGL -lGLESv2 -lz -lOpenSLES
 LOCAL_SHARED_LIBRARIES := luajit-5.1

+ 152 - 114
engine/os/android/AndroidDevice.cpp

@@ -25,6 +25,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include <jni.h>
+#include <android/sensor.h>
+#include <android_native_app_glue.h>
 #include "Allocator.h"
 #include "Device.h"
 #include "Log.h"
@@ -36,6 +38,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
+ANativeWindow* g_android_window;
+AAssetManager* g_android_asset_manager;
+
 class AndroidDevice : public Device
 {
 public:
@@ -67,17 +72,36 @@ public:
 		// Do nothing
 	}
 
+	void run(struct android_app* app)
+	{
+		app->userData = this;
+		app->onAppCmd = crown::AndroidDevice::on_app_cmd;
+		app->onInputEvent = crown::AndroidDevice::on_input_event;
+		g_android_asset_manager = app->activity->assetManager;
+
+		while (app->destroyRequested == 0)
+		{
+			int32_t num;
+			android_poll_source* source;
+			/*int32_t id =*/ ALooper_pollAll(-1, NULL, &num, (void**)&source);
+
+			if (NULL != source)
+			{
+				source->process(app, source);
+			}
+		}
+
+		m_game_thread.stop();
+	}
+
 	//-----------------------------------------------------------------------------
 	int32_t run(int, char**)
 	{
-		m_game_thread.start(main_loop, (void*)this);
-
-		//while (true) {}
 		return 0;
 	}
 
 	//-----------------------------------------------------------------------------
-	int32_t loop()
+	void loop()
 	{
 		#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
 			m_console = CE_NEW(default_allocator(), ConsoleServer)();
@@ -86,6 +110,11 @@ public:
 
 		Device::init();
 
+		// Push metrics here since Android does not trigger APP_CMD_WINDOW_RESIZED
+		const int32_t width = ANativeWindow_getWidth(g_android_window);
+		const int32_t height = ANativeWindow_getHeight(g_android_window);
+		m_queue.push_metrics_event(0, 0, width, height);
+
 		while (is_running() && !process_events())
 		{
 			#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
@@ -103,9 +132,6 @@ public:
 			m_console->shutdown();
 			CE_DELETE(default_allocator(), m_console);
 		#endif
-
-		exit(0);
-		return 0; // Just to not get a warning
 	}
 
 	//-----------------------------------------------------------------------------
@@ -146,8 +172,8 @@ public:
 				case OsEvent::METRICS:
 				{
 					const OsMetricsEvent& ev = event.metrics;
-					m_window->m_x = 0;
-					m_window->m_y = 0;
+					m_window->m_x = ev.x;
+					m_window->m_y = ev.y;
 					m_window->m_width = ev.width;
 					m_window->m_height = ev.height;
 					break;
@@ -178,137 +204,149 @@ public:
 	}
 
 	//-----------------------------------------------------------------------------
-	void push_keyboard_event(uint32_t modifier, KeyboardButton::Enum b, bool pressed)
-	{
-		m_queue.push_keyboard_event(modifier, b, pressed);
-	}
-
-	//-----------------------------------------------------------------------------
-	void push_touch_event(uint16_t x, uint16_t y, uint8_t pointer_id)
-	{
-		m_queue.push_touch_event(x, y, pointer_id);
-	}
-
-	//-----------------------------------------------------------------------------
-	void push_touch_event(uint16_t x, uint16_t y, uint8_t pointer_id, bool pressed)
-	{
-		m_queue.push_touch_event(x, y, pointer_id, pressed);
-	}
-
-	void push_metrics_event(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
+	static void on_app_cmd(struct android_app* app, int32_t cmd)
 	{
-		m_queue.push_metrics_event(x, y, width, height);
+		((AndroidDevice*) app->userData)->process_command(app, cmd);
 	}
 
 	//-----------------------------------------------------------------------------
-	void push_pause_event()
+	void process_command(struct android_app* app, int32_t cmd)
 	{
-		m_queue.push_pause_event();
+		switch (cmd)
+		{
+			case APP_CMD_SAVE_STATE:
+			{
+				// // The system has asked us to save our current state.  Do so.
+				// engine->app->savedState = malloc(sizeof(struct saved_state));
+				// *((struct saved_state*)engine->app->savedState) = engine->state;
+				// engine->app->savedStateSize = sizeof(struct saved_state);
+				break;
+			}
+			case APP_CMD_INIT_WINDOW:
+			{
+				CE_ASSERT(app->window != NULL, "Android window is NULL");
+				g_android_window = app->window;
+				m_game_thread.start(main_loop, (void*)this);
+				break;
+			}
+			case APP_CMD_TERM_WINDOW:
+			{
+				// The window is being hidden or closed, clean it up.
+				break;
+			}
+			case APP_CMD_WINDOW_RESIZED:
+			{
+				// Not triggered by Android
+				break;
+			}
+			case APP_CMD_GAINED_FOCUS:
+			{
+				break;
+			}
+			case APP_CMD_LOST_FOCUS:
+			{
+				break;
+			}
+			case APP_CMD_DESTROY:
+			{
+				m_queue.push_exit_event(0);
+				break;
+			}
+		}
 	}
 
 	//-----------------------------------------------------------------------------
-	void push_resume_event()
+	static int32_t on_input_event(struct android_app* app, AInputEvent* event)
 	{
-		m_queue.push_resume_event();
+		return ((AndroidDevice*) app->userData)->process_input(app, event);
 	}
 
 	//-----------------------------------------------------------------------------
-	void push_exit_event(int32_t code)
+	int32_t process_input(struct android_app* app, AInputEvent* event)
 	{
-		m_queue.push_exit_event(code);
-	}
-
-private:
-
-	OsEventQueue m_queue;
-	OsThread m_game_thread;
-};
+		if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
+		{
+			const int32_t action = AMotionEvent_getAction(event);
+			const int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+			const int32_t pointerCount = AMotionEvent_getPointerCount(event);
 
-static AndroidDevice* g_engine;
-ANativeWindow* g_android_window;
+			const int32_t pointerId = AMotionEvent_getPointerId(event, pointerIndex);
+			const float x = AMotionEvent_getX(event, pointerIndex);
+			const float y = AMotionEvent_getY(event, pointerIndex);
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initCrown(JNIEnv* /*env*/, jobject /*obj*/)
-{
-	memory::init();
-	os::init_os();
+			const int32_t actionMasked = (action & AMOTION_EVENT_ACTION_MASK);
 
-	g_engine = CE_NEW(default_allocator(), AndroidDevice);
-	set_device(g_engine);
-}
-
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdownCrown(JNIEnv* /*env*/, jobject /*obj*/)
-{
-	CE_DELETE(default_allocator(), g_engine);
-	memory::shutdown();
-}
+			switch (actionMasked)
+			{	
+				case AMOTION_EVENT_ACTION_DOWN:
+				case AMOTION_EVENT_ACTION_POINTER_DOWN:
+				{
+					m_queue.push_touch_event((uint16_t) x, (uint16_t) y, (uint8_t) pointerId, true);
+					break;			
+				}
+				case AMOTION_EVENT_ACTION_UP:
+				case AMOTION_EVENT_ACTION_POINTER_UP:
+				{
+					m_queue.push_touch_event((uint16_t) x, (uint16_t) y, (uint8_t) pointerId, false);
+					break;
+				}
+				case AMOTION_EVENT_ACTION_OUTSIDE:
+				case AMOTION_EVENT_ACTION_CANCEL:
+				{
+					m_queue.push_touch_event((uint16_t) x, (uint16_t) y, (uint8_t) pointerId, false);
+					break;			
+				}
+				case AMOTION_EVENT_ACTION_MOVE:
+				{
+					for (int index = 0; index < pointerCount; index++)
+					{
+						const float xx = AMotionEvent_getX(event, index);
+						const float yy = AMotionEvent_getY(event, index);
+						const int32_t id = AMotionEvent_getPointerId(event, index);
+						m_queue.push_touch_event((uint16_t) xx, (uint16_t) yy, (uint8_t) id);
+					}
+					break;
+				}
+			}
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_run(JNIEnv* /*env*/, jobject /*obj*/)
-{
-	g_engine->run(0, NULL);
-}
+			return 1;
+		}
+		else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY)
+		{
+			const int32_t keycode = AKeyEvent_getKeyCode(event);
+			const int32_t keyaction = AKeyEvent_getAction(event);
 
-//-----------------------------------------------------------------------------
-extern "C" void Java_crown_android_CrownLib_acquireWindow(JNIEnv *env, jclass /*clazz*/, jobject surface)
-{
-    // Obtain a native window from a Java surface
-	CE_ASSERT(surface != 0, "Unable to get Android window");
-    g_android_window = ANativeWindow_fromSurface(env, surface);
-    ANativeWindow_acquire(g_android_window);
-}
+			if (keycode == AKEYCODE_BACK)
+			{
+				m_queue.push_keyboard_event(0, KeyboardButton::ESCAPE, keyaction == AKEY_EVENT_ACTION_DOWN ? true : false);
+			}
 
-//-----------------------------------------------------------------------------
-extern "C" void Java_crown_android_CrownLib_releaseWindow(JNIEnv *env, jclass /*clazz*/, jobject surface)
-{
-    ANativeWindow_release(g_android_window);
-}
+			return 1;
+		}
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushKeyboardEvent(JNIEnv * /*env*/, jobject /*obj*/, jint modifier, jint b, jint pressed)
-{
-	g_engine->push_keyboard_event(modifier, (KeyboardButton::Enum) b, pressed);
-}
+		return 0;
+	}
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushTouchEventMove(JNIEnv * /*env*/, jobject /*obj*/, jint pointer_id, jint x, jint y)
-{
-	g_engine->push_touch_event(x, y, pointer_id);
-}
+private:
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushTouchEventPointer(JNIEnv * /*env*/, jobject /*obj*/, jint pointer_id, jint x, jint y, jint pressed)
-{
-	g_engine->push_touch_event(x, y, pointer_id, pressed);
-}
+	OsEventQueue m_queue;
+	OsThread m_game_thread;
+};
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushAccelerometerEvent(JNIEnv * /*env*/, jobject /*obj*/, jint type, jfloat x, jfloat y, jfloat z)
-{
-}
+} // namespace crown
 
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushMetricsEvent(JNIEnv * /*env*/, jobject /*obj*/, jint x, jint y, jint width, jint height)
+void android_main(struct android_app* app)
 {
-	g_engine->push_metrics_event(x, y, width, height);
-}
+	// Make sure glue isn't stripped.
+	app_dummy();
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushPauseEvent(JNIEnv * /*env*/, jobject /*obj*/)
-{
-	g_engine->push_pause_event();
-}
+	crown::memory::init();
+	crown::os::init_os();
+	crown::AndroidDevice* engine = CE_NEW(crown::default_allocator(), crown::AndroidDevice)();
+	crown::set_device(engine);
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushResumeEvent(JNIEnv * /*env*/, jobject /*obj*/)
-{
-	g_engine->push_resume_event();
-}
+	engine->run(app);
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushExitEvent(JNIEnv * /*env*/, jobject /*obj*/, jint code)
-{
-	g_engine->push_exit_event(code);
+	CE_DELETE(crown::default_allocator(), engine);
+	crown::memory::shutdown();
 }
-
-} // namespace crown

+ 22 - 20
engine/os/android/AndroidManifest.xml

@@ -1,24 +1,26 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-      package="crown.android"
-      android:versionCode="1"
-      android:versionName="1.0">
-    <uses-sdk
-        android:minSdkVersion="9"/>
+			package="crown.android"
+			android:versionCode="1"
+			android:versionName="1.0">
+		<uses-sdk android:minSdkVersion="9"/>
 
-    <uses-permission android:name="android.permission.INTERNET"/>
-    <uses-permission android:name="android.permission.SET_DEBUG_APP"/>
-    
-    <application android:label="Crown" >
-        <activity android:name="CrownActivity"
-                  android:label="Crown"
-				  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
-				  android:screenOrientation="landscape" 
-				  android:configChanges="orientation|keyboardHidden">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
+		<uses-permission android:name="android.permission.INTERNET"/>
+		<uses-permission android:name="android.permission.SET_DEBUG_APP"/>
+		
+		<application android:label="Crown" android:hasCode="true">
+				<activity android:name=".CrownActivity"
+									android:label="Crown"
+									android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
+									android:screenOrientation="landscape" 
+									android:configChanges="orientation|keyboardHidden">
+						<!-- Tell NativeActivity the name of our .so -->
+						<meta-data android:name="android.app.lib_name"
+												android:value="crown" />
+						<intent-filter>
+								<action android:name="android.intent.action.MAIN" />
+								<category android:name="android.intent.category.LAUNCHER" />
+						</intent-filter>
+				</activity>
+		</application>
 </manifest> 

+ 6 - 11
engine/os/android/ApkFile.cpp

@@ -24,12 +24,16 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include <android/asset_manager_jni.h>
 #include "ApkFile.h"
 #include "Assert.h"
 #include "Macros.h"
+#include "Log.h"
+#include <android/asset_manager.h>
 
-static AAssetManager* g_android_asset_manager = NULL;
+namespace crown
+{
+
+extern AAssetManager* g_android_asset_manager;
 
 //-----------------------------------------------------------------------------
 AAssetManager* get_android_asset_manager()
@@ -37,15 +41,6 @@ AAssetManager* get_android_asset_manager()
 	return g_android_asset_manager;
 }
 
-//-----------------------------------------------------------------------------
-extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initAssetManager(JNIEnv* env, jobject obj, jobject assetManager)
-{
-	g_android_asset_manager = AAssetManager_fromJava(env, assetManager);
-}
-
-namespace crown
-{
-
 //-----------------------------------------------------------------------------
 ApkFile::ApkFile(const char* path)
 	: File(FOM_READ), m_asset(NULL)

+ 18 - 17
engine/os/android/ApkFile.h

@@ -27,6 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "File.h"
+#include <android/asset_manager.h>
 
 namespace crown
 {
@@ -36,54 +37,54 @@ class ApkFile : public File
 public:
 
 	/// Opens the given @a filename.
-				ApkFile(const char* filename);
-				~ApkFile();
+	ApkFile(const char* filename);
+	~ApkFile();
 
 	/// @copydoc File::seek()
-	void		seek(size_t position);
+	void seek(size_t position);
 
 	/// @copydoc File::seek_to_end()
-	void		seek_to_end();
+	void seek_to_end();
 
 	/// @copydoc File::skip()
-	void		skip(size_t bytes);
+	void skip(size_t bytes);
 
 	/// @copydoc File::read()
-	void		read(void* buffer, size_t size);
+	void read(void* buffer, size_t size);
 
 	/// @copydoc File::write()
-	void		write(const void* buffer, size_t size);
+	void write(const void* buffer, size_t size);
 
 	/// @copydoc File::copy_to()
-	bool		copy_to(File& file, size_t size = 0);
+	bool copy_to(File& file, size_t size = 0);
 
 	/// @copydoc File::flush()
-	void		flush();
+	void flush();
 
 	/// @copydoc File::is_valid()
-	bool		is_valid();
+	bool is_valid();
 
 	/// @copydoc File::end_of_file()
-	bool		end_of_file();
+	bool end_of_file();
 
 	/// @copydoc File::size()
-	size_t		size();
+	size_t size();
 
 	/// @copydoc File::position()
-	size_t		position();
+	size_t position();
 
 	/// @copydoc File::can_read()
-	bool		can_read() const;
+	bool can_read() const;
 
 	/// @copydoc File::can_write()
-	bool		can_write() const;
+	bool can_write() const;
 
 	/// @copydoc File::can_seek()
-	bool		can_seek() const;
+	bool can_seek() const;
 
 private:
 
-	AAsset*		m_asset;
+	AAsset* m_asset;
 };
 
 } // namespace crown

+ 2 - 2
engine/os/android/ApkFilesystem.cpp

@@ -30,11 +30,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "ApkFile.h"
 #include "OS.h"
 
-extern AAssetManager* get_android_asset_manager();
-
 namespace crown
 {
 
+extern AAssetManager* get_android_asset_manager();
+
 //-----------------------------------------------------------------------------
 ApkFilesystem::ApkFilesystem()
 {

+ 22 - 22
engine/os/android/OsWindow.h

@@ -38,63 +38,63 @@ class OsWindow
 public:
 
 	/// Stub method, does nothing under Android.
-					OsWindow();
-					~OsWindow();
+	OsWindow();
+	~OsWindow();
 
 	/// Stub method, does nothing under Android.
-	void			show();
+	void show();
 
 	/// Stub method, does nothing under Android.
-	void			hide();
+	void hide();
 
 	/// Returns the size in pixel of the window.
-	void			get_size(uint32_t& width, uint32_t& height);
+	void get_size(uint32_t& width, uint32_t& height);
 
 	/// Returns always (0, 0) under Android.
-	void			get_position(uint32_t& x, uint32_t& y);
+	void get_position(uint32_t& x, uint32_t& y);
 
 	/// Stub method, does nothing under Android.
-	void			resize(uint32_t width, uint32_t height);
+	void resize(uint32_t width, uint32_t height);
 
 	/// Stub method, does nothing under Android.
-	void			move(uint32_t x, uint32_t y);
+	void move(uint32_t x, uint32_t y);
 
 	/// Stub method, does nothing under Android.	
-	void			minimize();
+	void minimize();
 
 	/// Stub method, does nothing under Android.
-	void			restore();
+	void restore();
 
 	/// Returns always false.
-	bool			is_resizable() const;
+	bool is_resizable() const;
 
 	/// Stub method, does nothing under Android.	
-	void			set_resizable(bool resizeable);
+	void set_resizable(bool resizeable);
 
 	/// Stub method, does nothing under Android.
-	void			show_cursor(bool show);
+	void show_cursor(bool show);
 
 	/// Stub method, does nothing under Android.
-	void			get_cursor_xy(int32_t& x, int32_t& y);
+	void get_cursor_xy(int32_t& x, int32_t& y);
 
 	/// Stub method, does nothing under Android.
-	void			set_cursor_xy(int32_t x, int32_t y);
+	void set_cursor_xy(int32_t x, int32_t y);
 
 	/// Returns always NULL under Android.
-	char*			title();
+	char* title();
 
 	/// Stub method, does nothing under Android.
-	void			set_title(const char* title);
+	void set_title(const char* title);
 
 	/// Stub method, does nothing under Android.
-	void			frame();
+	void frame();
 
 public:
 
-	uint32_t		m_x;
-	uint32_t		m_y;
-	uint32_t		m_width;
-	uint32_t		m_height;
+	uint32_t m_x;
+	uint32_t m_y;
+	uint32_t m_width;
+	uint32_t m_height;
 };
 
 } // namespace crown

+ 17 - 124
engine/os/android/java/CrownActivity.java

@@ -26,143 +26,36 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 package crown.android;
 
-import android.app.Activity;
+import android.app.NativeActivity;
 import android.os.Bundle;
 import android.util.Log;
-import android.view.WindowManager;
-import android.view.MotionEvent;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorManager;
-import android.content.Context;
-import android.widget.Toast;
-import android.content.res.AssetManager;
-import android.view.View;
-import android.view.Surface;
-import android.view.SurfaceView;
-import android.view.SurfaceHolder;
-import android.view.KeyEvent;
 
-public class CrownActivity extends Activity
+public class CrownActivity extends NativeActivity
 {
-	// Debug
-	public static String TAG = "crown";
-
-	// Resource attributes
-    static AssetManager 		mAssetManager;
-	private CrownSurfaceView 	mView;
-
-
-	//-----------------------------------------------------------------------------
-    public void onCreate(Bundle savedInstanceState)
-    {
-        super.onCreate(savedInstanceState);
-
-        // Initializes low-level systems (memory, os etc.)
-        CrownLib.initCrown();
-
-		// init AssetManager
-		mAssetManager = getAssets();
-		CrownLib.initAssetManager(mAssetManager);
-
-		// init Native Window
-		mView = new CrownSurfaceView(this);
-        setContentView(mView);
-
-		Log.i(TAG, "Crown Activity created");
-    }
-
-	//-----------------------------------------------------------------------------
-	public void onResume()
+	static 
 	{
-		super.onResume();
-		CrownLib.pushResumeEvent();
-		Log.i(TAG, "Crown Activity resumed");
+		System.loadLibrary("luajit-5.1");
+		System.loadLibrary("crown");
 	}
 
-	//-----------------------------------------------------------------------------
-	public void onPause()
-	{
-		super.onPause();
-		CrownLib.pushPauseEvent();
-		Log.i(TAG, "Crown Activity paused");
-	}
-
-	//-----------------------------------------------------------------------------
-	public void onDestroy()
-	{
-		super.onDestroy();
-		CrownLib.pushExitEvent(0);
-		CrownLib.releaseWindow();
-		CrownLib.shutdownCrown();
-		Log.i(TAG, "Crown Activity destroyed");
-	}
+	public static String TAG = "crown";
 
-	//-----------------------------------------------------------------------------
-	@Override
-	public boolean onKeyDown(int keyCode, KeyEvent event)
-	{
-		if ((keyCode == KeyEvent.KEYCODE_BACK))
-		{
-			CrownLib.pushKeyboardEvent(0, 0x1B, 1);
-		}
-		return super.onKeyDown(keyCode, event);
-	}
+	CrownActivity _activity;
 
-	//-----------------------------------------------------------------------------
 	@Override
-	public boolean onKeyUp(int keyCode, KeyEvent event)
+	public void onCreate(Bundle savedInstanceState)
 	{
-		if ((keyCode == KeyEvent.KEYCODE_BACK))
-		{
-			CrownLib.pushKeyboardEvent(0, 0x1B, 0);
-		}
-		return super.onKeyUp(keyCode, event);
-	}
+		super.onCreate(savedInstanceState);
 
-	//-----------------------------------------------------------------------------
-	public boolean onTouchEvent(MotionEvent event)
-	{
-		final int pointerIndex = event.getActionIndex();
-		final int pointerCount = event.getPointerCount();
+		_activity = this;
 
-		final int pointerId = event.getPointerId(pointerIndex);
-		final float x = event.getX(pointerIndex);
-		final float y = event.getY(pointerIndex);
-
-		final int actionMasked = event.getActionMasked();
-
-		switch (actionMasked) 
-		{	
-			case MotionEvent.ACTION_DOWN:
-			case MotionEvent.ACTION_POINTER_DOWN:
-			{
-				CrownLib.pushTouchEventPointer(pointerId, (int) x, (int) y, 1);
-				break;			
-			}
-			case MotionEvent.ACTION_UP:
-			case MotionEvent.ACTION_POINTER_UP:
-			{
-				CrownLib.pushTouchEventPointer(pointerId, (int) x, (int) y, 0);
-				break;
-			}
-			case MotionEvent.ACTION_OUTSIDE:
-			case MotionEvent.ACTION_CANCEL:
-			{
-				CrownLib.pushTouchEventPointer(pointerId, (int)x, (int)y, 0);
-				break;			
-			}
-			case MotionEvent.ACTION_MOVE:
-			{
-				for (int index = 0; index < pointerCount; index++)
-				{
-					CrownLib.pushTouchEventMove(event.getPointerId(index), (int)event.getX(index), (int)event.getY(index));
-				}
-				break;
-			}
-		}
+		// Init additional stuff here (ads, etc.)
+    }
 
-        return super.onTouchEvent(event);
+	@Override
+	public void onDestroy()
+	{
+		// Destroy additional stuff here (ads, etc)
+		super.onDestroy();
 	}
 }

+ 0 - 62
engine/os/android/java/CrownLib.java

@@ -1,62 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-package crown.android;
-
-import android.content.res.AssetManager;
-import android.view.Surface;
-
-public class CrownLib
-{
-	static 
-	{
-		System.loadLibrary("luajit-5.1");
-		System.loadLibrary("crown");
-	}
-
-	// Crown functions
-	public static native void		initCrown();
-	public static native void		shutdownCrown();
-
-	public static native int		run();
-
-	// AssetManager functions
-	public static native void 		initAssetManager(AssetManager assetManager);
-
-	// Window functions
-	public static native void		acquireWindow(Surface window);
-	public static native void		releaseWindow();
-
-	// Os events
-	public static native void		pushKeyboardEvent(int modifier, int b, int pressed);
-	public static native void 		pushTouchEventMove(int pointer_id, int x, int y);
-	public static native void		pushTouchEventPointer(int pointer_id, int x, int y, int pressed);
-	public static native void		pushMetricsEvent(int x, int y, int width, int height);
-	public static native void 		pushAccelerometerEvent(int type, float x, float y, float z);
-	public static native void		pushPauseEvent();
-	public static native void		pushResumeEvent();
-	public static native void		pushExitEvent(int code);
-}

+ 0 - 71
engine/os/android/java/CrownSurfaceView.java

@@ -1,71 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-package crown.android;
-
-import android.content.Context;
-import android.view.Surface;
-import android.view.SurfaceView;
-import android.view.SurfaceHolder;
-import android.graphics.PixelFormat;
-import android.util.Log;
-
-public class CrownSurfaceView extends SurfaceView implements SurfaceHolder.Callback
-{
-	private final String TAG = "crown";
-
-	//-----------------------------------------------------------------------------
-	public CrownSurfaceView(Context context)
-	{
-		super(context);
-		getHolder().addCallback(this);
-		setFocusable(true);
-	}
-
-	//-----------------------------------------------------------------------------
-	@Override
-	public void surfaceCreated(SurfaceHolder holder) 
-	{
-		Log.d(TAG, "Crown Surface created");
-		CrownLib.acquireWindow(holder.getSurface());
-		CrownLib.run();
-	}
-
-	//-----------------------------------------------------------------------------
-	@Override
-	public void surfaceDestroyed(SurfaceHolder holder) 
-	{
-		Log.d(TAG, "Crown Surface destroyed");
-	}
-
-	//-----------------------------------------------------------------------------
-	@Override
-	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) 
-	{
-		CrownLib.pushMetricsEvent(0, 0, width, height);
-		Log.d(TAG, "Crown Surface changed");
-	}
-}

+ 1 - 0
utils/crown-android.rb

@@ -85,6 +85,7 @@ $config_h =
 
 $application_mk =
 "
+APP_PLATFORM := android-10
 APP_STL := gnustl_static
 APP_ABI := armeabi-v7a
 "