concinnity_core/components/app_config.rs
1// src/components/app_config.rs
2//
3// Runtime `AppConfig` component. Its authored args live in the schema crate
4// (concinnity_asset::app_config); only what the running process needs survives
5// the bake: the state-tree location and the resource budgets. The distribution
6// metadata (name, id, version, author, icon) is read at build / export time
7// from the authored world, so it never ships in the blob.
8
9use alloc::string::String;
10
11use concinnity_asset::cook;
12
13use crate::ecs::Component;
14
15/// Runtime half of the AppConfig asset: where the application keeps what it
16/// writes, and its process resource budgets.
17#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
18pub struct AppConfig {
19 /// Where the running application writes its settings, saves, crash
20 /// reports, and shader caches. Empty means beside the application's data.
21 pub home: String,
22 /// Soft ceiling on host memory the runtime aims to stay under, in
23 /// mebibytes. `0` = auto.
24 pub max_memory_mb: u32,
25 /// Worker threads for the shared job pool. `0` = auto.
26 pub job_threads: u32,
27}
28
29impl AppConfig {
30 /// Translate the authored args into the runtime component: keep the state
31 /// location and the resource budgets. Run by cook at build time (the baked
32 /// blob record carries the result).
33 pub fn bake(args: cook::AppConfig) -> Self {
34 Self {
35 home: args.home,
36 max_memory_mb: args.max_memory_mb,
37 job_threads: args.job_threads,
38 }
39 }
40}
41
42impl Component for AppConfig {
43 const NAME: &'static str = "AppConfig";
44
45 fn from_baked(bytes: &[u8]) -> Result<Self, crate::result::CnResult> {
46 Ok(crate::blob::decode_exact(bytes)?)
47 }
48}