大重构

This commit is contained in:
2026-07-28 17:55:29 +08:00
parent 3a3d32be26
commit ae07e67619
88 changed files with 4924 additions and 1403 deletions
+91
View File
@@ -0,0 +1,91 @@
#include <QApplication>
#include <QElapsedTimer>
#include <QEventLoop>
#include <QThread>
#include <cmath>
#include <memory>
#include "../YSGraphic_Core/Axis/Axis.h"
#include "../YSGraphic_Core/Axis/Frequent_Axis.h"
#include "../YSGraphic_Core/architecture/Plot.h"
#include "../YSGraphic_Core/plottable/Spectrum.h"
namespace {
QVector<double> make_spectrum_data(int size, int frame) {
QVector<double> data(size);
for (int i = 0; i < size; ++i)
data[i] = -80.0 + 20.0 * std::sin((double)(i + frame) * 0.03);
return data;
}
void process_events(int ms) {
QElapsedTimer timer;
timer.start();
while (timer.elapsed() < ms) {
QApplication::processEvents(QEventLoop::AllEvents, 10);
QThread::msleep(1);
}
}
void stress_remove_local_cache_renderable() {
YSG::Plot plot;
plot.init();
plot.resize(640, 360);
auto data = plot.create_renderable_node(plot.root_renderable(), "DataRenderable");
auto axis = plot.create_renderable_node(plot.root_renderable(), "AxisRenderable");
auto xAxis = YSG::Frequent_Axis::Builder(axis, Qt::Horizontal).set_pixel_size(620).set_coord_range({0.0, 100.0}).build();
auto yAxis = YSG::Axis::Builder(axis, Qt::Vertical).set_pixel_size(300).set_coord_range({-120.0, 0.0}).build();
auto spectrum = YSG::Spectrum::Builder(data, xAxis, yAxis).set_frequent_point_size(4096).set_frequent_range({0.0, 100.0}).set_sample_mode(YSG::Spectrum_Sample_Mode::Pixel_Peak_Bucket).build();
spectrum->set_cache_mode(YSG::Renderable_Cache_Mode::Local_Pixel);
plot.start_render(120);
for (int i = 0; i < 64; ++i) {
spectrum->give_data(make_spectrum_data(4096, i));
spectrum->mark_render_dirty();
}
plot.remove_renderable(spectrum);
spectrum.reset();
process_events(250);
}
void stress_plot_destroy_with_pending_tasks() {
for (int round = 0; round < 32; ++round) {
auto plot = std::make_unique<YSG::Plot>();
plot->init();
plot->resize(480, 240);
auto data = plot->create_renderable_node(plot->root_renderable(), "DataRenderable");
auto axis = plot->create_renderable_node(plot->root_renderable(), "AxisRenderable");
auto xAxis = YSG::Frequent_Axis::Builder(axis, Qt::Horizontal).set_pixel_size(460).set_coord_range({100.0, 0.0}).build();
auto yAxis = YSG::Axis::Builder(axis, Qt::Vertical).set_pixel_size(220).set_coord_range({0.0, -120.0}).build();
auto spectrum = YSG::Spectrum::Builder(data, xAxis, yAxis).set_frequent_point_size(2048).set_frequent_range({100.0, 0.0}).set_sample_mode(YSG::Spectrum_Sample_Mode::Pixel_Peak_Bucket).build();
spectrum->set_cache_mode(YSG::Renderable_Cache_Mode::Local_Pixel);
plot->start_render(120);
for (int frame = 0; frame < 16; ++frame) {
spectrum->give_data(make_spectrum_data(2048, frame));
spectrum->mark_render_dirty();
}
plot.reset();
spectrum.reset();
xAxis.reset();
yAxis.reset();
process_events(20);
}
}
void stress_reinit_rejected() {
YSG::Plot plotA;
YSG::Plot plotB;
plotA.init();
plotB.init();
auto axisNodeA = plotA.create_renderable_node(plotA.root_renderable(), "AxisRenderableA");
auto axisNodeB = plotB.create_renderable_node(plotB.root_renderable(), "AxisRenderableB");
auto axis = YSG::Axis::Builder(axisNodeA, Qt::Horizontal).set_pixel_size(100).set_coord_range({0.0, 1.0}).build();
try {
axis->init(axisNodeB);
}
catch (...) {
}
}
}
int main(int argc, char** argv) {
QApplication app(argc, argv);
YSG::start_render_scheduler();
stress_remove_local_cache_renderable();
stress_plot_destroy_with_pending_tasks();
stress_reinit_rejected();
process_events(250);
return 0;
}