Skip to main content

Touch API

Interface ID 5, version 2.0. Include <ROCK/Touch.h>. Namespace rock::api::touch. Permissions: Read (1) for states and samples, Write (2) for targets, yields and authored hands. Lets a mod make bodies and surfaces holdable by ROCK's hands (doors, levers, sliders, climbable surfaces) and reserve a hand for its own authored interaction.

Entry points​

FunctionPermissionThreadPurpose
setTouchGrabTargetsForScopeWriteGameReplaces every target of a scope (nonzero, owner-chosen); up to kMaxTargets (256) per call and kMaxScopes (64) scopes.
clearTouchGrabTargetsForScopeWriteGameRemoves the scope's targets; held targets are released.
copyTouchGrabStatesForScopeReadGameCopies up to maxStates target states and the count copied.
requestTouchGrabYieldWriteGameAsks ROCK to let go of a held target (release reason OwnerYield).
setAuthoredHandWriteGame, including BeforeRockTakes or refreshes the lease on one hand.
clearAuthoredHandWriteGameReleases the lease.
getSampleReadAnyIdentity of the current publication.

setTouchGrabTargetsForScope returns OwnerConflict for a scope owned by another mod and GenerationMismatch for stale generations.

Touch-grab targets​

TouchGrabTarget:

  • targetId and targetGeneration: your identity for the target.
  • kind (TouchGrabKind): FixedAnchor (the hand latches to a point or surface), LimitedHinge or LimitedPrismatic (the hand drives a one-axis mechanism around pivotWorldGame and axisWorldGame between minimumCoordinate and maximumCoordinate, starting at currentCoordinate).
  • bodyId names one live dynamic or keyframed body. With MatchAnyBody, a FixedAnchor target instead matches any body whose layer is in allowedLayerMask and whose motion type is enabled by MatchStaticMotion, MatchKeyframedMotion or MatchDynamicMotion, without changing that body's motion type. This is the hand-to-surface latch climbing mods use.
  • flags (TouchGrabTargetFlag): AllowRightHand, AllowLeftHand, AllowTwoHands, LatchOnRelease, FallbackOnly (wildcard surfaces considered after explicit bodies, native authored points, close objects and ordinary wildcard registrations), ExcludePowerArmor.
  • leaseFrames 1 to kMaxLeaseFrames (120): the target expires unless set again.
  • World, skeleton and provider generations from the current publication.

TouchGrabState reports phase (Inactive, Armed, Held, Latched, Yielded, Invalidated), releaseReason (GripReleased, OwnerYield, TargetRemoved, RegistrationExpired, GenerationChanged, WorldLost, TargetInvalid, HandUnavailable), activeHandMask (Right 1, Left 2), flags (TouchGrabStateFlag), the current coordinate and its velocity, the contact point and normal, surfaceGripMode (CollisionAnchor, MeshAnchor, CollisionFallback, AnimatedArmorBone), the frame, the four generations, and a sequence that increases on every change of that target's state.

Authored hand​

One lease per physical hand; a competing owner gets OwnerConflict, a stale sample GenerationMismatch. Refresh it every frame (leaseFrames 1 to 3) with sample copied from the current publication. AuthoredFlag:

  • Indicator: ROCK shows its authored marker at contactWorldGame.
  • ReserveGrab: new ROCK grabs on that hand are consumed before static and climbing acquisition. Existing holds are not revoked.
  • Attached (requires ReserveGrab): only that hand's dynamic collider stops colliding with world surfaces; the other hand, actors, tools and queries are unaffected.

Your mod owns reach and occupancy checks, the grip pose and the mechanism's movement. Clearing, expiry, owner loss and generation or lifecycle loss remove the lease.

rock::api::touch::TouchGrabTarget lever{};
lever.targetId = 1;
lever.kind = rock::api::touch::TouchGrabKind::LimitedHinge;
lever.bodyId = leverBody;
lever.flags = static_cast<std::uint32_t>(rock::api::touch::TouchGrabTargetFlag::AllowRightHand);
lever.leaseFrames = 2;
// pivot, axis, coordinate range and generations from the current sample
touch->setTouchGrabTargetsForScope(client.owner(), myScope, &lever, 1);

Declarations​

Complete public declarations: ROCK/Touch.h
ROCK/Touch.h
#pragma once
#include "Abi.h"

#pragma pack(push, 8)
namespace rock::api::touch {
inline constexpr InterfaceId kInterfaceId = InterfaceId::Touch;
inline constexpr std::uint32_t kMajor = 2;
inline constexpr std::uint32_t kMinor = 0;
inline constexpr std::uint32_t kMaxTargets = 256;
inline constexpr std::uint32_t kMaxScopes = 64;
inline constexpr std::uint32_t kMaxLeaseFrames = 120;

/*
* A touch-grab target turns a body or surface into something a hand can
* hold instead of a loose-object grab. Limited mechanisms name one live
* dynamic or keyframed body. FixedAnchor may instead match a bounded
* collision layer/motion mask without changing that body's motion type;
* this is the hand-to-surface latch primitive climbing consumers use.
*/
enum class TouchGrabKind : std::uint32_t
{
FixedAnchor = 0,
LimitedHinge = 1,
LimitedPrismatic = 2,
};

enum class TouchGrabTargetFlag : std::uint32_t
{
None = 0,
AllowRightHand = 1u << 0,
AllowLeftHand = 1u << 1,
AllowTwoHands = 1u << 2,
LatchOnRelease = 1u << 3,
MatchAnyBody = 1u << 4,
MatchStaticMotion = 1u << 5,
MatchKeyframedMotion = 1u << 6,
MatchDynamicMotion = 1u << 7,
// Wildcard FixedAnchor only. Considered after explicit bodies, native
// authored points, close objects and ordinary wildcard registrations.
FallbackOnly = 1u << 8,
// Exclude native power-armor furniture and power-armor actors.
ExcludePowerArmor = 1u << 9,
// Wildcard FixedAnchor only. A grip that is already held latches the
// moment that hand touches a matching surface; without this flag a
// target is taken only on the grip press.
AcquireWhileGripHeld = 1u << 10,
};

enum class TouchGrabPhase : std::uint32_t
{
Inactive = 0,
Armed = 1,
Held = 2,
Latched = 3,
Yielded = 4,
Invalidated = 5,
};

enum class TouchGrabReleaseReason : std::uint32_t
{
None = 0,
GripReleased = 1,
OwnerYield = 2,
TargetRemoved = 3,
RegistrationExpired = 4,
GenerationChanged = 5,
WorldLost = 6,
TargetInvalid = 7,
HandUnavailable = 8,
};

enum class TouchGrabStateFlag : std::uint32_t
{
None = 0,
ContactPointValid = 1u << 0,
ContactNormalValid = 1u << 1,
CoordinateValid = 1u << 2,
FixedAnchor = 1u << 3,
OriginalMotionKeyframed = 1u << 4,
OriginalMotionDynamic = 1u << 5,
MeshSurfaceAnchor = 1u << 6,
MeshFingerPose = 1u << 7,
MeshCollisionFallback = 1u << 8,
};

enum class SurfaceGripMode : std::uint32_t
{
CollisionAnchor = 0,
MeshAnchor = 1,
CollisionFallback = 2,
AnimatedArmorBone = 3,
};

enum class TouchGrabHandMask : std::uint32_t
{
None = 0,
Right = 1u << 0,
Left = 1u << 1,
};

// The generations must match the current publication; leaseFrames is
// 1..kMaxLeaseFrames and the target expires unless set again.
struct TouchGrabTarget
{
std::uint32_t size{ sizeof(TouchGrabTarget) };
std::uint32_t version{ 1 };
std::uint64_t targetId{ 0 };
std::uint32_t targetGeneration{ 0 };
TouchGrabKind kind{ TouchGrabKind::FixedAnchor };
std::uint32_t flags{ 0 };
std::uint32_t bodyId{ 0x7FFF'FFFF };
std::uint32_t referenceFormId{ 0 };
std::uint32_t referenceNativeHandle{ 0 };
std::uint64_t allowedLayerMask{ 0 };
std::uint32_t leaseFrames{ 0 };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
Point3 pivotWorldGame{};
Point3 axisWorldGame{};
float minimumCoordinate{ 0.0f };
float maximumCoordinate{ 1.0f };
float currentCoordinate{ 0.0f };
};

// sequence increases on every change of this target's state.
struct TouchGrabState
{
std::uint32_t size{ sizeof(TouchGrabState) };
std::uint32_t version{ 1 };
std::uint64_t targetId{ 0 };
std::uint32_t targetGeneration{ 0 };
TouchGrabKind kind{ TouchGrabKind::FixedAnchor };
TouchGrabPhase phase{ TouchGrabPhase::Inactive };
TouchGrabReleaseReason releaseReason{ TouchGrabReleaseReason::None };
std::uint32_t bodyId{ 0x7FFF'FFFF };
std::uint32_t referenceFormId{ 0 };
std::uint32_t referenceNativeHandle{ 0 };
std::uint32_t activeHandMask{ 0 };
std::uint32_t flags{ 0 };
SurfaceGripMode surfaceGripMode{ SurfaceGripMode::CollisionAnchor };
float currentCoordinate{ 0.0f };
float coordinateVelocity{ 0.0f };
Point3 contactPointGame{};
Point3 contactNormalGame{};
std::uint64_t frameIndex{ 0 };
std::uint64_t sequence{ 0 };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
std::uint32_t collisionGeneration{ 0 };
};

enum class AuthoredFlag : std::uint32_t
{
Indicator = 1,
ReserveGrab = 2,
Attached = 4,
};

/*
* One lease per physical hand; a competing owner is rejected. Refresh it
* every frame (leaseFrames 1..3), with sample taken from the current
* publication. Indicator shows ROCK's authored marker at contactWorldGame.
* ReserveGrab consumes new ROCK grabs before static/climbing acquisition;
* it does not revoke an existing object or climbing hold. Attached
* requires ReserveGrab and suppresses only the owned dynamic hand's
* simulation pairs against world-surface layers; the other hand, actors,
* tools and queries are unaffected. Clear, expiry, owner loss and
* generation or lifecycle loss remove the lease. The caller owns reach and
* occupancy checks, the grip pose and the mechanism's movement.
*/
struct AuthoredHand
{
std::uint32_t size{ sizeof(AuthoredHand) };
std::uint32_t version{ 1 };
Sample sample{};
Hand hand{ Hand::None };
std::uint32_t flags{ 0 };
std::uint32_t referenceFormId{ 0 };
std::uint32_t leaseFrames{ 2 };
Point3 contactWorldGame{};
};

// Permission bits are local to this interface major. Discovery grants none.
enum class Permission : std::uint32_t { Read = 1, Write = 2 };
inline constexpr std::uint32_t kSupportedPermissions = 3;

struct Api
{
static constexpr InterfaceId interfaceId = kInterfaceId;
static constexpr std::uint32_t majorVersion = kMajor;
static constexpr std::uint32_t minorVersion = kMinor;
// Game thread. Replaces the scope's targets (Write).
Status(ROCK_CALL* setTouchGrabTargetsForScope)(OwnerToken owner, std::uint64_t scopeToken, const TouchGrabTarget* targets, std::uint32_t targetCount) noexcept;
Status(ROCK_CALL* clearTouchGrabTargetsForScope)(OwnerToken owner, std::uint64_t scopeToken) noexcept;
// Game thread (Read). Writes up to maxStates states and the count copied.
Status(ROCK_CALL* copyTouchGrabStatesForScope)(OwnerToken owner, std::uint64_t scopeToken, TouchGrabState* outStates, std::uint32_t maxStates, std::uint32_t* outStateCount) noexcept;
Status(ROCK_CALL* requestTouchGrabYield)(OwnerToken owner, std::uint64_t scopeToken, std::uint64_t targetId, std::uint32_t targetGeneration) noexcept;
// Game thread, including BeforeRock (Write).
Status(ROCK_CALL* setAuthoredHand)(OwnerToken owner, const AuthoredHand* request) noexcept;
Status(ROCK_CALL* clearAuthoredHand)(OwnerToken owner, Hand hand) noexcept;
// Any thread. Identity of the current publication.
Status(ROCK_CALL* getSample)(OwnerToken owner, Sample* outSample) noexcept;
};
}

#pragma pack(pop)