summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2023-11-26 20:28:29 -0500
committerBenji Dial <benji6283@gmail.com>2023-11-26 20:28:29 -0500
commit8723fe078180916a6b2f736232e7f5bec2b9674e (patch)
tree474ae9a0cc40a6cbb146fee224544bbe031f76a6
parent920bedec8c2bec3dc9e938a88fc2fe3fb7e49fe1 (diff)
downloadlib94-8723fe078180916a6b2f736232e7f5bec2b9674e.tar.gz
add function to lib94 to remove all warriors; fix crash on removing last warrior in bench
-rw-r--r--bench/bench_window.cpp12
-rw-r--r--include/lib94/lib94.hpp2
-rw-r--r--lib94/core.cpp4
3 files changed, 17 insertions, 1 deletions
diff --git a/bench/bench_window.cpp b/bench/bench_window.cpp
index 08f2236..39992eb 100644
--- a/bench/bench_window.cpp
+++ b/bench/bench_window.cpp
@@ -320,7 +320,17 @@ void bench_window::on_click_remove_warrior() {
break;
}
- on_click_new_round();
+ if (warriors.size())
+ on_click_new_round();
+
+ else {
+ lib94::remove_all_warriors();
+ lib94::clear_address_sets();
+ core.mut.lock();
+ core.clear_all();
+ core.mut.unlock();
+ update_ui();
+ }
delete w;
diff --git a/include/lib94/lib94.hpp b/include/lib94/lib94.hpp
index 40c9631..63f862e 100644
--- a/include/lib94/lib94.hpp
+++ b/include/lib94/lib94.hpp
@@ -108,6 +108,8 @@ namespace lib94 {
//with the current time, before the first time you call this.
bool init_round(const warrior *const *warriors, size_t count, const number_t *offsets, bool shuffle);
+ void remove_all_warriors();
+
//returns the number of warriors who have at least one process
size_t alive_warrior_count();
diff --git a/lib94/core.cpp b/lib94/core.cpp
index cf563d8..bec793b 100644
--- a/lib94/core.cpp
+++ b/lib94/core.cpp
@@ -114,6 +114,10 @@ namespace lib94 {
return true;
}
+ void remove_all_warriors() {
+ alive_warriors.clear();
+ }
+
size_t alive_warrior_count() {
return alive_warriors.size();
}