Sfoglia il codice sorgente

Fix os stuff to work with android

Daniele Bartolini 12 anni fa
parent
commit
927185f64e

+ 6 - 3
android/jni/Android.mk

@@ -36,8 +36,6 @@ LOCAL_SRC_FILES :=\
 	core/streams/FileStream.cpp\
 	core/streams/MemoryStream.cpp\
 	core/streams/Stream.cpp\
-	core/threads/Thread.cpp\
-	core/threads/Mutex.cpp\
 \
 	input/EventDispatcher.cpp\
 	input/InputManager.cpp\
@@ -47,6 +45,11 @@ LOCAL_SRC_FILES :=\
 	os/android/AndroidInput.cpp\
 	os/android/AndroidDevice.cpp\
 	os/android/File.cpp\
+	os/posix/Thread.cpp\
+	os/posix/Mutex.cpp\
+	os/posix/Cond.cpp\
+	os/posix/TCPSocket.cpp\
+	os/posix/UDPSocket.cpp\
 \
 	Filesystem.cpp\
 \
@@ -102,4 +105,4 @@ LOCAL_C_INCLUDES	:=\
 LOCAL_CPPFLAGS	:= -g -fexceptions
 LOCAL_LDLIBS	:= -llog -landroid -lGLESv1_CM
 include $(BUILD_SHARED_LIBRARY)
-#(call import-module, android/native_app_glue)
+#(call import-module, android/native_app_glue)

+ 2 - 5
src/os/android/AndroidDevice.cpp

@@ -1,7 +1,6 @@
 #include <jni.h>
 #include "Device.h"
 
-
 namespace crown
 {
 
@@ -16,15 +15,13 @@ extern "C"
 //------------------------------------------------------------------------------------
 JNIEXPORT void JNICALL Java_crown_android_CrownLib_init(JNIEnv* env, jobject obj)
 {
-	Device* device = GetDevice();
-	device->Init(0, NULL);
+	device()->init(0, NULL);
 }
 
 //------------------------------------------------------------------------------------
 JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdown(JNIEnv* env, jobject obj)
 {
-	Device* device = GetDevice();
-	device->Shutdown();
+	device()->shutdown();
 }
 
 } // namespace crown

+ 0 - 67
src/os/android/AndroidOS.cpp

@@ -266,73 +266,6 @@ void swap_buffers()
 	// not necessary
 }
 
-//-----------------------------------------------------------------------------
-void thread_create(ThreadFunction f, void* params, OSThread& thread, const char* name)
-{
-	OSThread tid;
-	tid.name = name;
-
-	// Make thread joinable
-	pthread_attr_t attr;
-	pthread_attr_init(&attr);
-	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-
-	// Create thread
-	int rc = pthread_create(&tid.thread, &attr, f, (void*)params);
-
-	if (rc != 0)
-	{
-		os::printf("OS: ERROR: Unable to create the thread '%s' Error code: %d\n", name, rc);
-		exit(-1);
-	}
-
-	// Free memory
-	pthread_attr_destroy(&attr);
-
-	thread = tid;
-}
-
-//-----------------------------------------------------------------------------
-void thread_join(OSThread thread)
-{
-	pthread_join(thread.thread, NULL);
-}
-
-//-----------------------------------------------------------------------------
-void thread_detach(OSThread thread)
-{
-	pthread_detach(thread.thread);
-}
-
-//-----------------------------------------------------------------------------
-void mutex_create(OSMutex& mutex)
-{
-	OSMutex mut;
-
-	pthread_mutex_init(&mut.mutex, NULL);
-
-	mutex = mut;
-}
-
-//-----------------------------------------------------------------------------
-void mutex_destroy(OSMutex mutex)
-{
-	pthread_mutex_destroy(&mutex.mutex);
-}
-
-//-----------------------------------------------------------------------------
-void mutex_lock(OSMutex mutex)
-{
-	pthread_mutex_lock(&mutex.mutex);
-}
-
-//-----------------------------------------------------------------------------
-void mutex_unlock(OSMutex mutex)
-{
-	pthread_mutex_unlock(&mutex.mutex);
-}
-
-
 //-----------------------------------------------------------------------------
 JNIEXPORT void JNICALL Java_crown_android_CrownLib_initAssetManager(JNIEnv* env, jobject obj, jobject assetManager)
 {

+ 1 - 1
src/os/android/File.cpp

@@ -35,7 +35,7 @@ namespace crown
 
 //-----------------------------------------------------------------------------
 File::File() :
-	m_file_handle(NULL),
+	m_asset(NULL),
 	m_mode(SOM_READ)
 {
 }

+ 0 - 5
src/os/android/File.h

@@ -88,8 +88,3 @@ private:
 };
 
 } // namespace crown
-
-
-
-} // namespace crown
-

+ 1 - 1
src/os/posix/TCPSocket.cpp

@@ -89,7 +89,7 @@ bool TCPSocket::open(uint16_t port)
 	sockaddr_in client;
 	size_t client_length = sizeof(client);
 
-	int asd = accept(sd, (sockaddr*)&client, &client_length);
+	int asd = accept(sd, (sockaddr*)&client, (socklen_t*)&client_length);
 
 	if (asd < 0)
 	{