From 38c5e1bb819d2bf06b9d8c387726fa285a9a3065 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 18 Dec 2024 13:03:49 +0100 Subject: add test + fix audio crash --- src/crepe/api/LoopManager.h | 19 +++++++++--------- src/example/CMakeLists.txt | 1 + src/example/audio-crash.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 src/example/audio-crash.cpp diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h index 1d23cbf..124cd3a 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -71,9 +71,19 @@ private: private: //! Global context Mediator mediator; + /** + * \brief Collection of System instances + * + * This map holds System instances indexed by the system's class typeid. It is filled in the + * constructor of LoopManager using LoopManager::load_system. + */ + std::unordered_map> systems; //! SDLContext instance SDLContext sdl_context{mediator}; + //! Resource manager instance + ResourceManager resource_manager{mediator}; + //! Component manager instance ComponentManager component_manager{mediator}; //! Scene manager instance @@ -82,8 +92,6 @@ private: LoopTimerManager loop_timer{mediator}; //! EventManager instance EventManager event_manager{mediator}; - //! Resource manager instance - ResourceManager resource_manager{mediator}; //! Save manager instance SaveManager save_manager{mediator}; @@ -94,13 +102,6 @@ private: * This function sets the game_running variable to false, stopping the gameloop and therefor quitting the game. */ bool on_shutdown(const ShutDownEvent & e); - /** - * \brief Collection of System instances - * - * This map holds System instances indexed by the system's class typeid. It is filled in the - * constructor of LoopManager using LoopManager::load_system. - */ - std::unordered_map> systems; /** * \brief Initialize a system * \tparam T System type (must be derivative of \c System) 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 +#include +#include +#include +#include + +#define private public +#include + +using namespace crepe; +using namespace std; + +class Auto : public Script { + unsigned i = 0; + void init() { + AudioSource & sound = get_component(); + sound.play(); + } + + void update() { + if (++i < 50) return; + EventManager & evmgr = this->mediator->event_manager; + evmgr.trigger_event(); + } +}; + +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(ivec2{10, 10}, vec2{1, 1}, Camera::Data{ }); + + GameObject sound = new_object("sound"); + sound.add_component(Asset{"mwe/audio/bgm.ogg"}); + sound.add_component().set_script(); + } +}; + +int main() { + Config & config = Config::get_instance(); + config.log.level = Log::Level::TRACE; + + LoopManager example; + example.add_scene(); + example.start(); + return 0; +} -- cgit v1.2.3 From cd389129cc2ed73596251cb7c9cc606f6e6d74d8 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 18 Dec 2024 13:04:27 +0100 Subject: restore examples --- src/example/CMakeLists.txt | 1 - src/example/audio-crash.cpp | 47 --------------------------------------------- 2 files changed, 48 deletions(-) delete mode 100644 src/example/audio-crash.cpp diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 3a196e1..f62414e 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -22,4 +22,3 @@ 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 deleted file mode 100644 index 6c1052e..0000000 --- a/src/example/audio-crash.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -#include - -#define private public -#include - -using namespace crepe; -using namespace std; - -class Auto : public Script { - unsigned i = 0; - void init() { - AudioSource & sound = get_component(); - sound.play(); - } - - void update() { - if (++i < 50) return; - EventManager & evmgr = this->mediator->event_manager; - evmgr.trigger_event(); - } -}; - -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(ivec2{10, 10}, vec2{1, 1}, Camera::Data{ }); - - GameObject sound = new_object("sound"); - sound.add_component(Asset{"mwe/audio/bgm.ogg"}); - sound.add_component().set_script(); - } -}; - -int main() { - Config & config = Config::get_instance(); - config.log.level = Log::Level::TRACE; - - LoopManager example; - example.add_scene(); - example.start(); - return 0; -} -- cgit v1.2.3