In this slides (after slide 15) it is suggested to use
void updateAims(float* aimDir, const AimingData* aim, vec3 target, uint count)
{
for(uint i = 0; i < count; i++)
{
aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i];
}
}
because it's more cache efficient.
What about if I have a class
class Bot
{
vec3 position;
float mod;
float aimDir;
void UpdateAim(vec3 target)
{
aimDir = dot3(position, target) * mod;
}
};
void updateBots(Bots* pBots, uint count, vec3 target)
{
for(uint i = 0; i < count; i++)
pBots[i]->UpdateAim(target);
}
And I store all objects of that class in a single linear array.
Since they're all in the same array will there be cache misses? Why would the first approach be better?