Okay so I've been working on an "Entity Management" system for my game. Basicly any object in the game(buildings, vehicles, etc) will be an entity, so I'm using a class with a list to manage all the entities. I'm able to create my EntityManager class, and add a couple entities to it fine. Each entity just loads a simple model and contains an Update() function that is called every game loop. Right now the update function just moves the entity a bit up. I have an Update() function in my EntityManager object as well, that loops through all the Entities stored in it and calls their update methods. The problem is, the loop seems to loop through the entities and call the update method on just one of the entities multiple times, resulting in the entity moving faster than it should normaly, and all the other entities just sit there since they're not being updated. I think this might be a problem with my use of the iterator for the list, but I'm not sure. This is my first time using lists in c++ so I'm still getting the hang of it. I create a list of GameEntity object pointers like so in my EntityManager.h file:
Code: Select all
std::list<GameEntity*> entityList;
std::list<GameEntity*>::iterator iEntity;
Then I add entities to the list with the AddEntity function in EntityManager.cpp:
Code: Select all
void EntityManager::AddEntity(GameManager* tGame, GameEntity* tEntity)
{
tEntity = GameEntity::Instance();
tEntity->Init(tGame, false, false);
entityList.push_back(tEntity);
}
And here is my Update function in EntityManager.cpp:
Code: Select all
void EntityManager::Update(GameManager* tGame)
{
for(iEntity = entityList.begin(); iEntity != entityList.end(); iEntity++)
{
GameEntity* tEntity = *iEntity;
tEntity->Update(tGame);
}
}
Its almost like the loop works correctly, but tEntity always points to the same GameEntity. Any ideas of what I'm doing wrong?