mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 02:30:46 +00:00
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:
parent
39bd7110d6
commit
da6c7109c1
8 changed files with 106 additions and 252 deletions
|
@ -111,7 +111,9 @@
|
|||
#define sc_kpad_Slash 0xb5 //0x67
|
||||
#define sc_kpad_Enter 0x9c //0x68
|
||||
#define sc_PrintScreen 0xb7 //0x69
|
||||
#define sc_LastScanCode 0x6e
|
||||
#define sc_LeftWin 0xdb
|
||||
#define sc_RightWin 0xdc
|
||||
//#define sc_LastScanCode 0x6e
|
||||
|
||||
// Ascii scan codes
|
||||
|
||||
|
|
|
@ -28,23 +28,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
//===============
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[8];
|
||||
int32_t handle,position,size;
|
||||
} lumpinfo_t;
|
||||
{
|
||||
char name[8];
|
||||
int32_t handle, position, size;
|
||||
} lumpinfo_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char identification[4]; // should be IWAD
|
||||
int32_t numlumps;
|
||||
int32_t infotableofs;
|
||||
} wadinfo_t;
|
||||
{
|
||||
char identification[4]; // should be "IWAD"
|
||||
int32_t numlumps;
|
||||
int32_t infotableofs;
|
||||
} wadinfo_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t filepos;
|
||||
int32_t size;
|
||||
char name[8];
|
||||
} filelump_t;
|
||||
{
|
||||
int32_t filepos;
|
||||
int32_t size;
|
||||
char name[8];
|
||||
} filelump_t;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8655,20 +8655,18 @@ void G_HandleLocalKeys(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED)
|
||||
if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED || WIN_IS_PRESSED)
|
||||
{
|
||||
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))
|
||||
{
|
||||
KB_ClearKeyDown(j);
|
||||
i = j - sc_F1 + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (++j < sc_F11);
|
||||
|
||||
if (i)
|
||||
{
|
||||
|
@ -8718,17 +8716,17 @@ void G_HandleLocalKeys(void)
|
|||
pub = NUMPAGES;
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (ud.lockout == 0)
|
||||
if (ud.config.SoundToggle && ALT_IS_PRESSED && (RTS_NumSounds() > 0) && g_RTSPlaying == 0 && (ud.config.VoiceToggle & 1))
|
||||
// Not SHIFT -- that is, either some ALT or WIN.
|
||||
if (!ud.lockout && ud.config.SoundToggle &&
|
||||
RTS_IsInitialized() && g_RTSPlaying == 0 && (ud.config.VoiceToggle & 1))
|
||||
{
|
||||
char *sndptr = (char *)RTS_GetSound(i-1);
|
||||
|
||||
if (sndptr != NULL)
|
||||
{
|
||||
#if 0
|
||||
// FIXME: http://forums.duke4.net/topic/6308-eduke32-crashed-when-press-altprintscreen/
|
||||
// HINT: keeping temp-sounding variables like "i" live for
|
||||
// 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;
|
||||
#ifndef NETCODE_DISABLE
|
||||
|
@ -8746,13 +8744,14 @@ void G_HandleLocalKeys(void)
|
|||
#endif
|
||||
pus = NUMPAGES;
|
||||
pub = NUMPAGES;
|
||||
#endif
|
||||
|
||||
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))
|
||||
|
@ -11671,8 +11670,8 @@ int32_t app_main(int32_t argc, const char **argv)
|
|||
|
||||
RTS_Init(ud.rtsname);
|
||||
|
||||
if (rts_numlumps)
|
||||
initprintf("Using RTS file \"%s\".\n",ud.rtsname);
|
||||
if (RTS_IsInitialized())
|
||||
initprintf("Using RTS file \"%s\".\n", ud.rtsname);
|
||||
|
||||
if (ud.last_level)
|
||||
Bstrcpy(ud.rtsname, defaultrtsfilename[0]);
|
||||
|
@ -12039,7 +12038,8 @@ int32_t G_DoMoveThings(void)
|
|||
// Moved lower so it is restored correctly by demo diffs:
|
||||
//if (g_earthquakeTime > 0) g_earthquakeTime--;
|
||||
|
||||
if (g_RTSPlaying > 0) g_RTSPlaying--;
|
||||
if (g_RTSPlaying > 0)
|
||||
g_RTSPlaying--;
|
||||
|
||||
for (i=0; i<MAXUSERQUOTES; i++)
|
||||
if (user_quote_time[i])
|
||||
|
|
|
@ -284,7 +284,6 @@ extern int32_t g_restorePalette;
|
|||
extern int32_t g_usingAddon;
|
||||
extern int32_t hud_glowingquotes;
|
||||
extern int32_t hud_showmapname;
|
||||
extern int32_t rts_numlumps;
|
||||
extern int32_t quotebot;
|
||||
extern int32_t quotebotgoal;
|
||||
extern int32_t r_maxfps;
|
||||
|
|
|
@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
// 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 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),\
|
||||
|
|
|
@ -682,13 +682,20 @@ void Net_ParsePacketCommon(uint8_t *pbuf, int32_t packbufleng, int32_t serverpac
|
|||
break;
|
||||
|
||||
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))
|
||||
break;
|
||||
|
||||
FX_PlayAuto3D((char *)RTS_GetSound(pbuf[1]-1),RTS_SoundLength(pbuf[1]-1),FX_ONESHOT,0,0,FX_VOLUME(1),255,-pbuf[1]);
|
||||
g_RTSPlaying = 7;
|
||||
{
|
||||
char *sndptr = (char *)RTS_GetSound(pbuf[1]-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;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PACKET_USER_MAP:
|
||||
|
|
|
@ -22,57 +22,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "duke3d.h"
|
||||
|
||||
//=============
|
||||
// STATICS
|
||||
//=============
|
||||
|
||||
int32_t rts_numlumps;
|
||||
static int32_t rts_numlumps;
|
||||
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;
|
||||
|
||||
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
|
||||
=
|
||||
= All files are optional, but at least one file must be found
|
||||
= Files with a .rts extension are wadlink files with multiple lumps
|
||||
= Other files are single lumps with the base filename for the lump name
|
||||
=
|
||||
====================
|
||||
*/
|
||||
|
||||
int32_t RTS_AddFile(const char *filename)
|
||||
static int32_t RTS_AddFile(const char *filename)
|
||||
{
|
||||
wadinfo_t header;
|
||||
lumpinfo_t *lump_p;
|
||||
uint32_t i;
|
||||
int32_t handle, length;
|
||||
int32_t startlump;
|
||||
int32_t i, handle, length, startlump;
|
||||
filelump_t *fileinfo, *fileinfoo;
|
||||
|
||||
//
|
||||
// read the entire file in
|
||||
// FIXME: shared opens
|
||||
|
||||
|
@ -86,16 +57,17 @@ int32_t RTS_AddFile(const char *filename)
|
|||
startlump = rts_numlumps;
|
||||
|
||||
// WAD file
|
||||
// initprintf(" Adding \"%s\".\n",filename);
|
||||
kread(handle, &header, sizeof(header));
|
||||
if (strncmp(header.identification,"IWAD",4))
|
||||
i = kread(handle, &header, sizeof(header));
|
||||
if (i != sizeof(header) || Bmemcmp(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);
|
||||
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);
|
||||
fileinfo = fileinfoo = (filelump_t *)Bmalloc(length);
|
||||
if (!fileinfo)
|
||||
|
@ -104,30 +76,34 @@ int32_t RTS_AddFile(const char *filename)
|
|||
kclose(handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
klseek(handle, header.infotableofs, SEEK_SET);
|
||||
kread(handle, fileinfo, length);
|
||||
|
||||
//
|
||||
// Fill in lumpinfo
|
||||
//
|
||||
lump_p = (lumpinfo_t *)Brealloc(rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t));
|
||||
if (!lump_p)
|
||||
{
|
||||
kclose(handle);
|
||||
return -1;
|
||||
lumpinfo_t *lump_p = (lumpinfo_t *)Brealloc(
|
||||
rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t));
|
||||
|
||||
if (!lump_p)
|
||||
{
|
||||
kclose(handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rts_lumpinfo = lump_p;
|
||||
}
|
||||
rts_lumpinfo = lump_p;
|
||||
|
||||
rts_numlumps += header.numlumps;
|
||||
|
||||
lump_p = &rts_lumpinfo[startlump];
|
||||
|
||||
for (i=startlump ; i<(uint32_t)rts_numlumps ; i++,lump_p++, fileinfo++)
|
||||
for (i=startlump; i<rts_numlumps; i++, fileinfo++)
|
||||
{
|
||||
lump_p->handle = handle;
|
||||
lump_p->position = IntelLong(fileinfo->filepos);
|
||||
lump_p->size = IntelLong(fileinfo->size);
|
||||
Bstrncpy(lump_p->name, fileinfo->name, 8);
|
||||
lumpinfo_t *lump = &rts_lumpinfo[i];
|
||||
|
||||
lump->handle = handle; // NOTE: cache1d-file is not closed!
|
||||
lump->position = B_LITTLE32(fileinfo->filepos);
|
||||
lump->size = B_LITTLE32(fileinfo->size);
|
||||
|
||||
Bstrncpy(lump->name, fileinfo->name, 8);
|
||||
}
|
||||
|
||||
Bfree(fileinfoo);
|
||||
|
@ -135,155 +111,63 @@ int32_t RTS_AddFile(const char *filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_Init
|
||||
=
|
||||
= Files with a .rts extension are idlink files with multiple lumps
|
||||
=
|
||||
====================
|
||||
*/
|
||||
|
||||
void RTS_Init(const char *filename)
|
||||
{
|
||||
int32_t length;
|
||||
//
|
||||
// open all the files, load headers, and count lumps
|
||||
//
|
||||
|
||||
rts_numlumps = 0;
|
||||
rts_lumpinfo = NULL; // will be realloced as lumps are added
|
||||
|
||||
// initprintf("RTS Manager Started.\n");
|
||||
if (RTS_AddFile(filename)) return;
|
||||
if (RTS_AddFile(filename))
|
||||
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_NumSounds
|
||||
=
|
||||
====================
|
||||
*/
|
||||
|
||||
int32_t RTS_NumSounds(void)
|
||||
int32_t RTS_IsInitialized(void)
|
||||
{
|
||||
return rts_numlumps-1;
|
||||
return rts_numlumps > 0;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_SoundLength
|
||||
=
|
||||
= Returns the buffer size needed to load the given lump
|
||||
=
|
||||
====================
|
||||
*/
|
||||
|
||||
#define RTS_BAD_LUMP(lump) ((uint32_t)lump >= (uint32_t)rts_numlumps)
|
||||
|
||||
int32_t RTS_SoundLength(int32_t lump)
|
||||
{
|
||||
lump++;
|
||||
if (lump >= rts_numlumps)
|
||||
{
|
||||
initprintf("RTS_SoundLength: %i >= numlumps\n",lump);
|
||||
RTS_Started = FALSE;
|
||||
rts_numlumps = 0;
|
||||
return 0;
|
||||
}
|
||||
return rts_lumpinfo[lump].size;
|
||||
|
||||
return RTS_BAD_LUMP(lump) ? 0 : 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++;
|
||||
if (i>=rts_numlumps)
|
||||
{
|
||||
initprintf("RTS_GetSoundName: %i >= numlumps\n",i);
|
||||
RTS_Started = FALSE;
|
||||
rts_numlumps = 0;
|
||||
return 0;
|
||||
}
|
||||
lumpinfo_t *l = &rts_lumpinfo[lump];
|
||||
|
||||
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);
|
||||
kread(l->handle,dest,l->size);
|
||||
kread(l->handle, dest, l->size);
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_GetSound
|
||||
=
|
||||
====================
|
||||
*/
|
||||
|
||||
void *RTS_GetSound(int32_t 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)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
else
|
||||
|
@ -293,6 +177,6 @@ void *RTS_GetSound(int32_t lump)
|
|||
else
|
||||
rts_lumplockbyte[lump]++;
|
||||
}
|
||||
|
||||
return rts_lumpcache[lump];
|
||||
}
|
||||
|
||||
|
|
|
@ -30,54 +30,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define __rts_public__
|
||||
|
||||
extern char rts_lumplockbyte[11];
|
||||
extern int32_t rts_numlumps;
|
||||
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_Init
|
||||
=
|
||||
= Files with a .rts extension are idlink files with multiple lumps
|
||||
=
|
||||
====================
|
||||
*/
|
||||
/* Files with a .rts extension are idlink files with multiple lumps */
|
||||
void RTS_Init(const char *filename);
|
||||
|
||||
void RTS_Init (const char *filename);
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_NumSounds
|
||||
=
|
||||
====================
|
||||
*/
|
||||
int32_t RTS_IsInitialized(void);
|
||||
|
||||
int32_t RTS_NumSounds (void);
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_SoundLength
|
||||
=
|
||||
= Returns the buffer size needed to load the given lump
|
||||
=
|
||||
====================
|
||||
*/
|
||||
/* Returns the buffer size needed to load the given lump */
|
||||
int32_t RTS_SoundLength(int32_t lump);
|
||||
|
||||
int32_t RTS_SoundLength (int32_t lump);
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_GetSoundName
|
||||
=
|
||||
====================
|
||||
*/
|
||||
void *RTS_GetSound(int32_t lump);
|
||||
|
||||
const char * RTS_GetSoundName (int32_t i);
|
||||
/*
|
||||
====================
|
||||
=
|
||||
= RTS_GetSound
|
||||
=
|
||||
====================
|
||||
*/
|
||||
void *RTS_GetSound (int32_t lump);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue