aboutsummaryrefslogtreecommitdiff
path: root/People.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'People.cpp')
-rw-r--r--People.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/People.cpp b/People.cpp
index dbd2a6c..a6e65d5 100644
--- a/People.cpp
+++ b/People.cpp
@@ -13,27 +13,32 @@ People::~People() {
delete artist;
}
this->artists.clear();
+ this->cleanup();
}
void People::add_artist(const ArtistData & data) {
- if (this->artists.size() >= 30e3) return;
- this->artists.push_back(new Artist(this->museum, data));
+ if (this->artist_count >= 10000) return;
+
+ this->artists.push_front(new Artist(this->museum, data));
+ this->artist_count++;
}
void People::remove_artist(Artist & target) {
auto it = find(this->artists.begin(), this->artists.end(), &target);
if (it == this->artists.end()) return;
- this->artists.erase(it);
+ this->deleted_artists.push_front(*it);
+ *it = nullptr;
+ this->artist_count--;
}
-list<Artist *> People::get_artists() {
+forward_list<Artist *> People::get_artists() {
return this->artists;
}
string People::to_string() {
string out = "";
- out += stringf("%d artists\n", this->artists.size());
+ out += stringf("%d artists\n", this->artist_count);
for (Artist * artist : this->artists) {
out += stringf("- at (%.2f,%.2f)\n", artist->data.x, artist->data.y);
}
@@ -41,7 +46,16 @@ string People::to_string() {
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();