Removed unneeded World::remove functions
This commit is contained in:
parent
454156eabe
commit
51fdaebd0c
2 changed files with 8 additions and 33 deletions
|
@ -31,20 +31,6 @@ World::insert(std::shared_ptr<Sprite> drawable) {
|
||||||
mDrawables[drawable->getCategory()].push_back(drawable);
|
mDrawables[drawable->getCategory()].push_back(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a drawable from the group.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
World::remove(std::shared_ptr<Sprite> drawable) {
|
|
||||||
for (auto v = mDrawables.begin(); v != mDrawables.end(); v++) {
|
|
||||||
auto item = std::find(v->second.begin(), v->second.end(), drawable);
|
|
||||||
if (item != v->second.end()) {
|
|
||||||
v->second.erase(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a character into the world. A character can only be inserted once.
|
* Inserts a character into the world. A character can only be inserted once.
|
||||||
* Also calls insert(character);
|
* Also calls insert(character);
|
||||||
|
@ -59,18 +45,6 @@ World::insertCharacter(std::shared_ptr<Character> character) {
|
||||||
insert(character);
|
insert(character);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a character from the world.
|
|
||||||
* Also calls remove(character);
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
World::removeCharacter(std::shared_ptr<Character> character) {
|
|
||||||
auto item = std::find(mCharacters.begin(), mCharacters.end(), character);
|
|
||||||
if (item != mCharacters.end())
|
|
||||||
mCharacters.erase(item);
|
|
||||||
remove(character);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the A* path finding algorithm with areas as nodes and portals as edges.
|
* Runs the A* path finding algorithm with areas as nodes and portals as edges.
|
||||||
*
|
*
|
||||||
|
@ -235,11 +209,11 @@ World::step(int elapsed) {
|
||||||
auto& spriteA = *it;
|
auto& spriteA = *it;
|
||||||
sf::Vector2f speed = spriteA->getSpeed() * (elapsed / 1000.0f);
|
sf::Vector2f speed = spriteA->getSpeed() * (elapsed / 1000.0f);
|
||||||
if (spriteA->getDelete()) {
|
if (spriteA->getDelete()) {
|
||||||
remove(spriteA);
|
v->second.erase(it);
|
||||||
it--;
|
it--;
|
||||||
}
|
}
|
||||||
// Apply movement for movable sprites.
|
// Apply movement for movable sprites.
|
||||||
else if ((*it)->getSpeed() != sf::Vector2f()) {
|
else if (spriteA->getSpeed() != sf::Vector2f()) {
|
||||||
bool overlap = false;
|
bool overlap = false;
|
||||||
for (auto w = mDrawables.begin(); w != mDrawables.end(); w++) {
|
for (auto w = mDrawables.begin(); w != mDrawables.end(); w++) {
|
||||||
for (auto& spriteB : w->second) {
|
for (auto& spriteB : w->second) {
|
||||||
|
@ -264,15 +238,18 @@ World::step(int elapsed) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls Character::onThink for each character. Must be called
|
* Calls Character::onThink for each character. Must be called
|
||||||
* before step (so Characters get removed asap).
|
* before step so Characters get removed correctly.
|
||||||
*
|
*
|
||||||
* @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.begin(); it != mCharacters.end(); ) {
|
for (auto it = mCharacters.begin(); it != mCharacters.end(); ) {
|
||||||
if ((*it)->getDelete())
|
if ((*it)->getDelete()) {
|
||||||
removeCharacter(*it);
|
mCharacters.erase(it);
|
||||||
|
auto& d = mDrawables[Sprite::CATEGORY_ACTOR];
|
||||||
|
d.erase(std::find(d.begin(), d.end(), *it));
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
(*it)->onThink(elapsed);
|
(*it)->onThink(elapsed);
|
||||||
it++;
|
it++;
|
||||||
|
|
|
@ -23,9 +23,7 @@ class Sprite;
|
||||||
class World : public sf::Drawable {
|
class World : public sf::Drawable {
|
||||||
public:
|
public:
|
||||||
void insert(std::shared_ptr<Sprite> drawable);
|
void insert(std::shared_ptr<Sprite> drawable);
|
||||||
void remove(std::shared_ptr<Sprite> drawable);
|
|
||||||
void insertCharacter(std::shared_ptr<Character> character);
|
void insertCharacter(std::shared_ptr<Character> character);
|
||||||
void removeCharacter(std::shared_ptr<Character> character);
|
|
||||||
void step(int elapsed);
|
void step(int elapsed);
|
||||||
void think(int elapsed);
|
void think(int elapsed);
|
||||||
void insertArea(const sf::IntRect& rect);
|
void insertArea(const sf::IntRect& rect);
|
||||||
|
|
Reference in a new issue