|
|
|
|
|
by Rayhem
316 days ago
|
|
If you're really accessing those fields it's overwhelmingly likely that you're accessing the same field for all of your instances. Your access pattern is going to be monsters[0].health = //calculation
monsters[1].health = //calculation
monsters[2].health = //calculation
and not monsters[0].health = //calculation
monsters[1].name = //update
monsters[2].is_poisoned = //check
Striding over your monsters array means you have to load each monster to access one field which just blows your cache to hell. Much better is to pack all of your health values together in a structures-of-arrays layout as opposed to the usual arrays-of-structures approach here. Entity-component-system architectures are a brilliant tool for managing this with some pretty performant results. |
|
I'm not a games developer, so I don't have a good feel for why you'd need to iterate over every monster's health property in a tightly loop vs accessing each monster and calculating their position, what properties they have and updating one or more of their values in an iteration.