ECS-Application
所属分类:数值算法/人工智能
开发工具:C++
文件大小:139KB
下载次数:0
上传日期:2019-06-27 02:10:41
上 传 者:
sh-1993
说明: 类似于C++中Unity的ECS,用于娱乐和科学
(Similar to Unity s ECS in C++ for fun and science)
文件列表:
.travis.yml (177, 2019-06-27)
.vscode (0, 2019-06-27)
.vscode\settings.json (93, 2019-06-27)
CMakeLists.txt (373, 2019-06-27)
cmake (0, 2019-06-27)
cmake\Catch.cmake (7060, 2019-06-27)
cmake\CatchAddTests.cmake (2168, 2019-06-27)
cmake\ParseAndAddCatchTests.cmake (13337, 2019-06-27)
example (0, 2019-06-27)
example\main.cpp (3029, 2019-06-27)
include (0, 2019-06-27)
include\Entity.hpp (252, 2019-06-27)
include\EntityArchetype.hpp (4821, 2019-06-27)
include\EntityChunk.hpp (2550, 2019-06-27)
include\EntityGroup.hpp (892, 2019-06-27)
include\EntityManager.hpp (7528, 2019-06-27)
include\Iterators (0, 2019-06-27)
include\Iterators\ComponentArray.hpp (1691, 2019-06-27)
include\Iterators\EntityArray.hpp (1186, 2019-06-27)
include\Types.hpp (172, 2019-06-27)
include\Types (0, 2019-06-27)
include\Types\ComponentType.hpp (952, 2019-06-27)
src (0, 2019-06-27)
src\Entity.cpp (381, 2019-06-27)
src\TODO.md (132, 2019-06-27)
tests (0, 2019-06-27)
tests\CMakeLists.txt (209, 2019-06-27)
tests\catch2 (0, 2019-06-27)
tests\catch2\catch.hpp (612684, 2019-06-27)
tests\main.cpp (240, 2019-06-27)
tests\testcase.cpp (5323, 2019-06-27)
[![Build Status](https://travis-ci.com/glauber-guimaraes/ECS-Application.svg?branch=master)](https://travis-ci.com/glauber-guimaraes/ECS-Application)
# ECS-Application
Similar to Unity's ECS in C++ for fun and science
## Usage
### Simple operations
```cpp
// Define a structure for your data. Primitive types can also be used.
struct Health {
float Value;
};
// Create an archetype.
EntityArchetype archetype = CreateArchetype();
// Create an entity manager.
EntityManager entityManager;
// Create an entity based off of the archetype.
Entity e = entityManager.CreateEntity(archetype);
// Set data for the entity.
Health h = { 5 };
entityManager.SetComponentData(e, h);
entityManager.SetComponentData(e, { 10 });
// Get data for the entity.
std::cout << entityManager.GetComponentData(e).Value;
// Check if entity still exists.
bool exists = entityManager.Exists(e);
// Check if it has a component.
bool has = entityManager.HasComponent(e);
// Add components at run time.
entityManager.AddComponent(e);
entityManager.AddComponent(e, 27);
// Remove components at run time.
entityManager.RemoveComponent(e);
// Destroy the entity.
entityManager.DestroyEntity(e);
```
### Iterating over entities
```cpp
// Create an entity group.
EntityGroup group = entityManager.GetEntityGroup(
ComponentType::Create(), // Matches archetypes with a Health component.
ComponentType::Subtractive() // Matches archetypes without a double component.
);
// Get an iterator.
auto iter = group.GetComponentArray(); // Iterate directly over the component.
auto entityIter = group.GetEntityArray(); // Iterate over the entities.
// Loop over the matching entities.
// Element i on both iterators represent the same entity.
for (int i = 0; i < iter.Length(); i++) {
std::cout << "Entity " << i << " health: " << iter[i].Value << "\n";
std::cout << "Entity " << i << " health: " << entityManager.GetComponentData(entityIter[i]).Value << "\n";
}
```
近期下载者:
相关文件:
收藏者: