From b9423484dcd5c8baf60c00eedc2b8ee61ed6c177 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 8 Oct 2019 03:58:19 +0700 Subject: [PATCH] add loading behaviour script asset --- headers/enduro2d/high/_high.hpp | 2 + .../enduro2d/high/components/behaviour.hpp | 22 +++ headers/enduro2d/high/luasol.hpp | 30 +++- headers/enduro2d/high/script.hpp | 36 ++++- sources/enduro2d/high/assets/script_asset.cpp | 12 +- .../enduro2d/high/components/behaviour.cpp | 25 +++- sources/enduro2d/high/luasol.cpp | 40 ++++-- sources/enduro2d/high/script.cpp | 41 ++++-- sources/enduro2d/high/starter.cpp | 4 +- untests/sources/untests_high/luasol.cpp | 130 +++++++++++------- 10 files changed, 251 insertions(+), 91 deletions(-) diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 72681c7b..0e497792 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -9,6 +9,8 @@ #include "../core/_all.hpp" #include + +#define SOL_ALL_SAFETIES_ON 1 #include <3rdparty/sol/sol.hpp> namespace e2d diff --git a/headers/enduro2d/high/components/behaviour.hpp b/headers/enduro2d/high/components/behaviour.hpp index b1fb540a..f97b8e6a 100644 --- a/headers/enduro2d/high/components/behaviour.hpp +++ b/headers/enduro2d/high/components/behaviour.hpp @@ -9,12 +9,19 @@ #include "../_high.hpp" #include "../factory.hpp" +#include "../assets/script_asset.hpp" namespace e2d { class behaviour final { public: behaviour() = default; + behaviour(const script_asset::ptr& script); + + behaviour& script(const script_asset::ptr& value) noexcept; + [[nodiscard]] const script_asset::ptr& script() const noexcept; + private: + script_asset::ptr script_; }; template <> @@ -31,3 +38,18 @@ namespace e2d const collect_context& ctx) const; }; } + +namespace e2d +{ + inline behaviour::behaviour(const script_asset::ptr& value) + : script_(value) {} + + inline behaviour& behaviour::script(const script_asset::ptr& value) noexcept { + script_ = value; + return *this; + } + + inline const script_asset::ptr& behaviour::script() const noexcept { + return script_; + } +} diff --git a/headers/enduro2d/high/luasol.hpp b/headers/enduro2d/high/luasol.hpp index 78ad8159..e3e5011f 100644 --- a/headers/enduro2d/high/luasol.hpp +++ b/headers/enduro2d/high/luasol.hpp @@ -8,16 +8,38 @@ #include "_high.hpp" +#include "script.hpp" + namespace e2d { class luasol final : public module { public: luasol(); - ~luasol() noexcept final; + ~luasol() noexcept final = default; - sol::state& lua() noexcept; - const sol::state& lua() const noexcept; + template < typename F > + decltype(auto) with_state(F&& f); + template < typename F > + decltype(auto) with_state(F&& f) const; + + std::optional