Правене на игри с Amethyst

08 януари 2019

Какво е Amethyst?

What sort of graphics do you need?

Source: https://gist.github.com/kvark/840c8cadf755b0d822b331222b0c3095

Подходи

Подходи

Подходи

Подходи

Една интересна презентация по темата:

"Update" pattern

1 2 3 4 5 6 7 8 9
loop {
    player.update();
    shots.update();
    enemies.update();

    player.draw();
    shots.draw();
    enemies.draw();
}

EC

Модел Entity-Component

EC

Модел Entity-Component

EC

Модел Entity-Component

EC - Entity

1 2 3 4 5 6 7 8 9 10
struct Ferris {
    rendering: RenderingComponent,
    position: PositionComponent
    shooting: ShootingComponent
}

struct Enemy {
    rendering: RenderingComponent,
    position: PositionComponent,
}

EC - Component

1 2 3 4 5 6 7 8 9 10
struct PositionComponent {
    pos: Vector2<f32>,
    vel: Vector2<f32>,
}

impl Component for PositionComponent {
    fn update(&mut self) {
        self.pos += self.vel * delta_time();
    }
}

EC

1 2 3 4 5 6 7 8 9 10 11
for c in components {
    c.update();
}

// or

for e in entities {
    for c in e.components() {
        c.update();
    }
}

ECS

Модел Entity-Component-System

ECS

Модел Entity-Component-System

ECS

Модел Entity-Component-System

ECS

Модел Entity-Component-System

ECS

Модел Entity-Component-System

ECS - Entity

EntityId(0)
Undefined behaviour EntityId(1)
EntityId(4)

ECS - Component

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
let components = Components {
    position: vec![
        (EntityId(0), PositionComponent { pos: .., vel: .. }),
        (EntityId(1), PositionComponent { pos: .., vel: .. }),
        (EntityId(4), PositionComponent { pos: .., vel: .. }),
    ],
    rendering: vec![
        (EntityId(0), RenderingComponent::Sprite("ferris_shooting.png")),
        (EntityId(1), RenderingComponent::Text("Undefined behaviour")),
        (EntityId(4), RenderingComponent::Sprite("pew.png")),
    ],
    shooting: vec![
        (EntityId(0), ShootingComponent { cooldown: 0.0, cooldown_rate: 1.0 }),
    ]
}

ECS - System

1 2 3
SELECT (t, mesh, mat)
FROM TransformComponent, MeshComponent, MaterialComponent
WHERE t.entity_id == mesh.entity_id == mat.entity_id

ECS - System

1 2 3
for (t, mesh, mat) in (&transforms, &meshes, &materials).join() {
    ...
}

Amethyst

Old amethyst logo

New amethyst logo

Amethyst

API документация

API документация

API документация

API документация

Оптимизации

Могат да се включат оптимизации в debug режим, без да се изключват останалите полезни проверки и опции

Това става като се добави в Cargo.toml

1 2
[profile.dev]
opt-level = 3

За повече информация: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections

Amethyst

Simple towers

Въпроси