mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-06 20:30:36 +08:00
Use shared prefs and setenv
This commit is contained in:
@@ -58,6 +58,7 @@ import com.beloko.games.hl.NativeLib;
|
||||
import com.beloko.touchcontrols.ControlInterpreter;
|
||||
import com.beloko.touchcontrols.Settings;
|
||||
import com.beloko.touchcontrols.TouchControlsSettings;
|
||||
import android.content.*;
|
||||
|
||||
/**
|
||||
SDL Activity
|
||||
@@ -66,7 +67,7 @@ public class SDLActivity extends Activity {
|
||||
private static final String TAG = "SDL";
|
||||
|
||||
// Keep track of the paused state
|
||||
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus;
|
||||
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus, mUseControls;
|
||||
public static boolean mExitCalledFromJava;
|
||||
|
||||
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
|
||||
@@ -89,9 +90,11 @@ public class SDLActivity extends Activity {
|
||||
// Audio
|
||||
protected static AudioTrack mAudioTrack;
|
||||
|
||||
//Touch control interp
|
||||
// Touch control interp
|
||||
public static ControlInterpreter controlInterp;
|
||||
|
||||
|
||||
// Preferences
|
||||
public static SharedPreferences mPref;
|
||||
/**
|
||||
* This method is called by SDL before loading the native shared libraries.
|
||||
* It can be overridden to provide names of shared libraries to be loaded.
|
||||
@@ -122,14 +125,7 @@ public class SDLActivity extends Activity {
|
||||
* @return arguments for the native application.
|
||||
*/
|
||||
protected String[] getArguments() {
|
||||
Intent intent = getIntent();
|
||||
String sArgv = intent.getStringExtra(in.celest.xash3d.LauncherActivity.ARGV);
|
||||
|
||||
Log.v("ArgvDebug", "Got args: " + sArgv);
|
||||
|
||||
if(sArgv == null || sArgv.isEmpty())
|
||||
return "-dev 3 -log -console".split(" ");
|
||||
else return sArgv.split(" ");
|
||||
return mPref.getString("argv","-dev 3 -log -console").split(" ");
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
@@ -169,7 +165,8 @@ public class SDLActivity extends Activity {
|
||||
SDLActivity.initialize();
|
||||
// So we can call stuff from static callbacks
|
||||
mSingleton = this;
|
||||
|
||||
mPref = this.getSharedPreferences("engine", 0);
|
||||
mUseControls = mPref.getBoolean("controls", false);
|
||||
// Load shared libraries
|
||||
String errorMsgBrokenLib = "";
|
||||
try {
|
||||
@@ -205,6 +202,12 @@ public class SDLActivity extends Activity {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
setenv("XASH3D_BASEDIR", mPref.getString("basedir","/sdcard/xash/"), true);
|
||||
setenv("XASH3D_ENGLIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
|
||||
setenv("XASH3D_GAMELIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
|
||||
setenv("XASH3D_GAMEDIR", "valve", true);
|
||||
|
||||
// Set up the surface
|
||||
mSurface = new SDLSurface(getApplication());
|
||||
@@ -467,7 +470,8 @@ public class SDLActivity extends Activity {
|
||||
int naxes, int nhats, int nballs);
|
||||
public static native int nativeRemoveJoystick(int device_id);
|
||||
public static native String nativeGetHint(String name);
|
||||
|
||||
public static native int setenv(String key, String value, boolean overwrite);
|
||||
|
||||
/**
|
||||
* This method is called by SDL using JNI.
|
||||
*/
|
||||
@@ -965,21 +969,23 @@ class SDLMain implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// Runs SDL_main()
|
||||
if(SDLActivity.mUseControls)
|
||||
{
|
||||
NativeLib engine = new NativeLib();
|
||||
engine.initTouchControls_if(SDLActivity.mSingleton.getFilesDir().toString() + "/",
|
||||
(int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
||||
|
||||
NativeLib engine = new NativeLib();
|
||||
engine.initTouchControls_if(SDLActivity.mSingleton.getFilesDir().toString() + "/",
|
||||
(int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
||||
SDLActivity.controlInterp = new ControlInterpreter(engine,Settings.IDGame.Doom,Settings.gamePadControlsFile,Settings.gamePadEnabled);
|
||||
|
||||
SDLActivity.controlInterp = new ControlInterpreter(engine,Settings.IDGame.Doom,Settings.gamePadControlsFile,Settings.gamePadEnabled);
|
||||
SDLActivity.controlInterp.setScreenSize((int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
||||
|
||||
SDLActivity.controlInterp.setScreenSize((int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
||||
|
||||
TouchControlsSettings.setup(SDLActivity.mSingleton, engine);
|
||||
TouchControlsSettings.loadSettings(SDLActivity.mSingleton);
|
||||
TouchControlsSettings.sendToQuake();
|
||||
|
||||
Settings.copyPNGAssets(SDLActivity.mSingleton,SDLActivity.mSingleton.getFilesDir().toString() + "/",null);
|
||||
TouchControlsSettings.setup(SDLActivity.mSingleton, engine);
|
||||
TouchControlsSettings.loadSettings(SDLActivity.mSingleton);
|
||||
TouchControlsSettings.sendToQuake();
|
||||
|
||||
Settings.copyPNGAssets(SDLActivity.mSingleton,SDLActivity.mSingleton.getFilesDir().toString() + "/",null);
|
||||
|
||||
}
|
||||
SDLActivity.nativeInit(SDLActivity.mSingleton.getArguments());
|
||||
//Log.v("SDL", "SDL thread terminated");
|
||||
}
|
||||
@@ -1189,12 +1195,14 @@ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
|
||||
|
||||
SDLActivity.controlInterp.onTouchEvent(event);
|
||||
return true;
|
||||
if(SDLActivity.mUseControls)
|
||||
{
|
||||
SDLActivity.controlInterp.onTouchEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Ref: http://developer.android.com/training/gestures/multi.html */
|
||||
/*
|
||||
|
||||
final int touchDevId = event.getDeviceId();
|
||||
final int pointerCount = event.getPointerCount();
|
||||
int action = event.getActionMasked();
|
||||
@@ -1262,7 +1270,6 @@ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
|
||||
}
|
||||
|
||||
return true;
|
||||
*/
|
||||
}
|
||||
|
||||
// Sensor events
|
||||
|
||||
Reference in New Issue
Block a user