Skip to content

Commit 376c208

Browse files
committed
best fps
1 parent 36d908a commit 376c208

File tree

12 files changed

+283
-145
lines changed

12 files changed

+283
-145
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.buildx-cache
12
build
23
lib
34
third_party

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ ENV PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/"
132132
#RUN echo "pause here" && sleep infinity
133133

134134
# -s USE_LIBJPEG=1
135-
RUN cd /src/php-src && export PKG_CONFIG_PATH='/usr/lib/x86_64-linux-gnu/pkgconfig/' && ./buildconf --force \
135+
RUN --mount=type=cache,target=/emsdk/upstream/emscripten/cache cd /src/php-src && export PKG_CONFIG_PATH='/usr/lib/x86_64-linux-gnu/pkgconfig/' && ./buildconf --force \
136136
&& emconfigure ./configure \
137137
CFLAGS="-s USE_ZLIB=1 -s USE_LIBPNG=1 " LDFLAGS="-s USE_ZLIB=1 -s USE_LIBPNG=1" \
138138
PKG_CONFIG_PATH='/usr/lib/x86_64-linux-gnu/pkgconfig/' \
@@ -175,7 +175,7 @@ RUN cd /src/php-src && emmake make -j8
175175
# PHP7 outputs a libphp7 whereas php8 a libphp
176176
RUN cd /src/php-src && bash -c '[[ -f .libs/libphp7.la ]] && mv .libs/libphp7.la .libs/libphp.la && mv .libs/libphp7.a .libs/libphp.a && mv .libs/libphp7.lai .libs/libphp.lai || exit 0'
177177
COPY ./source /src/source
178-
RUN cd /src/php-src && emcc $OPTIMIZE \
178+
RUN --mount=type=cache,target=/emsdk/upstream/emscripten/cache cd /src/php-src && emcc $OPTIMIZE \
179179
-I . \
180180
-I Zend \
181181
-I main \
@@ -184,12 +184,12 @@ RUN cd /src/php-src && emcc $OPTIMIZE \
184184
/src/source/phpw.c \
185185
-o /src/phpw.o \
186186
-s ERROR_ON_UNDEFINED_SYMBOLS=0
187-
RUN mkdir /build && cd /src/php-src && emcc $OPTIMIZE \
187+
RUN --mount=type=cache,target=/emsdk/upstream/emscripten/cache mkdir /build && cd /src/php-src && emcc $OPTIMIZE \
188188
-o /build/php-$WASM_ENVIRONMENT.$JAVASCRIPT_EXTENSION \
189189
--llvm-lto 2 \
190190
-fno-inline \
191191
-s DEMANGLE_SUPPORT=1 \
192-
-s EXPORTED_FUNCTIONS='["_phpw", "_phpw_flush", "_phpw_exec", "_phpw_run", "_chdir", "_setenv", "_php_embed_init", "_php_embed_shutdown", "_zend_eval_string"]' \
192+
-s EXPORTED_FUNCTIONS='["_phpw_run", "_chdir", "_setenv", "_php_embed_init", "_php_embed_shutdown", "_zend_eval_string"]' \
193193
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS"]' \
194194
-s ENVIRONMENT=$WASM_ENVIRONMENT \
195195
-s USE_SDL=2 \

demo/public/index.html

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
<html lang="fr">
44
<head>
55
<meta charset="UTF-8" />
6-
<title>Mon site</title>
7-
<link rel="stylesheet" href="./style.css">
8-
<script src="./script.js"></script>
6+
<title>Sonic</title>
97
</head>
108
<body>
119
<style>
@@ -19,20 +17,29 @@
1917

2018
<textarea id="php" style="display: none">
2119

22-
2320
require ('/src/src/vendor/autoload.php');
2421

25-
function sdl_frame($renderer)
22+
// utilise setTimeout
23+
function sdl_update_events($app)
24+
{
25+
// maximum speed (we stop sdl) !
26+
$app->game->disableSdl = true ;
27+
$app->game->gameLoop->start(1);
28+
$app->game->disableSdl = false ;
29+
}
30+
31+
// utilise animatedRequest
32+
function sdl_frame($app)
2633
{
27-
if ($GLOBALS['renderer'] == null)
28-
return ;
34+
if ($app->game->sdl->renderer->getRenderer() == null)
35+
return ;
2936

30-
$GLOBALS['game']->gameLoop->start(1);
37+
$app->game->disableSdl = false ;
38+
$app->game->gameLoop->start(1);
3139
}
3240

33-
$command = include ('/src/src/app.php');
34-
$renderer = $GLOBALS['renderer'] ;
35-
$GLOBALS['game'] = $command->game ;
41+
$app = include ('/src/src/app.php');
42+
3643
</textarea>
3744
<br>
3845
Array Keys , => Camera control : 2 8 6 4 and 5 to recenter , F3 F4 change level ! (dont touch other)
@@ -44,7 +51,6 @@
4451

4552
</textarea>
4653

47-
4854
<script type="module">
4955
import phpBinary from "./php-web.mjs";
5056
async function main() {
@@ -56,50 +62,23 @@
5662
canvas: document.getElementById('canvas'),
5763
print(data) {
5864
console.log(data);
59-
6065
document.getElementById('debug').value += '[stdout]' + data + "\n" ;
61-
// document.getElementById('debug').value = '[stdout]' + data + "\n" + document.getElementById('debug').value + "\n"
6266
}
63-
6467
,
65-
6668
printErr(data) {
6769
console.error('[stderr]', data);
6870
document.getElementById('debug').value += '[stderr]' + data + "\n" ;
69-
// document.getElementById('debug').value = '[stderr]' + data + "\n" + document.getElementById('debug').value + "\n"
7071
}
7172

7273
});
7374

75+
7476
window.FS = FS;
7577
window.run = () => {
76-
// Note that `/src` is the path we used when preloading!
77-
7878
ccall("phpw_run", "void", ["string"], [document.getElementById('php').value]);
79-
// ccall("phpw", null, ["string"], ["/src/index.php"]);
80-
// output.contentWindow.document.body.innerHTML = buffer.join('');
81-
// buffer.length = 0;
8279
}
83-
8480
run();
85-
86-
//alert(document.getElementById('php').value);
87-
88-
// ccall("phpw_run", "void", ["string"], [document.getElementById('php').value]);
89-
9081
return "ok" ;
91-
92-
// console.log(ccall("phpw_exec", "string", ["string"], ["return 2 ;"]));
93-
94-
// window.FS = FS;
95-
// window.run = () => {
96-
// // Note that `/src` is the path we used when preloading!
97-
// //ccall("phpw", null, ["string"], ["/src/index.php"]);
98-
// //output.contentWindow.document.body.innerHTML = buffer.join('');
99-
// // buffer.length = 0;
100-
// }
101-
//
102-
// run();
10382
}
10483

10584
await main();

demo/public/php-web.data

327 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

-5.35 KB
Binary file not shown.

docker-bake.hcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
target "default" {
22
output = ["type=local,dest=./build"]
33
tags = ["php-wasm"]
4+
5+
cache-from = ["type=local,src=./.buildx-cache"]
6+
cache-to = ["type=local,dest=./.buildx-cache"]
47
}

go.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/bin/bash
22

33
#docker buildx bake
4+
5+
docker buildx create --name wasm-builder --driver docker-container --use
6+
docker buildx use wasm-builder
47
docker buildx bake --progress=plain
8+
mkdir -p cache ;
9+
510
cp build/php-web.* demo/public/
611
docker run \
12+
-v $(pwd)/cache:/emsdk/upstream/emscripten/cache \
713
-v $(pwd)/demo/src:/src \
814
-v $(pwd)/demo/public:/dist \
915
-w /dist \
@@ -18,5 +24,8 @@ docker run \
1824
--no-node \
1925
--exclude '*/.*' \
2026
--export-name=createPhpModule
27+
2128
sed '/--pre-js/r demo/public/php-web.data.js' demo/public/php-web.mjs > this-has-preloaded-data-php-web.mjs ; mv this-has-preloaded-data-php-web.mjs demo/public/php-web.mjs
29+
30+
docker buildx use default
2231
php -S 0.0.0.0:80 -t demo/public

index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
require ('/src/src/vendor/autoload.php');
2424

25+
function sdl_update_events()
26+
{
27+
var_dump($GLOBALS['ok']++) ;
28+
}
29+
2530
function sdl_frame($renderer)
2631
{
2732
if ($GLOBALS['renderer'] == null)
@@ -33,6 +38,7 @@
3338
$command = include ('/src/src/app.php');
3439
$renderer = $GLOBALS['renderer'] ;
3540
$GLOBALS['game'] = $command->game ;
41+
$GLOBALS['game']->gameLoop->start(1);
3642
</textarea>
3743
<br>
3844
Array Keys , => Camera control : 2 8 6 4 and 5 to recenter , F3 F4 change level ! (dont touch other)

0 commit comments

Comments
 (0)