-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(lua): start scripted systems * feat(lua): lua systems work * feat(lua): fix working directory * feat(lua): more coverage
- Loading branch information
Showing
15 changed files
with
288 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
modules/ecs/antara/gaming/ecs/antara.ecs.event.add.base.system.tests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#include <doctest/doctest.h> | ||
#include "antara/gaming/ecs/event.add.base.system.hpp" | ||
|
||
namespace antara::gaming::ecs::tests | ||
{ | ||
TEST_SUITE ("test event add base system") | ||
{ | ||
TEST_CASE ("default constructible") | ||
{ | ||
antara::gaming::ecs::event::add_base_system evt{}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#include <utility> //! std::move | ||
#include "antara/gaming/ecs/event.add.base.system.hpp" | ||
|
||
namespace antara::gaming::ecs | ||
{ | ||
|
||
event::add_base_system::add_base_system(std::unique_ptr<ecs::base_system> system_ptr_) noexcept : system_ptr( | ||
std::move(system_ptr_)) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <memory> // std::unique_ptr | ||
#include "base.system.hpp" | ||
|
||
namespace antara::gaming::ecs::event | ||
{ | ||
struct add_base_system | ||
{ | ||
add_base_system(std::unique_ptr<ecs::base_system> system_ptr_ = nullptr) noexcept; | ||
std::unique_ptr<ecs::base_system> system_ptr{nullptr}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
modules/lua/antara/gaming/lua/details/lua.scripted.system.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <utility> | ||
#include <sol/state.hpp> | ||
#include "antara/gaming/ecs/system.hpp" | ||
|
||
namespace antara::gaming::lua::details | ||
{ | ||
template<typename SystemType> | ||
class scripted_system final : public ecs::system<scripted_system<SystemType>, SystemType> | ||
{ | ||
public: | ||
using TSystem = ecs::system<scripted_system<SystemType>, SystemType>; | ||
|
||
scripted_system(entt::registry &entity_registry, entt::dispatcher &dispatcher, std::string table_name, | ||
sol::state &state) noexcept | ||
: TSystem::system( | ||
entity_registry, dispatcher), table_name_(std::move(table_name)), state_(state) | ||
{ | ||
safe_function_("on_construct"); | ||
} | ||
|
||
~scripted_system() noexcept final | ||
{ | ||
safe_function_("on_destruct"); | ||
} | ||
|
||
void update() noexcept final | ||
{ | ||
safe_function_("update"); | ||
} | ||
|
||
private: | ||
template<typename ... Args> | ||
void safe_function_(const std::string &function, Args &&... args) noexcept | ||
{ | ||
try { | ||
sol::optional<sol::function> f = state_[table_name_][function]; | ||
if (f && f.value() != sol::lua_nil) { | ||
f.value()(std::forward<Args>(args)...); | ||
} | ||
} | ||
catch (const std::exception &error) { | ||
std::cerr << error.what() << std::endl; | ||
} | ||
} | ||
|
||
std::string table_name_; | ||
sol::state &state_; | ||
}; | ||
|
||
using lua_post_scripted_system = scripted_system<ecs::st_system_post_update>; | ||
using lua_pre_scripted_system = scripted_system<ecs::st_system_pre_update>; | ||
using lua_logic_scripted_system = scripted_system<ecs::st_system_logic_update>; | ||
} | ||
|
||
REFL_AUTO(template((typename SystemType), (antara::gaming::lua::details::scripted_system<SystemType>))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.