All Projects → xissburg → Edyn

xissburg / Edyn

Licence: mit
Edyn is a real-time physics engine organized as an ECS.

Projects that are alternatives of or similar to Edyn

Svelto.ecs
Svelto ECS C# Lightweight Data Oriented Entity Component System Framework
Stars: ✭ 605 (+435.4%)
Mutual labels:  ecs, game-development, entity-component-system
Endless Runner Entitas Ecs
Runner template for Unity
Stars: ✭ 41 (-63.72%)
Mutual labels:  ecs, game-development, entity-component-system
Octopuskit
2D ECS game engine in 100% Swift + SwiftUI for iOS, macOS, tvOS
Stars: ✭ 246 (+117.7%)
Mutual labels:  ecs, game-development, entity-component-system
Ecs
LeoECS is a fast Entity Component System (ECS) Framework powered by C# with optional integration to Unity
Stars: ✭ 578 (+411.5%)
Mutual labels:  ecs, game-development, entity-component-system
Etengine
Realtime 3D Game-Engine with a focus on space sim. Written in C++ 14
Stars: ✭ 408 (+261.06%)
Mutual labels:  ecs, game-development, entity-component-system
Uecs
Ubpa Entity-Component-System (U ECS) in Unity3D-style
Stars: ✭ 174 (+53.98%)
Mutual labels:  ecs, game-development, entity-component-system
Ecs
A simple and easy to use entity-component-system C++ library
Stars: ✭ 20 (-82.3%)
Mutual labels:  ecs, game-development, entity-component-system
Flecs
A fast entity component system (ECS) for C & C++
Stars: ✭ 2,201 (+1847.79%)
Mutual labels:  ecs, game-development, entity-component-system
Godex
Godex is a Godot Engine ECS library.
Stars: ✭ 307 (+171.68%)
Mutual labels:  ecs, game-development, entity-component-system
Gdk For Unity
SpatialOS GDK for Unity
Stars: ✭ 296 (+161.95%)
Mutual labels:  ecs, game-development, entity-component-system
Entt
Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
Stars: ✭ 6,017 (+5224.78%)
Mutual labels:  ecs, game-development, entity-component-system
Rust Game Development Frameworks
List of curated frameworks by the **Game Development in Rust** community.
Stars: ✭ 81 (-28.32%)
Mutual labels:  ecs, game-development, entity-component-system
Entitas Csharp
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
Stars: ✭ 5,393 (+4672.57%)
Mutual labels:  ecs, game-development, entity-component-system
Entitas Cpp
Entitas++ is a fast Entity Component System (ECS) C++11 port of Entitas C#
Stars: ✭ 229 (+102.65%)
Mutual labels:  ecs, game-development, entity-component-system
Ape Ecs
Entity-Component-System library for JavaScript.
Stars: ✭ 137 (+21.24%)
Mutual labels:  ecs, game-development, entity-component-system
Shipyard
Entity Component System focused on usability and speed.
Stars: ✭ 247 (+118.58%)
Mutual labels:  ecs, game-development, entity-component-system
Gdk For Unity Fps Starter Project
SpatialOS GDK for Unity FPS Starter Project
Stars: ✭ 119 (+5.31%)
Mutual labels:  ecs, game-development, entity-component-system
Defaultecs
Entity Component System framework aiming for syntax and usage simplicity with maximum performance for game development.
Stars: ✭ 286 (+153.1%)
Mutual labels:  ecs, game-development, entity-component-system
Kengine
Entity-Component-System (ECS) with a focus on ease-of-use, runtime extensibility and compile-time type safety and clarity.
Stars: ✭ 417 (+269.03%)
Mutual labels:  ecs, game-development, entity-component-system
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-13.27%)
Mutual labels:  ecs, game-development, entity-component-system

EdynLogo

Edyn (pronounced like "eh-dyin'") stands for Entity Dynamics and it is a real-time physics engine organized as an ECS (Entity-Component System) using the amazing EnTT library. The main goals of this library is to be multi-threaded and to support networked and distributed physics simulation of large dynamic worlds.

It is still in an early stage of development and is not yet ready for use. Feel free to explore and contribute meanwhile.

Examples are located in a separate repository: Edyn Testbed

Build Instructions

Requirements

A compiler with C++17 support is required, along with CMake version 3.12.4 or above.

Dependencies:

Steps

In the Edyn directory:

$ mkdir build
$ cd build
$ conan install ../conanfile.txt
$ cmake ..
$ make

The ECS approach

Typical physics engines will offer explicit means to create objects such as rigid bodies, whereas in Edyn object creation is implicit due to the entity-component design. A rigid body is created from the bottom up, by associating its parts to a single entity, such as:

entt::registry registry;
auto entity = registry.create();
registry.emplace<edyn::dynamic_tag>(entity);
registry.emplace<edyn::position>(entity, 0, 3, 0);
registry.emplace<edyn::orientation>(entity, edyn::quaternion_axis_angle({0, 1, 0}, edyn::to_radians(30)));
registry.emplace<edyn::linvel>(entity, edyn::vector3_zero);
registry.emplace<edyn::angvel>(entity, 0, 0.314, 0);
auto mass = edyn::scalar{50};
registry.emplace<edyn::mass>(entity, mass);
auto &shape = registry.emplace<edyn::shape>(entity, edyn::box_shape{0.5, 0.2, 0.4});
registry.emplace<edyn::inertia>(entity, shape.inertia(mass));
registry.emplace<edyn::material>(entity, 0.2, 0.9); // Restitution and friction.
registry.emplace<edyn::linacc>(entity, edyn::gravity_earth);

There's no explicit mention of a rigid body in the code, but during the physics update all entities that have a combination of the components assigned above will be treated as a rigid body and their state will be updated over time as expected. The update may be carried as follows:

// Apply gravity acceleration, increasing linear velocity.
auto view = registry.view<edyn::linvel, const edyn::linacc, const edyn::dynamic_tag>();
view.each([dt] (auto entity, edyn::linvel &vel, const edyn::linacc &acc, [[maybe_unused]] auto) {
  vel += acc * dt;
});
// ...
// Move entity with its linear velocity.
auto view = registry.view<edyn::position, const edyn::linvel, const edyn::dynamic_tag>();
view.each([dt] (auto entity, edyn::position &pos, const edyn::linvel &vel, [[maybe_unused]] auto) {
  pos += vel * dt;
});
// ...
// Rotate entity with its angular velocity.
auto view = registry.view<edyn::orientation, const edyn::angvel, const edyn::dynamic_tag>();
view.each([dt] (auto entity, edyn::orientation &orn, const edyn::angvel &vel, [[maybe_unused]] auto) {
  orn = edyn::integrate(orn, vel, dt);
});

Assigning each component to every rigid body entity individually quickly becomes a daunting task which is prone to errors, thus utility functions are provided for common tasks such as creating rigid bodies:

// Equivalent to implicit example above.
auto def = edyn::rigidbody_def();
def.kind = edyn::rigidbody_kind::rb_dynamic;
def.position = {0, 3, 0};
def.orientation = edyn::quaternion_axis_angle({0, 1, 0}, edyn::to_radians(30));
def.linvel = edyn::vector3_zero;
def.angvel = {0, 0.314, 0};
def.mass = 50;
def.shape_opt = {edyn::box_shape{0.5, 0.2, 0.4}}; // Shape is optional.
def.update_inertia();
def.restitution = 0.2;
def.friction = 0.9;
def.gravity = edyn::gravity_earth;
auto entity = edyn::make_rigidbody(registry, def);

Basics

Edyn is built as a multi-threaded library from the ground up which requires initializing its worker threads on start-up invoking edyn::init(), and then a edyn::world must be created before setting up the scene:

#include <entt/entt.hpp>
#include <edyn/edyn.hpp>

edyn::init();
entt::registry registry;
auto &world = registry.set<edyn::world>(registry);

// Create rigid bodies and constraints...

// Call `edyn::world::update()` periodically in your main loop somewhere.
for (;;) {
  world.update();
  // Do something with the results, e.g. render scene.
  // ...
}

When edyn::world::update() is called, it processes any pending changes, creates/destroys workers if needed, dispatches messages to workers, reads and processes messages from workers which are merged into the entt::registry, perparing the entities and components to be rendered right after.

Due to its multi-threaded nature, all changes to relevant components in the main entt::registry need to be propagated to the worker threads. The edyn::world doesn't automatically pick up these changes, thus it's necessary to notify it either by calling edyn::world::refresh() or assigning a edyn::dirty component to the entity and calling some of its functions such as edyn::dirty::updated() (e.g. registry.emplace<edyn::dirty>(entity).updated<edyn::position, edyn::linvel>()).

Documentation

See docs/Design.md to learn more about the engine's planned architecture.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].