diff --git a/headers/enduro2d/core/engine.hpp b/headers/enduro2d/core/engine.hpp index 53e71ea2..9baa2afe 100644 --- a/headers/enduro2d/core/engine.hpp +++ b/headers/enduro2d/core/engine.hpp @@ -89,24 +89,28 @@ namespace e2d parameters& game_name(str_view value); parameters& company_name(str_view value); + parameters& without_graphics(bool value); parameters& debug_params(const debug_parameters& value); parameters& window_params(const window_parameters& value); parameters& timer_params(const timer_parameters& value); str& game_name() noexcept; str& company_name() noexcept; + bool& without_graphics() noexcept; debug_parameters& debug_params() noexcept; window_parameters& window_params() noexcept; timer_parameters& timer_params() noexcept; const str& game_name() const noexcept; const str& company_name() const noexcept; + const bool& without_graphics() const noexcept; const debug_parameters& debug_params() const noexcept; const window_parameters& window_params() const noexcept; const timer_parameters& timer_params() const noexcept; private: str game_name_{"noname"}; str company_name_{"noname"}; + bool without_graphics_{false}; debug_parameters debug_params_; window_parameters window_params_; timer_parameters timer_params_; diff --git a/samples/sources/sample_03/sample_03.cpp b/samples/sources/sample_03/sample_03.cpp index 7981171e..97107fdd 100644 --- a/samples/sources/sample_03/sample_03.cpp +++ b/samples/sources/sample_03/sample_03.cpp @@ -33,7 +33,7 @@ namespace int e2d_main(int argc, char *argv[]) { const auto starter_params = starter::parameters( - engine::parameters("sample_03", "enduro3d") + engine::parameters("sample_03", "enduro2d") .timer_params(engine::timer_parameters() .maximal_framerate(100))); modules::initialize( diff --git a/sources/enduro2d/core/engine.cpp b/sources/enduro2d/core/engine.cpp index cf162422..b405a5b4 100644 --- a/sources/enduro2d/core/engine.cpp +++ b/sources/enduro2d/core/engine.cpp @@ -156,6 +156,11 @@ namespace e2d return *this; } + engine::parameters& engine::parameters::without_graphics(bool value) { + without_graphics_ = value; + return *this; + } + engine::parameters& engine::parameters::debug_params(const debug_parameters& value) { debug_params_ = value; return *this; @@ -179,6 +184,10 @@ namespace e2d return company_name_; } + bool& engine::parameters::without_graphics() noexcept { + return without_graphics_; + } + engine::debug_parameters& engine::parameters::debug_params() noexcept { return debug_params_; } @@ -199,6 +208,10 @@ namespace e2d return company_name_; } + const bool& engine::parameters::without_graphics() const noexcept { + return without_graphics_; + } + const engine::debug_parameters& engine::parameters::debug_params() const noexcept { return debug_params_; } @@ -346,27 +359,38 @@ namespace e2d the().register_sink(std::move(log_stream)); } - // setup input + if ( !params.without_graphics() ) + { + // setup input - safe_module_initialize(); + safe_module_initialize(); - // setup window + // setup window - safe_module_initialize( - params.window_params().size(), - params.window_params().caption(), - params.window_params().fullscreen()); + safe_module_initialize( + params.window_params().size(), + params.window_params().caption(), + params.window_params().fullscreen()); - the().register_event_listener(the()); + the().register_event_listener(the()); - // setup render + // setup render - safe_module_initialize( - the(), - the()); + safe_module_initialize( + the(), + the()); + } } - engine::~engine() noexcept = default; + engine::~engine() noexcept { + modules::shutdown(); + modules::shutdown(); + modules::shutdown(); + modules::shutdown(); + modules::shutdown(); + modules::shutdown(); + modules::shutdown(); + } bool engine::start(application_uptr app) { E2D_ASSERT(is_in_main_thread()); diff --git a/sources/enduro2d/high/starter.cpp b/sources/enduro2d/high/starter.cpp index fbff6038..b01c42a0 100644 --- a/sources/enduro2d/high/starter.cpp +++ b/sources/enduro2d/high/starter.cpp @@ -19,6 +19,28 @@ namespace modules::initialize(std::forward(args)...); } } + + class starter_application final : public application { + public: + starter_application(application_uptr application) + : application_(std::move(application)) {} + + bool initialize() final { + return application_ && application_->initialize(); + } + + void shutdown() noexcept final { + if ( application_ ) { + application_->shutdown(); + } + } + + bool frame_tick() final { + return application_ && application_->frame_tick(); + } + private: + application_uptr application_; + }; } namespace e2d @@ -74,9 +96,21 @@ namespace e2d safe_module_initialize>(the()); } - starter::~starter() noexcept = default; + starter::~starter() noexcept { + modules::shutdown>(); + modules::shutdown>(); + modules::shutdown>(); + modules::shutdown>(); + modules::shutdown>(); + modules::shutdown>(); + modules::shutdown>(); + modules::shutdown(); + modules::shutdown(); + } bool starter::start(application_uptr app) { - return the().start(std::move(app)); + return the().start( + std::make_unique( + std::move(app))); } } diff --git a/untests/sources/untests_high/starter.cpp b/untests/sources/untests_high/starter.cpp new file mode 100644 index 00000000..9becbba7 --- /dev/null +++ b/untests/sources/untests_high/starter.cpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018 Matvey Cherevko + ******************************************************************************/ + +#include + +#include "_high.hpp" +using namespace e2d; + +TEST_CASE("starter"){ + modules::initialize(0, nullptr, + starter::parameters( + engine::parameters("starter_untests", "enduro2d") + .without_graphics(true))); + modules::shutdown(); +}