-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b92bb4
commit 504761f
Showing
2 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR) | ||
|
||
# ---- Dependencies ---- | ||
|
||
include(../../cmake/CPM.cmake) | ||
|
||
CPMAddPackage( | ||
NAME EnTT | ||
VERSION 3.1.1 | ||
GITHUB_REPOSITORY skypjack/entt | ||
# EnTT's CMakeLists screws with configuration options | ||
DOWNLOAD_ONLY True | ||
) | ||
|
||
if (EnTT_ADDED) | ||
add_library(EnTT INTERFACE) | ||
target_include_directories(EnTT INTERFACE ${EnTT_SOURCE_DIR}/src) | ||
endif() | ||
|
||
# ---- Executable ---- | ||
|
||
add_executable(CPMEnTTExample "main.cpp") | ||
set_target_properties(CPMEnTTExample PROPERTIES CXX_STANDARD 17) | ||
target_link_libraries(CPMEnTTExample EnTT) |
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,54 @@ | ||
#include <entt/entt.hpp> | ||
#include <cstdint> | ||
|
||
struct position { | ||
float x; | ||
float y; | ||
}; | ||
|
||
struct velocity { | ||
float dx; | ||
float dy; | ||
}; | ||
|
||
void update(entt::registry ®istry) { | ||
auto view = registry.view<position, velocity>(); | ||
|
||
for(auto entity: view) { | ||
// gets only the components that are going to be used ... | ||
|
||
auto &vel = view.get<velocity>(entity); | ||
|
||
vel.dx = 0.; | ||
vel.dy = 0.; | ||
|
||
// ... | ||
} | ||
} | ||
|
||
void update(std::uint64_t dt, entt::registry ®istry) { | ||
registry.view<position, velocity>().each([dt](auto &pos, auto &vel) { | ||
// gets all the components of the view at once ... | ||
|
||
pos.x += vel.dx * dt; | ||
pos.y += vel.dy * dt; | ||
|
||
// ... | ||
}); | ||
} | ||
|
||
int main() { | ||
entt::registry registry; | ||
std::uint64_t dt = 16; | ||
|
||
for(auto i = 0; i < 10; ++i) { | ||
auto entity = registry.create(); | ||
registry.assign<position>(entity, i * 1.f, i * 1.f); | ||
if(i % 2 == 0) { registry.assign<velocity>(entity, i * .1f, i * .1f); } | ||
} | ||
|
||
update(dt, registry); | ||
update(registry); | ||
|
||
// ... | ||
} |