Skip to content

Commit

Permalink
docs: add audio sample page
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomsmiranda committed Dec 26, 2024
1 parent 395ff0d commit 9d16ac9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/pages/3_examples/2_engine/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ multiple plugins of the engine:
- @subpage examples-engine-events - @copybrief examples-engine-events
- @subpage examples-engine-voxels - @copybrief examples-engine-voxels
- @subpage examples-engine-imgui - @copybrief examples-engine-imgui
- @subpage examples-engine-audio - @copybrief examples-engine-audio
8 changes: 8 additions & 0 deletions engine/samples/audio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,37 @@ int main(int argc, char** argv)
input.bind(*bindings);
});

/// [Adding an AudioListener]
cubos.startupSystem("create a camera").call([](Commands cmds) {
cmds.create()
.add(Position{{0.0F, 0.0F, 0.0F}})
.add(Rotation::lookingAt({-1.0F, -1.0F, -1.0F}, glm::vec3{0.0F, 1.0F, 0.0F}))
.add(AudioListener{true});
});
/// [Adding an AudioListener]

/// [Adding the AudioSource]
cubos.startupSystem("create an audio source").after(audioStateInitTag).call([](Commands cmds) {
cmds.create()
.add(Position{{0.0F, 0.0F, 0.0F}})
.add(Velocity{.vec = {1.0F, 1.0F, 1.0F}})
.add(Rotation::lookingAt({-1.0F, -1.0F, -1.0F}, glm::vec3{0.0F, 1.0F, 0.0F}))
.add(AudioSource{});
});
/// [Adding the AudioSource]

cubos.system("play audio").call([&currAsset](Input& input, Commands cmds, Query<Entity, AudioSource&> query) {
for (auto [ent, src] : query)
{
/// [Adding the asset]
if (src.sound.isNull())
{
src.sound = AudioAssets[0];
cmds.add(ent, AudioPlay{});
}
/// [Adding the asset]

/// [Manipulating audio assets]
if (input.justPressed("skip"))
{
CUBOS_INFO("SKIP: {}", src.sound.getIdString());
Expand All @@ -102,6 +109,7 @@ int main(int argc, char** argv)
cmds.add(ent, AudioStop{});
CUBOS_INFO("STOPPING: {}", src.sound.getIdString());
}
/// [Manipulating audio assets]
}
});

Expand Down
2 changes: 1 addition & 1 deletion engine/samples/audio/page.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Audio {#examples-audio-sample}
# Audio {#examples-engine-audio}

@brief Using the @ref audio-plugin plugin

Expand Down

0 comments on commit 9d16ac9

Please sign in to comment.