author | nemo |
Tue, 21 Aug 2012 19:40:02 -0400 | |
changeset 7567 | da2aa8355d91 |
parent 7185 | 92a045156255 |
child 7221 | 8d04e85ca204 |
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 |
//Log.v("SDL", "SDL thread terminated"); |
447 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
448 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
449 |
|
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
|
450 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
451 |
/** |
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
|
452 |
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
|
453 |
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
|
454 |
|
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
|
455 |
Because of this, that's where we set up the SDL thread |
6599 | 456 |
*/ |
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
|
457 |
class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, |
6599 | 458 |
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
|
459 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
460 |
private GameConfig config; |
6599 | 461 |
|
462 |
// Sensors |
|
463 |
private static SensorManager mSensorManager; |
|
464 |
||
465 |
// Startup |
|
466 |
public SDLSurface(Context context, GameConfig _config) { |
|
467 |
super(context); |
|
468 |
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
|
469 |
|
6599 | 470 |
setFocusable(true); |
471 |
setFocusableInTouchMode(true); |
|
472 |
requestFocus(); |
|
473 |
setOnKeyListener(this); |
|
474 |
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
|
475 |
|
6599 | 476 |
mSensorManager = (SensorManager)context.getSystemService("sensor"); |
477 |
config = _config; |
|
478 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
479 |
|
6599 | 480 |
// Called when we have a valid drawing surface |
481 |
public void surfaceCreated(SurfaceHolder holder) { |
|
482 |
Log.v("SDL", "surfaceCreated()"); |
|
483 |
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); |
|
484 |
SDLActivity.createEGLSurface(); |
|
6901 | 485 |
// enableSensor(Sensor.TYPE_ACCELEROMETER, true); |
6599 | 486 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
487 |
|
6599 | 488 |
// Called when we lose the surface |
489 |
public void surfaceDestroyed(SurfaceHolder holder) { |
|
490 |
Log.v("SDL", "surfaceDestroyed()"); |
|
491 |
SDLActivity.nativePause(); |
|
6901 | 492 |
// enableSensor(Sensor.TYPE_ACCELEROMETER, false); |
6599 | 493 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
494 |
|
6599 | 495 |
// Called when the surface is resized |
496 |
public void surfaceChanged(SurfaceHolder holder, |
|
497 |
int format, int width, int height) { |
|
498 |
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
|
499 |
|
6599 | 500 |
int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default |
501 |
switch (format) { |
|
502 |
case PixelFormat.A_8: |
|
503 |
Log.v("SDL", "pixel format A_8"); |
|
504 |
break; |
|
505 |
case PixelFormat.LA_88: |
|
506 |
Log.v("SDL", "pixel format LA_88"); |
|
507 |
break; |
|
508 |
case PixelFormat.L_8: |
|
509 |
Log.v("SDL", "pixel format L_8"); |
|
510 |
break; |
|
511 |
case PixelFormat.RGBA_4444: |
|
512 |
Log.v("SDL", "pixel format RGBA_4444"); |
|
513 |
sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444 |
|
514 |
break; |
|
515 |
case PixelFormat.RGBA_5551: |
|
516 |
Log.v("SDL", "pixel format RGBA_5551"); |
|
517 |
sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551 |
|
518 |
break; |
|
519 |
case PixelFormat.RGBA_8888: |
|
520 |
Log.v("SDL", "pixel format RGBA_8888"); |
|
521 |
sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888 |
|
522 |
break; |
|
523 |
case PixelFormat.RGBX_8888: |
|
524 |
Log.v("SDL", "pixel format RGBX_8888"); |
|
525 |
sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888 |
|
526 |
break; |
|
527 |
case PixelFormat.RGB_332: |
|
528 |
Log.v("SDL", "pixel format RGB_332"); |
|
529 |
sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332 |
|
530 |
break; |
|
531 |
case PixelFormat.RGB_565: |
|
532 |
Log.v("SDL", "pixel format RGB_565"); |
|
533 |
sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 |
|
534 |
break; |
|
535 |
case PixelFormat.RGB_888: |
|
536 |
Log.v("SDL", "pixel format RGB_888"); |
|
537 |
// Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? |
|
538 |
sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888 |
|
539 |
break; |
|
540 |
default: |
|
541 |
Log.v("SDL", "pixel format unknown " + format); |
|
542 |
break; |
|
543 |
} |
|
544 |
SDLActivity.onNativeResize(width, height, sdlFormat); |
|
545 |
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
|
546 |
|
6599 | 547 |
SDLActivity.startApp(width, height, config); |
548 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
549 |
|
6599 | 550 |
// unused |
551 |
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
|
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 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
555 |
|
6599 | 556 |
// Key events |
557 |
public boolean onKey(View v, int keyCode, KeyEvent event) { |
|
6901 | 558 |
switch(keyCode){ |
559 |
case KeyEvent.KEYCODE_BACK: |
|
560 |
PascalExports.HWterminate(true); |
|
561 |
return true; |
|
562 |
case KeyEvent.KEYCODE_VOLUME_DOWN: |
|
563 |
case KeyEvent.KEYCODE_VOLUME_UP: |
|
564 |
case KeyEvent.KEYCODE_VOLUME_MUTE: |
|
565 |
return false; |
|
566 |
} |
|
6599 | 567 |
if (event.getAction() == KeyEvent.ACTION_DOWN) { |
568 |
//Log.v("SDL", "key down: " + keyCode); |
|
569 |
SDLActivity.onNativeKeyDown(keyCode); |
|
570 |
return true; |
|
571 |
} |
|
572 |
else if (event.getAction() == KeyEvent.ACTION_UP) { |
|
573 |
//Log.v("SDL", "key up: " + keyCode); |
|
574 |
SDLActivity.onNativeKeyUp(keyCode); |
|
575 |
return true; |
|
576 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
577 |
|
6599 | 578 |
return false; |
579 |
} |
|
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
|
580 |
|
6599 | 581 |
// Touch events |
582 |
public boolean onTouch(View v, MotionEvent event) { |
|
583 |
{ |
|
584 |
final int touchDevId = event.getDeviceId(); |
|
585 |
final int pointerCount = event.getPointerCount(); |
|
586 |
// touchId, pointerId, action, x, y, pressure |
|
587 |
int actionPointerIndex = event.getActionIndex(); |
|
588 |
int pointerFingerId = event.getPointerId(actionPointerIndex); |
|
589 |
int action = event.getActionMasked(); |
|
590 |
||
591 |
float x = event.getX(actionPointerIndex); |
|
592 |
float y = event.getY(actionPointerIndex); |
|
593 |
float p = event.getPressure(actionPointerIndex); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
594 |
|
6599 | 595 |
if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) { |
596 |
// TODO send motion to every pointer if its position has |
|
597 |
// changed since prev event. |
|
598 |
for (int i = 0; i < pointerCount; i++) { |
|
599 |
pointerFingerId = event.getPointerId(i); |
|
600 |
x = event.getX(i); |
|
601 |
y = event.getY(i); |
|
602 |
p = event.getPressure(i); |
|
603 |
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); |
|
604 |
} |
|
605 |
} else { |
|
606 |
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); |
|
607 |
} |
|
608 |
} |
|
609 |
return true; |
|
610 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
611 |
|
6599 | 612 |
// Sensor events |
613 |
public void enableSensor(int sensortype, boolean enabled) { |
|
614 |
// TODO: This uses getDefaultSensor - what if we have >1 accels? |
|
615 |
if (enabled) { |
|
616 |
mSensorManager.registerListener(this, |
|
617 |
mSensorManager.getDefaultSensor(sensortype), |
|
618 |
SensorManager.SENSOR_DELAY_GAME, null); |
|
619 |
} else { |
|
620 |
mSensorManager.unregisterListener(this, |
|
621 |
mSensorManager.getDefaultSensor(sensortype)); |
|
622 |
} |
|
623 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
624 |
|
6599 | 625 |
public void onAccuracyChanged(Sensor sensor, int accuracy) { |
626 |
// TODO |
|
627 |
} |
|
628 |
||
629 |
public void onSensorChanged(SensorEvent event) { |
|
630 |
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { |
|
631 |
SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH, |
|
632 |
event.values[1] / SensorManager.GRAVITY_EARTH, |
|
633 |
event.values[2] / SensorManager.GRAVITY_EARTH); |
|
634 |
} |
|
635 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
636 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
637 |
} |
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
|
638 |