author | Xeli |
Tue, 05 Jul 2011 23:29:32 +0200 | |
branch | hedgeroid |
changeset 5406 | a3f98a8a0b80 |
parent 5389 | b3cc5b4099f1 |
child 5416 | 26a36326d199 |
permissions | -rw-r--r-- |
5389
b3cc5b4099f1
Changed package name from org.hedgewars to org.hedgewars.mobile
Xeli
parents:
5387
diff
changeset
|
1 |
package org.hedgewars.mobile; |
5331
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
2 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
3 |
import javax.microedition.khronos.egl.EGL10; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
4 |
import javax.microedition.khronos.egl.EGLConfig; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
5 |
import javax.microedition.khronos.egl.EGLContext; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
6 |
import javax.microedition.khronos.egl.EGLDisplay; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
7 |
import javax.microedition.khronos.egl.EGLSurface; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
8 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
9 |
import android.app.Activity; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
10 |
import android.content.Context; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
11 |
import android.graphics.Canvas; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
12 |
import android.graphics.PixelFormat; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
13 |
import android.hardware.Sensor; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
14 |
import android.hardware.SensorEvent; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
15 |
import android.hardware.SensorEventListener; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
16 |
import android.hardware.SensorManager; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
17 |
import android.media.AudioFormat; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
18 |
import android.media.AudioManager; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
19 |
import android.media.AudioTrack; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
20 |
import android.os.Bundle; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
21 |
import android.os.Handler; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
22 |
import android.os.Message; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
23 |
import android.util.Log; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
24 |
import android.view.KeyEvent; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
25 |
import android.view.MotionEvent; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
26 |
import android.view.SurfaceHolder; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
27 |
import android.view.SurfaceView; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
28 |
import android.view.View; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
29 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
30 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
31 |
/** |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
32 |
SDL Activity |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
33 |
*/ |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
34 |
public class SDLActivity extends Activity { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
35 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
36 |
// Main components |
5406 | 37 |
public static SDLActivity mSingleton; |
5363
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
38 |
public static SDLSurface mSurface; |
5331
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
39 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
40 |
// Audio |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
41 |
private static Thread mAudioThread; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
42 |
private static AudioTrack mAudioTrack; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
43 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
44 |
// Load the .so |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
45 |
static { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
46 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
47 |
System.loadLibrary("SDL"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
48 |
System.loadLibrary("SDL_image"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
49 |
System.loadLibrary("mikmod"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
50 |
System.loadLibrary("SDL_net"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
51 |
System.loadLibrary("SDL_mixer"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
52 |
System.loadLibrary("SDL_ttf"); |
5371
bb809cd50781
Preloaded libhwengine.so and added an argument to nativeInit()
Xeli
parents:
5363
diff
changeset
|
53 |
System.loadLibrary("hwengine"); |
5331
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
54 |
System.loadLibrary("main"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
55 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
56 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
57 |
// Setup |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
58 |
protected void onCreate(Bundle savedInstanceState) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
59 |
//Log.v("SDL", "onCreate()"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
60 |
super.onCreate(savedInstanceState); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
61 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
62 |
// So we can call stuff from static callbacks |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
63 |
mSingleton = this; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
64 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
65 |
// Set up the surface |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
66 |
mSurface = new SDLSurface(getApplication()); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
67 |
setContentView(mSurface); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
68 |
SurfaceHolder holder = mSurface.getHolder(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
69 |
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
70 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
71 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
72 |
// Events |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
73 |
protected void onPause() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
74 |
//Log.v("SDL", "onPause()"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
75 |
super.onPause(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
76 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
77 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
78 |
protected void onResume() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
79 |
//Log.v("SDL", "onResume()"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
80 |
super.onResume(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
81 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
82 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
83 |
// Messages from the SDLMain thread |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
84 |
static int COMMAND_CHANGE_TITLE = 1; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
85 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
86 |
// Handler for the messages |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
87 |
Handler commandHandler = new Handler() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
88 |
public void handleMessage(Message msg) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
89 |
if (msg.arg1 == COMMAND_CHANGE_TITLE) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
90 |
setTitle((String)msg.obj); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
91 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
92 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
93 |
}; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
94 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
95 |
// Send a message from the SDLMain thread |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
96 |
void sendCommand(int command, Object data) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
97 |
Message msg = commandHandler.obtainMessage(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
98 |
msg.arg1 = command; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
99 |
msg.obj = data; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
100 |
commandHandler.sendMessage(msg); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
101 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
102 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
103 |
// C functions we call |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
104 |
public static native void nativeInit(String[] argv); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
105 |
public static native void nativeQuit(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
106 |
public static native void onNativeResize(int x, int y, int format); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
107 |
public static native void onNativeKeyDown(int keycode); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
108 |
public static native void onNativeKeyUp(int keycode); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
109 |
public static native void onNativeTouch(int action, float x, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
110 |
float y, float p); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
111 |
public static native void onNativeAccel(float x, float y, float z); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
112 |
public static native void nativeRunAudioThread(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
113 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
114 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
115 |
// Java functions called from C |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
116 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
117 |
public static boolean createGLContext(int majorVersion, int minorVersion) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
118 |
return mSurface.initEGL(majorVersion, minorVersion); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
119 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
120 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
121 |
public static void flipBuffers() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
122 |
mSurface.flipEGL(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
123 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
124 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
125 |
public static void setActivityTitle(String title) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
126 |
// Called from SDLMain() thread and can't directly affect the view |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
127 |
mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
128 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
129 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
130 |
// Audio |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
131 |
private static Object buf; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
132 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
133 |
public static Object audioInit(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
134 |
int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
135 |
int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
136 |
int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
137 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
138 |
Log.v("SDL", "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
139 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
140 |
// Let the user pick a larger buffer if they really want -- but ye |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
141 |
// gods they probably shouldn't, the minimums are horrifyingly high |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
142 |
// latency already |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
143 |
desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
144 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
145 |
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
146 |
channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
147 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
148 |
audioStartThread(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
149 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
150 |
Log.v("SDL", "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + ((float)mAudioTrack.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
151 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
152 |
if (is16Bit) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
153 |
buf = new short[desiredFrames * (isStereo ? 2 : 1)]; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
154 |
} else { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
155 |
buf = new byte[desiredFrames * (isStereo ? 2 : 1)]; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
156 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
157 |
return buf; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
158 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
159 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
160 |
public static void audioStartThread() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
161 |
mAudioThread = new Thread(new Runnable() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
162 |
public void run() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
163 |
mAudioTrack.play(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
164 |
nativeRunAudioThread(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
165 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
166 |
}); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
167 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
168 |
// I'd take REALTIME if I could get it! |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
169 |
mAudioThread.setPriority(Thread.MAX_PRIORITY); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
170 |
mAudioThread.start(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
171 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
172 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
173 |
public static void audioWriteShortBuffer(short[] buffer) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
174 |
for (int i = 0; i < buffer.length; ) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
175 |
int result = mAudioTrack.write(buffer, i, buffer.length - i); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
176 |
if (result > 0) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
177 |
i += result; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
178 |
} else if (result == 0) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
179 |
try { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
180 |
Thread.sleep(1); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
181 |
} catch(InterruptedException e) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
182 |
// Nom nom |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
183 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
184 |
} else { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
185 |
Log.w("SDL", "SDL audio: error return from write(short)"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
186 |
return; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
187 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
188 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
189 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
190 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
191 |
public static void audioWriteByteBuffer(byte[] buffer) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
192 |
for (int i = 0; i < buffer.length; ) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
193 |
int result = mAudioTrack.write(buffer, i, buffer.length - i); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
194 |
if (result > 0) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
195 |
i += result; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
196 |
} else if (result == 0) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
197 |
try { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
198 |
Thread.sleep(1); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
199 |
} catch(InterruptedException e) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
200 |
// Nom nom |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
201 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
202 |
} else { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
203 |
Log.w("SDL", "SDL audio: error return from write(short)"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
204 |
return; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
205 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
206 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
207 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
208 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
209 |
public static void audioQuit() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
210 |
if (mAudioThread != null) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
211 |
try { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
212 |
mAudioThread.join(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
213 |
} catch(Exception e) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
214 |
Log.v("SDL", "Problem stopping audio thread: " + e); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
215 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
216 |
mAudioThread = null; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
217 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
218 |
//Log.v("SDL", "Finished waiting for audio thread"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
219 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
220 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
221 |
if (mAudioTrack != null) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
222 |
mAudioTrack.stop(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
223 |
mAudioTrack = null; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
224 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
225 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
226 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
227 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
228 |
/** |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
229 |
Simple nativeInit() runnable |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
230 |
*/ |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
231 |
class SDLMain implements Runnable { |
5363
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
232 |
private int surfaceWidth, surfaceHeight; |
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
233 |
public SDLMain(int width, int height){ |
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
234 |
surfaceWidth = width; |
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
235 |
surfaceHeight = height; |
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
236 |
} |
5331
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
237 |
public void run() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
238 |
// Runs SDL_main() |
5406 | 239 |
|
240 |
String path = DownloadService.getDownloadPath(SDLActivity.mSingleton) + "Data"; |
|
5363
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
241 |
|
5406 | 242 |
SDLActivity.nativeInit(new String[]{ "0", String.valueOf(surfaceWidth), String.valueOf(surfaceHeight), "0", "null", "xeli", "1", "1", "1", "0", "/sdcard/bla.hwd", path}); |
5331
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
243 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
244 |
//Log.v("SDL", "SDL thread terminated"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
245 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
246 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
247 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
248 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
249 |
/** |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
250 |
SDLSurface. This is what we draw on, so we need to know when it's created |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
251 |
in order to do anything useful. |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
252 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
253 |
Because of this, that's where we set up the SDL thread |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
254 |
*/ |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
255 |
class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
256 |
View.OnKeyListener, View.OnTouchListener, SensorEventListener { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
257 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
258 |
// This is what SDL runs in. It invokes SDL_main(), eventually |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
259 |
private Thread mSDLThread; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
260 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
261 |
// EGL private objects |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
262 |
private EGLContext mEGLContext; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
263 |
private EGLSurface mEGLSurface; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
264 |
private EGLDisplay mEGLDisplay; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
265 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
266 |
// Sensors |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
267 |
private static SensorManager mSensorManager; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
268 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
269 |
// Startup |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
270 |
public SDLSurface(Context context) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
271 |
super(context); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
272 |
getHolder().addCallback(this); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
273 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
274 |
setFocusable(true); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
275 |
setFocusableInTouchMode(true); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
276 |
requestFocus(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
277 |
setOnKeyListener(this); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
278 |
setOnTouchListener(this); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
279 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
280 |
mSensorManager = (SensorManager)context.getSystemService("sensor"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
281 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
282 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
283 |
// Called when we have a valid drawing surface |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
284 |
public void surfaceCreated(SurfaceHolder holder) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
285 |
//Log.v("SDL", "surfaceCreated()"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
286 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
287 |
enableSensor(Sensor.TYPE_ACCELEROMETER, true); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
288 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
289 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
290 |
// Called when we lose the surface |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
291 |
public void surfaceDestroyed(SurfaceHolder holder) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
292 |
//Log.v("SDL", "surfaceDestroyed()"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
293 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
294 |
// Send a quit message to the application |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
295 |
SDLActivity.nativeQuit(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
296 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
297 |
// Now wait for the SDL thread to quit |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
298 |
if (mSDLThread != null) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
299 |
try { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
300 |
mSDLThread.join(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
301 |
} catch(Exception e) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
302 |
Log.v("SDL", "Problem stopping thread: " + e); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
303 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
304 |
mSDLThread = null; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
305 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
306 |
//Log.v("SDL", "Finished waiting for SDL thread"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
307 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
308 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
309 |
enableSensor(Sensor.TYPE_ACCELEROMETER, false); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
310 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
311 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
312 |
// Called when the surface is resized |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
313 |
public void surfaceChanged(SurfaceHolder holder, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
314 |
int format, int width, int height) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
315 |
Log.d("SDL", "surfaceChanged()"+ width + " + " + height); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
316 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
317 |
int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
318 |
switch (format) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
319 |
case PixelFormat.A_8: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
320 |
Log.v("SDL", "pixel format A_8"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
321 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
322 |
case PixelFormat.LA_88: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
323 |
Log.v("SDL", "pixel format LA_88"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
324 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
325 |
case PixelFormat.L_8: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
326 |
Log.v("SDL", "pixel format L_8"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
327 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
328 |
case PixelFormat.RGBA_4444: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
329 |
Log.v("SDL", "pixel format RGBA_4444"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
330 |
sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444 |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
331 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
332 |
case PixelFormat.RGBA_5551: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
333 |
Log.v("SDL", "pixel format RGBA_5551"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
334 |
sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551 |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
335 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
336 |
case PixelFormat.RGBA_8888: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
337 |
Log.v("SDL", "pixel format RGBA_8888"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
338 |
sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888 |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
339 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
340 |
case PixelFormat.RGBX_8888: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
341 |
Log.v("SDL", "pixel format RGBX_8888"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
342 |
sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888 |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
343 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
344 |
case PixelFormat.RGB_332: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
345 |
Log.v("SDL", "pixel format RGB_332"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
346 |
sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332 |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
347 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
348 |
case PixelFormat.RGB_565: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
349 |
Log.v("SDL", "pixel format RGB_565"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
350 |
sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
351 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
352 |
case PixelFormat.RGB_888: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
353 |
Log.v("SDL", "pixel format RGB_888"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
354 |
// Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
355 |
sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888 |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
356 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
357 |
default: |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
358 |
Log.v("SDL", "pixel format unknown " + format); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
359 |
break; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
360 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
361 |
SDLActivity.onNativeResize(width, height, sdlFormat); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
362 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
363 |
// Now start up the C app thread |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
364 |
if (mSDLThread == null) { |
5363
7f7800581012
Using the correct resolution rahter than a hardcoded one
Xeli
parents:
5347
diff
changeset
|
365 |
mSDLThread = new Thread(new SDLMain(width, height), "SDLThread"); |
5331
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
366 |
mSDLThread.start(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
367 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
368 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
369 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
370 |
// unused |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
371 |
public void onDraw(Canvas canvas) {} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
372 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
373 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
374 |
// EGL functions |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
375 |
public boolean initEGL(int majorVersion, int minorVersion) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
376 |
Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
377 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
378 |
try { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
379 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
380 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
381 |
EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
382 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
383 |
int[] version = new int[2]; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
384 |
egl.eglInitialize(dpy, version); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
385 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
386 |
int EGL_OPENGL_ES_BIT = 1; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
387 |
int EGL_OPENGL_ES2_BIT = 4; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
388 |
int renderableType = 0; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
389 |
if (majorVersion == 2) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
390 |
renderableType = EGL_OPENGL_ES2_BIT; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
391 |
} else if (majorVersion == 1) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
392 |
renderableType = EGL_OPENGL_ES_BIT; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
393 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
394 |
int[] configSpec = { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
395 |
//EGL10.EGL_DEPTH_SIZE, 16, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
396 |
EGL10.EGL_RENDERABLE_TYPE, renderableType, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
397 |
EGL10.EGL_NONE |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
398 |
}; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
399 |
EGLConfig[] configs = new EGLConfig[1]; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
400 |
int[] num_config = new int[1]; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
401 |
if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
402 |
Log.e("SDL", "No EGL config available"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
403 |
return false; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
404 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
405 |
EGLConfig config = configs[0]; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
406 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
407 |
EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
408 |
if (ctx == EGL10.EGL_NO_CONTEXT) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
409 |
Log.e("SDL", "Couldn't create context"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
410 |
return false; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
411 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
412 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
413 |
EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
414 |
if (surface == EGL10.EGL_NO_SURFACE) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
415 |
Log.e("SDL", "Couldn't create surface"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
416 |
return false; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
417 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
418 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
419 |
if (!egl.eglMakeCurrent(dpy, surface, surface, ctx)) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
420 |
Log.e("SDL", "Couldn't make context current"); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
421 |
return false; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
422 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
423 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
424 |
mEGLContext = ctx; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
425 |
mEGLDisplay = dpy; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
426 |
mEGLSurface = surface; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
427 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
428 |
} catch(Exception e) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
429 |
Log.v("SDL", e + ""); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
430 |
for (StackTraceElement s : e.getStackTrace()) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
431 |
Log.v("SDL", s.toString()); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
432 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
433 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
434 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
435 |
return true; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
436 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
437 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
438 |
// EGL buffer flip |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
439 |
public void flipEGL() { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
440 |
try { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
441 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
442 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
443 |
egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
444 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
445 |
// drawing here |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
446 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
447 |
egl.eglWaitGL(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
448 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
449 |
egl.eglSwapBuffers(mEGLDisplay, mEGLSurface); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
450 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
451 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
452 |
} catch(Exception e) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
453 |
Log.v("SDL", "flipEGL(): " + e); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
454 |
for (StackTraceElement s : e.getStackTrace()) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
455 |
Log.v("SDL", s.toString()); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
456 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
457 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
458 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
459 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
460 |
// Key events |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
461 |
public boolean onKey(View v, int keyCode, KeyEvent event) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
462 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
463 |
if (event.getAction() == KeyEvent.ACTION_DOWN) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
464 |
//Log.v("SDL", "key down: " + keyCode); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
465 |
SDLActivity.onNativeKeyDown(keyCode); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
466 |
return true; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
467 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
468 |
else if (event.getAction() == KeyEvent.ACTION_UP) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
469 |
//Log.v("SDL", "key up: " + keyCode); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
470 |
SDLActivity.onNativeKeyUp(keyCode); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
471 |
return true; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
472 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
473 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
474 |
return false; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
475 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
476 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
477 |
// Touch events |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
478 |
public boolean onTouch(View v, MotionEvent event) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
479 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
480 |
int action = event.getAction(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
481 |
float x = event.getX(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
482 |
float y = event.getY(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
483 |
float p = event.getPressure(); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
484 |
// TODO: Anything else we need to pass? |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
485 |
SDLActivity.onNativeTouch(action, x, y, p); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
486 |
return true; |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
487 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
488 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
489 |
// Sensor events |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
490 |
public void enableSensor(int sensortype, boolean enabled) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
491 |
// TODO: This uses getDefaultSensor - what if we have >1 accels? |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
492 |
if (enabled) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
493 |
mSensorManager.registerListener(this, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
494 |
mSensorManager.getDefaultSensor(sensortype), |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
495 |
SensorManager.SENSOR_DELAY_GAME, null); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
496 |
} else { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
497 |
mSensorManager.unregisterListener(this, |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
498 |
mSensorManager.getDefaultSensor(sensortype)); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
499 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
500 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
501 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
502 |
public void onAccuracyChanged(Sensor sensor, int accuracy) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
503 |
// TODO |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
504 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
505 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
506 |
public void onSensorChanged(SensorEvent event) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
507 |
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
508 |
SDLActivity.onNativeAccel(event.values[0], |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
509 |
event.values[1], |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
510 |
event.values[2]); |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
511 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
512 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
513 |
|
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
514 |
} |
3f93e036ca94
Changed the package path from org.libsdl.app to org.hedgewars
Xeli
parents:
diff
changeset
|
515 |