Browse Source

More android code changes

Tim Newell 12 years ago
parent
commit
8d0fc1488f

+ 1 - 1
engine/compilers/android/jni/Android.mk

@@ -512,7 +512,7 @@ LOCAL_SRC_FILES :=  ../../../lib/ljpeg/jcapimin.c \
 #					../../../source/testing/unitTesting.cc
  
 			   
-LOCAL_CFLAGS := -DENABLE_CONSOLE_MSGS -D__ANDROID__ -DTORQUE_OS_ANDROID -O0 -fsigned-char
+LOCAL_CFLAGS := -DENABLE_CONSOLE_MSGS -D__ANDROID__ -DTORQUE_OS_ANDROID -DGL_GLEXT_PROTOTYPES -O0 -fsigned-char
 				   
 LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv2 -lz -lOpenSLES
 LOCAL_STATIC_LIBRARIES := android_native_app_glue libpng libjpeg

+ 4 - 4
engine/source/platformAndroid/AndroidFont.cpp

@@ -20,10 +20,10 @@
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
 
-#import "platform/platform.h"
-#import "platformAndroid/platformAndroid.h"
-#import "platformAndroid/AndroidFont.h"
-#import "string/Unicode.h"
+#include "platform/platform.h"
+#include "platformAndroid/platformAndroid.h"
+#include "platformAndroid/AndroidFont.h"
+#include "string/Unicode.h"
 
 //------------------------------------------------------------------------------
 // New Unicode capable font class.

+ 3 - 3
engine/source/platformAndroid/AndroidGL2ES.cpp

@@ -28,9 +28,9 @@
 //  Copyright 2008 Pick Up And Play. All rights reserved.
 //
 
-#import "AndroidGL2ES.h"
-#import "platform/platformAssert.h"
-#import "AndroidOGLVideo.h"
+#include "AndroidGL2ES.h"
+#include "platform/platformAssert.h"
+#include "AndroidOGLVideo.h"
 
 #include "math/mMatrix.h"
 #include "math/mPoint.h"

+ 1 - 0
engine/source/platformAndroid/AndroidGL2ES.h

@@ -34,6 +34,7 @@
 
 #include "platform/types.h"
 #include <GLES/gl.h>
+#include <GLES/glext.h>
 
 extern "C"
 {

+ 1 - 1
engine/source/platformAndroid/AndroidMotionManager.cpp

@@ -20,7 +20,7 @@
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
 
-#import "AndroidMotionManager.h"
+#include "AndroidMotionManager.h"
 
 #include "platformAndroid.h"
 #include "string/stringBuffer.h"

+ 78 - 89
engine/source/platformAndroid/T2DActivity.cpp

@@ -20,12 +20,44 @@
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
 
-#import "T2DViewController.h"
-#import "platformAndroid/platformGL.h"
+#include "platformAndroid/platformGL.h"
 #include "platformAndroid/AndroidWindow.h"
 #include "platformAndroid/platformAndroid.h"
 #include "graphics/dgl.h"
 
+#include <errno.h>
+#include <EGL/egl.h>
+//#include <android/sensor.h>
+#include <android/log.h>
+#include <android_native_app_glue.h>
+#include <android/asset_manager.h>
+
+/**
+ * Our saved state data.
+ */
+struct saved_state {
+    float angle;
+    int32_t x;
+    int32_t y;
+};
+
+/**
+ * Shared state for our app.
+ */
+struct engine {
+    struct android_app* app;
+
+    int animating;
+    EGLDisplay display;
+    EGLSurface surface;
+    EGLContext context;
+    int32_t width;
+    int32_t height;
+    struct saved_state state;
+};
+
+static struct engine engine;
+
 extern AndroidPlatState platState;
 
 #define USE_DEPTH_BUFFER 0
@@ -39,6 +71,7 @@ extern void _AndroidGameInnerLoop();
 extern void _AndroidGameResignActive();
 extern void _AndroidGameBecomeActive();
 extern void _AndroidGameWillTerminate();
+extern S32 _AndroidGameGetOrientation();
 
 // Store current orientation for easy access
 extern void _AndroidGameChangeOrientation(S32 newOrientation);
@@ -52,7 +85,7 @@ bool _AndroidTorqueFatalError = false;
 extern U32  AccelerometerUpdateMS;
 extern void _AndroidGameInnerLoop();
 
-bool createFramebuffer() {
+bool T2DActivity::createFramebuffer() {
 	
 	glGenFramebuffersOES(1, &viewFramebuffer);
 	glGenRenderbuffersOES(1, &viewRenderbuffer);
@@ -76,14 +109,14 @@ bool createFramebuffer() {
 	if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
 		//TODO: android
 		//NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
-		return NO;
+		return false;
 	}
 	
-	return YES;
+	return true;
 }
 
 
-void destroyFramebuffer() {
+void T2DActivity::destroyFramebuffer() {
 	
 	glDeleteFramebuffersOES(1, &viewFramebuffer);
 	viewFramebuffer = 0;
@@ -97,7 +130,7 @@ void destroyFramebuffer() {
 }
 
 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-void finishGLSetup()
+void T2DActivity::finishGLSetup()
 {
     //TODO: android
     //self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
@@ -118,14 +151,14 @@ void finishGLSetup()
     //[self.view setMultipleTouchEnabled:YES];
     
 	_AndroidTorqueFatalError = false;
-	if(!_AndroidRunTorqueMain( appDelegate, self.view, self ))
+	if(!_AndroidRunTorqueMain())
 	{
 		_AndroidTorqueFatalError = true;
 		return;
 	}
 }
 
-void finishShutdown()
+void T2DActivity::finishShutdown()
 {
 	//TODO: android
     // Release any retained subviews of the main view.
@@ -136,12 +169,11 @@ void finishShutdown()
     //self.context = nil;
 }
 
-void update()
+void T2DActivity::update()
 {
     _AndroidGameInnerLoop();
 }
 
-extern Vector<Event *> TouchMoveEvents;
 Vector<Point2I> lastTouches;
 
 // Handle touch and keyboard input from android OS
@@ -169,10 +201,12 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
         		}
 
         	    S32 orientation = _AndroidGameGetOrientation();
-        	    if (UIDeviceOrientationIsPortrait(orientation))
+        	    //TODO: android
+        	    /* if (UIDeviceOrientationIsPortrait(orientation))
         	    {
         	    	point.y -= _AndroidGetPortraitTouchoffset();
         	    }
+        	    */
         	    createMouseDownEvent(i, point.x, point.y, touchCount);
         	}
 
@@ -189,11 +223,12 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
 				Point2I prevPoint = lastTouches[i];
 
 				S32 orientation = _AndroidGameGetOrientation();
-				if (UIDeviceOrientationIsPortrait(orientation))
+				//TODO: android
+				/*if (UIDeviceOrientationIsPortrait(orientation))
 				{
 					point.y -= _AndroidGetPortraitTouchoffset();
 					prevPoint.y -= _AndroidGetPortraitTouchoffset();
-				}
+				}*/
 				createMouseUpEvent(i, point.x, point.y, prevPoint.x, prevPoint.y, touchCount);
 
     	        //Luma: Tap support
@@ -217,11 +252,13 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
 				Point2I prevPoint = lastTouches[i];
 
 				S32 orientation = _AndroidGameGetOrientation();
+				//TODO: android
+				/*
 				if (UIDeviceOrientationIsPortrait(orientation))
 				{
 					point.y -= _AndroidGetPortraitTouchoffset();
 					prevPoint.y -= _AndroidGetPortraitTouchoffset();
-				}
+				}*/
 				createMouseMoveEvent(i, point.x, point.y, prevPoint.x, prevPoint.y);
 
 				lastTouches[i].x = point.x;
@@ -241,11 +278,14 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
 				Point2I prevPoint = lastTouches[i];
 
 				S32 orientation = _AndroidGameGetOrientation();
+				//TODO: android
+				/*
 				if (UIDeviceOrientationIsPortrait(orientation))
 				{
 					point.y -= _AndroidGetPortraitTouchoffset();
 					prevPoint.y -= _AndroidGetPortraitTouchoffset();
 				}
+				*/
 				createMouseUpEvent(i, point.x, point.y, prevPoint.x, prevPoint.y, touchCount);
 
 				//Luma: Tap support
@@ -369,8 +409,6 @@ char* _AndroidLoadFile(const char* fileName, int *size) {
 void _AndroidGetDeviceIPAddress(char* address) {
 
 	 int fd;
-	 struct ifreq ifr;
-
 	 strcpy(address, "error");
 
 	 // Attaches the current thread to the JVM.
@@ -458,7 +496,7 @@ static int engine_init_display(struct engine* engine) {
             EGL_RED_SIZE, 8,
             //EGL_ALPHA_SIZE, 8,
             //EGL_DEPTH_SIZE, 24,
-            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
             EGL_NONE
     };
 
@@ -515,17 +553,16 @@ static int engine_init_display(struct engine* engine) {
 
     glViewport(0, 0, engine->width, engine->height);
 
-    if (SetupCompleted == false) {
+    if (SetupCompleted == false)
+    {
 
-    	thePVDMan    = new PandaVideoDataManager();
-    	thePandaBase = new PandaBase();
-    	thePandaBase->SetupVideoData();
+    	//TODO: android
 
-    	PandaShader::CreateShaders();
-
-    	loadSplashScreen();
-
-    	PandaAudio::SetupSoundSystem();
+    }
+    else
+    {
+    	if(!_AndroidTorqueFatalError)
+    	        _AndroidGameBecomeActive();
     }
 
     return 0;
@@ -544,18 +581,6 @@ static void engine_update_frame(struct engine* engine) {
 	if (timeElapsed > 1.0f)
 		timeElapsed = 1.0f; // clamp it
 
-
-#ifdef GOOGLE_PLAY
-	if (gOBBPollData == true) {
-		gPollElapsed += timeElapsed;
-		//check every 10 seconds
-		if (gPollElapsed > 10.0f) {
-			PollOBBData();
-			gPollElapsed = 0.0f;
-		}
-	}
-#endif
-
 	if (SetupCompleted == false) {
 		if (timeElapsed > 0.25f) {
 			PandaSetup();
@@ -593,10 +618,7 @@ static void engine_update_frame(struct engine* engine) {
 			}
 		}
 
-
-		PandaTick(timeElapsed);
-		PandaTickMusic();
-
+		_AndroidGameInnerLoop();
 	}
 
 }
@@ -621,19 +643,20 @@ static void engine_draw_frame(struct engine* engine) {
 		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	}
-	backBufferFBO[currentActiveBuffer].AcceptRender(true);
+	//backBufferFBO[currentActiveBuffer].AcceptRender(true);
 
 	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	PandaDraw();
+	//TODO: android
+	//PandaDraw();
 
-	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+	//glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
-	int height = engine_screenHeight() - (keyboardTransition * (engine_screenHeight()/2));
+	//int height = engine_screenHeight() - (keyboardTransition * (engine_screenHeight()/2));
 
 	//draw tp screen
-	if (isDeviceiPhone()) {
+	/*if (isDeviceiPhone()) {
 
 		float scale = 1.0f;
 		//shrink it to fit screen if we have blown it up
@@ -655,7 +678,7 @@ static void engine_draw_frame(struct engine* engine) {
 
 		backBufferFBO[currentActiveBuffer].bitmap->DrawBuffer(width*scale,height*scale, scale);
 	}
-
+*/
     eglSwapBuffers(engine->display, engine->surface);
 }
 
@@ -665,7 +688,9 @@ static void engine_draw_frame(struct engine* engine) {
 static void engine_term_display(struct engine* engine, bool shutdown) {
 
 	if (shutdown == true) {
-
+		_AndroidGameWillTerminate();
+	} else {
+		 _AndroidGameResignActive();
 	}
 
     if (engine->display != EGL_NO_DISPLAY) {
@@ -684,37 +709,8 @@ static void engine_term_display(struct engine* engine, bool shutdown) {
     engine->surface = EGL_NO_SURFACE;
 }
 
-- (void)applicationDidFinishLaunching:(UIApplication *)application {
-
-	[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
-	//Also we set the currentRotation up so its not invalid
-	currentOrientation = [UIDevice currentDevice].orientation;
-	//So we make a selector to handle that, called didRotate (lower down in the code)
-	[[NSNotificationCenter defaultCenter] addObserver:self
-											 selector:@selector(didRotate:)
-												 name:UIDeviceOrientationDidChangeNotification
-											   object:nil];
-}
-
-- (void)applicationWillResignActive:(UIApplication *)application
-{
-    _AndroidGameResignActive();
-}
-
-- (void)applicationDidBecomeActive:(UIApplication *)application
-{
-    if(!_AndroidTorqueFatalError)
-        _AndroidGameBecomeActive();
-}
-
-- (void)applicationWillTerminate:(UIApplication *)application
-{
-    _AndroidGameWillTerminate();
-
-	[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
-}
-
-- (void)didRotate:(NSNotification *)notification
+//TODO: android rotate
+/*- (void)didRotate:(NSNotification *)notification
 {
     //Default to landscape left
 	UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
@@ -725,14 +721,7 @@ static void engine_term_display(struct engine* engine, bool shutdown) {
 		//Tell the rest of the engine
 		_AndroidGameChangeOrientation(currentOrientation);
 	}
-}
-
-- (void) runMainLoop
-{
-	_AndroidGameInnerLoop();
-}
-*/
-
+}*/
 
 void supportLandscape( bool enable)
 {

+ 9 - 4
engine/source/platformAndroid/T2DActivity.h

@@ -19,11 +19,11 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
+#include "platformAndroid/AndroidGL2ES.h"
 
+class T2DActivity {
 
-
-class T2DViewController {
-
+private:
 	// The pixel dimensions of the backbuffer
 	GLint backingWidth;
 	GLint backingHeight;
@@ -51,4 +51,9 @@ public:
 
     void supportLandscape( bool );
     void supportPortrait( bool );
-}
+    bool createFramebuffer();
+    void destroyFramebuffer();
+    void update();
+    void finishShutdown();
+    void finishGLSetup();
+};

+ 8 - 8
engine/source/platformAndroid/main.cpp

@@ -19,10 +19,9 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
-#import "platformAndroid/platformAndroid.h"
-#import "platformAndroid/T2DAppDelegate.h"
-#import "platformAndroid/AndroidEvents.h"
-#import "platformAndroid/AndroidUtil.h"
+#include "platformAndroid/platformAndroid.h"
+#include "platformAndroid/AndroidEvents.h"
+#include "platformAndroid/AndroidUtil.h"
 #include "platform/threads/thread.h"
 #include "game/gameInterface.h"
 #include "io/fileObject.h"
@@ -34,10 +33,10 @@ S32 gLastStart = 0;
 bool appIsRunning = true;
 
 //TODO: android
-/*
-int _AndroidRunTorqueMain( id appID, UIView * Window, T2DViewController *viewController)
-{
 
+int _AndroidRunTorqueMain()
+{
+/*
     UIApplication *app = [UIApplication sharedApplication];
     platState.viewController = viewController;
     
@@ -57,8 +56,9 @@ int _AndroidRunTorqueMain( id appID, UIView * Window, T2DViewController *viewCon
 	{
 		return 0;
 	}
+	*/
 }
-*/
+
 
 void _AndroidGameInnerLoop()
 {

+ 1 - 3
engine/source/platformAndroid/platformAndroid.h

@@ -28,9 +28,7 @@
 #include "platformAndroid/AndroidEvents.h"
 
 #include "platformAndroid/AndroidOGLVideo.h"
-
-#include "platformAndroid/T2DView.h"
-#include "platformAndroid/T2DViewController.h"
+#include "platformAndroid/T2DActivity.h"
 
 // Mich Note: Do not try to spend too much time analyzing this class.
 // It is planned to refactor the Android platform layer and replace this