luv

Workshop wiki

particles.lisp

luvcraft/particles.lisp

system luvcraft/core · 16 definitions · on GitHub

Short-lived block fragments for the direct manipulation feedback loop.

The particle system is a semantic session-owned object, while its small moving population and per-frame render product stay as compact records and one dense interleaved vertex array. Fragments reuse the ordinary block atlas and surface pipeline; this first effect deliberately does not cast shadows or participate in world collision.

in-package#:luvcraft
defstruct
block-particle
:constructormake-block-particle
blockxyzvelocity-xvelocity-yvelocity-zsizelifetime&optional
block*stone-block*:typeblock-kind
x0.0:typesingle-float
y0.0:typesingle-float
z0.0:typesingle-float
velocity-x0.0:typesingle-float
velocity-y0.0:typesingle-float
velocity-z0.0:typesingle-float
size0.12:typesingle-float
age0.0:typesingle-float
lifetime0.7:typesingle-float

A smashed fragment falls; a mote of light hangs where it was put.

defclassblock-particle-system
particles:initform
make-array+maximum-block-particles+:element-type'block-particle:adjustablet:fill-pointer0
:readerblock-particle-system-particles
defunblock-particle-count
system

Return the number of live fragments in system.

length
block-particle-system-particlessystem
defunfractional-part
number
-number
floornumber
defunblock-particle-pattern
indexxyz

Return deterministic spread values for burst particle index.

let*
salt
+
*x0.7548777
*y0.5698403
*z0.4382891
u
fractional-part
+salt
*index0.618034
v
fractional-part
+
*salt1.732051
*index0.414214
w
fractional-part
+
*salt2.236068
*index0.732051
valuesuvw
defundiscard-oldest-block-particles
particlescount
when
pluspcount
replaceparticlesparticles:start2count
decf
fill-pointerparticles
count
particles
defunsmash-block-particles
systemblockcoordinate

Emit a small deterministic fragment burst for block at coordinate.

check-typesystemblock-particle-system
check-typeblockblock-kind
let*
particles
block-particle-system-particlessystem
x
world-coordinate-xcoordinate
y
world-coordinate-ycoordinate
z
world-coordinate-zcoordinate
dotimes
multiple-value-bind
uvw
let*
angle
*2.0piu
horizontal-speed
+1.4
*2.2v
size
+0.09
*0.08w
vector-push-extend
make-block-particleblock
coerce
+x0.18
*0.64v
'single-float
coerce
+y0.18
*0.64w
'single-float
coerce
+z0.18
*0.64u
'single-float
coerce
*horizontal-speed
'single-float
coerce
+2.4
*3.2w
'single-float
coerce
*horizontal-speed
'single-float
coercesize'single-float
coerce
+0.55
*0.35v
'single-float
particles
system
defunemit-block-mote
systemblockxyz&key
velocity-x0.0
velocity-y0.0
velocity-z0.0
size0.05
lifetime0.3

Add one weightless block mote at X,Y,Z to system, dropping the oldest fragment when the population is full.

let
particles
block-particle-system-particlessystem
vector-push-extend
make-block-particleblock
coercex'single-float
coercey'single-float
coercez'single-float
coercevelocity-x'single-float
coercevelocity-y'single-float
coercevelocity-z'single-float
coercesize'single-float
coercelifetime'single-float
coercegravity'single-float
particles
system
defunadvance-block-particles
systemseconds

Advance system by seconds and compact expired fragments in place.

check-typesystemblock-particle-system
let*
particles
block-particle-system-particlessystem
dt
coerceseconds'single-float
write-index0
dotimes
read-index
lengthparticles
let
particle
arefparticlesread-index
incf
block-particle-ageparticle
dt
when
<
block-particle-ageparticle
block-particle-lifetimeparticle
decf
block-particle-velocity-yparticle
*
block-particle-gravityparticle
dt
incf
block-particle-xparticle
*
block-particle-velocity-xparticle
dt
incf
block-particle-yparticle
*
block-particle-velocity-yparticle
dt
incf
block-particle-zparticle
*
block-particle-velocity-zparticle
dt
setf
arefparticleswrite-index
particle
incfwrite-index
setf
fill-pointerparticles
write-index
system
defunemit-block-particle-face
verticesparticlefaceshade
let*
block
block-particle-blockparticle
corners
block-face-cornersface
normal
block-face-neighborface
nx
voxel-direction-dxnormal
ny
voxel-direction-dynormal
nz
voxel-direction-dznormal
half-size
*0.5
block-particle-sizeparticle
dolist
index'
012023
let*
corner
nthindexcorners
cx
firstcorner
cy
secondcorner
cz
thirdcorner
multiple-value-bind
local-ulocal-v
push-block-vertex-componentsvertices
+
block-particle-xparticle
*
-cx0.5
*2.0half-size
+
block-particle-yparticle
*
-cy0.5
*2.0half-size
+
block-particle-zparticle
*
-cz0.5
*2.0half-size
local-ulocal-vshadenxnynz1.00.0tile

A tumbling fragment has no neighbours at all, so every edge of every face is a convex one.

+block-face-edge-convex++block-face-edge-convex++block-face-edge-convex++block-face-edge-convex+
defunblock-particle-vertices
system

Build the block-pipeline vertex stream for system's current fragments.

let*
particles
block-particle-system-particlessystem
vertices
make-array:element-type'single-float:adjustablet:fill-pointer0
dotimes
index
lengthparticles
let
particle
arefparticlesindex
shade
+0.86
*0.035
modindex4
dolist
emit-block-particle-faceverticesparticlefaceshade
vertices