Skip to content

Commit d22492d

Browse files
committed
WIP sdl3 support
1 parent b8680c0 commit d22492d

File tree

6 files changed

+1735
-41
lines changed

6 files changed

+1735
-41
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ endif
148148

149149
# Select the system layer
150150
ifeq ($(RENDERTYPE),SDL)
151-
ENGINEOBJS+= $(SRC)/sdlayer2.$o
151+
ENGINEOBJS+= $(SRC)/sdlayer$(RENDERTYPEVER).$o
152152
OURCFLAGS+= $(SDLCONFIG_CFLAGS)
153153
OURLDFLAGS+= $(SDLCONFIG_LIBS)
154154

Makefile.shared

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,24 @@ else
8383
endif
8484

8585
ifeq ($(RENDERTYPE),SDL)
86-
ifneq ($(SDL2CONFIG),)
87-
SDLCONFIG_CFLAGS=$(shell $(SDL2CONFIG) --cflags)
88-
SDLCONFIG_LIBS=$(shell $(SDL2CONFIG) --libs)
86+
ifneq (,$(shell $(PKGCONFIG) --exists sdl3 && echo yes))
87+
SDLCONFIG_CFLAGS=$(shell $(PKGCONFIG) --cflags sdl3)
88+
SDLCONFIG_LIBS=$(shell $(PKGCONFIG) --libs sdl3)
89+
RENDERTYPEVER=3
8990
else
90-
$(error No $(SDL2CONFIG) could be found)
91+
ifneq (,$(shell $(PKGCONFIG) --exists sdl2 && echo yes))
92+
SDLCONFIG_CFLAGS=$(shell $(PKGCONFIG) --cflags sdl2)
93+
SDLCONFIG_LIBS=$(shell $(PKGCONFIG) --libs sdl2)
94+
RENDERTYPEVER=2
95+
else
96+
ifneq ($(SDL2CONFIG),)
97+
SDLCONFIG_CFLAGS=$(shell $(SDL2CONFIG) --cflags)
98+
SDLCONFIG_LIBS=$(shell $(SDL2CONFIG) --libs)
99+
RENDERTYPEVER=2
100+
else
101+
$(error No SDL2 or SDL3 could be found)
102+
endif
103+
endif
91104
endif
92105

93106
ifeq (1,$(WITHOUT_GTK))
@@ -106,6 +119,7 @@ ifeq ($(RENDERTYPE),WIN)
106119
BUILDLDFLAGS+= -mwindows -ldxguid
107120
#BUILDLDFLAGS+= -static
108121
#BUILDLDFLAGS+= -static-libgcc -static-libstdc++
122+
RENDERTYPEVER=1
109123
endif
110124

111125
# Until I work out how to deal with PIE and PIC, the x86 inline
@@ -114,7 +128,7 @@ endif
114128
USE_ASM=0
115129
#endif
116130

117-
BUILDCPPFLAGS+= -DRENDERTYPE$(RENDERTYPE)=1
131+
BUILDCPPFLAGS+= -DRENDERTYPE$(RENDERTYPE)=$(RENDERTYPEVER)
118132

119133
ifneq (0,$(USE_POLYMOST))
120134
BUILDCPPFLAGS+= -DUSE_POLYMOST=$(USE_POLYMOST)

kenbuild/src/kdmsound_sdl3.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Ken Silverman's official web site: "http://www.advsys.net/ken"
2+
// See the included license file "BUILDLIC.TXT" for license info.
3+
//
4+
// This file has been modified from Ken Silverman's original release
5+
// by Jonathon Fowler (jf@jonof.id.au)
6+
7+
#if defined __APPLE__
8+
# include <SDL3/SDL.h>
9+
#else
10+
# include "SDL.h"
11+
#endif
12+
13+
#define KDMSOUND_INTERNAL
14+
#include "kdmsound.h"
15+
16+
#if (SDL_MAJOR_VERSION != 3)
17+
# error This must be built with SDL3
18+
#endif
19+
20+
static SDL_AudioStream *dev;
21+
static int bytespertic;
22+
23+
static void SDLCALL preparesndbuf(void *udata, SDL_AudioStream *stream, int need, int total);
24+
25+
#define min(a,b) ((a)<(b)?(a):(b))
26+
#define max(a,b) ((a)>(b)?(a):(b))
27+
28+
void initsb(char dadigistat, char damusistat, int dasamplerate, char danumspeakers, char dabytespersample, char daintspersec, char daquality)
29+
{
30+
SDL_AudioSpec want;
31+
32+
(void)daintspersec; (void)daquality;
33+
34+
if (dev) return;
35+
36+
if ((dadigistat == 0) && (damusistat != 1))
37+
return;
38+
39+
SDL_memset(&want, 0, sizeof(want));
40+
want.freq = dasamplerate;
41+
want.format = dabytespersample == 1 ? SDL_AUDIO_U8 : SDL_AUDIO_S16;
42+
want.channels = max(1, min(2, danumspeakers));
43+
44+
if (!SDL_InitSubSystem(SDL_INIT_AUDIO)) {
45+
SDL_Log("Failed to initialise SDL audio subsystem: %s", SDL_GetError());
46+
return;
47+
}
48+
49+
dev = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &want, preparesndbuf, NULL);
50+
if (!dev) {
51+
SDL_Log("Failed to open audio: %s", SDL_GetError());
52+
return;
53+
}
54+
if (initkdm(dadigistat, damusistat, want.freq, want.channels, SDL_AUDIO_BITSIZE(want.format)>>3)) {
55+
SDL_DestroyAudioStream(dev);
56+
dev = NULL;
57+
SDL_Log("Failed to initialise KDM");
58+
return;
59+
}
60+
61+
loadwaves("waves.kwv");
62+
bytespertic = (SDL_AUDIO_BITSIZE(want.format)>>3)*want.channels*(((want.freq/120)+1)&~1);
63+
64+
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(dev));
65+
}
66+
67+
void uninitsb(void)
68+
{
69+
if (dev) SDL_DestroyAudioStream(dev);
70+
dev = NULL;
71+
72+
uninitkdm();
73+
}
74+
75+
int lockkdm(void)
76+
{
77+
if (!dev) return -1;
78+
SDL_LockAudioStream(dev);
79+
return 0;
80+
}
81+
82+
void unlockkdm(void)
83+
{
84+
if (!dev) return;
85+
SDL_UnlockAudioStream(dev);
86+
}
87+
88+
void refreshaudio(void)
89+
{
90+
}
91+
92+
void SDLCALL preparesndbuf(void *udata, SDL_AudioStream *stream, int need, int total)
93+
{
94+
Uint8 *sndoffsplc;
95+
int sndbufsiz = bytespertic;
96+
97+
(void)udata; (void)total;
98+
99+
if (need > 0) {
100+
while (sndbufsiz < need) sndbufsiz+=bytespertic;
101+
if ((sndoffsplc = SDL_stack_alloc(Uint8, sndbufsiz))) {
102+
preparekdmsndbuf(sndoffsplc, sndbufsiz);
103+
SDL_PutAudioStreamData(stream, sndoffsplc, sndbufsiz);
104+
SDL_stack_free(sndoffsplc);
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)