结构优化

This commit is contained in:
2026-08-13 15:17:02 +08:00
parent 65cf786e2d
commit e8e8b29806
25 changed files with 822 additions and 461 deletions
@@ -2,12 +2,13 @@
#include <atomic>
#include <memory>
#include "renderive/renderable/Renderable.hpp"
#include "renderive/renderable/Renderable_Test_Harness.hpp"
#include "renderive/scene/Scene.hpp"
#include "Scene_Test_Helpers.hpp"
struct Scene3D_Context_Test_Renderable : Renderable_Base {
explicit Scene3D_Context_Test_Renderable() : Renderable_Base() {}
void prepare(const Prepare_Render_Context&) override {
scene_is_3d = dynamic_cast<Scene_3D_Base*>(&scene()) != nullptr;
struct Scene3D_Context_Test_Renderable : Renderable_Test_Harness {
explicit Scene3D_Context_Test_Renderable() = default;
void prepare_for_test(const Prepare_Render_Context&) override {
scene_is_3d = dynamic_cast<Scene_3D_Base*>(&scene_for_test()) != nullptr;
++render_count;
}
std::atomic<int> render_count{};
@@ -22,9 +23,10 @@ TEST(scene3d_context_test, uses_scene_3d_base_contract) {
EXPECT_EQ(renderable->render_count.load(), 1);
EXPECT_TRUE(renderable->scene_is_3d);
}
struct Scene3D_Dependency_Cache_Test_Renderable : Renderable_Base {
explicit Scene3D_Dependency_Cache_Test_Renderable() : Renderable_Base({.cache_enabled = true}) {}
void prepare(const Prepare_Render_Context&) override {
struct Scene3D_Dependency_Cache_Test_Renderable : Renderable_Test_Harness {
explicit Scene3D_Dependency_Cache_Test_Renderable()
: Renderable_Test_Harness({.cache_enabled = true}) {}
void prepare_for_test(const Prepare_Render_Context&) override {
++render_count;
}
int render_count{};
@@ -38,15 +40,15 @@ TEST(scene3d_context_test, propagates_cache_invalidation_through_unsorted_depend
attach.attach(leaf);
attach.attach(middle);
attach.attach(root);
attach.set_parent(Scene_Base::Relationship::dependency, leaf, middle);
attach.set_parent(Scene_Base::Relationship::dependency, middle, root);
attach.set_dependency_parent(leaf, middle);
attach.set_dependency_parent(middle, root);
});
scene.render();
scene.wait_for_render();
EXPECT_EQ(root->render_count, 1);
EXPECT_EQ(middle->render_count, 1);
EXPECT_EQ(leaf->render_count, 1);
root->invalidate_prepare();
root->invalidate_prepare_for_test();
scene.render();
scene.wait_for_render();
EXPECT_EQ(root->render_count, 2);
@@ -62,19 +64,19 @@ TEST(scene3d_context_test, runtime_edit_explicitly_reparents_children_before_det
attach.attach(grandparent);
attach.attach(parent);
attach.attach(child);
attach.set_parent(Scene_Base::Relationship::display, parent, grandparent);
attach.set_parent(Scene_Base::Relationship::display, child, parent);
attach.set_parent(Scene_Base::Relationship::dependency, parent, grandparent);
attach.set_parent(Scene_Base::Relationship::dependency, child, parent);
attach.set_display_parent(parent, grandparent);
attach.set_display_parent(child, parent);
attach.set_dependency_parent(parent, grandparent);
attach.set_dependency_parent(child, parent);
});
scene.render();
scene.wait_for_render();
EXPECT_EQ(child->render_count, 1);
wait_renderable_edit(scene, [grandparent, parent, child](auto& editor) {
editor.set_parent(Scene_Base::Relationship::display, child, grandparent);
editor.set_parent(Scene_Base::Relationship::dependency, child, grandparent);
editor.clear_parents(Scene_Base::Relationship::display, parent);
editor.clear_parents(Scene_Base::Relationship::dependency, parent);
editor.set_display_parent(child, grandparent);
editor.set_dependency_parent(child, grandparent);
editor.clear_display_parent(parent);
editor.clear_dependency_parent(parent);
editor.detach(parent);
});
const auto topology = scene.topology_snapshot();