Giter VIP home page Giter VIP logo

specs's Introduction

specs

Build Status Crates.io Gitter

Specs is an Entity-Component System written in Rust. It aims for parallel systems execution with high ergonomics and flexibility. The name can be interpret in a number of ways:

  • "SPECS Parallel ECS"
  • "Super Powerful ECS"
  • "Special ECS"

Classification

According to ECS Design Crossroads, specs fulfills all the requirements, has In-place modification updates, and Generational ID entities.

Features

  • Automatic execution of the systems in parallel. Follows Rust ownership rules, where each component storage behaves as a variable. Depends on the order, in which systems are started.
  • Component storage is abstract behind the trait. One can use vectors, hashmaps, trees, or whatever else.
  • New components can be registered at any point from user modules. They don't have to be POD.
  • No virtual calls, low overhead.

Why is it fast

  • Do you know many other natively parallel ECS in Rust?
  • Abstract storage means you can choose the most efficient one according to your needs. You can even roll in your own.
  • No virtual calls during systems processing means you work with the data directly.

See ecs_bench for single- and multi-threaded performance comparisons.

Why is it cool

  • Your system can be as simple as a closure working on some components, no redundant info or boilerplate is needed. At the same time, you can manually fiddle with entities and components, and it would still be safe and convenient.
  • Your components can be anything (as long as they implement Component)! Neither Copy or even Clone bounds are needed.
  • Your component storages can be anything. Consider crazy stuff like a BSP tree, or a database over the network. Some storages can safely allow sharing their components between entities, some can not - but it's up to you to choose.

Examples

Entity creation:

let mut planner = {
    let mut w = specs::World::new();
    // All components types should be registered before working with them
    w.register::<Position>();
    w.register::<Speed>();
    // create_now() of World provides with an EntityBuilder to add components to an Entity
    w.create_now().with(Position(0)).with(Speed(2)).build();
    w.create_now().with(Position(-1)).with(Speed(100)).build();
    w.create_now().with(Position(127)).build();
    // Planner is used to run systems on the specified world with a specified number of threads
    specs::Planner::new(w, 4)
};

System run:

planner.run1w1r(|p: &mut Position, s: &Speed| {
    *p += *s;
});

Custom system:

impl System<u32> for MySystem {
    fn run(&mut self, arg: RunArg, context: u32) {
        let mut numbers = arg.fetch(|w| w.write::<u32>());
        for n in (&numbers).iter() {
            *n += context;
        }
    }
}

specs's People

Contributors

aceeri avatar csherratt avatar kimundi avatar kvark avatar lschmierer avatar malleusinferni avatar serprex avatar thezalli avatar userab1236872 avatar white-oak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.