sound support for mapster32. right now a sound console.

git-svn-id: https://svn.eduke32.com/eduke32@1247 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2009-03-15 22:58:20 +00:00
parent 287f173551
commit 8aa2923529
5 changed files with 1015 additions and 5 deletions

View File

@ -23,7 +23,7 @@ BUILD32_ON_64 = 0
RANCID_NETWORKING = 1
# Debugging/Build options
RELEASE?=1
RELEASE?=0
NOSOUND?=0
USE_OPENAL ?= 1
OPTLEVEL?=2
@ -150,7 +150,8 @@ GAMEOBJS=$(OBJ)/game.$o \
$(OBJ)/grpscan.$o \
$(JMACTOBJ)
EDITOROBJS=$(OBJ)/astub.$o
EDITOROBJS=$(OBJ)/astub.$o \
$(OBJ)/mathutil.$o
# PLATFORM SPECIFIC SETTINGS
@ -194,18 +195,20 @@ endif
ifeq ($(RENDERTYPE),SDL)
ifeq (0,$(SDL_FRAMEWORK))
OURCFLAGS+= $(subst -Dmain=SDL_main,,$(shell $(SDLCONFIG) --cflags))
OURCFLAGS+= $(subst -Dmain=SDL_main,,$(shell $(SDLCONFIG) --cflags))
else
OURCFLAGS += -DSDL_FRAMEWORK
endif
ifneq ($(PLATFORM),WINDOWS)
AUDIOLIBOBJ=$(AUDIOLIB_MUSIC_SDL) $(AUDIOLIB_FX_SDL) $(OBJ)/sounds.$o
AUDIOLIBOBJ_M32=$(AUDIOLIB_FX_SDL) $(OBJ)/sounds_mapster32.$o
ifeq (0,$(SDL_FRAMEWORK))
LIBS+= -lSDL_mixer
endif
else
AUDIOLIBOBJ=$(AUDIOLIB_MUSIC_STUB) $(AUDIOLIB_FX_STUB) $(OBJ)/sounds.$o
AUDIOLIBOBJ_M32=$(AUDIOLIB_FX_STUB) $(OBJ)/sounds_mapster32.$o
endif
ifeq (1,$(HAVE_GTK2))
@ -219,14 +222,17 @@ ifeq ($(RENDERTYPE),SDL)
endif
ifeq ($(RENDERTYPE),WIN)
AUDIOLIBOBJ=$(AUDIOLIB_MUSIC) $(AUDIOLIB_FX) $(OBJ)/sounds.$o
AUDIOLIBOBJ=$(AUDIOLIB_MUSIC) $(AUDIOLIB_FX) $(OBJ)/sounds.$o
AUDIOLIBOBJ_M32=$(AUDIOLIB_FX) $(OBJ)/sounds_mapster32.$o
endif
ifeq ($(NOSOUND),1)
AUDIOLIBOBJ=$(AUDIOLIB_MUSIC_STUB) $(AUDIOLIB_FX_STUB) $(OBJ)/sounds.$o
AUDIOLIBOBJ_M32=$(AUDIOLIB_FX_STUB) $(OBJ)/sounds_mapster32.$o
endif
GAMEOBJS+= $(AUDIOLIBOBJ)
EDITOROBJS+= $(AUDIOLIBOBJ_M32)
OURCFLAGS+= $(BUILDCFLAGS)
OURCXXFLAGS+= $(BUILDCFLAGS)

View File

@ -38,6 +38,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "scriptfile.h"
#include "crc32.h"
#include "sounds_mapster32.h"
#include "fx_man.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ -58,6 +61,14 @@ static int32_t lastsave = -180*60;
static int32_t NoAutoLoad = 0;
int32_t spnoclip=1;
// Sound in Mapster32
static char defaultgamecon[BMAX_PATH] = "game.con";
static char *gamecon = defaultgamecon;
sound_t g_sounds[MAXSOUNDS];
static int16_t g_definedsndnum[MAXSOUNDS]; // maps parse order index to g_sounds index
static int16_t g_sndnum[MAXSOUNDS]; // maps current order index to g_sounds index
int32_t g_numsounds = 0;
#if !defined(_WIN32)
static int32_t usecwd = 0;
#endif
@ -1569,6 +1580,216 @@ ENDFOR1:
keystatus[KEYSC_ESC] = keystatus[KEYSC_Q] = keystatus[KEYSC_F1] = 0;
}
}
#define SOUND_NUMDISPLINES IHELP_NUMDISPLINES
extern char SoundToggle;
static void SoundDisplay()
{
if (g_numsounds <= 0) return;
overridepm16y = 3*STATUS2DSIZ;
{
int32_t i, j;
// cursnd is the first displayed line, cursnd+curofs is where the cursor is
static int32_t cursnd=0, curofs=0;
char disptext[SOUND_NUMDISPLINES][80];
begindrawing();
clearbuf((char *)(frameplace + (ydim-overridepm16y)*bytesperline), (bytesperline*(overridepm16y-25)) >> 2, 0L);
drawline16(0,ydim-overridepm16y,xdim-1,ydim-overridepm16y,editorcolors[1]);
Bsprintf(tempbuf, "Sounds Listing");
printext16(9L,ydim2d-overridepm16y+9L,editorcolors[4],-1,tempbuf,0);
printext16(8L,ydim2d-overridepm16y+8L,editorcolors[12],-1,tempbuf,0);
enddrawing();
SoundToggle = 1;
while (keystatus[KEYSC_ESC]==0 && keystatus[KEYSC_Q]==0 && keystatus[KEYSC_F2]==0)
{
if (handleevents())
{
if (quitevent) quitevent = 0;
}
idle();
if (keystatus[KEYSC_G]) // goto specified sound#
{
keystatus[KEYSC_G]=0;
printmessage16(" ");
Bsprintf(tempbuf, "Goto sound#: ");
j = getnumber16(tempbuf, 0, g_numsounds-1, 0);
for (i=0; i<g_numsounds; i++)
if (g_sndnum[i]==j)
break;
if (i != g_numsounds)
{
if (i<SOUND_NUMDISPLINES)
cursnd = 0, curofs = i;
else if (i>=g_numsounds-SOUND_NUMDISPLINES)
cursnd = g_numsounds-SOUND_NUMDISPLINES, curofs = i-cursnd;
else
curofs = SOUND_NUMDISPLINES/2, cursnd = i-curofs;
}
}
else if (keystatus[KEYSC_UP]) // scroll up
{
keystatus[KEYSC_UP]=0;
if (curofs>0) curofs--;
else if (cursnd>0) cursnd--;
}
else if (keystatus[KEYSC_DOWN]) // scroll down
{
keystatus[KEYSC_DOWN]=0;
if (curofs<SOUND_NUMDISPLINES-1 && cursnd+curofs<g_numsounds-1)
curofs++;
else if (cursnd+SOUND_NUMDISPLINES < g_numsounds)
cursnd++;
}
else if (keystatus[KEYSC_PGUP]) // scroll one page up
{
keystatus[KEYSC_PGUP]=0;
i=SOUND_NUMDISPLINES;
while (i>0 && curofs>0)
i--, curofs--;
while (i>0 && cursnd>0)
i--, cursnd--;
}
else if (keystatus[KEYSC_PGDN]) // scroll one page down
{
keystatus[KEYSC_PGDN]=0;
i=SOUND_NUMDISPLINES;
while (i>0 && curofs<SOUND_NUMDISPLINES-1 && cursnd+curofs<g_numsounds-1)
i--, curofs++;
while (i>0 && cursnd+SOUND_NUMDISPLINES < g_numsounds)
i--, cursnd++;
}
else if (keystatus[KEYSC_SPACE] || keystatus[KEYSC_ENTER]) // play/stop sound
{
int32_t j = cursnd+curofs;
int32_t k = g_sndnum[j];
keystatus[KEYSC_SPACE] = keystatus[KEYSC_ENTER] = 0;
if (S_CheckSoundPlaying(0, k) > 0)
S_StopSound(k);
else
S_PlaySound(k);
}
else if (keystatus[KEYSC_HOME]) // goto first sound#
{
keystatus[KEYSC_HOME]=0;
cursnd = curofs = 0;
}
else if (keystatus[KEYSC_END]) // goto last sound#
{
keystatus[KEYSC_END]=0;
if ((cursnd=g_numsounds-SOUND_NUMDISPLINES) >= 0)
curofs=SOUND_NUMDISPLINES-1;
else
{
cursnd = 0;
curofs = g_numsounds-1;
}
}
else if (keystatus[KEYSC_S]) // sorting
{
char ch, bad=0;
i=0;
bflushchars();
while (bad == 0)
{
Bsprintf(tempbuf,"Sort by: (N)um d(E)f (F)ile (R) (M) (D) (P) (G)");
printmessage16(tempbuf);
showframe(1);
if (handleevents())
{
if (quitevent) quitevent = 0;
}
idle();
ch = bgetchar();
if (keystatus[1]) bad = 1;
else if (ch == 'n' || ch == 'e' || ch == 'f' || ch == 'r' ||
ch == 'm' || ch == 'd' || ch == 'p' || ch == 'g')
{
bad = 2;
// sort_sounds(ch);
}
}
if (bad==1)
{
keystatus[KEYSC_ESC] = keystatus[KEYSC_Q] = keystatus[KEYSC_F2] = 0;
}
if (bad==2)
{
keystatus[KEYSC_N] = keystatus[KEYSC_E] = keystatus[KEYSC_F] = keystatus[KEYSC_R] =
keystatus[KEYSC_M] = keystatus[KEYSC_D] = keystatus[KEYSC_P] = keystatus[KEYSC_G] = 0;
}
}
clearmidstatbar16();
printmessage16(" FILE NAME PITCH RANGE PRI FLAGS VOLUME");
for (i=0; j=cursnd+i, i<SOUND_NUMDISPLINES && j<g_numsounds; i++)
{
int32_t l, k=g_sndnum[j];
sound_t *snd=&g_sounds[k];
char *cp;
Bsprintf(disptext[i],
"%4d .................... ................ %6d:%-6d %3d %c%c%c%c%c %6d",
// 5678901234567890X23456789012345678901234567
k, snd->ps, snd->pe, snd->pr,
snd->m&1 ? 'R':'-', snd->m&2 ? 'M':'-', snd->m&4 ? 'D':'-',
snd->m&8 ? 'P':'-', snd->m&16 ? 'G':'-', snd->vo);
for (l = Bsnprintf(disptext[i]+5, 20, snd->definedname); l<20; l++)
disptext[i][5+l] = ' ';
if (snd->filename)
{
l = strlen(snd->filename);
if (l<=16)
cp = snd->filename;
else
cp = snd->filename + l-16;
for (l = Bsnprintf(disptext[i]+26, 16, cp); l<16; l++)
disptext[i][26+l] = ' ';
}
printext16(8, ydim-overridepm16y+28+i*9,
S_CheckSoundPlaying(-1, k) ? editorcolors[2] : editorcolors[10],
j==cursnd+curofs ? editorcolors[1] : -1,
disptext[i], 0);
}
showframe(1);
}
clearmidstatbar16();
overridepm16y = -1;
i=ydim16;
ydim16=ydim;
drawline16(0,ydim-STATUS2DSIZ,xdim-1,ydim-STATUS2DSIZ,editorcolors[1]);
ydim16=i;
printmessage16("");
showframe(1);
FX_StopAllSounds();
S_ClearSoundLocks();
SoundToggle = 0;
keystatus[KEYSC_ESC] = keystatus[KEYSC_Q] = keystatus[KEYSC_F2] = 0;
}
}
// PK_ ^^^^
static void Show3dText(char *name)
@ -6738,6 +6959,15 @@ static void Keys2d(void)
}
}
if (keystatus[KEYSC_F2])
{
keystatus[KEYSC_F2]=0;
clearmidstatbar16();
if (g_numsounds > 0)
SoundDisplay();
}
getpoint(searchx,searchy,&mousxplc,&mousyplc);
ppointhighlight = getpointhighlight(mousxplc,mousyplc, ppointhighlight);
@ -8037,6 +8267,8 @@ enum
T_MAPRANGEA,
T_OFFSET,
T_OFFSETA,
T_DEFINESOUND,
};
typedef struct
@ -8482,6 +8714,167 @@ int32_t loadtilegroups(char *fn)
return 0;
}
/// vvv Parse CON files partially to get sound definitions
int32_t parseconsounds(scriptfile *script)
{
int32_t tokn;
char *cmdtokptr;
int32_t numsounds=0, num_invalidsounds=0;
tokenlist cstokens[] =
{
{ "include", T_INCLUDE },
{ "#include", T_INCLUDE },
{ "define", T_DEFINE },
{ "#define", T_DEFINE },
{ "definesound", T_DEFINESOUND },
};
while (1)
{
tokn = getatoken(script,cstokens,sizeof(cstokens)/sizeof(tokenlist));
cmdtokptr = script->ltextptr;
switch (tokn)
{
case T_INCLUDE:
{
char *fn;
if (!scriptfile_getstring(script,&fn))
{
scriptfile *included;
included = scriptfile_fromfile(fn);
if (!included)
{
initprintf("Warning: Failed including %s on line %s:%d\n",
fn, script->filename,scriptfile_getlinum(script,cmdtokptr));
}
else
{
numsounds += parseconsounds(included);
scriptfile_close(included);
}
}
break;
}
case T_DEFINE:
{
char *name;
int32_t number;
if (scriptfile_getstring(script,&name)) break;
if (scriptfile_getsymbol(script,&number)) break;
if (scriptfile_addsymbolvalue(name,number) < 0)
initprintf("Warning: Symbol %s was NOT redefined to %d on line %s:%d\n",
name,number,script->filename,scriptfile_getlinum(script,cmdtokptr));
break;
}
case T_DEFINESOUND:
{
char *definedname, *filename;
int32_t sndnum, ps, pe, pr, m, vo;
int32_t slen;
if (scriptfile_getsymbol(script, &sndnum)) break;
definedname = Bstrdup(script->ltextptr);
if (!definedname) return -1;
if (sndnum < 0 || sndnum >= MAXSOUNDS)
{
initprintf("Warning: invalid sound definition %s (sound number < 0 or >= MAXSOUNDS) on line %s:%d\n",
definedname, script->filename,scriptfile_getlinum(script,cmdtokptr));
num_invalidsounds++;
break;
}
if (scriptfile_getstring(script, &filename))
{
Bfree(definedname);
num_invalidsounds++;
break;
}
slen = strlen(filename);
if (slen >= BMAX_PATH)
{
initprintf("Warning: invalid sound definition %s (filename too long) on line %s:%d\n",
definedname, script->filename,scriptfile_getlinum(script,cmdtokptr));
Bfree(definedname);
num_invalidsounds++;
break;
}
if (g_sounds[sndnum].filename == NULL)
g_sounds[sndnum].filename = Bcalloc(BMAX_PATH,sizeof(uint8_t));
// do other callers ever mess with g_sounds[].filename?
if (!g_sounds[sndnum].filename)
{
Bfree(definedname);
return -1;
}
Bmemcpy(g_sounds[sndnum].filename, filename, slen+1);
if (scriptfile_getnumber(script, &ps)) goto BAD;
if (scriptfile_getnumber(script, &pe)) goto BAD;
if (scriptfile_getnumber(script, &pr)) goto BAD;
if (scriptfile_getnumber(script, &m)) goto BAD;
if (scriptfile_getnumber(script, &vo)) goto BAD;
if (0)
{
BAD:
Bfree(definedname);
Bfree(g_sounds[sndnum].filename);
g_sounds[sndnum].filename = NULL;
num_invalidsounds++;
break;
}
g_sounds[sndnum].definedname = definedname; // we want to keep it for display purposes
g_sounds[sndnum].ps = ps;
g_sounds[sndnum].pe = pe;
g_sounds[sndnum].pr = pr;
g_sounds[sndnum].m = m;
g_sounds[sndnum].vo = vo;
g_sndnum[numsounds] = g_definedsndnum[numsounds] = sndnum;
numsounds++;
break;
}
case T_EOF:
goto END;
default:
break;
}
}
END:
return numsounds;
}
int32_t loadconsounds(char *fn)
{
scriptfile *script;
int32_t ret;
initprintf("Loading sounds from '%s'\n",fn);
script = scriptfile_fromfile(fn);
if (!script)
{
initprintf("Error loading sounds: file '%s' not found.\n", fn);
return -1;
}
ret = parseconsounds(script);
if (ret == 0)
initprintf("'%s' doesn't contain sound definitions. No sounds loaded.\n", fn);
else
initprintf("Loaded %d sound definitions.\n", ret);
scriptfile_close(script);
scriptfile_clearsymbols();
return ret;
}
/// ^^^
int32_t ExtInit(void)
{
int32_t rv = 0;
@ -8678,6 +9071,13 @@ int32_t ExtInit(void)
loadtilegroups("tiles.cfg");
g_numsounds = loadconsounds(gamecon);
if (g_numsounds > 0)
{
if (S_SoundStartup() != 0)
S_SoundShutdown();
}
ReadHelpFile("m32help.hlp");
return rv;
@ -8715,6 +9115,7 @@ void ExtUnInit(void)
{
int32_t i;
// setvmode(0x03);
S_SoundShutdown();
uninitgroupfile();
writesetup(setupfilename);

View File

@ -31,7 +31,7 @@ Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com)
#include <stdio.h>
#include <stdlib.h>
#include <duke3d.h>
//#include <duke3d.h>
#include "multivoc.h"
#include "ll_man.h"
#include "fx_man.h"
@ -43,6 +43,9 @@ Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com)
static unsigned FX_MixRate;
static char tempbuf[2048];
extern void initprintf(const char *, ...);
int32_t FX_SoundDevice = -1;
int32_t FX_ErrorCode = FX_Ok;
int32_t FX_Installed = FALSE;

View File

@ -0,0 +1,563 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
Copyright (C) 2004, 2007 - EDuke32 developers
This file is part of EDuke32
EDuke32 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//-------------------------------------------------------------------------
// Stripped sounds.c for use in Mapster32, breaks all ties to game & music
//#include <conio.h>
#include <stdio.h>
#include <string.h>
#include "types.h"
#include "fx_man.h"
//#include "music.h"
//#include "duke3d.h"
//#include "util_lib.h"
#include "osd.h"
//#include "compat.h"
#include "cache1d.h"
#include "macros.h"
#include "mathutil.h"
#include "build.h" // vec3_t
#ifdef _WIN32
#ifdef USE_OPENAL
#include "openal.h"
#endif
#endif
#include "sounds_mapster32.h"
#define LOUDESTVOLUME 150
#define MUSICANDSFX 5
static char SM32_havesound = 0;
extern sound_t g_sounds[MAXSOUNDS];
char SoundToggle = 0;
int32_t backflag,g_numEnvSoundsPlaying;
void MUSIC_Update(void) {} // needed when linking
void S_TestSoundCallback(uint32_t);
extern void initprintf(const char *f, ...);
/*
===================
=
= SoundStartup
=
===================
*/
int32_t S_SoundStartup(void)
{
int32_t status, err = 0;
// TODO: read config
int32_t FXVolume=220, NumVoices=32, NumChannels=2, NumBits=16, MixRate, ReverseStereo=0;
#if defined(_WIN32)
MixRate = 44100;
#else
MixRate = 48000;
#endif
// if they chose None lets return
if (0) return -1; // TODO: read config
RETRY:
status = FX_Init(0, NumVoices, NumChannels, NumBits, MixRate);
if (status == FX_Ok)
{
FX_SetVolume(FXVolume);
if (ReverseStereo == 1)
{
FX_SetReverseStereo(!FX_GetReverseStereo());
}
status = FX_SetCallBack(S_TestSoundCallback);
}
if (status != FX_Ok)
{
if (!err)
{
#if defined(_WIN32)
MixRate = 44100;
#else
MixRate = 48000;
#endif
NumBits = 16;
NumChannels = 2;
NumVoices = 32;
ReverseStereo = 0;
err = 1;
goto RETRY;
}
initprintf("Sound startup error: %s", FX_ErrorString(FX_Error));
return -2;
}
SM32_havesound = 1;
return 0;
}
/*
===================
=
= SoundShutdown
=
===================
*/
void S_SoundShutdown(void)
{
int32_t status;
if (!SM32_havesound)
return;
status = FX_Shutdown();
if (status != FX_Ok)
initprintf("Sound shutdown error: %s", FX_ErrorString(FX_Error));
}
int32_t S_LoadSound(uint32_t num)
{
int32_t fp = -1, l;
if (!SM32_havesound) return 0;
if (num >= MAXSOUNDS || SoundToggle == 0) return 0;
if (g_sounds[num].filename == NULL)
{
OSD_Printf(OSD_ERROR "Sound (#%d) not defined!\n",num);
return 0;
}
if (g_sounds[num].filename1) fp = kopen4load(g_sounds[num].filename1,pathsearchmode);
if (fp == -1) fp = kopen4load(g_sounds[num].filename,pathsearchmode);
if (fp == -1)
{
OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num);
return 0;
}
l = kfilelength(fp);
g_sounds[num].soundsiz = l;
g_sounds[num].lock = 200;
allocache((intptr_t *)&g_sounds[num].ptr,l,(char *)&g_sounds[num].lock);
kread(fp, g_sounds[num].ptr , l);
kclose(fp);
return 1;
}
extern vec3_t pos;
extern int16_t ang, cursectnum;
int32_t S_PlaySoundXYZ(int32_t num, int32_t i, const vec3_t *pos)
{
int32_t sndist, cx, cy, cz, j,k;
int32_t pitche,pitchs,cs;
int32_t voice, sndang, ca, pitch;
// if(num != 358) return 0;
if (num >= MAXSOUNDS ||
!SM32_havesound ||
// ((g_sounds[num].m&8) && ud.lockout) ||
SoundToggle == 0 ||
g_sounds[num].num > 3 ||
FX_VoiceAvailable(g_sounds[num].pr) == 0)
return -1;
if (g_sounds[num].m&128)
{
S_PlaySound(num);
return 0;
}
if (g_sounds[num].m&4)
{
for (j=0; j<MAXSOUNDS; j++)
// for (k=0; k<g_sounds[j].num; k++)
if ((g_sounds[j].num > 0) && (g_sounds[j].m&4))
return -1;
}
cx = pos->x;
cy = pos->y;
cz = pos->z;
cs = cursectnum;
ca = ang;
sndist = FindDistance3D((cx-pos->x),(cy-pos->y),(cz-pos->z)>>4);
if (i >= 0 && (g_sounds[num].m&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9)
sndist = divscale14(sndist,(SHT+1));
pitchs = g_sounds[num].ps;
pitche = g_sounds[num].pe;
cx = klabs(pitche-pitchs);
if (cx)
{
if (pitchs < pitche)
pitch = pitchs + (rand()%cx);
else pitch = pitche + (rand()%cx);
}
else pitch = pitchs;
sndist += g_sounds[num].vo;
if (sndist < 0) sndist = 0;
if (cs > -1 && sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,SX,SY,SZ-(24<<8),SECT))
sndist += sndist>>5;
/*
switch (num)
{
case PIPEBOMB_EXPLODE:
case LASERTRIP_EXPLODE:
case RPG_EXPLODE:
if (sndist > (6144))
sndist = 6144;
if (g_player[screenpeek].ps->cursectnum > -1 && sector[g_player[screenpeek].ps->cursectnum].lotag == 2)
pitch -= 1024;
break;
default:
*/
if (cursectnum > -1 && sector[cursectnum].lotag == 2 && (g_sounds[num].m&4) == 0)
pitch = -768;
if (sndist > 31444 && PN != MUSICANDSFX)
return -1;
// break;
// }
if (g_sounds[num].num > 0 && PN != MUSICANDSFX)
{
if (g_sounds[num].SoundOwner[0].i == i) S_StopSound(num);
else if (g_sounds[num].num > 1) S_StopSound(num);
// else if (A_CheckEnemySprite(&sprite[i]) && sprite[i].extra <= 0) S_StopSound(num);
}
sndang = 2048 + ca - getangle(cx-pos->x,cy-pos->y);
sndang &= 2047;
if (g_sounds[num].ptr == 0)
{
if (S_LoadSound(num) == 0) return 0;
}
else
{
if (g_sounds[num].lock < 200)
g_sounds[num].lock = 200;
else g_sounds[num].lock++;
}
if (g_sounds[num].m&16) sndist = 0;
if (sndist < ((255-LOUDESTVOLUME)<<6))
sndist = ((255-LOUDESTVOLUME)<<6);
if (g_sounds[num].m&1)
{
uint16_t start;
if (g_sounds[num].num > 0) return -1;
start = *(uint16_t *)(g_sounds[num].ptr + 0x14);
if (*g_sounds[num].ptr == 'C')
voice = FX_PlayLoopedVOC(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num);
else if (*g_sounds[num].ptr == 'O')
voice = FX_PlayLoopedOGG(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num);
else
voice = FX_PlayLoopedWAV(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num);
}
else
{
if (*g_sounds[num].ptr == 'C')
voice = FX_PlayVOC3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num);
else if (*g_sounds[num].ptr == 'O')
voice = FX_PlayOGG3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num);
else
voice = FX_PlayWAV3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num);
}
if (voice > FX_Ok)
{
g_sounds[num].SoundOwner[g_sounds[num].num].i = i;
g_sounds[num].SoundOwner[g_sounds[num].num].voice = voice;
g_sounds[num].num++;
}
else g_sounds[num].lock--;
return (voice);
}
void S_PlaySound(int32_t num)
{
int32_t pitch,pitche,pitchs,cx;
int32_t voice;
int32_t start;
if (!SM32_havesound) return;
if (SoundToggle==0) return;
// if ((g_sounds[num].m&8) && ud.lockout) return;
if (FX_VoiceAvailable(g_sounds[num].pr) == 0) return;
if (num < 0 || num > MAXSOUNDS-1 || !g_sounds[num].filename)
{
OSD_Printf("WARNING: invalid sound #%d\n",num);
return;
}
pitchs = g_sounds[num].ps;
pitche = g_sounds[num].pe;
cx = klabs(pitche-pitchs);
if (cx)
{
if (pitchs < pitche)
pitch = pitchs + (rand()%cx);
else pitch = pitche + (rand()%cx);
}
else pitch = pitchs;
if (g_sounds[num].ptr == 0)
{
if (S_LoadSound(num) == 0) return;
}
else
{
if (g_sounds[num].lock < 200)
g_sounds[num].lock = 200;
else g_sounds[num].lock++;
}
if (g_sounds[num].m&1)
{
if (*g_sounds[num].ptr == 'C')
{
start = (int32_t)*(uint16_t *)(g_sounds[num].ptr + 0x14);
voice = FX_PlayLoopedVOC(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].pr,num);
}
else if (*g_sounds[num].ptr == 'O')
{
start = (int32_t)*(uint16_t *)(g_sounds[num].ptr + 0x14);
voice = FX_PlayLoopedOGG(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].pr,num);
}
else
{
start = (int32_t)*(uint16_t *)(g_sounds[num].ptr + 0x14);
voice = FX_PlayLoopedWAV(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].pr,num);
}
}
else
{
if (*g_sounds[num].ptr == 'C')
voice = FX_PlayVOC3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
else if (*g_sounds[num].ptr == 'O')
voice = FX_PlayOGG3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
else
voice = FX_PlayWAV3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
}
if (voice > FX_Ok)// return;
{
g_sounds[num].SoundOwner[g_sounds[num].num].voice = voice;
g_sounds[num].num++;
return;
}
g_sounds[num].lock--;
}
int32_t A_PlaySound(uint32_t num, int32_t i)
{
if (num >= MAXSOUNDS) return -1;
if (i < 0)
{
S_PlaySound(num);
return 0;
}
return S_PlaySoundXYZ(num,i, (vec3_t *)&sprite[i]);
}
void A_StopSound(int32_t num, int32_t i)
{
UNREFERENCED_PARAMETER(i);
if (num >= 0 && num < MAXSOUNDS) S_StopSound(num);
}
void S_StopSound(int32_t num)
{
if (num >= 0 && num < MAXSOUNDS)
if (g_sounds[num].num > 0)
{
FX_StopSound(g_sounds[num].SoundOwner[g_sounds[num].num-1].voice);
S_TestSoundCallback(num);
}
}
void S_StopEnvSound(int32_t num,int32_t i)
{
int32_t j, k;
if (num >= 0 && num < MAXSOUNDS)
if (g_sounds[num].num > 0)
{
k = g_sounds[num].num;
for (j=0; j<k; j++)
if (g_sounds[num].SoundOwner[j].i == i)
{
FX_StopSound(g_sounds[num].SoundOwner[j].voice);
break;
}
}
}
void S_Pan3D(void)
{
int32_t sndist, sx, sy, sz, cx, cy, cz;
int32_t sndang,ca,j,k,i,cs;
g_numEnvSoundsPlaying = 0;
cx = pos.x;
cy = pos.y;
cz = pos.z;
cs = cursectnum;
ca = ang;
for (j=0; j<MAXSOUNDS; j++)
for (k=0; k<g_sounds[j].num; k++)
{
i = g_sounds[j].SoundOwner[k].i;
sx = sprite[i].x;
sy = sprite[i].y;
sz = sprite[i].z;
sndang = 2048 + ca - getangle(cx-sx,cy-sy);
sndang &= 2047;
sndist = FindDistance3D((cx-sx),(cy-sy),(cz-sz)>>4);
if (i >= 0 && (g_sounds[j].m&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9)
sndist = divscale14(sndist,(SHT+1));
sndist += g_sounds[j].vo;
if (sndist < 0) sndist = 0;
if (cs > -1 && sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT))
sndist += sndist>>5;
if (PN == MUSICANDSFX && SLT < 999)
g_numEnvSoundsPlaying++;
/*
switch (j)
{
case PIPEBOMB_EXPLODE:
case LASERTRIP_EXPLODE:
case RPG_EXPLODE:
if (sndist > (6144)) sndist = (6144);
break;
default:
*/
if (sndist > 31444 && PN != MUSICANDSFX)
{
S_StopSound(j);
continue;
}
// }
if (g_sounds[j].ptr == 0 && S_LoadSound(j) == 0) continue;
if (g_sounds[j].m&16) sndist = 0;
if (sndist < ((255-LOUDESTVOLUME)<<6))
sndist = ((255-LOUDESTVOLUME)<<6);
FX_Pan3D(g_sounds[j].SoundOwner[k].voice,sndang>>6,sndist>>6);
}
}
void S_TestSoundCallback(uint32_t num)
{
int32_t i,j,k;
k = g_sounds[num].num;
if (k > 0)
{
if ((g_sounds[num].m&16) == 0)
for (j=0; j<k; j++)
{
i = g_sounds[num].SoundOwner[j].i;
if (sprite[i].picnum == MUSICANDSFX && sector[sprite[i].sectnum].lotag < 3 && sprite[i].lotag < 999)
{
// ActorExtra[i].temp_data[0] = 0;
if ((j + 1) < k)
{
g_sounds[num].SoundOwner[j].voice = g_sounds[num].SoundOwner[k-1].voice;
g_sounds[num].SoundOwner[j].i = g_sounds[num].SoundOwner[k-1].i;
}
break;
}
}
g_sounds[num].num--;
g_sounds[num].SoundOwner[k-1].i = -1;
}
g_sounds[num].lock--;
}
void S_ClearSoundLocks(void)
{
int32_t i;
for (i=0; i<MAXSOUNDS; i++)
if (g_sounds[i].lock >= 200)
g_sounds[i].lock = 199;
}
int32_t A_CheckSoundPlaying(int32_t i, int32_t num)
{
UNREFERENCED_PARAMETER(i);
if (num < 0) num=0; // FIXME
return (g_sounds[num].num > 0);
}
int32_t S_CheckSoundPlaying(int32_t i, int32_t num)
{
if (i == -1)
{
if (g_sounds[num].lock == 200)
return 1;
return 0;
}
return(g_sounds[num].num);
}

View File

@ -0,0 +1,37 @@
#ifndef __sounds_mapster32_h__
#define __sounds_mapster32_h__
#include "build.h"
/// vvv sound structs from duke3d.h
typedef struct {
int32_t voice;
int32_t i;
} SOUNDOWNER;
typedef struct {
int32_t length, num, soundsiz;
char *filename, *ptr, *filename1;
SOUNDOWNER SoundOwner[4];
int16_t ps,pe,vo;
char pr,m;
volatile char lock;
char *definedname; // new
} sound_t;
int32_t S_SoundStartup(void);
void S_SoundShutdown(void);
int32_t S_PlaySoundXYZ(int32_t, int32_t, const vec3_t*);
void S_PlaySound(int32_t);
void A_StopSound(int32_t num, int32_t i);
void S_StopSound(int32_t num);
void S_StopEnvSound(int32_t num,int32_t i);
void S_Pan3D(void);
int32_t A_CheckSoundPlaying(int32_t i, int32_t num);
int32_t S_CheckSoundPlaying(int32_t i, int32_t num);
void S_ClearSoundLocks(void);
#define MAXSOUNDS 2560
#endif