luv

Workshop wiki

intent.lisp

luvcraft/intent.lisp

system luvcraft/core · 8 definitions · on GitHub

in-package#:luvcraft

What a body is trying to do, as distinct from what someone pressed.

A hash of held keys answered "is W down". An intent answers "is this body trying to go forward", which is a question a keyboard, a gamepad, a script, a recorded demo, and an animal's rider can all answer, and which the physics step can read without knowing that keyboards exist.

Every direction is held separately rather than summed into one number, because pressing both W and S is standing still and then letting go of S must leave the player walking forward again. A single axis cannot remember that; a set of urges can.

defclassmovement-intent
urges:initform
make-hash-table:test#'eq
:readermovement-intent-urges:documentation"The urges currently held, as a set of keywords."
jump-requested-p:initformnil:accessormovement-intent-jump-requested-p:documentation"Whether a jump is owed, cleared by whoever performs it."
:documentation

One body's movement will: which directions it is urging, and whether it owes a jump.

The urges are named after the body's own frame -- :FORWARD, :BACKWARD, :LEFT, :RIGHT, and :SPRINT -- rather than after any key or axis, so the same intent serves a walking player and a ridden animal.

defunmake-movement-intent

Construct an intent urging nothing.

make-instance'movement-intent
defunmovement-urging-p
intenturge

Whether intent currently holds urge.

values
gethashurge
movement-intent-urgesintent
defun
valueintenturge

Begin or end intent's urge.

ifvalue
setf
gethashurge
movement-intent-urgesintent
t
remhashurge
movement-intent-urgesintent
value
defunmovement-intent-axis
intentpositivenegative

Return -1, 0, or 1 from the two opposed urges intent holds.

-
if
movement-urging-pintentpositive
1d00d0
if
movement-urging-pintentnegative
1d00d0
defunmovement-intent-sprinting-p
intent

Whether intent is urging its body to hurry.

movement-urging-pintent:sprint
defunmovement-intent-still-p
intent

Whether intent is urging nothing at all.

and
zerop
hash-table-count
movement-intent-urgesintent
not
movement-intent-jump-requested-pintent
defunclear-movement-intent
intent

Let go of everything intent was holding.

clrhash
movement-intent-urgesintent
setf
movement-intent-jump-requested-pintent
nil
intent