PlayerController API
Interface ID 11, version 2.0. Include <ROCK/PlayerController.h>. Namespace rock::api::playercontroller. Permissions: Read (1) for the state, Write (2) for jumps. Reads the player's native character controller and requests native jumps; wall climbing uses both.
Entry points
| Function | Permission | Thread | Purpose |
|---|---|---|---|
getPlayerControllerState | Read | Game | Controller position, velocity, support and shape. NotReady before the provider and controller are ready. |
requestPlayerControllerJump | Write | Game | Starts a native jump of heightGameUnits. |
getSample | Read | Any | Identity of the current publication. |
requestPlayerControllerJump returns InvalidArgument for a height outside (0, kMaxNativeJumpHeightGame = 256] or a zero generation, GenerationMismatch for stale generations and NotReady while physics writes are not allowed. There is no teleport, velocity setter or penetration query.
Records
PlayerControllerState:sample;flags(PlayerControllerStateFlag:Valid,PositionValid,VelocityValid,ShapeValid,SupportNormalValid,Supported,Sliding,Proxy,RigidBody);implementation(PlayerControllerImplementation:Unknown,Proxy,RigidBody);supportState(PlayerSupportState:Unsupported,Sliding,Supported);positionGame,velocityGame,supportNormalGame;radiusGame,heightGame(capsule shape). Read a vector only when its...Validflag is set.PlayerControllerJumpRequest:heightGameUnitsand the world, skeleton and provider generations copied from a state'ssample.
PlayerControllerStateFlag bits 7 and 8 (penetration) are retired and never reused.
rock::api::playercontroller::PlayerControllerState state{};
if (controller->getPlayerControllerState(client.owner(), &state) == rock::api::Status::Ok) {
rock::api::playercontroller::PlayerControllerJumpRequest jump{};
jump.heightGameUnits = 64.0f;
jump.worldGeneration = state.sample.worldGeneration;
jump.skeletonGeneration = state.sample.skeletonGeneration;
jump.providerGeneration = state.sample.providerGeneration;
controller->requestPlayerControllerJump(client.owner(), &jump);
}
Declarations
Complete public declarations: ROCK/PlayerController.h
ROCK/PlayerController.h
#pragma once
#include "Abi.h"
#pragma pack(push, 8)
namespace rock::api::playercontroller {
inline constexpr InterfaceId kInterfaceId = InterfaceId::PlayerController;
inline constexpr std::uint32_t kMajor = 2;
inline constexpr std::uint32_t kMinor = 0;
inline constexpr float kMaxNativeJumpHeightGame = 256.0f;
enum class PlayerControllerImplementation : std::uint32_t
{
Unknown = 0,
Proxy = 1,
RigidBody = 2,
};
enum class PlayerSupportState : std::uint32_t
{
Unsupported = 0,
Sliding = 1,
Supported = 2,
};
// Bits 7 (penetration checked) and 8 (penetrating) are retired; never
// reuse them.
enum class PlayerControllerStateFlag : std::uint32_t
{
None = 0,
Valid = 1u << 0,
PositionValid = 1u << 1,
VelocityValid = 1u << 2,
ShapeValid = 1u << 3,
SupportNormalValid = 1u << 4,
Supported = 1u << 5,
Sliding = 1u << 6,
Proxy = 1u << 9,
RigidBody = 1u << 10,
};
// The generations must match the current publication (read them from a
// state's sample); a stale request is refused with GenerationMismatch.
struct PlayerControllerJumpRequest
{
std::uint32_t size{ sizeof(PlayerControllerJumpRequest) };
std::uint32_t version{ 1 };
float heightGameUnits{ 0.0f };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
};
// The player's native character controller, in game units.
struct PlayerControllerState
{
std::uint32_t size{ sizeof(PlayerControllerState) };
std::uint32_t version{ 1 };
Sample sample{};
std::uint32_t flags{ 0 };
PlayerControllerImplementation implementation{ PlayerControllerImplementation::Unknown };
PlayerSupportState supportState{ PlayerSupportState::Unsupported };
Point3 positionGame{};
Point3 velocityGame{};
Point3 supportNormalGame{};
float radiusGame{ 0.0f };
float heightGame{ 0.0f };
};
// 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, Read.
Status(ROCK_CALL* getPlayerControllerState)(OwnerToken owner, PlayerControllerState* outState) noexcept;
// Game thread, Write. Height in (0, kMaxNativeJumpHeightGame].
Status(ROCK_CALL* requestPlayerControllerJump)(OwnerToken owner, const PlayerControllerJumpRequest* request) noexcept;
// Any thread. Identity of the current publication.
Status(ROCK_CALL* getSample)(OwnerToken owner, Sample* outSample) noexcept;
};
}
#pragma pack(pop)