author | nemo |
Sat, 17 Mar 2012 17:18:43 -0400 | |
changeset 6792 | f72c8b5d421c |
parent 6661 | d16c898d1fe2 |
child 6839 | 2dd2c0f2c9d0 |
child 6892 | c02710a8bac4 |
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; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
|
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
|
34 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
35 |
/** |
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
|
36 |
SDL Activity |
6599 | 37 |
*/ |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
38 |
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
|
39 |
|
6599 | 40 |
// Main components |
41 |
public static SDLActivity mSingleton; |
|
42 |
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
|
43 |
|
6599 | 44 |
// This is what SDL runs in. It invokes SDL_main(), eventually |
45 |
private static Thread mSDLThread; |
|
46 |
||
47 |
// Audio |
|
48 |
private static Thread mAudioThread; |
|
49 |
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
|
50 |
|
6599 | 51 |
// EGL private objects |
52 |
private static EGLContext mEGLContext; |
|
53 |
private static EGLSurface mEGLSurface; |
|
54 |
private static EGLDisplay mEGLDisplay; |
|
55 |
private static EGLConfig mEGLConfig; |
|
56 |
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
|
57 |
|
6599 | 58 |
// Load the .so |
59 |
static { |
|
60 |
System.loadLibrary("SDL"); |
|
61 |
//System.loadLibrary("SDL_image"); |
|
62 |
//System.loadLibrary("SDL_mixer"); |
|
63 |
//System.loadLibrary("SDL_ttf"); |
|
64 |
System.loadLibrary("main"); |
|
65 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
66 |
|
6599 | 67 |
// Setup |
68 |
protected void onCreate(Bundle savedInstanceState) { |
|
69 |
//Log.v("SDL", "onCreate()"); |
|
70 |
super.onCreate(savedInstanceState); |
|
71 |
||
72 |
// So we can call stuff from static callbacks |
|
73 |
mSingleton = this; |
|
74 |
||
75 |
// Set up the surface |
|
76 |
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
|
77 |
|
6599 | 78 |
mSurface = new SDLSurface(getApplication(), config); |
79 |
setContentView(mSurface); |
|
80 |
SurfaceHolder holder = mSurface.getHolder(); |
|
81 |
} |
|
82 |
||
83 |
// Events |
|
84 |
protected void onPause() { |
|
85 |
Log.v("SDL", "onPause()"); |
|
86 |
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
|
87 |
|
6599 | 88 |
if(mEGLDisplay != null && mEGLContext != null){ |
89 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
90 |
egl.eglDestroyContext(mEGLDisplay, mEGLContext); |
|
91 |
mEGLDisplay = null; |
|
92 |
mEGLContext = null; |
|
93 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
94 |
|
6599 | 95 |
SDLActivity.nativePause(); |
96 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
97 |
|
6599 | 98 |
protected void onResume() { |
99 |
Log.v("SDL", "onResume()"); |
|
100 |
super.onResume(); |
|
101 |
} |
|
102 |
||
103 |
public void onBackPressed(){ |
|
104 |
super.onBackPressed(); |
|
105 |
PascalExports.HWterminate(true); |
|
106 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
107 |
|
6599 | 108 |
protected void onDestroy() { |
109 |
super.onDestroy(); |
|
110 |
Log.v("SDL", "onDestroy()"); |
|
111 |
// Send a quit message to the application |
|
112 |
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
|
113 |
|
6599 | 114 |
// Now wait for the SDL thread to quit |
115 |
if (mSDLThread != null) { |
|
116 |
try { |
|
117 |
mSDLThread.join(); |
|
118 |
} catch(Exception e) { |
|
119 |
Log.v("SDL", "Problem stopping thread: " + e); |
|
120 |
} |
|
121 |
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
|
122 |
|
6599 | 123 |
//Log.v("SDL", "Finished waiting for SDL thread"); |
124 |
} |
|
125 |
} |
|
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
|
126 |
|
6599 | 127 |
// Messages from the SDLMain thread |
128 |
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
|
129 |
|
6599 | 130 |
// Handler for the messages |
131 |
Handler commandHandler = new Handler() { |
|
132 |
public void handleMessage(Message msg) { |
|
133 |
if (msg.arg1 == COMMAND_CHANGE_TITLE) { |
|
134 |
setTitle((String)msg.obj); |
|
135 |
} |
|
136 |
} |
|
137 |
}; |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
138 |
|
6599 | 139 |
// Send a message from the SDLMain thread |
140 |
void sendCommand(int command, Object data) { |
|
141 |
Message msg = commandHandler.obtainMessage(); |
|
142 |
msg.arg1 = command; |
|
143 |
msg.obj = data; |
|
144 |
commandHandler.sendMessage(msg); |
|
145 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
146 |
|
6599 | 147 |
// C functions we call |
148 |
public static native void nativeInit(String...args); |
|
149 |
public static native void nativeQuit(); |
|
150 |
public static native void nativePause(); |
|
151 |
public static native void nativeResume(); |
|
152 |
public static native void onNativeResize(int x, int y, int format); |
|
153 |
public static native void onNativeKeyDown(int keycode); |
|
154 |
public static native void onNativeKeyUp(int keycode); |
|
155 |
public static native void onNativeTouch(int touchDevId, int pointerFingerId, |
|
156 |
int action, float x, |
|
157 |
float y, float p); |
|
158 |
public static native void onNativeAccel(float x, float y, float z); |
|
159 |
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
|
160 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
161 |
|
6599 | 162 |
// 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
|
163 |
|
6599 | 164 |
public static boolean createGLContext(int majorVersion, int minorVersion) { |
165 |
return initEGL(majorVersion, minorVersion); |
|
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 flipBuffers() { |
169 |
flipEGL(); |
|
170 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
171 |
|
6599 | 172 |
public static void setActivityTitle(String title) { |
173 |
// Called from SDLMain() thread and can't directly affect the view |
|
174 |
mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); |
|
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 Context getContext() { |
178 |
return mSingleton; |
|
179 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
180 |
|
6599 | 181 |
public static void startApp(int width, int height, GameConfig config) { |
182 |
// Start up the C app thread |
|
183 |
if (mSDLThread == null) { |
|
184 |
mSDLThread = new Thread(new SDLMain(width, height, config), "SDLThread"); |
|
185 |
mSDLThread.start(); |
|
186 |
} |
|
187 |
else { |
|
188 |
SDLActivity.nativeResume(); |
|
189 |
} |
|
190 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
191 |
|
6599 | 192 |
// EGL functions |
193 |
public static boolean initEGL(int majorVersion, int minorVersion) { |
|
194 |
if (SDLActivity.mEGLDisplay == null) { |
|
195 |
//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
|
196 |
|
6599 | 197 |
try { |
198 |
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
|
199 |
|
6599 | 200 |
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
|
201 |
|
6599 | 202 |
int[] version = new int[2]; |
203 |
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
|
204 |
|
6599 | 205 |
int EGL_OPENGL_ES_BIT = 1; |
206 |
int EGL_OPENGL_ES2_BIT = 4; |
|
207 |
int renderableType = 0; |
|
208 |
if (majorVersion == 2) { |
|
209 |
renderableType = EGL_OPENGL_ES2_BIT; |
|
210 |
} else if (majorVersion == 1) { |
|
211 |
renderableType = EGL_OPENGL_ES_BIT; |
|
212 |
} |
|
213 |
int[] configSpec = { |
|
214 |
//EGL10.EGL_DEPTH_SIZE, 16, |
|
215 |
EGL10.EGL_RENDERABLE_TYPE, renderableType, |
|
216 |
EGL10.EGL_NONE |
|
217 |
}; |
|
218 |
EGLConfig[] configs = new EGLConfig[1]; |
|
219 |
int[] num_config = new int[1]; |
|
220 |
if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) { |
|
221 |
Log.e("SDL", "No EGL config available"); |
|
222 |
return false; |
|
223 |
} |
|
224 |
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
|
225 |
|
6599 | 226 |
/*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
|
227 |
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
|
228 |
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
|
229 |
|
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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
} |
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
|
234 |
SDLActivity.mEGLContext = ctx;*/ |
6599 | 235 |
SDLActivity.mEGLDisplay = dpy; |
236 |
SDLActivity.mEGLConfig = config; |
|
237 |
SDLActivity.mGLMajor = majorVersion; |
|
238 |
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
|
239 |
|
6599 | 240 |
SDLActivity.createEGLSurface(); |
241 |
} catch(Exception e) { |
|
242 |
Log.v("SDL", e + ""); |
|
243 |
for (StackTraceElement s : e.getStackTrace()) { |
|
244 |
Log.v("SDL", s.toString()); |
|
245 |
} |
|
246 |
} |
|
247 |
} |
|
248 |
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
|
249 |
|
6599 | 250 |
return true; |
251 |
} |
|
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
|
252 |
|
6599 | 253 |
public static boolean createEGLContext() { |
254 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
255 |
int EGL_CONTEXT_CLIENT_VERSION=0x3098; |
|
256 |
int contextAttrs[] = new int[] { EGL_CONTEXT_CLIENT_VERSION, SDLActivity.mGLMajor, EGL10.EGL_NONE }; |
|
257 |
SDLActivity.mEGLContext = egl.eglCreateContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, EGL10.EGL_NO_CONTEXT, contextAttrs); |
|
258 |
if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) { |
|
259 |
Log.e("SDL", "Couldn't create context"); |
|
260 |
return false; |
|
261 |
} |
|
262 |
return true; |
|
263 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
264 |
|
6599 | 265 |
public static boolean createEGLSurface() { |
266 |
if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) { |
|
267 |
EGL10 egl = (EGL10)EGLContext.getEGL(); |
|
268 |
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
|
269 |
|
6599 | 270 |
Log.v("SDL", "Creating new EGL Surface"); |
271 |
EGLSurface surface = egl.eglCreateWindowSurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, SDLActivity.mSurface, null); |
|
272 |
if (surface == EGL10.EGL_NO_SURFACE) { |
|
273 |
Log.e("SDL", "Couldn't create surface"); |
|
274 |
return false; |
|
275 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
276 |
|
6599 | 277 |
if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) { |
278 |
Log.e("SDL", "Old EGL Context doesnt work, trying with a new one"); |
|
279 |
createEGLContext(); |
|
280 |
if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) { |
|
281 |
Log.e("SDL", "Failed making EGL Context current"); |
|
282 |
return false; |
|
283 |
} |
|
284 |
} |
|
285 |
SDLActivity.mEGLSurface = surface; |
|
286 |
return true; |
|
287 |
} |
|
288 |
return false; |
|
289 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
290 |
|
6599 | 291 |
// EGL buffer flip |
292 |
public static void flipEGL() { |
|
293 |
try { |
|
294 |
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
|
295 |
|
6599 | 296 |
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
|
297 |
|
6599 | 298 |
// 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
|
299 |
|
6599 | 300 |
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
|
301 |
|
6599 | 302 |
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
|
303 |
|
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
|
304 |
|
6599 | 305 |
} catch(Exception e) { |
306 |
Log.v("SDL", "flipEGL(): " + e); |
|
307 |
for (StackTraceElement s : e.getStackTrace()) { |
|
308 |
Log.v("SDL", s.toString()); |
|
309 |
} |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
// Audio |
|
314 |
private static Object buf; |
|
315 |
||
316 |
public static Object audioInit(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) { |
|
317 |
int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO; |
|
318 |
int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT; |
|
319 |
int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1); |
|
320 |
||
321 |
Log.v("SDL", "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer"); |
|
322 |
||
323 |
// Let the user pick a larger buffer if they really want -- but ye |
|
324 |
// gods they probably shouldn't, the minimums are horrifyingly high |
|
325 |
// latency already |
|
326 |
desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize); |
|
327 |
||
328 |
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, |
|
329 |
channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM); |
|
330 |
||
331 |
audioStartThread(); |
|
332 |
||
333 |
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"); |
|
334 |
||
335 |
if (is16Bit) { |
|
336 |
buf = new short[desiredFrames * (isStereo ? 2 : 1)]; |
|
337 |
} else { |
|
338 |
buf = new byte[desiredFrames * (isStereo ? 2 : 1)]; |
|
339 |
} |
|
340 |
return buf; |
|
341 |
} |
|
342 |
||
343 |
public static void audioStartThread() { |
|
344 |
mAudioThread = new Thread(new Runnable() { |
|
345 |
public void run() { |
|
346 |
mAudioTrack.play(); |
|
347 |
nativeRunAudioThread(); |
|
348 |
} |
|
349 |
}); |
|
350 |
||
351 |
// I'd take REALTIME if I could get it! |
|
352 |
mAudioThread.setPriority(Thread.MAX_PRIORITY); |
|
353 |
mAudioThread.start(); |
|
354 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
355 |
|
6599 | 356 |
public static void audioWriteShortBuffer(short[] buffer) { |
357 |
for (int i = 0; i < buffer.length; ) { |
|
358 |
int result = mAudioTrack.write(buffer, i, buffer.length - i); |
|
359 |
if (result > 0) { |
|
360 |
i += result; |
|
361 |
} else if (result == 0) { |
|
362 |
try { |
|
363 |
Thread.sleep(1); |
|
364 |
} catch(InterruptedException e) { |
|
365 |
// Nom nom |
|
366 |
} |
|
367 |
} else { |
|
368 |
Log.w("SDL", "SDL audio: error return from write(short)"); |
|
369 |
return; |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
373 |
|
6599 | 374 |
public static void audioWriteByteBuffer(byte[] buffer) { |
375 |
for (int i = 0; i < buffer.length; ) { |
|
376 |
int result = mAudioTrack.write(buffer, i, buffer.length - i); |
|
377 |
if (result > 0) { |
|
378 |
i += result; |
|
379 |
} else if (result == 0) { |
|
380 |
try { |
|
381 |
Thread.sleep(1); |
|
382 |
} catch(InterruptedException e) { |
|
383 |
// Nom nom |
|
384 |
} |
|
385 |
} else { |
|
386 |
Log.w("SDL", "SDL audio: error return from write(short)"); |
|
387 |
return; |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
391 |
|
6599 | 392 |
public static void audioQuit() { |
393 |
if (mAudioThread != null) { |
|
394 |
try { |
|
395 |
mAudioThread.join(); |
|
396 |
} catch(Exception e) { |
|
397 |
Log.v("SDL", "Problem stopping audio thread: " + e); |
|
398 |
} |
|
399 |
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
|
400 |
|
6599 | 401 |
//Log.v("SDL", "Finished waiting for audio thread"); |
402 |
} |
|
403 |
||
404 |
if (mAudioTrack != null) { |
|
405 |
mAudioTrack.stop(); |
|
406 |
mAudioTrack = null; |
|
407 |
} |
|
408 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
409 |
} |
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 |
/** |
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
|
412 |
Simple nativeInit() runnable |
6599 | 413 |
*/ |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
414 |
class SDLMain implements Runnable { |
6599 | 415 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
416 |
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
|
417 |
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
|
418 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
419 |
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
|
420 |
config = _config; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
421 |
surfaceWidth = width; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
422 |
surfaceHeight = height; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
423 |
} |
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 |
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
|
426 |
//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
|
427 |
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
|
428 |
|
6350 | 429 |
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
|
430 |
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
|
431 |
|
6599 | 432 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
433 |
// 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
|
434 |
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
|
435 |
String.valueOf(surfaceWidth), String.valueOf(surfaceHeight), |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
436 |
"0", "null", "xeli", "1", "1", "1", path, "" }); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
437 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
438 |
try { |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
439 |
ipc.quitIPC(); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
440 |
ipc.join(); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
441 |
} 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
|
442 |
e.printStackTrace(); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
443 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
444 |
//Log.v("SDL", "SDL thread terminated"); |
6599 | 445 |
//Log.v("SDL", "SDL thread terminated"); |
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(); |
|
6661
d16c898d1fe2
disable the use of the accelerometer on android, we don't use it and it only drains the battery
Xeli
parents:
6599
diff
changeset
|
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(); |
|
6661
d16c898d1fe2
disable the use of the accelerometer on android, we don't use it and it only drains the battery
Xeli
parents:
6599
diff
changeset
|
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) { |
|
557 |
if(keyCode == KeyEvent.KEYCODE_BACK) return false; |
|
558 |
if (event.getAction() == KeyEvent.ACTION_DOWN) { |
|
559 |
//Log.v("SDL", "key down: " + keyCode); |
|
560 |
SDLActivity.onNativeKeyDown(keyCode); |
|
561 |
return true; |
|
562 |
} |
|
563 |
else if (event.getAction() == KeyEvent.ACTION_UP) { |
|
564 |
//Log.v("SDL", "key up: " + keyCode); |
|
565 |
SDLActivity.onNativeKeyUp(keyCode); |
|
566 |
return true; |
|
567 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
568 |
|
6599 | 569 |
return false; |
570 |
} |
|
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
|
571 |
|
6599 | 572 |
// Touch events |
573 |
public boolean onTouch(View v, MotionEvent event) { |
|
574 |
{ |
|
575 |
final int touchDevId = event.getDeviceId(); |
|
576 |
final int pointerCount = event.getPointerCount(); |
|
577 |
// touchId, pointerId, action, x, y, pressure |
|
578 |
int actionPointerIndex = event.getActionIndex(); |
|
579 |
int pointerFingerId = event.getPointerId(actionPointerIndex); |
|
580 |
int action = event.getActionMasked(); |
|
581 |
||
582 |
float x = event.getX(actionPointerIndex); |
|
583 |
float y = event.getY(actionPointerIndex); |
|
584 |
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
|
585 |
|
6599 | 586 |
if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) { |
587 |
// TODO send motion to every pointer if its position has |
|
588 |
// changed since prev event. |
|
589 |
for (int i = 0; i < pointerCount; i++) { |
|
590 |
pointerFingerId = event.getPointerId(i); |
|
591 |
x = event.getX(i); |
|
592 |
y = event.getY(i); |
|
593 |
p = event.getPressure(i); |
|
594 |
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); |
|
595 |
} |
|
596 |
} else { |
|
597 |
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); |
|
598 |
} |
|
599 |
} |
|
600 |
return true; |
|
601 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
602 |
|
6599 | 603 |
// Sensor events |
604 |
public void enableSensor(int sensortype, boolean enabled) { |
|
605 |
// TODO: This uses getDefaultSensor - what if we have >1 accels? |
|
606 |
if (enabled) { |
|
607 |
mSensorManager.registerListener(this, |
|
608 |
mSensorManager.getDefaultSensor(sensortype), |
|
609 |
SensorManager.SENSOR_DELAY_GAME, null); |
|
610 |
} else { |
|
611 |
mSensorManager.unregisterListener(this, |
|
612 |
mSensorManager.getDefaultSensor(sensortype)); |
|
613 |
} |
|
614 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
615 |
|
6599 | 616 |
public void onAccuracyChanged(Sensor sensor, int accuracy) { |
617 |
// TODO |
|
618 |
} |
|
619 |
||
620 |
public void onSensorChanged(SensorEvent event) { |
|
621 |
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { |
|
622 |
SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH, |
|
623 |
event.values[1] / SensorManager.GRAVITY_EARTH, |
|
624 |
event.values[2] / SensorManager.GRAVITY_EARTH); |
|
625 |
} |
|
626 |
} |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
627 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
628 |
} |
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
|
629 |