Skip to content

Commit

Permalink
feat: add gaia-ecs
Browse files Browse the repository at this point in the history
  • Loading branch information
abeimler committed Feb 21, 2024
1 parent 0d90653 commit 4dbc52d
Show file tree
Hide file tree
Showing 32 changed files with 888 additions and 4 deletions.
6 changes: 6 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ if(ENABLE_BENCHMARK_PICO_ECS)
add_subdirectory(benchmarks/pico-ecs-extended)
endif()

if(ENABLE_BENCHMARK_GAIA_ECS)
add_subdirectory(benchmarks/gaia-ecs-entities)
add_subdirectory(benchmarks/gaia-ecs)
add_subdirectory(benchmarks/gaia-ecs-extended)
endif()

if(ENABLE_BENCHMARK_OOP)
add_subdirectory(benchmarks/oop)
endif()
5 changes: 3 additions & 2 deletions benchmark/benchmarks/ExtendedECSBenchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,9 @@ class ExtendedECSBenchmark

public:
template <class Comp, class... Args>
inline static void dummy_each(Comp& comp, Args&&... /*args*/) {
((comp.x = {}));
inline static void dummy_each(Comp& comp, Args&&... args) {
benchmark::DoNotOptimize(comp);
(benchmark::DoNotOptimize(args), ...);
}

template <typename Iterable, typename Func>
Expand Down
15 changes: 15 additions & 0 deletions benchmark/benchmarks/gaia-ecs-entities/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(INCLUDE_DIR "include") # must be relative paths
# NOTE: rename project in "ecs-benchmark-myecs"
add_executable(
ecs-benchmark-gaia-ecs-entities
# NOTE: add new benchmarks here
GaiaEcsEntityBenchmarkSuite.cpp GaiaEcsEntityBenchmarkSuite.h)
target_include_directories(
ecs-benchmark-gaia-ecs-entities
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${INCLUDE_DIR}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${INCLUDE_DIR}>")
target_link_libraries(ecs-benchmark-gaia-ecs-entities PRIVATE project_warnings project_options)
target_link_libraries(ecs-benchmark-gaia-ecs-entities PRIVATE ecs-benchmark)

# @NOTE: add libs for example here
target_link_libraries(ecs-benchmark-gaia-ecs-entities PRIVATE ecs-benchmark-example-gaia-ecs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "GaiaEcsEntityBenchmarkSuite.h"

static ecs::benchmarks::gaia_ecs::GaiaEcsEntityBenchmarkSuite benchmark_suite;

ECS_ENTITY_BENCHMARKS(benchmark_suite)

/*
static void BM_CreateEntitiesInBulk(benchmark::State& state) {
benchmark_suite.BM_CreateEntitiesInBulk(state);
}
BENCHMARK(BM_CreateEntitiesInBulk)->Apply(ecs::benchmarks::base::BEDefaultArguments);
static void BM_CreateEmptyEntitiesInBulk(benchmark::State& state) {
benchmark_suite.BM_CreateEmptyEntitiesInBulk(state);
}
BENCHMARK(BM_CreateEmptyEntitiesInBulk)->Apply(ecs::benchmarks::base::BEDefaultArguments);
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef ECS_BENCHMARKS_GAIA_ECS_ENTITYBENCHMARK_H_
#define ECS_BENCHMARKS_GAIA_ECS_ENTITYBENCHMARK_H_

#include "EntityBenchmark.h"
#include "gaia-ecs/entities/EntityFactory.h"
#include <utility>


namespace ecs::benchmarks::gaia_ecs {

class GaiaEcsEntityBenchmarkSuite final
: public ecs::benchmarks::base::EntityBenchmark<"gaia-ecs", entities::EntityFactory> {
public:
GaiaEcsEntityBenchmarkSuite() = default;

explicit GaiaEcsEntityBenchmarkSuite(ecs::benchmarks::base::ESCBenchmarkOptions options)
: EntityBenchmark(std::move(options)) {}
};

} // namespace ecs::benchmarks::gaia_ecs

#endif // ECS_BENCHMARKS_GAIA_ECS_ENTITYBENCHMARK_H_
15 changes: 15 additions & 0 deletions benchmark/benchmarks/gaia-ecs-extended/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(INCLUDE_DIR "include") # must be relative paths
# NOTE: rename project in "ecs-benchmark-myecs"
add_executable(
ecs-benchmark-gaia-ecs-extended
# NOTE: add new benchmarks here
GaiaEcsBenchmarkSuite.cpp GaiaEcsBenchmarkSuite.h)
target_include_directories(
ecs-benchmark-gaia-ecs-extended
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${INCLUDE_DIR}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${INCLUDE_DIR}>")
target_link_libraries(ecs-benchmark-gaia-ecs-extended PRIVATE project_warnings project_options)
target_link_libraries(ecs-benchmark-gaia-ecs-extended PRIVATE ecs-benchmark)

# @NOTE: add libs for example here
target_link_libraries(ecs-benchmark-gaia-ecs-extended PRIVATE ecs-benchmark-example-gaia-ecs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "GaiaEcsBenchmarkSuite.h"

static ecs::benchmarks::gaia_ecs::GaiaEcsBenchmarkSuite benchmark_suite({
.add_more_complex_system = true,
.version = std::nullopt,
});

ECS_COMPLEX_UPDATE_SYSTEMS_BENCHMARKS(benchmark_suite)
ECS_ITERATE_COMPONENTS_BENCHMARKS(benchmark_suite)
69 changes: 69 additions & 0 deletions benchmark/benchmarks/gaia-ecs-extended/GaiaEcsBenchmarkSuite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef ECS_BENCHMARKS_GAIABENCHMARK_H_
#define ECS_BENCHMARKS_GAIABENCHMARK_H_

#include "ExtendedECSBenchmark.h"
#include "gaia-ecs/GaiaEcsApplication.h"
#include "gaia-ecs/entities/EntityFactory.h"
#include "gaia-ecs/entities/HeroMonsterEntityFactory.h"
#include "gaia-ecs/systems/DataSystem.h"
#include "gaia-ecs/systems/MoreComplexSystem.h"
#include "gaia-ecs/systems/MovementSystem.h"
#include <utility>

namespace ecs::benchmarks::gaia_ecs {

class GaiaEcsBenchmarkSuite final
: public ecs::benchmarks::base::ExtendedECSBenchmark<"gaia-ecs", GaiaEcsApplication, entities::EntityFactory,
entities::HeroMonsterEntityFactory> {
public:
GaiaEcsBenchmarkSuite() = default;

explicit GaiaEcsBenchmarkSuite(ecs::benchmarks::base::ESCBenchmarkOptions options)
: ExtendedECSBenchmark(std::move(options)) {}

void BM_IterateSingleComponent(benchmark::State& state) {
using ComponentOne = ecs::benchmarks::base::components::PositionComponent;

BM_IterateSingleComponentWithPreCreatedView(
state,
[](auto& world) {
return world.query().template all<ComponentOne&>();
},
[&](ComponentOne& comp) {
dummy_each(comp);
});
}

void BM_IterateTwoComponents(benchmark::State& state) {
using ComponentOne = ecs::benchmarks::base::components::PositionComponent;
using ComponentTwo = ecs::benchmarks::base::components::VelocityComponent;

BM_IterateTwoComponentsWithPreCreatedView(
state,
[](auto& world) {
return world.query().template all<ComponentOne&, ComponentTwo&>();
},
[&](ComponentOne& comp, ComponentTwo& comp2) {
dummy_each(comp, comp2);
});
}

void BM_IterateThreeComponentsWithMixedEntities(benchmark::State& state) {
using ComponentOne = ecs::benchmarks::base::components::PositionComponent;
using ComponentTwo = ecs::benchmarks::base::components::VelocityComponent;
using ComponentThree = ecs::benchmarks::base::components::DataComponent;

BM_IterateThreeComponentsWithMixedEntitiesAndPreCreatedView(
state,
[](auto& world) {
return world.query().template all<ComponentOne&, ComponentTwo&, ComponentThree&>();
},
[&](ComponentOne& comp, ComponentTwo& comp2, ComponentThree& comp3) {
dummy_each(comp, comp2, comp3);
});
}
};

} // namespace ecs::benchmarks::gaia_ecs

#endif
15 changes: 15 additions & 0 deletions benchmark/benchmarks/gaia-ecs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(INCLUDE_DIR "include") # must be relative paths
# NOTE: rename project in "ecs-benchmark-myecs"
add_executable(
ecs-benchmark-gaia-ecs
# NOTE: add new benchmarks here
GaiaEcsBenchmarkSuite.cpp GaiaEcsBenchmarkSuite.h)
target_include_directories(
ecs-benchmark-gaia-ecs
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${INCLUDE_DIR}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${INCLUDE_DIR}>")
target_link_libraries(ecs-benchmark-gaia-ecs PRIVATE project_warnings project_options)
target_link_libraries(ecs-benchmark-gaia-ecs PRIVATE ecs-benchmark)

# @NOTE: add libs for example here
target_link_libraries(ecs-benchmark-gaia-ecs PRIVATE ecs-benchmark-example-gaia-ecs)
5 changes: 5 additions & 0 deletions benchmark/benchmarks/gaia-ecs/GaiaEcsBenchmarkSuite.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "GaiaEcsBenchmarkSuite.h"

static ecs::benchmarks::gaia_ecs::GaiaEcsBenchmarkSuite benchmark_suite;

ECS_UPDATE_SYSTEMS_BENCHMARKS(benchmark_suite)
28 changes: 28 additions & 0 deletions benchmark/benchmarks/gaia-ecs/GaiaEcsBenchmarkSuite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef ECS_BENCHMARKS_GAIA_ECS_BENCHMARK_H_
#define ECS_BENCHMARKS_GAIA_ECS_BENCHMARK_H_

#include "ECSBenchmark.h"
#include "gaia-ecs/GaiaEcsApplication.h"
#include "gaia-ecs/entities/EntityFactory.h"
#include "gaia-ecs/entities/HeroMonsterEntityFactory.h"
#include "gaia-ecs/systems/DataSystem.h"
#include "gaia-ecs/systems/MoreComplexSystem.h"
#include "gaia-ecs/systems/MovementSystem.h"
#include <utility>


namespace ecs::benchmarks::gaia_ecs {

class GaiaEcsBenchmarkSuite final
: public ecs::benchmarks::base::ECSBenchmark<"gaia-ecs", GaiaEcsApplication, entities::EntityFactory,
entities::HeroMonsterEntityFactory> {
public:
GaiaEcsBenchmarkSuite() = default;

explicit GaiaEcsBenchmarkSuite(ecs::benchmarks::base::ESCBenchmarkOptions options)
: ECSBenchmark(std::move(options)) {}
};

} // namespace ecs::benchmarks::gaia_ecs

#endif // ECS_BENCHMARKS_GAIA_ECS_BENCHMARK_H_
7 changes: 7 additions & 0 deletions plot.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@
"version": "2.3 (Sep 2023)",
"link": "https://github.com/empyreanx/pico_headers"
},
"gaia-ecs": {
"name": "gaia-ecs",
"author": "@richardbiely",
"description": "Gaia-ECS is a fast and easy-to-use ECS framework.",
"version": "v0.8.5",
"link": "https://github.com/richardbiely/gaia-ecs"
},
"oop": {
"name": "OOP",
"description": "Simple OOP Solution.",
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ option(ENABLE_BENCHMARK_OOP "Enable OOP Benchmarks" ON)
if(ENABLE_BENCHMARK_OOP)
add_subdirectory(oop)
endif()

option(ENABLE_BENCHMARK_GAIA_ECS "Enable gaia-ecs Benchmarks" ON)
if(ENABLE_BENCHMARK_GAIA_ECS)
add_subdirectory(gaia-ecs)
endif()
57 changes: 57 additions & 0 deletions src/gaia-ecs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# https://github.com/richardbiely/gaia-ecs
cpmaddpackage(
NAME
gaia
VERSION
0.8.5
GITHUB_REPOSITORY
richardbiely/gaia-ecs
# TODO: set current version, use main for build fixes
GIT_TAG
main
OPTIONS
"GAIA_BUILD_UNITTEST OFF"
"GAIA_BUILD_BENCHMARK OFF"
"GAIA_BUILD_EXAMPLES OFF"
"GAIA_MAKE_SINGLE_HEADER ON"
DOWNLOAD_ONLY True)
# @FIXME: can not found <gaia.h> header ... use single-header download
if(gaia_ADDED)
add_library(gaia INTERFACE ${gaia_SOURCE_DIR}/include/gaia.h)
add_library(gaia-ecs ALIAS gaia)
target_include_directories(gaia INTERFACE "$<BUILD_INTERFACE:${gaia_SOURCE_DIR}/include>")
target_compile_features(gaia INTERFACE cxx_std_17)
endif()

set(INCLUDE_DIR "include") # must be relative paths
# NOTE: rename project in "ecs-benchmark-example-myecs"
add_library(
ecs-benchmark-example-gaia-ecs STATIC
# NOTE: add source files here
gaia-ecs/systems/DataSystem.h
gaia-ecs/systems/DataSystem.cpp
gaia-ecs/systems/MoreComplexSystem.h
gaia-ecs/systems/MoreComplexSystem.cpp
gaia-ecs/systems/MovementSystem.h
gaia-ecs/systems/MovementSystem.cpp
gaia-ecs/entities/EntityFactory.h
gaia-ecs/entities/EntityFactory.cpp
gaia-ecs/entities/HeroMonsterEntityFactory.h
gaia-ecs/entities/HeroMonsterEntityFactory.cpp
gaia-ecs/GaiaEcsApplication.h
gaia-ecs/GaiaEcsApplication.cpp
)
add_library(ecs-benchmark::example::gaia-ecs ALIAS ecs-benchmark-example-gaia-ecs)

target_include_directories(
ecs-benchmark-example-gaia-ecs
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${INCLUDE_DIR}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${INCLUDE_DIR}>")
target_link_libraries(ecs-benchmark-example-gaia-ecs PRIVATE project_warnings project_options)
target_link_libraries(ecs-benchmark-example-gaia-ecs PUBLIC ecs-benchmark-base)

# NOTE: add 3rd-party libs here
target_link_system_libraries(ecs-benchmark-example-gaia-ecs PUBLIC gaia)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(ecs-benchmark-example-gaia-ecs PRIVATE Threads::Threads)
1 change: 1 addition & 0 deletions src/gaia-ecs/gaia-ecs/GaiaEcsApplication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "GaiaEcsApplication.h"
61 changes: 61 additions & 0 deletions src/gaia-ecs/gaia-ecs/GaiaEcsApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef ECS_BENCHMARKS_GAIA_ECS_APPLICATION_H_
#define ECS_BENCHMARKS_GAIA_ECS_APPLICATION_H_

#include "base/Application.h"

#include "systems/DataSystem.h"
#include "systems/MoreComplexSystem.h"
#include "systems/MovementSystem.h"
#include <gaia.h>

namespace ecs::benchmarks::gaia_ecs {

class GaiaEcsApplication {
public:
using EntityManager = ::gaia::ecs::World;
using TimeDelta = float;

GaiaEcsApplication() : m_sm(m_world) {}

explicit GaiaEcsApplication(bool add_more_complex_system)
: m_add_more_complex_system(add_more_complex_system), m_sm(m_world) {}

~GaiaEcsApplication() = default;

GaiaEcsApplication(const GaiaEcsApplication&) = delete;

GaiaEcsApplication& operator=(const GaiaEcsApplication&) = delete;

GaiaEcsApplication(GaiaEcsApplication&&) = default;

GaiaEcsApplication& operator=(GaiaEcsApplication&&) = default;

[[nodiscard]] inline EntityManager& getEntities() { return m_world; }

[[nodiscard]] inline const EntityManager& getEntities() const { return m_world; }


void init() {
m_sm.add<systems::MovementSystem>();
m_sm.add<systems::DataSystem>();
if (m_add_more_complex_system) {
m_sm.add<systems::MoreComplexSystem>();
m_sm.add<systems::HealthSystem>();
m_sm.add<systems::DamageSystem>();
}
}

void uninit() {
/// @TODO: remove system for better clean up
}

void update(TimeDelta dt) { m_sm.update(); }

private:
bool m_add_more_complex_system{false};
EntityManager m_world;
::gaia::ecs::SystemManager m_sm;
};
} // namespace ecs::benchmarks::gaia_ecs

#endif // ECS_BENCHMARKS_GAIA_ECS_APPLICATION_H_
Loading

0 comments on commit 4dbc52d

Please sign in to comment.