luv

Workshop wiki

construction.lisp

luvcraft/agent/construction.lisp

system luvcraft/agent · 23 definitions · on GitHub

in-package#:luvcraft.agent

Construction approval: an actual possible world, not a drafting diagram. This first primitive is deliberately additive. Its preview can therefore draw the exact candidate blocks over live terrain without pretending it can hide removals that the renderer has already submitted.

defclassblock-change-set
coordinates:initarg:coordinates:readerblock-change-set-coordinates
expected:initarg:expected:readerblock-change-set-expected
proposed:initarg:proposed:readerblock-change-set-proposed
lookup:initarg:lookup:readerblock-change-set-lookup
bounds:initarg:bounds:readerblock-change-set-bounds
world-revision:initarg:world-revision:readerblock-change-set-world-revision
:documentation

A frozen sparse voxel edit: dense coordinate/value columns plus lookup.

defunblock-change-set-count
change-set
length
block-change-set-proposedchange-set
defunblock-change-set-coordinate
change-setindex
let
coordinates
block-change-set-coordinateschange-set
offset
*3index
values
arefcoordinatesoffset
arefcoordinates
+offset1
arefcoordinates
+offset2
defunmake-additive-box-change-set
worldkindx1y1z1x2y2z2

Freeze the air cells in inclusive box corners into one additive change set.

unless
luvcraft::block-kind-placeable-pkind
error"~A is not a placeable block kind."
luvcraft:block-kind-namekind
let*
minimum-x
minx1x2
maximum-x
maxx1x2
minimum-y
miny1y2
maximum-y
maxy1y2
minimum-z
minz1z2
maximum-z
maxz1z2
volume
*
1+
-maximum-xminimum-x
1+
-maximum-yminimum-y
1+
-maximum-zminimum-z
when
error"The ~D-cell box exceeds the basic proposal limit of ~D cells."volume*maximum-construction-proposal-cells*
let
coordinate-listnil
expected-listnil
proposed-listnil
loopforzfromminimum-ztomaximum-zdo
loopforyfromminimum-ytomaximum-ydo
loopforxfromminimum-xtomaximum-xdo
multiple-value-bind
oldresidency
unless
eqresidency:resident
error"Cell ~D ~D ~D is not loaded (~(~A~))."xyzresidency
cond
nullold
pushxcoordinate-list
pushycoordinate-list
pushzcoordinate-list
pushnilexpected-list
pushkindproposed-list
not
eqoldkind
error"The additive preview would replace ~A at ~D ~D ~D."
luvcraft:block-kind-nameold
xyz
when
nullproposed-list
error"Every cell in that box is already ~A."
luvcraft:block-kind-namekind
let*
coordinates
make-array
lengthcoordinate-list
:element-type'fixnum:initial-contents
nreversecoordinate-list
expected
coerce
nreverseexpected-list
'simple-vector
proposed
coerce
nreverseproposed-list
'simple-vector
lookup
make-hash-table:test#'equal
dotimes
index
lengthproposed
multiple-value-bind
xyz
let
offset
*3index
values
arefcoordinatesoffset
arefcoordinates
+offset1
arefcoordinates
+offset2
setf
gethash
listxyz
lookup
index
make-instance'block-change-set:coordinatescoordinates:expectedexpected:proposedproposed:lookuplookup:bounds
listminimum-xminimum-yminimum-zmaximum-xmaximum-ymaximum-z
:world-revision
world:block-world-revisionworld
defunvalidate-block-change-set
change-setworld

Require every site to remain resident and equal to its frozen expectation.

dotimes
indext
multiple-value-bind
xyz
multiple-value-bind
currentresidency
unless
eqresidency:resident
error"Proposal cell ~D ~D ~D is no longer resident."xyz
unless
eqcurrent
aref
block-change-set-expectedchange-set
index
error"Proposal is stale at ~D ~D ~D."xyz
defunblock-change-set-after-value-at
change-setworldxyz
multiple-value-bind
indexproposed-p
gethash
listxyz
block-change-set-lookupchange-set
ifproposed-p
values
aref
block-change-set-proposedchange-set
index
:resident
defunmake-construction-preview-mesh
change-setworld

Mesh only change-set's additions against its complete counterfactual occupancy.

let
vertices
make-array:element-type'single-float:adjustablet:fill-pointer0
face-count0
dotimes
index
multiple-value-bind
xyz
let
block
aref
block-change-set-proposedchange-set
index
multiple-value-bind
sky-levelblock-levellight-status
declare
ignorelight-status
loopforfaceinluvcraft::*block-faces*do
let*
direction
luvcraft::block-face-neighborface
nx
world:voxel-direction-dxdirection
ny
world:voxel-direction-dydirection
nz
world:voxel-direction-dzdirection
multiple-value-bind
neighborresidency
block-change-set-after-value-atchange-setworld
+xnx
+yny
+znz
when
and
eqresidency:resident
incfface-count
let
corners
luvcraft::block-face-cornersface
dolist
corner-index'
012023
let
corner
nthcorner-indexcorners
multiple-value-bind
uv
luvcraft::push-block-vertex-componentsvertices
+x
firstcorner
+y
secondcorner
+z
thirdcorner
uvnxnynz
/
orsky-level0
15.0
/
orblock-level0
15.0
tile0.00.00.00.0
let
packed
make-array
lengthvertices
:element-type'single-float:initial-contentsvertices
make-instance'luvcraft:block-mesh:verticespacked:vertex-count:face-countface-count
defclassconstruction-preview-overlay
approval:initarg:approval:readerconstruction-preview-approval
mesh:initarg:mesh:readerconstruction-preview-mesh
vertex-buffer:initarg:vertex-buffer:accessorconstruction-preview-vertex-buffer
:documentation

GPU-owned rendering of one inert construction proposal.

defmethodluvcraft:luvcraft-overlay-stage
declare
ignoreoverlay
:scene
defmethodluvcraft:encode-luvcraft-overlay
sessionpasssurface-texture
let
mesh
construction-preview-meshoverlay
luv:set-bind-grouppass0
luvcraft::luvcraft-frame-scene-bind-groupframe
luv:set-vertex-bufferpass0
construction-preview-vertex-bufferoverlay
luv:drawpass
luvcraft:block-mesh-vertex-countmesh
overlay
defmethodluvcraft:release-luvcraft-overlay
alexandria:when-let
buffer
construction-preview-vertex-bufferoverlay
setf
construction-preview-vertex-bufferoverlay
nil
defunmake-construction-preview-overlay
approval
let*
session
tool-approval-sessionapproval
mesh
make-construction-preview-mesh
construction-approval-change-setapproval
luvcraft:luvcraft-session-worldsession
vertices
luvcraft:block-mesh-verticesmesh
buffer
luv:create
luvcraft:luvcraft-session-devicesession
luv:make-buffer-descriptor:label"construction possible world":size
max4
*4
lengthvertices
:usage'
:vertex:copy-dst
luv:write-bufferbuffervertices
make-instance'construction-preview-overlay:approvalapproval:meshmesh:vertex-bufferbuffer
defclassconstruction-approval
change-set:initarg:change-set:readerconstruction-approval-change-set
preview:initformnil:accessorconstruction-approval-preview
:documentation

Approval for a frozen additive block change set.

defmethodvalidate-tool-approval
validate-block-change-set
construction-approval-change-setapproval
luvcraft:luvcraft-session-world
tool-approval-sessionapproval
defunapply-block-change-set
change-setworld&keyafter-edit

Publish change-set as one world revision, optionally calling after-edit.

world:with-world-change-transaction
world
dotimes
index
multiple-value-bind
xyz
let
block
aref
block-change-set-proposedchange-set
index
whenafter-edit
funcallafter-editblockxyz
change-set
defmethodcommit-tool-approval
let*
session
tool-approval-sessionapproval
world
luvcraft:luvcraft-session-worldsession
change-set
construction-approval-change-setapproval
apply-block-change-setchange-setworld:after-edit
lambda
blockxyz
destructuring-bind
min-xmin-ymin-zmax-xmax-ymax-z
block-change-set-boundschange-set
let
wake-radius
+2.0
sqrt
+
expt
-max-xmin-x
2
expt
-max-zmin-z
2
alexandria:when-let
physics
luvcraft::luvcraft-session-physicssession
luvcraft:wake-physics-bodies-nearphysics
/
+min-xmax-x1
2.0
/
+min-ymax-y1
2.0
/
+min-zmax-z1
2.0
wake-radius
change-set
defmethoddetach-tool-approval
let
presence
tool-approval-presenceapproval
session
tool-approval-sessionapproval
when
eqapproval
embodied-agent-pending-approvalpresence
setf
embodied-agent-pending-approvalpresence
nil
alexandria:when-let
preview
construction-approval-previewapproval
setf
construction-approval-previewapproval
nil
alexandria:when-let
dialogue

Session teardown may already have disowned this frame before it reaches the semantic gnome overlay. A normal decision repaints; a dead mirror has nothing left to update.

unless
eq:disowned
frame-state
mcluv:widget-overlay-framedialogue
approval
defmethodtool-approval-focus-camera-pose
presencesession
declare
ignorepresencesession
destructuring-bind
min-xmin-ymin-zmax-xmax-ymax-z
block-change-set-bounds
construction-approval-change-setapproval
let*
center-x
/
+min-xmax-x1
2.0d0
center-y
/
+min-ymax-y1
2.0d0
center-z
/
+min-zmax-z1
2.0d0
radius
*0.5d0
sqrt
+
expt
1+
-max-xmin-x
2
expt
1+
-max-ymin-y
2
expt
1+
-max-zmin-z
2
distance
max5.0d0
+2.5d0
*radius1.45d0
seconds
/
-
get-internal-real-time
tool-approval-created-atapproval
floatinternal-time-units-per-second1.0d0
angle
+0.65d0
*seconds0.16d0
dx
-center-x
luvcraft::vec3-xposition
dy
-center-y
luvcraft::vec3-yposition
dz
-center-z
luvcraft::vec3-zposition
flat
max0.001d0
sqrt
+
*dxdx
*dzdz
luvcraft::make-camera-poseposition
atandxdz
atandyflat
luvcraft::+luvcraft-camera-focused-vertical-field-of-view+
define-presentation-methodpresent
approvalstream
viewtextual-view
&key
let
change-set
construction-approval-change-setapproval
destructuring-bind
min-xmin-ymin-zmax-xmax-ymax-z
block-change-set-boundschange-set
formatstream"Construction proposal ~(~A~): ~D block~:P in [~D,~D,~D]..[~D,~D,~D]"
tool-approval-stateapproval
min-xmin-ymin-zmax-xmax-ymax-z
when
tool-approval-noteapproval
formatstream" — ~A"
tool-approval-noteapproval
defuninstall-construction-approval
approval
let
presence
tool-approval-presenceapproval
session
tool-approval-sessionapproval
when
embodied-agent-pending-approvalpresence
error"~A already has a proposal waiting for the player."
let

A rejected ADD consumes PREVIEW. Publish approval state only after the application owns the corresponding visible attachment.

setf
construction-approval-previewapproval
preview
embodied-agent-pending-approvalpresence
approval
approval
define-command
com-propose-block-box:command-tableluvcraft-agent:name"Propose Block Box"
kind'luvcraft:block-kind:prompt"kind"
x1'integer:prompt"first x"
y1'integer:prompt"first y"
z1'integer:prompt"first z"
x2'integer:prompt"second x"
y2'integer:prompt"second y"
z2'integer:prompt"second z"
"Propose filling the inclusive axis-aligned box between two corners with KIND. The call waits while the player sees the possible world and approves, denies, or types revision guidance. This basic preview adds blocks only and never replaces occupied cells."
let*
presence
andagent
world-agent-presenceagent
session
unless
typeppresence'embodied-agent
error"A construction proposal needs an embodied agent beside the player."
install-construction-approval
make-instance'construction-approval:agentagent:presencepresence:sessionsession:change-set
make-additive-box-change-set
luvcraft:luvcraft-session-worldsession
kindx1y1z1x2y2z2