Skip to main content

khora_control/substrate/
flow_runner.rs

1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Flow runner — executes every registered [`Flow`](khora_data::flow::Flow)
16//! during the Substrate Pass and publishes their Views into the
17//! [`LaneBus`](khora_core::lane::LaneBus).
18//!
19//! Per the CLAD doctrine, this runs *before* agents execute (Pass A), so
20//! that lanes (in Pass B) read pre-projected, AGDF-adapted Views instead of
21//! querying the World directly.
22
23use khora_core::lane::LaneBus;
24use khora_core::Runtime;
25use khora_data::ecs::World;
26use khora_data::flow::FlowRegistration;
27
28/// Executes every registered Flow on the World, publishing each View into the
29/// bus. Flows are **read-only projectors**: they do not mutate the World and do
30/// not compete for the frame budget (only agents do), so no budget is passed.
31pub fn run_flows(world: &mut World, bus: &mut LaneBus, runtime: &Runtime) {
32    for reg in inventory::iter::<FlowRegistration> {
33        (reg.run)(world, bus, runtime);
34    }
35}