Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
random_container.h
1#pragma once
2
3#include "sound_bakery/node/container/container.h"
4
5namespace SB::Engine
6{
7 class SB_CLASS RandomContainer : public Container
8 {
9 public:
10 virtual void gatherChildrenForPlay(GatherChildrenContext& context) const override
11 {
12 switch (m_childNodes.size())
13 {
14 case 0:
15 break;
16 case 1:
17 context.sounds.push_back(m_childNodes.begin()->lookupRaw()->tryConvertObject<Container>());
18 break;
19 default:
20 int randomChildIndex = std::rand() % m_childNodes.size();
21 std::unordered_set<SB::Core::DatabasePtr<NodeBase>>::const_iterator childIter =
22 m_childNodes.begin();
23 std::advance(childIter, randomChildIndex);
24 context.sounds.push_back(childIter->lookupRaw()->tryConvertObject<Container>());
25 break;
26 }
27 }
28
29 REGISTER_REFLECTION(RandomContainer, Container)
30 RTTR_REGISTRATION_FRIEND
31 };
32} // namespace SB::Engine
Base container type. Inherited types include sounds, random, sequence etc.
Definition container.h:49
Definition random_container.h:8
virtual void gatherChildrenForPlay(GatherChildrenContext &context) const override
Collects and gathers sounds on this node and its children for play.
Definition random_container.h:10
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