aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_floor_cast.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-15 19:42:48 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-15 19:42:48 +0100
commit75f54cd49e5b9942678d2b8a8137ca1110a785f5 (patch)
tree9abbe2b12a0d1cc016bc3bfa5ce95f15d6cd625d /src/ft_floor_cast.c
parentRevert (diff)
download42-cub3d-75f54cd49e5b9942678d2b8a8137ca1110a785f5.tar.gz
42-cub3d-75f54cd49e5b9942678d2b8a8137ca1110a785f5.tar.bz2
42-cub3d-75f54cd49e5b9942678d2b8a8137ca1110a785f5.tar.xz
42-cub3d-75f54cd49e5b9942678d2b8a8137ca1110a785f5.tar.zst
42-cub3d-75f54cd49e5b9942678d2b8a8137ca1110a785f5.zip
Valgrind errors fix
Diffstat (limited to '')
-rw-r--r--src/ft_floor_cast.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index 2eda9d8..92dcb07 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -25,23 +25,21 @@ static void
{
float dist;
float calc;
+ t_rgb rgb;
- if ((dist = cl->rlist.row_dist) <= 0)
- dist = 0.0001;
+ dist = (cl->rlist.row_dist > 0) ? (cl->rlist.row_dist) : (0.0001);
calc = (dist * 0.1 * cl->mlist.darklvl);
calc = (calc >= 255) ? (255) : (calc);
calc = (calc < 1) ? (1) : (calc);
calc = (cl->mlist.darklvl > 0) ? (calc) : (1);
- cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
- (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
- cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc;
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
- (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
- cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc;
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
- (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ rgb.r = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2] / calc;
- cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0;
+ rgb.g = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc;
+ rgb.b = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc;
+ *(int*)(cl->img.ptr +
+ (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb);
}
static void
@@ -88,12 +86,12 @@ void
uint16_t y;
rl = &cl->rlist;
- y = (cl->wlist.y_size / 2) + 1;
- while (++y < cl->wlist.y_size)
+ y = (cl->wlist.y_size / 2);
+ while (y < cl->wlist.y_size)
{
ft_floor_cast_inits(y, rl, cl);
- x = -1;
- while (++x < cl->wlist.x_size)
+ x = 0;
+ while (x < cl->wlist.x_size)
{
if (cl->rlist.wall_bz[x] <= y)
{
@@ -101,6 +99,8 @@ void
}
rl->x_floor += cl->mlist.x_floor_step;
rl->y_floor += cl->mlist.y_floor_step;
+ x++;
}
+ y++;
}
}