DIFF

class CCTLiquidFrameProbe

CCTLiquidFrameProbe › Managed

Frame scoped, shared cache of the expensive liquid target queries.

ActionManagerClient.FindContextualUserActions() runs once per frame and feeds the very same PlayerBase, ActionTarget and item to every registered ActionInput, which then calls ActionBase.Can() on each of its candidate actions. With bare hands next to water that means CCTLiquid.Can() runs 4-6 times per frame (drink pond, wash hands, wash head, eat snow, wash hands snow, ...), and with a container in hands another few (fill, mix mortar, wet clothing) - every one of them tracing the exact same cursor position.

The engine queries those conditions need depend only on player + target object + component index + cursor hit position + surface detection type and *not* on the action's liquid mask, max distance or vertical reach. So they are evaluated once per frame and shared, while each condition still applies its own mask and reach checks on the cached values.

Result: N liquid conditions per frame cost 2 GetSurface + 1 raycast in total instead of 2N + N.

Everything is lazy: a payload is only queried when the first condition of the frame actually reaches that check, so an early rejecting frame stays cheap.

Constructors 1

Members 41

protected static ref CCTLiquidFrameProbe m_Instance
Referenced by GetInstance(), and InvalidateFrame()
protected PlayerBase m_Player

Identity of the currently cached frame. The tick time is a secondary guard only - the primary invalidation is the explicit InvalidateFrame() from ActionManagerBase.Update(), because GetTickTime() is a float and its resolution degrades below one frame on long running servers.

Referenced by Begin()
protected Object m_TargetObject
Referenced by Begin()
protected int m_ComponentIndex
Referenced by Begin()
protected vector m_HitPosition
protected int m_SurfaceDetectionType
Referenced by Begin()
protected bool m_HasFrame
Referenced by Begin(), and Invalidate()
protected bool m_LiquidSurfaceQueried

Cursor liquid surface (includeWater).

protected bool m_LiquidSurfaceValid
protected float m_LiquidSurfaceHeight
protected int m_LiquidSurfaceType
protected bool m_LiquidSurfaceHasType
protected bool m_NonWaterSurfaceQueried

Cursor terrain/roadway surface (no water), for the water-below-grass test.

protected bool m_NonWaterSurfaceValid
protected float m_NonWaterSurfaceHeight
protected bool m_ClearPathQueried

Line of sight to the liquid point. Memoized on the tested position.

Referenced by Begin(), and HasClearPath()
protected vector m_ClearPathPosition
Referenced by HasClearPath()
protected bool m_ClearPathValue
Referenced by HasClearPath()
protected bool m_SeaLevelsQueried

Sea levels, world constants but re-read once per frame.

Referenced by Begin(), and GetSeaLevels()
protected float m_SeaLevel
Referenced by GetSeaLevels()
protected float m_SeaLevelMax
Referenced by GetSeaLevels()
protected bool m_WaterLevelQueried

Player water level. Memoized on (player, playerPos) rather than on the Begin() frame key, because it depends only on where the player stands and not on the target being evaluated.

protected PlayerBase m_WaterLevelPlayer
Referenced by GetPlayerWaterLevel()
protected vector m_WaterLevelPos
Referenced by GetPlayerWaterLevel()
protected vector m_WaterLevelValue
Referenced by GetPlayerWaterLevel()
protected bool m_WellQueried

Well liquid source components. Memoized on the tested object + component.

Referenced by Begin(), and IsWellComponentValid()
protected Object m_WellObject
protected int m_WellComponentIndex
protected bool m_WellValue
protected ref SurfaceDetectionParameters m_SurfaceParams

Scratch buffers, one set for the whole game instead of one per condition.

protected ref SurfaceDetectionParameters m_SurfaceParamsNoWater
protected ref RaycastRVParams m_RaycastParams
protected ref array<ref RaycastRVResult> m_RaycastResults
protected ref TIntArray m_ComponentIndices
static int m_StatFramesDIAG_DEVELOPER

frames in which the probe was rebuilt

static int m_StatBeginCallsDIAG_DEVELOPER

Can() calls that touched the probe

static int m_StatCacheHitsDIAG_DEVELOPER

Can() calls served from the cached frame

static int m_StatSurfaceTracesDIAG_DEVELOPER
static int m_StatRaycastsDIAG_DEVELOPER
static int m_StatWaterLevelQueriesDIAG_DEVELOPER

Methods 15

bool Begin(PlayerBase player, Object targetObject, int componentIndex, vector hitPosition, SurfaceDetectionType surfaceDetectionType)

Declares the inputs the calling condition is about to evaluate. If they match the currently cached frame everything below is served from the cache, otherwise the cache is dropped.

Returns: true when the cached frame was reused

bool GetCursorLiquidSurface(out float surfaceHeight, out int liquidType, out bool hasSurfaceType)

Liquid surface under the cached cursor position.

bool GetCursorNonWaterSurface(out float surfaceHeight)

Highest non-liquid surface under the cached cursor position.

bool HasClearPath(PlayerBase player, vector surfacePos)
void GetPlayerWaterLevel(notnull PlayerBase player, out vector waterInfo)

Shared water level under the player, as returned by HumanCommandSwim.WaterLevelCheck: (totalWaterDepth, characterDepth, 0).

Several liquid actions resolve their stance from this every frame (see ActionBase.Can() -> GetClosestPossibleStance() -> GetStanceMask()), all with the same arguments, so the query is done once per frame and shared.

bool IsWellComponentValid(Object well, int componentIndex)

Is the aimed at component one of the well's liquid source components.

bool TraceLiquidSurface(vector probePosition, out float surfaceHeight, out int liquidType, out bool hasSurfaceType)

Uncached surface trace at an arbitrary position, for the camera ray march in CCTLiquidSyntheticCursor which samples many different positions.

bool TraceNonWaterSurface(vector probePosition, out float surfaceHeight)

The result object is reused, never read a stale surface.

void Invalidate()

Drops the cached frame. Called once per action manager update, and usable from anywhere that changes the world mid frame.

Referenced by InvalidateFrame()
static void InvalidateFrame()

No-op when no liquid condition has ever run, so the hook in ActionManagerBase.Update() does not create the probe for nothing.

References Invalidate(), and m_Instance