diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 21:42:37 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 21:42:37 +0200 |
commit | da9877a1668ace3370ea18ac4527ee5479b0fb40 (patch) | |
tree | 1042f42349e9cdc7f2e37a6beb8399d08f484e42 | |
parent | 157f77d6356f4fc2be209f879907f4289c8c511d (diff) |
remove overly cautious artist removal functionality
-rw-r--r-- | People.cpp | 21 | ||||
-rw-r--r-- | People.h | 4 | ||||
-rw-r--r-- | ViewController.cpp | 1 |
3 files changed, 4 insertions, 22 deletions
@@ -8,12 +8,9 @@ using namespace std; People::People(Museum & museum) : museum(museum) {} People::~People() { - for (Artist * artist : this->artists) { - if (artist == nullptr) continue; + for (Artist * artist : this->artists) delete artist; - } this->artists.clear(); - this->cleanup(); } void People::add_artist(const ArtistData & data) { @@ -26,9 +23,10 @@ void People::add_artist(const ArtistData & data) { void People::remove_artist(Artist & target) { auto it = find(this->artists.begin(), this->artists.end(), &target); if (it == this->artists.end()) return; - this->deleted_artists.push_front(*it); - *it = nullptr; + Artist * artist = *it; + this->artists.remove(&target); this->artist_count--; + delete artist; } forward_list<Artist *> People::get_artists() { @@ -40,25 +38,14 @@ string People::to_string() { out += stringf("%d artists\n", this->artist_count); for (Artist * artist : this->artists) { - if (artist == nullptr) continue; out += stringf("- at (%.2f,%.2f)\n", artist->data.x, artist->data.y); } return out; } -void People::cleanup() { - this->artists.remove(nullptr); - for (Artist * artist : this->deleted_artists) { - delete artist; - } - this->deleted_artists.clear(); -} - void People::update() { - this->cleanup(); for (Artist * artist : this->artists) { - if (artist == nullptr) continue; artist->update(); } } @@ -23,10 +23,6 @@ public: void update(); private: - std::forward_list<Artist *> deleted_artists; - void cleanup(); - -private: std::forward_list<Artist *> artists; size_t artist_count = 0; Museum & museum; diff --git a/ViewController.cpp b/ViewController.cpp index 74873e7..f5c4e1e 100644 --- a/ViewController.cpp +++ b/ViewController.cpp @@ -51,7 +51,6 @@ void ViewController::update_tiles() { void ViewController::update_artists() { People & people = this->museum.people; for (Artist * artist : people.get_artists()) { - if (artist == nullptr) continue; Rectangle rect = { .x = static_cast<unsigned int>(artist->data.x * scale), .y = static_cast<unsigned int>(artist->data.y * scale), |