Skip to content

Commit

Permalink
feat(lua): working on lua module (#37)
Browse files Browse the repository at this point in the history
* feat(lua): working on lua module

* feat(lua): working on lua module

* feat(lua): working on lua module

* feat(lua): working on lua module

* feat(lua): working on lua module

* feat(lua): add more scripting

* feat(lua): add more scripting

* feat(refl): using safe.refl.hpp

* improvements: coverage

* feat(lua): add more unit tests

* feat(lua): add keyboard enum

* feat(lua): add load script functionality

* fix(windows): compilation

* feat(lua): add scripted entities

* feat(lua): add update function

* feat(lua): add register_component basis

* feat(lua): add more function on components

* feat(lua): add more function on components

* fix: compilation

* feat(setup): update CI

* feat(setup): update CI

* feat(setup): update CI

* feat(lua): update path update

* fix(windows): runtime lua

* fix: fix bug with removing directories

* fix: use after free sanitizer

* fix: ubsan

* feat(lua): add for_each runtime
  • Loading branch information
Milerius authored Sep 21, 2019
1 parent 15be47e commit 1a3c010
Show file tree
Hide file tree
Showing 31 changed files with 1,029 additions and 49 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ endif ()

cmake_minimum_required(VERSION 3.14)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_VERBOSE_MAKEFILE on)

file(STRINGS "VERSION.md" VERSION_NB)

project(antara-gaming-sdk
VERSION ${VERSION_NB}
DESCRIPTION "Blockchain gaming sdk"
LANGUAGES CXX)
DESCRIPTION "Blockchain gaming sdk")

if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(FATAL_ERROR "Only Clang is supported (minimum LLVM 8.0)")
endif ()

option(USE_SFML_ANTARA_WRAPPER "Use SFML antara wrapper" OFF)
option(USE_LUA_ANTARA_WRAPPER "Use LUA antara wrapper" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(antara)

Expand Down
2 changes: 1 addition & 1 deletion CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DUSE_SFML_ANTARA_WRAPPER=ON",
"cmakeCommandArgs": "-DUSE_SFML_ANTARA_WRAPPER=ON -DUSE_LUA_ANTARA_WRAPPER=ON",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64" ],
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ init:
before_build:
- mkdir build
- cd build
- cmake ../ -G "%GENERATOR%" -A %platform% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -T "ClangCl" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DANTARA_BUILD_EXAMPLES=ON -DUSE_SFML_ANTARA_WRAPPER=ON
- cmake ../ -G "%GENERATOR%" -A %platform% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -T "ClangCl" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_EXAMPLES=ON -DUSE_SFML_ANTARA_WRAPPER=ON

build_script:
- cmake --build . --config %BUILD_TYPE%
Expand Down
5 changes: 5 additions & 0 deletions ci/travis_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ function build() {
fi

options+=' -DANTARA_BUILD_EXAMPLES=ON'
options+=' -DUSE_LUA_ANTARA_WRAPPER=ON'
echo "result -> ${cmd} ${options} ../"
${cmd} ${options} ../
cmake --build . --config ${BUILD_TYPE} || travis_terminate 1
ls -R bin/unit_tests
}

function run_test() {
cd ${TRAVIS_BUILD_DIR}/cmake-build-${BUILD_TYPE}/bin/unit_tests
pwd
ls -R .
if [[ "${EMSCRIPTEN_WEB}" == "ON" ]]; then
for i in *_tests*.js; do node ${i} --reporters=xml --out=${i}-result.xml -s || true; done;
else
Expand All @@ -61,6 +65,7 @@ function run_coverage() {
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/modules/config/antara/gaming/config/*.tests.*" -o coverage.info
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/modules/core/antara/gaming/core/*.tests.*" -o coverage.info
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/modules/ecs/antara/gaming/ecs/*.tests.*" -o coverage.info
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/modules/lua/antara/gaming/lua/*.tests.*" -o coverage.info
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/modules/timer/antara/gaming/timer/*.tests.*" -o coverage.info
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/modules/world/antara/gaming/world/*.tests.*" -o coverage.info
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/modules/event/antara/gaming/event/*.tests.*" -o coverage.info
Expand Down
33 changes: 31 additions & 2 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,46 @@ FetchContent_Declare(
URL https://github.com/veselink1/refl-cpp/archive/master.zip
)

if (USE_LUA_ANTARA_WRAPPER)
FetchContent_Declare(
lua
URL https://github.com/lua/lua/archive/master.zip
)

FetchContent_Declare(
sol2
URL https://github.com/ThePhD/sol2/archive/develop.zip
)
endif ()

if (USE_SFML_ANTARA_WRAPPER)
FetchContent_Declare(
SFML
URL https://github.com/Milerius/SFML/archive/patch-1.zip
)
endif()
endif ()

FetchContent_MakeAvailable(doctest entt doom_st expected range-v3 refl-cpp doom_meta nlohmann_json)
if (USE_SFML_ANTARA_WRAPPER)
FetchContent_MakeAvailable(SFML)
endif()
endif ()

if (USE_LUA_ANTARA_WRAPPER)
FetchContent_MakeAvailable(lua sol2)
add_library(lua_lib STATIC)
target_include_directories(lua_lib PUBLIC ${lua_SOURCE_DIR})
file(GLOB SRC_FILES ${lua_SOURCE_DIR}/*.c)
list(REMOVE_ITEM SRC_FILES "${lua_SOURCE_DIR}/onelua.c")
list(REMOVE_ITEM SRC_FILES "${lua_SOURCE_DIR}/ltests.c")
message(STATUS "lua_src -> ${SRC_FILES}")
target_sources(lua_lib PRIVATE ${SRC_FILES})

target_link_libraries(lua_lib PRIVATE ${CMAKE_DL_LIBS})
if (UNIX)
target_link_libraries(lua_lib PRIVATE m)
endif ()
add_library(antara::lua_lib ALIAS lua_lib)
endif ()

add_library(refl-cpp INTERFACE)
target_include_directories(refl-cpp INTERFACE ${refl-cpp_SOURCE_DIR})
Expand Down
8 changes: 4 additions & 4 deletions examples/sfml/basis-draft/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class game_scene final : public antara::gaming::scenes::base_scene
sf::Text &txt = txt_cmp.drawable;
txt.setFillColor(sf::Color::Blue);
txt.setOrigin(txt.getLocalBounds().width / 2.0f, txt.getLocalBounds().height / 2.0f);
this->entity_registry_.assign<antara::gaming::ecs::component_position>(dummy_entity,
this->entity_registry_.assign<antara::gaming::ecs::component::position>(dummy_entity,
static_cast<float>(window_info.width) /
2.f,
static_cast<float>(window_info.height) /
2.f);
entity_registry_.assign<entt::tag<"game_scene"_hs>>(dummy_entity);
this->entity_registry_.assign<antara::gaming::ecs::layer<0>>(dummy_entity);
this->entity_registry_.assign<antara::gaming::ecs::component::layer<0>>(dummy_entity);
}

void update() noexcept final
Expand Down Expand Up @@ -102,13 +102,13 @@ class intro_scene final : public antara::gaming::scenes::base_scene
sf::Text &txt = txt_cmp.drawable;
txt.setFillColor(sf::Color::Green);
txt.setOrigin(txt.getLocalBounds().width / 2.0f, txt.getLocalBounds().height / 2.0f);
this->entity_registry_.assign<antara::gaming::ecs::component_position>(dummy_entity,
this->entity_registry_.assign<antara::gaming::ecs::component::position>(dummy_entity,
static_cast<float>(window_info.width) /
2.f,
static_cast<float>(window_info.height) /
2.f);
entity_registry_.assign<entt::tag<"intro_scene"_hs>>(dummy_entity);
this->entity_registry_.assign<antara::gaming::ecs::layer<0>>(dummy_entity);
this->entity_registry_.assign<antara::gaming::ecs::component::layer<0>>(dummy_entity);
}

void update() noexcept final
Expand Down
4 changes: 4 additions & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ add_subdirectory(ecs)
add_subdirectory(scenes)
add_subdirectory(world)

if (USE_LUA_ANTARA_WRAPPER)
add_subdirectory(lua)
endif()

if (USE_SFML_ANTARA_WRAPPER)
add_subdirectory(sfml)
endif()
2 changes: 1 addition & 1 deletion modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
add_library(antara_core_shared_sources STATIC)
target_sources(antara_core_shared_sources PRIVATE antara/gaming/core/real.path.cpp)
target_include_directories(antara_core_shared_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_core_shared_sources PUBLIC antara::default_settings)
target_link_libraries(antara_core_shared_sources PUBLIC antara::default_settings EnTT antara::refl-cpp)
add_library(antara::core ALIAS antara_core_shared_sources)

##! antara core tests
Expand Down
28 changes: 28 additions & 0 deletions modules/core/antara/gaming/core/reflection.entity.registry.hpp
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. *
* *
******************************************************************************/

#pragma once

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#include <refl.hpp>

#pragma clang diagnostic pop

#include <entt/entity/registry.hpp>

REFL_AUTO(type(entt::registry));
24 changes: 24 additions & 0 deletions modules/core/antara/gaming/core/safe.refl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/******************************************************************************
* 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

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#include <refl.hpp>

#pragma clang diagnostic pop
2 changes: 1 addition & 1 deletion modules/ecs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target_sources(antara_ecs_shared_sources PRIVATE
antara/gaming/ecs/system.manager.cpp
antara/gaming/ecs/component.position.cpp)
target_include_directories(antara_ecs_shared_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_ecs_shared_sources PUBLIC EnTT strong_type expected range-v3 antara::refl-cpp antara::default_settings antara::timer antara::event doom::meta)
target_link_libraries(antara_ecs_shared_sources PUBLIC antara::core EnTT strong_type expected range-v3 antara::default_settings antara::timer antara::event doom::meta)
add_library(antara::ecs ALIAS antara_ecs_shared_sources)

##! antara ecs tests
Expand Down
39 changes: 39 additions & 0 deletions modules/ecs/antara/gaming/ecs/all.components.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/******************************************************************************
* 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 <meta/sequence/list.hpp>
#include "antara/gaming/ecs/component.layer.hpp"
#include "antara/gaming/ecs/component.position.hpp"

namespace antara::gaming::ecs::component
{
using components_list = doom::meta::list<
layer_0,
layer_1,
layer_2,
layer_3,
layer_4,
layer_5,
layer_6,
layer_7,
layer_8,
layer_9,
layer_10,
layer_11,
position>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ namespace antara::gaming::ecs::tests
{
TEST_CASE("component position is default constructible")
{
component_position c_pos{};
component::position c_pos{};
CHECK_EQ(c_pos.pos_x, 0.0f);
CHECK_EQ(c_pos.pos_y, 0.0f);
}

TEST_CASE("component position constructor with value")
{
component_position c_pos{42.0f, 27.0f};
component::position c_pos{42.0f, 27.0f};
CHECK_EQ(c_pos.pos_x, 42.0f);
CHECK_EQ(c_pos.pos_y, 27.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ namespace antara::gaming::ecs::tests
CHECK_FALSE(manager.disable_systems<logic_concrete_system, pre_concrete_system>());
CHECK_EQ(0ull, manager.update());
CHECK_EQ(0ull, manager.nb_systems());
manager.get_systems<logic_concrete_system, pre_concrete_system>();
c_mgr.get_systems<logic_concrete_system, pre_concrete_system>();
//manager.get_systems<logic_concrete_system, pre_concrete_system>(); //UBSAN
//c_mgr.get_systems<logic_concrete_system, pre_concrete_system>(); // UBSAN
}
}
}
6 changes: 1 addition & 5 deletions modules/ecs/antara/gaming/ecs/antara.ecs.system.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include <string>
#include <doctest/doctest.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <refl.hpp>
#pragma clang diagnostic pop

#include "antara/gaming/core/safe.refl.hpp"
#include "antara/gaming/ecs/base.system.hpp"
#include "antara/gaming/ecs/system.hpp"

Expand Down
30 changes: 28 additions & 2 deletions modules/ecs/antara/gaming/ecs/component.layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,38 @@

#include <cstddef>

namespace antara::gaming::ecs
namespace antara::gaming::ecs::component
{
inline constexpr std::size_t max_layer = 12ull;

template<std::size_t N>
struct layer
{
};
}

using layer_0 = layer<0>;
using layer_1 = layer<1>;
using layer_2 = layer<2>;
using layer_3 = layer<3>;
using layer_4 = layer<4>;
using layer_5 = layer<5>;
using layer_6 = layer<6>;
using layer_7 = layer<7>;
using layer_8 = layer<8>;
using layer_9 = layer<9>;
using layer_10 = layer<10>;
using layer_11 = layer<11>;
}

REFL_AUTO(type(antara::gaming::ecs::component::layer_0))
REFL_AUTO(type(antara::gaming::ecs::component::layer_1))
REFL_AUTO(type(antara::gaming::ecs::component::layer_2))
REFL_AUTO(type(antara::gaming::ecs::component::layer_3))
REFL_AUTO(type(antara::gaming::ecs::component::layer_4))
REFL_AUTO(type(antara::gaming::ecs::component::layer_5))
REFL_AUTO(type(antara::gaming::ecs::component::layer_6))
REFL_AUTO(type(antara::gaming::ecs::component::layer_7))
REFL_AUTO(type(antara::gaming::ecs::component::layer_8))
REFL_AUTO(type(antara::gaming::ecs::component::layer_9))
REFL_AUTO(type(antara::gaming::ecs::component::layer_10))
REFL_AUTO(type(antara::gaming::ecs::component::layer_11))
6 changes: 3 additions & 3 deletions modules/ecs/antara/gaming/ecs/component.position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

#include "antara/gaming/ecs/component.position.hpp"

namespace antara::gaming::ecs
namespace antara::gaming::ecs::component
{
component_position::component_position(float pos_x_, float pos_y_) noexcept : pos_x(pos_x_), pos_y(pos_y_)
position::position(float pos_x_, float pos_y_) noexcept : pos_x(pos_x_), pos_y(pos_y_)
{

}

component_position::component_position() noexcept : pos_x(0.f), pos_y(0.f)
position::position() noexcept : pos_x(0.f), pos_y(0.f)
{

}
Expand Down
Loading

0 comments on commit 1a3c010

Please sign in to comment.