nightshade 0.57.0

A cross-platform data-oriented game engine.
Documentation
//! Baked meshlet mesh storage.

use std::collections::HashMap;
use std::sync::Arc;

/// Every baked meshlet mesh the scene can reference, keyed by the id that
/// [`MeshletMesh`](crate::ecs::meshlet::components::MeshletMesh) carries.
///
/// Assets live here for the lifetime of the world. The renderer uploads each
/// one to its shared GPU buffers the first frame an entity references it, and
/// keys its own copy by the same id, so registering a mesh twice would upload
/// it twice: register once and reuse the id.
#[derive(Default)]
pub struct MeshletAssets {
    assets: HashMap<u64, Arc<crate::render::meshlet::asset::MeshletMesh>>,
    next_asset_id: u64,
}

impl MeshletAssets {
    /// Stores a baked mesh and returns the id that addresses it.
    pub fn register(&mut self, mesh: crate::render::meshlet::asset::MeshletMesh) -> u64 {
        let asset_id = self.next_asset_id;
        self.next_asset_id += 1;
        self.assets.insert(asset_id, Arc::new(mesh));
        asset_id
    }

    pub fn get(&self, asset_id: u64) -> Option<&Arc<crate::render::meshlet::asset::MeshletMesh>> {
        self.assets.get(&asset_id)
    }
}