Improve Our Rust Skills

by making an ECS library

But First...Who Am I?

Technical Team Lead at Health Scholars

Worked in the IT industry for over 15 years

Including contracting at NASA as a systems administrator

Live-coding Rust based projects fun visualizations, and tutorials on Twitch.tv

How building an ECS Library will improve our skills?

Game Dev is a different domain

Game Dev is fun*

*your fun amount may vary

What is ECS?

Player Enemy Tree Another Enemy
Location {x: 100.0, y: 200.0} {x: 150.0, y: 200.0 {x: 200.0, y: 750.0} {x: 450.0, y: 200.0}
Size 100.0 50.0 800.0 50.0
Health 100 10 10
Velocity {x: 10.0, y: 0.0} {x: -5.0, y: 0.0} {x: -5.0, y: 0.0}

Features

Player Enemy Tree Another Enemy
Location {x: 100.0, y: 200.0} {x: 150.0, y: 200.0 {x: 200.0, y: 750.0} {x: 450.0, y: 200.0}
Size 100.0 50.0 800.0 50.0
Health 100 10 10
Velocity {x: 10.0, y: 0.0} {x: -5.0, y: 0.0} {x: -5.0, y: 0.0}

What does a system look like?

We Need a Map

Player Enemy Tree Another Enemy
Location {x: 100.0, y: 200.0} {x: 150.0, y: 200.0 {x: 200.0, y: 750.0} {x: 450.0, y: 200.0}
Size 100.0 50.0 800.0 50.0
Health 100 10 10
Velocity {x: 10.0, y: 0.0} {x: -5.0, y: 0.0} {x: -5.0, y: 0.0}
00001111 00001111 00000011 00001111
Location 00000001
Size 00000010
Health 00000100
Velocity 00001000

A Use for BitWise Operations

fn main() {
    let location_mask = 0b00000001;
    let size_mask =     0b00000010;
    let mut map = 0;
    
    // We insert a location for the entity
    map |= location_mask;
    dbg!(map);
    
    // Next we insert a size for the entity
    map |= size_mask;
    dbg!(map);
}

Querying

2 Step Process

Figure out which entities match the query

Get the components for the matched entities

Clone but Still Have the Original?

All without unsafe

We can store Any type!

Yes, even Rust has an Any type*

*It's really a trait

Deleting

Just update the map

What can we create with this?

Questions

Made with Slides.com