author | Medo <smaxein@googlemail.com> |
Wed, 11 Jul 2012 01:52:01 +0200 | |
changeset 7328 | cd919a2ead4e |
parent 7326 | 1fae07363938 |
child 7334 | 66a10ae88457 |
permissions | -rw-r--r-- |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
1 |
package org.hedgewars.hedgeroid; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
2 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
3 |
import javax.microedition.khronos.egl.EGL10; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
4 |
import javax.microedition.khronos.egl.EGLConfig; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
5 |
import javax.microedition.khronos.egl.EGLContext; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
6 |
import javax.microedition.khronos.egl.EGLDisplay; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
7 |
import javax.microedition.khronos.egl.EGLSurface; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
8 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
9 |
import org.hedgewars.hedgeroid.EngineProtocol.EngineProtocolNetwork; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
10 |
import org.hedgewars.hedgeroid.EngineProtocol.GameConfig; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
11 |
import org.hedgewars.hedgeroid.EngineProtocol.PascalExports; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
12 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
13 |
import android.app.Activity; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
14 |
import android.content.Context; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
15 |
import android.graphics.Canvas; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
16 |
import android.graphics.PixelFormat; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
17 |
import android.hardware.Sensor; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
18 |
import android.hardware.SensorEvent; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
19 |
import android.hardware.SensorEventListener; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
20 |
import android.hardware.SensorManager; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
21 |
import android.media.AudioFormat; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
22 |
import android.media.AudioManager; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
23 |
import android.media.AudioTrack; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
24 |
import android.os.Bundle; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
25 |
import android.os.Handler; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
26 |
import android.os.Message; |
7167
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
7083
diff
changeset
|
27 |
import android.util.DisplayMetrics; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
28 |
import android.util.Log; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
29 |
import android.view.KeyEvent; |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
30 |
import android.view.MotionEvent; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
31 |
import android.view.SurfaceHolder; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
32 |
import android.view.SurfaceView; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
33 |
import android.view.View; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
34 |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
35 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
36 |
/** |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
37 |
SDL Activity |
6599 | 38 |
*/ |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
39 |
public class SDLActivity extends Activity { |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
40 |
|
6599 | 41 |
// Main components |
42 |
public static SDLActivity mSingleton; |
|
43 |
private static SDLSurface mSurface; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
44 |
|
6599 | 45 |
// This is what SDL runs in. It invokes SDL_main(), eventually |
46 |
private static Thread mSDLThread; |
|
47 |
||
48 |
// Audio |
|
49 |
private static Thread mAudioThread; |
|
50 |
private static AudioTrack mAudioTrack; |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
51 |
|
6599 | 52 |
// EGL private objects |
53 |
private static EGLContext mEGLContext; |
|
54 |
private static EGLSurface mEGLSurface; |
|
55 |
private static EGLDisplay mEGLDisplay; |
|
56 |
private static EGLConfig mEGLConfig; |
|
57 |
private static int mGLMajor, mGLMinor; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
58 |
|
6599 | 59 |
// Load the .so |
60 |
static { |
|
61 |
System.loadLibrary("SDL"); |
|
62 |
//System.loadLibrary("SDL_image"); |
|
63 |
//System.loadLibrary("SDL_mixer"); |
|
64 |
//System.loadLibrary("SDL_ttf"); |
|
65 |
System.loadLibrary("main"); |
|
66 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
67 |
|
6599 | 68 |
// Setup |
69 |
protected void onCreate(Bundle savedInstanceState) { |
|
70 |
//Log.v("SDL", "onCreate()"); |
|
71 |
super.onCreate(savedInstanceState); |
|
72 |
||
73 |
// So we can call stuff from static callbacks |
|
74 |
mSingleton = this; |
|
75 |
||
76 |
// Set up the surface |
|
77 |
GameConfig config = getIntent().getParcelableExtra("config"); |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
78 |
|
6599 | 79 |
mSurface = new SDLSurface(getApplication(), config); |
80 |
setContentView(mSurface); |
|
81 |
SurfaceHolder holder = mSurface.getHolder(); |
|
82 |
} |
|
83 |
||
84 |
// Events |
|
85 |
protected void onPause() { |
|
86 |
Log.v("SDL", "onPause()"); |
|
87 |
super.onPause(); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
88 |
|
6599 | 89 |
if(mEGLDisplay != null && mEGLContext != null){ |
90 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
91 |
egl.eglDestroyContext(mEGLDisplay, mEGLContext); |
|
92 |
mEGLDisplay = null; |
|
93 |
mEGLContext = null; |
|
94 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
95 |
|
6599 | 96 |
SDLActivity.nativePause(); |
97 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
98 |
|
6599 | 99 |
protected void onResume() { |
100 |
Log.v("SDL", "onResume()"); |
|
101 |
super.onResume(); |
|
102 |
} |
|
103 |
||
104 |
protected void onDestroy() { |
|
105 |
super.onDestroy(); |
|
106 |
Log.v("SDL", "onDestroy()"); |
|
107 |
// Send a quit message to the application |
|
108 |
SDLActivity.nativeQuit(); |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
109 |
|
6599 | 110 |
// Now wait for the SDL thread to quit |
111 |
if (mSDLThread != null) { |
|
112 |
try { |
|
113 |
mSDLThread.join(); |
|
114 |
} catch(Exception e) { |
|
115 |
Log.v("SDL", "Problem stopping thread: " + e); |
|
116 |
} |
|
117 |
mSDLThread = null; |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
118 |
|
6599 | 119 |
//Log.v("SDL", "Finished waiting for SDL thread"); |
120 |
} |
|
121 |
} |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
122 |
|
6599 | 123 |
// Messages from the SDLMain thread |
124 |
static int COMMAND_CHANGE_TITLE = 1; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
125 |
|
6599 | 126 |
// Handler for the messages |
127 |
Handler commandHandler = new Handler() { |
|
128 |
public void handleMessage(Message msg) { |
|
129 |
if (msg.arg1 == COMMAND_CHANGE_TITLE) { |
|
130 |
setTitle((String)msg.obj); |
|
131 |
} |
|
132 |
} |
|
133 |
}; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
134 |
|
6599 | 135 |
// Send a message from the SDLMain thread |
136 |
void sendCommand(int command, Object data) { |
|
137 |
Message msg = commandHandler.obtainMessage(); |
|
138 |
msg.arg1 = command; |
|
139 |
msg.obj = data; |
|
140 |
commandHandler.sendMessage(msg); |
|
141 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
142 |
|
6599 | 143 |
// C functions we call |
144 |
public static native void nativeInit(String...args); |
|
145 |
public static native void nativeQuit(); |
|
146 |
public static native void nativePause(); |
|
147 |
public static native void nativeResume(); |
|
148 |
public static native void onNativeResize(int x, int y, int format); |
|
149 |
public static native void onNativeKeyDown(int keycode); |
|
150 |
public static native void onNativeKeyUp(int keycode); |
|
151 |
public static native void onNativeTouch(int touchDevId, int pointerFingerId, |
|
152 |
int action, float x, |
|
153 |
float y, float p); |
|
154 |
public static native void onNativeAccel(float x, float y, float z); |
|
155 |
public static native void nativeRunAudioThread(); |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
156 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
157 |
|
6599 | 158 |
// Java functions called from C |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
159 |
|
6599 | 160 |
public static boolean createGLContext(int majorVersion, int minorVersion) { |
161 |
return initEGL(majorVersion, minorVersion); |
|
162 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
163 |
|
6599 | 164 |
public static void flipBuffers() { |
165 |
flipEGL(); |
|
166 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
167 |
|
6599 | 168 |
public static void setActivityTitle(String title) { |
169 |
// Called from SDLMain() thread and can't directly affect the view |
|
170 |
mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); |
|
171 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
172 |
|
6599 | 173 |
public static Context getContext() { |
174 |
return mSingleton; |
|
175 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
176 |
|
6599 | 177 |
public static void startApp(int width, int height, GameConfig config) { |
178 |
// Start up the C app thread |
|
179 |
if (mSDLThread == null) { |
|
180 |
mSDLThread = new Thread(new SDLMain(width, height, config), "SDLThread"); |
|
181 |
mSDLThread.start(); |
|
182 |
} |
|
183 |
else { |
|
184 |
SDLActivity.nativeResume(); |
|
185 |
} |
|
186 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
187 |
|
6599 | 188 |
// EGL functions |
189 |
public static boolean initEGL(int majorVersion, int minorVersion) { |
|
190 |
if (SDLActivity.mEGLDisplay == null) { |
|
191 |
//Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
192 |
|
6599 | 193 |
try { |
194 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
195 |
|
6599 | 196 |
EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
197 |
|
6599 | 198 |
int[] version = new int[2]; |
199 |
egl.eglInitialize(dpy, version); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
200 |
|
6599 | 201 |
int EGL_OPENGL_ES_BIT = 1; |
202 |
int EGL_OPENGL_ES2_BIT = 4; |
|
203 |
int renderableType = 0; |
|
204 |
if (majorVersion == 2) { |
|
205 |
renderableType = EGL_OPENGL_ES2_BIT; |
|
206 |
} else if (majorVersion == 1) { |
|
207 |
renderableType = EGL_OPENGL_ES_BIT; |
|
208 |
} |
|
209 |
int[] configSpec = { |
|
210 |
//EGL10.EGL_DEPTH_SIZE, 16, |
|
211 |
EGL10.EGL_RENDERABLE_TYPE, renderableType, |
|
212 |
EGL10.EGL_NONE |
|
213 |
}; |
|
214 |
EGLConfig[] configs = new EGLConfig[1]; |
|
215 |
int[] num_config = new int[1]; |
|
216 |
if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) { |
|
217 |
Log.e("SDL", "No EGL config available"); |
|
218 |
return false; |
|
219 |
} |
|
220 |
EGLConfig config = configs[0]; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
221 |
|
6599 | 222 |
/*int EGL_CONTEXT_CLIENT_VERSION=0x3098; |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
223 |
int contextAttrs[] = new int[] { EGL_CONTEXT_CLIENT_VERSION, majorVersion, EGL10.EGL_NONE }; |
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
224 |
EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, contextAttrs); |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
225 |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
226 |
if (ctx == EGL10.EGL_NO_CONTEXT) { |
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
227 |
Log.e("SDL", "Couldn't create context"); |
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
228 |
return false; |
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
229 |
} |
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
230 |
SDLActivity.mEGLContext = ctx;*/ |
6599 | 231 |
SDLActivity.mEGLDisplay = dpy; |
232 |
SDLActivity.mEGLConfig = config; |
|
233 |
SDLActivity.mGLMajor = majorVersion; |
|
234 |
SDLActivity.mGLMinor = minorVersion; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
235 |
|
6599 | 236 |
SDLActivity.createEGLSurface(); |
237 |
} catch(Exception e) { |
|
238 |
Log.v("SDL", e + ""); |
|
239 |
for (StackTraceElement s : e.getStackTrace()) { |
|
240 |
Log.v("SDL", s.toString()); |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
else SDLActivity.createEGLSurface(); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
245 |
|
6599 | 246 |
return true; |
247 |
} |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
248 |
|
6599 | 249 |
public static boolean createEGLContext() { |
250 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
251 |
int EGL_CONTEXT_CLIENT_VERSION=0x3098; |
|
252 |
int contextAttrs[] = new int[] { EGL_CONTEXT_CLIENT_VERSION, SDLActivity.mGLMajor, EGL10.EGL_NONE }; |
|
253 |
SDLActivity.mEGLContext = egl.eglCreateContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, EGL10.EGL_NO_CONTEXT, contextAttrs); |
|
254 |
if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) { |
|
255 |
Log.e("SDL", "Couldn't create context"); |
|
256 |
return false; |
|
257 |
} |
|
258 |
return true; |
|
259 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
260 |
|
6599 | 261 |
public static boolean createEGLSurface() { |
262 |
if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) { |
|
263 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
264 |
if (SDLActivity.mEGLContext == null) createEGLContext(); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
265 |
|
6599 | 266 |
Log.v("SDL", "Creating new EGL Surface"); |
267 |
EGLSurface surface = egl.eglCreateWindowSurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, SDLActivity.mSurface, null); |
|
268 |
if (surface == EGL10.EGL_NO_SURFACE) { |
|
269 |
Log.e("SDL", "Couldn't create surface"); |
|
270 |
return false; |
|
271 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
272 |
|
6599 | 273 |
if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) { |
274 |
Log.e("SDL", "Old EGL Context doesnt work, trying with a new one"); |
|
275 |
createEGLContext(); |
|
276 |
if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) { |
|
277 |
Log.e("SDL", "Failed making EGL Context current"); |
|
278 |
return false; |
|
279 |
} |
|
280 |
} |
|
281 |
SDLActivity.mEGLSurface = surface; |
|
282 |
return true; |
|
283 |
} |
|
284 |
return false; |
|
285 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
286 |
|
6599 | 287 |
// EGL buffer flip |
288 |
public static void flipEGL() { |
|
289 |
try { |
|
290 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
291 |
|
6599 | 292 |
egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null); |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
293 |
|
6599 | 294 |
// drawing here |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
295 |
|
6599 | 296 |
egl.eglWaitGL(); |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
297 |
|
6599 | 298 |
egl.eglSwapBuffers(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface); |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
299 |
|
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
300 |
|
6599 | 301 |
} catch(Exception e) { |
302 |
Log.v("SDL", "flipEGL(): " + e); |
|
303 |
for (StackTraceElement s : e.getStackTrace()) { |
|
304 |
Log.v("SDL", s.toString()); |
|
305 |
} |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
// Audio |
|
310 |
private static Object buf; |
|
311 |
||
312 |
public static Object audioInit(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) { |
|
313 |
int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO; |
|
314 |
int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT; |
|
315 |
int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1); |
|
316 |
||
317 |
Log.v("SDL", "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer"); |
|
318 |
||
319 |
// Let the user pick a larger buffer if they really want -- but ye |
|
320 |
// gods they probably shouldn't, the minimums are horrifyingly high |
|
321 |
// latency already |
|
322 |
desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize); |
|
323 |
||
324 |
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, |
|
325 |
channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM); |
|
326 |
||
327 |
audioStartThread(); |
|
328 |
||
329 |
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"); |
|
330 |
||
331 |
if (is16Bit) { |
|
332 |
buf = new short[desiredFrames * (isStereo ? 2 : 1)]; |
|
333 |
} else { |
|
334 |
buf = new byte[desiredFrames * (isStereo ? 2 : 1)]; |
|
335 |
} |
|
336 |
return buf; |
|
337 |
} |
|
338 |
||
339 |
public static void audioStartThread() { |
|
340 |
mAudioThread = new Thread(new Runnable() { |
|
341 |
public void run() { |
|
342 |
mAudioTrack.play(); |
|
343 |
nativeRunAudioThread(); |
|
344 |
} |
|
345 |
}); |
|
346 |
||
347 |
// I'd take REALTIME if I could get it! |
|
348 |
mAudioThread.setPriority(Thread.MAX_PRIORITY); |
|
349 |
mAudioThread.start(); |
|
350 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
351 |
|
6599 | 352 |
public static void audioWriteShortBuffer(short[] buffer) { |
353 |
for (int i = 0; i < buffer.length; ) { |
|
354 |
int result = mAudioTrack.write(buffer, i, buffer.length - i); |
|
355 |
if (result > 0) { |
|
356 |
i += result; |
|
357 |
} else if (result == 0) { |
|
358 |
try { |
|
359 |
Thread.sleep(1); |
|
360 |
} catch(InterruptedException e) { |
|
361 |
// Nom nom |
|
362 |
} |
|
363 |
} else { |
|
364 |
Log.w("SDL", "SDL audio: error return from write(short)"); |
|
365 |
return; |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
369 |
|
6599 | 370 |
public static void audioWriteByteBuffer(byte[] buffer) { |
371 |
for (int i = 0; i < buffer.length; ) { |
|
372 |
int result = mAudioTrack.write(buffer, i, buffer.length - i); |
|
373 |
if (result > 0) { |
|
374 |
i += result; |
|
375 |
} else if (result == 0) { |
|
376 |
try { |
|
377 |
Thread.sleep(1); |
|
378 |
} catch(InterruptedException e) { |
|
379 |
// Nom nom |
|
380 |
} |
|
381 |
} else { |
|
382 |
Log.w("SDL", "SDL audio: error return from write(short)"); |
|
383 |
return; |
|
384 |
} |
|
385 |
} |
|
386 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
387 |
|
6599 | 388 |
public static void audioQuit() { |
389 |
if (mAudioThread != null) { |
|
390 |
try { |
|
391 |
mAudioThread.join(); |
|
392 |
} catch(Exception e) { |
|
393 |
Log.v("SDL", "Problem stopping audio thread: " + e); |
|
394 |
} |
|
395 |
mAudioThread = null; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
396 |
|
6599 | 397 |
//Log.v("SDL", "Finished waiting for audio thread"); |
398 |
} |
|
399 |
||
400 |
if (mAudioTrack != null) { |
|
401 |
mAudioTrack.stop(); |
|
402 |
mAudioTrack = null; |
|
403 |
} |
|
404 |
} |
|
7167
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
7083
diff
changeset
|
405 |
|
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7167
diff
changeset
|
406 |
public static int getDensity(){ |
7167
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
7083
diff
changeset
|
407 |
DisplayMetrics dm = SDLActivity.getContext().getResources().getDisplayMetrics(); |
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7167
diff
changeset
|
408 |
return dm.densityDpi; |
7167
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
7083
diff
changeset
|
409 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
410 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
411 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
412 |
/** |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
413 |
Simple nativeInit() runnable |
6599 | 414 |
*/ |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
415 |
class SDLMain implements Runnable { |
6599 | 416 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
417 |
private int surfaceWidth, surfaceHeight; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
418 |
private GameConfig config; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
419 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
420 |
public SDLMain(int width, int height, GameConfig _config) { |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
421 |
config = _config; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
422 |
surfaceWidth = width; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
423 |
surfaceHeight = height; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
424 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
425 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
426 |
public void run() { |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
427 |
//Set up the IPC socket server to communicate with the engine |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
428 |
EngineProtocolNetwork ipc = new EngineProtocolNetwork(config); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
429 |
|
6350 | 430 |
String path = Utils.getDataPath(SDLActivity.mSingleton);//This represents the data directory |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
431 |
path = path.substring(0, path.length()-1);//remove the trailing '/' |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
432 |
|
6599 | 433 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
434 |
// Runs SDL_main() with added parameters |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
435 |
SDLActivity.nativeInit(new String[] { String.valueOf(ipc.port), |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
436 |
String.valueOf(surfaceWidth), String.valueOf(surfaceHeight), |
7083 | 437 |
"0", "en.txt", "xeli", "1", "1", "1", path, "" }); |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
438 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
439 |
try { |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
440 |
ipc.quitIPC(); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
441 |
ipc.join(); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
442 |
} catch (InterruptedException e) { |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
443 |
e.printStackTrace(); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
444 |
} |
6892
c02710a8bac4
android: prevent the app from a semi-crash when exiting a game
Xeli
parents:
6661
diff
changeset
|
445 |
Log.v("SDL", "SDL thread terminated"); |
6599 | 446 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
447 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
448 |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
449 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
450 |
/** |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
451 |
SDLSurface. This is what we draw on, so we need to know when it's created |
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
452 |
in order to do anything useful. |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
453 |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
454 |
Because of this, that's where we set up the SDL thread |
6599 | 455 |
*/ |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
456 |
class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, |
6599 | 457 |
View.OnKeyListener, View.OnTouchListener, SensorEventListener { |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
458 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
459 |
private GameConfig config; |
6599 | 460 |
|
461 |
// Sensors |
|
462 |
private static SensorManager mSensorManager; |
|
463 |
||
464 |
// Startup |
|
465 |
public SDLSurface(Context context, GameConfig _config) { |
|
466 |
super(context); |
|
467 |
getHolder().addCallback(this); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
468 |
|
6599 | 469 |
setFocusable(true); |
470 |
setFocusableInTouchMode(true); |
|
471 |
requestFocus(); |
|
472 |
setOnKeyListener(this); |
|
473 |
setOnTouchListener(this); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
474 |
|
6599 | 475 |
mSensorManager = (SensorManager)context.getSystemService("sensor"); |
476 |
config = _config; |
|
477 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
478 |
|
6599 | 479 |
// Called when we have a valid drawing surface |
480 |
public void surfaceCreated(SurfaceHolder holder) { |
|
481 |
Log.v("SDL", "surfaceCreated()"); |
|
482 |
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); |
|
483 |
SDLActivity.createEGLSurface(); |
|
6901 | 484 |
// enableSensor(Sensor.TYPE_ACCELEROMETER, true); |
6599 | 485 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
486 |
|
6599 | 487 |
// Called when we lose the surface |
488 |
public void surfaceDestroyed(SurfaceHolder holder) { |
|
489 |
Log.v("SDL", "surfaceDestroyed()"); |
|
490 |
SDLActivity.nativePause(); |
|
6901 | 491 |
// enableSensor(Sensor.TYPE_ACCELEROMETER, false); |
6599 | 492 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
493 |
|
6599 | 494 |
// Called when the surface is resized |
495 |
public void surfaceChanged(SurfaceHolder holder, |
|
496 |
int format, int width, int height) { |
|
497 |
Log.v("SDL", "surfaceChanged()"); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
498 |
|
6599 | 499 |
int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default |
500 |
switch (format) { |
|
501 |
case PixelFormat.A_8: |
|
502 |
Log.v("SDL", "pixel format A_8"); |
|
503 |
break; |
|
504 |
case PixelFormat.LA_88: |
|
505 |
Log.v("SDL", "pixel format LA_88"); |
|
506 |
break; |
|
507 |
case PixelFormat.L_8: |
|
508 |
Log.v("SDL", "pixel format L_8"); |
|
509 |
break; |
|
510 |
case PixelFormat.RGBA_4444: |
|
511 |
Log.v("SDL", "pixel format RGBA_4444"); |
|
512 |
sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444 |
|
513 |
break; |
|
514 |
case PixelFormat.RGBA_5551: |
|
515 |
Log.v("SDL", "pixel format RGBA_5551"); |
|
516 |
sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551 |
|
517 |
break; |
|
518 |
case PixelFormat.RGBA_8888: |
|
519 |
Log.v("SDL", "pixel format RGBA_8888"); |
|
520 |
sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888 |
|
521 |
break; |
|
522 |
case PixelFormat.RGBX_8888: |
|
523 |
Log.v("SDL", "pixel format RGBX_8888"); |
|
524 |
sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888 |
|
525 |
break; |
|
526 |
case PixelFormat.RGB_332: |
|
527 |
Log.v("SDL", "pixel format RGB_332"); |
|
528 |
sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332 |
|
529 |
break; |
|
530 |
case PixelFormat.RGB_565: |
|
531 |
Log.v("SDL", "pixel format RGB_565"); |
|
532 |
sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 |
|
533 |
break; |
|
534 |
case PixelFormat.RGB_888: |
|
535 |
Log.v("SDL", "pixel format RGB_888"); |
|
536 |
// Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? |
|
537 |
sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888 |
|
538 |
break; |
|
539 |
default: |
|
540 |
Log.v("SDL", "pixel format unknown " + format); |
|
541 |
break; |
|
542 |
} |
|
543 |
SDLActivity.onNativeResize(width, height, sdlFormat); |
|
544 |
Log.v("SDL", "Window size:" + width + "x"+height); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
545 |
|
6599 | 546 |
SDLActivity.startApp(width, height, config); |
547 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
548 |
|
6599 | 549 |
// unused |
550 |
public void onDraw(Canvas canvas) {} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
551 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
552 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
553 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
554 |
|
6599 | 555 |
// Key events |
556 |
public boolean onKey(View v, int keyCode, KeyEvent event) { |
|
6901 | 557 |
switch(keyCode){ |
558 |
case KeyEvent.KEYCODE_BACK: |
|
559 |
PascalExports.HWterminate(true); |
|
560 |
return true; |
|
561 |
case KeyEvent.KEYCODE_VOLUME_DOWN: |
|
562 |
case KeyEvent.KEYCODE_VOLUME_UP: |
|
563 |
case KeyEvent.KEYCODE_VOLUME_MUTE: |
|
564 |
return false; |
|
565 |
} |
|
6599 | 566 |
if (event.getAction() == KeyEvent.ACTION_DOWN) { |
567 |
//Log.v("SDL", "key down: " + keyCode); |
|
568 |
SDLActivity.onNativeKeyDown(keyCode); |
|
569 |
return true; |
|
570 |
} |
|
571 |
else if (event.getAction() == KeyEvent.ACTION_UP) { |
|
572 |
//Log.v("SDL", "key up: " + keyCode); |
|
573 |
SDLActivity.onNativeKeyUp(keyCode); |
|
574 |
return true; |
|
575 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
576 |
|
6599 | 577 |
return false; |
578 |
} |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
579 |
|
6599 | 580 |
// Touch events |
581 |
public boolean onTouch(View v, MotionEvent event) { |
|
6839
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
582 |
final int action = event.getAction() & MotionEvent.ACTION_MASK; |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
583 |
final int actionPointerIndex = event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
584 |
|
6839
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
585 |
if (action == MotionEvent.ACTION_MOVE) { |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
586 |
// TODO send motion to every pointer if its position has |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
587 |
// changed since prev event. |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
588 |
for (int i = 0; i < event.getPointerCount(); i++) { |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
589 |
sendNativeTouch(event, action, i); |
6599 | 590 |
} |
6839
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
591 |
} else { |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
592 |
sendNativeTouch(event, action, actionPointerIndex); |
6599 | 593 |
} |
594 |
return true; |
|
595 |
} |
|
6839
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
596 |
|
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
597 |
private static void sendNativeTouch(MotionEvent event, int action, int pointerIndex) { |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
598 |
int touchDevId = event.getDeviceId(); |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
599 |
int pointerFingerId = event.getPointerId(pointerIndex); |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
600 |
float x = event.getX(pointerIndex); |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
601 |
float y = event.getY(pointerIndex); |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
602 |
float pressure = event.getPressure(pointerIndex); |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
603 |
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, pressure); |
2dd2c0f2c9d0
Remove API Level 8 dependency found by Android Lint
Medo <smaxein@googlemail.com>
parents:
6661
diff
changeset
|
604 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
605 |
|
6599 | 606 |
// Sensor events |
607 |
public void enableSensor(int sensortype, boolean enabled) { |
|
608 |
// TODO: This uses getDefaultSensor - what if we have >1 accels? |
|
609 |
if (enabled) { |
|
610 |
mSensorManager.registerListener(this, |
|
611 |
mSensorManager.getDefaultSensor(sensortype), |
|
612 |
SensorManager.SENSOR_DELAY_GAME, null); |
|
613 |
} else { |
|
614 |
mSensorManager.unregisterListener(this, |
|
615 |
mSensorManager.getDefaultSensor(sensortype)); |
|
616 |
} |
|
617 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
618 |
|
6599 | 619 |
public void onAccuracyChanged(Sensor sensor, int accuracy) { |
620 |
// TODO |
|
621 |
} |
|
622 |
||
623 |
public void onSensorChanged(SensorEvent event) { |
|
624 |
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { |
|
625 |
SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH, |
|
626 |
event.values[1] / SensorManager.GRAVITY_EARTH, |
|
627 |
event.values[2] / SensorManager.GRAVITY_EARTH); |
|
628 |
} |
|
629 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
630 |
} |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6487
diff
changeset
|
631 |