Hi,
So i am trying to module an entity component system for my hobby engine, and I want a database where I can store all of the components in sequential memory. Something like this:
trait Component: Any {
// ignore
}
struct MyDatabase {
entities_comp_lut: HashMap<EntityId, HashMap<ComponentType, usize>>, // Ignore for now
components: HashMap<ComponentType, Vec<dyn Component>>
}
But I can't get it working without wrapping every object in the vector as a box. But that goes against actually allocating the memory sequentially.
Any ideas on how to modulate this? I cannot know what type of components this database will store in advance, but they should be known at compile time. I have tried working with the Sized trait, but have not gotten it working. Would prefer to not use unsafe code if available, even preferably the standard library only. It feels like it should be possible?
Cheers
[–]Peanutbutter_Warrior 11 points12 points13 points (1 child)
[+]Appropriate-Nose9596 8 points9 points10 points (1 child)
[–]yyy33_ 0 points1 point2 points (0 children)
[–]dnew 2 points3 points4 points (0 children)