Forráskód Böngészése

fix Android according to recent changes

mikymod 12 éve
szülő
commit
c7b4d2ef71

+ 2 - 3
engine/Android.mk

@@ -62,15 +62,13 @@ LOCAL_SRC_FILES :=\
 \
 \
 	network/BitMessage.cpp\
 	network/BitMessage.cpp\
 \
 \
-	os/EventBuffer.cpp\
+	os/OS.cpp\
 	os/android/AndroidOS.cpp\
 	os/android/AndroidOS.cpp\
 	os/android/AndroidDevice.cpp\
 	os/android/AndroidDevice.cpp\
 	os/android/OsWindow.cpp\
 	os/android/OsWindow.cpp\
 	os/android/ApkFile.cpp\
 	os/android/ApkFile.cpp\
 	os/android/ApkFilesystem.cpp\
 	os/android/ApkFilesystem.cpp\
 	os/posix/OsFile.cpp\
 	os/posix/OsFile.cpp\
-	os/posix/Mutex.cpp\
-	os/posix/Cond.cpp\
 	os/posix/TCPSocket.cpp\
 	os/posix/TCPSocket.cpp\
 	os/posix/UDPSocket.cpp\
 	os/posix/UDPSocket.cpp\
 \
 \
@@ -108,6 +106,7 @@ LOCAL_SRC_FILES :=\
 	Device.cpp\
 	Device.cpp\
 	FPSSystem.cpp\
 	FPSSystem.cpp\
 	ConsoleServer.cpp\
 	ConsoleServer.cpp\
+	EventBuffer.cpp\
 \
 \
 
 
 LOCAL_C_INCLUDES	:=\
 LOCAL_C_INCLUDES	:=\

+ 0 - 16
engine/Device.cpp

@@ -425,11 +425,6 @@ void Device::pause()
 {
 {
 	m_is_paused = true;
 	m_is_paused = true;
 
 
-	while (!m_is_really_paused)
-	{
-		Log::i("Pausing...");
-	}
-
 	Log::d("Engine paused");
 	Log::d("Engine paused");
 }
 }
 
 
@@ -467,12 +462,6 @@ void Device::frame()
 	m_last_delta_time = (m_current_time - m_last_time) / 1000000.0f;
 	m_last_delta_time = (m_current_time - m_last_time) / 1000000.0f;
 	m_last_time = m_current_time;
 	m_last_time = m_current_time;
 
 
-	if (m_renderer_init_request)
-	{
-		m_renderer->init();
-		m_renderer_init_request = false;
-	}
-
 	if (!m_is_paused)
 	if (!m_is_paused)
 	{
 	{
 		m_resource_manager->poll_resource_loader();
 		m_resource_manager->poll_resource_loader();
@@ -489,11 +478,6 @@ void Device::frame()
 		m_renderer->frame();
 		m_renderer->frame();
 	}
 	}
 
 
-	if (m_is_paused)
-	{
-		m_is_really_paused = true;
-	}
-
 	m_frame_count++;
 	m_frame_count++;
 
 
 	os_event_buffer()->clear();
 	os_event_buffer()->clear();

+ 0 - 3
engine/Device.h

@@ -133,9 +133,6 @@ public:
 
 
 	ConsoleServer*			console_server();
 	ConsoleServer*			console_server();
 
 
-	// FixMe: Should be implemented throush OsEventBuffer and a renderer event
-	inline void				init_renderer() { m_renderer_init_request = true; }
-
 private:
 private:
 
 
 	void					init();
 	void					init();

+ 1 - 1
engine/os/android/AndroidDevice.cpp

@@ -91,7 +91,7 @@ extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_frame(JNIEnv* /*en
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initRenderer(JNIEnv* /*env*/, jobject /*obj*/)
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initRenderer(JNIEnv* /*env*/, jobject /*obj*/)
 {
 {
-	device()->init_renderer();
+	device()->renderer()->init();
 	Log::i("Renderer initialized");
 	Log::i("Renderer initialized");
 }
 }
 
 

+ 5 - 40
engine/os/android/java/CrownActivity.java

@@ -50,7 +50,6 @@ import crown.android.CrownEnum;
 */
 */
 public class CrownActivity extends Activity
 public class CrownActivity extends Activity
 {
 {
-
 	// Debug
 	// Debug
 	public static String TAG = "crown";
 	public static String TAG = "crown";
 
 
@@ -61,8 +60,8 @@ public class CrownActivity extends Activity
 	private CrownTouch 			mTouch;
 	private CrownTouch 			mTouch;
 	private CrownSensor			mSensor;
 	private CrownSensor			mSensor;
 
 
-	// Graphic attributes
-	static CrownSurfaceView		mWindow;
+	private CrownSurfaceView 	mView;
+
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
     public void onCreate(Bundle savedInstanceState)
     public void onCreate(Bundle savedInstanceState)
@@ -74,8 +73,8 @@ public class CrownActivity extends Activity
 		CrownLib.initAssetManager(mAssetManager);
 		CrownLib.initAssetManager(mAssetManager);
 
 
 		// init Native Window
 		// init Native Window
-        mWindow = new CrownSurfaceView(this);
-        setContentView(mWindow);
+		mView = new CrownSurfaceView(this);
+        setContentView(mView);
 
 
 		// Init Input
 		// Init Input
 		mTouch = new CrownTouch(this);
 		mTouch = new CrownTouch(this);
@@ -84,19 +83,11 @@ public class CrownActivity extends Activity
 		Log.i(TAG, "Crown Activity created");
 		Log.i(TAG, "Crown Activity created");
     }
     }
 
 
-//-----------------------------------------------------------------------------
-	public void onStart()
-	{
-		super.onStart();
-
-		Log.i(TAG, "Crown Activity started");
-	}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 	public void onResume()
 	public void onResume()
 	{
 	{
 		super.onResume();
 		super.onResume();
-
+		
 		// init accelerometer
 		// init accelerometer
 		mSensor.startListening(this);
 		mSensor.startListening(this);
 
 
@@ -114,32 +105,6 @@ public class CrownActivity extends Activity
 		Log.i(TAG, "Crown Activity paused");
 		Log.i(TAG, "Crown Activity paused");
 	}
 	}
 
 
-//-----------------------------------------------------------------------------
-	public void onStop()
-	{
-		super.onStop();
-
-		Log.i(TAG, "Crown Activity stopped");
-	}
-
-//-----------------------------------------------------------------------------
-	public void onRestart()
-	{
-		super.onRestart();
-
-		Log.i(TAG, "Crown Activity restarted");
-	}
-
-//-----------------------------------------------------------------------------
-	public void onDestroy()
-	{
-		super.onDestroy();
-
-		CrownLib.stopDevice();
-
-		Log.i(TAG, "Crown Activity destroyed");
-	}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 	public boolean onTouchEvent(MotionEvent event)
 	public boolean onTouchEvent(MotionEvent event)
 	{
 	{

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

@@ -45,6 +45,7 @@ public class CrownLib
 
 
 	public static native boolean 	isDeviceInit();
 	public static native boolean 	isDeviceInit();
 	public static native boolean	isDeviceRunning();
 	public static native boolean	isDeviceRunning();
+	public static native boolean	isDevicePaused();
 
 
 	public static native void 		frame();
 	public static native void 		frame();
 
 

+ 68 - 0
engine/os/android/java/CrownMainThread.java

@@ -0,0 +1,68 @@
+/*
+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.util.Log;
+import android.view.SurfaceHolder;
+
+///
+public class CrownMainThread extends Thread
+{
+	private SurfaceHolder mSurfaceHolder;
+
+	private boolean mPaused;
+
+
+//-----------------------------------------------------------------------------
+	public CrownMainThread(SurfaceHolder holder)
+	{
+		super();
+		mSurfaceHolder = holder;
+	}
+
+//-----------------------------------------------------------------------------
+	@Override
+	public void run()
+	{
+		CrownLib.createWindow(mSurfaceHolder.getSurface());
+
+		if (!CrownLib.isDeviceInit())
+		{
+			CrownLib.initDevice();
+		}
+		else
+		{
+			CrownLib.initRenderer();
+			CrownLib.unpauseDevice();
+		}
+
+		while (CrownLib.isDeviceRunning() && !CrownLib.isDevicePaused())
+		{
+			CrownLib.frame();
+		}
+	}
+}

+ 50 - 20
engine/os/android/java/CrownSurfaceView.java

@@ -37,19 +37,47 @@ public class CrownSurfaceView extends SurfaceView implements SurfaceHolder.Callb
 {
 {
 	private final String TAG = "crown";
 	private final String TAG = "crown";
 
 
-	//-----------------------------------------------------------------------------
+	private CrownMainThread mThread;
+
+	private boolean mSurfaceCreated;
+
+//-----------------------------------------------------------------------------
 	public CrownSurfaceView(Context context)
 	public CrownSurfaceView(Context context)
 	{
 	{
 		super(context);
 		super(context);
 
 
 		getHolder().addCallback(this);
 		getHolder().addCallback(this);
+
+		setFocusable(true);
+
+		mSurfaceCreated = false;
 	}
 	}
 
 
-	//-----------------------------------------------------------------------------
-	@Override
-	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) 
+//-----------------------------------------------------------------------------
+	public boolean isSurfaceCreated()
 	{
 	{
-		Log.d(TAG, "Crown Surface changed");
+		return mSurfaceCreated;
+	}
+
+//-----------------------------------------------------------------------------
+	public void createThread(SurfaceHolder holder)
+	{
+		mThread = new CrownMainThread(holder);
+		mThread.start();
+	}
+
+//-----------------------------------------------------------------------------
+	public void destroyThread()
+	{
+        try
+        {
+        	CrownLib.pauseDevice();
+            mThread.join();
+        }
+        catch (InterruptedException e)
+        {
+            Log.e("crown", "terminateThread corrupts");
+        }     
 	}
 	}
 
 
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
@@ -58,20 +86,11 @@ public class CrownSurfaceView extends SurfaceView implements SurfaceHolder.Callb
 	{
 	{
 		Log.d(TAG, "Crown Surface created");
 		Log.d(TAG, "Crown Surface created");
 
 
-		// getHolder().setFormat(PixelFormat.RGBA_8888);
-
-		setFocusable(true);
-
-		CrownLib.createWindow(getHolder().getSurface());
-
-		if (!CrownLib.isDeviceInit())
+		if (!mSurfaceCreated)
 		{
 		{
-			CrownLib.initDevice();
-		}
-		else
-		{
-			CrownLib.initRenderer();
-			CrownLib.unpauseDevice();
+			mSurfaceCreated = true;
+
+			createThread(holder);
 		}
 		}
 	}
 	}
 
 
@@ -79,12 +98,23 @@ public class CrownSurfaceView extends SurfaceView implements SurfaceHolder.Callb
 	@Override
 	@Override
 	public void surfaceDestroyed(SurfaceHolder holder) 
 	public void surfaceDestroyed(SurfaceHolder holder) 
 	{
 	{
-		CrownLib.pauseDevice();
+		mSurfaceCreated = false;
 
 
-		CrownLib.shutdownRenderer();
+		destroyThread();
+
+		CrownLib.pauseDevice();
 
 
 		CrownLib.destroyWindow();
 		CrownLib.destroyWindow();
 
 
+		CrownLib.shutdownRenderer();
+
 		Log.d(TAG, "Crown Surface destroyed");
 		Log.d(TAG, "Crown Surface destroyed");
 	}
 	}
+
+	//-----------------------------------------------------------------------------
+	@Override
+	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) 
+	{
+		Log.d(TAG, "Crown Surface changed");
+	}
 }
 }

+ 4 - 3
engine/os/linux/main.cpp

@@ -61,17 +61,18 @@ int32_t main_thread(void* data)
 	return 0;
 	return 0;
 }
 }
 
 
-int ce_main(void* args)
+int32_t ce_main(void* args)
 {
 {
 	thread.start(main_thread, args);
 	thread.start(main_thread, args);
 
 
-	while (thread.is_running()) ;
+	while (thread.is_running());
+	
 	return 0;
 	return 0;
 }
 }
 
 
 }
 }
 
 
-int main(int argc, char** argv)
+int32_t main(int argc, char** argv)
 {
 {
 	crown::MainArgs args;
 	crown::MainArgs args;
 	args.argc = argc;
 	args.argc = argc;