project_files/Android-build/SDL-android-project/jni/src/hedgewars_main.c
author unc0rr
Tue, 20 Nov 2012 00:10:12 +0400
changeset 8070 66bc20d089fc
parent 5934 9f05a0f43003
child 8465 9114b50fed82
permissions -rw-r--r--
Okay, remove previous request only if it has same parent as this one. Fixes the last note of previous commit (which was nearly impossible to hit, but whatever, just cleaning implementation)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     1
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     2
#include "android/log.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     3
#include "SDL.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     4
#include "dlfcn.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     5
#include "GLES/gl.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     6
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     7
#define TAG "HWEngine Loader"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     8
5350
4c100fbfad5f Fixed a fault strcpy
Xeli
parents: 5304
diff changeset
     9
typedef  (*HWEngine_Game)(char**);
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    10
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    11
main(int argc, char *argv[]){
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    12
	void *handle;
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    13
	char *error;
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    14
	HWEngine_Game Game;
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    15
	
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    16
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    17
        __android_log_print(ANDROID_LOG_INFO, TAG, "HWEngine being loaded");
5369
0ce1ef75c08f Removed absolute path to libhwengine.so, the library must be preloaded from Java now. Which automagically knows where libhwengine.so is!
Xeli
parents: 5350
diff changeset
    18
	handle = dlopen("libhwengine.so", RTLD_NOW|RTLD_GLOBAL);
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    19
	if(!handle){
5934
9f05a0f43003 Exit hedgewars cleanly and return to the frontend with out crashing + fixed error messages "foo" -> HWEngine_Loader
Xeli
parents: 5369
diff changeset
    20
		__android_log_print(ANDROID_LOG_INFO, TAG, dlerror());
9f05a0f43003 Exit hedgewars cleanly and return to the frontend with out crashing + fixed error messages "foo" -> HWEngine_Loader
Xeli
parents: 5369
diff changeset
    21
		__android_log_print(ANDROID_LOG_INFO, TAG, "error dlopen");
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    22
		exit(EXIT_FAILURE);
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    23
	}
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    24
	dlerror();
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    25
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    26
        __android_log_print(ANDROID_LOG_INFO, TAG, "HWEngine successfully loaded..");
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    27
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    28
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    29
	Game = (HWEngine_Game) dlsym(handle,"Game");
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    30
	if((error = dlerror()) != NULL){
5934
9f05a0f43003 Exit hedgewars cleanly and return to the frontend with out crashing + fixed error messages "foo" -> HWEngine_Loader
Xeli
parents: 5369
diff changeset
    31
		__android_log_print(ANDROID_LOG_INFO, TAG, error);
9f05a0f43003 Exit hedgewars cleanly and return to the frontend with out crashing + fixed error messages "foo" -> HWEngine_Loader
Xeli
parents: 5369
diff changeset
    32
		__android_log_print(ANDROID_LOG_INFO, TAG, "error dlsym");
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    33
		exit(EXIT_FAILURE);
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    34
	}
5934
9f05a0f43003 Exit hedgewars cleanly and return to the frontend with out crashing + fixed error messages "foo" -> HWEngine_Loader
Xeli
parents: 5369
diff changeset
    35
	__android_log_print(ANDROID_LOG_INFO, TAG, "dlsym succeeded");
5350
4c100fbfad5f Fixed a fault strcpy
Xeli
parents: 5304
diff changeset
    36
	Game(argv);
5934
9f05a0f43003 Exit hedgewars cleanly and return to the frontend with out crashing + fixed error messages "foo" -> HWEngine_Loader
Xeli
parents: 5369
diff changeset
    37
	__android_log_print(ANDROID_LOG_INFO, TAG, "Game() ended");
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    38
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    39
	dlclose(handle);
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    40
}