fuaZandroX modding reference

Psprite layers

A psprite ("player sprite") is one of the sprites drawn in front of the player's view — the weapon in their hands, its muzzle flash, the Strife targeter reticles. Each psprite lives on a numbered layer.

Stock Zandronum has exactly five psprites, in a fixed array: the weapon, its flash, and three targeter slots. There is no way for a mod to add a sixth. ZandroX replaces that array with a container addressed by layer id, so a weapon can create as many layers as it wants at whatever ids it likes, and the A_Overlay family manipulates them.

Availability

ZandroX only. Neither the layer model nor the A_Overlay family exists in Zandronum 3.2.

Works in netgames. A player's client runs its own weapon's states, overlays included, as it always ran the weapon layer. A jump only the server can decide (A_Jump, A_JumpIf and the like) reaches the client from the server, on any layer; a client still behind the server first runs its layer up to the frame that jumped, so it skips none of the frames before it. Other players' layers are never sent, since nobody sees another player's weapon.

Layer ids

A layer id is any int. Five ids are reserved by the engine:

Constant Value Layer
PSP_WEAPON 1 The ready weapon's own sprite.
PSP_FLASH 1000 The weapon's muzzle flash (what A_GunFlash sets).
— 2147483645 Strife targeter, centre.
— 2147483646 Strife targeter, left.
— 2147483647 Strife targeter, right. The highest layer number there is.

These values match GZDoom's, so a layer number copied out of a GZDoom mod lands in the same place relative to the weapon.

Use ids 2 and up, or -2 and down. This is GZDoom's recommendation and it applies here too: it keeps clear of the reserved ids, including -1, which GZDoom reserves as PSP_STRIFEHANDS for Strife's burning-hands effect. ZandroX does not reserve -1 — its A_ItBurnsItBurns drives the weapon layer directly — so -1 works in this engine, but a mod that uses it will misbehave if it is ever run under GZDoom.

Layer 0 is not a real layer. Passing 0 as the layer argument of any A_Overlay function means "the layer whose state is currently executing" — see OverlayID. Outside a psprite state action there is no such layer, and the call does nothing.

Draw order

Layers are drawn in ascending id order, so a higher id draws in front of a lower one:

  • An overlay at id 2..999 draws in front of the weapon but behind the flash.
  • An overlay at id 1001 or above draws in front of the flash.
  • A negative id draws behind the weapon — useful for a left hand, a shield, or a backdrop the weapon sits on top of.

The three targeter layers are drawn in a separate later pass and always sit in front of everything else.

Layer lifetime

A layer is created by A_Overlay and disappears on any of these:

  • Its state chain ends. An overlay whose state sequence reaches Stop removes itself. This is the normal way to end an overlay, and it is the difference between an overlay and a reserved layer: the weapon and flash layers persist with no state.

  • A_Overlay is called on it with no state, which removes it explicitly.

  • A_ClearOverlays removes it as part of a range.

  • The weapon goes away. Switching weapons, dropping the weapon, and dying clear every overlay but the ones the player class's own states made, which last until they end or are cleared, and run with no weapon up. Overlays are cleared before the incoming weapon's Select state runs, so a weapon may create overlays from Select.

    Differs from UZDoom. There, an overlay a CustomInventory item created persists until the item goes away. ZandroX clears it on weapon switch like a weapon's.

Where these functions can be called from

The A_Overlay family is defined on Actor, as in UZDoom, so it can be called from the states of a weapon, any other inventory item, including CustomInventory, or the player class itself. It does nothing when the calling actor has no player attached.

What a layer carries

Beyond the sprite and frame every psprite has always had, each layer owns:

Property Set by Default
Offset (x, y) A_OverlayOffset (0, 0)
Scale (x, y) A_OverlayScale (1, 1)
Turn A_OverlayRotate 0
Pivot and its corner A_OverlayPivot, A_OverlayPivotAlign (0, 0) from the top left
Corner shifts A_OverlayVertexOffset none
Translation A_OverlayTranslation none
Alpha A_OverlayAlpha 1.0, but unused — the weapon's alpha is drawn
Render style A_OverlayRenderStyle unset — the weapon's style is drawn
PSPF_ flags A_OverlayFlags PSPF_ADDWEAPON, PSPF_ADDBOB, PSPF_POWDOUBLE, PSPF_CVARFAST, PSPF_PIVOTPERCENT

A new overlay therefore follows the weapon by default: PSPF_ADDWEAPON and PSPF_ADDBOB are already set, so it moves with the gun and sways with the player's bob, sitting at the weapon's position until A_OverlayOffset moves it. It also speeds up with PowerDoubleFiringSpeed and sv_fastweapons, as the weapon does. This matches UZDoom. Clear PSPF_ADDWEAPON and PSPF_ADDBOB if you want an overlay pinned to the screen instead.

The overlay is drawn with the weapon's alpha and render style rather than its own until PSPF_ALPHA or PSPF_RENDERSTYLE is set.

The reserved weapon and flash layers ignore the flags entirely and behave exactly as they always have, which is why adding this feature changed nothing about existing weapons.

Implementation notes

The layer container, the reserved-id remapping, and the per-layer render state are in p_pspr.cpp and p_pspr.h; the drawing pass is in features/sprites/pspritebuild.cpp, its corners from features/sprites/computation/pspritequad_compute.cpp. The branch-heavy decisions are extracted into computation/psprite_overlay_compute.cpp with colocated tests. A jump on an overlay reaches clients as FuaSetPlayerPSpriteLayer (protocolspec/spec.misc.txt).

Introduced in #44.

See also

The A_Overlay family
A_Overlay A_OverlayFlags
A_ClearOverlays A_OverlayOffset
OverlayID A_OverlayScale
A_OverlayAlpha
A_OverlayRenderStyle
A_OverlayRotate
A_OverlayPivot
A_OverlayPivotAlign
A_OverlayVertexOffset
A_OverlayTranslation