Cogs.Core
SceneTraversal.h
1#pragma once
2
3#include "Components/Core/SceneComponent.h"
4
5#include "Foundation/ComponentModel/Entity.h"
6
7namespace Cogs
8{
9 namespace Core
10 {
13 template<typename ComponentType, typename MemberType, class Recurse>
14 void applyRecursiveFieldChange(ComponentModel::Entity * entity, MemberType ComponentType::* member, MemberType value, Recurse recurse)
15 {
17
18 entity->getComponents(collection);
19
20 for (auto & component : collection) {
21 component.*member = value;
22 component.setChanged();
23
24 }
25
26 if (recurse == nullptr || recurse(entity)) {
27 const SceneComponent* sceneComponent = entity->getComponent<SceneComponent>();
28 if (sceneComponent) {
29 for (auto& child : sceneComponent->children) {
30 applyRecursiveFieldChange(child.get(), member, value, recurse);
31 }
32 }
33 }
34 }
35 }
36}
Container for components, providing composition of dynamic entities.
Definition: Entity.h:18
T * getComponent() const
Get a pointer to the first component implementing the given type in the entity.
Definition: Entity.h:35
void getComponents(ComponentCollection< T > &collection) const
Get all the components implementing the templated type.
Definition: Entity.h:52
Contains information on how the entity behaves in the scene.
std::vector< EntityPtr > children
Contains all child entities owned by this component.
void applyRecursiveFieldChange(ComponentModel::Entity *entity, MemberType ComponentType::*member, MemberType value, Recurse recurse)
Contains all Cogs related functionality.
Definition: FieldSetter.h:23