Merge pull request #25 from BlackMATov/dev

Dev
This commit is contained in:
2019-05-14 21:35:24 +07:00
committed by GitHub
13 changed files with 244 additions and 14415 deletions

View File

@@ -3,6 +3,7 @@ shallow_clone: true
image: image:
- Visual Studio 2015 - Visual Studio 2015
- Visual Studio 2017 - Visual Studio 2017
- Visual Studio 2019 Preview
platform: platform:
- Win32 - Win32
- x64 - x64

View File

@@ -66,5 +66,16 @@ matrix:
after_success: ./scripts/upload_coverage.sh after_success: ./scripts/upload_coverage.sh
before_install: before_install:
- eval "${MATRIX_EVAL}" - eval "${MATRIX_EVAL}"
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then
brew update;
brew upgrade cmake;
brew install git-lfs;
fi
- if [ "$TRAVIS_OS_NAME" == 'linux' ]; then
mkdir $HOME/cmake;
export PATH="$HOME/cmake/bin:$PATH";
travis_retry wget -q https://cmake.org/files/v3.11/cmake-3.11.4-Linux-x86_64.sh;
sh cmake-3.11.4-Linux-x86_64.sh --prefix=$HOME/cmake --exclude-subdir --skip-license;
fi
script: script:
- ./scripts/build_all.sh - ./scripts/build_all.sh

View File

@@ -1,51 +1,26 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # 3.8 version is required for `cxx_std_14`
project(ecs) cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
# if(NOT DEFINED PROJECT_NAME)
# coverage mode set(BUILD_AS_STANDALONE ON)
#
option(ECS_BUILD_WITH_COVERAGE "Build with coverage" OFF)
if(ECS_BUILD_WITH_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
add_definitions(-DECS_BUILD_WITH_COVERAGE)
set(ECS_COVERAGE_FLAGS "--coverage")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${ECS_COVERAGE_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${ECS_COVERAGE_FLAGS}")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${ECS_COVERAGE_FLAGS}")
endif() endif()
# project(ecs.hpp)
# sanitizer mode
#
option(ECS_BUILD_WITH_SANITIZER "Build with sanitizer" OFF) add_library(${PROJECT_NAME} INTERFACE)
if(ECS_BUILD_WITH_SANITIZER AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")) target_include_directories(${PROJECT_NAME} INTERFACE headers)
add_definitions(-DECS_BUILD_WITH_SANITIZER) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14)
set(ECS_SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${ECS_SANITIZER_FLAGS}") if(BUILD_AS_STANDALONE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${ECS_SANITIZER_FLAGS}") option(BUILD_WITH_UNBENCH "Build with benchmarks" OFF)
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${ECS_SANITIZER_FLAGS}") if(BUILD_WITH_UNBENCH)
enable_testing()
add_subdirectory(unbench)
endif()
option(BUILD_WITH_UNTESTS "Build with unit tests" ON)
if(BUILD_WITH_UNTESTS)
enable_testing()
add_subdirectory(untests)
endif()
endif() endif()
#
# tests executable
#
file(GLOB test_sources "*.cpp" "*.hpp")
add_executable(${PROJECT_NAME} ${test_sources})
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:
/W4>
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wall -Wextra -Wpedantic>)
enable_testing()
add_test(${PROJECT_NAME} ${PROJECT_NAME})

View File

@@ -25,10 +25,17 @@
## Installation ## Installation
[ecs.hpp][ecs] is a single header library. All you need to do is copy the header file into your project and include this file: [ecs.hpp][ecs] is a header-only library. All you need to do is copy the headers files from `headers` directory into your project and include them:
```cpp ```cpp
#include "ecs.hpp" #include "ecs.hpp/ecs.hpp"
```
Also, you can add the root repository directory to your [cmake](https://cmake.org) project:
```cmake
add_subdirectory(external/ecs.hpp)
target_link_libraries(your_project_target ecs.hpp)
``` ```
## Basic usage ## Basic usage

14362
catch.hpp

File diff suppressed because it is too large Load Diff

View File

@@ -991,6 +991,14 @@ namespace ecs_hpp
T* find() noexcept; T* find() noexcept;
const T* find() const noexcept; const T* find() const noexcept;
T& operator*();
const T& operator*() const;
T* operator->() noexcept;
const T* operator->() const noexcept;
explicit operator bool() const noexcept;
private: private:
entity owner_; entity owner_;
}; };
@@ -1047,6 +1055,10 @@ namespace ecs_hpp
const T& get() const; const T& get() const;
const T* find() const noexcept; const T* find() const noexcept;
const T& operator*() const;
const T* operator->() const noexcept;
explicit operator bool() const noexcept;
private: private:
const_entity owner_; const_entity owner_;
}; };
@@ -1689,6 +1701,31 @@ namespace ecs_hpp
return detail::as_const(owner_).template find_component<T>(); return detail::as_const(owner_).template find_component<T>();
} }
template < typename T >
T& component<T>::operator*() {
return get();
}
template < typename T >
const T& component<T>::operator*() const {
return get();
}
template < typename T >
T* component<T>::operator->() noexcept {
return find();
}
template < typename T >
const T* component<T>::operator->() const noexcept {
return find();
}
template < typename T >
component<T>::operator bool() const noexcept {
return exists();
}
template < typename T > template < typename T >
bool operator<(const component<T>& l, const component<T>& r) noexcept { bool operator<(const component<T>& l, const component<T>& r) noexcept {
return l.owner() < r.owner(); return l.owner() < r.owner();
@@ -1751,6 +1788,21 @@ namespace ecs_hpp
return detail::as_const(owner_).template find_component<T>(); return detail::as_const(owner_).template find_component<T>();
} }
template < typename T >
const T& const_component<T>::operator*() const {
return get();
}
template < typename T >
const T* const_component<T>::operator->() const noexcept {
return find();
}
template < typename T >
const_component<T>::operator bool() const noexcept {
return exists();
}
template < typename T > template < typename T >
bool operator<(const const_component<T>& l, const const_component<T>& r) noexcept { bool operator<(const const_component<T>& l, const const_component<T>& r) noexcept {
return l.owner() < r.owner(); return l.owner() < r.owner();

View File

@@ -4,7 +4,7 @@ set -e
BUILD_DIR=`dirname "$BASH_SOURCE"`/../build BUILD_DIR=`dirname "$BASH_SOURCE"`/../build
mkdir -p $BUILD_DIR/coverage mkdir -p $BUILD_DIR/coverage
cd $BUILD_DIR/coverage cd $BUILD_DIR/coverage
cmake -DCMAKE_BUILD_TYPE=Debug -DECS_BUILD_WITH_COVERAGE=ON ../.. cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_WITH_COVERAGE=ON ../..
cmake --build . -- -j8 cmake --build . -- -j8
lcov -d . -z lcov -d . -z

34
unbench/CMakeLists.txt Normal file
View File

@@ -0,0 +1,34 @@
# 3.11 version is required for `FetchContent`
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(ecs.hpp.unbench)
#
# google benchmark
#
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
include(FetchContent)
FetchContent_Declare(
gbench
GIT_REPOSITORY https://github.com/google/benchmark)
FetchContent_GetProperties(gbench)
if(NOT gbench_POPULATED)
FetchContent_Populate(gbench)
add_subdirectory(${gbench_SOURCE_DIR} ${gbench_BINARY_DIR})
endif()
#
# benchmark executable
#
file(GLOB UNBENCH_SOURCES "*.cpp" "*.hpp")
add_executable(${PROJECT_NAME} ${UNBENCH_SOURCES})
target_link_libraries(${PROJECT_NAME}
benchmark_main
ecs.hpp)
add_test(${PROJECT_NAME} ${PROJECT_NAME})

13
unbench/bench_base.hpp Normal file
View File

@@ -0,0 +1,13 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/ecs.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include <benchmark/benchmark.h>
namespace ecs_hpp_unbench
{
}

View File

@@ -0,0 +1,11 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/ecs.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include "bench_base.hpp"
using namespace ecs_hpp_unbench;
#include "ecs.hpp"
namespace ecs = ecs_hpp;

39
untests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,39 @@
# 3.11 version is required for `FetchContent`
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(flat.hpp.untests)
set(CATCH_BUILD_TESTING OFF CACHE BOOL "" FORCE)
include(FetchContent)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/catch2)
FetchContent_GetProperties(catch2)
if(NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
endif()
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
if(BUILD_WITH_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
set(COVERAGE_FLAGS "--coverage")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
endif()
file(GLOB UNTESTS_SOURCES "*.cpp" "*.hpp")
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
target_link_libraries(${PROJECT_NAME}
Catch2
ecs.hpp)
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:
/W4>
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wall -Wextra -Wpedantic>)
add_test(${PROJECT_NAME} ${PROJECT_NAME})

View File

@@ -1,9 +1,9 @@
/******************************************************************************* /*******************************************************************************
* This file is part of the "https://github.com/blackmatov/ecs.hpp" * This file is part of the "https://github.com/blackmatov/ecs.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md * For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018 Matvey Cherevko * Copyright (C) 2018-2019 Matvey Cherevko
******************************************************************************/ ******************************************************************************/
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_FAST_COMPILE #define CATCH_CONFIG_FAST_COMPILE
#include "catch.hpp" #include <catch2/catch.hpp>

View File

@@ -5,9 +5,9 @@
******************************************************************************/ ******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE #define CATCH_CONFIG_FAST_COMPILE
#include "catch.hpp" #include <catch2/catch.hpp>
#include "ecs.hpp" #include <ecs.hpp/ecs.hpp>
namespace ecs = ecs_hpp; namespace ecs = ecs_hpp;
namespace namespace
@@ -518,6 +518,54 @@ TEST_CASE("registry") {
REQUIRE_FALSE(c1.remove()); REQUIRE_FALSE(c1.remove());
} }
{
using namespace ecs::detail;
ecs::registry w;
ecs::entity e1 = w.create_entity();
ecs::component<position_c> c1 = w.wrap_component<position_c>(e1);
ecs::const_component<position_c> c2 = w.wrap_component<position_c>(e1);
REQUIRE_FALSE(c1);
REQUIRE_FALSE(as_const(c1));
REQUIRE_FALSE(c2);
REQUIRE_FALSE(as_const(c2));
REQUIRE_THROWS_AS(*c1, std::logic_error);
REQUIRE_THROWS_AS(*as_const(c1), std::logic_error);
REQUIRE_THROWS_AS(*c2, std::logic_error);
REQUIRE_THROWS_AS(*as_const(c2), std::logic_error);
c1.assign(1,2);
REQUIRE(c1);
REQUIRE(as_const(c1));
REQUIRE(c2);
REQUIRE(as_const(c2));
REQUIRE(*c1 == position_c(1,2));
REQUIRE(*as_const(c1) == position_c(1,2));
REQUIRE(*c2 == position_c(1,2));
REQUIRE(*as_const(c2) == position_c(1,2));
REQUIRE(c1->x == 1);
REQUIRE(c1->y == 2);
REQUIRE(as_const(c1)->x == 1);
REQUIRE(as_const(c1)->y == 2);
REQUIRE(c2->x == 1);
REQUIRE(c2->y == 2);
REQUIRE(as_const(c2)->x == 1);
REQUIRE(as_const(c2)->y == 2);
c1.remove();
REQUIRE_FALSE(c1);
REQUIRE_FALSE(as_const(c1));
REQUIRE_FALSE(c2);
REQUIRE_FALSE(as_const(c2));
}
} }
SECTION("prototypes") { SECTION("prototypes") {
{ {