Runtime contract
Threads
ROCK runs on the game thread that delivers FRIK's frames. Most calls must be made there; elsewhere they return WrongThread. These calls copy published state and are safe from any thread:
| Interface | Any-thread calls |
|---|---|
| Core | getModVersion, isProviderReady, getSnapshot, registerConsumer, bindInterface, getSample |
| Hands | getHandFrame, getHeadPose, getRoles, getSample |
| Collision | getEnvironment, getSample |
| Grab | getHandInteractionState, getSample |
| Touch, Animation, Input, PlayerController | getSample |
| Weapon | isEquipPickup, getSample |
| WeaponParts | getGripState, setItemState, moveItemState, clearItemStates, setLooseItemModels, clearLooseItemModels, getSample |
Before FRIK's first frame establishes the game thread, Core frame callbacks and Animation phase callbacks may be registered from startup.
Callbacks
| Callback | Runs | May call ROCK |
|---|---|---|
| Core frame callback | Once per ROCK publication | Yes |
| Animation phase callback | At its selected phases | Yes |
| NativeInteraction callbacks | In ROCK's physics frame and Havok substeps; contact callbacks on any physics thread | Only the NativeInteraction calls allowed in that phase |
| Grab event callback | Synchronously on the producing thread | No (Busy) |
| Storage stash converter | On the game thread during a stash | No |
Records passed to a callback are borrowed for the call. Unregistering stops future calls but does not wait for a call already in progress; keep userData valid through it. A faulting callback revokes its owner: everything the owner holds is released, reads keep working, writes and callbacks return OwnerRevoked.
Samples and generations
ROCK publishes once per frame. A Sample names the publication: frameIndex, publicationSequence, and the world, skeleton, provider and collision generations. The world, skeleton and provider generations change when the physics world, FRIK's skeleton or ROCK's runtime are rebuilt (loads, cell changes, power armor). Requests that carry generations are refused with GenerationMismatch when they are stale; copy them from a current sample. Compare samples before combining two reads.
Body ids, source keys and reference keys are values, not pointers, and valid only with their generations. A weapon part's sourceKey holds only for its weaponGenerationKey.
Leases
Suppressions, authorities, targets, drives, displays and reservations are leases of a few frames. Renew each one every frame you need it. A lease ends on expiry, clear, owner loss or a generation change; a lost lease shows up as a failed renew (and, where the interface has one, in its state record). Use frame leases, not wall-clock timers.
Requests and results
RequestQueued admits a request for a later frame; it is not success. Poll the result with the interface's getter (Grab getInteractionCommandResult, Weapon getInventoryEquipResult, Collision ejection clearance and object rest by repeating the request). A request can be cancelled until it commits (AlreadyCommitted afterwards).
There are no event streams. Follow lasting state through state records and their sequence counters (stateSequence, gripSequence, terminalSequence and similar), which advance only when that state changes. Grab's event callback reports one-off moments (pull, catch, impact, release, stash) as they happen.
Records and buffers
- Value-initialize every record (
{}). Records withsizeandversionrequiresize == sizeof(record)andversion == 1, for input and output, or the call returnsInvalidSizeorUnsupportedVersionand touches nothing. - ROCK clears an output record before filling it. Check the status first, then the record's validity flags.
- Copy calls take an element capacity no larger than the interface's
kMax...limit (CapacityFullotherwise), report the total, and copymin(capacity, total). Capacity 0 only counts. - No call hands out engine pointers except NativeInteraction, whose native addresses are borrowed only inside the callback that supplied them.
- Exceptions never cross the boundary; an internal failure returns
InternalErrorand is logged inROCK.log.
Units
Fields named ...Game are game units, ...Havok Havok units; Collision getEnvironment gives both scales. Transform stores the rotation as three rows, the translation and a uniform scale. A value-initialized rotation is all zeros, not an identity: read a transform only when its validity flag is set.