Skip to content

Commit

Permalink
Merge pull request #7 from KomodoPlatform/roman_dev
Browse files Browse the repository at this point in the history
feat(ecs): working on ecs module
  • Loading branch information
Milerius authored Sep 13, 2019
2 parents 655dead + ff8213a commit 784826c
Show file tree
Hide file tree
Showing 11 changed files with 708 additions and 61 deletions.
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ matrix:
packages: [clang-8, libstdc++-8-dev]
env: [CXX=clang++-8, CC=clang-8, BUILD_TYPE=Debug, DEFAULT_COMPILER=clang, WILL_COMPILE_CODE=ON, DEPLOY=ON, PIP=pip, UBSAN=ON]
- os: osx
osx_image: xcode10.2
osx_image: xcode11
sudo: true
env: [BUILD_TYPE=Release,
CLANG_VERSION=clang-8,
Expand All @@ -89,14 +89,12 @@ matrix:
RANLIB=llvm-ranlib,
LDFLAGS=-L/usr/local/opt/llvm/lib,
CPPFLAGS=-I/usr/local/opt/llvm/include,
PIP=pip3,
WILL_COMPILE_CODE=ON, DEFAULT_COMPILER=clang]
addons:
homebrew:
packages: [cmake,ninja,llvm,python3]
update: true
packages: [cmake,ninja,llvm]
- os: osx
osx_image: xcode10.2
osx_image: xcode11
sudo: true
env: [BUILD_TYPE=Debug,
CODE_COVERAGE=ON,
Expand All @@ -108,12 +106,10 @@ matrix:
RANLIB=llvm-ranlib,
LDFLAGS=-L/usr/local/opt/llvm/lib,
CPPFLAGS=-I/usr/local/opt/llvm/include,
PIP=pip3,
WILL_COMPILE_CODE=ON, DEFAULT_COMPILER=clang]
addons:
homebrew:
packages: [cmake,ninja,llvm,python3]
update: true
packages: [cmake,ninja,llvm]


install:
Expand Down
2 changes: 2 additions & 0 deletions ci/travis_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function run_coverage() {
lcov -d . -c -o coverage.info
lcov -r coverage.info "/usr*" -o coverage.info
lcov -r coverage.info "${TRAVIS_BUILD_DIR}/*.test.*" -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}/cmake-build-${BUILD_TYPE}/_deps/*" -o coverage.info
lcov -l coverage.info
bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
Expand Down
23 changes: 22 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,25 @@ FetchContent_Declare(
URL https://github.com/doom/strong_type/archive/1.0.2.tar.gz
)

FetchContent_MakeAvailable(doctest entt doom_st)

set(EXPECTED_ENABLE_TESTS OFF CACHE BOOL "Override option" FORCE)
FetchContent_Declare(
expected
URL https://github.com/TartanLlama/expected/archive/master.zip
)

FetchContent_Declare(
range-v3
URL https://github.com/ericniebler/range-v3/archive/master.zip
)

FetchContent_Declare(
refl-cpp
URL https://github.com/veselink1/refl-cpp/archive/master.zip
)

FetchContent_MakeAvailable(doctest entt doom_st expected range-v3 refl-cpp)

add_library(refl-cpp INTERFACE)
target_include_directories(refl-cpp INTERFACE ${refl-cpp_SOURCE_DIR})
add_library(antara::refl-cpp ALIAS refl-cpp)
7 changes: 4 additions & 3 deletions modules/ecs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## shared sources between the module and his unit tests
add_library(antara_ecs_shared_sources INTERFACE)
target_sources(antara_ecs_shared_sources INTERFACE antara/gaming/ecs/base.system.cpp)
target_sources(antara_ecs_shared_sources INTERFACE antara/gaming/ecs/base.system.cpp antara/gaming/ecs/system.manager.cpp)
target_include_directories(antara_ecs_shared_sources INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_ecs_shared_sources INTERFACE EnTT strong_type)
target_link_libraries(antara_ecs_shared_sources INTERFACE EnTT strong_type expected range-v3 antara::refl-cpp)
add_library(antara::ecs_shared_sources ALIAS antara_ecs_shared_sources)


Expand All @@ -15,7 +15,8 @@ add_library(antara::ecs ALIAS antara_ecs)
add_executable(antara_ecs_tests)
target_sources(antara_ecs_tests PUBLIC
antara/gaming/ecs/antara.ecs.tests.cpp
antara/gaming/ecs/antara.ecs.system.tests.cpp)
antara/gaming/ecs/antara.ecs.system.tests.cpp
antara/gaming/ecs/antara.ecs.system.manager.tests.cpp)
target_link_libraries(antara_ecs_tests PRIVATE doctest PUBLIC antara::ecs_shared_sources)
set_target_properties(antara_ecs_tests
PROPERTIES
Expand Down
138 changes: 138 additions & 0 deletions modules/ecs/antara/gaming/ecs/antara.ecs.system.manager.tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/******************************************************************************
* 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/system.hpp"
#include "antara/gaming/ecs/system.manager.hpp"

class logic_concrete_system final : public antara::gaming::ecs::logic_update_system<logic_concrete_system>
{
public:
logic_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

logic_concrete_system() = default;

void update() noexcept final
{

}

~logic_concrete_system() noexcept final = default;
};

class pre_concrete_system final : public antara::gaming::ecs::pre_update_system<pre_concrete_system>
{
public:
pre_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

pre_concrete_system() = default;

void update() noexcept final
{

}

~pre_concrete_system() noexcept final = default;
};

REFL_AUTO(type(logic_concrete_system))
REFL_AUTO(type(pre_concrete_system))

namespace antara::gaming::ecs::tests
{
TEST_SUITE ("system manager test suite")
{
entt::registry registry;
entt::dispatcher dispatcher;
system_manager manager{registry, dispatcher};
const system_manager &c_mgr = manager;
TEST_CASE ("add system")
{
CHECK_EQ(manager.nb_systems(), 0u);
manager.create_system<logic_concrete_system>();
CHECK(manager.has_system<logic_concrete_system>());
CHECK_EQ(manager.nb_systems(), 1u);
CHECK_EQ(manager.nb_systems(logic_concrete_system::get_system_type()), 1u);
manager.create_system<logic_concrete_system>();
CHECK_EQ(manager.nb_systems(), 1u);
CHECK_EQ(manager.nb_systems(logic_concrete_system::get_system_type()), 1u);
}

TEST_CASE("remove system")
{
CHECK_EQ(manager.nb_systems(), 1u);
CHECK(manager.mark_system<logic_concrete_system>());
manager.update();
CHECK_FALSE(manager.has_system<logic_concrete_system>());
CHECK_EQ(manager.nb_systems(), 0u);
CHECK_FALSE(manager.mark_system<logic_concrete_system>());
}

TEST_CASE("add multiple systems")
{
manager.load_systems<logic_concrete_system, pre_concrete_system>();
CHECK_EQ(manager.nb_systems(), 2u);
CHECK(manager.has_systems<logic_concrete_system, pre_concrete_system>());
}

TEST_CASE("update/enable/disable systems from specific type")
{
CHECK_EQ(manager.update_systems(pre_update), 1ull);
CHECK(manager.disable_system<pre_concrete_system>());
CHECK_EQ(manager.update_systems(pre_update), 0ull);
CHECK(manager.enable_system<pre_concrete_system>());

CHECK(manager.disable_systems<logic_concrete_system, pre_concrete_system>());
CHECK(manager.enable_systems<logic_concrete_system, pre_concrete_system>());
}

TEST_CASE("get single system")
{
auto &logic_system = manager.get_system<logic_concrete_system>();

const auto& c_logic_system = c_mgr.get_system<logic_concrete_system>();
CHECK_EQ(logic_system.get_name(), "logic_concrete_system");
CHECK_EQ(c_logic_system.get_name(), "logic_concrete_system");
}

TEST_CASE("get multiple systems")
{
auto&& [lgc_sys, pre_sys] = manager.get_systems<logic_concrete_system, pre_concrete_system>();
CHECK_EQ(lgc_sys.get_name(), "logic_concrete_system");
CHECK_EQ(pre_sys.get_name(), "pre_concrete_system");

auto&& [c_lgc_sys, c_pre_sys] = c_mgr.get_systems<logic_concrete_system, pre_concrete_system>();
CHECK_EQ(c_lgc_sys.get_name(), "logic_concrete_system");
CHECK_EQ(c_pre_sys.get_name(), "pre_concrete_system");
}

TEST_CASE("marked multiple systems")
{
CHECK(manager.has_systems<logic_concrete_system, pre_concrete_system>());
CHECK(manager.mark_systems<logic_concrete_system, pre_concrete_system>());
manager.update();
CHECK_FALSE(manager.has_systems<logic_concrete_system, pre_concrete_system>());
CHECK_FALSE(manager.enable_systems<logic_concrete_system, pre_concrete_system>());
CHECK_FALSE(manager.disable_systems<logic_concrete_system, pre_concrete_system>());
}
}
}
117 changes: 69 additions & 48 deletions modules/ecs/antara/gaming/ecs/antara.ecs.system.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,67 @@
* *
******************************************************************************/

#include <string>
#include <doctest/doctest.h>
#include <refl.hpp>
#include "antara/gaming/ecs/base.system.hpp"
#include "antara/gaming/ecs/system.hpp"

namespace antara::gaming::ecs::tests
{
class logic_concrete_system final : public logic_update_system<logic_concrete_system>
{
public:
logic_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

void update() noexcept final
{

}

~logic_concrete_system() noexcept final = default;
};

class pre_concrete_system final : public pre_update_system<pre_concrete_system>
{
public:
pre_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

void update() noexcept final
{

}

~pre_concrete_system() noexcept final = default;
};

class post_concrete_system final : public post_update_system<post_concrete_system>
{
public:
post_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

void update() noexcept final
{

}

~post_concrete_system() noexcept final = default;
};

TEST_SUITE ("antara-gaming ecs test suite")
{
TEST_CASE ("base system abstract object tests")
{
struct concrete_system : base_system
struct concrete_system final : base_system
{
concrete_system(entt::registry registry, entt::dispatcher dispatcher) : base_system(registry,
dispatcher)
Expand All @@ -42,6 +92,11 @@ namespace antara::gaming::ecs::tests
//!
}

[[nodiscard]] std::string get_name() const noexcept final
{
return "concrete_system";
}

~concrete_system() noexcept final = default;
};
concrete_system dummy_system{entt::registry{}, entt::dispatcher{}};
Expand Down Expand Up @@ -78,57 +133,15 @@ namespace antara::gaming::ecs::tests
auto data = dummy_system.get_user_data();
CHECK_EQ(*static_cast<int *>(data), 42);
}

SUBCASE("check class name") {
CHECK_EQ("concrete_system", dummy_system.get_name());
}
}

TEST_CASE ("system tests")
{
class logic_concrete_system : public logic_update_system<logic_concrete_system>
{
public:
logic_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

void update() noexcept final
{

}

~logic_concrete_system() noexcept final = default;
};

class pre_concrete_system : public pre_update_system<pre_concrete_system>
{
public:
pre_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

void update() noexcept final
{

}

~pre_concrete_system() noexcept final = default;
};

class post_concrete_system : public post_update_system<post_concrete_system>
{
public:
post_concrete_system(entt::registry &registry, entt::dispatcher &dispatcher) : system(registry, dispatcher)
{

}

void update() noexcept final
{

}

~post_concrete_system() noexcept final = default;
};
entt::registry registry;
entt::dispatcher dispatcher;
logic_concrete_system dummy_system{registry, dispatcher};
Expand Down Expand Up @@ -187,6 +200,14 @@ namespace antara::gaming::ecs::tests
pre_dummy_system.update();
post_dummy_system.update();
}

SUBCASE ("system name") {
CHECK_EQ(dummy_system.get_name(), "antara::gaming::ecs::tests::logic_concrete_system");
}
}
}
}
}

REFL_AUTO(type(antara::gaming::ecs::tests::logic_concrete_system))
REFL_AUTO(type(antara::gaming::ecs::tests::post_concrete_system))
REFL_AUTO(type(antara::gaming::ecs::tests::pre_concrete_system))
Loading

0 comments on commit 784826c

Please sign in to comment.