Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
switch_container.h
1#pragma once
2
3#include "sound_bakery/node/container/container.h"
4
5namespace SB::Engine
6{
7 class SB_CLASS SwitchContainer : public Container
8 {
9 public:
10 void gatherChildrenForPlay(GatherChildrenContext& context) const override
11 {
13
14 if (auto findLocalValue = context.parameters.intParameters.find(m_switchParameter);
15 findLocalValue != context.parameters.intParameters.cend())
16 {
17 selectedValue = SB::Core::DatabasePtr<NamedParameterValue>(findLocalValue->second.get());
18 }
19 else if (m_switchParameter.lookup())
20 {
21 selectedValue = m_switchParameter->getSelectedValue();
22 }
23
24 if (auto foundIter = m_switchToChild.find(selectedValue); foundIter != m_switchToChild.end())
25 {
26 SB::Core::ChildPtr<Container> selectedChild(*this);
27 selectedChild = foundIter->second;
28
29 if (selectedChild.lookup())
30 {
31 context.sounds.push_back(selectedChild.lookupRaw());
32 }
33 }
34 }
35
37 {
38 parameters.intParameters.insert(m_switchParameter);
39 }
40
41 void setSwitchParameter(SB::Core::DatabasePtr<NamedParameter> parameter);
42
43 SB::Core::DatabasePtr<NamedParameter> getSwitchParameter() const { return m_switchParameter; }
44
45 std::unordered_map<SB::Core::DatabasePtr<NamedParameterValue>, SB::Core::ChildPtr<Container>>
46 getSwitchToChildMap() const
47 {
48 return m_switchToChild;
49 }
50
51 private:
52 void setSwitchToChild(
54
55 void populateChildKeys();
56
60 GlobalIntParameter m_switchParameter;
61
65 std::unordered_map<SB::Core::DatabasePtr<NamedParameterValue>, SB::Core::ChildPtr<Container>> m_switchToChild;
66
67 REGISTER_REFLECTION(SwitchContainer, Container)
68 RTTR_REGISTRATION_FRIEND
69 };
70} // namespace SB::Engine
Definition database_ptr.h:23
bool lookup() const
Find the live object referenced by the ID and store it.
Definition database_ptr.h:142
Base container type. Inherited types include sounds, random, sequence etc.
Definition container.h:49
Definition switch_container.h:8
void gatherChildrenForPlay(GatherChildrenContext &context) const override
Collects and gathers sounds on this node and its children for play.
Definition switch_container.h:10
void gatherParametersFromThis(GlobalParameterList &parameters) override
Appends parameters from this node that are relevant to the runtime output.
Definition switch_container.h:36
Contains all information required for gathering sounds for runtime playing and selection.
Definition container.h:13
std::vector< const Container * > sounds
Vector of containers that should play this iteration.
Definition container.h:25
LocalParameterList parameters
List of parameters that are local to this gathering.
Definition container.h:32
Holds a list of parameters.
Definition parameter.h:224