Merge branch 'imbris/fix' into 'master'

Fix glyph too large panic

See merge request veloren/veloren!1250
This commit is contained in:
Imbris 2020-07-31 06:31:22 +00:00
commit ea90ddce94
3 changed files with 28 additions and 32 deletions

View File

@ -48,7 +48,6 @@ pub fn handle_lantern(server: &mut Server, entity: EcsEntity) {
} }
} }
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
pub fn handle_mount(server: &mut Server, mounter: EcsEntity, mountee: EcsEntity) { pub fn handle_mount(server: &mut Server, mounter: EcsEntity, mountee: EcsEntity) {
let state = server.state_mut(); let state = server.state_mut();
@ -58,24 +57,18 @@ pub fn handle_mount(server: &mut Server, mounter: EcsEntity, mountee: EcsEntity)
.get(mounter) .get(mounter)
.is_none() .is_none()
{ {
let not_mounting_yet = if let Some(comp::MountState::Unmounted) = state let not_mounting_yet = matches!(
.ecs() state.ecs().read_storage::<comp::MountState>().get(mountee),
.read_storage::<comp::MountState>() Some(comp::MountState::Unmounted)
.get(mountee) );
.cloned()
{
true
} else {
false
};
if not_mounting_yet { if not_mounting_yet {
if let (Some(mounter_uid), Some(mountee_uid)) = ( if let (Some(mounter_uid), Some(mountee_uid)) = (
state.ecs().uid_from_entity(mounter), state.ecs().uid_from_entity(mounter),
state.ecs().uid_from_entity(mountee), state.ecs().uid_from_entity(mountee),
) { ) {
state.write_component(mountee, comp::MountState::MountedBy(mounter_uid.into())); state.write_component(mountee, comp::MountState::MountedBy(mounter_uid));
state.write_component(mounter, comp::Mounting(mountee_uid.into())); state.write_component(mounter, comp::Mounting(mountee_uid));
} }
} }
} }

View File

@ -911,7 +911,8 @@ impl Hud {
// Increase font size based on fraction of maximum health // Increase font size based on fraction of maximum health
// "flashes" by having a larger size in the first 100ms // "flashes" by having a larger size in the first 100ms
let font_size_xp = 30 let font_size_xp = 30
+ (exp_change.abs() as f32 / stats.exp.maximum() as f32 * 50.0) as u32 + ((exp_change.abs() as f32 / stats.exp.maximum() as f32).min(1.0)
* 50.0) as u32
+ if timer < 0.1 { + if timer < 0.1 {
(FLASH_MAX * (1.0 - timer / 0.1)) as u32 (FLASH_MAX * (1.0 - timer / 0.1)) as u32
} else { } else {
@ -953,7 +954,8 @@ impl Hud {
// Increase font size based on fraction of maximum health // Increase font size based on fraction of maximum health
// "flashes" by having a larger size in the first 100ms // "flashes" by having a larger size in the first 100ms
let font_size_xp = 30 let font_size_xp = 30
+ (floater.exp_change.abs() as f32 / stats.exp.maximum() as f32 + ((floater.exp_change.abs() as f32 / stats.exp.maximum() as f32)
.min(1.0)
* 50.0) as u32 * 50.0) as u32
+ if floater.timer < 0.1 { + if floater.timer < 0.1 {
(FLASH_MAX * (1.0 - floater.timer / 0.1)) as u32 (FLASH_MAX * (1.0 - floater.timer / 0.1)) as u32

View File

@ -90,11 +90,10 @@ pub struct Font(text::Font);
impl assets::Asset for Font { impl assets::Asset for Font {
const ENDINGS: &'static [&'static str] = &["ttf"]; const ENDINGS: &'static [&'static str] = &["ttf"];
#[allow(clippy::redundant_clone)] // TODO: Pending review in #587
fn parse(mut buf_reader: BufReader<File>) -> Result<Self, assets::Error> { fn parse(mut buf_reader: BufReader<File>) -> Result<Self, assets::Error> {
let mut buf = Vec::new(); let mut buf = Vec::new();
buf_reader.read_to_end(&mut buf)?; buf_reader.read_to_end(&mut buf)?;
Ok(Font(text::Font::from_bytes(buf.clone()).unwrap())) Ok(Font(text::Font::from_bytes(buf).unwrap()))
} }
} }
@ -588,23 +587,25 @@ impl Ui {
glyph_cache.queue_glyph(font_id.index(), glyph.clone()); glyph_cache.queue_glyph(font_id.index(), glyph.clone());
} }
glyph_cache if let Err(err) = glyph_cache.cache_queued(|rect, data| {
.cache_queued(|rect, data| { let offset = [rect.min.x as u16, rect.min.y as u16];
let offset = [rect.min.x as u16, rect.min.y as u16]; let size = [rect.width() as u16, rect.height() as u16];
let size = [rect.width() as u16, rect.height() as u16];
let new_data = data let new_data = data
.iter() .iter()
.map(|x| [255, 255, 255, *x]) .map(|x| [255, 255, 255, *x])
.collect::<Vec<[u8; 4]>>(); .collect::<Vec<[u8; 4]>>();
if let Err(err) = if let Err(err) =
renderer.update_texture(cache_tex, offset, size, &new_data) renderer.update_texture(cache_tex, offset, size, &new_data)
{ {
warn!("Failed to update texture: {:?}", err); warn!("Failed to update texture: {:?}", err);
} }
}) }) {
.unwrap(); warn!("Failed to cache queued glyphs: {:?}", err);
// Clear uncachable glyphs from the queue
glyph_cache.clear_queue();
}
let color = srgba_to_linear(color.to_fsa().into()); let color = srgba_to_linear(color.to_fsa().into());