Skip to main content

Module balls

Module balls 

Source
Expand description

The balls: dropping them, giving each one a render instance and a physics body, and publishing where they are.

This is the scene’s busiest object. Every drop spawns a Ball entity of its own and then asks the two other worlds for the halves that make it visible: the render world creates an instance, the physics world a body, and both answer with the ball entity they were asked for, so an answer that no longer finds its ball is cleaned up instead of leaking. A ball the camera loses sight of is put away whole: the render world despawns the instance and reports it, and the body and the ball entity go with it.

Every answer names the ball, never a place in a parallel list, so two answers arriving in either order land on the same ball. A ball counts as shown once the render world confirms the instance wears its assets, not when the job is queued: a job a full queue turned away is simply sent again on the next tick.

Re-exportsΒ§

use std::sync::Arc; πŸ”’
use glam::Vec3; πŸ”’
use unlit_ecs::Bundle; πŸ”’
use unlit_ecs::DynamicBundle; πŸ”’
use unlit_ecs::Entity; πŸ”’
use unlit_ecs::Scope; πŸ”’
use unlit_ecs::World; πŸ”’
use unlit_ecs::bundle; πŸ”’
use unlit3d::components::Transform; πŸ”’
use super::Scene; πŸ”’
use super::shapes::BALL_COLORS; πŸ”’
use super::shapes::SHAPE_KINDS; πŸ”’
use super::shapes::shape_body; πŸ”’
use super::shared::SceneState; πŸ”’
use super::shared::create_instance; πŸ”’
use super::shared::look; πŸ”’
use super::tick::advancing_in; πŸ”’
use super::GamePhysics; πŸ”’
use super::ScenePoses; πŸ”’
use super::pose_job; πŸ”’
use super::world_ended; πŸ”’
use crate::render::BallInstance; πŸ”’
use crate::render::RenderEntity; πŸ”’
use crate::render::despawn_instances_job; πŸ”’
use crate::render::show; πŸ”’
use crate::render::sweep; πŸ”’
use unlit3dx::prelude::*; πŸ”’

StructsΒ§

Ball
One ball, on an entity of its own in the gameplay world.
BallDrops πŸ”’
The balls and the tick that drops, poses and sweeps them, spawned together.
Balls
The balls, living on their own entity in the gameplay world.
ShowCandidate πŸ”’
A ball whose two halves have both landed, waiting to be shown.

EnumsΒ§

BallPhase
How far a ball has come through its flow.
Waiting πŸ”’
What a tick does with a ball that has not been shown yet.

ConstantsΒ§

PENDING_TIMEOUT πŸ”’
How long a ball may wait for its two halves before its instance and body are reclaimed, in seconds.
SPAWN_HEIGHT πŸ”’
Where balls spawn, in metres above the ground.
SPAWN_PERIOD πŸ”’
How long between automatic ball drops, in seconds.
SPAWN_SPREAD πŸ”’
How far from the centre a ball may spawn, in metres.
STATUS_PERIOD πŸ”’
How often the ball flow reports its own status, in seconds.
SWEEP_PERIOD πŸ”’
How often live instances are tested against the camera’s view, in seconds.

FunctionsΒ§

live_poses πŸ”’
The poses a tick publishes: one per shown ball, at the pose the physics snapshot names for its body. A ball the snapshot has not named yet is left out, keeping the transform the show job gave it.
waiting πŸ”’
What a tick does with a ball.