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 sbk::engine
6{
7 class SB_CLASS RandomContainer : public container
8 {
9 public:
10 virtual void gather_children_for_play(gather_children_context& 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()->try_convert_object<container>());
18 break;
19 default:
20 int randomChildIndex = std::rand() % m_childNodes.size();
21 std::unordered_set<sbk::core::database_ptr<node_base>>::const_iterator childIter =
22 m_childNodes.begin();
23 std::advance(childIter, randomChildIndex);
24 context.sounds.push_back(childIter->lookupRaw()->try_convert_object<container>());
25 break;
26 }
27 }
28
29 REGISTER_REFLECTION(RandomContainer, container)
30 RTTR_REGISTRATION_FRIEND
31 };
32} // namespace sbk::engine
Definition random_container.h:8
virtual void gather_children_for_play(gather_children_context &context) const override
Collects and gathers sounds on this node and its children for play.
Definition random_container.h:10
Base container type. Inherited types include sounds, random, sequence etc.
Definition container.h:49
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