F3+4 shows the lightmap texture in the bottom right corner
DebugScreenOverlay.toggleLightmapTexture and showLightmapTexture: the 16x16 lightmap at 64x64 on a black border, 2 pixels from the corner, sky light up and block light right, as vanilla's flipped blit. It shares the bottom of the screen with the F3+2 and F3+3 charts, so each switch turns the others off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,8 @@ pub struct DebugCharts {
|
||||
pub fps: bool,
|
||||
/// `renderNetworkCharts` (F3+3).
|
||||
pub network: bool,
|
||||
/// `renderLightmapTexture` (F3+4).
|
||||
pub lightmap: bool,
|
||||
/// `frameTimeLogger`: nanoseconds between frames.
|
||||
pub frame_times: SampleLogger,
|
||||
/// `tickTimeLogger`: the integrated server's ticks.
|
||||
@@ -80,6 +82,7 @@ impl DebugCharts {
|
||||
if self.fps {
|
||||
*overlay = true;
|
||||
self.network = false;
|
||||
self.lightmap = false;
|
||||
}
|
||||
}
|
||||
/// `toggleNetworkCharts`.
|
||||
@@ -88,6 +91,16 @@ impl DebugCharts {
|
||||
if self.network {
|
||||
*overlay = true;
|
||||
self.fps = false;
|
||||
self.lightmap = false;
|
||||
}
|
||||
}
|
||||
/// `toggleLightmapTexture`.
|
||||
pub fn toggle_lightmap(&mut self, overlay: &mut bool) {
|
||||
self.lightmap = !*overlay || !self.lightmap;
|
||||
if self.lightmap {
|
||||
*overlay = true;
|
||||
self.fps = false;
|
||||
self.network = false;
|
||||
}
|
||||
}
|
||||
/// `reset`: leaving a world.
|
||||
@@ -165,6 +178,22 @@ impl DebugCharts {
|
||||
}
|
||||
}
|
||||
|
||||
/// The lightmap view (`showLightmapTexture`): the 16 by 16 texture at 64
|
||||
/// by 64 in the bottom right corner on a black border, sky light up and
|
||||
/// block light right (the blit flips the texture's rows). `pixels` are RGBA
|
||||
/// rows of sky level by block level.
|
||||
pub fn lightmap(pixels: &[u8; 16 * 16 * 4], width: i32, height: i32) -> Vec<GuiDraw> {
|
||||
let (x, y) = (width - 64 - 2, height - 64 - 2);
|
||||
let mut out = vec![fill(x - 1, y - 1, x + 64 + 1, y + 64 + 1, 0xFF00_0000)];
|
||||
for (i, p) in pixels.as_chunks::<4>().0.iter().enumerate() {
|
||||
let (sky, block) = ((i / 16) as i32, (i % 16) as i32);
|
||||
let color = argb(255, u32::from(p[0]), u32::from(p[1]), u32::from(p[2]));
|
||||
let (cx, cy) = (x + block * 4, y + (15 - sky) * 4);
|
||||
out.push(fill(cx, cy, cx + 4, cy + 4, color));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The four charts and what each needs to scale its bars.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Chart {
|
||||
@@ -470,6 +499,9 @@ mod tests {
|
||||
assert!(c.network && !c.fps);
|
||||
c.toggle_network(&mut overlay);
|
||||
assert!(!c.network && overlay);
|
||||
c.toggle_lightmap(&mut overlay);
|
||||
c.toggle_fps(&mut overlay);
|
||||
assert!(c.fps && !c.lightmap);
|
||||
// With the overlay hidden, the key shows it again with the chart on.
|
||||
c.toggle_fps(&mut overlay);
|
||||
overlay = false;
|
||||
@@ -477,6 +509,17 @@ mod tests {
|
||||
assert!(overlay && c.fps);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_lightmap_puts_full_sky_light_at_the_top_left() {
|
||||
let mut pixels = [0u8; 16 * 16 * 4];
|
||||
// Sky 15, block 0: the last row's first texel.
|
||||
pixels[15 * 64..15 * 64 + 4].copy_from_slice(&[10, 20, 30, 255]);
|
||||
let draws = lightmap(&pixels, 427, 240);
|
||||
assert_eq!(draws[0], fill(360, 173, 426, 239, 0xFF00_0000));
|
||||
assert_eq!(draws.len(), 257);
|
||||
assert!(draws.contains(&fill(361, 174, 365, 178, 0xFF0A_141E)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ticks_and_bandwidth_log_their_differences() {
|
||||
let mut c = DebugCharts::default();
|
||||
|
||||
Reference in New Issue
Block a user