Skip to content

Commit

Permalink
feat(blockchain+log): add logger and basis blockchain module
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Nov 6, 2019
1 parent 7365f38 commit 985c2be
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 15 deletions.
18 changes: 17 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ FetchContent_Declare(
URL https://github.com/skypjack/entt/archive/master.zip
)

FetchContent_Declare(
loguru
URL https://github.com/emilk/loguru/archive/v2.1.0.zip
)

FetchContent_Declare(
fmt
URL https://github.com/fmtlib/fmt/releases/download/6.0.0/fmt-6.0.0.zip
)

FetchContent_Declare(
doom_st
URL https://github.com/doom/strong_type/archive/1.0.2.tar.gz
Expand Down Expand Up @@ -89,7 +99,7 @@ if (USE_SDL_ANTARA_WRAPPER)
)
endif ()

FetchContent_MakeAvailable(doctest entt doom_st expected range-v3 refl-cpp doom_meta nlohmann_json joboccara-pipes)
FetchContent_MakeAvailable(doctest entt doom_st expected range-v3 refl-cpp doom_meta nlohmann_json joboccara-pipes loguru fmt)
if (USE_SFML_ANTARA_WRAPPER)
FetchContent_MakeAvailable(SFML)
endif ()
Expand All @@ -112,6 +122,12 @@ if (USE_SDL_ANTARA_WRAPPER)
)
endif ()

add_library(antara_log INTERFACE)
target_sources(antara_log INTERFACE ${loguru_SOURCE_DIR}/loguru.cpp)
target_include_directories(antara_log INTERFACE ${loguru_SOURCE_DIR})
target_link_libraries(antara_log INTERFACE fmt::fmt)
add_library(antara::log ALIAS antara_log)

add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR})
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
Expand Down
1 change: 1 addition & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_subdirectory(geometry)
add_subdirectory(ecs)
add_subdirectory(collisions)
add_subdirectory(resources)
add_subdirectory(blockchain)
add_subdirectory(scenes)
add_subdirectory(world)

Expand Down
38 changes: 38 additions & 0 deletions modules/blockchain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
add_library(antara_nspv STATIC)
target_sources(antara_nspv PRIVATE antara/gaming/blockchain/nspv.system.cpp)
target_include_directories(antara_nspv PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_nspv PUBLIC antara::default_settings antara::ecs)
add_library(antara::nspv ALIAS antara_nspv)

if (ANTARA_BUILD_UNIT_TESTS)
##! antara blockchain tests
add_executable(antara_blockchain_tests)
target_link_libraries(antara_blockchain_tests PRIVATE doctest PUBLIC antara::nspv)
target_sources(antara_blockchain_tests PRIVATE
antara/gaming/blockchain/antara.blockchain.tests.cpp
antara/gaming/blockchain/nspv.system.tests.cpp)
set_target_properties(antara_blockchain_tests
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/unit_tests"
)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets DESTINATION ${CMAKE_BINARY_DIR}/bin/unit_tests/nspv/)


target_enable_coverage(antara_blockchain_tests)
target_enable_tsan(antara_blockchain_tests)
target_enable_asan(antara_blockchain_tests)
target_enable_ubsan(antara_blockchain_tests)

if (EMSCRIPTEN)
message(STATUS "Emscripten detected")
if (ENABLE_HTML_COMPILATION)
message(STATUS "Html compilation enabled")
set_target_properties(antara_blockchain_tests PROPERTIES LINK_FLAGS "-s FORCE_FILESYSTEM=1 -s EXIT_RUNTIME=1"
SUFFIX ".html")
else ()
message(STATUS "Local js compilation")
set_target_properties(antara_blockchain_tests PROPERTIES LINK_FLAGS "-s FORCE_FILESYSTEM=1 -s NODERAWFS=1 -s EXIT_RUNTIME=1")
endif ()
endif ()
endif ()
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>
21 changes: 21 additions & 0 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/******************************************************************************
* 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/blockchain/nspv.system.hpp>

namespace antara::gaming::blockchain
{
}
40 changes: 40 additions & 0 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/******************************************************************************
* 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 <filesystem>
#include <entt/entity/registry.hpp>
#include <antara/gaming/core/real.path.hpp>
#include <antara/gaming/ecs/system.hpp>

namespace antara::gaming::blockchain {
class nspv final : public ecs::logic_update_system<nspv> {
public:
nspv(entt::registry &registry,
std::filesystem::path tools_path = antara::gaming::core::assets_real_path() / "tools") noexcept
: system(registry), tools_path_(std::move(tools_path)) {
this->disable();
}

void update() noexcept final {}

private:
std::filesystem::path tools_path_;
};
}

REFL_AUTO(type(antara::gaming::blockchain::nspv))
31 changes: 31 additions & 0 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.tests.cpp
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 <doctest/doctest.h>
#include <antara/gaming/ecs/system.manager.hpp>
#include "nspv.system.hpp"

namespace antara::gaming::blockchain::tests
{
TEST_CASE("nspv system creation")
{
entt::registry entity_registry;
[[ maybe_unused ]] entt::dispatcher& dispatcher{entity_registry.set<entt::dispatcher>()};
antara::gaming::ecs::system_manager mgr{entity_registry};

auto& nspv_system = mgr.create_system<blockchain::nspv>(std::filesystem::current_path() / "nspv/assets/tools");
}
}
Empty file.
2 changes: 1 addition & 1 deletion modules/world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
add_library(antara_world_shared_sources STATIC)
target_sources(antara_world_shared_sources PRIVATE antara/gaming/world/world.app.cpp)
target_include_directories(antara_world_shared_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_world_shared_sources PUBLIC antara::config antara::core antara::ecs)
target_link_libraries(antara_world_shared_sources PUBLIC antara::config antara::core antara::ecs antara::log)
if (EMSCRIPTEN)
if (ENABLE_HTML_COMPILATION)
target_compile_definitions(antara_world_shared_sources PUBLIC EMSCRIPTEN_ONLY_WEB)
Expand Down
28 changes: 16 additions & 12 deletions modules/world/antara/gaming/world/world.app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@
#include <emscripten.h>
#endif

#define LOGURU_USE_FMTLIB 1

#include <loguru.hpp>
#include "antara/gaming/core/real.path.hpp"
#include "antara/gaming/config/config.loading.hpp"
#include "antara/gaming/config/config.game.maker.hpp"
#include "antara/gaming/event/start.game.hpp"
#include "antara/gaming/world/world.app.hpp"

//LCOV_EXCL_START
void emscripten_antara_loop(void *world)
{
void emscripten_antara_loop(void *world) {
static_cast<antara::gaming::world::app *>(world)->process_one_frame();
}
//LCOV_EXCL_STOP
namespace antara::gaming::world
{
namespace antara::gaming::world {
//! Constructor
app::app(std::string config_maker_name) noexcept
{
app::app(std::string config_maker_name) noexcept {
LOG_SCOPE_FUNCTION(INFO);
auto cfg_maker = config::load_configuration<graphics::canvas_2d>(core::assets_real_path() / "config",
std::move(config_maker_name));
auto &canvas_2d_cmp = this->entity_registry_.set<graphics::canvas_2d>(cfg_maker);
Expand All @@ -43,8 +44,8 @@ namespace antara::gaming::world
}

//! Public callbacks
void app::receive_quit_game(const event::quit_game &evt) noexcept
{
void app::receive_quit_game(const event::quit_game &evt) noexcept {
LOG_SCOPE_FUNCTION(INFO);
this->is_running_ = false;
this->game_return_value_ = evt.return_value_;
//LCOV_EXCL_START
Expand All @@ -54,8 +55,8 @@ namespace antara::gaming::world
//LCOV_EXCL_STOP
}

int app::run() noexcept
{
int app::run() noexcept {
LOG_SCOPE_FUNCTION(INFO);
if (not system_manager_.nb_systems()) {
return this->game_return_value_;
}
Expand All @@ -74,8 +75,11 @@ namespace antara::gaming::world
return this->game_return_value_;
}

void app::process_one_frame()
{
void app::process_one_frame() {
this->system_manager_.update();
}

app::~app() noexcept {
LOG_SCOPE_FUNCTION(INFO);
}
}
2 changes: 1 addition & 1 deletion modules/world/antara/gaming/world/world.app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace antara::gaming::world
{
public:
app(std::string config_maker_name = "game.config.maker.json") noexcept;

~app() noexcept;
//! Public callbacks
void receive_quit_game(const event::quit_game &evt) noexcept;
int run() noexcept;
Expand Down

0 comments on commit 985c2be

Please sign in to comment.