fix(runtime): bound camera resolver work and handle extreme coordinates
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Preserve camera hysteresis with constant-time wide arithmetic, refresh nonoverlapping cache jumps, and clip wide offsets before drawing. Add guest pixel-oracle and resource/snapshot regressions and document the contract. Validated by the complete tooling verify run 20261126T113331Z-1d071c1d (all 11 stages passed), plus focused debug/release tests. Work: WRK-0020.
This commit is contained in:
@@ -770,16 +770,16 @@ impl Gfx {
|
||||
);
|
||||
};
|
||||
|
||||
let tile_size_px = request.tile_size as i32;
|
||||
let tile_size_px = request.tile_size as i64;
|
||||
for cache_y in 0..layer_cache.height() {
|
||||
let screen_tile_y = cache_y as i32 * tile_size_px - request.source_offset_y_px;
|
||||
if screen_tile_y >= screen_h as i32 || screen_tile_y + tile_size_px <= 0 {
|
||||
let screen_tile_y = cache_y as i64 * tile_size_px - request.source_offset_y_px;
|
||||
if screen_tile_y >= screen_h as i64 || screen_tile_y + tile_size_px <= 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
for cache_x in 0..layer_cache.width() {
|
||||
let screen_tile_x = cache_x as i32 * tile_size_px - request.source_offset_x_px;
|
||||
if screen_tile_x >= screen_w as i32 || screen_tile_x + tile_size_px <= 0 {
|
||||
let screen_tile_x = cache_x as i64 * tile_size_px - request.source_offset_x_px;
|
||||
if screen_tile_x >= screen_w as i64 || screen_tile_x + tile_size_px <= 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -791,8 +791,10 @@ impl Gfx {
|
||||
Self::draw_cached_tile_pixels(
|
||||
&mut target,
|
||||
CachedTileDraw {
|
||||
x: screen_tile_x,
|
||||
y: screen_tile_y,
|
||||
// Culling leaves -tile_size < local < screen extent;
|
||||
// only these small local coordinates enter the pixel loop.
|
||||
x: i32::try_from(screen_tile_x).expect("visible tile x must fit Int32"),
|
||||
y: i32::try_from(screen_tile_y).expect("visible tile y must fit Int32"),
|
||||
entry,
|
||||
bank: &bank,
|
||||
tile_size: request.tile_size,
|
||||
|
||||
@@ -107,3 +107,55 @@ fn native_tile_edges_and_mixed_camera_layers_cover_every_corner() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cache_tiles_are_clipped_in_wide_coordinates_before_local_pixel_drawing() {
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
let mut bank = GlyphBank::new(TileSize::Size8, 8, 8);
|
||||
bank.pixel_indices.fill(1);
|
||||
bank.palettes[0][1] = Color::WHITE;
|
||||
banks.install_glyph_bank(0, Arc::new(bank));
|
||||
let scene = SceneBank {
|
||||
layers: std::array::from_fn(|_| SceneLayer {
|
||||
active: true,
|
||||
glyph_asset_id: 0,
|
||||
tile_size: TileSize::Size8,
|
||||
parallax_factor: ParallaxFactor { x: 1.0, y: 1.0 },
|
||||
tilemap: TileMap {
|
||||
width: 128,
|
||||
height: 128,
|
||||
tiles: vec![
|
||||
Tile {
|
||||
active: true,
|
||||
glyph: Glyph { glyph_id: 0, palette_id: 0 },
|
||||
flip_x: false,
|
||||
flip_y: false,
|
||||
};
|
||||
128 * 128
|
||||
],
|
||||
},
|
||||
}),
|
||||
};
|
||||
let mut resolver = SceneViewportResolver::new(640, 360, 85, 49, 4, 12);
|
||||
let mut cache = SceneViewportCache::new(&scene, 85, 49);
|
||||
cache.materialize_all_layers(&scene);
|
||||
let mut gfx = Gfx::new(WIDTH, HEIGHT, banks);
|
||||
let mut update = resolver.update(&scene, 0, 0);
|
||||
gfx.render_scene_from_cache(&cache, &update, &[0; 4]);
|
||||
gfx.present();
|
||||
assert!(gfx.front_buffer().iter().all(|&p| p == Color::WHITE.raw()));
|
||||
for offset in [i64::from(i32::MIN), i64::from(i32::MAX), -(1_i64 << 37), 1_i64 << 37] {
|
||||
for vertical in [false, true] {
|
||||
for copy in &mut update.copy_requests {
|
||||
copy.source_offset_x_px = if vertical { 0 } else { offset };
|
||||
copy.source_offset_y_px = if vertical { offset } else { 0 };
|
||||
}
|
||||
gfx.render_scene_from_cache(&cache, &update, &[0; 4]);
|
||||
gfx.present();
|
||||
assert!(
|
||||
gfx.front_buffer().iter().all(|&p| p == Color::BLACK.raw()),
|
||||
"off-scene offset={offset}, vertical={vertical}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user