Use DVR folder on Phone

This commit is contained in:
Simon 2016-03-04 19:42:39 +00:00
parent 9138ea77ab
commit 2f50889ce5
16 changed files with 287 additions and 497 deletions

View file

@ -12,7 +12,7 @@
#define USE_ANDROID 1
/* Define to be the path where Doom WADs are stored */
#define DOOMWADDIR "/sdcard/doom"
//#define DOOMWADDIR "/sdcard/doom"
/* Define if you are building with OpenGL support */
/* #undef GL_DOOM */

View file

@ -87,6 +87,8 @@ static boolean isExtraDDisplay = false;
static void D_QuitNetGame (void);
extern char *doomWADDir;
#ifndef HAVE_NET
doomcom_t* doomcom;
#endif
@ -152,7 +154,7 @@ void D_InitNetGame (void)
while (i--) {
#ifdef USE_ANDROID
char tmp[80];
strcpy(tmp, DOOMWADDIR);
strcpy(tmp, doomWADDir);
strcat(tmp, "/");
strcat(tmp, p);
D_AddFile(tmp, source_net);

View file

@ -107,6 +107,8 @@ float hmdYaw;
float hmdRoll;
float hmdPitch;
char *doomWADDir;
//jff 1/22/98 parms for disabling music and sound
boolean nosfxparm;
@ -1170,10 +1172,12 @@ static void L_SetupConsoleMasks(void) {
// CPhipps - the old contents of D_DoomMain, but moved out of the main
// line of execution so its stack space can be freed
void D_DoomMainSetup(void)
void D_DoomMainSetup(char *wadDir)
{
int p,slot;
doomWADDir = wadDir;
L_SetupConsoleMasks();
// Vladimir setbuf(stdout,NULL);

View file

@ -70,7 +70,7 @@ void D_DoAdvanceDemo (void);
void D_Display(int eye);
void D_PageTicker(void);
void D_StartTitle(void);
void D_DoomMainSetup();
void D_DoomMainSetup(char *wadDir);
void D_DoomStartFrame(float, float, float);
void D_DoomEndFrame(void);
void D_AddFile (const char *file, wad_source_t source);

View file

@ -351,7 +351,7 @@ uid_t stored_euid = -1;
#endif
//int main(int argc, const char * const * argv)
int doom_main(int argc, char **argv)
int doom_main(int argc, char **argv, char *wadDir)
{
#ifdef SECURE_UID
/* First thing, revoke setuid status (if any) */
@ -414,7 +414,7 @@ int doom_main(int argc, char **argv)
/* cphipps - call to video specific startup code */
I_PreInitGraphics();
D_DoomMainSetup();
D_DoomMainSetup(wadDir);
return 0;
}

View file

@ -223,7 +223,8 @@ const char* I_GetVersionString(char* buf, size_t sz)
snprintf(buf,sz,"LxDoom v%s (http://lxdoom.linuxgames.com/)",VERSION);
return buf;
}
/*
/*
* I_Filelength
*
* Return length of an open file.
@ -243,27 +244,10 @@ int I_Filelength(int handle)
return length;
}
// cph - V.Aguilar (5/30/99) suggested return ~/.lxdoom/, creating
// if non-existant
static const char prboom_dir[] = {"/doom"}; // Mead rem extra slash 8/21/03
extern char* doomWADDir;
const char *I_DoomExeDir(void)
{
static char *base;
if (!base) // cache multiple requests
{
char *home = "/sdcard"; //getenv("HOME");
size_t len = strlen(home);
base = malloc(len + strlen(prboom_dir) + 1);
strcpy(base, home);
// I've had trouble with trailing slashes before...
if (base[len-1] == '/') base[len-1] = 0;
strcat(base, prboom_dir);
//mkdir(base, S_IRUSR | S_IWUSR | S_IXUSR); // Make sure it exists
printf("I_DoomExeDir: Create dir %s\n", base);
}
return base;
return doomWADDir;
}
/*
@ -291,48 +275,12 @@ char* I_FindFile(const char* wfname, const char* ext)
//exit (1);
}
// lookup table of directories to search
static const struct {
const char *dir; // directory
const char *sub; // subdirectory
const char *env; // environment variable
const char *(*func)(void); // for I_DoomExeDir
} search[] = {
{NULL}, // current working directory
{NULL, NULL, "DOOMWADDIR"}, // run-time $DOOMWADDIR
{DOOMWADDIR}, // build-time configured DOOMWADDIR
{NULL, "doom", "HOME"}, // ~/doom
{NULL, NULL, "HOME"}, // ~
{NULL, NULL, NULL, I_DoomExeDir}, // config directory
{"/data"},
{"/data/data"},
{"/sdcard/doom"},
{"/sdcard"},
};
int i;
/* Precalculate a length we will need in the loop */
size_t pl = strlen(wfname) + strlen(ext) + 4;
for (i = 0; i < sizeof(search)/sizeof(*search); i++) {
char * p;
const char * d = NULL;
const char * s = NULL;
/* Each entry in the switch sets d to the directory to look in,
* and optionally s to a subdirectory of d */
// switch replaced with lookup table
if (search[i].env) {
if (!(d = getenv(search[i].env)))
continue;
} else if (search[i].func)
d = search[i].func();
else
d = search[i].dir;
s = search[i].sub;
p = malloc((d ? strlen(d) : 0) + (s ? strlen(s) : 0) + pl);
sprintf(p, "%s%s%s%s%s", d ? d : "", (d && !HasTrailingSlash(d)) ? "/" : "",
s ? s : "", (s && !HasTrailingSlash(s)) ? "/" : "",
const char * d = I_DoomExeDir();
char * p = malloc((d ? strlen(d) : 0) + pl);
sprintf(p, "%s%s%s", d ? d : "", (d && !HasTrailingSlash(d)) ? "/" : "",
wfname);
if (access(p,F_OK))
@ -344,7 +292,7 @@ char* I_FindFile(const char* wfname, const char* ext)
}
free(p);
}
return NULL;
}

View file

@ -19,7 +19,7 @@ extern "C" {
* Signature: ([Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_doom_util_Natives_DoomInit
(JNIEnv *, jclass, jobjectArray);
(JNIEnv *, jclass, jobjectArray, jstring);
/*
* Class: doom_util_Natives

View file

@ -117,7 +117,7 @@ int loadJNIMethods(JNIEnv * env)
return 0;
}
extern int doom_main(int argc, char **argv);
extern int doom_main(int argc, char **argv, char *wadDir);
/*
* Class: doom_util_Natives
@ -125,7 +125,7 @@ extern int doom_main(int argc, char **argv);
* Signature: ([Ljava/lang/String;)V
*/
JNIEXPORT jint JNICALL Java_doom_util_Natives_DoomInit
(JNIEnv * env, jclass class, jobjectArray jargv)
(JNIEnv * env, jclass class, jobjectArray jargv, jstring jDoomWADDir)
{
(*env)->GetJavaVM(env, &g_VM);
@ -153,7 +153,17 @@ JNIEXPORT jint JNICALL Java_doom_util_Natives_DoomInit
(*env)->ReleaseStringUTFChars(env, jrow, row);
}
doom_main (clen, args);
const char *row = (*env)->GetStringUTFChars(env, jDoomWADDir, 0);
char *doomWADDir = malloc( strlen(row) + 1);
strcpy (doomWADDir, row);
jni_printf("Main argv[%d]=%s", i, args[i]);
// free java string jrow
(*env)->ReleaseStringUTFChars(env, jrow, row);
doom_main (clen, args, doomWADDir);
return 0;
}

View file

@ -945,11 +945,11 @@ void M_LoadDefaults (void)
#else
sprintf ((char *)defaultfile,
#endif
"%s%s%sboom.cfg", exedir, HasTrailingSlash(exedir) ? "" : "/",
"%s%s%s.cfg", exedir, HasTrailingSlash(exedir) ? "" : "/",
#if ((defined GL_DOOM) && (defined _MSC_VER))
"gl");
#else
"pr");
"DVR");
#endif
}

View file

@ -77,8 +77,8 @@ snd_channels 8
# Video settings
videomode "8"
screen_width 320
screen_height 200
screen_width 640
screen_height 400
use_fullscreen 1
use_doublebuffer 1
translucency 1

Binary file not shown.

View file

@ -1,32 +0,0 @@
package com.drbeef.dvr;
import android.os.Environment;
import java.io.File;
public class DVRConfig {
static public String GetSDCARD()
{
return Environment.getExternalStorageDirectory().getPath();
}
static public String GetWorkingFolder()
{
//Do we use old folder name?
if (new File(GetSDCARD() + "/Q4C").exists())
{
return "Q4C/";
}
else
{
return "DVR/";
}
}
static public String GetFullWorkingFolder()
{
return GetSDCARD() + "/" + GetWorkingFolder();
}
}

View file

@ -13,7 +13,6 @@ import android.opengl.GLES20;
import android.opengl.GLUtils;
import android.opengl.Matrix;
import android.os.Bundle;
import android.os.Message;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
@ -291,6 +290,10 @@ public class MainActivity
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
//At the very least ensure we have a directory containing a config file
copy_asset("DVR.cfg", DoomTools.GetDVRFolder() + "/");
copy_asset("prboom.wad", DoomTools.GetDVRFolder() + "/");
if (!DoomTools.wadsExist()) {
MessageBox("Read this carefully",
"You must install a game file. Tap \"Install WADs\" for auto-install. "
@ -425,9 +428,10 @@ public class MainActivity
if (!mShowingSpashScreen) {
final String[] argv;
String args = new String();
args = "doom -width 640 -height 400 -iwad doom.wad";
args = "doom -iwad " + WADChooser.GetChosenWAD();
argv = args.split(" ");
Natives.DoomInit(argv);
String dvr= DoomTools.GetDVRFolder();
Natives.DoomInit(argv, dvr);
mDVRInitialised = true;
}
}

View file

@ -0,0 +1,14 @@
package com.drbeef.dvr;
/**
* Created by Simon on 04/03/2016.
*/
public class WADChooser {
static String wad = "doom.wad";
public static String GetChosenWAD()
{
return wad;
}
}

View file

@ -11,36 +11,31 @@ import java.util.zip.ZipInputStream;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
public class DoomTools {
public static final String DOOM_FOLDER = "/sdcard/doom" + File.separator ;
// Soundtrack
public static final String DOOM_SOUND_FOLDER = "/sdcard/doom" + File.separator + "sound";
static public String GetSDCARD()
{
return Environment.getExternalStorageDirectory().getPath();
}
// Base server URL
public static final String URL_BASE = "http://prboom4android.googlecode.com/files/";
static public String GetWorkingFolder()
{
return "DVR";
}
// HowTo URL
public static final String URL_HOWTO = "http://code.google.com/p/prboom4android/wiki/HowTo";
// Url prefix that has all Doom files: WADs, Sound + JNI lib
public static final String DOWNLOAD_BASE = URL_BASE + "" ;
// Url prefix that has all Sounds
public static final String SOUND_BASE = DOWNLOAD_BASE + "" ;
static public String GetDVRFolder()
{
return GetSDCARD() + File.separator + GetWorkingFolder();
}
// Game files we can handle
public static final String[] DOOM_WADS = {"freedoom.wad", "freedm.wad"};
/**
* Doom lib. To be downloaded into /data/data/APP_PKG/files
*/
//public static final String DOOM_LIB = "libdoom_jni.so";
public static final String DOOM_LIB = "prboom_jni";
public static final String[] DOOM_WADS =
{"freedoom.wad", "freedm.wad", "doom.wad", "doom2.wad"};
// These are required for the game to run
public static final String REQUIRED_DOOM_WAD = "prboom.wad";
@ -215,87 +210,19 @@ public class DoomTools {
}
static public boolean installConfig(Context ctx) {
File f = new File(DoomTools.DOOM_FOLDER + File.separator);
if(!f.exists())
f.mkdir();
InputStream cfgIn;
try {
cfgIn = ctx.getAssets().open("prboom.cfg.zip");
unzip(cfgIn, new File(DOOM_FOLDER));
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
static public boolean installPrBoom(Context ctx) {
// check of /sdcard/doom exists, if not create it
File f = new File(DoomTools.DOOM_FOLDER + File.separator);
if(!f.exists())
f.mkdir();
InputStream prboomIn;
try {
prboomIn = ctx.getAssets().open("prboom.zip");
unzip(prboomIn, new File(DOOM_FOLDER));
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* SDCARD?
* @return
*/
static public boolean hasSDCard() {
try {
File f = new File(DOOM_FOLDER);
// Does /sdcard/doom exist?
if ( f.exists()) return true;
// Can we write into it?
return f.mkdir();
} catch (Exception e) {
System.err.println(e.toString());
return false;
}
}
/**
* Ping the download server
* @return
*/
static public boolean pingServer() {
try {
WebDownload wd = new WebDownload(URL_BASE);
wd.doGet();
int rc = wd.getResponseCode();
Log.d(TAG, "PingServer Response:" + rc);
return rc == 200;
} catch (Exception e) {
Log.e(TAG, "PingServer: " + e.toString());
return false;
}
}
static public boolean wadExists (int idx) {
final String path = DOOM_FOLDER + File.separator + DOOM_WADS[idx];
final String path = GetDVRFolder() + File.separator + DOOM_WADS[idx];
return new File(path).exists();
}
static public boolean wadExists (String name) {
final String path = DOOM_FOLDER + File.separator + name;
final String path = GetDVRFolder() + File.separator + name;
return new File(path).exists();
}
static public boolean wadsExist() {
for(int i = 0; i < DOOM_WADS.length; i++) {
File f = new File(DOOM_FOLDER + File.separator + DOOM_WADS[i]);
File f = new File(GetDVRFolder() + File.separator + DOOM_WADS[i]);
if(f.exists())
return true;
}
@ -306,20 +233,19 @@ public class DoomTools {
System.exit(code);
}
/**
* Sound present for a WAD?
*/
public static boolean hasSound() {
Log.d(TAG, "Sound folder: " + DOOM_SOUND_FOLDER);
return new File(DOOM_SOUND_FOLDER).exists();
Log.d(TAG, "Sound folder: " + GetDVRFolder() + File.separator + "sound");
return new File(GetDVRFolder() + File.separator + "sound").exists();
}
/**
* Get the sound folder name for a game file
*/
public static File getSoundFolder() {
return new File(DOOM_SOUND_FOLDER);
return new File(GetDVRFolder() + File.separator + "sound");
}
@ -358,36 +284,6 @@ public class DoomTools {
static final String TAG = "DoomTools";
/**
* Ckech 4 sdcard
* @return
*/
public static boolean checkSDCard(Context ctx) {
boolean sdcard = DoomTools.hasSDCard();
if ( ! sdcard) {
//DialogTool.MessageBox(ctx, "No SDCARD", "An SDCARD is required to store game files.");
return false;
}
return true;
}
/**
* Make sure you have a web cn
* @param ctx
* @return
*/
public static boolean checkServer(Context ctx) {
boolean alive = DoomTools.pingServer();
if ( ! alive) {
//DialogTool.MessageBox(ctx, "Sever Ping Failed", "Make sure you have a web connection.");
return false;
}
return true;
}
/**
* Clean sounds
*/
@ -410,60 +306,4 @@ public class DoomTools {
if ( folder.exists() ) folder.delete();
}
/**
* Cleanup game files
*/
private static void deleteWads() {
File folder = new File(DoomTools.DOOM_FOLDER);
if ( !folder.exists()) {
Log.e(TAG, "Error: Doom folder " + folder + " not found.");
return;
}
File[] files = folder.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].exists() )
files[i].delete();
}
if ( folder.exists() ) folder.delete();
}
/**
* Add a default config to DOOM_FOLDER with default key bindings
* @param ctx
*/
// static final String DEFAULT_CFG = "prboom.cfg";
//
// public static void createDefaultDoomConfig(Handler handler, Context ctx) {
// File dest = new File(DOOM_FOLDER + DEFAULT_CFG);
//
// // Skip if config exists
// if ( dest.exists()) {
// Log.w(TAG, "A default Doom config already exists in " + dest);
// return;
// }
//
// try {
// BufferedInputStream is = new BufferedInputStream( ctx.getAssets().open(DEFAULT_CFG));
// FileOutputStream fos = new FileOutputStream(dest);
//
// byte[] buf = new byte [1024];
//
// // let the user know
// Toast(handler, ctx, "Default movement keys: 1AQW");
//
// Log.d(TAG, "Writing a default DOOM config to " + dest);
//
// for (int read = is.read(buf); read != -1; read = is.read(buf)) {
// fos.write(buf,0, read);
// }
//
// } catch (Exception e) {
// Log.e(TAG, "Error saving default DOOm config: " + e.toString());
// }
// }
}

View file

@ -37,7 +37,7 @@ public class Natives
* @param argv
* @return
*/
public static native int DoomInit(String[] argv);
public static native int DoomInit(String[] argv, String wadDir);
/**
* Start frame rendering