How ading2210/doompdf works
Project Type and Overall Purpose
• The project is a source port of the classic Doom game designed to run within a PDF file via embedded JavaScript.
• Its main challenges are compiling C code (using Emscripten targeting asm.js) and interfacing with the very limited IO provided by PDF’s JavaScript, particularly for rendering output (using rows of text fields for the framebuffer) and processing user inputs.
Key Components/Modules Identified from the File Structure
A. Core Game Engine (doomgeneric directory):
• Contains all the C source files for the Doom engine such as game logic (d_main.c, d_loop.c, etc.), graphics rendering (r_draw.c, r_main.c, etc.), sound and input (i_input.c, i_video.c, i_sound.c), and many utility and subsystem files.
• Multiple Makefiles (Makefile.emscripten, Makefile.sdl, and others) indicate support for different build targets/platforms.
B. Build and Compilation System:
• build.sh: Script that automates the build process on Linux. This downloads the older Emscripten version and compiles the engine (targeting asm.js for PDF compatibility).
• Python scripts (embed_file.py, generate.py): Likely help with embedding assets (WAD files) into the PDF or generating necessary code/configuration dynamically.
• requirements.txt: Lists Python dependencies needed, ensuring a reproducible build environment.
C. Web and Deployment Component:
• The “web” directory (with index.html, index.js, index.css) is used to serve and possibly demonstrate the PDF. This might be for hosting a demo or interfacing with the user when custom WADs are inserted via the web interface.
D. PDF-Specific Components:
• The README explains how JavaScript is used inside the PDF. Although not directly present in separate source files, the “pre.js” file and aspects embedded with the C build output contribute to the PDF’s JS that drives the input and text-field based framebuffer.
Relationships and Data Flow
• The Build Process:
• The build.sh script orchestrates the compilation. It calls the appropriate Makefiles (from the doomgeneric directory) to compile the C source using Emscripten.
• The generated asm.js output is then embedded into the PDF. Python scripts (embed_file.py, generate.py) possibly handle the injection of compiled code and optional custom WAD files.
• The PDF Execution Environment:
• Once the PDF is created, its embedded JavaScript (loaded from pre.js and code injected during build) interprets user inputs via form fields (buttons for keys) and updates the display by rewriting text fields (representing row pixels of the game framebuffer).
• The Web Interface:
• The web folder is used to serve the final PDF via a simple HTTP server, providing a user interface particularly for loading custom WADs, as referenced in the README.
Final Checklist
• Major interactions, showing how the game is compiled, embedded within the PDF, and then run inside a PDF viewer with interactive inputs.