try to fix some android issues...
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5206 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
f3ae58608b
commit
912812083e
3 changed files with 90 additions and 8 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <dlfcn.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef ANDROID
|
||||
#error ANDROID wasnt defined
|
||||
|
@ -33,6 +34,7 @@ static char sys_basedir[MAX_OSPATH];
|
|||
static char sys_basepak[MAX_OSPATH];
|
||||
extern jmp_buf host_abort;
|
||||
JNIEnv *sys_jenv;
|
||||
JavaVM *sys_jvm;
|
||||
|
||||
cvar_t sys_vibrate = CVARFD("sys_vibrate", "1", CVAR_ARCHIVE, "Enables the system vibrator for damage events and such things. The value provided is a duration scaler.");
|
||||
cvar_t sys_osk = CVAR("sys_osk", "0"); //to be toggled
|
||||
|
@ -46,6 +48,13 @@ void VID_Register(void);
|
|||
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, DISTRIBUTION"Droid", __VA_ARGS__))
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, DISTRIBUTION"Droid", __VA_ARGS__))
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
{
|
||||
sys_jvm = vm;
|
||||
|
||||
return JNI_VERSION_1_2;
|
||||
}
|
||||
|
||||
void Sys_Vibrate(float count)
|
||||
{
|
||||
if (count < 0)
|
||||
|
@ -122,6 +131,8 @@ JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_frame(JNIEnv *env, jobject
|
|||
{
|
||||
int ret;
|
||||
|
||||
// Sys_Printf("run frame\n");
|
||||
|
||||
sys_jenv = env;
|
||||
|
||||
//if we had an error, don't even run a frame any more.
|
||||
|
@ -233,13 +244,18 @@ JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_init(JNIEnv *env, jobject o
|
|||
#else
|
||||
Host_Init(&parms);
|
||||
#endif
|
||||
sys_running = true;
|
||||
sys_lastframe = Sys_Milliseconds();
|
||||
sys_orientation.modified = true;
|
||||
|
||||
while(r_blockvidrestart == 1)
|
||||
Java_com_fteqw_FTEDroidEngine_frame(env, obj);
|
||||
{
|
||||
unsigned int now = Sys_Milliseconds();
|
||||
double tdelta = (now - sys_lastframe) * 0.001;
|
||||
Host_Frame(tdelta);
|
||||
sys_lastframe = now;
|
||||
}
|
||||
|
||||
sys_running = true;
|
||||
Sys_Printf("Engine started\n");
|
||||
}
|
||||
}
|
||||
|
@ -343,15 +359,20 @@ void Sys_Error (const char *error, ...)
|
|||
void Sys_Printf (char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
static char linebuf[2048]; //android doesn't do \ns properly *sigh*
|
||||
static char *endbuf = linebuf; //android doesn't do \ns properly *sigh*
|
||||
char *e;
|
||||
|
||||
static char linebuf[2048]; //android doesn't do \ns properly *sigh*
|
||||
static char *endbuf = linebuf; //android doesn't do \ns properly *sigh*
|
||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_lock(&lock);
|
||||
|
||||
//append the new data
|
||||
va_start (argptr, fmt);
|
||||
vsnprintf (endbuf,sizeof(linebuf)-(endbuf-linebuf)-1, fmt,argptr);
|
||||
va_end (argptr);
|
||||
endbuf += strlen(endbuf);
|
||||
|
||||
//split it on linebreaks
|
||||
while ((e = strchr(linebuf, '\n')))
|
||||
{
|
||||
*e = 0;
|
||||
|
@ -360,6 +381,8 @@ void Sys_Printf (char *fmt, ...)
|
|||
linebuf[endbuf-(e+1)] = 0;
|
||||
endbuf -= (e+1)-linebuf;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
void Sys_Warn (char *fmt, ...)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,66 @@ void Sys_ThreadAbort(void)
|
|||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <jni.h>
|
||||
extern JavaVM *sys_jvm;
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
typedef struct {
|
||||
int (*func)(void *);
|
||||
void *args;
|
||||
} qthread_t;
|
||||
static int Sys_CreatedThread(void *v)
|
||||
{
|
||||
qthread_t *qthread = v;
|
||||
int r;
|
||||
|
||||
#ifdef ANDROID
|
||||
JNIEnv* env;
|
||||
(*sys_jvm)->AttachCurrentThread(sys_jvm, &env, NULL);
|
||||
#endif
|
||||
|
||||
r = qthread->func(qthread->args);
|
||||
|
||||
#ifdef ANDROID
|
||||
(*sys_jvm)->DetachCurrentThread(sys_jvm);
|
||||
#endif
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void *Sys_CreateThread(char *name, int (*func)(void *), void *args, int priority, int stacksize)
|
||||
{
|
||||
pthread_t *thread;
|
||||
qthread_t *qthread;
|
||||
pthread_attr_t attr;
|
||||
|
||||
thread = (pthread_t *)malloc(sizeof(pthread_t)+sizeof(qthread_t));
|
||||
if (!thread)
|
||||
return NULL;
|
||||
|
||||
qthread = (qthread_t*)(thread+1);
|
||||
qthread->func = func;
|
||||
qthread->args = args;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
if (stacksize < PTHREAD_STACK_MIN*2)
|
||||
stacksize = PTHREAD_STACK_MIN*2;
|
||||
if (stacksize < PTHREAD_STACK_MIN+65536*16)
|
||||
stacksize = PTHREAD_STACK_MIN+65536*16;
|
||||
pthread_attr_setstacksize(&attr, stacksize);
|
||||
if (pthread_create(thread, &attr, (pfunction_t)Sys_CreatedThread, qthread))
|
||||
{
|
||||
free(thread);
|
||||
thread = NULL;
|
||||
}
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
return (void *)thread;
|
||||
}
|
||||
#else
|
||||
void *Sys_CreateThread(char *name, int (*func)(void *), void *args, int priority, int stacksize)
|
||||
{
|
||||
pthread_t *thread;
|
||||
|
@ -70,6 +130,7 @@ void *Sys_CreateThread(char *name, int (*func)(void *), void *args, int priority
|
|||
|
||||
return (void *)thread;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Sys_WaitOnThread(void *thread)
|
||||
{
|
||||
|
@ -336,7 +397,7 @@ pubsubserver_t *Sys_ForkServer(void)
|
|||
|
||||
return NULL; //lets hope the caller can cope.
|
||||
//jump out into the main work loop
|
||||
// longjmp(host_abort, 1);
|
||||
// longjmp(host_abort, 1);
|
||||
// exit(0); //err...
|
||||
}
|
||||
else
|
||||
|
|
|
@ -220,18 +220,16 @@ public class FTEDroidActivity extends Activity
|
|||
{
|
||||
private FTEView theview;
|
||||
private android.view.SurfaceHolder surfaceholder;
|
||||
private android.view.Surface surf;
|
||||
private boolean doquit;
|
||||
public FTERenderThread(FTEView parent, android.view.SurfaceHolder sh)
|
||||
{
|
||||
surfaceholder = sh;
|
||||
surf = sh.getSurface();
|
||||
theview = parent;
|
||||
}
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
FTEDroidEngine.setwindow(surf);
|
||||
FTEDroidEngine.setwindow(surfaceholder.getSurface());
|
||||
if (!theview.inited)
|
||||
{
|
||||
FTEDroidEngine.init(0, 0, basedir, userdir);
|
||||
|
|
Loading…
Reference in a new issue