-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpp toying to create background threads for processing
- Loading branch information
Showing
12 changed files
with
106 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "draw_popups.h" | ||
|
||
#include "reducers.h" | ||
|
||
const auto no_move_draw_resize = | ||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | | ||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize; | ||
|
||
void draw_confirmation_popup(const model::ViewModel&) { | ||
ImVec2 center = ImGui::GetMainViewport()->GetCenter(); | ||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); | ||
|
||
ImGui::Begin("About", NULL, no_move_draw_resize); | ||
ImGui::Text("Are you sure you want to save to "); | ||
|
||
if (ImGui::Button("Ok")) { | ||
removeView(&draw_confirmation_popup); | ||
} | ||
ImGui::End(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
#include "model.h" | ||
void draw_confirmation_popup(const model::ViewModel& vm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <iostream> | ||
#include <variant> | ||
|
||
#include "model.h" | ||
#include "rpp/rpp.hpp" | ||
#include "rximgui.h" | ||
|
||
namespace rxdispatch { | ||
|
||
using Update = | ||
std::variant<model::Reducer, std::function<model::Reducer(void)>>; | ||
|
||
void unsubscribe(); | ||
moodycamel::BlockingConcurrentQueue<model::Reducer>& getQueue(); | ||
void push(model::Reducer&& r); | ||
moodycamel::BlockingConcurrentQueue<Update>& getQueue(); | ||
void push(Update&& r); | ||
|
||
struct VisitPackage { | ||
auto operator()(model::Reducer r) { | ||
return rpp::source::just(rximgui::rl, std::move(r)).as_dynamic(); | ||
} | ||
auto operator()(std::function<model::Reducer(void)> f) { | ||
return (rpp::source::just(scheduler, std::move(f)) | | ||
rpp::operators::map([](auto f) { return f(); })) | ||
.as_dynamic(); | ||
} | ||
|
||
private: | ||
inline static rpp::schedulers::thread_pool scheduler{4}; | ||
}; | ||
|
||
inline auto get_events_observable() { | ||
return rpp::source::create<model::Reducer>([](auto&& observer) { | ||
model::Reducer f; | ||
return rpp::source::create<Update>([](auto&& observer) { | ||
Update f; | ||
auto mainthreadid = std::this_thread::get_id(); | ||
while (not observer.is_disposed()) { | ||
std::cout << "dispatch " << mainthreadid << std::endl; | ||
getQueue().wait_dequeue(f); | ||
observer.on_next(std::move(f)); | ||
observer.on_next(std::forward<Update>(f)); | ||
} | ||
}) | | ||
rpp::operators::subscribe_on(rpp::schedulers::thread_pool{3}); | ||
rpp::operators::subscribe_on(rpp::schedulers::new_thread{}) | | ||
rpp::operators::flat_map( | ||
[](auto value) { return std::visit(VisitPackage(), value); }) | | ||
rpp::operators::tap([](auto&&) { | ||
std::cout << "tap " << std::this_thread::get_id() << std::endl; | ||
}); | ||
} | ||
|
||
} // namespace rxdispatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "rpp/rpp.hpp" | ||
|
||
namespace rximgui { | ||
static inline rpp::subjects::publish_subject<int> framebus; | ||
static inline auto frameout = framebus.get_observer(); | ||
static inline auto sendframe = []() { frameout.on_next(1); }; | ||
static inline auto frames = framebus.get_observable(); | ||
static inline rpp::schedulers::run_loop rl{}; | ||
|
||
} // namespace rximgui |