diff options
author | Rudy Bousset <rbousset@z2r4p1.le-101.fr> | 2020-03-11 16:07:29 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r4p1.le-101.fr> | 2020-03-11 16:07:29 +0100 |
commit | 7f77c9bc922fb608f689385d642304956afe0492 (patch) | |
tree | 50ccbb70b2f39f6dbe2d8336165eea47b6b5c048 | |
parent | qweqwe (diff) | |
download | 42-cub3d-7f77c9bc922fb608f689385d642304956afe0492.tar.gz 42-cub3d-7f77c9bc922fb608f689385d642304956afe0492.tar.bz2 42-cub3d-7f77c9bc922fb608f689385d642304956afe0492.tar.xz 42-cub3d-7f77c9bc922fb608f689385d642304956afe0492.tar.zst 42-cub3d-7f77c9bc922fb608f689385d642304956afe0492.zip |
Performance
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | inc/cub3d.h | 1 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | src/ft_draw_scene.c | 11 | ||||
-rw-r--r-- | src/ft_hex_to_rgb.c | 11 | ||||
-rw-r--r-- | src/ft_init_lists.c | 1 | ||||
-rw-r--r-- | src/ft_key_loop.c | 7 | ||||
-rw-r--r-- | src/ft_suffer_animation.c | 26 |
8 files changed, 35 insertions, 25 deletions
@@ -183,10 +183,8 @@ all: ${NAME} clean: ifeq (${OS}, Darwin) @$(MAKE) --no-print-directory -C ${MLX_DIR} clean -ifdef BETA ${RM} libmlx.dylib endif -endif @$(MAKE) --no-print-directory -C ${LFT_DIR} clean ${RM} ${OBJS_DIR} #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index 4172c9d..ae353ae 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -33,6 +33,7 @@ t_rgb ft_init_rgb(void); int8_t ft_init_map(t_map *mlist); t_bmp_file ft_init_bmp(void); t_bmp_info ft_init_bmp_info(void); +t_rgb ft_hex_to_og_rgb(uint32_t color); /* ** ====== HOOKS ====== diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 310ba90..957d154 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -208,6 +208,7 @@ typedef struct s_cub uint8_t ishud; uint8_t walltexgood; uint8_t isoldmus; + uint8_t doicast; uint16_t currlvl; uint16_t i; char *const *envp; diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 9664363..39cdadc 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -45,22 +45,19 @@ void /* clist->wlist.x_size, clist->wlist.y_size); */ /* clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, */ /* &clist->img.sizeline, &clist->img.endian); */ - ft_castray(clist); + if (clist->doicast) + ft_castray(clist); + else + clist->doicast = 1; if (clist->ishud) - { ft_draw_hud(clist); - } if (clist->mlist.isskybox) ft_draw_skybox(clist); mlx_put_image_to_window(clist->wlist.wlx, clist->wlist.winptr, clist->img.img, 0, 0); if (clist->ishud && clist->mlist.isnlvl) - { if (ft_put_stage(clist) < 0) - { ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); - } - } /* mlx_destroy_image(clist->wlist.wlx, clist->img.img); */ } diff --git a/src/ft_hex_to_rgb.c b/src/ft_hex_to_rgb.c index 30332cc..1732473 100644 --- a/src/ft_hex_to_rgb.c +++ b/src/ft_hex_to_rgb.c @@ -13,6 +13,17 @@ #include <cub3d.h> #include <stdint.h> +t_rgb + ft_hex_to_og_rgb(uint32_t color) +{ + t_rgb rgb; + + rgb.r = (color >> 16) & 255; + rgb.g = (color >> 8) & 255; + rgb.b = color & 255; + return (rgb); +} + t_bmp_rgb ft_hex_to_rgb(uint32_t color) { diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 79b0d14..d480912 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -74,6 +74,7 @@ static int8_t cl->key_input[i] = -1; cl->ishud = 0; cl->isoldmus = 0; + cl->doicast = 1; cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index e0c2c28..45ed379 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -12,6 +12,7 @@ #include <libft.h> #include <cub3d.h> +#include <mlx.h> #include <stdint.h> #include <stddef.h> @@ -55,8 +56,8 @@ static void y = ft_find_y(key, pl); if (cl->mlist.map[y][x] == 'T') { - pl->pos_x = old_x + ((old_x - x) / 4); - pl->pos_y = old_y + ((old_y - y) / 4); + pl->pos_x = old_x + ((old_x - x) / 3); + pl->pos_y = old_y + ((old_y - y) / 3); ft_suffer_animation(cl); x = ft_find_x(key, pl); y = ft_find_y(key, pl); @@ -93,8 +94,6 @@ int i++; } if (cl->key_input[0] != -1) - { ft_draw_scene(cl); - } return (0); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 2a1beb4..1a9b51a 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -21,24 +21,26 @@ void { int32_t x; int32_t y; - int8_t i; + int32_t col; + t_rgb rgb; - /* cl->red_scr.img = mlx_new_image(cl->wlist.wlx, */ - /* cl->wlist.x_size, cl->wlist.y_size); */ - /* cl->red_scr.ptr = mlx_get_data_addr(cl->red_scr.img, &cl->red_scr.bpp, */ - /* &cl->red_scr.sizeline, &cl->red_scr.endian); */ y = -1; + col = 0x00880000; while (++y < (int32_t)cl->wlist.y_size) { x = -1; while (++x < (int32_t)cl->wlist.x_size) + { + rgb = ft_hex_to_og_rgb(*(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline)))); + rgb.r += 120; *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = 0x00ffffff; + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); + } + /* if (y < (int32_t)cl->wlist.y_size / 2) */ + /* col += 0x00000000; */ + /* else */ + /* col -= 0x00000000; */ } - i = -1; - mlx_put_image_to_window(cl->wlist.wlx, - cl->wlist.winptr, cl->img.img, 0, 0); - sleep(5); - /* while (++i < 120) */ - /* mlx_destroy_image(cl->wlist.wlx, cl->red_scr.img); */ + cl->doicast = 0; } |