Skip to main content

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:

InterfaceAny-thread calls
CoregetModVersion, isProviderReady, getSnapshot, registerConsumer, bindInterface, getSample
HandsgetHandFrame, getHeadPose, getRoles, getSample
CollisiongetEnvironment, getSample
GrabgetHandInteractionState, getSample
Touch, Animation, Input, PlayerControllergetSample
WeaponisEquipPickup, getSample
WeaponPartsgetGripState, 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​

CallbackRunsMay call ROCK
Core frame callbackOnce per ROCK publicationYes
Animation phase callbackAt its selected phasesYes
NativeInteraction callbacksIn ROCK's physics frame and Havok substeps; contact callbacks on any physics threadOnly the NativeInteraction calls allowed in that phase
Grab event callbackSynchronously on the producing threadNo (Busy)
Storage stash converterOn the game thread during a stashNo

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 with size and version require size == sizeof(record) and version == 1, for input and output, or the call returns InvalidSize or UnsupportedVersion and 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 (CapacityFull otherwise), report the total, and copy min(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 InternalError and is logged in ROCK.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.