Shipyard - Entity Component System focused on usability and speed

栏目: IT技术 · 发布时间: 5年前

内容简介:Shipyard is an Entity Component System focused on usability and speed.While usable it is far from finished, there's a lot of planned features, nearly all being backward compatible additions.Most discussions about current and future features happen on zulip

Shipyard

Shipyard is an Entity Component System focused on usability and speed.

While usable it is far from finished, there's a lot of planned features, nearly all being backward compatible additions.

Most discussions about current and future features happen on zulip, feel free to join in to follow the development, ask any question or just say hi.

If you are new here, the user guide is a great place to learn all about Shipyard!

Simple Example

use shipyard::prelude::*;

struct Health(f32);
struct Position { x: f32, y: f32 }

#[system(InAcid)]
fn run(pos: &Position, mut health: &mut Health) {
    (&pos, &mut health).iter()
        .filter(|(pos, _)| is_in_acid(pos))
        .for_each(|(pos, mut health)| {
            health.0 -= 1.0;
        });
}

fn is_in_acid(pos: &Position) -> bool {
    // it's wet season
    true
}

let world = World::new();

{
    let (mut entities, mut positions, mut healths) =
        world.borrow::<(EntitiesMut, &mut Position, &mut Health)>();
   
    entities.add_entity(
        (&mut positions, &mut healths),
        (Position { x: 0.0, y: 0.0 },
        Health(1000.0))
    );
}

world.run_system::<InAcid>();

Past, Present and Future

I initially started to make an ECS to learn how it works. After a failed attempt and learning a lot from it and other ECS out there, I started to work on Shipyard.

Specs was already well established as the go-to Rust ECS but I thought I could do better and went with EnTT core data-structure: SparseSet .

It turned out to be extremely flexible and is still the core of Shipyard. You can pay for what you want: iteration speed, memory, ease of use,...

And it allowed amazing features:

  • No component boilerplate
  • Very simple systems
  • Powerful inner and outer system parallelism
  • Ability to add/remove components while adding/removing entities
  • Chunk iteration
  • And a lot more!

Today I wouldn't say Shipyard is better or worse than Specs, it's just different. I'm really happy with it and the future looks very promising, especially:

Similar Projects

  • EnTT - C++ library built on SparseSet and providing grouping functionality, a lot of its designs are explained in a blog . This is where Shipyard's SparseSet and most packs come from
  • Specs - Rust library relying on BitSet and allowing to use multiple storage types
  • Legion - Rust library based on archetypes
  • Hecs - Rust library also based on archetypes but keeping a minimalistic approach

Performance

If you're wondering how fast Shipyard is you can look at a few graphs in this issue .

There is still a lot of room for optimization, the current focus is more on adding functionalities.

Features

  • parallel (default) — adds parallel iterators and dispatch
  • proc (default) — adds system proc macro
  • serde — adds (de)serialization support with serde
  • non_send — add methods and types required to work with !Send components
  • non_sync — add methods and types required to work with !Sync components
  • std (default) — let shipyard use the standard library

Unsafe

This crate uses unsafe both because sometimes there's no way around it, and for performance gain.

Releases should have all invocation of unsafe explained.

If you find places where a safe alternative is possible without repercussion (small ones are sometimes acceptable) feel free to open an issue or a PR.

Origin of the Name

Assembly lines take input, process it at each step, and output a result. You can have multiple lines working in parallel as long as they don't bother each other.

Shipyards such as the Venetian Arsenal are some of the oldest examples of successful, large-scale, industrial assembly lines. So successful that it could output a fully-finished ship every day .

Shipyard is a project you can use to build your own highly-parallel software processes.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

思考,快与慢

思考,快与慢

[美] 丹尼尔·卡尼曼 / 胡晓姣、李爱民、何梦莹 / 中信出版社 / 2012-7 / 69.00元

《纽约时报》2011年度十大好书 新书上市,连续20多周蝉联亚马逊、《纽约时报》畅销书排行榜前20名,上市至今超过7个月,横扫全球各大畅销书排行榜,稳居亚马逊总榜前50名 《经济学人》、《华尔街日报》、《卫报》、《纽约时报》、《金融时报》、《商业周刊》、《华盛顿邮报》、等国外权威媒体,《三联生活周刊》、《商学院》、《东方早报》等国内知名媒体争相报道,国内外读者好评如潮 人类究竟有......一起来看看 《思考,快与慢》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换