mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Cleanup atlas allocator work, remaining TODO:
* refactor meshing and trait API to replace guillotiere types * associated config type on atlas trait * investigate other areas of sprite performance like LOD scaling (i.e. there are now significant gaps in between meshing)
This commit is contained in:
@ -268,10 +268,7 @@ fn main() {
|
|||||||
|
|
||||||
let clipboard = iced_winit::Clipboard::connect(window.window());
|
let clipboard = iced_winit::Clipboard::connect(window.window());
|
||||||
|
|
||||||
let mut lazy_init = SpriteRenderContext::new(window.renderer_mut());
|
let lazy_init = SpriteRenderContext::new(window.renderer_mut());
|
||||||
let _t = lazy_init(window.renderer_mut());
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(1000));
|
|
||||||
std::process::exit(0);
|
|
||||||
|
|
||||||
#[cfg(feature = "egui-ui")]
|
#[cfg(feature = "egui-ui")]
|
||||||
let egui_state = EguiState::new(&window);
|
let egui_state = EguiState::new(&window);
|
||||||
|
@ -136,17 +136,7 @@ impl AtlasAllocator for guillotiere::SimpleAtlasAllocator {
|
|||||||
fn size(&self) -> Vec2<i32> { self.size().to_array().into() }
|
fn size(&self) -> Vec2<i32> { self.size().to_array().into() }
|
||||||
|
|
||||||
/// Grows the size of the atlas to the provided size.
|
/// Grows the size of the atlas to the provided size.
|
||||||
fn grow(&mut self, new_size: Vec2<i32>) {
|
fn grow(&mut self, new_size: Vec2<i32>) { self.grow(guillotiere_size(new_size)) }
|
||||||
{
|
|
||||||
prof_span!("debug");
|
|
||||||
let free_space = self.free_space();
|
|
||||||
//let (lw, lh) = self.largest_free_size();
|
|
||||||
let area = self.size().width * self.size().height; // - lw * lh;
|
|
||||||
let used = area - free_space;
|
|
||||||
dbg!((used, free_space, area, area as f32 / used as f32,));
|
|
||||||
}
|
|
||||||
self.grow(guillotiere_size(new_size))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GuillotiereTiled {
|
pub struct GuillotiereTiled {
|
||||||
@ -167,28 +157,23 @@ pub struct GuillotiereTiled {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GuillotiereTiled {
|
impl GuillotiereTiled {
|
||||||
|
// We can potentially further optimize packing by deferring the allocations
|
||||||
|
// until all rectangles are available for packing.
|
||||||
|
//
|
||||||
// Tested with sprites:
|
// Tested with sprites:
|
||||||
// 64 1.63s 1.109 packing
|
// 64 1.63s 1.109 packing
|
||||||
// 128 1.65s 1.083 packing
|
// 128 1.65s 1.083 packing
|
||||||
// 256 1.77s 1.070 packing
|
// 256 1.77s 1.070 packing
|
||||||
// 512 2.27s 1.055 packing
|
// 512 2.27s 1.055 packing
|
||||||
// 1024 5.32s 1.045 packing (didn't fill up)
|
// 1024 5.32s 1.045 packing
|
||||||
// 2048 10.49s n/a packing (didn't fill up)
|
// 2048 10.49s n/a packing (didn't fill up)
|
||||||
const TILE_SIZE: u16 = 256;
|
const TILE_SIZE: u16 = 512;
|
||||||
|
|
||||||
fn allocator_options() -> guillotiere::AllocatorOptions {
|
fn allocator_options() -> guillotiere::AllocatorOptions {
|
||||||
// TODO: Collect information to see if we can choose a good value here.
|
// TODO: Collect information to see if we can choose a better value here (these
|
||||||
let large_size_threshold = 8; //256.min(min_max_dim / 2 + 1);
|
// values were picked before switching to this tiled implementation).
|
||||||
let small_size_threshold = 3; //33.min(large_size_threshold / 2 + 1);
|
let large_size_threshold = 8;
|
||||||
|
let small_size_threshold = 3;
|
||||||
// (12, 3) 24.5
|
|
||||||
// (12, 2) 33.2
|
|
||||||
// (12, 4) 27.2
|
|
||||||
// (14, 3) 25.6
|
|
||||||
// (10, 3) 20.9
|
|
||||||
// (8, 3) 17.9
|
|
||||||
// (6, 3) 18.0
|
|
||||||
// (5, 3) 18.0
|
|
||||||
|
|
||||||
guillotiere::AllocatorOptions {
|
guillotiere::AllocatorOptions {
|
||||||
alignment: guillotiere::Size::new(1, 1),
|
alignment: guillotiere::Size::new(1, 1),
|
||||||
@ -261,7 +246,6 @@ impl AtlasAllocator for GuillotiereTiled {
|
|||||||
None => self.next_tile(),
|
None => self.next_tile(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg!(size);
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -275,10 +259,8 @@ impl AtlasAllocator for GuillotiereTiled {
|
|||||||
|
|
||||||
/// Grows the size of the atlas to the provided size.
|
/// Grows the size of the atlas to the provided size.
|
||||||
fn grow(&mut self, new_size: Vec2<i32>) {
|
fn grow(&mut self, new_size: Vec2<i32>) {
|
||||||
{
|
if tracing::enabled!(tracing::Level::TRACE) {
|
||||||
prof_span!("debug");
|
tracing::trace!(
|
||||||
tracing::error!("here");
|
|
||||||
println!(
|
|
||||||
"Tile count: {}",
|
"Tile count: {}",
|
||||||
self.history.len() + self.free_tiles.len() + self.current.is_some() as usize
|
self.history.len() + self.free_tiles.len() + self.current.is_some() as usize
|
||||||
);
|
);
|
||||||
@ -288,21 +270,18 @@ impl AtlasAllocator for GuillotiereTiled {
|
|||||||
total_area += area;
|
total_area += area;
|
||||||
total_used += used;
|
total_used += used;
|
||||||
}
|
}
|
||||||
dbg!(total_area as f32 / total_used as f32);
|
tracing::trace!("Packing ratio: {}", total_area as f32 / total_used as f32);
|
||||||
}
|
}
|
||||||
|
|
||||||
let diff = (new_size - self.size()).map(|e| e.max(0));
|
let diff = (new_size - self.size()).map(|e| e.max(0));
|
||||||
dbg!(self.size());
|
// NOTE: `e` should fit in usize since it is a postive i32 (and we aren't
|
||||||
dbg!(new_size);
|
// targeting 16-bit platforms, although this will probably hit the max
|
||||||
dbg!(diff);
|
// texture size limit first regardless)
|
||||||
// TODO: as cast
|
|
||||||
// NOTE: growing only occurs in increments of tiles size so any remaining size
|
// NOTE: growing only occurs in increments of tiles size so any remaining size
|
||||||
// is ignored.
|
// is ignored.
|
||||||
let diff_tiles = diff.map(|e| e as usize / usize::from(Self::TILE_SIZE));
|
let diff_tiles = diff.map(|e| e as usize / usize::from(Self::TILE_SIZE));
|
||||||
dbg!(diff_tiles);
|
|
||||||
let old_size = self.size;
|
let old_size = self.size;
|
||||||
self.size += diff_tiles;
|
self.size += diff_tiles;
|
||||||
dbg!(self.size);
|
|
||||||
|
|
||||||
// Add new tiles to free tile list
|
// Add new tiles to free tile list
|
||||||
for x in old_size.x..self.size.x {
|
for x in old_size.x..self.size.x {
|
||||||
|
Reference in New Issue
Block a user