mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-16 17:11:03 +00:00
Move all SDL backend function to the SDL backend and use SDL_ as prefix
This commit is contained in:
parent
3e294e5288
commit
f1ce0c0c00
3 changed files with 86 additions and 69 deletions
|
@ -48,9 +48,55 @@ static int dmasize = 0;
|
|||
static dma_t *dmabackend;
|
||||
cvar_t *s_sdldriver;
|
||||
|
||||
/* The callback */
|
||||
/*
|
||||
* Gives information over user
|
||||
* defineable variables
|
||||
*/
|
||||
void
|
||||
SDL_SoundInfo(void)
|
||||
{
|
||||
Com_Printf("%5d stereo\n", dma.channels - 1);
|
||||
Com_Printf("%5d samples\n", dma.samples);
|
||||
Com_Printf("%5d samplepos\n", dma.samplepos);
|
||||
Com_Printf("%5d samplebits\n", dma.samplebits);
|
||||
Com_Printf("%5d submission_chunk\n", dma.submission_chunk);
|
||||
Com_Printf("%5d speed\n", dma.speed);
|
||||
Com_Printf("%p dma buffer\n", dma.buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates when a sound
|
||||
* must be started.
|
||||
*/
|
||||
int
|
||||
SDL_DriftBeginofs(float timeofs)
|
||||
{
|
||||
int start = (int)(cl.frame.servertime * 0.001f * dma.speed + s_beginofs);
|
||||
|
||||
if (start < paintedtime)
|
||||
{
|
||||
start = paintedtime;
|
||||
s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * dma.speed));
|
||||
}
|
||||
else if (start > paintedtime + 0.3f * dma.speed)
|
||||
{
|
||||
start = (int)(paintedtime + 0.1f * dma.speed);
|
||||
s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * dma.speed));
|
||||
}
|
||||
else
|
||||
{
|
||||
s_beginofs -= 10;
|
||||
}
|
||||
|
||||
return timeofs ? start + timeofs * dma.speed : paintedtime;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback funktion for SDL. Writes
|
||||
* sound data to SDL when requested.
|
||||
*/
|
||||
static void
|
||||
sdl_audio_callback(void *data, Uint8 *stream, int length)
|
||||
SDL_Callback(void *data, Uint8 *stream, int length)
|
||||
{
|
||||
int length1;
|
||||
int length2;
|
||||
|
@ -100,8 +146,12 @@ sdl_audio_callback(void *data, Uint8 *stream, int length)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes the SDL sound
|
||||
* backend and sets up SDL.
|
||||
*/
|
||||
qboolean
|
||||
SNDDMA_Init(void)
|
||||
SDL_BackendInit(void)
|
||||
{
|
||||
char drivername[128];
|
||||
char reqdriver[128];
|
||||
|
@ -197,7 +247,7 @@ SNDDMA_Init(void)
|
|||
}
|
||||
|
||||
desired.channels = sndchans;
|
||||
desired.callback = sdl_audio_callback;
|
||||
desired.callback = SDL_Callback;
|
||||
|
||||
/* Okay, let's try our luck */
|
||||
if (SDL_OpenAudio(&desired, &obtained) == -1)
|
||||
|
@ -240,14 +290,11 @@ SNDDMA_Init(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
SNDDMA_GetDMAPos(void)
|
||||
{
|
||||
return dmapos;
|
||||
}
|
||||
|
||||
/*
|
||||
* Shuts the SDL backend down.
|
||||
*/
|
||||
void
|
||||
SNDDMA_Shutdown(void)
|
||||
SDL_BackendShutdown(void)
|
||||
{
|
||||
Com_Printf("Closing SDL audio device...\n");
|
||||
SDL_PauseAudio(1);
|
||||
|
@ -259,20 +306,26 @@ SNDDMA_Shutdown(void)
|
|||
snd_inited = 0;
|
||||
Com_Printf("SDL audio device shut down.\n");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_GetPos(void)
|
||||
{
|
||||
return dmapos;
|
||||
}
|
||||
|
||||
/*
|
||||
* This sends the sound to the device.
|
||||
* In the SDL backend it's useless and
|
||||
* only implemented for compatiblity.
|
||||
*/
|
||||
void
|
||||
SNDDMA_Submit(void)
|
||||
SDL_Submit(void)
|
||||
{
|
||||
SDL_UnlockAudio();
|
||||
}
|
||||
|
||||
void
|
||||
SNDDMA_BeginPainting(void)
|
||||
SDL_BeginPainting(void)
|
||||
{
|
||||
SDL_LockAudio();
|
||||
}
|
||||
|
|
|
@ -123,17 +123,22 @@ typedef enum
|
|||
|
||||
extern sndstarted_t sound_started;
|
||||
|
||||
int s_beginofs;
|
||||
|
||||
/* initializes cycling through a DMA
|
||||
buffer and returns information on it */
|
||||
qboolean SNDDMA_Init(void);
|
||||
qboolean SDL_BackendInit(void);
|
||||
|
||||
/* gets the current DMA position */
|
||||
int SNDDMA_GetDMAPos(void);
|
||||
int SDL_GetPos(void);
|
||||
|
||||
/* shutdown the DMA xfer. */
|
||||
void SNDDMA_Shutdown(void);
|
||||
void SNDDMA_BeginPainting(void);
|
||||
void SNDDMA_Submit(void);
|
||||
void SDL_BackendShutdown(void);
|
||||
void SDL_BeginPainting(void);
|
||||
void SDL_Submit(void);
|
||||
|
||||
void SDL_SoundInfo(void);
|
||||
int SDL_DriftBeginofs(float);
|
||||
|
||||
#define MAX_CHANNELS 32
|
||||
extern channel_t channels[MAX_CHANNELS];
|
||||
|
|
|
@ -72,8 +72,6 @@ playsound_t s_playsounds[MAX_PLAYSOUNDS];
|
|||
playsound_t s_freeplays;
|
||||
playsound_t s_pendingplays;
|
||||
|
||||
int s_beginofs;
|
||||
|
||||
cvar_t *s_volume;
|
||||
cvar_t *s_testsound;
|
||||
cvar_t *s_loadas8bit;
|
||||
|
@ -85,21 +83,6 @@ cvar_t *s_ambient;
|
|||
int s_rawend;
|
||||
portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
|
||||
|
||||
/*
|
||||
* User-setable variables
|
||||
*/
|
||||
static void
|
||||
DMA_SoundInfo(void)
|
||||
{
|
||||
Com_Printf("%5d stereo\n", dma.channels - 1);
|
||||
Com_Printf("%5d samples\n", dma.samples);
|
||||
Com_Printf("%5d samplepos\n", dma.samplepos);
|
||||
Com_Printf("%5d samplebits\n", dma.samplebits);
|
||||
Com_Printf("%5d submission_chunk\n", dma.submission_chunk);
|
||||
Com_Printf("%5d speed\n", dma.speed);
|
||||
Com_Printf("%p dma buffer\n", dma.buffer);
|
||||
}
|
||||
|
||||
void
|
||||
S_SoundInfo_f(void)
|
||||
{
|
||||
|
@ -118,7 +101,7 @@ S_SoundInfo_f(void)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
DMA_SoundInfo();
|
||||
SDL_SoundInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,7 +152,7 @@ S_Init(void)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
if (SNDDMA_Init())
|
||||
if (SDL_BackendInit())
|
||||
{
|
||||
sound_started = SS_DMA;
|
||||
}
|
||||
|
@ -262,7 +245,7 @@ S_Shutdown(void)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
SNDDMA_Shutdown();
|
||||
SDL_BackendShutdown();
|
||||
}
|
||||
|
||||
sound_started = SS_NOT;
|
||||
|
@ -785,30 +768,6 @@ S_RegisterSexedSound(entity_state_t *ent, char *base)
|
|||
return sfx;
|
||||
}
|
||||
|
||||
static int
|
||||
DMA_DriftBeginofs(float timeofs)
|
||||
{
|
||||
/* drift s_beginofs */
|
||||
int start = (int)(cl.frame.servertime * 0.001f * dma.speed + s_beginofs);
|
||||
|
||||
if (start < paintedtime)
|
||||
{
|
||||
start = paintedtime;
|
||||
s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * dma.speed));
|
||||
}
|
||||
else if (start > paintedtime + 0.3f * dma.speed)
|
||||
{
|
||||
start = (int)(paintedtime + 0.1f * dma.speed);
|
||||
s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * dma.speed));
|
||||
}
|
||||
else
|
||||
{
|
||||
s_beginofs -= 10;
|
||||
}
|
||||
|
||||
return timeofs ? start + timeofs * dma.speed : paintedtime;
|
||||
}
|
||||
|
||||
/*
|
||||
* Validates the parms and ques the sound up if pos is NULL, the sound
|
||||
* will be dynamically sourced from the entity Entchannel 0 will never
|
||||
|
@ -881,7 +840,7 @@ S_StartSound(vec3_t origin, int entnum, int entchannel, sfx_t *sfx,
|
|||
else
|
||||
#endif
|
||||
{
|
||||
ps->begin = DMA_DriftBeginofs(timeofs);
|
||||
ps->begin = SDL_DriftBeginofs(timeofs);
|
||||
ps->volume = fvol * 255;
|
||||
}
|
||||
|
||||
|
@ -941,7 +900,7 @@ S_ClearBuffer(void)
|
|||
clear = 0;
|
||||
}
|
||||
|
||||
SNDDMA_BeginPainting();
|
||||
SDL_BeginPainting();
|
||||
|
||||
if (dma.buffer)
|
||||
{
|
||||
|
@ -957,7 +916,7 @@ S_ClearBuffer(void)
|
|||
}
|
||||
}
|
||||
|
||||
SNDDMA_Submit();
|
||||
SDL_Submit();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1284,7 +1243,7 @@ GetSoundtime(void)
|
|||
|
||||
/* it is possible to miscount buffers if it has wrapped twice between
|
||||
calls to S_Update. Oh well. This a hack around that. */
|
||||
samplepos = SNDDMA_GetDMAPos();
|
||||
samplepos = SDL_GetPos();
|
||||
|
||||
if (samplepos < oldsamplepos)
|
||||
{
|
||||
|
@ -1411,7 +1370,7 @@ S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
|
|||
return;
|
||||
}
|
||||
|
||||
SNDDMA_BeginPainting();
|
||||
SDL_BeginPainting();
|
||||
|
||||
if (!dma.buffer)
|
||||
{
|
||||
|
@ -1447,7 +1406,7 @@ S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
|
|||
|
||||
S_PaintChannels(endtime);
|
||||
|
||||
SNDDMA_Submit();
|
||||
SDL_Submit();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue