khora_core/
context.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//! Core engine context providing access to foundational subsystems.
16
17use crate::service_registry::ServiceRegistry;
18use std::any::Any;
19
20/// Engine context providing access to various subsystems.
21///
22/// This structure is shared across both the Strategic Brain (Agents)
23/// and the user-facing application logic.
24///
25/// # Design
26///
27/// Subsystem-specific services (e.g., `GraphicsDevice`, `RenderSystem`) are
28/// accessed through the generic [`ServiceRegistry`] instead of named fields.
29/// This respects the Interface Segregation Principle: each agent fetches only
30/// the services it needs, and adding new services never changes this struct.
31pub struct EngineContext<'a> {
32    /// A type-erased pointer to the main ECS World.
33    /// This allows agents to access data without khora-core depending on khora-data.
34    pub world: Option<&'a mut dyn Any>,
35
36    /// Generic service registry — agents fetch typed services as needed.
37    pub services: ServiceRegistry,
38}