所有权指针明确

This commit is contained in:
2026-08-28 13:33:17 +08:00
parent 0bc281b6b9
commit e07d16ea74
70 changed files with 1387 additions and 960 deletions
+23 -20
View File
@@ -17,7 +17,7 @@ using namespace aethera;
using namespace aethera::render_2d;
template <typename Object, typename... Arguments>
Object* build_object(Arguments&&... arguments) {
owner<Object*> build_object(Arguments&&... arguments) {
typename Object::template Builder<Object> builder(std::forward<Arguments>(arguments)...);
auto result = builder.build();
if (!result) std::_Exit(2);
@@ -27,7 +27,7 @@ Object* build_object(Arguments&&... arguments) {
bool contains_color(Image_View view) {
for (int y = 0; y < view.height; ++y) {
const auto* row = reinterpret_cast<const Pixel*>(
view.data + static_cast<std::ptrdiff_t>(y) * view.stride);
view.data.data() + static_cast<std::ptrdiff_t>(y) * view.stride);
for (int x = 0; x < view.width; ++x)
if (row[x] != 0) return true;
}
@@ -48,15 +48,16 @@ int main() {
initialize_runtime({.workers = 4});
auto* frequency = build_object<Frequency>();
auto* power = build_object<Power>();
auto* spectrum = build_object<Spectrum_Object>(frequency, power, 4u);
auto* spectrum = build_object<Spectrum_Object>(
not_null{frequency}, not_null{power}, 4u);
auto* time = build_object<Time>();
auto* waterfall = build_object<Waterfall_Object>(
frequency, time, Plot_Partition_Grid{2, 2});
not_null{frequency}, not_null{time}, Plot_Partition_Grid{2, 2});
auto* afterglow = build_object<Afterglow_Object>(
frequency, power, Plot_Partition_Grid{2, 2});
not_null{frequency}, not_null{power}, Plot_Partition_Grid{2, 2});
auto* q_axis = build_object<Power>();
auto* constellation = build_object<Constellation_Object>(
power, q_axis, 3u);
not_null{power}, not_null{q_axis}, 3u);
auto* spectrum_painted = new std::atomic_bool{};
auto* topology_valid = new std::atomic_bool{true};
auto* second_frame_valid = new std::atomic_bool{};
@@ -75,10 +76,10 @@ int main() {
verify_spectrum_precedes_axis);
typename Scene_Object::template Builder<Scene_Object> scene_builder;
scene_builder.add_renderable(spectrum);
scene_builder.add_renderable(waterfall);
scene_builder.add_renderable(afterglow);
scene_builder.add_renderable(constellation);
scene_builder.add_renderable(not_null{spectrum});
scene_builder.add_renderable(not_null{waterfall});
scene_builder.add_renderable(not_null{afterglow});
scene_builder.add_renderable(not_null{constellation});
auto scene_result = scene_builder.build();
if (!scene_result) return 2;
auto* scene = std::move(scene_result).value().release();
@@ -157,12 +158,13 @@ int main() {
!afterglow_color_barrier)
trace_valid->store(false, std::memory_order_relaxed);
};
scene->set_frame_callback(
if (!scene->render(
frame,
[scene, spectrum, waterfall, afterglow, constellation, frame,
resized_partition_frame, spectrum_painted,
topology_valid, second_frame_valid, trace_valid,
validate_trace](Frame_2D* completed) {
const bool valid = completed == frame &&
validate_trace](not_null<Frame_2D*> completed) {
const bool valid = completed.get() == frame &&
spectrum->read_state<Spectrum::Base_Tag>().sample_count ==
512 &&
topology_valid->load(std::memory_order_relaxed) &&
@@ -181,12 +183,13 @@ int main() {
constellation->set<
&Constellation_Diagram::Prop::partition_count>(2u);
spectrum_painted->store(false, std::memory_order_relaxed);
scene->set_frame_callback(
if (!scene->render(
resized_partition_frame,
[resized_partition_frame, second_frame_valid,
topology_valid, trace_valid,
validate_trace](Frame_2D* next) {
validate_trace](not_null<Frame_2D*> next) {
const bool resized_valid =
next == resized_partition_frame &&
next.get() == resized_partition_frame &&
topology_valid->load(std::memory_order_relaxed) &&
contains_color(next->image());
second_frame_valid->store(resized_valid,
@@ -197,10 +200,10 @@ int main() {
trace_valid->load(std::memory_order_relaxed)
? 0
: 1);
});
if (!scene->render(resized_partition_frame)) std::_Exit(2);
});
if (!scene->render(frame)) return 2;
}))
std::_Exit(2);
}))
return 2;
/*
* render() 是异步入口。结束提交线程但保持 Taskflow worker 和进程存活,