Explorar o código

Android native files updated

mikymod %!s(int64=12) %!d(string=hai) anos
pai
achega
298d58c70b

+ 22 - 12
src/os/android/AndroidDevice.cpp

@@ -4,24 +4,34 @@
 namespace crown
 namespace crown
 {
 {
 
 
-extern "C" 
-{
-	//!< Device init() jni bind
-	JNIEXPORT void JNICALL Java_crown_android_CrownLib_init(JNIEnv* env, jobject obj);
-	//!< Device shutdown() jni bind
-	JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdown(JNIEnv* env, jobject obj);
-};
-
-//------------------------------------------------------------------------------------
-JNIEXPORT void JNICALL Java_crown_android_CrownLib_init(JNIEnv* env, jobject obj)
+//-----------------------------------------------------------------------------
+extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_init(JNIEnv* env, jobject obj)
 {
 {
 	device()->init(0, NULL);
 	device()->init(0, NULL);
 }
 }
 
 
-//------------------------------------------------------------------------------------
-JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdown(JNIEnv* env, jobject obj)
+//-----------------------------------------------------------------------------
+extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdown(JNIEnv* env, jobject obj)
 {
 {
 	device()->shutdown();
 	device()->shutdown();
 }
 }
 
 
+//-----------------------------------------------------------------------------
+extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_frame(JNIEnv* env, jobject obj)
+{
+	device()->frame();
+}
+
+//-----------------------------------------------------------------------------
+extern "C" JNIEXPORT bool JNICALL Java_crown_android_CrownLib_isInit(JNIEnv* env, jobject obj)
+{
+	return device()->is_init();
+}
+
+//-----------------------------------------------------------------------------
+extern "C" JNIEXPORT bool JNICALL Java_crown_android_CrownLib_isRunning(JNIEnv* env, jobject obj)
+{
+	return device()->is_running();
+}
+
 } // namespace crown
 } // namespace crown

+ 53 - 56
src/os/android/AndroidOS.cpp

@@ -34,10 +34,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <sys/time.h>
 #include <sys/time.h>
 #include <time.h>
 #include <time.h>
 #include <android/asset_manager_jni.h>
 #include <android/asset_manager_jni.h>
-#include <pthread.h>
 
 
 #include "OS.h"
 #include "OS.h"
 #include "AndroidOS.h"
 #include "AndroidOS.h"
+#include "OsWindow.h"
 #include "Log.h"
 #include "Log.h"
 
 
 namespace crown
 namespace crown
@@ -45,13 +45,6 @@ namespace crown
 namespace os
 namespace os
 {
 {
 
 
-extern "C" 
-{
-	// This is sadly necessary in order to get the asset manager from java...
-    JNIEXPORT void JNICALL Java_crown_android_CrownLib_initAssetManager(JNIEnv* env, jobject obj, jobject assetManager);
-	JNIEXPORT void JNICALL Java_crown_android_CrownLib_setRenderWindowMetrics(JNIEnv* env, jobject obj, jint width, jint height);
-};
-
 static timespec			base_time;
 static timespec			base_time;
 static AAssetManager*	asset_manager = NULL;
 static AAssetManager*	asset_manager = NULL;
 static uint32_t			window_width;
 static uint32_t			window_width;
@@ -97,6 +90,38 @@ void log_info(const char* string, va_list arg)
 	__android_log_vprint(ANDROID_LOG_INFO, "crown", string, arg);
 	__android_log_vprint(ANDROID_LOG_INFO, "crown", string, arg);
 }
 }
 
 
+//-----------------------------------------------------------------------------
+bool is_root_path(const char* path)
+{
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+
+	if (string::strlen(path) == 1)
+	{
+		if (path[0] == PATH_SEPARATOR)
+		{
+			return true;
+		}
+	}
+
+	return false;
+}
+
+//-----------------------------------------------------------------------------
+bool is_absolute_path(const char* path)
+{
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+
+	if (string::strlen(path) > 0)
+	{
+		if (path[0] == PATH_SEPARATOR)
+		{
+			return true;
+		}
+	}
+
+	return false;
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 bool exists(const char* path)
 bool exists(const char* path)
 {
 {
@@ -188,29 +213,6 @@ const char* get_env(const char* env)
 	return envDevel;
 	return envDevel;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-// bool ls(const char* path, List<Str>& fileList)
-// {
-// 	DIR *dir;
-// 	struct dirent *ent;
-
-// 	dir = opendir(path);
-
-// 	if (dir == NULL)
-// 	{
-// 		return false;
-// 	}
-
-// 	while ((ent = readdir (dir)) != NULL)
-// 	{
-// 		fileList.push_back(Str(ent->d_name));
-// 	}
-
-// 	closedir (dir);
-
-// 	return true;
-// }
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void init_os()
 void init_os()
 {
 {
@@ -243,43 +245,38 @@ AAssetManager* get_android_asset_manager()
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-bool create_render_window(uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool fullscreen)
+extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initAssetManager(JNIEnv* env, jobject obj, jobject assetManager)
 {
 {
-	return true;
+	asset_manager = AAssetManager_fromJava(env, assetManager);
 }
 }
 
 
-//-----------------------------------------------------------------------------
-bool destroy_render_window()
-{
-	return true;
-}
+} // namespace os
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void get_render_window_metrics(uint32_t& width, uint32_t& height)
-{
-	width = window_width;
-	height = window_height;
-}
+extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushIntEvent(JNIEnv * env, jobject obj, jint type, jint a, jint b, jint c, jint d)
+{	
+	OsEventParameter values[4];
 
 
-//-----------------------------------------------------------------------------
-void swap_buffers()
-{
-	// not necessary
-}
+	values[0].int_value = a;
+	values[1].int_value = b;
+	values[2].int_value = c;
+	values[3].int_value = d;
 
 
-//-----------------------------------------------------------------------------
-JNIEXPORT void JNICALL Java_crown_android_CrownLib_initAssetManager(JNIEnv* env, jobject obj, jobject assetManager)
-{
-	asset_manager = AAssetManager_fromJava(env, assetManager);
+	push_event((OsEventType)type, values[0], values[1], values[2], values[3]);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-JNIEXPORT void JNICALL Java_crown_android_CrownLib_setRenderWindowMetrics(JNIEnv* env, jobject obj, jint width, jint height)
+extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushFloatEvent(JNIEnv * env, jobject obj, jint type, jfloat a, jfloat b, jfloat c, jfloat d)
 {
 {
-	window_width = width;
-	window_height = height;
+	OsEventParameter values[4];
+
+	values[0].float_value = a;
+	values[1].float_value = b;
+	values[2].float_value = c;
+	values[3].float_value = d;
+
+	push_event((OsEventType)type, values[0], values[1], values[2], values[3]);
 }
 }
 
 
-} // namespace os
 } // namespace crown
 } // namespace crown
 
 

+ 2 - 1
src/os/android/AndroidOS.h

@@ -23,6 +23,7 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
+#pragma once
 
 
 #include <jni.h>
 #include <jni.h>
 #include <sys/types.h>
 #include <sys/types.h>
@@ -34,7 +35,7 @@ namespace os
 {
 {
 
 
 // Accessor to the android asset manager
 // Accessor to the android asset manager
-AAssetManager* get_android_asset_manager();
+AAssetManager* 	get_android_asset_manager();
 
 
 } // namespace crown
 } // namespace crown
 } // namespace os
 } // namespace os

+ 3 - 4
src/os/android/OsFile.cpp

@@ -33,15 +33,14 @@ namespace crown
 {
 {
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-OsFile::OsFile(const char* path, FileOpenMode mode) :
-	m_asset(NULL),
+OsFile::OsFile(const char* path, FileOpenMode mode)
 {
 {
 	// Android assets are always read-only
 	// Android assets are always read-only
 	(void) mode;
 	(void) mode;
-	m_mode = SOM_READ;
+	m_mode = FOM_READ;
 	m_asset = AAssetManager_open(os::get_android_asset_manager(), path, AASSET_MODE_RANDOM);
 	m_asset = AAssetManager_open(os::get_android_asset_manager(), path, AASSET_MODE_RANDOM);
 
 
-	CE_ASSERT(m_asset != NULL, "Unable to open file: %s", path)
+	CE_ASSERT(m_asset != NULL, "Unable to open file: %s", path);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 143 - 0
src/os/android/OsWindow.cpp

@@ -0,0 +1,143 @@
+/*
+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.
+*/
+
+#include <android/native_window_jni.h>
+
+#include "OsWindow.h"
+#include "GLContext.h"
+#include "Assert.h"
+
+namespace crown
+{
+
+static ANativeWindow* window = NULL;
+
+//-----------------------------------------------------------------------------
+OsWindow::OsWindow(uint32_t width, uint32_t height) :
+	m_window(NULL),
+	m_width(0),
+	m_height(0),
+	m_x(0),
+	m_y(0)
+{
+	m_window = window;
+
+	m_width = ANativeWindow_getWidth(m_window);
+	m_height = ANativeWindow_getHeight(m_window);
+
+    set_android_window(m_window);
+}
+
+//-----------------------------------------------------------------------------
+OsWindow::~OsWindow()
+{
+	if (m_window)
+	{
+		ANativeWindow_release(m_window);
+	}
+
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::show()
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::hide()
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::get_size(uint32_t& width, uint32_t& height)
+{
+	width = m_width;
+	height = m_height;
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::get_position(uint32_t& x, uint32_t& y)
+{
+	x = m_x;
+	y = m_y;
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::resize(uint32_t width, uint32_t height)
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::move(uint32_t x, uint32_t y)
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::show_cursor()
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::hide_cursor()
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::get_cursor_xy(int32_t& x, int32_t& y)
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::set_cursor_xy(int32_t x, int32_t y)
+{
+}
+
+//-----------------------------------------------------------------------------
+char* OsWindow::title()
+{
+	return NULL;
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::set_title(const char* title)
+{
+}
+
+//-----------------------------------------------------------------------------
+void OsWindow::frame()
+{
+	// implemented on Java-side
+}
+
+//-----------------------------------------------------------------------------
+extern "C" void Java_crown_android_CrownLib_setWindow(JNIEnv *env, jclass clazz, jobject surface)
+{
+    // obtain a native window from a Java surface
+	CE_ASSERT(surface != 0, "Unable to get Android window");
+    window = ANativeWindow_fromSurface(env, surface);
+}
+
+} // namespace crown

+ 72 - 0
src/os/android/OsWindow.h

@@ -0,0 +1,72 @@
+/*
+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.
+*/
+
+#pragma once
+
+#include <sys/types.h>
+#include <android/native_window.h>
+
+namespace crown
+{
+
+class OsWindow
+{
+public:
+
+					OsWindow(uint32_t width, uint32_t height);
+					~OsWindow();
+
+	void			show();
+	void			hide();
+
+	void			get_size(uint32_t& width, uint32_t& height);
+	void			get_position(uint32_t& x, uint32_t& y);
+
+	void			resize(uint32_t width, uint32_t height);
+	void			move(uint32_t x, uint32_t y);
+
+	void			show_cursor();
+	void			hide_cursor();
+
+	void			get_cursor_xy(int32_t& x, int32_t& y);
+	void			set_cursor_xy(int32_t x, int32_t y);
+
+	char*			title();
+	void			set_title(const char* title);
+
+	void			frame();
+
+private:
+
+	ANativeWindow*	m_window;
+
+	uint32_t		m_x;
+	uint32_t		m_y;
+	uint32_t		m_width;
+	uint32_t		m_height;
+};
+
+} // namespace crown