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

Added in code to get filesize (doesnt work on compressed files though) and fixed problem with getRealMilliseconds overflowing u32 and causing scene to not update

Tim Newell 12 éve
szülő
commit
bb3bc1e60a

+ 19 - 0
engine/compilers/android/src/com/garagegames/torque2d/FileWalker.java

@@ -1,10 +1,12 @@
 package com.garagegames.torque2d;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Hashtable;
 import java.util.Vector;
 
 import android.content.Context;
+import android.content.res.AssetFileDescriptor;
 import android.content.res.AssetManager;
 import android.util.Log;
 
@@ -94,4 +96,21 @@ public class FileWalker
 			return false;
 		}
 	}
+	
+	public static int GetFileSize(Context context, String file)
+	{
+		int ret = 0;
+		try {
+			if (file.startsWith("/"))
+				file = file.substring(1);
+			
+			AssetFileDescriptor afd = context.getAssets().openFd(file);
+			ret = (int)afd.getLength();
+			
+			afd.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return ret;
+	}
 }

+ 1 - 1
engine/source/console/console.cc

@@ -1808,4 +1808,4 @@ ConsoleFunction(getPathExpandoValue, const char*, 2, 2, "(int expandoIndex) - Ge
 
 } // end of Console namespace
 
-#endif
+#endif

+ 6 - 0
engine/source/persistence/taml/xml/tamlXmlParser.cc

@@ -43,6 +43,12 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor )
 
     FileStream stream;
 
+#ifdef TORQUE_OS_ANDROID
+    if (strlen(pFilename) > strlen(filenameBuffer)) {
+    	strcpy(filenameBuffer, pFilename);
+    }
+#endif
+
     // File open for read?
     if ( !stream.open( filenameBuffer, FileStream::Read ) )
     {

+ 10 - 2
engine/source/platformAndroid/AndroidTime.cpp

@@ -23,6 +23,14 @@
 #include "platformAndroid/platformAndroid.h"
 #include "game/gameInterface.h"
 
+static double startupTime = 0;
+void android_StartupTime()
+{
+	struct timeval  tv;
+	gettimeofday(&tv, NULL);
+    startupTime = ((tv.tv_sec) * 1000.0 + (tv.tv_usec) / 1000.0);
+}
+
 #include <unistd.h>
 //--------------------------------------
 void Platform::getLocalTime(LocalTime &lt)
@@ -66,8 +74,8 @@ U32 Platform::getRealMilliseconds()
 {
    struct timeval  tv;
    gettimeofday(&tv, NULL);
-
-   return ((tv.tv_sec) * 1000.0 + (tv.tv_usec) / 1000.0);
+   double ret = ((tv.tv_sec) * 1000.0 + (tv.tv_usec) / 1000.0) - startupTime;
+   return (U32)ret;
 }   
 
 U32 Platform::getVirtualMilliseconds()

+ 42 - 2
engine/source/platformAndroid/T2DActivity.cpp

@@ -31,6 +31,7 @@
 extern AndroidPlatState platState;
 
 static void engine_term_display(struct engine* engine, bool shutdown);
+extern void android_StartupTime();
 
 T2DActivity activity;
 
@@ -968,6 +969,9 @@ void android_main(struct android_app* state) {
 
 	sleep(10);
 
+	//init startup time so U32 doesnt overflow
+	android_StartupTime();
+
     // Make sure glue isn't stripped.
     app_dummy();
 
@@ -1319,8 +1323,44 @@ bool android_IsDir(const char* path)
 
 U32 android_GetFileSize(const char* pFilePath)
 {
-	//TODO: get file size
-	return 0;
+	// Attaches the current thread to the JVM.
+	jint lResult;
+	jint lFlags = 0;
+
+	JavaVM* lJavaVM = engine.app->activity->vm;
+	JNIEnv* lJNIEnv = engine.app->activity->env;
+
+	JavaVMAttachArgs lJavaVMAttachArgs;
+	lJavaVMAttachArgs.version = JNI_VERSION_1_6;
+	lJavaVMAttachArgs.name = "NativeThread";
+	lJavaVMAttachArgs.group = NULL;
+
+	lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
+	if (lResult == JNI_ERR) {
+		return false;
+	}
+
+	// Retrieves NativeActivity.
+	jobject lNativeActivity = engine.app->activity->clazz;
+	jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
+
+	jmethodID getClassLoader = lJNIEnv->GetMethodID(ClassNativeActivity,"getClassLoader", "()Ljava/lang/ClassLoader;");
+	jobject cls = lJNIEnv->CallObjectMethod(lNativeActivity, getClassLoader);
+	jclass classLoader = lJNIEnv->FindClass("java/lang/ClassLoader");
+	jmethodID findClass = lJNIEnv->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
+	jstring strClassName = lJNIEnv->NewStringUTF("com/garagegames/torque2d/FileWalker");
+	jclass FileWalkerClass = (jclass)lJNIEnv->CallObjectMethod(cls, findClass, strClassName);
+	jstring strFileName = lJNIEnv->NewStringUTF(pFilePath);
+	jmethodID MethodFileWalker = lJNIEnv->GetStaticMethodID(FileWalkerClass, "GetFileSize", "(Landroid/content/Context;Ljava/lang/String;)I");
+	jint jsize = lJNIEnv->CallStaticIntMethod(FileWalkerClass, MethodFileWalker, lNativeActivity, strFileName);
+	long size = jsize;
+	lJNIEnv->DeleteLocalRef(strClassName);
+	lJNIEnv->DeleteLocalRef(strFileName);
+
+		// Finished with the JVM.
+	lJavaVM->DetachCurrentThread();
+
+	return size;
 }
 
 ConsoleFunction(doDeviceVibrate, void, 1, 1, "Makes the device do a quick vibration. Only works on devices with vibration functionality.")

+ 2 - 2
engine/source/platformAndroid/platformAndroid.h

@@ -70,8 +70,8 @@ public:
     bool              backgrounded;
     bool              minimized;
 
-    S32               sleepTicks;
-    S32               lastTimeTick;
+    U32               sleepTicks;
+    U32               lastTimeTick;
 
     Point2I           windowSize;