Skip to content

Commit

Permalink
Zephyr: Scene: benchmark scene transform changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed May 27, 2024
1 parent 47a46dc commit a2cc760
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
14 changes: 14 additions & 0 deletions app/next/src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ namespace zephyr {
camera_transform.SetPosition(camera_position);
camera_transform.GetRotation().SetFromEuler(euler_x, euler_y, 0.0f);

for(SceneNode* cube : m_dynamic_cubes) {
Vector3 position = cube->GetTransform().GetPosition();
position.X() += 0.01;
cube->GetTransform().SetPosition(position);

Quaternion rotation = cube->GetTransform().GetRotation().GetAsQuaternion();
rotation = Quaternion::FromAxisAngle({0, 1, 0}, 0.01f) * rotation;
cube->GetTransform().GetRotation().SetFromQuaternion(rotation);
}

RenderFrame();
}
}
Expand Down Expand Up @@ -268,6 +278,10 @@ namespace zephyr {
cube->CreateComponent<MeshComponent>(cube_geometry, std::shared_ptr<Material>{});
cube->GetTransform().SetPosition({(f32)x, (f32)y, (f32)-z});
cube->GetTransform().SetScale({0.1, 0.1, 0.1});

if(m_dynamic_cubes.size() < 32768) {
m_dynamic_cubes.push_back(cube.get());
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/next/src/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace zephyr {
std::shared_ptr<SceneGraph> m_scene_graph{};
std::shared_ptr<SceneNode> m_camera_node{};
std::shared_ptr<SceneNode> m_behemoth_scene{};
std::vector<SceneNode*> m_dynamic_cubes{};

int m_fps_counter{};
std::chrono::steady_clock::time_point m_time_point_last_update{};
Expand Down
1 change: 1 addition & 0 deletions zephyr/scene/include/zephyr/scene/scene_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace zephyr {
void SignalNodeTransformChanged(SceneNode* node);

std::shared_ptr<SceneNode> m_root_node{};
std::vector<SceneNode*> m_pending_nodes_with_dirty_transforms{};
std::vector<SceneNode*> m_nodes_with_dirty_transform{};
};

Expand Down
5 changes: 1 addition & 4 deletions zephyr/scene/src/scene_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ namespace zephyr {
}

void SceneGraph::SignalNodeTransformChanged(SceneNode* node) {
// TODO(fleroviux): try to efficiently eliminate redundant updates.
node->Traverse([this](SceneNode* child_node) {
const auto match = std::ranges::find(m_nodes_with_dirty_transform, child_node);
if(match != m_nodes_with_dirty_transform.end()) {
m_nodes_with_dirty_transform.erase(match);
}
m_nodes_with_dirty_transform.push_back(child_node);
return true;
});
Expand Down

0 comments on commit a2cc760

Please sign in to comment.