luv

Workshop wiki

world-tests.lisp

luvcraft/world-tests.lisp

system luvcraft/core/test · 18 definitions · on GitHub

in-package#:luvcraft.tests
luvcraft.world.fields:define-voxel-field:test-voxel-reading:site-kind:voxel-cell:value-typedouble-float:quantity
:quantity:distance:unit:metre
:missing-value:unavailable:legal-valuesdouble-float:representation:test-v1
defuncoordinate=
leftright
and
=
world-coordinate-xleft
world-coordinate-xright
=
world-coordinate-yleft
world-coordinate-yright
=
world-coordinate-zleft
world-coordinate-zright
deftestsigned-world-coordinate-decomposition
let
space
make-voxel-space:chunk-shape
make-chunk-shape:width16:height8:depth4
:cell-extent
0.5d02d04d0
dolist
case'
-17-215
-16-10
-1-115
000
15015
1610
destructuring-bind
world-xexpected-chunk-xexpected-local-x
case
multiple-value-bind
chunklocal
ok
=
chunk-coordinate-xchunk
expected-chunk-x
ok
=
local-coordinate-xlocal
expected-local-x
ok
=
chunk-coordinate-ychunk
-1
ok
=
local-coordinate-ylocal
7
ok
=
chunk-coordinate-zchunk
1
ok
=
local-coordinate-zlocal
0
deftestlattice-and-metric-storage-declarations-stay-distinct
let*
ok
eq:voxel-cell-extent
luv.arithmetic:quantity-specification-nameextent-quantity
ok
luv.arithmetic:unit-expression='
:metre1
:cell-1
luv.arithmetic:quantity-specification-unitextent-quantity
ok
eq:ray-distance
luv.arithmetic:quantity-specification-namedistance-quantity
ok
luv.arithmetic:unit-expression=:cell
luv.arithmetic:quantity-specification-unitdistance-quantity
deftestvoxel-field-definitions-separate-meaning-from-storage-policy
let*
world
make-block-world:chunk-width2:chunk-height2:chunk-depth2
chunk
column
block-chunk-contentchunk
ok
eq:block-content
luvcraft.world.fields:voxel-field-definition-namedefinition
ok
eq:voxel-cell
luvcraft.world.fields:voxel-field-definition-site-kinddefinition
ok
eq:palette-u16
luvcraft.world.fields:voxel-field-definition-representation-policydefinition
ok
deftestfield-redefinition-has-visible-definition-identity
let*
old-revision
luvcraft.world.fields:voxel-field-definition-revisionold
handler-bind
warning#'muffle-warning
eval'
luvcraft.world.fields:define-voxel-field:test-voxel-reading:site-kind:voxel-cell:value-typedouble-float:quantity
:quantity:distance:unit:metre
:missing-value:unavailable:legal-valuesdouble-float:representation:test-v2
let
ok
not
eqoldnew
ok
not
eqold-revision
luvcraft.world.fields:voxel-field-definition-revisionnew
ok
eq:test-v2
luvcraft.world.fields:voxel-field-definition-representation-policynew
deftestchunk-domain-coordinate-traversal
let*
space
make-voxel-space:chunk-shape
make-chunk-shape:width4:height3:depth2
sitesnil
positive-x-facenil
multiple-value-bind
chunklocal
ok
equalpchunk
ok
equalplocal
multiple-value-bind
offsetdestinationcrossing
ok
=offset18
ok
equalpdestination
ok
nullcrossing
multiple-value-bind
offsetdestinationcrossing
ok
=offset19
ok
equalpdestination
ok
do-chunk-domain-sites
offsetlocaldomain
push
listoffset
local-coordinate-xlocal
local-coordinate-ylocal
local-coordinate-zlocal
sites
ok
=
lengthsites
24
ok
equal
first
lastsites
'
0000
ok
equal
firstsites
'
23321
do-chunk-domain-face
offsetlocaldomain+voxel-positive-x+
declare
ignorelocal
pushoffsetpositive-x-face
ok
equal
nreversepositive-x-face
'
3711151923
deftestpalette-backed-block-content
let*
world
make-block-world:chunk-width4:chunk-height4:chunk-depth4
chunk
column
block-chunk-contentchunk
stone
list:stone
ok
equal
array-element-type
block-content-column-indicescolumn
'
unsigned-byte16
ok
=
length
block-content-column-indicescolumn
64
setfstonestone
ok
=
aref
block-content-column-indicescolumn
0
1
ok
=
aref
block-content-column-indicescolumn
1
1
multiple-value-bind
blockstatus
ok
eqblockstone
ok
eqstatus:resident
multiple-value-bind
blockstatus
ok
nullblock
ok
eqstatus:resident
multiple-value-bind
blockstatus
ok
nullblock
ok
eqstatus:absent
deftestwhole-domain-block-storage-is-borrowed-without-row-objects
let*
world
make-block-world:chunk-width4:chunk-height3:chunk-depth2
chunk
stone
list:stone
describednil
setfstone
ok
=
block-chunk-revisionchunk
1
ok
=
block-world-revisionworld
2
setfstone
ok
=
block-chunk-revisionchunk
1
ok
=
block-world-revisionworld
2
with-block-content-storage
domainpaletteindices
chunk
ok
eqdomain
block-chunk-domainchunk
ok
eqpalette
block-content-column-palette
block-chunk-contentchunk
ok
eqindices
block-content-column-indices
block-chunk-contentchunk
ok
eq
arefpalette
arefindices1
stone
map-chunk-blocks
lambda
blocklocal
whenblock

Retaining local is valid in this presentation protocol; the dense traversal macro itself instead lends a dynamic-extent value.

pushlocaldescribed
chunk
ok
=
lengthdescribed
1
ok
equalp
firstdescribed
deftestchunk-and-residency-revisions
let*
world
make-block-world:chunk-width4:chunk-height4:chunk-depth4
stone
list:stone
chunk
ok
=
block-world-residency-revisionworld
1
ok
=
block-world-revisionworld
1
ok
eqchunk
ok
=
block-world-residency-revisionworld
1
ok
=
block-world-revisionworld
1
ok
=
block-chunk-revisionchunk
0
setfstone
ok
=
block-chunk-revisionchunk
1
ok
=
block-world-revisionworld
2
setfstone
ok
=
block-chunk-revisionchunk
1
ok
=
block-world-revisionworld
2
setfnil
ok
=
block-chunk-revisionchunk
2
ok
=
block-world-revisionworld
3

A resident chunk is still world-owned: lower-level writes must also invalidate world-derived products such as meshes.

setfstone
ok
=
block-chunk-revisionchunk
3
ok
=
block-world-revisionworld
4
multiple-value-bind
removedpresent-p
ok
eqremovedchunk
okpresent-p
ok
=
block-world-residency-revisionworld
2
ok
=
block-world-revisionworld
5
setfstone
ok
=
block-chunk-revisionchunk
4
ok
=
block-world-revisionworld
5
deftestchunk-boundaries-and-world-change-transactions
let*
world
make-block-world:chunk-width4:chunk-height4:chunk-depth4
stone
list:stone
chunknil
with-world-change-transaction
world
setfchunk

Interior content changes do not invalidate neighbor-derived products.

setfstone
ok
=
block-world-revisionworld
1
ok
=
block-world-residency-revisionworld
1
ok
=
block-chunk-revisionchunk
2

A transaction containing only no-op assignments is itself a no-op.

ok
=
block-world-revisionworld
1
setfstone
ok
=
block-world-revisionworld
2
deftestnegative-and-cross-chunk-access
let*
world
make-block-world:chunk-width4:chunk-height4:chunk-depth4
left
right
stone
list:stone
dirt
list:dirt
setfstonedirt
ok
eqstone
ok
eqdirt
multiple-value-bind
blockstatus
ok
nullblock
ok
eqstatus:absent
ok
signals
setfstone
'chunk-not-resident
deftestdomain-identity-and-deterministic-residency
let
world
make-block-world:chunk-width2:chunk-height2:chunk-depth2
let*
domains
mapcar#'block-chunk-domainchunks
x-coordinates
mapcar
lambda
domain
chunk-coordinate-x
chunk-domain-coordinatedomain
domains
ok
equalx-coordinates'
-101
ok
every
lambda
domain
eq
chunk-domain-spacedomain
block-world-spaceworld
domains
ok
not
eq
firstdomains
seconddomains
deftestchunk-incarnations-survive-eviction-and-storage-transfer-is-owned
let*
world
make-block-world:chunk-width2:chunk-height2:chunk-depth2
first
transferred
block-chunk-contentfirst
setf:transferred-stone
let
indices
block-content-column-indicestransferred
source-domain
block-content-column-domaintransferred
let
ok
>
block-chunk-incarnationsecond
block-chunk-incarnationfirst
ok
eq:transferred-stone
ok
eq
block-content-column-indices
block-chunk-contentsecond
indices
ok
not
eqsource-domain
block-chunk-domainsecond
ok
eq
block-chunk-domainsecond
block-content-column-domain
block-chunk-contentsecond
deftestone-world-vocabulary-closes-every-chunk-column
let*
world
make-block-world:chunk-width2:chunk-height2:chunk-depth2
stone
list:stone
dirt
list:dirt
first
vocabulary
block-world-vocabularyworld

Both chunks are closed by the same vocabulary, so the same block has the same index everywhere and palettes are one shared vector.

ok
eq
block-content-column-palette
block-chunk-contentfirst
ok
=1
block-vocabulary-offsetvocabularystonenil
ok
=2
block-vocabulary-offsetvocabularydirtnil
ok
null
block-vocabulary-offsetvocabulary
list:unknown
nil
ok
=1
aref
block-content-column-indices
block-chunk-contentfirst
0
ok
=1
aref
block-content-column-indices
block-chunk-contentsecond
1

A column produced under another world's vocabulary is translated in place when it is installed, and new members are appended, not moved.

let*
other
make-block-world:chunk-width2:chunk-height2:chunk-depth2
foreign
sand
list:sand
setfsandstone
ok
=1
aref
block-content-column-indices
block-chunk-contentforeign
0
let
installed
install-world-chunk-storageworld010
block-chunk-contentforeign
ok
eq
block-content-column-vocabulary
block-chunk-contentinstalled
vocabulary
ok
eqsand
ok
eqstone
ok
=3
block-vocabulary-offsetvocabularysandnil
ok
=1
block-vocabulary-offsetvocabularystonenil
deftestresident-lattice-raycast
let*
world
make-block-world:chunk-width4:chunk-height4:chunk-depth4
stone
list:stone
setfstone
multiple-value-bind
hitstatus
raycast-block-worldworld
make-vec30.5d01.5d01.5d0
make-vec31d00d00d0
#'identity:max-distance8d0
ok
eqstatus:hit
ok
eq
block-ray-hit-blockhit
stone
ok
coordinate=
block-ray-hit-coordinatehit
ok
coordinate=
block-ray-hit-adjacent-coordinatehit
ok
=
block-ray-hit-distancehit
1.5d0
setfnil
multiple-value-bind
hitstatus
raycast-block-worldworld
make-vec30.5d01.5d01.5d0
make-vec31d00d00d0
#'identity:max-distance2d0
ok
nullhit
ok
eqstatus:miss
multiple-value-bind
hitstatus
raycast-block-worldworld
make-vec30.5d01.5d01.5d0
make-vec31d00d00d0
#'identity:max-distance8d0
ok
nullhit
ok
eqstatus:absent
ok
signals
raycast-block-worldworld
make-vec30d00d00d0
make-vec30d00d00d0
#'identity:max-distance8d0
deftesttrusted-site-neighbors-agree-with-checked-window-steps

do-chunk-site-neighbors validates a site once and steps primitively; it must expose exactly the offsets, crossings, and window results of the checked do-chunk-window-neighbors at every site of a small domain, consulting the window only at crossings. #FGT96H

let*
world
make-block-world:chunk-width4:chunk-height3:chunk-depth5
domain
block-chunk-domainchunk
declare
ignoreneighbor
let
agreements0
dotimes
let
checkednil
trustednil
let
do-chunk-window-neighbors
targetdestinationcrossingdirectionmaterializationavailabilityworlddomainlocal*voxel-face-directions*
valuesdestination
push
listtarget
andcrossingt
directionmaterializationavailability
checked
do-chunk-site-neighbors
targetcrossingdirectionmaterializationavailabilityworlddomainoffset*voxel-face-directions*
push
listtarget
andcrossingt
directionmaterializationavailability
trusted
when
equalcheckedtrusted
incfagreements
ok
ok
signals
do-chunk-site-neighbors
targetcrossingdirectionmaterializationavailabilityworlddomain60*voxel-face-directions*
valuestargetcrossingdirectionmaterializationavailability
'error