wecs (wckd-ecs) is a simple ECS library suitable for general use.

Overview

wecs

wecs (wckd-ecs) is a simple ECS library heavily based on bevy_ecs.

Motivation

As part of my "Road to Rust GameDev" journey, I wanted to learn how stuff worked behind the scenes, so I started with the foundation of many game engines, the Entity-Component-System. I did it by devouring bevy_ecs and creating my own version of it, with similar inner workings and identical syntax, without all the optimization that I am yet to learn. I'll be using it on my personal projects and hopefully be incrementing on its features.

Code Example

- "Gravity" sim

use wecs::{query::Query, resource::Res, schedule::Schedule, world::World};

#[derive(Resource, Default)]
pub struct GravityManager {
    gravity: f32,
}

#[derive(Debug, Component)]
pub struct Position {
    x: f32,
    y: f32,
    z: f32,
}

fn main() {
    let mut world = World::new();
    world.insert_resource(GravityManager { gravity: 10.0 });
    world.spawn_entity(Position {
        x: 0.0,
        y: 50.0,
        z: 0.0,
    });

    let mut schedule = Schedule::new()
        .with_system(update_system)
        .with_system(print_system);

    loop {
        schedule.run(&mut world);
        std::thread::sleep(Duration::from_secs(1));
    }
}

fn update_system(query: Query<&mut Position>, manager: Res<GravityManager>) {
    for position in query {
        position.y -= manager.gravity;
    }
}

fn print_system(query: Query<&Position>) {
    for position in query {
        let Position {x, y, z} = position;
        println!("entity position is {x},{y},{z}");
    }
}

output:

entity position is 0,40,0
entity position is 0,30,0
entity position is 0,20,0
entity position is 0,10,0
entity position is 0,0,0
entity position is 0,-10,0
entity position is 0,-20,0
...

- Events

use wecs::{schedule::Schedule, world::World, EventManager, EventReader, EventWriter};

struct CoolEvent {
    pub num: u32,
}

fn main() {
    let mut world = World::new();
    world.init_resource::<EventManager<CoolEvent>>();

    let mut schedule = Schedule::new();
    schedule.add_system(publish_events);
    schedule.add_system(consume_events);
    schedule.add_system(EventManager::<CoolEvent>::clear);

    schedule.run(&mut world);
}

fn publish_events(mut writer: EventWriter<CoolEvent>) {
    writer.dispatch_one(CoolEvent { num: 0 });
}

fn consume_events(reader: EventReader<CoolEvent>) {
    for event in reader {
        println!("CoolEvent's num is {}", event.num);
    }
}

output:

CoolEvent's num is 0

You might also like...
Bring Bevy's ECS to Godot4

bevy_godot4 Bring the design power of Bevy's ECS to the mature engine capabilities of Godot 4. WARNING: This crate is very early in development, and i

A direct ecs to low-level server implementation for Godot 4.1

godot_ecs What if Godot 4.1 and Bevy got married? Well, you'd get one interesting duo of data driven goodness. In Development This crate is not produc

A simple example showcasing how to use Bevy to display a square with acceleration (controllable with your keyboard) that wraps around the screen!
A simple example showcasing how to use Bevy to display a square with acceleration (controllable with your keyboard) that wraps around the screen!

Bevy Wrapping Square example A simple example showcasing how to use Bevy to display a square with acceleration (controllable with your keyboard) that

A simple-to-use input manager for the Bevy game engine that empowers players and makes accessibility easy.

Bevy Ineffable A simple-to-use input manager for the Bevy game engine that empowers players and makes accessibility easy. Core tenets Make accessibili

A Bevy plugin to use Kira for game audio

Bevy Kira audio This bevy plugin is intended to try integrating Kira into Bevy. The end goal would be to replace or update bevy_audio, if Kira turns o

Easy to use game engine
Easy to use game engine

arcana Arcana is a game engine built with focus on ease of use without compromising on level of control. Getting started Starting writing a game is as

A interactive and fun to use memory game written in Rust

memg - Memory Game memg is a interactive and fun to use memory game written in rust Installation Make sure you have rust installed. Use this official

GDDB is a superfast in-memory database designed for use in Godot

GDDB GDDB is a superfast in-memory database designed for use in Godot. This database aims to provide an easy frontend to an efficient in-memory databa

A high-performance renderer to render glTF models that use the `KHR_materials_transmission` and `KHR_materials_volume` extensions.
A high-performance renderer to render glTF models that use the `KHR_materials_transmission` and `KHR_materials_volume` extensions.

This is a high-performance renderer designed among other things to render glTF models that use the KHR_materials_transmission and KHR_materials_volume

Releases(0.1.2)
Owner
João Victor
João Victor
General purpose client/server networking library written in Rust, built on top of the QUIC protocol which is implemented by quinn

Overview "This library stinks!" ... "Unless you like durian" durian is a client-server networking library built on top of the QUIC protocol which is i

Michael 92 Dec 31, 2022
A simple type safety solution for Bevy ECS.

?? Moonshine Kind A simple type safety solution for Bevy ECS. Overview An Entity is a generic way to reference entities within Bevy ECS: #[derive(Comp

null 8 Nov 3, 2023
High performance Rust ECS library

Legion aims to be a feature rich high performance Entity component system (ECS) library for Rust game projects with minimal boilerplate. Getting Start

Amethyst Engine 1.4k Jan 5, 2023
A feature-rich, production-ready, general purpose 2D/3D game engine written in Rust with a scene editor.

A feature-rich, production-ready, general purpose 2D/3D game engine written in Rust with a scene editor.

rg3d engine 5.4k Jan 4, 2023
Specs - Parallel ECS

Specs Specs Parallel ECS Specs is an Entity-Component System written in Rust. Unlike most other ECS libraries out there, it provides easy parallelism

Amethyst Engine 2.2k Jan 8, 2023
A tilemap rendering crate for bevy which is more ECS friendly.

bevy_ecs_tilemap A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile. Features A tile per entity Fast renderin

John 414 Dec 30, 2022
Creative Coding Framework based on Entity Component System (ECS) written in Rust

creativity creativity is Creative Coding Framework based on Entity Component System (ECS) written in Rust. Key Features TBA Quick Start TBA How To Con

Chris Ohk 9 Nov 6, 2021
🤹‍ 2D sprite rendering extension for the specs ECS system

specs-blit 2D sprite rendering extension for the Specs ECS system. All sprites are loaded onto a big array on the heap. Example // Setup the specs wor

Thomas Versteeg 8 Aug 14, 2022
🏷️ Markers for Bevy ECS Entities

Bevy ECS Markers Adds the support for marking entites and fetching them in queries Example View the whole example here #[derive(EntityMarker)] enum Pl

Chopped Studio 2 Dec 23, 2022
Minimalistic implementation of entity kinds for Bevy ECS.

Bevy ?? Kindly This crate is a minimalistic implementation of Kinded Entities for Bevy game engine. In summary, it allows the user to define, construc

null 10 Jan 26, 2023