Fixed character removal and getCharacters returning self.
This commit is contained in:
parent
c6cd8483e0
commit
5f7c2a8ee4
1 changed files with 8 additions and 2 deletions
|
@ -232,6 +232,8 @@ std::vector<std::shared_ptr<Character> >
|
||||||
World::getCharacters(const sf::Vector2f& position, float maxDistance) const {
|
World::getCharacters(const sf::Vector2f& position, float maxDistance) const {
|
||||||
std::vector<std::shared_ptr<Character> > visible;
|
std::vector<std::shared_ptr<Character> > visible;
|
||||||
for (auto it : mCharacters) {
|
for (auto it : mCharacters) {
|
||||||
|
if (position == it->getPosition())
|
||||||
|
continue;
|
||||||
if (thor::squaredLength(position - it->getPosition()) <=
|
if (thor::squaredLength(position - it->getPosition()) <=
|
||||||
maxDistance * maxDistance)
|
maxDistance * maxDistance)
|
||||||
visible.push_back(it);
|
visible.push_back(it);
|
||||||
|
@ -288,14 +290,18 @@ World::step(int elapsed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls Character::onThink for each character.
|
* Calls Character::onThink for each character. Must be called
|
||||||
|
* before step (due to character removal).
|
||||||
*
|
*
|
||||||
* @param elapsed Time since last call.
|
* @param elapsed Time since last call.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
World::think(int elapsed) {
|
World::think(int elapsed) {
|
||||||
for (auto it : mCharacters) {
|
for (auto it : mCharacters) {
|
||||||
it->onThink(elapsed);
|
if (it->getDelete())
|
||||||
|
removeCharacter(it);
|
||||||
|
else
|
||||||
|
it->onThink(elapsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue