Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kelpsyberry committed Mar 21, 2024
1 parent 2f40950 commit ed8a31c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 63 deletions.
21 changes: 12 additions & 9 deletions frontend/desktop/src/ui/config_editor/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,18 @@ impl RawSetting for OptNonZeroU32Slider {
let checkbox_width = ui.frame_height();
let input_width = width - checkbox_width - style!(ui, item_spacing)[0];

let mut active = value.is_some();
if ui.checkbox("##active", &mut active) {
value = if active { Some(self.default) } else { None };
if ui.checkbox("##active", &mut value.is_some()) {
value = if value.is_some() {
None
} else {
Some(self.default)
};
updated = true;
}
hovered |= ui.is_item_hovered_with_flags(ItemHoveredFlags::ALLOW_WHEN_DISABLED);

if active {
let mut raw_value = value.unwrap().get();
if let Some(value_) = value {
let mut raw_value = value_.get();
ui.same_line();
ui.set_next_item_width(input_width);
if ui
Expand Down Expand Up @@ -442,20 +445,20 @@ impl<T: DataTypeKind> BoolAndValueSlider<T> {

impl<T: DataTypeKind> RawSetting for BoolAndValueSlider<T> {
fn draw(&mut self, ui: &Ui, config: &mut Config, tooltip: &str, width: f32) {
let (mut active, mut value) = (self.get)(config);
let (mut is_active, mut value) = (self.get)(config);

let mut updated = false;
let mut hovered = false;

let checkbox_width = ui.frame_height();
let input_width = width - checkbox_width - style!(ui, item_spacing)[0];

if ui.checkbox("##active", &mut active) {
if ui.checkbox("##active", &mut is_active) {
updated = true;
}
hovered |= ui.is_item_hovered_with_flags(ItemHoveredFlags::ALLOW_WHEN_DISABLED);

if active {
if is_active {
ui.same_line();
ui.set_next_item_width(input_width);
if ui
Expand All @@ -472,7 +475,7 @@ impl<T: DataTypeKind> RawSetting for BoolAndValueSlider<T> {
}

if updated {
(self.set)(config, (active, value));
(self.set)(config, (is_active, value));
}

if !tooltip.is_empty() && hovered {
Expand Down
72 changes: 18 additions & 54 deletions render/soft-3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl Renderer {
|| edges[1].x_incr() == 0,
];

let edge_mask = (y == poly.top_y) as u8 | (y + 1 == poly.bot_y) as u8;
let is_y_edge = (y == poly.top_y) || (y + 1 == poly.bot_y);

macro_rules! interp_edge {
($i: expr, $x: expr) => {{
Expand All @@ -742,60 +742,10 @@ impl Renderer {

let x_interp = InterpLineData::<false>::new(l_w, r_w);

for i in 0..2 {
if fill_edges[i] {
for x in ranges[i].0..=ranges[i].1 {
if poly.is_shadow && !self.attr_buffer.0[x as usize].stencil() {
continue;
}
macro_rules! render_pixel {
($x: expr) => {{
let x = $x;

let interp = x_interp.set_x(x - x_span_start, x_span_len);
let x = x as usize;
let depth = interp.depth(l_depth, r_depth, rendering_data.w_buffering);
if (poly.depth_test)(depth, self.depth_buffer.0[x], self.attr_buffer.0[x]) {
let vert_color = interp.color(l_vert_color, r_vert_color);
let uv = interp.uv(l_uv, r_uv);
let mut color =
(poly.process_pixel)(rendering_data, poly, uv, vert_color);
let alpha = color[3];
if alpha > rendering_data.alpha_test_ref as u16 {
if alpha == 0x1F {
self.color_buffer.0[x] = color.cast();
self.depth_buffer.0[x] = depth;
self.attr_buffer.0[x] =
PixelAttrs::from_opaque_poly_attrs(poly);
} else {
let prev_attrs = self.attr_buffer.0[x];
if prev_attrs.translucent_id() != poly.id | 0x40 {
if rendering_data.control.alpha_blending_enabled() {
let prev_color = self.color_buffer.0[x].cast();
let prev_alpha = prev_color[3];
if prev_alpha != 0 {
color = ((color * InterpColor::splat(alpha + 1))
+ (prev_color
* InterpColor::splat(31 - alpha)))
>> InterpColor::splat(5);
color[3] = alpha.max(prev_alpha);
}
}
self.color_buffer.0[x] = color.cast();
if poly.attrs.update_depth_for_translucent() {
self.depth_buffer.0[x] = depth;
}
self.attr_buffer.0[x] =
PixelAttrs::from_translucent_poly_attrs(
poly, prev_attrs,
);
}
}
}
}
}
}
}

if !wireframe || edge_mask != 0 {
for x in ranges[0].1 + 1..ranges[1].0 {
if poly.is_shadow && !self.attr_buffer.0[x as usize].stencil() {
continue;
}
Expand Down Expand Up @@ -837,6 +787,20 @@ impl Renderer {
}
}
}
}};
}

for i in 0..2 {
if fill_edges[i] {
for x in ranges[i].0..=ranges[i].1 {
render_pixel!(x);
}
}
}

if !wireframe || is_y_edge {
for x in ranges[0].1 + 1..ranges[1].0 {
render_pixel!(x);
}
}
}
Expand Down

0 comments on commit ed8a31c

Please sign in to comment.