Fruit Fly
README.md
FruitFlyBrain
A whole connectome running as a spiking network on this entity. It loads the
connectome asset the field names (the package's maleCNS by default),
steps it every frame the gameplay clock runs and, with runInEdit, in edit
mode too; draws every neuron with a soma as a lit point around the entity;
plays the network's own crackle from it; and hands the live network to
anything that asks.
Fields: connectome, running, runInEdit, timeScale,
maxStepsPerFrame, gain, minSynapses, showCloud, cloudGate,
cloudScale, neuronRadius, bloom, bloomIntensity, crackle. The
defaults are the calibrated regime: gain 0.6, minSynapses 5, timeScale 1,
maxStepsPerFrame 32.
Methods on the ref: getBrain(), stimulate(sel, hz, source?),
silence(sel, on), clearStimulation(source?), drives(), reset(),
watch(name, sel), unwatch(name), rates(), classRates(limit?),
groupActivity(name), neuronAt(screenX, screenY, radiusPx?),
keepCloudDrawn(seconds?), describe(). stimulate, silence,
clearStimulation and reset are synced calls, so every peer's copy of the
network receives the same inputs. onLoaded fires with the neuron and edge
counts once the network is on the GPU.
local e = entity.spawn("Brain")
e.position = { 0, 5, -8 }
e.component.add("FruitFlyBrain", { gain = 0.6 })
local c = e.component.get("FruitFlyBrain")
c:watch("MN9", { types = { "MN9" } })
c:stimulate({ types = { "claw_tpGRN" } }, 100, "bench")
The visibility gate, and what it means for a capture
The cloud is 139,741 instances, and a registered instanced population has its
whole transform run recomposed on the CPU every frame whether or not the cull
draws any of it. Measured on this world: render.mesh_transform_compose is
4.74 ms a frame with the cloud registered and 0.67 ms with it down. So the
component tests the cloud's bounding sphere against the on-screen camera's
frustum every three frames, registers the draw the moment the sphere enters,
and drops it after thirty consecutive frames outside. showCloud = false
still takes everything down.
The gate only knows about the camera on screen. An offscreen capture aimed
at the brain from a station the player is not standing at can therefore come
back with no cloud in it. Call keepCloudDrawn(seconds) first, or set
cloudGate false.
Moving the entity moves the cloud with it: the transforms are rewritten from the neuron records a slice a frame, with no rebuild.
Drives are owned
stimulate takes the name of whoever is driving. The rate a neuron sees is
the largest any source asked for, so the fly stepping onto a food patch
("fly") cannot take away what the bench ("bench") or a protocol
("protocol") is driving, and clearStimulation("fly") clears only the
fly's. A call that names no source is recorded as "code". drives() is what
the bench lists.
Sound and light
While the cloud is drawn the component registers the builtin bloom on the
scene layer, which is what turns a spiking neuron from a bright dot into a
point of light, and takes it off again when the cloud goes down. The Audio
component it puts on the entity plays the package's crackle clip on a loop
with its volume following the whole-network rate: silent below 0.05 Hz,
rising to 0.35 by 5 Hz.