Android: Pressing back button sends stop command to server
Android: ToJava can call functions on Java by using JNI Android: Plugins work Android: Added android specific files to VS2008 project, but they are excluded from compiling git-svn-id: http://mc-server.googlecode.com/svn/trunk@747 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
1f42ef9a1e
commit
c40af4c4ab
@ -1620,6 +1620,70 @@
|
||||
RelativePath="..\source\cTimer.h"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="Android Specific"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\jni\Android.mk"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\jni\app-android.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\jni\Application.mk"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\jni\ToJava.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\jni\ToJava.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Bindings"
|
||||
|
@ -9,7 +9,7 @@ LOCAL_SRC_FILES := $(shell find lua-5.1.4 jsoncpp-src-0.5.0 zlib-1.2.7 source sq
|
||||
LOCAL_SRC_FILES := $(filter-out %SquirrelFunctions.cpp %SquirrelBindings.cpp %cPlugin_Squirrel.cpp %cSquirrelCommandBinder.cpp %minigzip.c %lua.c %tolua.c %toluabind.c %LeakFinder.cpp %StackWalker.cpp %example.c,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES := $(patsubst %.cpp,../%.cpp,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES := $(patsubst %.c,../%.c,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES += app-android.cpp
|
||||
LOCAL_SRC_FILES += app-android.cpp ToJava.cpp
|
||||
|
||||
LOCAL_CFLAGS := -DANDROID_NDK \
|
||||
-ffast-math \
|
||||
|
3
jni/ToJava.cpp
Normal file
3
jni/ToJava.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "Globals.h"
|
||||
|
||||
#include "ToJava.h"
|
47
jni/ToJava.h
Normal file
47
jni/ToJava.h
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
extern JNIEnv* g_CurrentJNIEnv;
|
||||
|
||||
extern jobject g_JavaThread;
|
||||
//extern jobject g_JavaActivity;
|
||||
|
||||
//__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList);
|
||||
|
||||
static void CallJavaFunction_Void_String( jobject a_Object, const std::string & a_FunctionName, const std::string & a_StringParam )
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
|
||||
jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
|
||||
jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "(Ljava/lang/String;)V"); // void a_FunctionName( String )
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
|
||||
if (mid != 0)
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
|
||||
g_CurrentJNIEnv->CallVoidMethod( a_Object, mid, g_CurrentJNIEnv->NewStringUTF( a_StringParam.c_str() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void CallJavaFunction_Void_Void( jobject a_Object, const std::string & a_FunctionName )
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
|
||||
jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
|
||||
jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "()V"); // void a_FunctionName( String )
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
|
||||
if (mid != 0)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
|
||||
g_CurrentJNIEnv->CallVoidMethod( a_Object, mid );
|
||||
}
|
||||
else
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
|
||||
}
|
||||
}
|
@ -13,24 +13,34 @@
|
||||
#include "cCriticalSection.h"
|
||||
#include "cRoot.h"
|
||||
#include "cMakeDir.h"
|
||||
#include "ToJava.h"
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
cCriticalSection g_CriticalSection;
|
||||
|
||||
JNIEnv* g_CurrentJNIEnv = 0;
|
||||
jobject g_JavaRenderer = 0;
|
||||
jobject g_JavaThread = 0;
|
||||
//jobject g_JavaActivity = 0;
|
||||
|
||||
cRoot * pRoot = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Called when program/activity is created */
|
||||
extern "C" void Java_com_mcserver_MainThread_NativeOnCreate( JNIEnv* env )
|
||||
extern "C" void Java_com_mcserver_MainThread_NativeOnCreate( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaThread = thiz;
|
||||
//if( !cLogger::GetSingletonPtr() ) new cLogger();
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Logging from C++!");
|
||||
g_CriticalSection.Unlock();
|
||||
|
||||
//CallJavaFunction_Void_Void(g_JavaActivity, "TestTest" );
|
||||
//CallJavaFunction_Void_String(g_JavaThread, "AddToLog", "herpderpderp!!" );
|
||||
|
||||
mkdir("/sdcard/mcserver", S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
|
||||
@ -39,57 +49,20 @@ extern "C" void Java_com_mcserver_MainThread_NativeOnCreate( JNIEnv* env )
|
||||
delete pRoot;
|
||||
}
|
||||
|
||||
extern "C" void Java_com_mcserver_MCServerActivity_NativeCleanUp( JNIEnv* env )
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" void Java_com_mcserver_MainThread_NativeCleanUp( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
|
||||
g_JavaThread = thiz;
|
||||
g_CriticalSection.Unlock();
|
||||
|
||||
pRoot->ServerCommand("stop");
|
||||
}
|
||||
|
||||
/* Call to initialize the graphics state */
|
||||
extern "C" void Java_com_ballz_CppWrapperRenderer_NativeInitGL( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaRenderer = thiz;
|
||||
|
||||
g_CriticalSection.Unlock();
|
||||
}
|
||||
|
||||
extern "C" void Java_com_ballz_CppWrapperRenderer_NativeResize( JNIEnv* env, jobject thiz, jint w, jint h )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaRenderer = thiz;
|
||||
|
||||
g_CriticalSection.Unlock();
|
||||
}
|
||||
|
||||
extern "C" void Java_com_ballz_CppWrapperRenderer_NativeRender( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaRenderer = thiz;
|
||||
|
||||
|
||||
g_CriticalSection.Unlock();
|
||||
}
|
||||
|
||||
extern "C" void Java_com_ballz_CppWrapperGLSurfaceView_NativeTouchScreen( JNIEnv* env, jobject thiz, jint mouseid, jint touched )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
|
||||
g_CriticalSection.Unlock();
|
||||
}
|
||||
|
||||
extern "C" void Java_com_ballz_CppWrapperGLSurfaceView_NativeTouchEvent( JNIEnv* env, jobject thiz, jint mouseid, jfloat x, jfloat y )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
|
||||
g_CriticalSection.Unlock();
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
|
||||
#if defined(ANDROID_NDK)
|
||||
#include <android/log.h>
|
||||
#include "ToJava.h"
|
||||
#endif
|
||||
|
||||
|
||||
@ -130,6 +131,7 @@ void cLog::Log(const char * a_Format, va_list argList)
|
||||
// Print to console:
|
||||
#if defined(ANDROID_NDK)
|
||||
__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList);
|
||||
//CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line );
|
||||
#else
|
||||
printf("%s", Line.c_str());
|
||||
#endif
|
||||
|
@ -73,7 +73,7 @@ bool cPlugin_NewLua::Initialize()
|
||||
ManualBindings::Bind( m_LuaState );
|
||||
}
|
||||
|
||||
std::string PluginPath = std::string("Plugins/") + m_Directory + "/";
|
||||
std::string PluginPath = FILE_IO_PREFIX + std::string("Plugins/") + m_Directory + "/";
|
||||
|
||||
// Load all files for this plugin, and execute them
|
||||
AStringList Files = GetDirectoryContents(PluginPath.c_str());
|
||||
|
@ -2,35 +2,42 @@ package com.mcserver;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
public class MCServerActivity extends Activity {
|
||||
MainThread mThread = null;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
MainThread p = new MainThread();
|
||||
p.start();
|
||||
mThread = new MainThread();
|
||||
mThread.start();
|
||||
}
|
||||
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if(keyCode==KeyEvent.KEYCODE_BACK)
|
||||
{
|
||||
//android.os.Process.killProcess(android.os.Process.myPid());
|
||||
NativeCleanUp();
|
||||
mThread.NativeCleanUp();
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void AddToLog( String logMessage ) {
|
||||
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("mcserver");
|
||||
}
|
||||
|
||||
private static native void NativeCleanUp();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -39,9 +46,23 @@ class MainThread extends Thread {
|
||||
MainThread() {
|
||||
}
|
||||
|
||||
public void AddToLog( String logMessage ) {
|
||||
//Log.d("MCServer", "Add to log: " + logMessage);
|
||||
}
|
||||
|
||||
public void TestTest(){
|
||||
Log.d("MCServer", "in testtest");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
NativeOnCreate();
|
||||
}
|
||||
|
||||
private static native void NativeOnCreate();
|
||||
}
|
||||
public native void NativeOnCreate();
|
||||
public native void NativeCleanUp();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user