From da9877a1668ace3370ea18ac4527ee5479b0fb40 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 15 Oct 2024 21:42:37 +0200 Subject: remove overly cautious artist removal functionality --- People.cpp | 21 ++++----------------- People.h | 4 ---- ViewController.cpp | 1 - 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/People.cpp b/People.cpp index 4cd8a05..ff393eb 100644 --- a/People.cpp +++ b/People.cpp @@ -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 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(); } } diff --git a/People.h b/People.h index 4769e61..1e9ced0 100644 --- a/People.h +++ b/People.h @@ -22,10 +22,6 @@ public: void update(); -private: - std::forward_list deleted_artists; - void cleanup(); - private: std::forward_list artists; size_t artist_count = 0; 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(artist->data.x * scale), .y = static_cast(artist->data.y * scale), -- cgit v1.2.3