diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e40c6c37..7e7e0af5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -177,9 +177,9 @@ jobs: if: runner.os == 'Linux' || runner.os == 'macOS' run: | if [[ "${{matrix.name}}" == "ubuntu-18-04-emcc-latest-debug" ]]; then - cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC + cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON -DCMAKE_TOOLCHAIN_FILE=emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC else - cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON + cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON fi - name: Configure (Windows) @@ -187,7 +187,7 @@ jobs: ANTARA_BUILD_TYPE: ${{matrix.cmake_build_type}} if: runner.os == 'Windows' run: | - cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON + cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON - name: TSan (Linux) if: matrix.name == 'ubuntu-18-04-clang-8-debug-tsan' diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 422944c3..68ab00f9 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -45,6 +45,13 @@ FetchContent_Declare( URL https://github.com/veselink1/refl-cpp/archive/v0.5.2.zip ) +if (USE_BOX2D_ANTARA_WRAPPER) + FetchContent_Declare( + box2d + URL https://github.com/erincatto/Box2D/archive/master.zip + ) +endif() + if (USE_LUA_ANTARA_WRAPPER) FetchContent_Declare( lua @@ -69,6 +76,17 @@ if (USE_SFML_ANTARA_WRAPPER) FetchContent_MakeAvailable(SFML) endif () +if (USE_BOX2D_ANTARA_WRAPPER) + FetchContent_MakeAvailable(box2d) + add_library(Box2D STATIC) + file(GLOB_RECURSE BOX2D_SOURCES ${box2d_SOURCE_DIR}/Box2D/*.cpp) + message(STATUS "box2d sources: -> ${BOX2D_SOURCES}") + target_sources(Box2D PRIVATE ${BOX2D_SOURCES}) + target_include_directories(Box2D PUBLIC ${box2d_SOURCE_DIR}) + target_compile_features(Box2D PRIVATE cxx_std_11) + add_library(antara::box2d_wrapper ALIAS Box2D) +endif() + if (USE_LUA_ANTARA_WRAPPER) FetchContent_MakeAvailable(lua sol2) add_library(lua_lib STATIC) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 18c04702..e3de5c11 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -11,6 +11,10 @@ if (USE_LUA_ANTARA_WRAPPER) add_subdirectory(lua) endif() +if (USE_BOX2D_ANTARA_WRAPPER) + add_subdirectory(box2d) +endif() + if (USE_SFML_ANTARA_WRAPPER) add_subdirectory(sfml) endif() \ No newline at end of file diff --git a/modules/box2d/CMakeLists.txt b/modules/box2d/CMakeLists.txt new file mode 100644 index 00000000..938aebce --- /dev/null +++ b/modules/box2d/CMakeLists.txt @@ -0,0 +1,36 @@ +## shared sources between the module and his unit tests +add_library(antara_box2d_shared_sources STATIC) +target_sources(antara_box2d_shared_sources PRIVATE + antara/gaming/box2d/box2d.system.cpp) +target_include_directories(antara_box2d_shared_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(antara_box2d_shared_sources PUBLIC antara::default_settings antara::box2d_wrapper antara::ecs antara::timer antara::core) +add_library(antara::box2d ALIAS antara_box2d_shared_sources) + +if (ANTARA_BUILD_UNIT_TESTS) + ##! antara box2d tests + add_executable(antara_box2d_tests) + target_sources(antara_box2d_tests PUBLIC + antara/gaming/box2d/antara.box2d.tests.cpp + antara/gaming/box2d/antara.box2d.system.tests.cpp) + target_link_libraries(antara_box2d_tests PRIVATE doctest PUBLIC antara::box2d) + set_target_properties(antara_box2d_tests + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/unit_tests" + ) + target_enable_coverage(antara_box2d_tests) + target_enable_tsan(antara_box2d_tests) + target_enable_asan(antara_box2d_tests) + target_enable_ubsan(antara_box2d_tests) + + if (EMSCRIPTEN) + message(STATUS "Emscripten detected") + if (ENABLE_HTML_COMPILATION) + message(STATUS "Html compilation enabled") + set_target_properties(antara_box2d_tests PROPERTIES LINK_FLAGS "-s FORCE_FILESYSTEM=1 -s EXIT_RUNTIME=1" + SUFFIX ".html") + else () + message(STATUS "Local js compilation") + set_target_properties(antara_box2d_tests PROPERTIES LINK_FLAGS "-s FORCE_FILESYSTEM=1 -s NODERAWFS=1 -s EXIT_RUNTIME=1") + endif () + endif () +endif () \ No newline at end of file diff --git a/modules/box2d/antara/gaming/box2d/antara.box2d.system.tests.cpp b/modules/box2d/antara/gaming/box2d/antara.box2d.system.tests.cpp new file mode 100644 index 00000000..817ddf8a --- /dev/null +++ b/modules/box2d/antara/gaming/box2d/antara.box2d.system.tests.cpp @@ -0,0 +1,32 @@ +/****************************************************************************** + * 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 +#include "antara/gaming/box2d/box2d.system.hpp" + +namespace antara::gaming::box2d::tests +{ + TEST_SUITE ("box2d system tests suite") + { + entt::registry registry; + entt::dispatcher dispatcher; + box2d_system system{registry, dispatcher}; + TEST_CASE ("update system") + { + system.update(); + } + } +} \ No newline at end of file diff --git a/modules/box2d/antara/gaming/box2d/antara.box2d.tests.cpp b/modules/box2d/antara/gaming/box2d/antara.box2d.tests.cpp new file mode 100644 index 00000000..caa05e4d --- /dev/null +++ b/modules/box2d/antara/gaming/box2d/antara.box2d.tests.cpp @@ -0,0 +1,18 @@ +/****************************************************************************** + * 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. * + * * + ******************************************************************************/ + +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include \ No newline at end of file diff --git a/modules/box2d/antara/gaming/box2d/box2d.system.cpp b/modules/box2d/antara/gaming/box2d/box2d.system.cpp new file mode 100644 index 00000000..6718b2b3 --- /dev/null +++ b/modules/box2d/antara/gaming/box2d/box2d.system.cpp @@ -0,0 +1,31 @@ +/****************************************************************************** + * 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 "antara/gaming/timer/time.step.hpp" +#include "antara/gaming/box2d/box2d.system.hpp" + +namespace antara::gaming::box2d +{ + box2d_system::box2d_system(entt::registry ®istry, entt::dispatcher &dispatcher) noexcept : system(registry, dispatcher) + { + + } + + void box2d_system::update() noexcept + { + world_.Step(antara::gaming::timer::time_step::get_fixed_delta_time(), 8, 3); + } +} \ No newline at end of file diff --git a/modules/box2d/antara/gaming/box2d/box2d.system.hpp b/modules/box2d/antara/gaming/box2d/box2d.system.hpp new file mode 100644 index 00000000..c6ce4d36 --- /dev/null +++ b/modules/box2d/antara/gaming/box2d/box2d.system.hpp @@ -0,0 +1,41 @@ +/****************************************************************************** + * 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 +#include +#include +#include "antara/gaming/core/safe.refl.hpp" +#include "antara/gaming/ecs/system.hpp" + +namespace antara::gaming::box2d +{ + class box2d_system final : public ecs::logic_update_system + { + public: + //! Constructors + box2d_system(entt::registry ®istry, entt::dispatcher &dispatcher) noexcept; + + void update() noexcept final; + + private: + b2Vec2 gravity_{0.f, 9.8f}; + b2World world_{gravity_}; + }; +} + +REFL_AUTO(type(antara::gaming::box2d::box2d_system)); \ No newline at end of file