Remove the vast majority of floor/ceil/round ops
parent
2304bf95a3
commit
261125a758
|
@ -448,9 +448,9 @@ impl PicData {
|
|||
|
||||
fn colourmap_for_scale(&self, scale: f32) -> usize {
|
||||
let mut colourmap = if self.double_res {
|
||||
(scale * 15.8 / 2.0).floor() as u32
|
||||
(scale * 15.8 / 2.0) as u32
|
||||
} else {
|
||||
(scale * 15.8).ceil() as u32
|
||||
(scale * 15.8) as u32
|
||||
};
|
||||
if colourmap >= MAXLIGHTSCALE as u32 - 1 {
|
||||
colourmap = MAXLIGHTSCALE as u32 - 1;
|
||||
|
|
|
@ -862,7 +862,7 @@ impl Think for MapObject {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.z.floor() - this.floorz.floor()).abs() > f32::EPSILON || this.momz != 0.0 {
|
||||
if (this.z - this.floorz).abs() > f32::EPSILON || this.momz != 0.0 {
|
||||
this.p_z_movement();
|
||||
}
|
||||
|
||||
|
|
|
@ -145,14 +145,14 @@ impl SoftwareRenderer {
|
|||
let sky_mid = pixels.height() / 2 - down_shift; // shift down by 6 pixels
|
||||
let skytex = textures.sky_pic();
|
||||
|
||||
for x in plane.minx.floor() as i32..=plane.maxx.ceil() as i32 {
|
||||
for x in plane.minx as i32..=plane.maxx as i32 {
|
||||
let dc_yl = plane.top[x as usize];
|
||||
let dc_yh = plane.bottom[x as usize];
|
||||
if dc_yl <= dc_yh {
|
||||
let angle = (view_angle.rad().to_degrees()
|
||||
+ screen_to_x_view(x as f32, pixels.width() as f32).to_degrees())
|
||||
* 2.8444; // 2.8444 seems to give the corect skybox width
|
||||
let texture_column = textures.wall_pic_column(skytex, angle.floor() as i32);
|
||||
let texture_column = textures.wall_pic_column(skytex, angle as i32);
|
||||
|
||||
let mut dc = DrawColumn::new(
|
||||
texture_column,
|
||||
|
@ -180,7 +180,7 @@ impl SoftwareRenderer {
|
|||
plane.view_angle = view_angle;
|
||||
|
||||
let mut span_start = vec![0.0; pixels.width() as usize];
|
||||
for x in plane.minx.floor() as i32..=plane.maxx.floor() as i32 {
|
||||
for x in plane.minx as i32..=plane.maxx as i32 {
|
||||
let mut step = x - 1;
|
||||
if step < 0 {
|
||||
step = 0;
|
||||
|
|
|
@ -106,10 +106,7 @@ impl VisPlaneRender {
|
|||
let len = self.visplanes.len();
|
||||
|
||||
for (index, plane) in self.visplanes[0..self.lastvisplane].iter().enumerate() {
|
||||
if height.floor() == plane.height.floor()
|
||||
&& picnum == plane.picnum
|
||||
&& light_level == plane.lightlevel
|
||||
{
|
||||
if height == plane.height && picnum == plane.picnum && light_level == plane.lightlevel {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
@ -156,8 +153,8 @@ impl VisPlaneRender {
|
|||
return plane_idx;
|
||||
}
|
||||
|
||||
for i in intrl.floor() as i32..=self.screen_width as i32 {
|
||||
if i >= intrh.floor() as i32 {
|
||||
for i in intrl as i32..=self.screen_width as i32 {
|
||||
if i >= intrh as i32 {
|
||||
plane.minx = unionl;
|
||||
plane.maxx = unionh;
|
||||
// Use the same plane
|
||||
|
@ -329,7 +326,8 @@ impl<'a> DrawSpan<'a> {
|
|||
|
||||
fn draw(&mut self, textures: &PicData, pixels: &mut PixelBuf) {
|
||||
let pal = textures.palette();
|
||||
for s in self.ds_x1.round() as i32..=self.ds_x2.round() as i32 {
|
||||
// for s in self.ds_x1.round() as i32..=self.ds_x2.round() as i32 {
|
||||
for s in self.ds_x1 as i32..=self.ds_x2 as i32 {
|
||||
let mut x = self.ds_xfrac.abs() as usize & 0xff;
|
||||
let mut y = self.ds_yfrac.abs() as usize & 0xff;
|
||||
|
||||
|
@ -343,7 +341,7 @@ impl<'a> DrawSpan<'a> {
|
|||
|
||||
let px = self.colourmap[self.texture.data[x][y] as usize];
|
||||
let c = pal[px];
|
||||
pixels.set_pixel(s as usize, self.ds_y.floor() as usize, c.r, c.g, c.b, 255);
|
||||
pixels.set_pixel(s as usize, self.ds_y as usize, c.r, c.g, c.b, 255);
|
||||
|
||||
self.ds_xfrac += self.ds_xstep;
|
||||
self.ds_yfrac += self.ds_ystep;
|
||||
|
|
|
@ -220,7 +220,7 @@ impl SegRender {
|
|||
if linedef.flags & LineDefFlags::UnpegBottom as u32 != 0 {
|
||||
if let Some(mid_tex) = seg.sidedef.midtexture {
|
||||
let texture_column = textures.wall_pic_column(mid_tex, 0);
|
||||
let vtop = frontsector.floorheight.ceil() + texture_column.len() as f32 - 1.0;
|
||||
let vtop = frontsector.floorheight + texture_column.len() as f32 - 1.0;
|
||||
self.rw_midtexturemid = vtop - viewz;
|
||||
} else {
|
||||
// top of texture at top
|
||||
|
@ -341,7 +341,7 @@ impl SegRender {
|
|||
// if sidedef.midtexture.is_some() {
|
||||
self.maskedtexture = true;
|
||||
// Set the indexes in to visplanes.openings
|
||||
self.maskedtexturecol = (rdata.visplanes.lastopening - self.rw_x).floor() as i32;
|
||||
self.maskedtexturecol = (rdata.visplanes.lastopening - self.rw_x) as i32;
|
||||
ds_p.maskedtexturecol = self.maskedtexturecol;
|
||||
|
||||
rdata.visplanes.lastopening += self.rw_stopx - self.rw_x;
|
||||
|
@ -429,7 +429,7 @@ impl SegRender {
|
|||
break;
|
||||
}
|
||||
}
|
||||
ds_p.sprtopclip = Some((rdata.visplanes.lastopening - start).floor() as i32);
|
||||
ds_p.sprtopclip = Some((rdata.visplanes.lastopening - start) as i32);
|
||||
rdata.visplanes.lastopening += self.rw_stopx - start;
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ impl SegRender {
|
|||
break;
|
||||
}
|
||||
}
|
||||
ds_p.sprbottomclip = Some((rdata.visplanes.lastopening - start).floor() as i32);
|
||||
ds_p.sprbottomclip = Some((rdata.visplanes.lastopening - start) as i32);
|
||||
rdata.visplanes.lastopening += self.rw_stopx - start;
|
||||
}
|
||||
|
||||
|
@ -481,7 +481,7 @@ impl SegRender {
|
|||
let mut angle;
|
||||
let mut texture_column = 0;
|
||||
while self.rw_x < self.rw_stopx {
|
||||
let clip_index = self.rw_x.floor() as usize;
|
||||
let clip_index = self.rw_x as usize;
|
||||
|
||||
// yl = (topfrac + HEIGHTUNIT - 1) >> HEIGHTBITS;
|
||||
// Whaaaat?
|
||||
|
@ -533,7 +533,7 @@ impl SegRender {
|
|||
let mut dc_iscale = 0.0;
|
||||
if self.segtextured {
|
||||
angle = self.rw_centerangle + screen_to_x_view(self.rw_x, pixels.width() as f32);
|
||||
texture_column = (self.rw_offset - angle.tan() * self.rw_distance).floor() as i32;
|
||||
texture_column = (self.rw_offset - angle.tan() * self.rw_distance) as i32;
|
||||
|
||||
dc_iscale = 1.0 / self.rw_scale;
|
||||
}
|
||||
|
@ -637,8 +637,7 @@ impl SegRender {
|
|||
}
|
||||
|
||||
if self.maskedtexture {
|
||||
rdata.visplanes.openings
|
||||
[(self.maskedtexturecol + self.rw_x.floor() as i32) as usize] =
|
||||
rdata.visplanes.openings[(self.maskedtexturecol + self.rw_x as i32) as usize] =
|
||||
texture_column as f32;
|
||||
}
|
||||
}
|
||||
|
@ -691,16 +690,13 @@ impl<'a> DrawColumn<'a> {
|
|||
pub fn draw_column(&mut self, textures: &PicData, doubled: bool, pixels: &mut PixelBuf) {
|
||||
let pal = textures.palette();
|
||||
let mut frac =
|
||||
self.dc_texturemid + (self.yl - pixels.height() as f32 / 2.0) * self.fracstep;
|
||||
self.dc_texturemid + (self.yl - pixels.height() as f32 / 2.0) * self.fracstep + 0.1;
|
||||
|
||||
for n in self.yl.floor() as i32..=self.yh.floor() as i32 {
|
||||
// (frac - 0.01).floor() is a ridiculous magic number to prevent the
|
||||
// jaggy line across horizontal center. It tips the number *just enough*
|
||||
// without throwing all the alignment out of wack.
|
||||
for n in self.yl as i32..=self.yh as i32 {
|
||||
let mut select = if doubled {
|
||||
((frac - 0.01).round() as i32 / 2) & 0xff
|
||||
(frac as i32 / 2) & 0xff
|
||||
} else {
|
||||
((frac - 0.01).round() as i32) & 0xff
|
||||
(frac as i32) & 0xff
|
||||
};
|
||||
if select >= self.texture_column.len() as i32 {
|
||||
select %= self.texture_column.len() as i32;
|
||||
|
@ -712,7 +708,7 @@ impl<'a> DrawColumn<'a> {
|
|||
|
||||
let px = self.colourmap[self.texture_column[select as usize]];
|
||||
let c = pal[px];
|
||||
pixels.set_pixel(self.dc_x.floor() as usize, n as usize, c.r, c.g, c.b, 255);
|
||||
pixels.set_pixel(self.dc_x as usize, n as usize, c.r, c.g, c.b, 255);
|
||||
|
||||
frac += self.fracstep;
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ impl SoftwareRenderer {
|
|||
if sprite_frame.rotate == 1 {
|
||||
let angle = point_to_angle_2(player_mobj.xy, thing.xy);
|
||||
let rot = ((angle - thing.angle + FRAME_ROT_OFFSET).rad()) * FRAME_ROT_SELECT;
|
||||
let rot = rot.floor();
|
||||
let rot = rot;
|
||||
patch_index = sprite_frame.lump[rot as usize] as usize;
|
||||
patch = texture_data.sprite_patch(patch_index);
|
||||
flip = sprite_frame.flip[rot as usize];
|
||||
|
@ -201,13 +201,13 @@ impl SoftwareRenderer {
|
|||
}
|
||||
|
||||
tx -= patch.left_offset as f32;
|
||||
let x1 = ((screen_width as f32 / 2.0) + tx * x_scale).floor() as i32 - 1;
|
||||
let x1 = ((screen_width as f32 / 2.0) + tx * x_scale) as i32 - 1;
|
||||
if x1 > screen_width as i32 {
|
||||
return true;
|
||||
}
|
||||
|
||||
tx += patch.data.len() as f32;
|
||||
let x2 = ((screen_width as f32 / 2.0) + tx * x_scale).floor() as i32;
|
||||
let x2 = ((screen_width as f32 / 2.0) + tx * x_scale) as i32;
|
||||
if x2 < 0 {
|
||||
return true;
|
||||
}
|
||||
|
@ -272,16 +272,16 @@ impl SoftwareRenderer {
|
|||
};
|
||||
|
||||
for x in vis.x1..=vis.x2 {
|
||||
let tex_column = (frac).floor() as usize;
|
||||
let tex_column = (frac) as usize;
|
||||
if tex_column >= patch.data.len() {
|
||||
break;
|
||||
}
|
||||
|
||||
let sprtopscreen = (pixels.height() as f32 / 2.0 - dc_texmid * spryscale).floor();
|
||||
let sprtopscreen = pixels.height() as f32 / 2.0 - dc_texmid * spryscale;
|
||||
let texture_column = &patch.data[tex_column];
|
||||
|
||||
let mut top = sprtopscreen as i32;
|
||||
let mut bottom = top + (spryscale * texture_column.len() as f32).ceil() as i32;
|
||||
let mut bottom = top + (spryscale * texture_column.len() as f32) as i32;
|
||||
|
||||
if bottom >= clip_bottom[x as usize] {
|
||||
bottom = clip_bottom[x as usize] - 1;
|
||||
|
@ -318,22 +318,22 @@ impl SoftwareRenderer {
|
|||
// Breaking liftime to enable this loop
|
||||
let segs = unsafe { &*(&self.r_data.drawsegs as *const Vec<DrawSeg>) };
|
||||
for seg in segs.iter().rev() {
|
||||
if seg.x1.floor() as i32 > vis.x2
|
||||
|| (seg.x2.floor() as i32) < vis.x1
|
||||
if seg.x1 as i32 > vis.x2
|
||||
|| (seg.x2 as i32) < vis.x1
|
||||
|| (seg.silhouette == 0 && seg.maskedtexturecol == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let r1 = if (seg.x1.floor() as i32) < vis.x1 {
|
||||
let r1 = if (seg.x1 as i32) < vis.x1 {
|
||||
vis.x1
|
||||
} else {
|
||||
seg.x1.floor() as i32
|
||||
seg.x1 as i32
|
||||
};
|
||||
let r2 = if (seg.x2.floor() as i32) > vis.x2 {
|
||||
let r2 = if (seg.x2 as i32) > vis.x2 {
|
||||
vis.x2
|
||||
} else {
|
||||
seg.x2.floor() as i32
|
||||
seg.x2 as i32
|
||||
};
|
||||
|
||||
let (lowscale, scale) = if seg.scale1 > seg.scale2 {
|
||||
|
@ -363,7 +363,7 @@ impl SoftwareRenderer {
|
|||
if clip_bottom[r as usize] == -2 && seg.sprbottomclip.is_some() {
|
||||
clip_bottom[r as usize] = self.r_data.visplanes.openings
|
||||
[(seg.sprbottomclip.unwrap() + r) as usize]
|
||||
.floor() as i32;
|
||||
as i32;
|
||||
if clip_bottom[r as usize] < 0 {
|
||||
clip_bottom[r as usize] = 0;
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ impl SoftwareRenderer {
|
|||
if clip_top[r as usize] == -2 && seg.sprtopclip.is_some() {
|
||||
clip_top[r as usize] = self.r_data.visplanes.openings
|
||||
[(seg.sprtopclip.unwrap() + r) as usize]
|
||||
.floor() as i32;
|
||||
as i32;
|
||||
if clip_top[r as usize] >= pixels.height() as i32 {
|
||||
clip_top[r as usize] = pixels.height() as i32;
|
||||
}
|
||||
|
@ -425,13 +425,13 @@ impl SoftwareRenderer {
|
|||
let flip = frame.flip[0];
|
||||
// 160.0 is pretty much a hardcoded number to center the weapon always
|
||||
let mut tx = sprite.sx - 160.0 - patch.left_offset as f32;
|
||||
let x1 = (pixels.width() as i32 / 2) + (tx * pspritescale).floor() as i32;
|
||||
let x1 = (pixels.width() as i32 / 2) + (tx * pspritescale) as i32;
|
||||
|
||||
if x1 >= pixels.width() as i32 {
|
||||
return;
|
||||
}
|
||||
tx += patch.data.len() as f32;
|
||||
let x2 = ((pixels.width() / 2) as i32 + (tx * pspritescale).floor() as i32) - 1;
|
||||
let x2 = ((pixels.width() / 2) as i32 + (tx * pspritescale) as i32) - 1;
|
||||
|
||||
if x2 < 0 {
|
||||
return;
|
||||
|
@ -482,13 +482,7 @@ impl SoftwareRenderer {
|
|||
|
||||
let segs: Vec<DrawSeg> = self.r_data.drawsegs.to_vec();
|
||||
for ds in segs.iter().rev() {
|
||||
self.render_masked_seg_range(
|
||||
player,
|
||||
ds,
|
||||
ds.x1.floor() as i32,
|
||||
ds.x2.floor() as i32,
|
||||
pixels,
|
||||
);
|
||||
self.render_masked_seg_range(player, ds, ds.x1 as i32, ds.x2 as i32, pixels);
|
||||
}
|
||||
|
||||
self.draw_player_sprites(player, pixels);
|
||||
|
@ -550,7 +544,7 @@ impl SoftwareRenderer {
|
|||
{
|
||||
let texture_column = textures.wall_pic_column(
|
||||
unsafe { seg.sidedef.midtexture.unwrap_unchecked() },
|
||||
self.r_data.visplanes.openings[index].floor() as i32,
|
||||
self.r_data.visplanes.openings[index] as i32,
|
||||
);
|
||||
|
||||
let mut mceilingclip = self.r_data.visplanes.openings
|
||||
|
@ -568,8 +562,8 @@ impl SoftwareRenderer {
|
|||
|
||||
// // calculate unclipped screen coordinates for post
|
||||
let sprtopscreen = (pixels.height() / 2) as f32 - dc_texturemid * spryscale;
|
||||
let top = sprtopscreen.ceil() as i32;
|
||||
let bottom = top + (spryscale * texture_column.len() as f32).ceil() as i32;
|
||||
let top = sprtopscreen as i32;
|
||||
let bottom = top + (spryscale * texture_column.len() as f32) as i32;
|
||||
let mut yl = top;
|
||||
let mut yh = bottom;
|
||||
|
||||
|
@ -619,7 +613,7 @@ fn draw_masked_column(
|
|||
let pal = &textures.palette();
|
||||
let mut frac = dc_texturemid + 0.5 + (yl as f32 - (pixels.height() / 2) as f32) * fracstep;
|
||||
for n in yl..=yh {
|
||||
let select = frac.floor() as usize;
|
||||
let select = frac as usize;
|
||||
|
||||
if select >= texture_column.len() {
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue