mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Clean up OS-specific initialization
This commit is contained in:
parent
ad5e9aa5e3
commit
93c2aff2cf
5 changed files with 84 additions and 98 deletions
|
@ -39,23 +39,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
extern int main(int argc, char *argv[]);
|
||||
|
||||
namespace porting {
|
||||
void cleanupAndroid(); // used here
|
||||
bool setSystemPaths(); // used in porting.cpp
|
||||
}
|
||||
|
||||
void android_main(android_app *app)
|
||||
{
|
||||
int retval = 0;
|
||||
porting::app_global = app;
|
||||
|
||||
Thread::setName("Main");
|
||||
|
||||
char *argv[] = {strdup(PROJECT_NAME), strdup("--verbose"), nullptr};
|
||||
try {
|
||||
main(ARRLEN(argv) - 1, argv);
|
||||
} catch (std::exception &e) {
|
||||
errorstream << "Uncaught exception in main thread: " << e.what() << std::endl;
|
||||
retval = -1;
|
||||
} catch (...) {
|
||||
errorstream << "Uncaught exception in main thread!" << std::endl;
|
||||
retval = -1;
|
||||
}
|
||||
int retval = main(ARRLEN(argv) - 1, argv);
|
||||
free(argv[0]);
|
||||
free(argv[1]);
|
||||
|
||||
|
@ -65,8 +61,8 @@ void android_main(android_app *app)
|
|||
}
|
||||
|
||||
namespace porting {
|
||||
android_app *app_global;
|
||||
JNIEnv *jnienv;
|
||||
android_app *app_global = nullptr;
|
||||
JNIEnv *jnienv = nullptr;
|
||||
jclass nativeActivity;
|
||||
|
||||
jclass findClass(const std::string &classname)
|
||||
|
@ -86,9 +82,8 @@ jclass findClass(const std::string &classname)
|
|||
return (jclass) jnienv->CallObjectMethod(cls, findClass, strClassName);
|
||||
}
|
||||
|
||||
void initAndroid()
|
||||
void osSpecificInit()
|
||||
{
|
||||
porting::jnienv = nullptr;
|
||||
JavaVM *jvm = app_global->activity->vm;
|
||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
||||
|
@ -108,8 +103,7 @@ void initAndroid()
|
|||
|
||||
#ifdef GPROF
|
||||
// in the start-up code
|
||||
__android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME_C,
|
||||
"Initializing GPROF profiler");
|
||||
warningstream << "Initializing GPROF profiler" << std::endl;
|
||||
monstartup("libMinetest.so");
|
||||
#endif
|
||||
}
|
||||
|
@ -117,7 +111,7 @@ void initAndroid()
|
|||
void cleanupAndroid()
|
||||
{
|
||||
#ifdef GPROF
|
||||
errorstream << "Shutting down GPROF profiler" << std::endl;
|
||||
warningstream << "Shutting down GPROF profiler" << std::endl;
|
||||
setenv("CPUPROFILE", (path_user + DIR_DELIM + "gmon.out").c_str(), 1);
|
||||
moncleanup();
|
||||
#endif
|
||||
|
@ -137,7 +131,7 @@ static std::string readJavaString(jstring j_str)
|
|||
return str;
|
||||
}
|
||||
|
||||
void initializePathsAndroid()
|
||||
bool setSystemPaths()
|
||||
{
|
||||
// Set user and share paths
|
||||
{
|
||||
|
@ -149,7 +143,6 @@ void initializePathsAndroid()
|
|||
std::string str = readJavaString((jstring) result);
|
||||
path_user = str;
|
||||
path_share = str;
|
||||
path_locale = str + DIR_DELIM + "locale";
|
||||
}
|
||||
|
||||
// Set cache path
|
||||
|
@ -160,9 +153,9 @@ void initializePathsAndroid()
|
|||
"porting::initializePathsAndroid unable to find Java getCachePath method");
|
||||
jobject result = jnienv->CallObjectMethod(app_global->activity->clazz, getCachePath);
|
||||
path_cache = readJavaString((jstring) result);
|
||||
|
||||
migrateCachePath();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void showInputDialog(const std::string &acceptButton, const std::string &hint,
|
||||
|
@ -183,7 +176,7 @@ void showInputDialog(const std::string &acceptButton, const std::string &hint,
|
|||
jacceptButton, jhint, jcurrent, jeditType);
|
||||
}
|
||||
|
||||
void openURIAndroid(const std::string &url)
|
||||
void openURIAndroid(const char *url)
|
||||
{
|
||||
jmethodID url_open = jnienv->GetMethodID(nativeActivity, "openURI",
|
||||
"(Ljava/lang/String;)V");
|
||||
|
@ -191,7 +184,7 @@ void openURIAndroid(const std::string &url)
|
|||
FATAL_ERROR_IF(url_open == nullptr,
|
||||
"porting::openURIAndroid unable to find Java openURI method");
|
||||
|
||||
jstring jurl = jnienv->NewStringUTF(url.c_str());
|
||||
jstring jurl = jnienv->NewStringUTF(url);
|
||||
jnienv->CallVoidMethod(app_global->activity->clazz, url_open, jurl);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue