My Expereince Writting an ECS system
Writting an ECS system was hard and confusing.
Variants
At first I was going to use std::variants, and use that to hold the objects. In fact I went all the way through, and implemented them. But then I relised, that, I cannot change the values in a variant without entirely remaking the object. Now, this ecs system doesn't need to be fast. My needs just need fast read/write. But this was gonna be too slow. So I threw it out.
Raw pointers
Im writting this in c++, so no.
unique_ptrs
Why did I make this unique? Idk. I wanted everyone to have access to just one pointer, so I dont accidently leave something allocated uk. In the end this is what I went with. The method I used for loading data is something to be studied, and I'll probs discuss it late LMAO.
Maps
So in the end my ecs system ended up just being a map with some extra functions (very useful functions). Really all the heavy lifting is done by a map lmao. I need to actually change its key to smth better, as a string aint that great lmaoo.
Anywaysss, there are like 3 types of maps fof the top of my head. Ordered map(default in c++), unordered, and unordered_dense. You can read into the semantics of each one yourself,, its not worth the space here whilst other people have written so much more, and better stuff.
If you need to choose between these three, ask yourself these questions; how many elements will be there, how much memory, speed use.
Map uses a lot less memory than both unordered_map, and unordered_dense(generally since there isnt anything in the c++ standard yet), this is espectially true at low elements amounts.
From there I just ask myself do I actually need the speed benifits, and will they be visible.
Unless Im doing like over 1k entities, I dont bother using anything other than map.
Type_info/type_index
Type_info returns like a hash on the type of class or wtvvv, I realllyyy like it. BUt make sure to know when to use type_index instead. As type_info returns a ptr which in a lot of situations is NOT what you want, whilst type_index returns data or smth. Basically,, use type_index when possible, I think, there are a lot of nuances.
Reminds me that I should learn about decltype.
lvalues, and rvalues
At some point search them up, they kinda just make sense.