Skip to content

Commit 86fb74b

Browse files
committed
Add Mp3 (mixer) and TTF
1 parent edd6a68 commit 86fb74b

File tree

16 files changed

+120
-11
lines changed

16 files changed

+120
-11
lines changed

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ RUN git clone https://github.com/kea/php-sdl-image.git && \
6060
mkdir -p /src/php-src/ext/sdl_image && \
6161
cp -r php-sdl-image/* /src/php-src/ext/sdl_image
6262

63+
RUN git clone https://github.com/kea/php-sdl-mixer.git && \
64+
mkdir -p /src/php-src/ext/sdl_mixer && \
65+
cp -r php-sdl-mixer/* /src/php-src/ext/sdl_mixer
66+
67+
RUN git clone https://github.com/kea/php-sdl-ttf.git && \
68+
mkdir -p /src/php-src/ext/sdl_ttf && \
69+
cp -r php-sdl-ttf/* /src/php-src/ext/sdl_ttf
70+
6371
# todo voir
6472
#RUN #git clone https://github.com/krakjoe/parallel.git /tmp/php-parallel && \
6573
# mkdir -p /src/php-src/ext/parallel && \
@@ -69,6 +77,8 @@ RUN git clone https://github.com/kea/php-sdl-image.git && \
6977

7078
COPY config.sdl /src/php-src/ext/sdl/config.m4
7179
COPY config-image.sdl /src/php-src/ext/sdl_image/config.m4
80+
COPY config-mixer.sdl /src/php-src/ext/sdl_mixer/config.m4
81+
COPY config-ttf.sdl /src/php-src/ext/sdl_ttf/config.m4
7282

7383

7484

@@ -140,6 +150,8 @@ RUN --mount=type=cache,target=/emsdk/upstream/emscripten/cache cd /src/php-src &
140150
--with-layout=GNU \
141151
--enable-sdl \
142152
--with-sdl_image \
153+
--enable-sdl_ttf \
154+
--with-sdl_mixer \
143155
# --with-libxml \
144156
--enable-gd \
145157
--with-png \
@@ -197,7 +209,10 @@ RUN --mount=type=cache,target=/emsdk/upstream/emscripten/cache mkdir /build && c
197209
-s USE_LIBPNG=1 \
198210
# -s USE_LIBJPEG=1 \
199211
-s USE_SDL_IMAGE=2 \
212+
-s USE_SDL_MIXER=2 \
213+
-s USE_SDL_TTF=2 \
200214
-s SDL2_IMAGE_FORMATS='["bmp", "png","jpg"]' \
215+
-s SDL2_MIXER_FORMATS='["ogg", "wav", "mp3"]' \
201216
-s FORCE_FILESYSTEM=1 \
202217
-s MAXIMUM_MEMORY=2gb \
203218
-s INITIAL_MEMORY=$INITIAL_MEMORY \

config-mixer.sdl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
dnl config.m4 for extension sdl_mixer
2+
3+
PHP_ARG_WITH([sdl_mixer],
4+
[whether to enable sdl_mixer support],
5+
[AS_HELP_STRING([[--with-sdl_mixer[=DIR]]],
6+
[Include SDL_mixer support. DIR is the SDL_mixer base include and lib directory])])
7+
8+
if test "$PHP_SDL_MIXER" != "no"; then
9+
SEARCH_PATH="/usr/local /usr"
10+
SEARCH_FOR="/include/SDL2/SDL_mixer.h"
11+
AC_MSG_CHECKING([for SDL_mixer files])
12+
if test -r $PHP_SDL_MIXER/$SEARCH_FOR; then # path given as parameter
13+
SDL_MIXER_DIR=$PHP_SDL_MIXER
14+
else # search default path list
15+
for i in $SEARCH_PATH ; do
16+
if test -r $i/$SEARCH_FOR; then
17+
SDL_MIXER_DIR=$i
18+
fi
19+
done
20+
fi
21+
22+
if test -z "$SDL_MIXER_DIR"; then
23+
AC_MSG_RESULT([not found])
24+
AC_MSG_ERROR([Please reinstall the SDL_mixer distribution])
25+
fi
26+
27+
PHP_ADD_INCLUDE($SDL_MIXER_DIR/include)
28+
AC_MSG_RESULT(found in $SDL_MIXER_DIR)
29+
30+
PKG_CHECK_MODULES([_SDL2], [sdl2 < 3.0])
31+
PHP_EVAL_INCLINE($_SDL2_CFLAGS)
32+
33+
dnl === Vérification manuelle avec AC_LINK_IFELSE
34+
save_LIBS="$LIBS"
35+
LIBS="$LIBS -L$SDL_MIXER_DIR/$PHP_LIBDIR -lSDL2 -lSDL2_mixer"
36+
37+
PHP_SUBST(SDL_MIXER_SHARED_LIBADD)
38+
AC_DEFINE(HAVE_SDL_MIXER, 1, [ Have sdl_mixer support ])
39+
40+
41+
CFLAGS="$CFLAGS -sUSE_SDL=2"
42+
CPPFLAGS="$CPPFLAGS -sUSE_SDL=2"
43+
LDFLAGS="$LDFLAGS -sUSE_SDL=2"
44+
45+
PHP_NEW_EXTENSION(sdl_mixer, src/effect_position.c src/effect_stereoreverse.c src/Mix_Music.c src/Mix_Chunk.c src/music.c src/mixer.c php_sdl_mixer.c, $ext_shared, -sUSE_SDL=2 -sUSE_SDL_MIXER=2, -sUSE_SDL=2 -sUSE_SDL_MIXER=2)
46+
PHP_ADD_EXTENSION_DEP(sdl_mixer, sdl)
47+
fi

config-ttf.sdl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
dnl config.m4 for extension sdl_ttf
2+
3+
PHP_ARG_ENABLE([sdl_ttf],
4+
[whether to enable sdl_ttf support],
5+
[AS_HELP_STRING([--enable-sdl_ttf],
6+
[Enable sdl_ttf support])],
7+
[no])
8+
9+
if test "$PHP_SDL_TTF" != "no"; then
10+
AC_DEFINE(WITH_SDL_TTF, 1, [Whether you want SDL Mixer])
11+
AC_MSG_CHECKING([for SDL_ttf.h])
12+
for i in $PHP_SDL_TTF /usr/local /usr; do
13+
if test -r $i/include/SDL2/SDL_ttf.h; then
14+
SDL_TTF_DIR=$i
15+
AC_DEFINE(HAVE_SDL_TTF_H, 1, [Whether you have SDL2/SDL_ttf.h])
16+
PHP_ADD_INCLUDE($i/include/SDL2)
17+
fi
18+
done
19+
20+
if test -z "$SDL_TTF_DIR"; then
21+
AC_MSG_RESULT([not found])
22+
AC_MSG_ERROR([Please reinstall the SDL_ttf distribution including development files])
23+
else
24+
AC_MSG_RESULT([found])
25+
fi
26+
27+
28+
dnl === Vérification manuelle avec AC_LINK_IFELSE
29+
save_LIBS="$LIBS"
30+
LIBS="$LIBS -L$SDL_TTF_DIR/$PHP_LIBDIR -lSDL2 -lSDL2_ttf"
31+
32+
PHP_SUBST(SDL_TTF_SHARED_LIBADD)
33+
AC_DEFINE(HAVE_SDL_TTF, 1, [ Have sdl_ttf support ])
34+
35+
36+
37+
PHP_NEW_EXTENSION(sdl_ttf, sdl_ttf.c, $ext_shared, -sUSE_SDL=2 -sUSE_SDL_TTF=2, -sUSE_SDL=2 -sUSE_SDL_TTF=2)
38+
PHP_ADD_EXTENSION_DEP(sdl_ttf, sdl)
39+
fi

demo/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<textarea id="php" style="display: none">
1919

20+
// TODO : onfocus on wasm ? (pause game)
2021
require ('/src/src/vendor/autoload.php');
2122

2223
// utilise setTimeout

demo/public/out.wasm

-20.2 MB
Binary file not shown.

demo/public/php-web.data

-326 KB
Binary file not shown.

demo/public/php-web.data.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/public/php-web.mjs

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

demo/public/php-web.wasm

1.64 MB
Binary file not shown.

demo/src/src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 37a0c2daef9bdc8d6093c9525fb2c277f4d43c2c
1+
Subproject commit 05b8b12c70ac51f9f7af3f23aee08a85077f2ce4

0 commit comments

Comments
 (0)