Many improvements

- Fixed sound volume control for (bad) music
- Made wad chooser look quite good
- Quit menu responds to A button
This commit is contained in:
Simon 2016-03-07 22:01:18 +00:00
parent e14bb87afb
commit 2dddd6ad40
13 changed files with 125 additions and 175 deletions

View file

@ -1590,7 +1590,7 @@ void D_DoomMainSetup(char *wadDir)
//jff 9/3/98 use logical output routine
lprintf(LO_INFO,"S_Init: Setting up sound.\n");
S_Init(snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ );
S_Init(snd_SfxVolume, snd_MusicVolume);
//jff 9/3/98 use logical output routine
lprintf(LO_INFO,"HU_Init: Setting up heads up display.\n");

View file

@ -638,27 +638,11 @@ void I_ShutdownMusic(void)
void I_InitMusic(void)
{
#ifdef HAVE_MIXER
if (!music_tmp) {
#ifndef _WIN32
music_tmp = strdup("/tmp/prboom-music-XXXXXX");
{
int fd = mkstemp(music_tmp);
if (fd<0) {
lprintf(LO_ERROR, "I_InitMusic: failed to create music temp file %s", music_tmp);
free(music_tmp); return;
} else
close(fd);
}
#else /* !_WIN32 */
music_tmp = strdup("doom.tmp");
#endif
atexit(I_ShutdownMusic);
}
#endif
#ifdef USE_ANDROID
if (!music_tmp) {
music_tmp = strdup("/sdcard/doom/sound/prboom-music-XXXXXX.mid");
char musFilename[256];
sprintf(musFilename, "%s%s", doomWADDir, "/sound/prboom-music-XXXXXX");
music_tmp = strdup(musFilename);
{
int fd = mkstemp(music_tmp);
if (fd<0) {
@ -733,43 +717,6 @@ void I_UnRegisterSong(int handle)
int I_RegisterSong(const void *data, size_t len)
{
#ifdef HAVE_MIXER
MIDI *mididata;
FILE *midfile;
if ( len < 32 )
return 0; // the data should at least as big as the MUS header
if ( music_tmp == NULL )
return 0;
midfile = fopen(music_tmp, "wb");
if ( midfile == NULL ) {
lprintf(LO_ERROR,"Couldn't write MIDI to %s\n", music_tmp);
return 0;
}
/* Convert MUS chunk to MIDI? */
if ( memcmp(data, "MUS", 3) == 0 )
{
UBYTE *mid;
int midlen;
mididata = malloc(sizeof(MIDI));
mmus2mid(data, mididata, 89, 0);
MIDIToMidi(mididata,&mid,&midlen);
M_WriteFile(music_tmp,mid,midlen);
free(mid);
free_mididata(mididata);
free(mididata);
} else {
fwrite(data, len, 1, midfile);
}
fclose(midfile);
music[0] = Mix_LoadMUS(music_tmp);
if ( music[0] == NULL ) {
lprintf(LO_ERROR,"Couldn't load MIDI from %s: %s\n", music_tmp, Mix_GetError());
}
#endif
#ifdef USE_ANDROID
MIDI *mididata;
FILE *midfile;
@ -851,10 +798,6 @@ int writeSoundFile(const char * name, const unsigned char * buffer, size_t len)
char *data;
sprintf(fileName, "%s%s%s%s", doomWADDir, "/sound/", name, ".wav");
//strcpy(fileName, doomWADDir);
//strcpy(fileName, "/sound/");
//strcat(fileName, name);
//strcat(fileName, ".wav");
file = fopen(fileName, "r");
if(!file)

View file

@ -364,20 +364,13 @@ void jni_send_str( const char * text, int level) {
(*g_VM)->AttachCurrentThread(g_VM, &env, NULL);
}
int iSize = strlen(text);
jbyteArray jstr = (*env)-> NewByteArray(env, iSize);
(*env)->SetByteArrayRegion(env, jstr, 0, iSize, (jbyte *) text);
// Call doom.jni.Natives.OnMessage(String)
if (jSendStr) {
(*env)->CallStaticVoidMethod(env, jNativesCls
, jSendStr
, jstr
, jSendStr
, (*env)->NewStringUTF(env, text)
, (jint) level );
}
(*env)->DeleteLocalRef(env, jstr);
}
/**

View file

@ -1030,7 +1030,7 @@ int quitsounds2[8] =
static void M_QuitResponse(int ch)
{
if (ch != 'y')
if (ch != 'y' && ch != 0x0d)
return;
if ((!netgame || demoplayback) // killough 12/98
&& !nosfxparm && snd_card) // avoid delay if no sound card
@ -4205,7 +4205,7 @@ boolean M_Responder (event_t* ev) {
if (messageToPrint) {
if (messageNeedsInput == true &&
!(ch == ' ' || ch == 'n' || ch == 'y' || ch == key_escape)) // phares
!(ch == ' ' || ch == 'n' || ch == 'y' || ch == key_escape || ch == 0x0d)) // phares
return false;
menuactive = messageLastMenuActive;

View file

@ -297,8 +297,8 @@ default_t defaults[] =
{"pitched_sounds",{&pitched_sounds},{0},0,1, // killough 2/21/98
def_bool,ss_none}, // enables variable pitch in sound effects (from id's original code)
{"samplerate",{&snd_samplerate},{22050},11025,48000, def_int,ss_none},
{"sfx_volume",{&snd_SfxVolume},{8},0,15, def_int,ss_none},
{"music_volume",{&snd_MusicVolume},{8},0,15, def_int,ss_none},
{"sfx_volume",{&snd_SfxVolume},{15},0,15, def_int,ss_none},
{"music_volume",{&snd_MusicVolume},{15},0,15, def_int,ss_none},
{"mus_pause_opt",{&mus_pause_opt},{2},0,2, // CPhipps - music pausing
def_int, ss_none}, // 0 = kill music when paused, 1 = pause music, 2 = let music continue
{"snd_channels",{&default_numChannels},{8},1,32,

View file

@ -467,6 +467,8 @@ void S_StartMusic(int m_id)
// JNI Callback
void jni_start_music (const char * name, int loop);
extern char* music_tmp;
void S_ChangeMusic(int musicnum, int looping)
{
musicinfo_t *music;
@ -534,10 +536,10 @@ void S_ChangeMusic(int musicnum, int looping)
// play it
//printf("S_ChangeMusic Playing %s handle: %d, looping: %d\n", music->name, music->handle, looping);
__android_log_print(ANDROID_LOG_ERROR, "DVR", "Starting Music = %s", music->name);
jni_start_music (music->name, looping);
__android_log_print(ANDROID_LOG_INFO, "DVR", "Starting Music = %s", music->name);
jni_start_music (music_tmp, looping);
I_PlaySong(music->handle, looping);
//I_PlaySong(music->handle, looping);
mus_playing = music;
}

View file

@ -70,8 +70,8 @@ sound_card -1
music_card -1
pitched_sounds 0
samplerate 22050
sfx_volume 8
music_volume 8
sfx_volume 15
music_volume 15
mus_pause_opt 2
snd_channels 8

Binary file not shown.

View file

@ -27,7 +27,6 @@ import com.google.vrtoolkit.cardboard.Viewport;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
@ -176,6 +175,9 @@ public class MainActivity
if(!folder.exists())
folder.mkdirs();
//Clean up sound folder
DoomTools.deleteSounds();
//See if user is trying to use command line params
BufferedReader br;
try {
@ -300,7 +302,7 @@ public class MainActivity
if (!mShowingSpashScreen) {
final String[] argv;
String args = new String();
args = "doom -iwad " + mWADChooser.GetChosenWAD() + " " + commandLineParams;
args = "doom -iwad " + mWADChooser.GetSelectedWADName() + " " + commandLineParams;
argv = args.split(" ");
String dvr= DoomTools.GetDVRFolder();
Natives.DoomInit(argv, dvr);
@ -374,11 +376,12 @@ public class MainActivity
// Object first appears directly in front of user.
Matrix.setIdentityM(openGL.modelScreen, 0);
Matrix.translateM(openGL.modelScreen, 0, 0, 0, -openGL.screenDistance);
Matrix.scaleM(openGL.modelScreen, 0, openGL.screenScale, openGL.screenScale, 1.0f);
Matrix.scaleM(openGL.modelScreen, 0, openGL.screenScale*1.5f, openGL.screenScale*1.5f, 1.0f);
// Set the position of the screen
if (mShowingSpashScreen) {
float mAngle = 360.0f * (float)((System.currentTimeMillis() % 2000) / 2000.0f);
float mAngle = 180.0f * (float)((System.currentTimeMillis() % 2000) / 2000.0f);
if (mAngle > 90.0f) mAngle += 180.0f;
Matrix.rotateM(openGL.modelScreen, 0, mAngle, 0.0f, 1.0f, 0.0f);
}
@ -493,7 +496,7 @@ public class MainActivity
mPlayer.release();
mShowingSpashScreen = false;
mWADChooser.Initialise();
mWADChooser.Initialise(this.getAssets());
}
}
@ -502,6 +505,12 @@ public class MainActivity
int keyCode = event.getKeyCode();
int action = event.getAction();
//Following buttons must not be handled here
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
)
return false;
if (!mShowingSpashScreen &&
mWADChooser.choosingWAD())
{
@ -562,13 +571,6 @@ public class MainActivity
}
}
//Following buttons must not be handled here
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL
)
return false;
if (mDVRInitialised) {
if (action == KeyEvent.ACTION_DOWN) {
Natives.keyEvent(Natives.EV_KEYDOWN,
@ -603,14 +605,6 @@ public class MainActivity
// 2 - Samsung gamepad that uses different axes for right stick
int gamepadType = 0;
int lTrigAction = KeyEvent.ACTION_UP;
int rTrigAction = KeyEvent.ACTION_UP;
boolean wDown = false;
boolean aDown = false;
boolean sDown = false;
boolean dDown = false;
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
int source = event.getSource();
@ -619,9 +613,6 @@ public class MainActivity
{
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
float x = getCenteredAxis(event, MotionEvent.AXIS_X);
float y = -getCenteredAxis(event, MotionEvent.AXIS_Y);
float z = getCenteredAxis(event, MotionEvent.AXIS_Z);
float rz = -getCenteredAxis(event, MotionEvent.AXIS_RZ);
//For the samsung game pad (uses different axes for the second stick)
@ -732,7 +723,7 @@ public class MainActivity
}
@Override
public void OnInfoMessage(final String msg, final int type) {
public void OnInfoMessage(String msg, final int type) {
Log.i(TAG, "**Doom Message: " + msg);
}

View file

@ -7,6 +7,7 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.opengl.GLES20;
import android.opengl.Matrix;
@ -30,6 +31,19 @@ public class WADChooser {
OpenGL openGL = null;
List<String> wads = new ArrayList<String>();
Map<String, String> wadThumbnails = new HashMap<String, String>();
Typeface type;
enum Transition
{
ready,
move_left,
moving_left,
move_right,
moving_right
};
Transition mCurrentTransition = Transition.ready;
long mTransitionStart = -1;
private int selectedWAD = 0;
@ -37,7 +51,7 @@ public class WADChooser {
this.openGL = openGL;
}
public void Initialise()
public void Initialise(AssetManager assets)
{
wadThumbnails.put(new String("doom.wad"), new String("d1.png"));
wadThumbnails.put(new String("doom2.wad"), new String("d2.png"));
@ -45,6 +59,8 @@ public class WADChooser {
wadThumbnails.put(new String("freedoom1.wad"), new String("fd1.png"));
wadThumbnails.put(new String("freedoom2.wad"), new String("fd2.png"));
type = Typeface.createFromAsset(assets, "fonts/DooM.ttf");
File[] files = new File(DoomTools.GetDVRFolder()).listFiles();
for (File file : files) {
@ -69,22 +85,24 @@ public class WADChooser {
mChoosingWAD = false;
}
public String GetChosenWAD() {
public String GetSelectedWADName() {
return wads.get(selectedWAD);
}
public void MoveNext()
{
selectedWAD++;
if (selectedWAD == wads.size())
selectedWAD = 0;
if (mCurrentTransition == Transition.ready) {
mCurrentTransition = Transition.move_right;
mTransitionStart = System.currentTimeMillis();
}
}
public void MovePrev()
{
selectedWAD--;
if (selectedWAD < 0)
selectedWAD = wads.size()-1;
if (mCurrentTransition == Transition.ready) {
mCurrentTransition = Transition.move_left;
mTransitionStart = System.currentTimeMillis();
}
}
void DrawWADName(Context ctx)
@ -97,34 +115,69 @@ public class WADChooser {
bitmap.eraseColor(0);
Paint paint = new Paint();
paint.setTextSize(20);
paint.setTypeface(type);
paint.setAntiAlias(true);
paint.setARGB(0xff, 0xff, 0x20, 0x00);
if (wadThumbnails.containsKey(GetChosenWAD().toLowerCase())) {
if (wadThumbnails.containsKey(GetSelectedWADName().toLowerCase())) {
try {
AssetManager assets = ctx.getAssets();
InputStream in = assets.open("thumbnails/" + wadThumbnails.get(GetChosenWAD().toLowerCase()));
InputStream in = assets.open("thumbnails/" + wadThumbnails.get(GetSelectedWADName().toLowerCase()));
Bitmap thumbnail = BitmapFactory.decodeStream(in);
in.close();
canvas.drawBitmap(thumbnail, null, new Rect(0, 0, 256, 200), paint);
canvas.drawBitmap(thumbnail, null, new Rect(36, 36, 218, 214), paint);
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
canvas.drawText("no thumbnail", 42, 114, paint);
}
// Draw the text
paint.setTextSize(20);
if (mCurrentTransition == Transition.ready) {
canvas.drawText("Choose Wad", 32, 24, paint);
canvas.drawText(GetSelectedWADName(), 32, 256, paint);
paint.setAntiAlias(true);
paint.setARGB(0xff, 0xff, 0x20, 0x00);
canvas.drawText("<- " + GetChosenWAD() + " ->", 24, 220, paint);
//Draw arrows
paint.setTextSize(36);
paint.setARGB(0xff, 0x20, 0x20, 0xff);
canvas.drawText("<", 0, 116, paint);
canvas.drawText(">", 228, 116, paint);
}
openGL.CopyBitmapToTexture(bitmap, openGL.fbo.ColorTexture[0]);
}
public void onDrawEye(Eye eye, Context ctx) {
if (System.currentTimeMillis() - mTransitionStart > 250) {
if (mCurrentTransition == Transition.move_right) {
selectedWAD++;
if (selectedWAD == wads.size())
selectedWAD = 0;
mCurrentTransition = Transition.moving_right;
}
if (mCurrentTransition == Transition.move_left) {
selectedWAD--;
if (selectedWAD < 0)
selectedWAD = wads.size() - 1;
mCurrentTransition = Transition.moving_left;
}
}
if (System.currentTimeMillis() - mTransitionStart > 500)
{
mTransitionStart = -1;
mCurrentTransition = Transition.ready;
}
DrawWADName(ctx);
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
@ -160,6 +213,18 @@ public class WADChooser {
Matrix.setIdentityM(openGL.modelScreen, 0);
Matrix.translateM(openGL.modelScreen, 0, 0, 0, -openGL.screenDistance);
Matrix.scaleM(openGL.modelScreen, 0, openGL.screenScale, openGL.screenScale, 1.0f);
if (mTransitionStart != -1) {
long transVal = System.currentTimeMillis() - mTransitionStart;
if (mCurrentTransition == Transition.moving_left ||
mCurrentTransition == Transition.move_left)
transVal = 500 - transVal;
float mAngle = 180.0f * (float) (((float)transVal) / 500.0f);
if (mAngle > 90.0f)
mAngle += 180.0f;
Matrix.rotateM(openGL.modelScreen, 0, mAngle, 0.0f, 1.0f, 0.0f);
}
Matrix.multiplyMM(openGL.modelView, 0, openGL.view, 0, openGL.modelScreen, 0);
Matrix.multiplyMM(openGL.modelViewProjection, 0, perspective, 0, openGL.modelView, 0);
GLES20.glVertexAttribPointer(openGL.positionParam, 3, GLES20.GL_FLOAT, false, 0, openGL.screenVertices);

View file

@ -23,7 +23,6 @@ public class AudioClip
name = ctx.getResources().getResourceName(resID);
mPlayer = MediaPlayer.create(ctx, resID);
//mPlayer.setVolume(1000, 1000);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
@Override
@ -76,7 +75,9 @@ public class AudioClip
mPlaying = true;
//Log.d(TAG, "Play " + name + " vol=" + vol);
mPlayer.setVolume( (float)Math.log10(vol), (float)Math.log(vol));
float log1=1.0f - (float)(Math.log(101-vol)/Math.log(101));
mPlayer.setVolume(log1, log1);
mPlayer.start();
}
}
@ -119,7 +120,8 @@ public class AudioClip
*/
public void setVolume (int vol) {
if ( mPlayer != null) {
mPlayer.setVolume((float)Math.log10(vol), (float)Math.log10(vol));
float log1=1.0f - (float)(Math.log(101-vol)/Math.log(101));
mPlayer.setVolume(log1, log1);
}
}
}

View file

@ -41,7 +41,6 @@ public class AudioManager
private AudioManager(Context ctx) {
mContext = ctx;
preloadSounds(ctx);
}
/**
@ -63,7 +62,7 @@ public class AudioManager
}
else {
// load clip from disk
File folder = DoomTools.getSoundFolder(); //DoomTools.DOOM_WADS[mWadIdx]);
File folder = DoomTools.GetSoundFolder(); //DoomTools.DOOM_WADS[mWadIdx]);
File sound = new File(folder.getAbsolutePath() + File.separator + key);
if ( ! sound.exists()) {
@ -100,47 +99,7 @@ public class AudioManager
mClipCount++;
}
}
/**
* PreLoad the most used sounds into a hash map
* @param ctx
* @return
*/
public void preloadSounds(Context ctx)
{
// These are some common sound keys pre-loaded for speed
String [] names = new String[] {"DSPISTOL.wav" // pistol
, "DSDOROPN.wav", "DSDORCLS.wav" // doors open/close
, "DSPSTOP.wav", "DSSWTCHN.wav", "DSSWTCHX.wav"
, "DSITEMUP.wav", "DSPOSACT.wav"
, "DSPOPAIN.wav", "DSPODTH1.wav"
, "DSSHOTGN.wav" };
// Sound folder
File folder = DoomTools.getSoundFolder();
if ( !folder.exists()) {
Log.e(TAG, "Error: Sound folder " + folder + " not found.");
return;
}
// WAVs
File[] files = new File[names.length];
for (int i = 0; i < files.length; i++ ) {
files[i] = new File(folder + File.separator + names[i]);
if ( files[i].exists()) {
//Log.d(TAG "PreLoading sound " + files[i].getName() + " uri=" + Uri.fromFile(files[i]));
mSounds.put(files[i].getName(), new AudioClip(ctx, Uri.fromFile(files[i])));
}
else
System.err.println("AudioMgr:" + files[i] + " not found");
}
}
/**
* Start background music
* @param ctx
@ -149,8 +108,8 @@ public class AudioManager
public void startMusic (Context ctx , String key, int loop) {
if(mPaused)
return;
// Sound folder
File sound = new File(DoomTools.GetDVRFolder() + File.separator + key + ".mp3");
// Sound file
File sound = new File(key);
if ( !sound.exists()) {
Log.e(TAG, "Unable to find music " + sound);
@ -176,9 +135,8 @@ public class AudioManager
* @param key
*/
public void stopMusic (String key) {
// Sound folder
File folder = DoomTools.getSoundFolder(); //DoomTools.DOOM_WADS[mWadIdx]);
Uri sound = Uri.fromFile(new File(folder + File.separator + "d1" + key + ".mp3"));
File file = new File(DoomTools.GetDVRFolder() + File.separator + key + ".mid");
Uri sound = Uri.fromFile(file);
if ( music != null ) {
if ( !sound.equals(Uri.parse(music.getName()))) {

View file

@ -1,7 +1,6 @@
package doom.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -10,7 +9,6 @@ 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;
@ -212,7 +210,7 @@ public class DoomTools {
/**
* Get the sound folder name for a game file
*/
public static File getSoundFolder() {
public static File GetSoundFolder() {
return new File(GetDVRFolder() + File.separator + "sound");
}
@ -253,9 +251,9 @@ public class DoomTools {
/**
* Clean sounds
*/
private static void deleteSounds() //int wadIdx)
public static void deleteSounds() //int wadIdx)
{
File folder = getSoundFolder(); //DoomTools.DOOM_WADS[wadIdx]);
File folder = GetSoundFolder();
if ( !folder.exists()) {
Log.e(TAG, "Error: Sound folder " + folder + " not found.");
@ -269,7 +267,5 @@ public class DoomTools {
if (files[i].exists() )
files[i].delete();
}
if ( folder.exists() ) folder.delete();
}
}