Skip to content

Commit 942bf8a

Browse files
committed
Fix audio buffer reporting and splash shortcuts alignment
1 parent aadf45a commit 942bf8a

2 files changed

Lines changed: 167 additions & 34 deletions

File tree

src/audio.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ pub fn spawn_dsp_thread(
127127
// Decay/smooth the execution stats for readability
128128
state.stats.fft_us = state.stats.fft_us * 0.9 + fft_elapsed * 0.1;
129129

130-
if let Some(cap) = rx.capacity() {
131-
state.stats.audio_buffer_fill_pct = (rx.len() as f32 / cap as f32) * 100.0;
130+
if state.stats.bitstream_active {
131+
if let Some(cap) = rx.capacity() {
132+
state.stats.audio_buffer_fill_pct = (rx.len() as f32 / cap as f32) * 100.0;
133+
}
132134
}
133135

134136
state.raw_channel_vus.clear();

src/engine.rs

Lines changed: 163 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,24 +1797,150 @@ impl<'a> VulkanEngine<'a> {
17971797
// --- Background Retro Grid (Demoscene Vibe) ---
17981798
let bg_painter = ctx.layer_painter(egui::LayerId::background());
17991799
let rect = ctx.content_rect();
1800-
let horizon_y = rect.top() + rect.height() * 0.20;
1800+
let horizon_y = rect.top() + rect.height() * 0.55;
18011801
let center_x = rect.center().x;
18021802

1803-
// Color cycle the grid slightly
1804-
let grid_hue = (time * 0.02).fract();
1805-
let grid_color: egui::Color32 = egui::ecolor::Hsva::new(grid_hue, 0.8, 1.0, 0.4).into();
1803+
// 1. Sky gradient
1804+
let sky_steps = 40;
1805+
let sky_height = horizon_y - rect.top();
1806+
for i in 0..sky_steps {
1807+
let t = i as f32 / sky_steps as f32;
1808+
let next_t = (i + 1) as f32 / sky_steps as f32;
1809+
let color = if t < 0.6 {
1810+
let st = t / 0.6;
1811+
egui::Color32::from_rgb(
1812+
(43.0 * (1.0 - st) + 150.0 * st) as u8,
1813+
(16.0 * (1.0 - st) + 20.0 * st) as u8,
1814+
(85.0 * (1.0 - st) + 120.0 * st) as u8,
1815+
)
1816+
} else {
1817+
let st = (t - 0.6) / 0.4;
1818+
egui::Color32::from_rgb(
1819+
(150.0 * (1.0 - st) + 255.0 * st) as u8,
1820+
(20.0 * (1.0 - st) + 126.0 * st) as u8,
1821+
(120.0 * (1.0 - st) + 103.0 * st) as u8,
1822+
)
1823+
};
1824+
bg_painter.rect_filled(
1825+
egui::Rect::from_min_max(
1826+
egui::pos2(rect.left(), rect.top() + t * sky_height),
1827+
egui::pos2(rect.right(), rect.top() + next_t * sky_height),
1828+
),
1829+
0.0,
1830+
color,
1831+
);
1832+
}
1833+
1834+
// 2. Stars
1835+
let pseudo_rand = |seed: u32| -> f32 {
1836+
let mut x = seed.wrapping_mul(136453);
1837+
x ^= x << 13;
1838+
x ^= x >> 17;
1839+
x ^= x << 5;
1840+
(x % 1000) as f32 / 1000.0
1841+
};
1842+
1843+
for i in 0..50 {
1844+
let rx = pseudo_rand(i * 31);
1845+
let ry = pseudo_rand(i * 31 + 1);
1846+
let rr = pseudo_rand(i * 31 + 2);
1847+
let rt = pseudo_rand(i * 31 + 3);
1848+
1849+
let x = rect.left() + rx * rect.width();
1850+
let y = rect.top() + ry * sky_height * 0.7; // Stars in upper 70%
1851+
let radius = rr * 1.5 + 0.5;
1852+
let twinkle = ((time * (1.0 + rt * 2.0) + rx * 100.0).sin() * 0.5 + 0.5) * 200.0 + 55.0;
1853+
1854+
bg_painter.circle_filled(
1855+
egui::pos2(x, y),
1856+
radius,
1857+
egui::Color32::from_white_alpha(twinkle as u8),
1858+
);
1859+
}
1860+
1861+
// 3. Retro Sliced Sun
1862+
let sun_radius = rect.width().min(rect.height()) * 0.25;
1863+
let sun_center = egui::pos2(center_x, horizon_y - sun_radius * 0.3);
18061864

1807-
// Draw horizon line
1808-
bg_painter.line_segment(
1809-
[egui::pos2(rect.left(), horizon_y), egui::pos2(rect.right(), horizon_y)],
1810-
egui::Stroke::new(2.0, grid_color)
1865+
let sun_steps = 40;
1866+
for i in 0..sun_steps {
1867+
let t = i as f32 / sun_steps as f32;
1868+
let next_t = (i + 1) as f32 / sun_steps as f32;
1869+
1870+
if t > 0.45 {
1871+
let slice_t = (t - 0.45) / 0.55;
1872+
let slice_val = (slice_t * 15.0).fract();
1873+
let gap_threshold = 0.2 + slice_t * 0.6;
1874+
if slice_val < gap_threshold {
1875+
continue;
1876+
}
1877+
}
1878+
1879+
let y_min = sun_center.y - sun_radius + t * sun_radius * 2.0;
1880+
let y_max = sun_center.y - sun_radius + next_t * sun_radius * 2.0;
1881+
1882+
let r = 255;
1883+
let g = (204.0 * (1.0 - t) + 80.0 * t) as u8;
1884+
let b = (0.0 * (1.0 - t) + 100.0 * t) as u8;
1885+
let color = egui::Color32::from_rgb(r, g, b);
1886+
1887+
bg_painter.with_clip_rect(egui::Rect::from_min_max(
1888+
egui::pos2(rect.left(), y_min),
1889+
egui::pos2(rect.right(), y_max),
1890+
)).circle_filled(
1891+
sun_center,
1892+
sun_radius,
1893+
color,
1894+
);
1895+
}
1896+
1897+
// 4. Wireframe Mountains
1898+
for i in 0..25 {
1899+
let h1 = pseudo_rand(i * 17);
1900+
let h2 = pseudo_rand(i * 17 + 1);
1901+
let h3 = pseudo_rand(i * 17 + 2);
1902+
1903+
let cx = rect.left() + h1 * rect.width();
1904+
let cy = horizon_y;
1905+
let width = rect.width() * (0.1 + h2 * 0.25);
1906+
let height = rect.height() * (0.05 + h3 * 0.25);
1907+
1908+
let p1 = egui::pos2(cx - width, cy);
1909+
let p2 = egui::pos2(cx + width, cy);
1910+
let p3 = egui::pos2(cx, cy - height);
1911+
1912+
bg_painter.add(egui::Shape::convex_polygon(
1913+
vec![p1, p2, p3],
1914+
egui::Color32::from_rgb(27, 27, 58),
1915+
egui::Stroke::new(1.0, egui::Color32::from_rgb(91, 50, 212)),
1916+
));
1917+
1918+
// Center ridge
1919+
let ridge_offset = (pseudo_rand(i * 17 + 3) - 0.5) * 0.4;
1920+
bg_painter.line_segment(
1921+
[p3, egui::pos2(cx + width * ridge_offset, cy)],
1922+
egui::Stroke::new(1.0, egui::Color32::from_rgb(91, 50, 212))
1923+
);
1924+
}
1925+
1926+
// 5. Floor Grid
1927+
bg_painter.rect_filled(
1928+
egui::Rect::from_min_max(
1929+
egui::pos2(rect.left(), horizon_y),
1930+
egui::pos2(rect.right(), rect.bottom())
1931+
),
1932+
0.0,
1933+
egui::Color32::from_rgb(36, 21, 84)
18111934
);
1935+
1936+
let grid_color = egui::Color32::from_rgb(212, 34, 161);
18121937

18131938
// Vertical radiating lines
18141939
let num_v_lines = 40;
18151940
for i in 0..=num_v_lines {
18161941
let t = i as f32 / num_v_lines as f32;
18171942
let bottom_x = rect.left() + (t - 0.5) * rect.width() * 8.0;
1943+
18181944
bg_painter.line_segment(
18191945
[egui::pos2(center_x, horizon_y), egui::pos2(bottom_x, rect.bottom())],
18201946
egui::Stroke::new(1.0, grid_color)
@@ -1827,13 +1953,11 @@ impl<'a> VulkanEngine<'a> {
18271953
let offset = (i as f32 - (time * 1.5).fract()) / num_h_lines as f32;
18281954
if offset <= 0.0 { continue; }
18291955
let y = horizon_y + (rect.bottom() - horizon_y) * offset.powf(3.0);
1830-
let thickness = 1.0 + offset * 3.0;
1831-
let fade = (offset * 3.0).min(1.0); // Fade in near horizon
1832-
let line_color: egui::Color32 = egui::ecolor::Hsva::new(grid_hue, 0.8, 1.0, 0.4 * fade).into();
1956+
let thickness = 1.0 + offset * 2.0;
18331957

18341958
bg_painter.line_segment(
18351959
[egui::pos2(rect.left(), y), egui::pos2(rect.right(), y)],
1836-
egui::Stroke::new(thickness, line_color)
1960+
egui::Stroke::new(thickness, grid_color)
18371961
);
18381962
}
18391963
// --- End Retro Grid ---
@@ -1849,13 +1973,20 @@ impl<'a> VulkanEngine<'a> {
18491973
egui::Panel::bottom("splash_bottom")
18501974
.frame(egui::Frame::NONE.fill(egui::Color32::from_rgba_unmultiplied(10, 10, 15, 180)).inner_margin(40.0))
18511975
.show_inside(ctx, |ui| {
1852-
ui.vertical_centered(|ui| {
1853-
egui::Frame::NONE
1854-
.fill(egui::Color32::from_black_alpha(200))
1855-
.corner_radius(10.0)
1856-
.inner_margin(20.0)
1857-
.show(ui, |ui| {
1858-
ui.horizontal_centered(|ui| {
1976+
let height = if show_kb && show_gp { 170.0 } else { 140.0 };
1977+
ui.add_space(height);
1978+
});
1979+
1980+
egui::Area::new(egui::Id::new("splash_shortcuts_area"))
1981+
.anchor(egui::Align2::CENTER_BOTTOM, egui::vec2(0.0, -40.0))
1982+
.order(egui::Order::Foreground)
1983+
.show(ctx, |ui| {
1984+
egui::Frame::NONE
1985+
.fill(egui::Color32::from_black_alpha(200))
1986+
.corner_radius(10.0)
1987+
.inner_margin(20.0)
1988+
.show(ui, |ui| {
1989+
ui.horizontal_centered(|ui| {
18591990
let pairs_per_row = if show_kb && show_gp { 2 } else { 3 };
18601991

18611992
if show_kb {
@@ -1941,8 +2072,7 @@ impl<'a> VulkanEngine<'a> {
19412072
});
19422073
}
19432074
});
1944-
});
1945-
});
2075+
});
19462076
});
19472077
}
19482078

@@ -1951,18 +2081,19 @@ impl<'a> VulkanEngine<'a> {
19512081
.inner_margin(40.0);
19522082

19532083
egui::CentralPanel::default().frame(frame).show_inside(ctx, |ui| {
1954-
ui.allocate_ui_with_layout(
1955-
ui.available_size(),
1956-
egui::Layout::top_down(egui::Align::Center),
1957-
|ui| {
1958-
let avail_height = ui.available_height();
1959-
let space = avail_height * 0.15;
2084+
let real_avail_height = ui.available_height();
2085+
let real_avail_width = ui.available_width();
2086+
2087+
egui::ScrollArea::vertical().show(ui, |ui| {
2088+
ui.vertical_centered(|ui| {
2089+
let space = real_avail_height * 0.15;
19602090
if space > 0.0 {
19612091
ui.add_space(space);
19622092
}
19632093
// Scale title to fit smaller screens (like Steam Deck 1280x800)
1964-
let avail_width = ui.available_width();
1965-
let scale_factor = (avail_width / 1100.0).clamp(0.4, 1.0);
2094+
let width_scale = (real_avail_width / 1100.0).clamp(0.4, 1.0);
2095+
let height_scale = (real_avail_height / 500.0).clamp(0.4, 1.0);
2096+
let scale_factor = width_scale.min(height_scale);
19662097
let title_width = 1000.0 * scale_factor;
19672098
let title_height = 160.0 * scale_factor;
19682099
let font_size = 140.0 * scale_factor;
@@ -2005,7 +2136,7 @@ impl<'a> VulkanEngine<'a> {
20052136
}
20062137

20072138
// 3. Sliced Chrome Gradient Interior
2008-
let steps = 40;
2139+
let steps = 20;
20092140
let top_y = title_rect.center().y - gradient_extent;
20102141
let bottom_y = title_rect.center().y + gradient_extent;
20112142
let height = bottom_y - top_y;
@@ -2091,8 +2222,8 @@ impl<'a> VulkanEngine<'a> {
20912222
}
20922223
}
20932224
// The shortcuts are now rendered in the TopBottomPanel
2094-
}
2095-
);
2225+
});
2226+
});
20962227
});
20972228
return;
20982229
}

0 commit comments

Comments
 (0)