Reincarnate RTS sound functionality together with cleaning up related code.

- Make Win+F* also make play and RTS sound, since modern OS's window managers
  like to eat Alt-F*. (Some Win+F* may be inaccessible too, but together all
  10 should hopefully be covered.)
- Fix an issue where keys other than F1-F10 were considered as starting an RTS
  sound and crashing EDuke32 in the process

git-svn-id: https://svn.eduke32.com/eduke32@4278 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-01-30 19:12:08 +00:00
parent 39bd7110d6
commit da6c7109c1
8 changed files with 106 additions and 252 deletions

View file

@ -111,7 +111,9 @@
#define sc_kpad_Slash 0xb5 //0x67 #define sc_kpad_Slash 0xb5 //0x67
#define sc_kpad_Enter 0x9c //0x68 #define sc_kpad_Enter 0x9c //0x68
#define sc_PrintScreen 0xb7 //0x69 #define sc_PrintScreen 0xb7 //0x69
#define sc_LastScanCode 0x6e #define sc_LeftWin 0xdb
#define sc_RightWin 0xdc
//#define sc_LastScanCode 0x6e
// Ascii scan codes // Ascii scan codes

View file

@ -28,23 +28,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//=============== //===============
typedef struct typedef struct
{ {
char name[8]; char name[8];
int32_t handle,position,size; int32_t handle, position, size;
} lumpinfo_t; } lumpinfo_t;
typedef struct typedef struct
{ {
char identification[4]; // should be IWAD char identification[4]; // should be "IWAD"
int32_t numlumps; int32_t numlumps;
int32_t infotableofs; int32_t infotableofs;
} wadinfo_t; } wadinfo_t;
typedef struct typedef struct
{ {
int32_t filepos; int32_t filepos;
int32_t size; int32_t size;
char name[8]; char name[8];
} filelump_t; } filelump_t;
#endif #endif

View file

@ -8655,20 +8655,18 @@ void G_HandleLocalKeys(void)
#endif #endif
} }
if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED) if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED || WIN_IS_PRESSED)
{ {
i = 0; i = 0;
j = sc_F1;
do // NOTE: sc_F1 .. sc_F10 are contiguous. sc_F11 is not sc_F10+1.
{ for (j=sc_F1; j<=sc_F10; j++)
if (KB_UnBoundKeyPressed(j)) if (KB_UnBoundKeyPressed(j))
{ {
KB_ClearKeyDown(j); KB_ClearKeyDown(j);
i = j - sc_F1 + 1; i = j - sc_F1 + 1;
break;
} }
}
while (++j < sc_F11);
if (i) if (i)
{ {
@ -8718,17 +8716,17 @@ void G_HandleLocalKeys(void)
pub = NUMPAGES; pub = NUMPAGES;
return; return;
} }
if (ud.lockout == 0) // Not SHIFT -- that is, either some ALT or WIN.
if (ud.config.SoundToggle && ALT_IS_PRESSED && (RTS_NumSounds() > 0) && g_RTSPlaying == 0 && (ud.config.VoiceToggle & 1)) if (!ud.lockout && ud.config.SoundToggle &&
RTS_IsInitialized() && g_RTSPlaying == 0 && (ud.config.VoiceToggle & 1))
{ {
#if 0 char *sndptr = (char *)RTS_GetSound(i-1);
// FIXME: http://forums.duke4.net/topic/6308-eduke32-crashed-when-press-altprintscreen/
// HINT: keeping temp-sounding variables like "i" live for if (sndptr != NULL)
// a long time surely is recipe for disaster :/. {
FX_PlayAuto3D((char *)RTS_GetSound(i-1),RTS_SoundLength(i-1),0,0,FX_VOLUME(1),255,-i); FX_PlayAuto3D(sndptr, RTS_SoundLength(i-1), FX_ONESHOT, 0, 0, FX_VOLUME(1), 255, -i);
g_RTSPlaying = 7; g_RTSPlaying = 7;
#ifndef NETCODE_DISABLE #ifndef NETCODE_DISABLE
@ -8746,13 +8744,14 @@ void G_HandleLocalKeys(void)
#endif #endif
pus = NUMPAGES; pus = NUMPAGES;
pub = NUMPAGES; pub = NUMPAGES;
#endif
return; return;
} }
} }
} }
}
if (!ALT_IS_PRESSED && !SHIFTS_IS_PRESSED) if (!ALT_IS_PRESSED && !SHIFTS_IS_PRESSED && !WIN_IS_PRESSED)
{ {
if ((g_netServer || ud.multimode > 1) && BUTTON(gamefunc_SendMessage)) if ((g_netServer || ud.multimode > 1) && BUTTON(gamefunc_SendMessage))
@ -11671,8 +11670,8 @@ int32_t app_main(int32_t argc, const char **argv)
RTS_Init(ud.rtsname); RTS_Init(ud.rtsname);
if (rts_numlumps) if (RTS_IsInitialized())
initprintf("Using RTS file \"%s\".\n",ud.rtsname); initprintf("Using RTS file \"%s\".\n", ud.rtsname);
if (ud.last_level) if (ud.last_level)
Bstrcpy(ud.rtsname, defaultrtsfilename[0]); Bstrcpy(ud.rtsname, defaultrtsfilename[0]);
@ -12039,7 +12038,8 @@ int32_t G_DoMoveThings(void)
// Moved lower so it is restored correctly by demo diffs: // Moved lower so it is restored correctly by demo diffs:
//if (g_earthquakeTime > 0) g_earthquakeTime--; //if (g_earthquakeTime > 0) g_earthquakeTime--;
if (g_RTSPlaying > 0) g_RTSPlaying--; if (g_RTSPlaying > 0)
g_RTSPlaying--;
for (i=0; i<MAXUSERQUOTES; i++) for (i=0; i<MAXUSERQUOTES; i++)
if (user_quote_time[i]) if (user_quote_time[i])

View file

@ -284,7 +284,6 @@ extern int32_t g_restorePalette;
extern int32_t g_usingAddon; extern int32_t g_usingAddon;
extern int32_t hud_glowingquotes; extern int32_t hud_glowingquotes;
extern int32_t hud_showmapname; extern int32_t hud_showmapname;
extern int32_t rts_numlumps;
extern int32_t quotebot; extern int32_t quotebot;
extern int32_t quotebotgoal; extern int32_t quotebotgoal;
extern int32_t r_maxfps; extern int32_t r_maxfps;

View file

@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Macros, some from SW source // Macros, some from SW source
#define WIN_IS_PRESSED ( KB_KeyPressed( sc_RightWin ) || KB_KeyPressed( sc_LeftWin ) )
#define ALT_IS_PRESSED ( KB_KeyPressed( sc_RightAlt ) || KB_KeyPressed( sc_LeftAlt ) ) #define ALT_IS_PRESSED ( KB_KeyPressed( sc_RightAlt ) || KB_KeyPressed( sc_LeftAlt ) )
#define SHIFTS_IS_PRESSED ( KB_KeyPressed( sc_RightShift ) || KB_KeyPressed( sc_LeftShift ) ) #define SHIFTS_IS_PRESSED ( KB_KeyPressed( sc_RightShift ) || KB_KeyPressed( sc_LeftShift ) )
#define RANDOMSCRAP A_InsertSprite(s->sectnum,s->x+(krand()&255)-128,s->y+(krand()&255)-128,s->z-(8<<8)-(krand()&8191),\ #define RANDOMSCRAP A_InsertSprite(s->sectnum,s->x+(krand()&255)-128,s->y+(krand()&255)-128,s->z-(8<<8)-(krand()&8191),\

View file

@ -682,13 +682,20 @@ void Net_ParsePacketCommon(uint8_t *pbuf, int32_t packbufleng, int32_t serverpac
break; break;
case PACKET_RTS: case PACKET_RTS:
if (rts_numlumps == 0) break; if (!RTS_IsInitialized())
break;
if (ud.config.SoundToggle == 0 || ud.lockout == 1 || ud.config.FXDevice < 0 || !(ud.config.VoiceToggle & 4)) if (ud.config.SoundToggle == 0 || ud.lockout == 1 || ud.config.FXDevice < 0 || !(ud.config.VoiceToggle & 4))
break; break;
{
char *sndptr = (char *)RTS_GetSound(pbuf[1]-1);
FX_PlayAuto3D((char *)RTS_GetSound(pbuf[1]-1),RTS_SoundLength(pbuf[1]-1),FX_ONESHOT,0,0,FX_VOLUME(1),255,-pbuf[1]); if (sndptr != NULL)
{
FX_PlayAuto3D(sndptr, RTS_SoundLength(pbuf[1]-1), FX_ONESHOT, 0, 0, FX_VOLUME(1), 255, -pbuf[1]);
g_RTSPlaying = 7; g_RTSPlaying = 7;
}
}
break; break;
case PACKET_USER_MAP: case PACKET_USER_MAP:

View file

@ -22,57 +22,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "duke3d.h" #include "duke3d.h"
//=============
// STATICS
//=============
int32_t rts_numlumps; static int32_t rts_numlumps;
static void **rts_lumpcache; static void **rts_lumpcache;
static lumpinfo_t *rts_lumpinfo; // location of each lump on disk static lumpinfo_t *rts_lumpinfo;
static int32_t RTS_Started = FALSE; static int32_t RTS_Started = FALSE;
char rts_lumplockbyte[11]; char rts_lumplockbyte[11];
int32_t IntelLong(int32_t l)
{
#if B_BIG_ENDIAN != 0
int32_t t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8);
return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16);
#else
return l;
#endif
}
/* /*
============================================================================
LUMP BASED ROUTINES
============================================================================
*/
/*
====================
=
= RTS_AddFile = RTS_AddFile
= =
= All files are optional, but at least one file must be found = All files are optional, but at least one file must be found
= Files with a .rts extension are wadlink files with multiple lumps = Files with a .rts extension are wadlink files with multiple lumps
= Other files are single lumps with the base filename for the lump name = Other files are single lumps with the base filename for the lump name
=
====================
*/ */
static int32_t RTS_AddFile(const char *filename)
int32_t RTS_AddFile(const char *filename)
{ {
wadinfo_t header; wadinfo_t header;
lumpinfo_t *lump_p; int32_t i, handle, length, startlump;
uint32_t i;
int32_t handle, length;
int32_t startlump;
filelump_t *fileinfo, *fileinfoo; filelump_t *fileinfo, *fileinfoo;
//
// read the entire file in // read the entire file in
// FIXME: shared opens // FIXME: shared opens
@ -86,16 +57,17 @@ int32_t RTS_AddFile(const char *filename)
startlump = rts_numlumps; startlump = rts_numlumps;
// WAD file // WAD file
// initprintf(" Adding \"%s\".\n",filename); i = kread(handle, &header, sizeof(header));
kread(handle, &header, sizeof(header)); if (i != sizeof(header) || Bmemcmp(header.identification, "IWAD", 4))
if (strncmp(header.identification,"IWAD",4))
{ {
initprintf("RTS file \"%s\" doesn't have IWAD id\n",filename); initprintf("RTS file \"%s\" too short or doesn't have IWAD id\n", filename);
kclose(handle); kclose(handle);
return -1; return -1;
} }
header.numlumps = IntelLong(header.numlumps);
header.infotableofs = IntelLong(header.infotableofs); header.numlumps = B_LITTLE32(header.numlumps);
header.infotableofs = B_LITTLE32(header.infotableofs);
length = header.numlumps*sizeof(filelump_t); length = header.numlumps*sizeof(filelump_t);
fileinfo = fileinfoo = (filelump_t *)Bmalloc(length); fileinfo = fileinfoo = (filelump_t *)Bmalloc(length);
if (!fileinfo) if (!fileinfo)
@ -104,30 +76,34 @@ int32_t RTS_AddFile(const char *filename)
kclose(handle); kclose(handle);
return -1; return -1;
} }
klseek(handle, header.infotableofs, SEEK_SET); klseek(handle, header.infotableofs, SEEK_SET);
kread(handle, fileinfo, length); kread(handle, fileinfo, length);
// {
// Fill in lumpinfo lumpinfo_t *lump_p = (lumpinfo_t *)Brealloc(
// rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t));
lump_p = (lumpinfo_t *)Brealloc(rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t));
if (!lump_p) if (!lump_p)
{ {
kclose(handle); kclose(handle);
return -1; return -1;
} }
rts_lumpinfo = lump_p; rts_lumpinfo = lump_p;
}
rts_numlumps += header.numlumps; rts_numlumps += header.numlumps;
lump_p = &rts_lumpinfo[startlump]; for (i=startlump; i<rts_numlumps; i++, fileinfo++)
for (i=startlump ; i<(uint32_t)rts_numlumps ; i++,lump_p++, fileinfo++)
{ {
lump_p->handle = handle; lumpinfo_t *lump = &rts_lumpinfo[i];
lump_p->position = IntelLong(fileinfo->filepos);
lump_p->size = IntelLong(fileinfo->size); lump->handle = handle; // NOTE: cache1d-file is not closed!
Bstrncpy(lump_p->name, fileinfo->name, 8); lump->position = B_LITTLE32(fileinfo->filepos);
lump->size = B_LITTLE32(fileinfo->size);
Bstrncpy(lump->name, fileinfo->name, 8);
} }
Bfree(fileinfoo); Bfree(fileinfoo);
@ -135,155 +111,63 @@ int32_t RTS_AddFile(const char *filename)
return 0; return 0;
} }
/*
====================
=
= RTS_Init
=
= Files with a .rts extension are idlink files with multiple lumps
=
====================
*/
void RTS_Init(const char *filename) void RTS_Init(const char *filename)
{ {
int32_t length;
//
// open all the files, load headers, and count lumps // open all the files, load headers, and count lumps
//
rts_numlumps = 0; rts_numlumps = 0;
rts_lumpinfo = NULL; // will be realloced as lumps are added rts_lumpinfo = NULL; // will be realloced as lumps are added
// initprintf("RTS Manager Started.\n"); if (RTS_AddFile(filename))
if (RTS_AddFile(filename)) return; return;
if (!rts_numlumps) return; if (rts_numlumps == 0)
return;
rts_lumpcache = (void **)Bcalloc(rts_numlumps, sizeof(rts_lumpcache[0]));
//
// set up caching
//
length = (rts_numlumps) * sizeof(*rts_lumpcache);
rts_lumpcache = (void **)Bmalloc(length);
memset(rts_lumpcache,0,length);
RTS_Started = TRUE; RTS_Started = TRUE;
} }
/* int32_t RTS_IsInitialized(void)
====================
=
= RTS_NumSounds
=
====================
*/
int32_t RTS_NumSounds(void)
{ {
return rts_numlumps-1; return rts_numlumps > 0;
} }
/*
==================== #define RTS_BAD_LUMP(lump) ((uint32_t)lump >= (uint32_t)rts_numlumps)
=
= RTS_SoundLength
=
= Returns the buffer size needed to load the given lump
=
====================
*/
int32_t RTS_SoundLength(int32_t lump) int32_t RTS_SoundLength(int32_t lump)
{ {
lump++; lump++;
if (lump >= rts_numlumps)
{ return RTS_BAD_LUMP(lump) ? 0 : rts_lumpinfo[lump].size;
initprintf("RTS_SoundLength: %i >= numlumps\n",lump);
RTS_Started = FALSE;
rts_numlumps = 0;
return 0;
}
return rts_lumpinfo[lump].size;
} }
/*
====================
=
= RTS_GetSoundName
=
====================
*/
const char *RTS_GetSoundName(int32_t i) /* Loads the lump into the given buffer, which must be >= RTS_SoundLength() */
static void RTS_ReadLump(int32_t lump, void *dest)
{ {
i++; lumpinfo_t *l = &rts_lumpinfo[lump];
if (i>=rts_numlumps)
{
initprintf("RTS_GetSoundName: %i >= numlumps\n",i);
RTS_Started = FALSE;
rts_numlumps = 0;
return 0;
}
return &(rts_lumpinfo[i].name[0]);
}
/*
====================
=
= RTS_ReadLump
=
= Loads the lump into the given buffer, which must be >= RTS_SoundLength()
=
====================
*/
void RTS_ReadLump(int32_t lump, void *dest)
{
lumpinfo_t *l;
if (lump >= rts_numlumps)
{
initprintf("RTS_ReadLump: %i >= numlumps\n",lump);
RTS_Started = FALSE;
rts_numlumps = 0;
return;
}
if (lump < 0)
{
initprintf("RTS_ReadLump: %i < 0\n",lump);
RTS_Started = FALSE;
rts_numlumps = 0;
return;
}
l = rts_lumpinfo+lump;
klseek(l->handle, l->position, SEEK_SET); klseek(l->handle, l->position, SEEK_SET);
kread(l->handle,dest,l->size); kread(l->handle, dest, l->size);
} }
/*
====================
=
= RTS_GetSound
=
====================
*/
void *RTS_GetSound(int32_t lump) void *RTS_GetSound(int32_t lump)
{ {
lump++; lump++;
if ((uint32_t)lump >= (uint32_t)rts_numlumps)
{
initprintf("RTS_GetSound: %i >= %i\n",lump,rts_numlumps);
RTS_Started = FALSE;
rts_numlumps = 0;
return 0;
}
if (RTS_BAD_LUMP(lump))
return NULL;
if (rts_lumpcache[lump] == NULL) if (rts_lumpcache[lump] == NULL)
{ {
rts_lumplockbyte[lump] = 200; rts_lumplockbyte[lump] = 200;
allocache((intptr_t *)&rts_lumpcache[lump],(int32_t)RTS_SoundLength(lump-1),&rts_lumplockbyte[lump]); // JBF 20030910: char * => int32_t * allocache((intptr_t *)&rts_lumpcache[lump], RTS_SoundLength(lump-1), &rts_lumplockbyte[lump]); // JBF 20030910: char * => int32_t *
RTS_ReadLump(lump, rts_lumpcache[lump]); RTS_ReadLump(lump, rts_lumpcache[lump]);
} }
else else
@ -293,6 +177,6 @@ void *RTS_GetSound(int32_t lump)
else else
rts_lumplockbyte[lump]++; rts_lumplockbyte[lump]++;
} }
return rts_lumpcache[lump]; return rts_lumpcache[lump];
} }

View file

@ -30,54 +30,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define __rts_public__ #define __rts_public__
extern char rts_lumplockbyte[11]; extern char rts_lumplockbyte[11];
extern int32_t rts_numlumps;
/* /* Files with a .rts extension are idlink files with multiple lumps */
==================== void RTS_Init(const char *filename);
=
= RTS_Init
=
= Files with a .rts extension are idlink files with multiple lumps
=
====================
*/
void RTS_Init (const char *filename); int32_t RTS_IsInitialized(void);
/*
====================
=
= RTS_NumSounds
=
====================
*/
int32_t RTS_NumSounds (void); /* Returns the buffer size needed to load the given lump */
/* int32_t RTS_SoundLength(int32_t lump);
====================
=
= RTS_SoundLength
=
= Returns the buffer size needed to load the given lump
=
====================
*/
int32_t RTS_SoundLength (int32_t lump); void *RTS_GetSound(int32_t lump);
/*
====================
=
= RTS_GetSoundName
=
====================
*/
const char * RTS_GetSoundName (int32_t i);
/*
====================
=
= RTS_GetSound
=
====================
*/
void *RTS_GetSound (int32_t lump);
#endif #endif