Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
27d80262
Commit
27d80262
authored
Jul 27, 2010
by
Paul Hunkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shut down the C application properly on quit instead of crashing in the most horrible way possible
parent
d42b7d39
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
13 deletions
+40
-13
app-android.cpp
android/testproject/jni/app-android.cpp
+35
-11
lesson05.c
android/testproject/jni/lesson05.c
+2
-1
SDLActivity.java
android/testproject/src/org/libsdl/android/SDLActivity.java
+3
-1
No files found.
android/testproject/jni/app-android.cpp
View file @
27d80262
...
...
@@ -38,22 +38,29 @@ jmethodID midFlipBuffers;
extern
"C"
int
SDL_main
();
extern
"C"
int
Android_OnKeyDown
(
int
keycode
);
extern
"C"
int
Android_OnKeyUp
(
int
keycode
);
extern
"C"
int
SDL_SendQuit
();
//If we're not the active app, don't try to render
bool
bRenderingEnabled
=
false
;
/*******************************************************************************
Functions called by JNI
*******************************************************************************/
extern
"C"
void
Java_org_libsdl_android_SDLActivity_nativeInit
(
JNIEnv
*
env
,
jobject
obj
)
{
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"JNI: NativeInit"
);
extern
"C"
void
Java_org_libsdl_android_SDLActivity_nativeInit
(
JNIEnv
*
env
,
jobject
obj
){
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: Native Init"
);
mEnv
=
env
;
bRenderingEnabled
=
true
;
SDL_main
();
}
extern
"C"
jint
JNI_OnLoad
(
JavaVM
*
vm
,
void
*
reserved
)
{
extern
"C"
jint
JNI_OnLoad
(
JavaVM
*
vm
,
void
*
reserved
)
{
JNIEnv
*
env
=
NULL
;
jint
result
=
-
1
;
...
...
@@ -85,6 +92,7 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env
int
r
=
Android_OnKeyDown
(
keycode
);
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: native key down %d, %d
\n
"
,
keycode
,
r
);
}
extern
"C"
void
Java_org_libsdl_android_SDLActivity_onNativeKeyUp
(
JNIEnv
*
env
,
...
...
@@ -93,13 +101,28 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env,
int
r
=
Android_OnKeyUp
(
keycode
);
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: native key up %d, %d
\n
"
,
keycode
,
r
);
}
extern
"C"
void
Java_org_libsdl_android_SDLActivity_onNativeTouch
(
JNIEnv
*
env
,
jobject
obj
,
jint
action
,
jfloat
x
,
jfloat
y
,
jfloat
p
){
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: native touch event %d @ %f/%f, pressure %f
\n
"
,
action
,
x
,
y
,
p
);
}
extern
"C"
void
Java_org_libsdl_android_SDLActivity_nativeQuit
(
JNIEnv
*
env
,
jobject
obj
){
//Stop rendering as we're no longer in the foreground
bRenderingEnabled
=
false
;
//Inject a SDL_QUIT event
int
r
=
SDL_SendQuit
();
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: Native quit %d"
,
r
);
}
...
...
@@ -110,17 +133,18 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env,
extern
"C"
void
sdl_create_context
(){
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: sdl_create_context()
\n
"
);
mEnv
->
CallStaticVoidMethod
(
mActivityInstance
,
midCreateGLContext
);
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: sdl_create_context() return
\n
"
);
bRenderingEnabled
=
true
;
// exit(1);
mEnv
->
CallStaticVoidMethod
(
mActivityInstance
,
midCreateGLContext
);
}
extern
"C"
void
sdl_render
(){
//When we get here, we've accumulated a full frame
//__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_render()");
if
(
!
bRenderingEnabled
){
return
;
}
//When we get here, we've accumulated a full frame
mEnv
->
CallStaticVoidMethod
(
mActivityInstance
,
midFlipBuffers
);
}
android/testproject/jni/lesson05.c
View file @
27d80262
...
...
@@ -348,7 +348,7 @@ int drawGLScene( GLvoid )
}
}
rotation
++
;
return
(
TRUE
);
}
...
...
@@ -463,6 +463,7 @@ int SDL_main( int argc, char **argv )
case
SDL_QUIT
:
/* handle quit requests */
done
=
TRUE
;
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"App is shutting down
\n
"
);
break
;
default
:
break
;
...
...
android/testproject/src/org/libsdl/android/SDLActivity.java
View file @
27d80262
...
...
@@ -61,6 +61,7 @@ public class SDLActivity extends Activity {
//C functions we call
public
static
native
void
nativeInit
();
public
static
native
void
nativeQuit
();
public
static
native
void
onNativeKeyDown
(
int
keycode
);
public
static
native
void
onNativeKeyUp
(
int
keycode
);
public
static
native
void
onNativeTouch
(
int
action
,
float
x
,
...
...
@@ -69,7 +70,6 @@ public class SDLActivity extends Activity {
//Java functions called from C
private
static
void
createGLContext
(){
mSurface
.
initEGL
();
...
...
@@ -139,6 +139,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
//Called when we lose the surface
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
Log
.
v
(
"SDL"
,
"Surface destroyed"
);
SDLActivity
.
nativeQuit
();
}
//Called when the surface is resized
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment