Converted a couple more things to shared pointers.

This commit is contained in:
2023-11-10 20:12:18 -06:00
parent 0beb1d9cb7
commit 732a90931c
16 changed files with 114 additions and 79 deletions

32
src/dawn/event/Event.hpp Normal file
View File

@ -0,0 +1,32 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
template<typename ...T>
class Event {
private:
std::hashmap<int32_t, std::function<void(T...)>> callback;
int32_t nextEventId = 0;
public:
int32_t listen(const std::function <void(T...)> &callback) {
this->callback.insert(std::make_pair(this->nextEventId, callback));
return this->nextEventId++;
}
void unlisten(int32_t id) {
this->callback.erase(id);
}
void trigger(T... args) {
for(auto &it : this->callback) {
it.second(args...);
}
}
};
}