template<typename... Args>
class Signal< Args >
A signal allows you to connect multiple callbacks to it and fire it with arguments. It's basically a Godot signal (because I like Godot), however with some notable differences:
First off, since Calamity is single-threaded (for now), a signal should generally be used by connecting callbacks:
});
static void info(fmt::format_string< Args... > fmt, Args &&...args)
Definition logger.hpp:28
void connect(std::function< void(Args...)> cb)
Definition signal.hpp:69
void fire(Args... args)
Definition signal.hpp:57
However, if you don't wish to use callbacks and you don't need arguments, you can check if the signal has been fired. For example, you could use this pattern if you want to wait for an AudioSource to finish playing:
std::shared_ptr<AudioSource> source = std::make_shared<AudioSource>("path/to/sound.wav");
source->play();
if (!source->finishedSignal.fired) return;
source->finishedSignal.reset();
Since fired is a boolean, to fire a signal again you have to reset it. This is usually done by the code which recieves the signal (like the previous example).
});
void reset()
Definition signal.hpp:65