统一 2D/3D Renderable 继承链与实时数据策略

This commit is contained in:
2026-08-14 18:47:36 +08:00
parent bb64801679
commit cb32f72bc9
43 changed files with 1010 additions and 528 deletions
@@ -318,7 +318,10 @@ TEST(threading_contract_test, low_latency_strategy_keeps_frames_consistent_durin
TEST(threading_contract_test, real_time_data_observations_follow_mutation_revision_order) {
Threading_Revision_Observer observer;
auto observer_data = observer.data;
Latest_Real_Time_Data<int, std::mutex, Threading_Revision_Observer_State> data(Threading_Revision_Observer_State(observer, Threading_Test_Time_Source{}));
History_Real_Time_Data<int, std::vector<int>, std::mutex,
Threading_Revision_Observer_State>
data(Threading_Revision_Observer_State(
observer, Threading_Test_Time_Source{}));
constexpr int updater_count = 8;
constexpr int updates_per_thread = 500;
constexpr int update_count = updater_count * updates_per_thread;
@@ -345,8 +348,8 @@ TEST(threading_contract_test, real_time_data_observations_follow_mutation_revisi
}
}
}
TEST(threading_contract_test, latest_real_time_data_supports_concurrent_updates_and_snapshots) {
Latest_Real_Time_Data<Threading_Test_Frame> data;
TEST(threading_contract_test, retained_history_supports_concurrent_latest_updates_and_snapshots) {
History_Real_Time_Data<Threading_Test_Frame> data;
constexpr int updater_count = 4;
constexpr int updates_per_thread = 1000;
constexpr int update_count = updater_count * updates_per_thread;
@@ -357,7 +360,7 @@ TEST(threading_contract_test, latest_real_time_data_supports_concurrent_updates_
wait_start(start);
while (updates_done.load(std::memory_order_acquire) != updater_count) {
const auto snapshot = data.snapshot();
if (snapshot && !valid_frame(*snapshot)) {
if (!snapshot.empty() && !valid_frame(snapshot.back())) {
invalid.fetch_add(1, std::memory_order_relaxed);
}
const auto state = data.update_state();
@@ -373,7 +376,7 @@ TEST(threading_contract_test, latest_real_time_data_supports_concurrent_updates_
wait_start(start);
for (int index = 0; index < updates_per_thread; ++index) {
const auto value = static_cast<std::uint64_t>(updater * updates_per_thread + index);
data.update({value, ~value});
data.update({value, ~value}, 1);
}
updates_done.fetch_add(1, std::memory_order_release);
});
@@ -570,7 +573,9 @@ TEST(threading_contract_test, scene_render_and_render_graph_rebuild_are_serializ
EXPECT_EQ(executed.load(std::memory_order_acquire), render_count + 1);
}
TEST(threading_contract_test, real_time_data_updates_can_race_with_scene_destruction) {
using Data = Latest_Real_Time_Data<int, std::mutex, Observer_State<Frame_Strategy_Real_Time_Data_Observer>>;
using Data = History_Real_Time_Data<
int, std::vector<int>, std::mutex,
Observer_State<Frame_Strategy_Real_Time_Data_Observer>>;
struct Renderable : Renderable_Base {
explicit Renderable() : Renderable_Base() {}
};