diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-18 13:03:49 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-18 13:03:49 +0100 |
commit | 38c5e1bb819d2bf06b9d8c387726fa285a9a3065 (patch) | |
tree | 8e68d4c576d51b90e413cab08e60e37759d3d5bd /src/example | |
parent | 81404db80bbf9463c3d535ae389e7fbb753a902c (diff) |
add test + fix audio crash
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/example/audio-crash.cpp | 47 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index f62414e..3a196e1 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -22,3 +22,4 @@ add_example(button) add_example(loadfont) add_example(FontExample) add_example(AITest) +add_example(audio-crash) diff --git a/src/example/audio-crash.cpp b/src/example/audio-crash.cpp new file mode 100644 index 0000000..6c1052e --- /dev/null +++ b/src/example/audio-crash.cpp @@ -0,0 +1,47 @@ +#include <crepe/api/LoopManager.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Camera.h> +#include <crepe/api/AudioSource.h> +#include <crepe/api/Config.h> + +#define private public +#include <crepe/api/Script.h> + +using namespace crepe; +using namespace std; + +class Auto : public Script { + unsigned i = 0; + void init() { + AudioSource & sound = get_component<AudioSource>(); + sound.play(); + } + + void update() { + if (++i < 50) return; + EventManager & evmgr = this->mediator->event_manager; + evmgr.trigger_event<ShutDownEvent>(); + } +}; + +class Bug : public Scene { + virtual std::string get_name() const override { return "bug"; } + void load_scene() override { + GameObject camera = new_object("camera"); + camera.add_component<Camera>(ivec2{10, 10}, vec2{1, 1}, Camera::Data{ }); + + GameObject sound = new_object("sound"); + sound.add_component<AudioSource>(Asset{"mwe/audio/bgm.ogg"}); + sound.add_component<BehaviorScript>().set_script<Auto>(); + } +}; + +int main() { + Config & config = Config::get_instance(); + config.log.level = Log::Level::TRACE; + + LoopManager example; + example.add_scene<Bug>(); + example.start(); + return 0; +} |