And, yes, it HAS to be global. That's just plain retarded.
No it HAS NOT. You are missing the entire point of programming in any language above assembler: encapsulation. Even by keeping a procedural approach to the problem, wanna see how the global goes away? Here it is:
// CREATE 10 players
for (int i=0;i<10;i++)
// GAME LOOP
// clean up yada yada
void updatePlayers(vector<Player*>& players)
for (auto player : players)
// UPDATE THE PLAYER
there you go.. players is not global anymore and only functions that REQUIRE access to it receive it as a parameter.
This gives you the huge advantage that now you know which subset of your code can access to players.. and when your code reaches 100k lines of code possibly multithreaded, trust me, you'll be glad to be limited to 3-4 functions instead of the EVERYWHERE you get from a global.
Edited by kunos, 27 April 2013 - 03:10 PM.