Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add audio sample page #1421

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading