DoomPDF
+This is a Doom source port that runs inside a PDF file.
+Source code: https://github.com/ading2210/doompdf
+ ++ +
+ +
+ +
+
Note: the PDF only works inside Chromium-based browsers.
+diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fe2fcb87a..6665640ef 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,8 +17,6 @@ jobs: source .venv/bin/activate pip3 install -r requirements.txt env CFLAGS=-O3 ./build.sh - cp index.html out - rm out/compiled.js du -sh out/* - name: Publish to Cloudflare Pages diff --git a/build.sh b/build.sh index 6acca1ac7..fdbbe10ff 100755 --- a/build.sh +++ b/build.sh @@ -21,6 +21,11 @@ fi emmake make -C doomgeneric -f Makefile.pdfjs -j$(nproc --all) mkdir -p out +cp web/* out/ + python3 embed_file.py file_template.js doomgeneric/doom1.wad out/data.js cat pre.js out/data.js doomgeneric/doomgeneric.js > out/compiled.js -python3 generate.py out/compiled.js out/doom.pdf \ No newline at end of file +cat pre.js file_template.js doomgeneric/doomgeneric.js > out/compiled_nowad.js + +python3 generate.py out/compiled.js out/doom.pdf +python3 generate.py out/compiled_nowad.js out/doom_nowad.pdf \ No newline at end of file diff --git a/doomgeneric/doomgeneric_pdfjs.c b/doomgeneric/doomgeneric_pdfjs.c index b17ea61a2..ac46025da 100644 --- a/doomgeneric/doomgeneric_pdfjs.c +++ b/doomgeneric/doomgeneric_pdfjs.c @@ -131,9 +131,10 @@ void doomjs_tick() { int main(int argc, char **argv) { EM_ASM({ - let stream = FS.open("/doom1.wad", "w+"); - FS.write(stream, file_data, 0, file_data.length, 0); - FS.close(stream); + write_file(file_name, file_data); + if (file2_data) { + write_file(file2_name, file2_data); + } }); doomgeneric_Create(argc, argv); diff --git a/embed_file.py b/embed_file.py index 33f417752..3732e9779 100644 --- a/embed_file.py +++ b/embed_file.py @@ -6,7 +6,8 @@ with open(sys.argv[2], "rb") as f: b64 = base64.b64encode(f.read()).decode() - js = js.replace("__b64_data__", b64, 1) + js = js.replace("__iwad_file__", b64, 1) + js = js.replace("__iwad_filename__", "doom1.wad", 1) with open(sys.argv[3], "w") as f: f.write(js) \ No newline at end of file diff --git a/file_template.js b/file_template.js index b55586686..424bd0121 100644 --- a/file_template.js +++ b/file_template.js @@ -12,4 +12,17 @@ function b64_to_uint8array(str) { return new Uint8Array(result); } -var file_data = b64_to_uint8array("__b64_data__"); \ No newline at end of file +var file_data = b64_to_uint8array("__iwad_file__"); +var file_name = "__iwad_filename__" +var file2_data = b64_to_uint8array("__wad_file__"); +var file2_name = "__wad_filename__" + +if (file_data.length <= 9) { + throw "Error: IWAD not found."; +} +if (file2_data.length <= 9) { + file2_data = null; +} +else { + Module.arguments = ["-file", file2_name]; +} \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 232015afc..000000000 --- a/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - -
- - - -Redirecting to /doom.pdf...
- - \ No newline at end of file diff --git a/pre.js b/pre.js index d9527e8f2..557052fc2 100644 --- a/pre.js +++ b/pre.js @@ -64,3 +64,9 @@ function reset_input_box() { } app.setInterval("reset_input_box()", 1000); +function write_file(filename, data) { + let stream = FS.open("/"+filename, "w+"); + FS.write(stream, data, 0, data.length, 0); + FS.close(stream); +} + diff --git a/web/favicon.ico b/web/favicon.ico new file mode 100644 index 000000000..2e2bf57d9 Binary files /dev/null and b/web/favicon.ico differ diff --git a/web/favicon.png b/web/favicon.png new file mode 100644 index 000000000..64a594fa1 Binary files /dev/null and b/web/favicon.png differ diff --git a/web/index.css b/web/index.css new file mode 100644 index 000000000..5c4029b54 --- /dev/null +++ b/web/index.css @@ -0,0 +1,56 @@ +* { + font-family: Arial, Helvetica, sans-serif; + box-sizing: border-box; +} +body { + padding: 8px; + margin: 0px; + width: 100%; + background-color: #222222; +} + +.spacer { + flex-grow: 1; +} + +#article { + background-color: whitesmoke; + padding: 12px; + border-radius: 4px; + + position: absolute; + top: 50%; + left: 50%; + width: 550px; + height: 300px; + margin-left: -275px; + margin-top: -150px; +} +#header_box { + display: flex; + align-items: center; + gap: 8px; +} +#header_box > h1 { + margin: 0px; +} +#controls_box { + display: flex; + align-items: center; +} +#controls_box > * { + font-size: 14px; +} +#wad_container { + align-items: center; + font-size: 12px; + display: none; + margin-top: 12px; +} +#play_button { + text-decoration: none; + color: black; + background-color: lightgray; + padding: 8px; + border-radius: 3px; +} \ No newline at end of file diff --git a/web/index.html b/web/index.html new file mode 100644 index 000000000..bb9eee95f --- /dev/null +++ b/web/index.html @@ -0,0 +1,44 @@ + + + + + +This is a Doom source port that runs inside a PDF file.
+Source code: https://github.com/ading2210/doompdf
+ +Note: the PDF only works inside Chromium-based browsers.
+