project_files/Android-build/SDL-android-project/jni/src/hedgewars_main.c
author koda
Wed, 06 Mar 2013 01:24:59 +0100
changeset 8657 3a957233f459
parent 8465 9114b50fed82
child 10017 de822cd3df3a
permissions -rw-r--r--
rework FindSparkle.cmake
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8465
9114b50fed82 Fix Hedgeroid argc/argv parameter passing to the engine
Medo <smaxein@googlemail.com>
parents: 5934
diff changeset
     1
#include<stdint.h>
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     2
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     3
#include "android/log.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     4
#include "SDL.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     5
#include "dlfcn.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     6
#include "GLES/gl.h"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     7
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     8
#define TAG "HWEngine Loader"
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
     9
8465
9114b50fed82 Fix Hedgeroid argc/argv parameter passing to the engine
Medo <smaxein@googlemail.com>
parents: 5934
diff changeset
    10
typedef  (*HWEngine_Game)(int32_t argc, char** argv);
5304
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    11
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    12
main(int argc, char *argv[]){
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    13
	void *handle;
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    14
	char *error;
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    15
	HWEngine_Game Game;
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
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    18
        __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
    19
	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
    20
	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
    21
		__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
    22
		__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
    23
		exit(EXIT_FAILURE);
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    24
	}
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    25
	dlerror();
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    26
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    27
        __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
    28
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    29
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    30
	Game = (HWEngine_Game) dlsym(handle,"Game");
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    31
	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
    32
		__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
    33
		__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
    34
		exit(EXIT_FAILURE);
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    35
	}
5934
9f05a0f43003 Exit hedgewars cleanly and return to the frontend with out crashing + fixed error messages "foo" -> HWEngine_Loader
Xeli
parents: 5369
diff changeset
    36
	__android_log_print(ANDROID_LOG_INFO, TAG, "dlsym succeeded");
8465
9114b50fed82 Fix Hedgeroid argc/argv parameter passing to the engine
Medo <smaxein@googlemail.com>
parents: 5934
diff changeset
    37
	Game(argc, 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
    38
	__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
    39
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    40
	dlclose(handle);
e29aa9e29f00 Added SDL-android-project, this is the Android/Java part of the application
Xeli
parents:
diff changeset
    41
}