Skip to content

Commit

Permalink
Upgrade to Bevy 0.9 & fix CI (#19)
Browse files Browse the repository at this point in the history
* Upgrade bevy to 0.9.0
* Use dtolnay rust toolchain
* Fix CI, remove MacOS check
  • Loading branch information
blaind authored Nov 13, 2022
1 parent bf635ad commit ba473ee
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 79 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: test

on: [push, pull_request]

env:
CARGO_TERM_COLOR: always

jobs:
test:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
rust: [stable, nightly]
runs-on: ${{ matrix.os }}

steps:
- name: Install dependencies
run: sudo apt-get install gcc patch libudev-dev
if: runner.os == 'linux'

- uses: actions/checkout@v2

- uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{matrix.rust}}

- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Run tests
run: cargo test --verbose
47 changes: 0 additions & 47 deletions .github/workflows/test.yml

This file was deleted.

10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog

[git_tag_comparison]: https://github.com/blaind/bevy_text_mesh/compare/v0.4.0...main
[git_tag_comparison]: https://github.com/blaind/bevy_text_mesh/compare/v0.5.0...main

## Version 0.5.0 (2022-11-13)

[Compare changelog](https://github.com/blaind/bevy_text_mesh/compare/v0.4.0...v0.5.0)

### Changed

- Upgrade bevy to 0.9.0

## Version 0.4.0 (2022-10-24)

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_text_mesh"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
description = "A bevy 3D text mesh generator for displaying text"
repository = "https://github.com/blaind/bevy_text_mesh"
Expand All @@ -18,15 +18,15 @@ anyhow = "1.0"
glyph_brush_layout = "0.2.3"

[dependencies.bevy]
version = "0.8.0"
version = "0.9.0"
default-features = false
features = ["render", "bevy_asset"]

[dev-dependencies]
rand = "0.8.4"

[dev-dependencies.bevy]
version = "0.8.0"
version = "0.9.0"
default-features = false
features = [
"bevy_winit",
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Consider this as a preview of the plugin for gathering feedback about the API:

| bevy | bevy_text_mesh |
| ---- | -------------- |
| 0.9 | 0.5.0 |
| 0.8 | 0.4.0 |
| 0.7 | 0.2.0 |
| 0.6 | 0.1.0 |
Expand Down Expand Up @@ -58,7 +59,7 @@ Add to Cargo.toml:

```
[dependencies]
bevy_text_mesh = "0.4.0"
bevy_text_mesh = "0.5.0"
```

Include the library:
Expand Down Expand Up @@ -94,7 +95,7 @@ let font: Handle<TextMeshFont> = asset_server.load("fonts/FiraSans-Medium.ttf#me
Then, spawn a textmesh bundle:

```rust
commands.spawn_bundle(TextMeshBundle {
commands.spawn(TextMeshBundle {
text_mesh: TextMesh::new_with_color("Hello Bevy", font, Color::rgb(1., 1., 0.)),
transform: Transform::from_xyz(-1., 1.75, 0.),
..Default::default()
Expand All @@ -104,7 +105,7 @@ commands.spawn_bundle(TextMeshBundle {
Or with expanded syntax:

```rust
commands.spawn_bundle(TextMeshBundle {
commands.spawn(TextMeshBundle {
text_mesh: TextMesh {
text: String::from("Hello Bevy!"),
style: TextMeshStyle {
Expand Down
6 changes: 3 additions & 3 deletions examples/2d_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
};
let text_alignment = TextAlignment::CENTER;

commands.spawn_bundle(Camera2dBundle::default());
commands.spawn(Camera2dBundle::default());
commands
.spawn_bundle(Text2dBundle {
.spawn(Text2dBundle {
text: Text::from_section("standard 2d text works too", text_style.clone())
.with_alignment(text_alignment),
..default()
Expand All @@ -35,6 +35,6 @@ fn animate_rotation(
mut query: Query<&mut Transform, (With<Text>, With<AnimateRotation>)>,
) {
for mut transform in &mut query {
transform.rotation = Quat::from_rotation_z(time.seconds_since_startup().cos() as f32);
transform.rotation = Quat::from_rotation_z(time.elapsed_seconds_f64().cos() as f32);
}
}
19 changes: 10 additions & 9 deletions examples/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
fn setup_text_mesh(mut commands: Commands, asset_server: Res<AssetServer>) {
let font: Handle<TextMeshFont> = asset_server.load("fonts/FiraMono-Medium.ttf#mesh");

commands.spawn_bundle(TextMeshBundle {
commands.spawn(TextMeshBundle {
text_mesh: TextMesh {
text: String::from("Time since startup"),
style: TextMeshStyle {
Expand All @@ -40,7 +40,7 @@ fn setup_text_mesh(mut commands: Commands, asset_server: Res<AssetServer>) {
});

commands
.spawn_bundle(TextMeshBundle {
.spawn(TextMeshBundle {
text_mesh: TextMesh {
text: String::from("0"),
style: TextMeshStyle {
Expand All @@ -61,10 +61,11 @@ fn setup_text_mesh(mut commands: Commands, asset_server: Res<AssetServer>) {
.insert(EngineTime);

commands.insert_resource(UpdateTimer {
timer: Timer::new(Duration::from_millis(100), true),
timer: Timer::new(Duration::from_millis(100), TimerMode::Repeating),
});
}

#[derive(Resource)]
struct UpdateTimer {
timer: Timer,
}
Expand All @@ -79,7 +80,7 @@ fn update_text_mesh(
) {
if timer.timer.tick(time.delta()).just_finished() {
for mut text_mesh in text_meshes.iter_mut() {
let updated_text = String::from(format!("Time = {:.3}", time.seconds_since_startup()));
let updated_text = String::from(format!("Time = {:.3}", time.elapsed_seconds_f64()));

if text_mesh.text != updated_text {
text_mesh.text = updated_text;
Expand All @@ -90,7 +91,7 @@ fn update_text_mesh(

fn rotate_camera(mut camera: Query<&mut Transform, With<Camera>>, time: Res<Time>) {
for mut camera in camera.iter_mut() {
let angle = time.seconds_since_startup() as f32 / 2. + 1.55 * std::f32::consts::PI;
let angle = time.elapsed_seconds_f64() as f32 / 2. + 1.55 * std::f32::consts::PI;

let distance = 3.5;

Expand All @@ -110,22 +111,22 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
});
commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
Expand Down
30 changes: 18 additions & 12 deletions examples/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ fn main() {
.run();
}

#[derive(Resource)]
struct SceneState {
font: Handle<TextMeshFont>,
material: Handle<StandardMaterial>,
text_count: usize,
text_update_count: usize,
}

#[derive(Resource)]
struct UpdateTimer {
spawn_new_text_timer: Timer,
fps_update_timer: Timer,
Expand Down Expand Up @@ -86,7 +88,7 @@ fn setup_text_mesh(
};

commands
.spawn_bundle(TextMeshBundle {
.spawn(TextMeshBundle {
text_mesh: TextMesh {
text: String::from("FPS"),
style: TextMeshStyle {
Expand All @@ -103,7 +105,7 @@ fn setup_text_mesh(
.insert(FPS);

commands
.spawn_bundle(TextMeshBundle {
.spawn(TextMeshBundle {
text_mesh: TextMesh {
text: String::from("Text count"),
style: TextMeshStyle {
Expand All @@ -122,11 +124,14 @@ fn setup_text_mesh(
commands.insert_resource(state);

commands.insert_resource(UpdateTimer {
spawn_new_text_timer: Timer::new(Duration::from_millis(INITIAL_WAIT_MS), false),
text_update_timer: Timer::new(Duration::from_millis(TEXT_UPDATE_INTERVAL_MS), true),
spawn_new_text_timer: Timer::new(Duration::from_millis(INITIAL_WAIT_MS), TimerMode::Once),
text_update_timer: Timer::new(
Duration::from_millis(TEXT_UPDATE_INTERVAL_MS),
TimerMode::Repeating,
),

// how often FPS text is updated
fps_update_timer: Timer::new(Duration::from_millis(150), true),
fps_update_timer: Timer::new(Duration::from_millis(150), TimerMode::Repeating),
});
}

Expand All @@ -141,7 +146,8 @@ fn spawn_meshes(
.tick(time.delta())
.just_finished()
{
timer.spawn_new_text_timer = Timer::new(Duration::from_millis(TEXT_SPAWN_INTERVAL), false);
timer.spawn_new_text_timer =
Timer::new(Duration::from_millis(TEXT_SPAWN_INTERVAL), TimerMode::Once);

let mut rng = rand::thread_rng(); // how performant is this?

Expand All @@ -160,7 +166,7 @@ fn spawn_meshes(
);

commands
.spawn_bundle(TextMeshBundle {
.spawn(TextMeshBundle {
text_mesh: TextMesh {
text: String::from(""),
style: TextMeshStyle {
Expand Down Expand Up @@ -190,7 +196,7 @@ fn update_text_mesh(
let mut update_count = 0;
if timer.text_update_timer.tick(time.delta()).just_finished() {
for mut text_mesh in text_meshes.iter_mut() {
let updated_text = String::from(format!("Time = {:.3}", time.seconds_since_startup()));
let updated_text = String::from(format!("Time = {:.3}", time.elapsed_seconds_f64()));

if text_mesh.text != updated_text {
text_mesh.text = updated_text;
Expand All @@ -205,7 +211,7 @@ fn update_text_mesh(

fn rotate_camera(mut camera: Query<&mut Transform, With<Camera>>, time: Res<Time>) {
for mut camera in camera.iter_mut() {
let angle = time.seconds_since_startup() as f32 / 2. + 1.55 * std::f32::consts::PI;
let angle = time.elapsed_seconds_f64() as f32 / 2. + 1.55 * std::f32::consts::PI;

let distance = 6.5;

Expand Down Expand Up @@ -256,16 +262,16 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
Expand Down
3 changes: 3 additions & 0 deletions src/mesh_cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{collections::HashMap, hash::Hash};

use bevy::prelude::*;

// TODO: add accuracy to depth cache
// TODO: purge cached entries, keep count per depth, and if it reaches zero
// TODO: actually cache meshdata
Expand Down Expand Up @@ -38,6 +40,7 @@ impl Hash for Depth {
// FIXME uhm, empty?
impl Eq for Depth {}

#[derive(Resource)]
pub struct MeshCache {
pub(crate) meshes: HashMap<CacheKey, ttf2mesh::Mesh<'static, ttf2mesh::Mesh3d>>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/mesh_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub(crate) fn text_mesh(

apply_mesh(ttf2_mesh, &mut mesh);

commands.entity(entity).insert_bundle(PbrBundle {
commands.entity(entity).insert(PbrBundle {
mesh: meshes.add(mesh),
material: material.map(|m| m.clone()).unwrap_or_else(|| {
materials.add(StandardMaterial {
Expand Down

0 comments on commit ba473ee

Please sign in to comment.