Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Features and changelog since the [initial](https://blog.cloudflare.com/doom-mult
- Over-the-Internet multiplayer support using WebSocket TCP connections and a Durable Object for communication and routing between clients.
- Durable Object router: migrated away from fetch to [invoke RPC methods](https://developers.cloudflare.com/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/#invoke-rpc-methods). 🆕
- Uses Workers AI [Text-to-Spech models](https://developers.cloudflare.com/workers-ai/models/?tasks=Text-to-Speech) to "speak" the multi-player and system game messages. 💬 🆕
- Engine-side state introspection for AI agents via [`wmcp_get_state_json`](doom/src/doom/wmcp_state.c), a patched-in `EMSCRIPTEN_KEEPALIVE` export that reads `gamestate`, `players[consoleplayer]` and the global `thinkercap` mobj chain, returning a JSON snapshot (HUD, keys, enemies in FOV with bearing/distance bins) matching the [`DoomVisionState`](src/lib/doomState.ts) schema. Surfaced to model contexts as the `get_state` WebMCP tool alongside the existing `get_screenshot`. 🆕

## Running locally and deploying

Expand Down
16 changes: 15 additions & 1 deletion doom/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ if (DEFINED EMSCRIPTEN)
# by net_websockets.c)
# -gsource-map / --source-map-base / - emit a wasm sourcemap
# -O3 - override the project-wide -O2 default
set(EM_LINK_FLAGS "${SDL_FLAGS} -s SDL2_MIXER_FORMATS=[\"ogg\"] -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=64MB -s ASYNCIFY=1 -s EMULATE_FUNCTION_POINTER_CASTS=1 -s EXIT_RUNTIME=1 -s ASSERTIONS=0 -s STACK_OVERFLOW_CHECK=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s FORCE_FILESYSTEM=1 -s EXPORTED_RUNTIME_METHODS=ccall,cwrap,FS,ENV,PATH,ERRNO_CODES,callMain -s EXPORTED_FUNCTIONS=_main -lwebsocket.js -O3 -gsource-map --source-map-base /")
# EXPORTED_FUNCTIONS additions:
# _wmcp_get_state_json - reads a snapshot of the game state from
# C globals (players[], gamestate, automapactive, thinkercap)
# and returns a static-buffer JSON string. Called from the
# React app's `get_state` WebMCP tool via Module.ccall.
# _wmcp_get_framebuffer_rgba - returns a pointer to a static
# 320x200 RGBA snapshot of I_VideoBuffer with the current palette
# applied. Called from the `get_screenshot` WebMCP tool to build
# a pixel-perfect PNG without going through the scaled DOM canvas.
# _wmcp_get_menu_json - reads currentMenu / itemOn / save
# strings and returns a JSON description of the active menu
# (labels resolved from M_XXXXX lump names, with a special case
# for the load/save slot menus). Called from the `get_menu`
# WebMCP tool.
set(EM_LINK_FLAGS "${SDL_FLAGS} -s SDL2_MIXER_FORMATS=[\"ogg\"] -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=64MB -s ASYNCIFY=1 -s EMULATE_FUNCTION_POINTER_CASTS=1 -s EXIT_RUNTIME=1 -s ASSERTIONS=0 -s STACK_OVERFLOW_CHECK=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s FORCE_FILESYSTEM=1 -s EXPORTED_RUNTIME_METHODS=ccall,cwrap,FS,ENV,PATH,ERRNO_CODES,callMain,HEAPU8 -s EXPORTED_FUNCTIONS=_main,_wmcp_get_state_json,_wmcp_get_framebuffer_rgba,_wmcp_get_menu_json -lwebsocket.js -O3 -gsource-map --source-map-base /")
set_target_properties("${PROGRAM_PREFIX}doom" PROPERTIES LINK_FLAGS "${EM_LINK_FLAGS}")
endif()
3 changes: 2 additions & 1 deletion doom/src/doom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ add_library(doom STATIC
statdump.c statdump.h
st_lib.c st_lib.h
st_stuff.c st_stuff.h
wi_stuff.c wi_stuff.h)
wi_stuff.c wi_stuff.h
wmcp_state.c)

target_include_directories(doom PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")

Expand Down
Loading