Bevy Engine

學海無涯,思境無維;數乃六藝,理之始也。
或有一得足矣 愚千慮

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

https://bevyengine.org/

Bevy Book

App & AppBuilder

App indicate the application which control the life time of the app.

AppBuilder just like a helper to add plugins, resources, systems into the stage, and the systems (game logics)
would be triggered every frame to update the entities on stage(scene), finally the renderer would render the scence.

Window

via Winit to cross platform(native window)

ECS

  • entities(as character instances) with components(a bundle of properties)
  • systems (for game logic)

system can query the components to manipulate the properties, ex:

  • sprite animation system
  • render system

add_system()

  • add the system into stage, triggered every frame.

other systems

  • audio
  • text
  • font
  • network
  • ui
  • input
  • graphics(2d/3d)
  • phsyics

Component

Registered components must implement the Properties and FromResources traits.

The Properties trait enables serialization, deserialization, dynamic property access, and change detection.

Properties enable a bunch of cool behaviors, so its worth checking out the dedicated properties.rs example.

The FromResources trait determines how your component is constructed when it loads. For simple use cases you can just implement the Default trait (which automatically implements FromResources). The simplest registered component just needs these two derives:

#[derive(Properties, Default)]
struct ComponentA {
    pub x: f32,
    pub y: f32,
}

Some components have fields that cannot (or should not) be written to scene files. These can be ignored with the #[property(ignore)] attribute. This is also generally where the FromResources trait comes into play.

#[derive(Properties)]
struct ComponentB {
    pub value: String,
    #[property(ignore)]
    pub time_since_startup: Duration,
}

FromResources gives you access to your App's current ECS Resources when you construct your component.

Resource

Res<T> : Shared borrow of an entity's component.
ResMut<T> : Unique borrow of an entity's component.
Resources : A collection of resource instances identified by their type.

Compile Time

cargo build --release

is much faster then

cargo build (debug)

spawn/despwan

world.rs
commands.rs

Custom Game Loop

fn game_loop() {
    ...
}

App::build()
    .set_runner(game_loop)

Math

bevy use glam for SIMD support.
https://docs.rs/glam/0.11.0/glam/

Misc

  • Assets<T>
Assets<ColorMaterial>
  • bevy::ecs/core/bundle.rs(DynamicBundle)
    • SpriteBundle
    • Camera2dBundle
  • Commands.spawn().with()
  • Handle { handleId, }
  • Cameras

Perspective Projections

  • near, far : distance from the camera (>= 0)
  • right-hand side rule: x -> right, y -> top, z is negative in front of the camera.
  • z value transform(from (-near, -far) normalized to -1~+1) is non-linear since we want more precision close to the camera and less precision far away from the camera.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

also the floating pointer number is more precision within -1~+1

Reference

Perspective Projections

tags: game dev rust bevy