Skip to content

Instantly share code, notes, and snippets.

@nariakiiwatani
Created December 8, 2020 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nariakiiwatani/7b669afd89c407984148f2b667501adb to your computer and use it in GitHub Desktop.
Save nariakiiwatani/7b669afd89c407984148f2b667501adb to your computer and use it in GitHub Desktop.
template<typename T>
class DelayBank {
public:
void add(const T &t, float wait_time) {
waiter_.push_back({t,wait_time});
}
void update() {
using namespace std;
ended_.clear();
float time = ofGetLastFrameTime();
auto remove_begin = remove_if(begin(waiter_), end(waiter_), [time](Waiter &w) {
return (w.rest_time -= time) <= 0;
});
for(auto it = remove_begin; it != end(waiter_); ++it) {
ended_.push_back(it->t);
}
waiter_.erase(remove_begin, end(waiter_));
}
std::vector<T>& getEnded() {
return ended_;
}
private:
struct Waiter {
T t;
float rest_time;
};
std::vector<Waiter> waiter_;
std::vector<T> ended_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment