-
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(box2d): add a minimal box2d system (#71)
- Loading branch information
Showing
8 changed files
with
183 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 () |
32 changes: 32 additions & 0 deletions
32
modules/box2d/antara/gaming/box2d/antara.box2d.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,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 <doctest/doctest.h> | ||
#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(); | ||
} | ||
} | ||
} |
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,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 <doctest/doctest.h> |
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,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); | ||
} | ||
} |
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,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 <Box2D/Box2D.h> | ||
#include <entt/entity/registry.hpp> | ||
#include <entt/signal/dispatcher.hpp> | ||
#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<box2d_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)); |