mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-20 03:36:37 +02:00
fixed spelling in us
added async to us
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include "./default_strategy.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
|
||||
namespace MM::UpdateStrategies {
|
||||
|
||||
@ -206,17 +207,27 @@ void SingleThreadedDefault::doUpdate(MM::Engine& engine) {
|
||||
// post
|
||||
runType(engine, update_phase_t::POST);
|
||||
|
||||
if (!_defered_queue.empty()) {
|
||||
for (auto&& fn : _defered_queue) {
|
||||
// simulate async
|
||||
for (size_t i = 0; !_async_queue.empty() && i < _max_async_per_tick; i++) {
|
||||
_async_queue.back()(engine);
|
||||
_async_queue.pop_back();
|
||||
}
|
||||
|
||||
if (!_deferred_queue.empty()) {
|
||||
for (auto&& fn : _deferred_queue) {
|
||||
fn(engine);
|
||||
}
|
||||
|
||||
_defered_queue.clear();
|
||||
_deferred_queue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void SingleThreadedDefault::addDefered(std::function<void(Engine&)> function) {
|
||||
_defered_queue.emplace_back(std::move(function));
|
||||
void SingleThreadedDefault::addDeferred(std::function<void(Engine&)> function) {
|
||||
_deferred_queue.emplace_back(std::move(function));
|
||||
}
|
||||
|
||||
void SingleThreadedDefault::addAsync(std::function<void(Engine&)> function) {
|
||||
_async_queue.emplace_back(std::move(function));
|
||||
}
|
||||
|
||||
#undef __L_ASSERT
|
||||
|
@ -44,7 +44,9 @@ class SingleThreadedDefault : public MM::UpdateStrategies::UpdateStrategy {
|
||||
std::set<update_key_t> _main_active;
|
||||
std::set<update_key_t> _post_active;
|
||||
|
||||
std::vector<std::function<void(Engine&)>> _defered_queue;
|
||||
std::vector<std::function<void(Engine&)>> _deferred_queue;
|
||||
std::vector<std::function<void(Engine&)>> _async_queue;
|
||||
const size_t _max_async_per_tick = 5; // prevent blocking, this should be finetuned
|
||||
|
||||
private:
|
||||
Graph& getGraph(update_phase_t phase);
|
||||
@ -72,7 +74,9 @@ class SingleThreadedDefault : public MM::UpdateStrategies::UpdateStrategy {
|
||||
|
||||
bool depend(const update_key_t A, const update_key_t B) override;
|
||||
|
||||
void addDefered(std::function<void(Engine&)> function) override;
|
||||
void addDeferred(std::function<void(Engine&)> function) override;
|
||||
|
||||
void addAsync(std::function<void(Engine&)> function) override;
|
||||
};
|
||||
|
||||
} // MM::UpdateStrategies
|
||||
|
@ -69,10 +69,13 @@ class UpdateStrategy {
|
||||
// WIP:
|
||||
|
||||
// dont use, if you are not using it to modify the engine.
|
||||
// you usualy dont need to use this, if you think you need to use this, you probably dont.
|
||||
//virtual void addFixedDefered(std::function<void(Engine&)> function) = 0;
|
||||
virtual void addDefered(std::function<void(Engine&)> function) = 0; // called after everything
|
||||
// you usually dont need to use this, if you think you need to use this, you probably dont.
|
||||
virtual void addDeferred(std::function<void(Engine&)> function) = 0; // called after everything
|
||||
|
||||
// adds a task, which does not need to be completed on the end of the tick.
|
||||
// warning: in a single-threaded environment, they will still be done on the main thread, so blocking is not a option
|
||||
// note: the US might decide to limit the amount of executed asyncs per tick (eg. when single-threaded)
|
||||
virtual void addAsync(std::function<void(Engine&)> function) = 0;
|
||||
//virtual std::future addAsync(std::function<void(Engine&)> function) = 0;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user