diff --git a/Makefile b/Makefile index dcabcd3..5e5a3a3 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tmaluh +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/02/06 14:43:13 by tmaluh #+# #+# # -# Updated: 2019/06/11 20:21:53 by tmaluh ### ########.fr # +# Updated: 2019/06/11 23:09:31 by tmaluh ### ########.fr # # # # **************************************************************************** # @@ -14,6 +14,7 @@ NAME := wolf3d NPWD := $(CURDIR)/$(NAME) CC := gcc -march=native -mtune=native -flto -Ofast -pipe +CC_DEBUG := gcc -march=native -mtune=native -g3 CFLAGS := -Wall -Wextra -Werror -Wunused IFLAGS := -I $(CURDIR)/includes/ -I $(CURDIR)/libft/includes LIBSINC := @@ -65,8 +66,6 @@ del: pre: del all @echo "$(INVERT)$(GREEN)Successed re-build.$(WHITE)" -pre: del all - $(CC_DEBUG): @$(eval CC=$(CC_DEBUG)) debug_all: $(CC_DEBUG) pre diff --git a/includes/wolf3d.h b/includes/wolf3d.h index 435919f..12a67ff 100644 --- a/includes/wolf3d.h +++ b/includes/wolf3d.h @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/06 14:30:10 by tmaluh #+# #+# */ -/* Updated: 2019/04/10 11:18:58 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:41:20 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -210,7 +210,9 @@ void wolf_rendering_minimap(t_env *env); /* ** Render torch. */ -void wolf_rendering_torch(t_env *env); +void wolf_rendering_torch(t_torch *torch, + Uint32 *win_pxls, + uint8_t fog_freq); /* ** Render fog. @@ -230,7 +232,7 @@ float wolf_fog_freq(uint8_t *freq, float *delta, float game_delta); /* ** Render blur. */ -void wolf_blur(point size, iarr src, float value, float dimmed); +void wolf_blur(point size, Uint32 *src, float value, float dimmed); /* ** Play steps sound effects. diff --git a/includes/wolf3d_macroses.h b/includes/wolf3d_macroses.h index bde791b..bcc2557 100644 --- a/includes/wolf3d_macroses.h +++ b/includes/wolf3d_macroses.h @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/09 16:32:35 by tmaluh #+# #+# */ -/* Updated: 2019/06/11 20:20:51 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:32:27 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,12 @@ /* ** Shift torch textures by X for correct display in right down corner. */ -# define TORCH_SHIFT_X ((WIN_X + TORCH->tex[torch_frame].surf->w) / 1.6) +# define TORCH_SHIFT_X ((WIN_X + torch->tex[torch_frame].surf->w) / 1.6) /* ** Shift torch textures by Y for correct display in right down corner. */ -# define TORCH_SHIFT_Y (WIN_Y - TORCH->tex[torch_frame].surf->h) +# define TORCH_SHIFT_Y (WIN_Y - torch->tex[torch_frame].surf->h) /* ** Main menu selector shift by X for correct display in center. diff --git a/includes/wolf3d_structs.h b/includes/wolf3d_structs.h index 52fe5ea..a146b34 100644 --- a/includes/wolf3d_structs.h +++ b/includes/wolf3d_structs.h @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/07 21:38:46 by tmaluh #+# #+# */ -/* Updated: 2019/06/11 20:27:39 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:42:00 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,7 @@ struct s_sdl { SDL_Window *win; SDL_Surface *win_surface; - iarr win_pixels; + Uint32 *win_pixels; SDL_Event event; TTF_Font *font; }; @@ -293,7 +293,7 @@ struct s_walls point *start; int32_t in_row; int32_t in_column; - int32_t max_textures; + size_t max_textures; }; /* @@ -385,7 +385,7 @@ FCOLOR; struct s_bhelp { point *p; - iarr src; + Uint32 *src; float *bmap; float dimm; float factor; diff --git a/srcs/blur/wolf_blur.c b/srcs/blur/wolf_blur.c index 09118ed..d0e1b17 100644 --- a/srcs/blur/wolf_blur.c +++ b/srcs/blur/wolf_blur.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/17 17:47:08 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 19:38:29 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:41:07 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,7 +66,7 @@ static void add_blur_proccesing(t_bhelp b) b.src[b.p->y * WIN_X + b.p->x] = (outc.r << 16 | outc.g << 8 | outc.b); } -void wolf_blur(point size, iarr src, float value, float dimmed) +void wolf_blur(point size, Uint32 *src, float value, float dimmed) { float bmap[size.y][size.x]; float factor; diff --git a/srcs/flags/wolf_fparser.c b/srcs/flags/wolf_fparser.c index bb194e5..a82e2f5 100644 --- a/srcs/flags/wolf_fparser.c +++ b/srcs/flags/wolf_fparser.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/07 17:16:29 by tmaluh #+# #+# */ -/* Updated: 2019/04/10 13:51:34 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:45:03 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,12 +22,12 @@ bool add_fparse_current(t_env *env, string flag, strtab av, int32_t ac) wolf_fno_sound, wolf_fmouse, wolf_fno_menu, wolf_no_fog, wolf_ftex_sides_of_world}; bool is_valid_flag; - int8_t i; + size_t i; - i = -true; + i = ~0UL; is_valid_flag = false; while (F_MAX > ++i) - if (ft_is_one_of_str(flag, 2, flags[i], short_flags[i])) + if (ft_is_one_of_str(flag, false, 2, flags[i], short_flags[i])) { is_valid_flag = true; f_fns[i](env, av, ac); @@ -38,16 +38,19 @@ bool add_fparse_current(t_env *env, string flag, strtab av, int32_t ac) bool wolf_fparser(t_env *env, strtab av, int32_t ac) { - int32_t i; + size_t i; - i = -1; - while (ac > ++i) + i = ~0UL; + while ((size_t)ac > ++i) if (av[i][0] == '-' && ft_isalpha(av[i][1])) { - NOTIS(E_IFLAG, add_fparse_current(env, av[i], av, ac), - wolf_free(&env), false); + NODOM_F(E_IFLAG, add_fparse_current(env, av[i], av, ac), + wolf_free(&env)); } else - NOTIS2(E_IFLAG, false, wolf_free(&env), exit(EXIT_FAILURE)); + { + MSGN(E_IFLAG); + wolf_free(&env); + } return (true); } diff --git a/srcs/flags/wolf_fwindow.c b/srcs/flags/wolf_fwindow.c index 3b7bd9e..38704e7 100644 --- a/srcs/flags/wolf_fwindow.c +++ b/srcs/flags/wolf_fwindow.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/07 21:24:15 by tmaluh #+# #+# */ -/* Updated: 2019/04/10 11:45:45 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:43:55 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ inline void wolf_fnoborder(t_env *env, strtab av, int32_t ac) env->sdl->win = SDL_CreateWindow(WOLF_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIN_X, WIN_Y, SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS); - NOTIS2(SDL_GetError(), env->sdl->win, wolf_free(&env), exit(EXIT_FAILURE)); + IFDOM(SDL_GetError(), env->sdl->win, exit(EXIT_FAILURE)); env->sdl->win_surface = SDL_GetWindowSurface(env->sdl->win); env->sdl->win_pixels = env->sdl->win_surface->pixels; } diff --git a/srcs/free/wolf_free.c b/srcs/free/wolf_free.c index de11d67..e148ae0 100644 --- a/srcs/free/wolf_free.c +++ b/srcs/free/wolf_free.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/06 14:43:13 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 20:09:51 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:16:55 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/init/wolf_init.c b/srcs/init/wolf_init.c index fad34af..8af5be6 100644 --- a/srcs/init/wolf_init.c +++ b/srcs/init/wolf_init.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/06 14:38:13 by tmaluh #+# #+# */ -/* Updated: 2019/04/10 11:20:00 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 21:51:04 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,50 +24,43 @@ void wolf_setup_rc(t_env *env) break ; } if (!env->map->tab[(int32_t)env->rc->pos.y] - [(int32_t)(env->rc->pos.x + 0.05f)]) + [(int32_t)(env->rc->pos.x + 0.05f)]) env->rc->pos.x += 0.05f; if (!env->map->tab[(int32_t)(env->rc->pos.y + 0.05f)] - [(int32_t)env->rc->pos.x]) + [(int32_t)env->rc->pos.x]) env->rc->pos.y += 0.05f; } static bool add_init_menu_and_text(t_env *env) { - ISZ(t_menu, env->menu, 1); - ISZ(t_tex, env->menu->bg, 1); - ISZ(t_tex, env->menu->selector, 1); - NOTIS_F(env->menu->bg->surf = + MEM(t_menu, env->menu, 1, E_ALLOC); + MEM(t_tex, env->menu->bg, 1, E_ALLOC); + MEM(t_tex, env->menu->selector, 1, E_ALLOC); + NO_F(env->menu->bg->surf = wolf_optimize_surf_load(MENU_BG, env->sdl->win_surface->format)); - NOTIS_F(env->menu->selector->surf = + NO_F(env->menu->selector->surf = SDL_CreateRGBSurface(0, SELECTOR_X, SELECTOR_Y, 32, 0, 0, 0, 0)); SDL_FillRect(env->menu->selector->surf, NULL, RGB_WHITE); - NOTIS_F(env->menu->selector->pixels = env->menu->selector->surf->pixels); - NOTIS_F(env->menu->bg->pixels = env->menu->bg->surf->pixels); - NOTIS(TTF_GetError(), - env->sdl->font = TTF_OpenFont(FPS_FONT, 20), exit(EXIT_FAILURE), false); + NO_F(env->menu->selector->pixels = env->menu->selector->surf->pixels); + NO_F(env->menu->bg->pixels = env->menu->bg->surf->pixels); + NOM_F(TTF_GetError(), env->sdl->font = TTF_OpenFont(FPS_FONT, 20)); env->menu->is_selector_start = true; return (true); } static bool add_init_audio(t_env *env) { - ISM(Mix_GetError(), - 0 > Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048), exit(1), false); - ISZ(t_sfx, env->sfx, 1); + IFM_F(Mix_GetError(), + 0 > Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048)); + MEM(t_sfx, env->sfx, 1, E_ALLOC); *(env->sfx) = (t_sfx){NULL, NULL, NULL, NULL, NULL, NULL, {0, 0, 0}, BG_VOL_DEF}; - NOTIS(Mix_GetError(), - env->sfx->ambient_bg = Mix_LoadMUS(AMBIENT_BG), exit(1), false); - NOTIS(Mix_GetError(), - env->sfx->start = Mix_LoadWAV(MSTART), exit(1), false); - NOTIS(Mix_GetError(), - env->sfx->selector = Mix_LoadWAV(MSELECTOR), exit(1), false); - NOTIS(Mix_GetError(), - env->sfx->selector_err = Mix_LoadWAV(MSERROR), exit(1), false); - NOTIS(Mix_GetError(), - env->sfx->lstep = Mix_LoadWAV(GAME_LSTEP), exit(1), false); - NOTIS(Mix_GetError(), - env->sfx->rstep = Mix_LoadWAV(GAME_RSTEP), exit(1), false); + NOM_F(Mix_GetError(), env->sfx->ambient_bg = Mix_LoadMUS(AMBIENT_BG)); + NOM_F(Mix_GetError(), env->sfx->start = Mix_LoadWAV(MSTART)); + NOM_F(Mix_GetError(), env->sfx->selector = Mix_LoadWAV(MSELECTOR)); + NOM_F(Mix_GetError(), env->sfx->selector_err = Mix_LoadWAV(MSERROR)); + NOM_F(Mix_GetError(), env->sfx->lstep = Mix_LoadWAV(GAME_LSTEP)); + NOM_F(Mix_GetError(), env->sfx->rstep = Mix_LoadWAV(GAME_RSTEP)); Mix_VolumeChunk(env->sfx->lstep, 35); Mix_VolumeChunk(env->sfx->rstep, 35); Mix_PlayMusic(env->sfx->ambient_bg, -1); @@ -80,22 +73,22 @@ bool wolf_init(t_env *env) { env->fog = (t_fog){dark, RGB_BLACK, 4.2, 0}; env->bsize = BLUR_DEF; - ISM(SDL_GetError(), SDL_Init(SDL_INIT_EVERYTHING) < 0, exit(1), false); - ISM(TTF_GetError(), TTF_Init() < 0, exit(1), false); - ISZ(t_sdl, env->sdl, 1); - NOTIS(SDL_GetError(), + IFM_F(SDL_GetError(), SDL_Init(SDL_INIT_EVERYTHING) < 0); + IFM_F(TTF_GetError(), TTF_Init() < 0); + MEM(t_sdl, env->sdl, 1, E_ALLOC); + NOM_F(SDL_GetError(), env->sdl->win = SDL_CreateWindow(WOLF_TITLE, SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, WIN_X, WIN_Y, 4), exit(1), false); - NOTIS(SDL_GetError(), - env->sdl->win_surface = SDL_GetWindowSurface(SWIN), exit(1), false); - NOTIS_F(env->sdl->win_pixels = env->sdl->win_surface->pixels); - ISZ(t_isr, env->isr, 1); + SDL_WINDOWPOS_CENTERED, WIN_X, WIN_Y, 4)); + NOM_F(SDL_GetError(), + env->sdl->win_surface = SDL_GetWindowSurface(SWIN)); + NO_F(env->sdl->win_pixels = env->sdl->win_surface->pixels); + MEM(t_isr, env->isr, 1, E_ALLOC); *(env->isr) = (t_isr){1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - ISZ(t_map, env->map, 1); - ISZ(t_rc, env->rc, 1); - ISZ(t_mouse, env->mouse, 1); - NOTIS_F(wolf_init_textures(env)); - NOTIS_F(add_init_menu_and_text(env)); - NOTIS_F(add_init_audio(env)); + MEM(t_map, env->map, 1, E_ALLOC); + MEM(t_rc, env->rc, 1, E_ALLOC); + MEM(t_mouse, env->mouse, 1, E_ALLOC); + NO_F(wolf_init_textures(env)); + NO_F(add_init_menu_and_text(env)); + NO_F(add_init_audio(env)); return (true); } diff --git a/srcs/init/wolf_init_textures.c b/srcs/init/wolf_init_textures.c index f79849c..729b893 100644 --- a/srcs/init/wolf_init_textures.c +++ b/srcs/init/wolf_init_textures.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/15 10:38:52 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 20:10:21 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 21:58:08 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,21 +15,20 @@ static bool add_init_textures_map(t_env *env) { point p; - int32_t i; + size_t i; - i = -1; - NOTIS_F(env->floor_and_sky->surf = + NO_F(env->floor_and_sky->surf = wolf_optimize_surf_load(FLOORNSKY, env->sdl->win_surface->format)); - NOTIS_F(env->floor_and_sky->pixels = env->floor_and_sky->surf->pixels); - NOTIS_F(env->walls->data->surf = + NO_F(env->floor_and_sky->pixels = env->floor_and_sky->surf->pixels); + NO_F(env->walls->data->surf = wolf_optimize_surf_load(WALLTEXTURES, env->sdl->win_surface->format)); - NOTIS_F(env->walls->data->pixels = env->walls->data->surf->pixels); + NO_F(env->walls->data->pixels = env->walls->data->surf->pixels); env->walls->in_column = env->walls->data->surf->h / WALLS_BLOCK_SIZE; env->walls->in_row = env->walls->data->surf->w / WALLS_BLOCK_SIZE; env->walls->max_textures = env->walls->in_column * env->walls->in_row; - ISZ(point, env->walls->start, env->walls->max_textures); - i = -1; + MEM(point, env->walls->start, env->walls->max_textures, E_ALLOC); p = (point){0, 0}; + i = ~0UL; while (env->walls->max_textures > ++i) { env->walls->start[i] = (point){p.y, p.x}; @@ -43,18 +42,20 @@ static bool add_init_textures_map(t_env *env) bool wolf_init_textures(t_env *env) { const string torch[] = {TORCH1, TORCH2, TORCH3, TORCH4, TORCH5, TORCH6}; - int32_t i; + size_t i; - i = -1; - ISZ(t_torch, env->torch, 1); - ISZ(t_tex, env->torch->tex, MAX_TORCH); - ISZ(t_tex, env->floor_and_sky, 1); - ISZ(t_walls, env->walls, 1); - ISZ(t_tex, env->walls->data, 1); + i = ~0UL; + MEM(t_torch, env->torch, 1, E_ALLOC); + MEM(t_tex, env->torch->tex, MAX_TORCH, E_ALLOC); + MEM(t_tex, env->floor_and_sky, 1, E_ALLOC); + MEM(t_walls, env->walls, 1, E_ALLOC); + MEM(t_tex, env->walls->data, 1, E_ALLOC); while (MAX_TORCH > ++i) - NOTIS_F((env->torch->tex[i].surf = - wolf_optimize_surf_load(torch[i], env->sdl->win_surface->format)) - && (env->torch->tex[i].pixels = env->torch->tex[i].surf->pixels)); + { + NO_F(env->torch->tex[i].surf = + wolf_optimize_surf_load(torch[i], env->sdl->win_surface->format)); + env->torch->tex[i].pixels = env->torch->tex[i].surf->pixels; + } add_init_textures_map(env); return (true); } diff --git a/srcs/main.c b/srcs/main.c index c7a1c7c..661e9bd 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/06 14:19:04 by tmaluh #+# #+# */ -/* Updated: 2019/06/11 20:22:58 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:57:07 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,17 +30,17 @@ int main(int argc, string argv[]) { t_env *env; - IFM(E_DIR, ft_strcmp(*argv, WOLF_EXE_PATH), exit(EXIT_FAILURE), 0); - ISARGS(argc, argv); - ISZ(t_env, env, 1); - NOTIS(E_ALLOC, wolf_init(env), wolf_free(&env), EXIT_FAILURE); - NOTIS(E_FILEXT, !ft_strcmp(argv[argc - 1] + + // IFM_F(E_DIR, ft_strcmp(*argv, WOLF_EXE_PATH)); + ISARGS(argc, argv, E_USAGE); + MEM(t_env, env, 1, E_ALLOC); + NODOM_F(E_ALLOC, wolf_init(env), wolf_free(&env)); + NODOM_F(E_FILEXT, !ft_strcmp(argv[argc - 1] + (ft_strlen(argv[argc - 1]) - ft_strlen(WOLF_FILE_EXT)), WOLF_FILE_EXT), - wolf_free(&env), false); - NOTIS_F(wolf_fparser(env, argv, argc - 1)); - NOTIS(E_FILER, wolf_readnsave(argv[argc - 1], env), exit(EXIT_FAILURE), 0); + wolf_free(&env)); + NO_F(wolf_fparser(env, argv, argc - 1)); + NODOM_F(E_FILER, wolf_readnsave(argv[argc - 1], env), wolf_free(&env)); wolf_setup_rc(env); - NOTIS(E_OPEN, ft_putfile(USAGE_GAME_FILE), exit(EXIT_FAILURE), -1); + NOM_F(E_OPEN, ft_putfile(USAGE_GAME_FILE)); if (env->isr->is_no_main_menu) wolf_sdl_rendering_loop(env); else diff --git a/srcs/raycaster/wolf_raycaster.c b/srcs/raycaster/wolf_raycaster.c index 9038c0f..60010fe 100644 --- a/srcs/raycaster/wolf_raycaster.c +++ b/srcs/raycaster/wolf_raycaster.c @@ -6,13 +6,13 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/13 11:13:19 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 23:37:00 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 23:13:23 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ #include "wolf3d.h" -static void add_fill_floornceiling(t_sdl *sdl) +static void add_fill_floornceiling(t_sdl *sdl) { point p; @@ -23,7 +23,7 @@ static void add_fill_floornceiling(t_sdl *sdl) (p.y >= WIN_Y / 2) ? RGB_FLOOR : RGB_SKY; } -static void add_set_diststep(t_rc *rc) +static inline void add_set_diststep(t_rc *rc) { if (0 > rc->raydir.x) { @@ -47,7 +47,7 @@ static void add_set_diststep(t_rc *rc) } } -static void add_dist_to_wall(t_rc *rc) +static inline void add_dist_to_wall(t_rc *rc) { if (!rc->is_side) rc->pwd = (rc->map.x - rc->pos.x + (1 - rc->step.x) / 2) / rc->raydir.x; @@ -60,7 +60,7 @@ static void add_dist_to_wall(t_rc *rc) IFDO(rc->draw_end >= WIN_Y, rc->draw_end = WIN_Y - 1); } -inline void add_check_hit(t_rc *rc, int8_t **map) +static inline void add_check_hit(t_rc *rc, int8_t **map) { if (rc->side_dist.x < rc->side_dist.y) { @@ -77,7 +77,7 @@ inline void add_check_hit(t_rc *rc, int8_t **map) IFDO(map[rc->map.y][rc->map.x] > 0, rc->is_hit = true); } -void wolf_raycaster(t_env *env) +void wolf_raycaster(t_env *env) { point p; diff --git a/srcs/rendering/wolf_fog.c b/srcs/rendering/wolf_fog.c index aacc860..c4e7b2e 100644 --- a/srcs/rendering/wolf_fog.c +++ b/srcs/rendering/wolf_fog.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/16 19:10:46 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 23:32:19 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:22:31 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ Uint32 wolf_fog_change(t_colors *c) float wolf_fog_freq(uint8_t *freq, float *delta, float game_delta) { - const float freqs[] = {4.2, 4.25, 4.13, 4.17, 4.22, 4.3, 4.1, 4.19}; + const float freqs[] = {4.2f, 4.25f, 4.13f, 4.17f, 4.22f, 4.3f, 4.1f, 4.19f}; if (REFRESH_TORCH_FOG_FREQ < *delta) { diff --git a/srcs/rendering/wolf_fps.c b/srcs/rendering/wolf_fps.c index da79ca2..bf051a3 100644 --- a/srcs/rendering/wolf_fps.c +++ b/srcs/rendering/wolf_fps.c @@ -6,13 +6,13 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/07 14:42:44 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 20:19:07 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:40:34 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ #include "wolf3d.h" -static void add_render_fps(SDL_Surface *text, iarr screen, bool pos) +static void add_render_fps(SDL_Surface *text, Uint32 *screen, bool pos) { point tp; point p; diff --git a/srcs/rendering/wolf_rendering.c b/srcs/rendering/wolf_rendering.c index af44146..8067aee 100644 --- a/srcs/rendering/wolf_rendering.c +++ b/srcs/rendering/wolf_rendering.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/06 22:03:53 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 23:30:33 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:36:05 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ void wolf_rendering(t_env *env) { env->fog.fog_dist = wolf_fog_freq(&env->fog.freq, &env->torch->delta, env->fps.time.res); - wolf_rendering_torch(env); + wolf_rendering_torch(env->torch, env->sdl->win_pixels, env->fog.freq); } IFDO(env->isr->is_render_minimap, wolf_rendering_minimap(env)); if (env->isr->is_render_blur) diff --git a/srcs/rendering/wolf_textured.c b/srcs/rendering/wolf_textured.c index 0534725..12b2d77 100644 --- a/srcs/rendering/wolf_textured.c +++ b/srcs/rendering/wolf_textured.c @@ -6,14 +6,14 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/13 15:41:02 by tmaluh #+# #+# */ -/* Updated: 2019/04/10 11:45:19 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 23:14:45 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ #include "wolf3d.h" -static void add_render_floor_init_fpos(t_env *env, t_texhelp *tx, - t_floorhelper *h) +static inline void add_render_floor_init_fpos(t_env *env, t_texhelp *tx, + t_floorhelper *h) { if (!env->rc->is_side && 0 < env->rc->raydir.x) h->fpos = (fpoint){env->rc->map.y + tx->where_is_hit, env->rc->map.x}; @@ -27,7 +27,7 @@ static void add_render_floor_init_fpos(t_env *env, t_texhelp *tx, env->rc->map.x + tx->where_is_hit}; } -static void add_is_render_fog(t_floorhelper *h, t_env *env, +static inline void add_is_render_fog(t_floorhelper *h, t_env *env, point *p, float fog_distance) { const Uint32 curr_floor = (env->floor_and_sky->pixels[FPOS] >> 1) & FCL; @@ -56,7 +56,9 @@ static void add_is_render_fog(t_floorhelper *h, t_env *env, } } -static void add_render_floornceiling(t_env *env, t_texhelp *tx, point *p) +static void add_render_floornceiling(t_env *env, + t_texhelp *tx, + point *p) { t_floorhelper h; @@ -77,7 +79,7 @@ static void add_render_floornceiling(t_env *env, t_texhelp *tx, point *p) } } -inline void add_choose_current_texture(t_env *env, int32_t *curr_tex) +static inline void add_choose_current_texture(t_env *env, int32_t *curr_tex) { uint8_t tex; @@ -87,11 +89,11 @@ inline void add_choose_current_texture(t_env *env, int32_t *curr_tex) if (env->rc->is_side) (0 > env->rc->step.y) ? (tex = 2) : (tex = 3); - if (env->walls->max_textures - 1 < (*curr_tex += tex)) + if (env->walls->max_textures - 1 < (size_t)(*curr_tex += tex)) *curr_tex -= (env->walls->max_textures - 1); } -void wolf_render_textured(t_env *env, point *p) +void wolf_render_textured(t_env *env, point *p) { t_texhelp h; diff --git a/srcs/rendering/wolf_torch.c b/srcs/rendering/wolf_torch.c index 19627a5..1afb133 100644 --- a/srcs/rendering/wolf_torch.c +++ b/srcs/rendering/wolf_torch.c @@ -6,13 +6,13 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/16 22:08:27 by tmaluh #+# #+# */ -/* Updated: 2019/04/10 11:10:28 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:35:58 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ #include "wolf3d.h" -void wolf_rendering_torch(t_env *env) +void wolf_rendering_torch(t_torch *torch, Uint32 *win_pxls, uint8_t fog_freq) { static uint8_t old_torch_frame; static uint8_t torch_frame; @@ -20,21 +20,20 @@ void wolf_rendering_torch(t_env *env) point tp; point p; - if (old_torch_frame != env->fog.freq) + if (old_torch_frame != fog_freq) { torch_frame = ft_rand(MAX_TORCH - 1); - old_torch_frame = env->fog.freq; + old_torch_frame = fog_freq; } tp.y = -1; - torch_shift = (fpoint){TORCH_SHIFT_Y, TORCH_SHIFT_X}; p.y = torch_shift.y; + torch_shift = (fpoint){TORCH_SHIFT_Y, TORCH_SHIFT_X}; while (WIN_Y > ++(p.y) && (tp.x = -1) - && env->torch->tex[torch_frame].surf->h > ++tp.y && (p.x = torch_shift.x)) - while (++p.x < WIN_X && ++tp.x < env->torch->tex[torch_frame].surf->w) - if (!ft_is_one_of_n(env->torch->tex[torch_frame].pixels[ - tp.y * env->torch->tex[torch_frame].surf->w + tp.x], 2, - (long)0xff000000, (long)0x00)) - env->sdl->win_pixels[p.y * WIN_X + p.x] = - env->torch->tex[torch_frame].pixels[tp.y * env->torch->tex[ - torch_frame].surf->w + tp.x]; + && torch->tex[torch_frame].surf->h > ++tp.y && (p.x = torch_shift.x)) + while (++p.x < WIN_X && ++tp.x < torch->tex[torch_frame].surf->w) + if (!ft_is_one_of_n(torch->tex[torch_frame] + .pixels[tp.y * torch->tex[torch_frame].surf->w + tp.x], + 2UL, 0xff000000L, 0x00L)) + win_pxls[p.y * WIN_X + p.x] = torch->tex[torch_frame] + .pixels[tp.y * torch->tex[torch_frame].surf->w + tp.x]; } diff --git a/srcs/sdl/wolf_sdl_optimizing_load.c b/srcs/sdl/wolf_sdl_optimizing_load.c index eabc90a..757fc79 100644 --- a/srcs/sdl/wolf_sdl_optimizing_load.c +++ b/srcs/sdl/wolf_sdl_optimizing_load.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/16 09:51:17 by tmaluh #+# #+# */ -/* Updated: 2019/04/05 15:55:38 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 21:44:49 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,10 @@ SDL_Surface *wolf_optimize_surf_load(string bmp_path, temp_load = NULL; optimize_out = NULL; - NOTIS(SDL_GetError(), - temp_load = SDL_LoadBMP(bmp_path), exit(EXIT_FAILURE), NULL); - NOTIS(SDL_GetError(), - optimize_out = SDL_ConvertSurface(temp_load, format, 0), - exit(EXIT_FAILURE), NULL); + NOM_R(SDL_GetError(), + temp_load = SDL_LoadBMP(bmp_path), NULL); + NOM_R(SDL_GetError(), + optimize_out = SDL_ConvertSurface(temp_load, format, 0), NULL); SDL_FreeSurface(temp_load); return (optimize_out); } @@ -37,12 +36,10 @@ SDL_Surface *wolf_optimize_font_load(string text, SDL_Color text_color, temp_load = NULL; optimize_out = NULL; - NOTIS(TTF_GetError(), - temp_load = TTF_RenderText_Solid(font, text, text_color), - exit(EXIT_FAILURE), NULL); - NOTIS(SDL_GetError(), - optimize_out = SDL_ConvertSurface(temp_load, format, 0), - exit(EXIT_FAILURE), NULL); + NOM_R(TTF_GetError(), + temp_load = TTF_RenderText_Solid(font, text, text_color), NULL); + NOM_R(SDL_GetError(), + optimize_out = SDL_ConvertSurface(temp_load, format, 0), NULL); SDL_FreeSurface(temp_load); return (optimize_out); } diff --git a/srcs/sdl/wolf_sdl_rendering_loop.c b/srcs/sdl/wolf_sdl_rendering_loop.c index 3ce6eb4..c17d2ee 100644 --- a/srcs/sdl/wolf_sdl_rendering_loop.c +++ b/srcs/sdl/wolf_sdl_rendering_loop.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/15 22:59:14 by tmaluh #+# #+# */ -/* Updated: 2019/04/10 11:05:49 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 22:17:30 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,17 +53,17 @@ static void add_loop_isr(t_env *env) void wolf_sdl_rendering_loop(t_env *env) { - bool exit_; + bool quit; - exit_ = false; - while (!exit_) + quit = false; + while (!quit) { while (0 < SDL_PollEvent(&env->sdl->event)) { - IFDO(SDL_QUIT == env->sdl->event.type, exit_ = true); + IFDO(SDL_QUIT == env->sdl->event.type, quit = true); if (SDL_KEYDOWN == env->sdl->event.type) { - wolf_rendering_loop_keys_press(env, &exit_); + wolf_rendering_loop_keys_press(env, &quit); wolf_rendering_loop_keys_sfx_press(env); } if (SDL_KEYUP == env->sdl->event.type) diff --git a/srcs/wolf_map_reader.c b/srcs/wolf_map_reader.c index d9fb380..13c28d0 100644 --- a/srcs/wolf_map_reader.c +++ b/srcs/wolf_map_reader.c @@ -6,7 +6,7 @@ /* By: tmaluh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/06 17:18:56 by tmaluh #+# #+# */ -/* Updated: 2019/04/09 20:04:15 by tmaluh ### ########.fr */ +/* Updated: 2019/06/11 23:01:21 by tmaluh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ static bool add_save_map(string line, int8_t *map_line, if (ft_isdigit(*line)) { map_line[++x] = ft_atoi(line); - NOTIS_F(!(map_line[x] < 0 || map_line[x] > MAX_TEXTURES)); + NO_F(!(map_line[x] < 0 || map_line[x] > MAX_TEXTURES)); colors_line[x] = colors[map_line[x] - 1]; temp_digits = ft_itoa(map_line[x]); digits = ft_strlen(temp_digits); @@ -68,21 +68,21 @@ static bool add_valid_info(string info_line, t_map *map) int i; i = 0; - IS_F(!(map->size.y = ft_atoi(info_line)) || map->size.y < 0); + IF_F(!(map->size.y = ft_atoi(info_line)) || map->size.y < 0); while (info_line[i] && ft_isdigit(info_line[i])) ++i; - NOTIS_F(i); - IS_F(!(map->size.x = ft_atoi(info_line + ++i)) || map->size.x < 0); + NO_F(i); + IF_F(!(map->size.x = ft_atoi(info_line + ++i)) || map->size.x < 0); while (info_line[i] && ft_isdigit(info_line[i])) ++i; - IS_F(info_line[i]); - NOTIS_F(map->tab = (int8_t**)malloc(sizeof(int8_t*) * map->size.y)); - NOTIS_F(map->colors = (itab)malloc(sizeof(iarr) * map->size.y)); + IF_F(info_line[i]); + NO_F(map->tab = (int8_t**)malloc(sizeof(int8_t*) * map->size.y)); + NO_F(map->colors = (itab)malloc(sizeof(iarr) * map->size.y)); i = -1; while (++i < map->size.y) { - NOTIS_F(map->tab[i] = (int8_t*)malloc(sizeof(int8_t) * map->size.x)); - NOTIS_F(map->colors[i] = (iarr)malloc(sizeof(int) * map->size.x)); + NO_F(map->tab[i] = (int8_t*)malloc(sizeof(int8_t) * map->size.x)); + NO_F(map->colors[i] = (iarr)malloc(sizeof(int) * map->size.x)); } ft_strdel(&info_line); return (true); @@ -98,7 +98,7 @@ static bool add_endofmap(t_env *env, int y, { while (++y < map_max.y - 1 && (i = -1)) while (++i < map_max.x) - IS(!env->map->tab[y][i], (void)i, true); + NO_R(env->map->tab[y][i], true); return (false); } else if (!y || y == map_max.y - 1) @@ -118,29 +118,30 @@ static bool add_endofmap(t_env *env, int y, bool wolf_readnsave(string map_name, t_env *env) { - string gnl_temp; - int gnl_ret; - int fd; - int i; + const int32_t fd = open(map_name, O_RDONLY); + string gnl_temp; + int32_t gnl_ret; + size_t i; - i = -1; + i = ~0UL; gnl_temp = NULL; - IS_F(!(fd = open(map_name, O_RDONLY)) || fd < 0); - IS_F(ft_gnl(fd, &gnl_temp) < 0); - NOTIS_F(add_valid_info(gnl_temp, env->map)); - while ((gnl_ret = ft_gnl(fd, &gnl_temp)) && ++i < env->map->size.y) + IF_F(!fd || 0 > fd); + IFDO_F(ft_gnl(fd, &gnl_temp) < 0, close(fd)); + NO_F(add_valid_info(gnl_temp, env->map)); + while ((gnl_ret = ft_gnl(fd, &gnl_temp)) && (size_t)env->map->size.y > ++i) { - ISM(E_IMAP, add_valid_inline_numbers(gnl_temp) != env->map->size.x, + IFDOMR(E_IMAP, add_valid_inline_numbers(gnl_temp) != env->map->size.x, ft_strdel(&gnl_temp), false); - NOTIS(E_IMAP, add_save_map(gnl_temp, MAP[i], MAPC[i], + IFDOMR(E_IMAP, add_save_map(gnl_temp, MAP[i], MAPC[i], env->map->size.x), ft_strdel(&gnl_temp), false); - NOTIS(E_ENDMAP, add_endofmap(env, i, (point){MAPY, env->map->size.x}, + IFDOMR(E_ENDMAP, add_endofmap(env, i, (point){MAPY, env->map->size.x}, false), ft_strdel(&gnl_temp), false); ft_strdel(&gnl_temp); } - ISM(E_IMAP, gnl_ret || gnl_temp, exit(EXIT_FAILURE), false); - IS_F(++i != env->map->size.y); - NOTIS(E_NOFLOOR, add_endofmap(env, 0, (point){env->map->size.y, - env->map->size.x}, true), exit(EXIT_FAILURE), 0); + close(fd); + IFM_F(E_IMAP, gnl_ret || gnl_temp); + IF_F(++i != (size_t)env->map->size.y); + NOM_F(E_NOFLOOR, add_endofmap(env, 0, (point){env->map->size.y, + env->map->size.x}, true)); return (true); }