Replace a very ugly float comparison with integer logic
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
67f275b2fc
commit
9fb640c4e0
2 changed files with 20 additions and 15 deletions
|
@ -287,8 +287,8 @@ impl HudState {
|
||||||
pub const HUD_VERTICES: [HudVertex; 12] = [
|
pub const HUD_VERTICES: [HudVertex; 12] = [
|
||||||
// Crosshair
|
// Crosshair
|
||||||
HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * 8.0], texture_coordinates: [240.0 / 256.0, 0.0 / 256.0] },
|
HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * 8.0], texture_coordinates: [240.0 / 256.0, 0.0 / 256.0] },
|
||||||
HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * 8.0], texture_coordinates: [256.0 / 256.0, 0.0 / 256.0] },
|
HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * 8.0], texture_coordinates: [ 1.0, 0.0 / 256.0] },
|
||||||
HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * -8.0], texture_coordinates: [256.0 / 256.0, 16.0 / 256.0] },
|
HudVertex { position: [UI_SCALE_X * 8.0, UI_SCALE_Y * -8.0], texture_coordinates: [ 1.0, 16.0 / 256.0] },
|
||||||
HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * -8.0], texture_coordinates: [240.0 / 256.0, 16.0 / 256.0] },
|
HudVertex { position: [UI_SCALE_X * -8.0, UI_SCALE_Y * -8.0], texture_coordinates: [240.0 / 256.0, 16.0 / 256.0] },
|
||||||
|
|
||||||
// Hotbar
|
// Hotbar
|
||||||
|
|
|
@ -66,11 +66,11 @@ impl Quad {
|
||||||
let mut current_index = start_index;
|
let mut current_index = start_index;
|
||||||
let mut vertices = Vec::new();
|
let mut vertices = Vec::new();
|
||||||
let mut indices = Vec::new();
|
let mut indices = Vec::new();
|
||||||
let highlighted: [f32; 3] = self.highlighted_normal.cast().unwrap().into();
|
|
||||||
|
|
||||||
if self.visible_faces & FACE_LEFT == FACE_LEFT {
|
if self.visible_faces & FACE_LEFT == FACE_LEFT {
|
||||||
let normal = [-1.0, 0.0, 0.0];
|
let normal = Vector3::new(-1, 0, 0);
|
||||||
let highlighted = (normal == highlighted) as i32;
|
let highlighted = (self.highlighted_normal == normal) as i32;
|
||||||
|
let normal = normal.cast().unwrap().into();
|
||||||
vertices.extend(&[
|
vertices.extend(&[
|
||||||
BlockVertex { position: [x, y, z ], texture_coordinates: [dz, 1.0], texture_id: t.0 as i32, normal, highlighted },
|
BlockVertex { position: [x, y, z ], texture_coordinates: [dz, 1.0], texture_id: t.0 as i32, normal, highlighted },
|
||||||
BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.0 as i32, normal, highlighted },
|
BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.0 as i32, normal, highlighted },
|
||||||
|
@ -85,8 +85,9 @@ impl Quad {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.visible_faces & FACE_RIGHT == FACE_RIGHT {
|
if self.visible_faces & FACE_RIGHT == FACE_RIGHT {
|
||||||
let normal = [1.0, 0.0, 0.0];
|
let normal = Vector3::new(1, 0, 0);
|
||||||
let highlighted = (normal == highlighted) as i32;
|
let highlighted = (self.highlighted_normal == normal) as i32;
|
||||||
|
let normal = normal.cast().unwrap().into();
|
||||||
vertices.extend(&[
|
vertices.extend(&[
|
||||||
BlockVertex { position: [x + dx, y, z ], texture_coordinates: [0.0, 1.0], texture_id: t.1 as i32, normal, highlighted },
|
BlockVertex { position: [x + dx, y, z ], texture_coordinates: [0.0, 1.0], texture_id: t.1 as i32, normal, highlighted },
|
||||||
BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [dz, 1.0], texture_id: t.1 as i32, normal, highlighted },
|
BlockVertex { position: [x + dx, y, z + dz], texture_coordinates: [dz, 1.0], texture_id: t.1 as i32, normal, highlighted },
|
||||||
|
@ -101,8 +102,9 @@ impl Quad {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.visible_faces & FACE_BACK == FACE_BACK {
|
if self.visible_faces & FACE_BACK == FACE_BACK {
|
||||||
let normal = [0.0, 0.0, -1.0];
|
let normal = Vector3::new(0, 0, -1);
|
||||||
let highlighted = (normal == highlighted) as i32;
|
let highlighted = (self.highlighted_normal == normal) as i32;
|
||||||
|
let normal = normal.cast().unwrap().into();
|
||||||
vertices.extend(&[
|
vertices.extend(&[
|
||||||
BlockVertex { position: [x, y, z], texture_coordinates: [dx, 1.0], texture_id: t.2 as i32, normal, highlighted },
|
BlockVertex { position: [x, y, z], texture_coordinates: [dx, 1.0], texture_id: t.2 as i32, normal, highlighted },
|
||||||
BlockVertex { position: [x, y + dy, z], texture_coordinates: [dx, 0.0], texture_id: t.2 as i32, normal, highlighted },
|
BlockVertex { position: [x, y + dy, z], texture_coordinates: [dx, 0.0], texture_id: t.2 as i32, normal, highlighted },
|
||||||
|
@ -117,8 +119,9 @@ impl Quad {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.visible_faces & FACE_FRONT == FACE_FRONT {
|
if self.visible_faces & FACE_FRONT == FACE_FRONT {
|
||||||
let normal = [0.0, 0.0, 1.0];
|
let normal = Vector3::new(0, 0, 1);
|
||||||
let highlighted = (normal == highlighted) as i32;
|
let highlighted = (self.highlighted_normal == normal) as i32;
|
||||||
|
let normal = normal.cast().unwrap().into();
|
||||||
vertices.extend(&[
|
vertices.extend(&[
|
||||||
BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.3 as i32, normal, highlighted },
|
BlockVertex { position: [x, y, z + dz], texture_coordinates: [0.0, 1.0], texture_id: t.3 as i32, normal, highlighted },
|
||||||
BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, 0.0], texture_id: t.3 as i32, normal, highlighted },
|
BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, 0.0], texture_id: t.3 as i32, normal, highlighted },
|
||||||
|
@ -133,8 +136,9 @@ impl Quad {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.visible_faces & FACE_BOTTOM == FACE_BOTTOM {
|
if self.visible_faces & FACE_BOTTOM == FACE_BOTTOM {
|
||||||
let normal = [0.0, -1.0, 0.0];
|
let normal = Vector3::new(0, -1, 0);
|
||||||
let highlighted = (normal == highlighted) as i32;
|
let highlighted = (self.highlighted_normal == normal) as i32;
|
||||||
|
let normal = normal.cast().unwrap().into();
|
||||||
vertices.extend(&[
|
vertices.extend(&[
|
||||||
BlockVertex { position: [x, y, z ], texture_coordinates: [dx, 0.0], texture_id: t.4 as i32, normal, highlighted },
|
BlockVertex { position: [x, y, z ], texture_coordinates: [dx, 0.0], texture_id: t.4 as i32, normal, highlighted },
|
||||||
BlockVertex { position: [x, y, z + dz], texture_coordinates: [dx, dz ], texture_id: t.4 as i32, normal, highlighted },
|
BlockVertex { position: [x, y, z + dz], texture_coordinates: [dx, dz ], texture_id: t.4 as i32, normal, highlighted },
|
||||||
|
@ -149,8 +153,9 @@ impl Quad {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.visible_faces & FACE_TOP == FACE_TOP {
|
if self.visible_faces & FACE_TOP == FACE_TOP {
|
||||||
let normal = [0.0, 1.0, 0.0];
|
let normal = Vector3::new(0, 1, 0);
|
||||||
let highlighted = (normal == highlighted) as i32;
|
let highlighted = (self.highlighted_normal == normal) as i32;
|
||||||
|
let normal = normal.cast().unwrap().into();
|
||||||
vertices.extend(&[
|
vertices.extend(&[
|
||||||
BlockVertex { position: [x, y + dy, z ], texture_coordinates: [0.0, 0.0], texture_id: t.5 as i32, normal, highlighted },
|
BlockVertex { position: [x, y + dy, z ], texture_coordinates: [0.0, 0.0], texture_id: t.5 as i32, normal, highlighted },
|
||||||
BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, dz ], texture_id: t.5 as i32, normal, highlighted },
|
BlockVertex { position: [x, y + dy, z + dz], texture_coordinates: [0.0, dz ], texture_id: t.5 as i32, normal, highlighted },
|
||||||
|
|
Loading…
Reference in a new issue