 11b41206eb
			
		
	
	
		11b41206eb
		
	
	
	
	
		
			
			This updates the `pipelined-rendering` branch to use the latest `bevy_ecs` from `main`. This accomplishes a couple of goals: 1. prepares for upcoming `custom-shaders` branch changes, which were what drove many of the recent bevy_ecs changes on `main` 2. prepares for the soon-to-happen merge of `pipelined-rendering` into `main`. By including bevy_ecs changes now, we make that merge simpler / easier to review. I split this up into 3 commits: 1. **add upstream bevy_ecs**: please don't bother reviewing this content. it has already received thorough review on `main` and is a literal copy/paste of the relevant folders (the old folders were deleted so the directories are literally exactly the same as `main`). 2. **support manual buffer application in stages**: this is used to enable the Extract step. we've already reviewed this once on the `pipelined-rendering` branch, but its worth looking at one more time in the new context of (1). 3. **support manual archetype updates in QueryState**: same situation as (2).
		
			
				
	
	
		
			97 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			97 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use bevy::{prelude::*, text::FontAtlasSet};
 | |
| 
 | |
| // TODO: This is now broken. See #1243
 | |
| /// This example illustrates how FontAtlases are populated. Bevy uses FontAtlases under the hood to
 | |
| /// optimize text rendering.
 | |
| fn main() {
 | |
|     App::new()
 | |
|         .init_resource::<State>()
 | |
|         .insert_resource(ClearColor(Color::BLACK))
 | |
|         .add_plugins(DefaultPlugins)
 | |
|         .add_startup_system(setup)
 | |
|         .add_system(text_update_system)
 | |
|         .add_system(atlas_render_system)
 | |
|         .run();
 | |
| }
 | |
| 
 | |
| struct State {
 | |
|     atlas_count: u32,
 | |
|     handle: Handle<Font>,
 | |
|     timer: Timer,
 | |
| }
 | |
| 
 | |
| impl Default for State {
 | |
|     fn default() -> Self {
 | |
|         Self {
 | |
|             atlas_count: 0,
 | |
|             handle: Handle::default(),
 | |
|             timer: Timer::from_seconds(0.05, true),
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| fn atlas_render_system(
 | |
|     mut commands: Commands,
 | |
|     mut state: ResMut<State>,
 | |
|     mut materials: ResMut<Assets<ColorMaterial>>,
 | |
|     font_atlas_sets: Res<Assets<FontAtlasSet>>,
 | |
|     texture_atlases: Res<Assets<TextureAtlas>>,
 | |
| ) {
 | |
|     if let Some(set) = font_atlas_sets.get(&state.handle.as_weak::<FontAtlasSet>()) {
 | |
|         if let Some((_size, font_atlas)) = set.iter().next() {
 | |
|             let x_offset = state.atlas_count as f32;
 | |
|             if state.atlas_count == font_atlas.len() as u32 {
 | |
|                 return;
 | |
|             }
 | |
|             let texture_atlas = texture_atlases
 | |
|                 .get(&font_atlas[state.atlas_count as usize].texture_atlas)
 | |
|                 .unwrap();
 | |
|             state.atlas_count += 1;
 | |
|             commands.spawn_bundle(ImageBundle {
 | |
|                 material: materials.add(texture_atlas.texture.clone().into()),
 | |
|                 style: Style {
 | |
|                     position_type: PositionType::Absolute,
 | |
|                     position: Rect {
 | |
|                         top: Val::Px(0.0),
 | |
|                         left: Val::Px(512.0 * x_offset),
 | |
|                         ..Default::default()
 | |
|                     },
 | |
|                     ..Default::default()
 | |
|                 },
 | |
|                 ..Default::default()
 | |
|             });
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| fn text_update_system(mut state: ResMut<State>, time: Res<Time>, mut query: Query<&mut Text>) {
 | |
|     if state.timer.tick(time.delta()).finished() {
 | |
|         for mut text in query.iter_mut() {
 | |
|             let c = rand::random::<u8>() as char;
 | |
|             if !text.sections[0].value.contains(c) {
 | |
|                 text.sections[0].value.push(c);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         state.timer.reset();
 | |
|     }
 | |
| }
 | |
| 
 | |
| fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut state: ResMut<State>) {
 | |
|     let font_handle = asset_server.load("fonts/FiraSans-Bold.ttf");
 | |
|     state.handle = font_handle.clone();
 | |
|     commands.spawn_bundle(UiCameraBundle::default());
 | |
|     commands.spawn_bundle(TextBundle {
 | |
|         text: Text::with_section(
 | |
|             "a",
 | |
|             TextStyle {
 | |
|                 font: font_handle,
 | |
|                 font_size: 60.0,
 | |
|                 color: Color::YELLOW,
 | |
|             },
 | |
|             Default::default(),
 | |
|         ),
 | |
|         ..Default::default()
 | |
|     });
 | |
| }
 |