内核优化
This commit is contained in:
+3
-73
@@ -1,75 +1,5 @@
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#ifdef RENDERIVE_WITH_GTEST
|
||||
#include <gtest/gtest.h>
|
||||
#endif
|
||||
#include "../src/renderive/base/property/Property.hpp"
|
||||
#include "../src/renderive/renderable/Renderable.hpp"
|
||||
#include "../src/renderive/scene/Scene.hpp"
|
||||
#include "../src/renderive/state/State_Strategy.hpp"
|
||||
struct Radio_State {
|
||||
struct Even_Validator {
|
||||
void operator()(const int& value) const {
|
||||
if (value % 2 != 0) {
|
||||
throw std::invalid_argument("buffer_count must be even");
|
||||
}
|
||||
}
|
||||
};
|
||||
Range_Value<int, 1, 65535> port{8080};
|
||||
Validated_Value<int, Even_Validator> buffer_count{2};
|
||||
int low_watermark{};
|
||||
int high_watermark{};
|
||||
};
|
||||
struct Radio_Base {
|
||||
Radio_Base(int id, std::string name) : id(id), name(std::move(name)) {}
|
||||
static void validate_state(const Radio_State& state) {
|
||||
if (state.low_watermark > state.high_watermark) {
|
||||
throw std::invalid_argument("low_watermark must not exceed high_watermark");
|
||||
}
|
||||
}
|
||||
int id;
|
||||
std::string name;
|
||||
};
|
||||
struct Demo_Renderable : Renderable_Base {
|
||||
explicit Demo_Renderable(Scene_Base& scene) : Renderable_Base(scene, {.cache_enabled = true}) {}
|
||||
void render(const Scene_Render_Context&) override {
|
||||
++render_count;
|
||||
}
|
||||
std::atomic<int> render_count{};
|
||||
};
|
||||
using Radio_Strategy = Double_State_Strategy<Radio_Base, Radio_State>;
|
||||
using Radio = Attach_State_Builder<Radio_Strategy, Radio_State>;
|
||||
int run_main_flow() {
|
||||
auto radio = Radio::Builder{}
|
||||
.set < &Radio_State::port > (9000)
|
||||
.set<&Radio_State::buffer_count>(8)
|
||||
.configure([](Radio_State& state) {
|
||||
state.low_watermark = 16;
|
||||
state.high_watermark = 64;
|
||||
})
|
||||
.build(1, "primary");
|
||||
radio->set < &Radio_State::port > (9100);
|
||||
radio->publish();
|
||||
Scene2D_Context<> scene;
|
||||
auto renderable = std::make_shared<Demo_Renderable>(scene);
|
||||
scene.attach_renderable(renderable);
|
||||
scene.render();
|
||||
scene.wait_for_render();
|
||||
const auto& state = radio->render_use_state();
|
||||
std::cout << radio->id << ' ' << radio->name << ' ' << state.port.get() << ' ' << state.buffer_count.get() << ' ' << renderable->render_count.load() << ' ' << scene.frame_control.frequency_hz() << '\n';
|
||||
return 0;
|
||||
}
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
|
||||
#ifdef RENDERIVE_WITH_GTEST
|
||||
if (argc > 1 && std::string(argv[1]) == "--gtest") {
|
||||
--argc;
|
||||
++argv;
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
#endif
|
||||
return run_main_flow();
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user