luv

Workshop wiki

surroundings.lisp

luvcraft/agent/surroundings.lisp

system luvcraft/agent · 20 definitions · on GitHub

in-package#:luvcraft.agent

An embodied glance has two inseparable products: a perspective image and a small exact reading of the resident world around the body. The image is what the figure can see; the axis-aligned census is explicitly a sampled neighbourhood rather than a fictitious bounding box for the view frustum.

defparameter*surroundings-above*10
defparameter*surroundings-camera-lift*1.25d0
defparameter*surroundings-look-ahead*3.0d0
defclassneighborhood-census
minimum:initarg:minimum:readercensus-minimum
maximum:initarg:maximum:readercensus-maximum
total:initarg:total:readercensus-total
resident:initarg:resident:readercensus-resident
unavailable:initarg:unavailable:readercensus-unavailable
air:initarg:air:readercensus-air
kind-counts:initarg:kind-counts:readercensus-kind-counts
:documentation

An exact material census over one inclusive integer world box.

defclasssurroundings-observation
png:initarg:png:readersurroundings-png
width:initarg:width:readersurroundings-width
height:initarg:height:readersurroundings-height
subject:initarg:subject:readersurroundings-subject
subject-position:initarg:subject-position:readersurroundings-subject-position
facing-yaw:initarg:facing-yaw:readersurroundings-facing-yaw
camera-position:initarg:camera-position:readersurroundings-camera-position
camera-yaw:initarg:camera-yaw:readersurroundings-camera-yaw
camera-pitch:initarg:camera-pitch:readersurroundings-camera-pitch
player-position:initarg:player-position:readersurroundings-player-position
player-offset:initarg:player-offset:readersurroundings-player-offset
player-distance:initarg:player-distance:readersurroundings-player-distance
world-revision:initarg:world-revision:readersurroundings-world-revision
nearby-edit-count:initarg:nearby-edit-count:readersurroundings-nearby-edit-count
census:initarg:census:readersurroundings-census
:documentation

One clean third-person PNG and the compact world reading captured with it.

defuninclusive-box-volume
minimummaximum
destructuring-bind
minimum-xminimum-yminimum-z
minimum
destructuring-bind
maximum-xmaximum-ymaximum-z
maximum
*
1+
-maximum-xminimum-x
1+
-maximum-yminimum-y
1+
-maximum-zminimum-z
defuncensus-block-neighborhood
worldminimummaximum

Count each resident dense lane of world inside inclusive minimum..maximum.

destructuring-bind
minimum-xminimum-yminimum-z
minimum
destructuring-bind
maximum-xmaximum-ymaximum-z
maximum
let
resident0
air0
counts
make-hash-table:test#'eq
dolist
let*
domain
world:block-chunk-domainchunk
shape
world:voxel-space-chunk-shape
world:chunk-domain-spacedomain
width
world:chunk-shape-widthshape
height
world:chunk-shape-heightshape
depth
world:chunk-shape-depthshape
multiple-value-bind
origin-xorigin-yorigin-z
let
from-x
maxminimum-xorigin-x
from-y
maxminimum-yorigin-y
from-z
maxminimum-zorigin-z
to-x
minmaximum-x
+origin-xwidth-1
to-y
minmaximum-y
+origin-yheight-1
to-z
minmaximum-z
+origin-zdepth-1
when
and
<=from-xto-x
<=from-yto-y
<=from-zto-z
world:with-block-content-storage
dense-domainpaletteindices
chunk
declare
ignoredense-domain
loopforworld-zfromfrom-ztoto-zdo
loopforworld-yfromfrom-ytoto-ydo
loopforworld-xfromfrom-xtoto-xforoffset=
world:chunk-domain-offset-componentsdomain
-world-xorigin-x
-world-yorigin-y
-world-zorigin-z
forblock=
arefpalette
arefindicesoffset
do
incfresident
ifblock
incf
gethash
luvcraft:block-kind-nameblock
counts0
incfair
let
total
inclusive-box-volumeminimummaximum
make-instance'neighborhood-census:minimumminimum:maximummaximum:totaltotal:residentresident:unavailable
-totalresident
:airair:kind-counts
sort
loopfornamebeingthehash-keysofcountsusing
hash-valuecount
collect
consnamecount
lambda
leftright
if
=
cdrleft
cdrright
string<
symbol-name
carleft
symbol-name
carright
>
cdrleft
cdrright
defunauthored-edits-in-box
worldminimummaximum
let
source
world:block-world-sourceworld
if
destructuring-bind
minimum-xminimum-yminimum-z
minimum
destructuring-bind
maximum-xmaximum-ymaximum-z
maximum
loopforcoordinatebeingthehash-keysof
world:block-edit-overlay-entries
luvcraft:little-world-source-editssource
count
destructuring-bind
xyz
coordinate
and
<=minimum-xxmaximum-x
<=minimum-yymaximum-y
<=minimum-zzmaximum-z
0
defunread-binary-file
pathname
with-open-file
streampathname:direction:input:element-type'
unsigned-byte8
let
octets
make-array
file-lengthstream
:element-type'
unsigned-byte8
read-sequenceoctetsstream
octets
defuncapture-surroundings-observation
agent

Capture one clean agent glance, including its bounded dense census.

check-typeagentembodied-agent
let*
session
gnome-sessionagent
world
luvcraft:luvcraft-session-worldsession
player
luvcraft:luvcraft-session-playersession
posenil
factsnil
pathname
merge-pathnames
make-pathname:name
formatnil"luv-surroundings-~36R"
random
expt3610
:type"png"
uiop:temporary-directory
unwind-protect
multiple-value-bind
writtenpixelswidthheightformatmetadata
luvcraft:capture-luvcraft-screenshotsessionpathname:camera-pose
lambda
ignored-session
declare
ignoreignored-session
:metadata-function
lambda
ignored-session
declare
ignoreignored-session
multiple-value-bind
minimummaximum
let*
census
census-block-neighborhoodworldminimummaximum
agent-position
player-position
offset
mapcar#'-player-positionagent-position
distance
sqrt
reduce#'+offset:key
lambda
value
*valuevalue
setffacts
list:subject:subject-positionagent-position:facing-yaw
embodied-agent-facing-yawagent
:player-positionplayer-position:player-offsetoffset:player-distancedistance:world-revision
world:block-world-revisionworld
:nearby-edit-count
authored-edits-in-boxworldminimummaximum
:censuscensus
:include-hud-pnil:include-viewmodel-pnil
declare
ignorepixelsformatmetadata
let
camera-position
luvcraft::camera-pose-positionpose
make-instance'surroundings-observation:png:widthwidth:heightheight:subject
getffacts:subject
:subject-position
getffacts:subject-position
:facing-yaw
getffacts:facing-yaw
:camera-position
list
luvcraft::vec3-xcamera-position
luvcraft::vec3-ycamera-position
luvcraft::vec3-zcamera-position
:camera-yaw
luvcraft::camera-pose-yawpose
:camera-pitch
luvcraft::camera-pose-pitchpose
:player-position
getffacts:player-position
:player-offset
getffacts:player-offset
:player-distance
getffacts:player-distance
:world-revision
getffacts:world-revision
:nearby-edit-count
getffacts:nearby-edit-count
:census
getffacts:census
when
probe-filepathname
delete-filepathname
defunpresent-position
positionstream
destructuring-bind
xyz
position
formatstream"(~,2F, ~,2F, ~,2F)"xyz
define-presentation-methodpresent
observationstream
viewtextual-view
&key
let
census
surroundings-censusobservation
formatstream"~:(~A~) sees a ~Dx~D third-person view, facing ~A.~%"
surroundings-subjectobservation
surroundings-widthobservation
surroundings-heightobservation
compass-word
surroundings-facing-yawobservation
write-string"Agent "stream
present-position
surroundings-subject-positionobservation
stream
write-string"; camera "stream
present-position
surroundings-camera-positionobservation
stream
formatstream" yaw=~,3F pitch=~,3F.~%"
surroundings-camera-yawobservation
surroundings-camera-pitchobservation
write-string"Player "stream
present-position
surroundings-player-positionobservation
stream
write-string"; offset from agent "stream
present-position
surroundings-player-offsetobservation
stream
formatstream"; distance ~,2F.~%"
surroundings-player-distanceobservation
formatstream"Sampled neighbourhood ~S..~S: ~:D cells; ~:D resident (~:D air), ~:D unavailable.~%"
census-minimumcensus
census-maximumcensus
census-totalcensus
census-residentcensus
census-aircensus
census-unavailablecensus
if
census-kind-countscensus
formatstream"Blocks: ~{~(~A~)=~:D~^, ~}.~%"
loopfor
name.count
in
census-kind-countscensus
append
listnamecount
write-string"Blocks: none.~%"stream
formatstream"World revision ~D; ~:D authored edit~:P in the sampled box."
surroundings-world-revisionobservation
surroundings-nearby-edit-countobservation
define-command
com-view-surroundings:command-tableluvcraft-agent:name"View Surroundings"
"Look forward from just above and behind your body. Return a clean third-person image together with agent, camera, and player coordinates and an exact material census of a nearby sampled voxel box. Unavailable cells are distinct from air."
let*
unless
typepsubject'embodied-agent
error"View Surroundings needs an embodied agent presence."
defmethodcommand-tool-runs-on-canvas-p
command
eql'com-view-surroundings

capture-luvcraft-screenshot owns its own canvas request and waits for the readback; nesting it inside execute-command-for-agent would deadlock.

nil
defmethodcommand-provider-output
command
eql'com-view-surroundings
valuestext
declare
ignorecommand
let
observation
firstvalues
openai:make-tool-output:texttext:images
list
openai:make-tool-output-image
surroundings-pngobservation
:media-type"image/png":detail"high"