Fix glyph to large panic

This commit is contained in:
Imbris 2020-07-31 01:13:31 -04:00
parent 66c7a18403
commit f589564760
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) {
let state = server.state_mut();
@ -58,24 +57,18 @@ pub fn handle_mount(server: &mut Server, mounter: EcsEntity, mountee: EcsEntity)
.get(mounter)
.is_none()
{
let not_mounting_yet = if let Some(comp::MountState::Unmounted) = state
.ecs()
.read_storage::<comp::MountState>()
.get(mountee)
.cloned()
{
true
} else {
false
};
let not_mounting_yet = matches!(
state.ecs().read_storage::<comp::MountState>().get(mountee),
Some(comp::MountState::Unmounted)
);
if not_mounting_yet {
if let (Some(mounter_uid), Some(mountee_uid)) = (
state.ecs().uid_from_entity(mounter),
state.ecs().uid_from_entity(mountee),
) {
state.write_component(mountee, comp::MountState::MountedBy(mounter_uid.into()));
state.write_component(mounter, comp::Mounting(mountee_uid.into()));
state.write_component(mountee, comp::MountState::MountedBy(mounter_uid));
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
// "flashes" by having a larger size in the first 100ms
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 {
(FLASH_MAX * (1.0 - timer / 0.1)) as u32
} else {
@ -953,7 +954,8 @@ impl Hud {
// Increase font size based on fraction of maximum health
// "flashes" by having a larger size in the first 100ms
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
+ if floater.timer < 0.1 {
(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 {
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> {
let mut buf = Vec::new();
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
.cache_queued(|rect, data| {
let offset = [rect.min.x as u16, rect.min.y as u16];
let size = [rect.width() as u16, rect.height() as u16];
if let Err(err) = glyph_cache.cache_queued(|rect, data| {
let offset = [rect.min.x as u16, rect.min.y as u16];
let size = [rect.width() as u16, rect.height() as u16];
let new_data = data
.iter()
.map(|x| [255, 255, 255, *x])
.collect::<Vec<[u8; 4]>>();
let new_data = data
.iter()
.map(|x| [255, 255, 255, *x])
.collect::<Vec<[u8; 4]>>();
if let Err(err) =
renderer.update_texture(cache_tex, offset, size, &new_data)
{
warn!("Failed to update texture: {:?}", err);
}
})
.unwrap();
if let Err(err) =
renderer.update_texture(cache_tex, offset, size, &new_data)
{
warn!("Failed to update texture: {:?}", err);
}
}) {
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());