DetPhysDocs日本語

detphys_turn.hturn-based sessions, transport interface, loopback (version 9)

Transport interface and loopback

FunctionDescription
detphys_loopback_desc_defaultDefault loopback settings (no delay, no loss)
detphys_loopback_createCreates a loopback joining two peers in one process
detphys_loopback_destroyDestroys it
detphys_loopback_transportGets the transport of side 0 or 1
detphys_loopback_pumpAdvances time by one (the unit of delay)
detphys_loopback_get_statsSent, dropped, duplicated, delivered counts
StructDescription
detphys_transportThe transport interface (send, recv and user). Implement this for Steam, EOS and so onUsage: Transports and room codes › Usage (the same for every transport)
detphys_loopbackA loopback (opaque)
detphys_loopback_descDelay, loss and duplication rates, seed
detphys_loopback_statsLoopback counters

Sessions (rule interface)

FunctionDescription
detphys_turn_abi_versionThis header's version
detphys_turn_config_defaultDefault session settings (up to 900 ticks per turn, 5000 ms peer timeout, 20 ms minimum resend, 250 ms keepalive)
detphys_turn_create_ruleCreates a session with a rule
detphys_turn_create_rule_kinematicSame, also passing a kinematic table (moving concave shapes)Usage: Concepts › Moving concave shapes
detphys_turn_destroyDestroys it
detphys_turn_pollReads what arrived, advances up to max_ticks, sends (resends by count; for in-process tests)
detphys_turn_poll_atSame, with the engine's monotonic clock [µs] (use this on real networks)Usage: Concepts › Transports
detphys_turn_stateCurrent state (DETPHYS_TURN_CONNECTING, WAIT_LOCAL_INPUT, WAIT_REMOTE_INPUT, SIMULATING, WAIT_HASH, WAIT_RESYNC, ERROR, DETPHYS_TURN_PEER_LOST)
detphys_turn_currentCurrent turn number
detphys_turn_current_moverCurrent mover
detphys_turn_submit_wordsSubmits the mover's input (int32 × input_words)Usage: Concepts › Turn-based
detphys_turn_next_resultTakes one finished turn's result (with inputs and state)
detphys_turn_get_statusCurrent status (turn, match, mover, world replacement counter, time since the last packet, …)
detphys_turn_read_stateReads the current match state words
detphys_turn_worldCurrent world (read only)
detphys_turn_errorReason when in ERRORUsage: Desyncs › When peers do not connect (config check mismatch)
detphys_turn_set_timingMinimum resend time and keepalive interval
detphys_turn_set_peer_timeoutPeer timeout (until PEER_LOST)
detphys_turn_set_checkpoint_kindKind of the guest's per-turn checkpoint (FULL default / DYNAMIC / LEGACY)Usage: Concepts › Snapshots
detphys_turn_get_checkpoint_statsCheckpoint counts, sizes and times
detphys_turn_debug_nudge_atTest only: shifts the state by 1 ULP at the start of that turnUsage: Determinism rules › How to check
detphys_turn_get_tag_info, detphys_tag_part_nameReads what a peer with a mismatching config check sends (detphys_tag_info) / returns a part's name. Version 9. See the section belowUsage: Desyncs › When peers do not connect (config check mismatch)
StructDescription
detphys_turn_sessionA session (opaque)
detphys_turn_configSession settings (session id, shapes, peer, first mover, tick limit, world, network values)
detphys_turn_ruleA rule (input and state word counts, params, begin_match, check_input, apply_input, after_tick, end_turn)Usage: Concepts › Rules
detphys_rule_ctxValues passed to callbacks (world, params, state, mover, turn, tick, settled)
detphys_turn_meshShape data (.dnshape bytes)
detphys_turn_resultOne turn's result (hashes, bytes, turn, mover, next mover, ticks, flags [DETPHYS_TURN_FLAG_*])
detphys_turn_statusCurrent status
detphys_turn_checkpoint_statsGuest checkpoint statistics
detphys_tag_infoState of a peer whose config check does not match (136 B, the same as for rt; see the section below)Usage: Desyncs › When peers do not connect (config check mismatch)

Rule return values: after_tick returns DETPHYS_RULE_CONTINUE / END_TURN / END_MATCH; end_turn returns the next mover (OR DETPHYS_RULE_MATCH_OVER to end the match).

Built-in rule: stacking

FunctionDescription
detphys_rule_stack_desc_defaultDefault stacking settings (base 7 m wide, 0.6 m high, top at y = 0; drop clearance 300 mm; x range ±5000 mm; fall line −1000 mm)
detphys_rule_stack_next_defaultDefault next-shape settings (SEED, UNIFORM, a different sequence per match, equal weights, 2 shapes ahead)
detphys_turn_rule_stack_exWrites the stacking rule (with the next-shape settings)
detphys_turn_create_stack_exCreates a stacking session (the easy way from C# and others)Usage: Concepts › Rules
detphys_rule_stack_next_shapeWith SEED, computes the shape of match m, turn t (no session needed)
detphys_turn_rule_stackWrites the stacking rule where the input picks the shape (3 input words)
detphys_turn_create_stackCreates a session with that rule
StructDescription
detphys_rule_stack_descDrop clearance, range, fall line, material, base boxes (1–16)
detphys_rule_stack_nextNext shape (mode SEED / INPUT, seed, draw UNIFORM / BAG, per_match, weights, preview 0–8)
detphys_turn_boxA static box [mm]

3D sessions (version 8)

The turn flow, hash checks, resync, rejoin, host restart and the guest's per-turn checkpoint are the same as in 2D; the world is 3D (detphys3d.h). The config's world and meshes are not used (mesh_count must be 0); register convex hulls in begin_match with detphys3d_world_add_hull, in the same order on both peers. State sent to another peer (resync, joining) uses detphys3d_world_transfer_*. Pass a 3D kinematic table with detphys_turn_create_rule3d_kinematic in detphys3d_kinematic.h (the 2D table of detphys_turn_create_rule_kinematic cannot be used in 3D). A moving kinematic body keeps the world from settling, so end turns in after_tick by tick count or similar. The desync debugger (detphys_turn_set_debug) works in 3D too (when detphys_debug_abi_version() is 3 or later; recordings use the 3D format and reports the 3D fields; see 5. Troubleshooting desyncs).

FunctionDescription
detphys_turn_create_rule3dCreates a session from a 3D rule and 3D world settings (detphys3d_world_desc, NULL = defaults). The world is rebuilt for every matchUsage: Concepts › 3D
detphys_turn_world3dThe current 3D world (read only). For 3D sessions detphys_turn_world returns NULL
StructDescription
detphys_turn_rule3dA 3D rule (same layout as detphys_turn_rule; callbacks receive detphys_rule_ctx3d; 80 B)
detphys_rule_ctx3dValues passed to callbacks (same layout as detphys_rule_ctx; only world is a detphys3d_world*)

Stacking-only functions (new code should use the rule interface above)

Function / structDescription
detphys_turn_desc_default, detphys_turn_createCreate a session from stacking-only settings (uses the built-in stacking rule)
detphys_turn_submitSubmits a stacking input (shape, x, angle)
detphys_turn_next_reportTakes one turn's report (detphys_turn_report)
detphys_turn_desc, detphys_turn_input, detphys_turn_report, detphys_turn_shapeSettings, input, report and shape for the functions above

Desync debugger (turn-based)

FunctionDescription
detphys_turn_set_debugTurns the desync debugger on / off (detphys_debug_session_config)Usage: Desyncs › Turning the desync debugger on
detphys_turn_debug_countNumber of reports
detphys_turn_debug_getReads a report (with the list of differences and the spread)
detphys_turn_debug_bundlePacks a report and both recordings into a bundle (DNDB)
detphys_turn_debug_statsRecording and exchange counters

Peers whose config check does not match (version 9)

Peers whose settings, rule, shapes, hulls, kinematic tables or core version differ do not connect (packets whose config check tag does not match are dropped). Since version 9 (rt: version 7) the session counts those packets and exchanges the tag contents (one hash per part) with that peer, so you can tell which part differs. Read it with detphys_turn_get_tag_info (rt: detphys_rt_get_tag_info); both fill the same struct, detphys_tag_info. The tag values themselves, the existing structs and the protocol are the same as in version 8 (rt: 6). How to read it and what to fix is in 5. Troubleshooting desyncs.

Field (detphys_tag_info, 136 B)Contents
struct_sizeSet to sizeof(detphys_tag_info)
flagsSEEN 0x01 (a mismatching tag arrived), REMOTE_KNOWN 0x02 (the peer's contents arrived), PEER_KNOWS 0x04 (the peer got ours), ACTIVE 0x08 (not connected yet)
local_tag, remote_tagOur tag and the last mismatching peer tag (rt sends only the low 32 bits; before the contents arrive, rt's remote_tag is those 32 bits. Turn-based: 0 when only the session_id differs)
mismatch_packetsNumber of packets dropped because the tag did not match
diff_partsParts that differ (OR of DETPHYS_TAG_PART_*; only with REMOTE_KNOWN. 0 means all parts are equal and only the whole tag differs)
dimensions, remote_dimensions2 or 3 (the peer's only with REMOTE_KNOWN, otherwise 0)
local_version, remote_versionCheck version × 65536 + protocol version (rt: 3 and 3, turn-based: 6 and 4)
local_shape_count, remote_shape_countNumber of shapes (2D: registered shapes / 3D: hulls)
first_shape_diffIndex of the first differing shape (the first DETPHYS_TAG_MAX_SHAPES = 64 are compared; if only the counts differ, the smaller count; −1 = none or unknown)
local_parts[8], remote_parts[8]Hash per part ([i] is part 1 << i; 32 bits, independent of build and device; entries after 5 are 0)
info_sent, info_receivedHow many times we sent our contents / received the peer's (usually 1–2 per side)
Part (DETPHYS_TAG_PART_*)detphys_tag_part_nameContents
VERSION (0x01)versionThe core's check and protocol versions, 2D / 3D
CONFIG (0x02)configsession_id, tick rate, substeps, gravity, 3D contact tuning, turn-based first mover and tick limit per turn
RULE (0x04)rulerule_id, input and state word counts, params
SHAPES (0x08)shapes2D: checksums of the registered shapes (.dnshape) / 3D: checksums and vertex counts of the hulls registered in begin
KINEMATIC (0x10)kinematicThe kinematic table (whether one was passed, flags, contents after begin)

DETPHYS_TAG_PART_COUNT is 5; unknown values are named "unknown". Flags: rt uses DETPHYS_RT_FRAME_TAG_MISMATCH (0x200) in detphys_rt_frame.flags; turn-based sessions use DETPHYS_TAG_INFO_ACTIVE in flags. Both reads can be called at any time (every frame is fine) and return 0 on success, negative for NULL or a wrong struct_size.

DetPhys is not affiliated with Box2D or Box3D and is not endorsed or recommended by Box2D, Box3D or their author. It uses Box2D v3 and Box3D, both under the MIT license, as its physics.

LicensesMatches the current versions (2026-11)

© 2026 PetafProductsContactPrivacy

This site uses no analytics or tracking.

↑↓ to choose, Enter to open, Esc to close