luv

Workshop wiki

physics-tests.lisp

luvcraft/physics-tests.lisp

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

Executable claims for the sphere physics: what a pile does, what a rolling ball does not do, and that the wide kernels are the scalar ones.

in-package#:luvcraft.tests
defunmake-physics-test-world
&key

A flat world: dirt at y=0, grass at y=1, width cells square from the origin.

let
loopforchunk-xbelow
ceilingwidth16
do
loopforchunk-zbelow
ceilingwidth16
do
ensure-world-chunkworldchunk-x0chunk-z
loopforxbelowwidthdo
loopforzbelowwidthdo
setfluvcraft::*dirt-block*luvcraft::*grass-block*
world
defunstep-physics
physicssteps
dotimes
isteps
physics
deftesta-dropped-ball-comes-to-rest-on-the-floor-and-sleeps
let*
physics
make-physics-world:terrainworld:kernels:scalar
ball
spawn-physics-bodyphysics8.55.08.5:radius0.25:restitution0.3
step-physicsphysics240
multiple-value-bind
xyz

Resting on the grass top at y=2, a slop under its radius.

ok
<
abs
-x8.5
1e-3
ok
<
abs
-z8.5
1e-3
deftesta-bouncy-ball-bounces-and-a-dead-one-does-not
let*
physics
make-physics-world:terrainworld:kernels:scalar
bouncy
spawn-physics-bodyphysics4.54.04.5:radius0.25:restitution0.8
dead
spawn-physics-bodyphysics12.54.012.5:radius0.25:restitution0.0
bouncy-peak0.0
dead-peak0.0
landed-pnil
dotimes
i200
multiple-value-bind
xyz
declare
ignorexz
multiple-value-bind
vxvyvz
declare
ignorevxvz
when
and
notlanded-p
<y2.3
setflanded-pt
when
andlanded-p
pluspvy
setfbouncy-peak
maxbouncy-peaky
multiple-value-bind
xyz
declare
ignorexz
multiple-value-bind
vxvyvz
declare
ignorevxvz
when
and
pluspvy
>
physics-world-step-countphysics
40
setfdead-peak
maxdead-peaky

The bouncy ball rose again after landing; the dead one never did.

ok
>bouncy-peak2.6
ok
<dead-peak2.3
deftesta-rolling-ball-crosses-cell-seams-without-catching
let*
physics
make-physics-world:terrainworld:kernels:scalar
ball
spawn-physics-bodyphysics2.52.2458.5:radius0.25:vx4.0:friction0.5:rolling-resistance0.0
max-rise0.0
max-vy0.0
dotimes
i240
multiple-value-bind
xyz
declare
ignorexz
setfmax-rise
maxmax-rise
-y2.245
multiple-value-bind
vxvyvz
declare
ignorevxvz
setfmax-vy
maxmax-vy
absvy
multiple-value-bind
xyz
declare
ignoreyz

It got somewhere: rolling friction is off, so it barely slowed.

ok
>x12.0

And it never hopped at a seam.

ok
<max-rise0.02
ok
<max-vy0.3
deftesta-pile-sleeps-and-a-thrown-ball-wakes-it
let*
physics
make-physics-world:terrainworld:kernels:scalar
pile
loopforibelow6collect
spawn-physics-bodyphysics8.5
+2.3
*0.6i
8.5:radius0.25:restitution0.1
step-physicsphysics400
ok
every
lambda
handle
pile
ok
zerop
luvcraft::physics-body-columns-length
physics-world-awakephysics

A ball thrown into the pile wakes what it hits, and they wake others.

let
thrown
spawn-physics-bodyphysics4.52.58.5:radius0.25:vx8.0
step-physicsphysics60
ok
ok
some
lambda
handle
pile
deftesta-moving-box-pushes-balls-out-of-its-way
let*
physics
make-physics-world:terrainworld:kernels:scalar
ball
spawn-physics-bodyphysics8.52.58.5:radius0.25
step-physicsphysics60
multiple-value-bind
x0y0z0
declare
ignorey0z0

A box a cell wide walks into the ball from the west at 3 cells/s.

loopforstepfrom0below60forbox-x=
+6.0
*3.0
/step60.0
do
post-physics-boxphysicsbox-x2.08.0
+box-x1.0
3.89.0:vx3.0:owner:walker
multiple-value-bind
x1y1z1
declare
ignorey1z1
ok
>x1
+x00.5
deftestcontacts-begin-and-end-and-mortal-bodies-expire
let*
physics
make-physics-world:terrainworld:kernels:scalar
ball
spawn-physics-bodyphysics8.53.08.5:radius0.25:lifetime1.0
kindsnil
dotimes
i90
dolist
event
pushnew
getfevent:kind
kinds
ok
member:beginkinds
ok
member:expiredkinds

The slot is reused with a new generation, so the old handle stays dead.

deftesta-terrain-edit-wakes-the-sleepers-above-it
let*
physics
make-physics-world:terrainworld:kernels:scalar
ball
spawn-physics-bodyphysics8.52.58.5:radius0.25
step-physicsphysics200
setfnil
ok
plusp
step-physicsphysics120
multiple-value-bind
xyz
declare
ignorexz

It fell into the hole.

ok
<y1.9
defunphysics-hash-after
kernelssteps
let*
physics
make-physics-world:terrainworld:kernelskernels
dotimes
i200
multiple-value-bind
layerrest
multiple-value-bind
rowcol
floorrest5
spawn-physics-bodyphysics
+4.0
*1.6col
*0.03layer
+3.0
*0.6layer
+4.0
*1.6row
:radius0.3:restitution0.4:friction0.5
step-physicsphysicssteps
valuesphysics
deftestthe-wide-kernels-are-the-scalar-kernels-bit-for-bit
let
if
nullwide
skip"no wide kernel family on this machine"
multiple-value-bind
scalar-hashscalar-world
dolist
familywide
multiple-value-bind
wide-hashwide-world
ok
=scalar-hashwide-hash
ok
=
luvcraft::physics-body-columns-length
physics-world-awakescalar-world
luvcraft::physics-body-columns-length
physics-world-awakewide-world
deftesta-hard-arrival-on-a-box-reports-a-hit-with-its-owner
let*
physics
make-physics-world:terrainworld:kernels:scalar
hitsnil

A ball flying at 10 cells/s into a box owned by :turtle.

spawn-physics-bodyphysics6.52.68.5:radius0.25:vx10.0
dotimes
i60
post-physics-boxphysics8.02.08.09.02.69.0:owner:turtle
dolist
event
when
eq
getfevent:kind
:hit
pusheventhits
ok
plusp
lengthhits
ok
every
lambda
event
eq:turtle
getfevent:owner
hits
ok