Question about design/performance between two ways of storing all game objects.

What's better - a single vector with all gameobjects derived from the same base class (and using dynamic_cast), or multiple vectors?

something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

std::vector<Entity*> entities;

for (int i = 0; i < entities.size(); i++)
	{
		Tower * tower = dynamic_cast<Tower*>(entities[i]);
                Enemy * enemy = dynamic_cast<Enemy*>(entities[i]);


		if (tower)
			tower->Update(*Window);
                if(enemy)
                        enemy->Update(*Window, entities);


//...
	}


or

1
2
3
4
5
6
7
8
9
10
11
12
13
14
std::vector<Tower*> towers;
std::vector<Enemy*> enemies;

for (int i = 0; i < towers.size(); i++)
{

}

for(int i = 0; i < enemies.size(); i++)
{

}

//... 
Last edited on
Topic archived. No new replies allowed.