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
9c7acc66
Commit
9c7acc66
authored
Jul 27, 2010
by
Paul Hunkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More joystick stuff
parent
ef474722
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
11 deletions
+72
-11
app-android.cpp
android/testproject/jni/app-android.cpp
+3
-3
lesson05.c
android/testproject/jni/lesson05.c
+1
-1
SDLActivity.java
android/testproject/src/org/libsdl/android/SDLActivity.java
+68
-7
No files found.
android/testproject/jni/app-android.cpp
View file @
9c7acc66
...
@@ -48,7 +48,7 @@ extern "C" void Android_EnableFeature(int featureid, bool enabled);
...
@@ -48,7 +48,7 @@ extern "C" void Android_EnableFeature(int featureid, bool enabled);
bool
bRenderingEnabled
=
false
;
bool
bRenderingEnabled
=
false
;
//Feature IDs
//Feature IDs
static
const
int
FEATURE_
SOUND
=
1
;
static
const
int
FEATURE_
AUDIO
=
1
;
static
const
int
FEATURE_ACCEL
=
2
;
static
const
int
FEATURE_ACCEL
=
2
;
//Accelerometer data storage
//Accelerometer data storage
...
@@ -76,7 +76,7 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){
...
@@ -76,7 +76,7 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){
mActivityInstance
=
cls
;
mActivityInstance
=
cls
;
midCreateGLContext
=
mEnv
->
GetStaticMethodID
(
cls
,
"createGLContext"
,
"()V"
);
midCreateGLContext
=
mEnv
->
GetStaticMethodID
(
cls
,
"createGLContext"
,
"()V"
);
midFlipBuffers
=
mEnv
->
GetStaticMethodID
(
cls
,
"flipBuffers"
,
"()V"
);
midFlipBuffers
=
mEnv
->
GetStaticMethodID
(
cls
,
"flipBuffers"
,
"()V"
);
midEnableFeature
=
mEnv
->
GetStaticMethodID
(
cls
,
"enableFeature"
,
"(I
,
I)V"
);
midEnableFeature
=
mEnv
->
GetStaticMethodID
(
cls
,
"enableFeature"
,
"(II)V"
);
if
(
!
midCreateGLContext
||
!
midFlipBuffers
||
!
midEnableFeature
){
if
(
!
midCreateGLContext
||
!
midFlipBuffers
||
!
midEnableFeature
){
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: Bad mids
\n
"
);
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: Bad mids
\n
"
);
...
@@ -196,7 +196,7 @@ extern "C" void Android_Render(){
...
@@ -196,7 +196,7 @@ extern "C" void Android_Render(){
extern
"C"
void
Android_EnableFeature
(
int
featureid
,
bool
enabled
){
extern
"C"
void
Android_EnableFeature
(
int
featureid
,
bool
enabled
){
mEnv
->
CallStaticVoidMethod
(
mActivityInstance
,
mid
FlipBuffers
,
mEnv
->
CallStaticVoidMethod
(
mActivityInstance
,
mid
EnableFeature
,
featureid
,
(
int
)
enabled
);
featureid
,
(
int
)
enabled
);
}
}
android/testproject/jni/lesson05.c
View file @
9c7acc66
...
@@ -511,7 +511,7 @@ int SDL_main( int argc, char **argv )
...
@@ -511,7 +511,7 @@ int SDL_main( int argc, char **argv )
resizeWindow
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
resizeWindow
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
testAudio
();
//
testAudio();
/* wait for events */
/* wait for events */
...
...
android/testproject/src/org/libsdl/android/SDLActivity.java
View file @
9c7acc66
...
@@ -13,6 +13,8 @@ import android.graphics.*;
...
@@ -13,6 +13,8 @@ import android.graphics.*;
import
android.text.method.*
;
import
android.text.method.*
;
import
android.text.*
;
import
android.text.*
;
import
android.media.*
;
import
android.media.*
;
import
android.hardware.*
;
import
android.content.*
;
import
java.lang.*
;
import
java.lang.*
;
...
@@ -25,11 +27,16 @@ public class SDLActivity extends Activity {
...
@@ -25,11 +27,16 @@ public class SDLActivity extends Activity {
//Main components
//Main components
private
static
SDLActivity
mSingleton
;
private
static
SDLActivity
mSingleton
;
private
static
SDLSurface
mSurface
;
private
static
SDLSurface
mSurface
;
//Audio
private
static
AudioTrack
mAudioTrack
;
private
static
AudioTrack
mAudioTrack
;
private
static
boolean
bAudioIsEnabled
;
//Sensors
private
static
boolean
bAccelIsEnabled
;
//feature IDs. Must match up on the C side as well.
//feature IDs. Must match up on the C side as well.
private
static
int
FEATURE_
SOUND
=
1
;
private
static
int
FEATURE_
AUDIO
=
1
;
private
static
int
FEATURE_ACCEL
=
2
;
private
static
int
FEATURE_ACCEL
=
2
;
//Load the .so
//Load the .so
...
@@ -52,6 +59,7 @@ public class SDLActivity extends Activity {
...
@@ -52,6 +59,7 @@ public class SDLActivity extends Activity {
}
}
//Audio
public
static
boolean
initAudio
(){
public
static
boolean
initAudio
(){
//blah. Hardcoded things are bad. FIXME when we have more sound stuff
//blah. Hardcoded things are bad. FIXME when we have more sound stuff
...
@@ -61,9 +69,24 @@ public class SDLActivity extends Activity {
...
@@ -61,9 +69,24 @@ public class SDLActivity extends Activity {
AudioFormat
.
CHANNEL_CONFIGURATION_MONO
,
AudioFormat
.
CHANNEL_CONFIGURATION_MONO
,
AudioFormat
.
ENCODING_PCM_8BIT
,
AudioFormat
.
ENCODING_PCM_8BIT
,
2048
,
2048
,
AudioTrack
.
MODE_STREAM
);
AudioTrack
.
MODE_STREAM
);
bAudioIsEnabled
=
true
;
return
true
;
}
//Accel
public
static
boolean
initAccel
(){
mSurface
.
enableSensor
(
Sensor
.
TYPE_ACCELEROMETER
,
true
);
bAccelIsEnabled
=
true
;
return
true
;
return
true
;
}
}
public
static
boolean
closeAccel
(){
mSurface
.
enableSensor
(
Sensor
.
TYPE_ACCELEROMETER
,
false
);
bAccelIsEnabled
=
false
;
return
true
;
}
//Events
//Events
protected
void
onPause
()
{
protected
void
onPause
()
{
...
@@ -87,7 +110,7 @@ public class SDLActivity extends Activity {
...
@@ -87,7 +110,7 @@ public class SDLActivity extends Activity {
public
static
native
void
onNativeTouch
(
int
action
,
float
x
,
public
static
native
void
onNativeTouch
(
int
action
,
float
x
,
float
y
,
float
p
);
float
y
,
float
p
);
public
static
native
void
onNativeResize
(
int
x
,
int
y
,
int
format
);
public
static
native
void
onNativeResize
(
int
x
,
int
y
,
int
format
);
public
static
native
void
onNativeAccel
(
float
x
,
float
y
,
float
z
);
...
@@ -117,7 +140,7 @@ public class SDLActivity extends Activity {
...
@@ -117,7 +140,7 @@ public class SDLActivity extends Activity {
//Yuck. This is all horribly inelegent. If it gets to more than a few
//Yuck. This is all horribly inelegent. If it gets to more than a few
//'features' I'll rip this out and make something nicer, I promise :)
//'features' I'll rip this out and make something nicer, I promise :)
if
(
featureid
==
FEATURE_
SOUND
){
if
(
featureid
==
FEATURE_
AUDIO
){
if
(
enabled
==
1
){
if
(
enabled
==
1
){
initAudio
();
initAudio
();
}
else
{
}
else
{
...
@@ -125,6 +148,14 @@ public class SDLActivity extends Activity {
...
@@ -125,6 +148,14 @@ public class SDLActivity extends Activity {
//closeAudio();
//closeAudio();
}
}
}
}
else
if
(
featureid
==
FEATURE_ACCEL
){
if
(
enabled
==
1
){
initAccel
();
}
else
{
closeAccel
();
}
}
}
}
...
@@ -157,7 +188,7 @@ class SDLRunner implements Runnable{
...
@@ -157,7 +188,7 @@ class SDLRunner implements Runnable{
Because of this, that's where we set up the SDL thread
Because of this, that's where we set up the SDL thread
*/
*/
class
SDLSurface
extends
SurfaceView
implements
SurfaceHolder
.
Callback
,
class
SDLSurface
extends
SurfaceView
implements
SurfaceHolder
.
Callback
,
View
.
OnKeyListener
,
View
.
OnTouchListener
{
View
.
OnKeyListener
,
View
.
OnTouchListener
,
SensorEventListener
{
//This is what SDL runs in. It invokes SDL_main(), eventually
//This is what SDL runs in. It invokes SDL_main(), eventually
private
Thread
mSDLThread
;
private
Thread
mSDLThread
;
...
@@ -167,6 +198,9 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
...
@@ -167,6 +198,9 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
private
EGLSurface
mEGLSurface
;
private
EGLSurface
mEGLSurface
;
private
EGLDisplay
mEGLDisplay
;
private
EGLDisplay
mEGLDisplay
;
//Sensors
private
static
SensorManager
mSensorManager
;
//Startup
//Startup
public
SDLSurface
(
Context
context
)
{
public
SDLSurface
(
Context
context
)
{
super
(
context
);
super
(
context
);
...
@@ -176,7 +210,9 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
...
@@ -176,7 +210,9 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
setFocusableInTouchMode
(
true
);
setFocusableInTouchMode
(
true
);
requestFocus
();
requestFocus
();
setOnKeyListener
(
this
);
setOnKeyListener
(
this
);
setOnTouchListener
(
this
);
setOnTouchListener
(
this
);
mSensorManager
=
(
SensorManager
)
context
.
getSystemService
(
"sensor"
);
}
}
//Called when we have a valid drawing surface
//Called when we have a valid drawing surface
...
@@ -321,6 +357,31 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
...
@@ -321,6 +357,31 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
return
true
;
return
true
;
}
}
//Sensor events
public
void
enableSensor
(
int
sensortype
,
boolean
enabled
){
//TODO: This uses getDefaultSensor - what if we have >1 accels?
if
(
enabled
){
mSensorManager
.
registerListener
(
this
,
mSensorManager
.
getDefaultSensor
(
sensortype
),
SensorManager
.
SENSOR_DELAY_GAME
,
null
);
}
else
{
mSensorManager
.
unregisterListener
(
this
,
mSensorManager
.
getDefaultSensor
(
sensortype
));
}
}
public
void
onAccuracyChanged
(
Sensor
sensor
,
int
accuracy
){
//TODO
}
public
void
onSensorChanged
(
SensorEvent
event
){
if
(
event
.
sensor
.
getType
()
==
Sensor
.
TYPE_ACCELEROMETER
){
SDLActivity
.
onNativeAccel
(
event
.
values
[
0
],
event
.
values
[
1
],
event
.
values
[
2
]
);
}
}
}
}
...
...
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