Skip to content

Commit

Permalink
refactor?
Browse files Browse the repository at this point in the history
  • Loading branch information
Iipal committed Jun 11, 2019
1 parent 2a86d33 commit 00a4a38
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 177 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
# By: tmaluh <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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 #
# #
# **************************************************************************** #

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 :=
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions includes/wolf3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions includes/wolf3d_macroses.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions includes/wolf3d_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};

/*
Expand Down Expand Up @@ -385,7 +385,7 @@ FCOLOR;
struct s_bhelp
{
point *p;
iarr src;
Uint32 *src;
float *bmap;
float dimm;
float factor;
Expand Down
4 changes: 2 additions & 2 deletions srcs/blur/wolf_blur.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
Expand Down
23 changes: 13 additions & 10 deletions srcs/flags/wolf_fparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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);
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions srcs/flags/wolf_fwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion srcs/free/wolf_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down
77 changes: 35 additions & 42 deletions srcs/init/wolf_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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);
Expand All @@ -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);
}
39 changes: 20 additions & 19 deletions srcs/init/wolf_init_textures.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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};
Expand All @@ -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);
}
Loading

0 comments on commit 00a4a38

Please sign in to comment.