1
0
Fork 0

Replace SDL 1.2 with SDL 2.0

This massive patch is based on work of NY00123, which was published on
Vogons forum in 2013 and was waiting for inclusion in SVN since then:

https://www.vogons.org/viewtopic.php?f=41&t=34770

Revision from December 2018 was used to kickstart this work. However, a
number of changes were implemented:

- Original patch preserves all SDL 1.2 code by ifdefing it; this patch
  completely removes all code ifdefed for several versions of SDL 1.2.*
  This way the code will be easier to maintain going forward and
  features enabled by SDL 2.0 do not need to be backported.
  A side-effect of this change is almost-complete removal of DirectDraw
  support - but users can now use Direct3D based acceleration (without
  any ifdefs in code).
- Code ifdefed for Android was removed to make the project easier to
  understand and modify. Android port should still be possible, but it
  requires more work (mostly CI and buildsystem work).
  Android-related functionalities that were cross-platform were
  preserved.
- Code ifdefed for OpenGL ES (which was only used for Android) was
  removed - this should not affect Android support, as
  hardware-accelerated 2D should still be viable via "texture" output,
  but it was not tested, as buildsystem does not support Android ATM.
- SDL_cdrom code is not included; it was outside of scope of SDL2
  changes. Inclusion of that library did not justify supporting one
  small usecase (playblack of CD audio from physical CDs).
- Few code warning were fixed (but new sdl_mapper implementation
  introduces many, many new warnings).
- Some formatting changes were implemented.

Overall, the original patch had ~40k lines of code - here it was
trimmed to +769,-972 (so more old code got removed than new code added).

This implementation was extensively tested on Linux and somewhat tested
on Windows 10.  It fixes numerous issues (too many too list).

Testing found two small regressions:

- Starting game in fullscreen makes it impossible to switch back to
  windowed mode correctly (Windows 10)
- Scaling works a bit worse, only in text mode, only in window (Linux)

This implementation introduces revised user settings in sdl section - it
is only partly compatible with settings from SDL 1.2; this is an issue,
but it will need to be addressed in a separete commit.
This commit is contained in:
Patryk Obara 2019-12-22 04:02:56 +01:00 committed by Patryk Obara
parent 3eaabb41c1
commit a06035a35e
4 changed files with 768 additions and 972 deletions

View file

@ -89,6 +89,8 @@ static struct {
bool nosound;
Bit32u freq;
Bit32u blocksize;
//Note: As stated earlier, all sdl code shall rather be in sdlmain
SDL_AudioDeviceID sdldevice;
} mixer;
Bit8u MixTemp[MIXER_BUFSIZE];
@ -149,6 +151,14 @@ void MIXER_DelChannel(MixerChannel* delchan) {
}
}
static void MIXER_LockAudioDevice(void) {
SDL_LockAudioDevice(mixer.sdldevice);
}
static void MIXER_UnlockAudioDevice(void) {
SDL_UnlockAudioDevice(mixer.sdldevice);
}
void MixerChannel::UpdateVolume(void) {
volmul[0]=(Bits)((1 << MIXER_VOLSHIFT)*scale[0]*volmain[0]*mixer.mastervol[0]);
volmul[1]=(Bits)((1 << MIXER_VOLSHIFT)*scale[1]*volmain[1]*mixer.mastervol[1]);
@ -205,9 +215,9 @@ void MixerChannel::Enable(bool _yesno) {
enabled=_yesno;
if (enabled) {
freq_counter = 0;
SDL_LockAudio();
MIXER_LockAudioDevice();
if (done<mixer.done) done=mixer.done;
SDL_UnlockAudio();
MIXER_UnlockAudioDevice();
}
}
@ -450,14 +460,14 @@ void MixerChannel::AddSamples_s32_nonnative(Bitu len,const Bit32s * data) {
}
void MixerChannel::FillUp(void) {
SDL_LockAudio();
MIXER_LockAudioDevice();
if (!enabled || done<mixer.done) {
SDL_UnlockAudio();
MIXER_UnlockAudioDevice();
return;
}
float index=PIC_TickIndex();
Mix((Bitu)(index*mixer.needed));
SDL_UnlockAudio();
MIXER_UnlockAudioDevice();
}
extern bool ticksLocked;
@ -507,12 +517,12 @@ static void MIXER_MixData(Bitu needed) {
}
static void MIXER_Mix(void) {
SDL_LockAudio();
MIXER_LockAudioDevice();
MIXER_MixData(mixer.needed);
mixer.tick_counter += mixer.tick_add;
mixer.needed+=(mixer.tick_counter >> TICK_SHIFT);
mixer.tick_counter &= TICK_MASK;
SDL_UnlockAudio();
MIXER_UnlockAudioDevice();
}
static void MIXER_Mix_NoSound(void) {
@ -536,6 +546,7 @@ static void MIXER_Mix_NoSound(void) {
}
static void SDLCALL MIXER_CallBack(void * userdata, Uint8 *stream, int len) {
memset(stream, 0, len);
Bitu need=(Bitu)len/MIXER_SSIZE;
Bit16s * output=(Bit16s *)stream;
Bitu reduce;
@ -763,7 +774,7 @@ void MIXER_Init(Section* sec) {
LOG_MSG("MIXER: No Sound Mode Selected.");
mixer.tick_add=calc_tickadd(mixer.freq);
TIMER_AddTickHandler(MIXER_Mix_NoSound);
} else if (SDL_OpenAudio(&spec, &obtained) <0 ) {
} else if ((mixer.sdldevice = SDL_OpenAudioDevice(NULL, 0, &spec, &obtained, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE)) ==0 ) {
mixer.nosound = true;
LOG_MSG("MIXER: Can't open audio: %s , running in nosound mode.",SDL_GetError());
mixer.tick_add=calc_tickadd(mixer.freq);
@ -775,7 +786,7 @@ void MIXER_Init(Section* sec) {
mixer.blocksize=obtained.samples;
mixer.tick_add=calc_tickadd(mixer.freq);
TIMER_AddTickHandler(MIXER_Mix);
SDL_PauseAudio(0);
SDL_PauseAudioDevice(mixer.sdldevice, 0);
}
mixer.min_needed=section->Get_int("prebuffer");
if (mixer.min_needed>100) mixer.min_needed=100;
@ -784,3 +795,12 @@ void MIXER_Init(Section* sec) {
mixer.needed=mixer.min_needed+1;
PROGRAMS_MakeFile("MIXER.COM",MIXER_ProgramStart);
}
void MIXER_CloseAudioDevice(void) {
if (!mixer.nosound) {
if (mixer.sdldevice != 0) {
SDL_CloseAudioDevice(mixer.sdldevice);
mixer.sdldevice = 0;
}
}
}