• Create Account

### #Actualkunos

Posted 27 April 2013 - 12:04 AM

void UpdateAI()
{
for(int i = 0; i < PlayerList.size(); ++i)
{
if(!PlayerList[i].IsAlive || !PlayerList[i].IsAi) {
continue;
}
UpdateAI(PlayerList[i]);
}
}

void UpdateAI(TPlayer& aiPlayer);


why the continue? Why the checks with ! ??? Why not the proper for (auto& player : playerList) ? And even better, if we really need to have a function that updates only one player (and I really feel we don't) why are the rules to call it expressed OUTSIDE? It should be as simple as calling a std::for_each(begin(playerList), end(playerList), UpdateAI) and then do the simple rule check INSIDE that if (player.IsActive && player.IsAI) { do your things} .. this opens the door to parallelism.. on Windows replace std:: with parallel:: and you're multithread.. and it's 3 lines of code! .. no dumb "!" to mess up your logic, no continue to early exit a loop.. it doesnt make sense at ALL! I code what I DO when a certain condition is met, thinking "right I don't do something and continue the loop if a couple of not conditions are true" is really on the edge of insanity.. it really is.

Should I continue? pun intended ... do we need an UpdateAI ? do we need a IsAI? Chances are that there is also an Update somewhere for !IsAI players.. what ever happened to polymorphism???? A Player (please no CPlayer ) class with a virtual Update method and a PlayerAI class that overrides that Update..

for (auto player : playerList) player->Update();

It's 1 line of code!

### #1kunos

Posted 27 April 2013 - 12:03 AM

void UpdateAI()
{
for(int i = 0; i < PlayerList.size(); ++i)
{
if(!PlayerList[i].IsAlive || !PlayerList[i].IsAi) {
continue;
}
UpdateAI(PlayerList[i]);
}
}

void UpdateAI(TPlayer& aiPlayer);


why the continue? Why the checks with ! ??? Why not the proper for (auto& player : playerList) ? And even better, if we really need to have a function that updates only one player (and I really feel we don't) why are the rules to call it expressed OUTSIDE? It should be as simple as calling a std::for_each(begin(playerList), end(playerList), UpdateAI) and then do the simple rule check INSIDE that if (player.IsActive && player.IsAI) { do your things} .. this opens the door to parallelism.. on Windows replace std:: with parallel:: and you're multithread.. and it's 3 lines of code! .. no dumb "!" to mess up your logic, no continue to early exit a loop.. it doesnt make sense at ALL! Let me know what I DO when a certain condition is met, thinking "right I don't do something and continue the loop if a couple of not conditions are true" is really on the edge of insanity.. it really is.

Should I continue? pun intended ... do we need an UpdateAI ? do we need a IsAI? Chances are that there is also an Update somewhere for !IsAI players.. what ever happened to polymorphism???? A Player (please no CPlayer ) class with a virtual Update method and a PlayerAI class that overrides that Update..

for (auto player : playerList) player->Update();

It's 1 line of code!

PARTNERS