limit text cache size. work on build scripts again [rebuild]

This commit is contained in:
Dustin Carlino 2020-02-08 13:25:48 -08:00
parent a5e9505fd2
commit 0fc864ee51
6 changed files with 13 additions and 20 deletions

View File

@ -9,5 +9,5 @@ unzip release_data.zip
mv release_data/* data
rmdir release_data
rm -f release_data.zip
# TODO Can't do this automatically, because it fails when called from Github Actions?
echo "You probably need to run 'git checkout data/system' to fix the gitignore files that were deleted by running this script"
# The zip clobbers the .gitignore symlinks; just let git take care of it
git checkout data/system

View File

@ -17,6 +17,7 @@ glium = "0.25.1"
glutin = "0.22.0"
htmlescape = "0.3.1"
image = "0.22.2"
lru = "0.4.3"
lyon = "0.14.2"
ordered-float = "1.0.1"
serde = "1.0.98"

View File

@ -1,5 +1,6 @@
use crate::text::Font;
use crate::{text, GeomBatch};
use lru::LruCache;
use std::cell::RefCell;
use std::collections::HashMap;
use usvg::Options;
@ -8,7 +9,7 @@ use usvg::Options;
pub struct Assets {
pub default_line_height: f64,
pub default_font_size: usize,
text_cache: RefCell<HashMap<String, GeomBatch>>,
text_cache: RefCell<LruCache<String, GeomBatch>>,
line_height_cache: RefCell<HashMap<(Font, usize), f64>>,
pub text_opts: Options,
}
@ -18,7 +19,7 @@ impl Assets {
let mut a = Assets {
default_line_height: 0.0,
default_font_size,
text_cache: RefCell::new(HashMap::new()),
text_cache: RefCell::new(LruCache::new(500)),
line_height_cache: RefCell::new(HashMap::new()),
text_opts: Options::default(),
};
@ -50,13 +51,11 @@ impl Assets {
height
}
pub fn get_cached_text(&self, key: &str) -> Option<GeomBatch> {
self.text_cache.borrow().get(key).cloned()
pub fn get_cached_text(&self, key: &String) -> Option<GeomBatch> {
self.text_cache.borrow_mut().get(key).cloned()
}
pub fn cache_text(&self, key: String, geom: GeomBatch) {
self.text_cache.borrow_mut().insert(key, geom);
//println!("cache has {} things",
// abstutil::prettyprint_usize(self.text_cache.borrow().len()));
self.text_cache.borrow_mut().put(key, geom);
}
}

View File

@ -243,7 +243,6 @@ impl Canvas {
HorizontalAlignment::Left => 0.0,
HorizontalAlignment::Center => (self.window_width - dims.width) / 2.0,
HorizontalAlignment::Right => self.window_width - dims.width,
HorizontalAlignment::FillScreen => 0.0,
HorizontalAlignment::Percent(pct) => pct * self.window_width,
HorizontalAlignment::Centered(x) => x - (dims.width / 2.0),
};
@ -266,7 +265,6 @@ pub enum HorizontalAlignment {
Left,
Center,
Right,
FillScreen,
Percent(f64),
Centered(f64),
}

View File

@ -237,13 +237,8 @@ impl<'a> GfxCtx<'a> {
txt: Text,
(horiz, vert): (HorizontalAlignment, VerticalAlignment),
) {
let mut dims = txt.clone().dims(&self.prerender.assets);
let dims = txt.clone().dims(&self.prerender.assets);
let top_left = self.canvas.align_window(dims, horiz, vert);
// TODO This doesn't take effect anymore
if let HorizontalAlignment::FillScreen = horiz {
dims.width = self.canvas.window_width;
}
self.draw_blocking_text_at_screenspace_topleft(txt, top_left);
}

View File

@ -7,16 +7,16 @@ output=$1;
runner=$2;
binary=$3;
./data/grab_minimal_seed_data.sh
mkdir $output
cd $output
../data/grab_minimal_seed_data.sh
cd ..
cp docs/INSTRUCTIONS.md $output
cp release/$runner $output
mkdir $output/game
cp $binary $output/game
cp -Rv game/assets $output/game
cp -Rv data $output/data
# TODO Github will double-zip this, but if we just pass the directory, then the
# chmod +x bits get lost