leudz / shipyard

Entity Component System focused on usability and flexibility.
Other
755 stars 46 forks source link

A question about shipyard's architecture #204

Closed PudgeKim closed 3 months ago

PudgeKim commented 3 months ago
pub struct AllStorages {
    pub(crate) storages: RwLock<HashMap<StorageId, SBox>>,
    #[cfg(feature = "thread_local")]
    thread_id: std::thread::ThreadId,
    counter: Arc<AtomicU32>,
}

AllStorages struct handles all storages. Storage is trait so I think View or ViewMut should implements Storage trait.

But SparseSet implements Storage which is in View/ViewMut. I think View or ViewMut should have a Storage trait field instead of SparseSet. impl<T: 'static + Component + Send + Sync> Storage for SparseSet<T>

hmm.. I don't understand what this code means. Please explain why..! And would you explain me about some connection between important traits(or structs) (Component, View/ViewMut, ...)? (It would help me looking code..!)

leudz commented 3 months ago

Views are temporary borrow of storages. Storages are where components are stored. So they are mutually exclusive.

View/ViewMut are SparseSet's views. In theory they could be called SparseSetView/SparseSetViewMut but that would be a long name. You could have instead View/ViewMut for dyn Storage, it would simplify a bunch of code. But execution speed would take a hit.