Skip to content

Commit

Permalink
Global Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Iipal committed Mar 16, 2019
1 parent acdcaa8 commit ec85540
Show file tree
Hide file tree
Showing 54 changed files with 219 additions and 188 deletions.
25 changes: 14 additions & 11 deletions Makefile
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/03/15 10:58:32 by tmaluh ### ########.fr #
# Updated: 2019/03/16 22:22:38 by tmaluh ### ########.fr #
# #
# **************************************************************************** #

Expand All @@ -26,15 +26,18 @@ endif

CC = gcc -march=native
CFLAGS = -Wall -Wextra -Werror -Ofast

SRC = srcs/main.c srcs/wolf_init.c srcs/wolf_init_textures.c srcs/wolf_map_reader.c \
srcs/wolf_sdl_optimizing_load.c srcs/wolf_sdl_mainmenu_loop.c \
srcs/wolf_sdl_rendering_loop.c srcs/wolf_sdl_rendering_loop_key_press_events.c \
srcs/wolf_sdl_sfx_steps.c srcs/wolf_raycaster.c srcs/wolf_rendering.c \
srcs/wolf_rendering_mainmenu.c srcs/wolf_rendering_colored.c srcs/wolf_rendering_textured.c \
srcs/wolf_rendering_textured_help_fck_norme.c srcs/wolf_rendering_minimap.c \
srcs/wolf_rendering_weapons.c srcs/wolf_rendering_fps_counter.c srcs/wolf_rendering_fog.c \
srcs/wolf_rotatenmove.c srcs/wolf_free.c
INC = -I $(CURDIR)/includes/

SRC = srcs/main.c srcs/wolf_map_reader.c srcs/free/wolf_free.c srcs/init/wolf_init.c srcs/init/wolf_init_textures.c \
srcs/sdl/wolf_sdl_optimizing_load.c \
srcs/sdl/wolf_sdl_mainmenu_loop.c srcs/sdl/wolf_sdl_rendering_loop.c \
srcs/sdl/wolf_sdl_rendering_loop_key_press_events.c \
srcs/sdl/wolf_sdl_sfx_steps.c srcs/raycaster/wolf_raycaster.c srcs/raycaster/wolf_rotatenmove.c \
srcs/rendering/wolf_rendering.c srcs/rendering/wolf_main_menu.c \
srcs/rendering/wolf_colored.c srcs/rendering/wolf_textured.c \
srcs/rendering/wolf_textured_help_fck_norme.c srcs/rendering/wolf_minimap.c \
srcs/rendering/wolf_weapons.c srcs/rendering/wolf_torch.c srcs/rendering/wolf_fps_counter.c \
srcs/rendering/wolf_fog.c

OBJ = $(SRC:.c=.o)

Expand All @@ -53,7 +56,7 @@ all: $(NAME)

$(OBJ): %.o: %.c
@$(ECHO) -n ' $@: '
@$(CC) -c $(CFLAGS) $(SDLINCLUDE) $< -o $@
@$(CC) -c $(CFLAGS) $(SDLINCLUDE) $(INC) $< -o $@
@$(ECHO) "[$(GREEN)$(WHITE)]"

$(LIBFT):
Expand Down
22 changes: 11 additions & 11 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/03/15 11:21:30 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:09:11 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -241,10 +241,11 @@ bool wolf_init(t_env *env);
bool wolf_init_textures(t_env *env);
void wolf_setup_rc(t_env *env);

void wolf_rendering_mainmenu(t_env *env);

void wolf_rendering_fps_counter(t_env *env);
void wolf_rendering_minimap(t_env *env);
Uint32 wolf_fog(float dist_to_obj, Uint32 src_color, t_fog *fog);
Uint32 wolf_fog_change(t_colors *c);
void wolf_rendering_torch(t_env *env);

void wofl_rendering_loop_keys_press(t_env *env, bool *exit);
void wofl_rendering_loop_keys_sfx_press(t_env *env);
Expand All @@ -253,27 +254,26 @@ void wofl_rendering_loop_keys_release(t_env *env);
void wolf_sdl_rendering_loop(t_env *env);
void wolf_sdl_mainmenu_loop(t_env *env);

void wolf_rendering_waepons(t_env *env);
void wolf_rendering_weapons(t_env *env);

void wolf_rendering_rc(t_env *env);
void wolf_rendering_mainmenu(t_env *env);
void wolf_rendering(t_env *env);
void wolf_raycaster(t_env *env);

Uint32 wolf_fog(float dist_to_obj, Uint32 src_color, t_fog *fog);
Uint32 wolf_fog_change(t_colors *c);
float wolf_fog_freq(int *freq, t_time *time);

void wolf_render_textured_help(t_env *env, point *p, t_texhelper *h);
void wolf_render_textured(t_env *env, point *p);
void wolf_render_colored(t_env *env, point *p);
void wolf_fill_floor_if_colored_rc(t_sdl *sdl);

void wolf_set_diststep(t_rc *rc);
void wolf_check_hit(t_rc *rc, itab map);
void wolf_dist_to_wall(t_rc *rc);

bool wolf_is_tile(t_map *map, fpoint pos);

void wolf_rotate(t_rc *rc, float angle);
void wolf_move(t_env *env, float dist);

void wolf_playing_steps(t_sfx *sfx, bool is_boost);

void wolf_press_selector(t_env *env);

void wolf_free(t_env **env);
Expand Down
11 changes: 9 additions & 2 deletions srcs/wolf_free.c → srcs/free/wolf_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/06 14:43:13 by tmaluh #+# #+# */
/* Updated: 2019/03/14 17:15:14 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:20:04 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

void wolf_free_map(t_map **map)
{
Expand Down Expand Up @@ -88,6 +88,13 @@ void wolf_free(t_env **env)
SDL_FreeSurface((*env)->floor_and_sky->surf);
_FREE((*env)->floor_and_sky, free);
}
if ((*env)->walls)
{
SDL_FreeSurface((*env)->walls->data->surf);
_FREE((*env)->walls->data, free);
_FREE((*env)->walls->start, free);
_FREE((*env)->walls, free);
}
_FREE((*env)->isr, free);
_FREE((*env)->rc, free);
_FREE((*env)->sdl->font, TTF_CloseFont);
Expand Down
Binary file added srcs/free/wolf_free.o
Binary file not shown.
4 changes: 2 additions & 2 deletions srcs/wolf_init.c → srcs/init/wolf_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/06 14:38:13 by tmaluh #+# #+# */
/* Updated: 2019/03/15 10:39:52 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 21:27:05 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

void wolf_setup_rc(t_env *env)
{
Expand Down
Binary file added srcs/init/wolf_init.o
Binary file not shown.
4 changes: 2 additions & 2 deletions srcs/wolf_init_textures.c → srcs/init/wolf_init_textures.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/15 10:38:52 by tmaluh #+# #+# */
/* Updated: 2019/03/15 12:26:51 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 21:27:13 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

static bool add_init_textures_map(t_env *env)
{
Expand Down
Binary file added srcs/init/wolf_init_textures.o
Binary file not shown.
4 changes: 2 additions & 2 deletions srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/06 14:19:04 by tmaluh #+# #+# */
/* Updated: 2019/03/15 10:59:26 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 21:26:51 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

static void wolf_usage(void)
{
Expand Down
45 changes: 40 additions & 5 deletions srcs/wolf_raycaster.c → srcs/raycaster/wolf_raycaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/13 11:13:19 by tmaluh #+# #+# */
/* Updated: 2019/02/17 09:36:53 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:22:15 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

void wolf_set_diststep(t_rc *rc)
static void add_set_diststep(t_rc *rc)
{
if (rc->raydir.x < 0)
{
Expand All @@ -36,7 +36,7 @@ void wolf_set_diststep(t_rc *rc)
}
}

void wolf_check_hit(t_rc *rc, itab map)
static void add_check_hit(t_rc *rc, itab map)
{
while (!rc->is_hit)
{
Expand All @@ -57,7 +57,7 @@ void wolf_check_hit(t_rc *rc, itab map)
}
}

void wolf_dist_to_wall(t_rc *rc)
static void add_dist_to_wall(t_rc *rc)
{
!rc->is_side
? (rc->pwd = (rc->map.x - rc->pos.x + (1 - rc->step.x) / 2) / rc->raydir.x)
Expand All @@ -70,3 +70,38 @@ void wolf_dist_to_wall(t_rc *rc)
if (rc->draw_end >= WIN_Y)
rc->draw_end = WIN_Y - 1;
}

static void add_fill_floornceiling(t_sdl *sdl)
{
point p;

p.y = -1;
while (++(p.y) < WIN_Y && (p.x = -1))
while (++(p.x) < WIN_X)
sdl->win_pixels[p.y * WIN_X + p.x] =
(p.y >= WIN_Y / 2) ? IRGB_FLOOR : IRGB_SKY;
}

void wolf_raycaster(t_env *env)
{
point p;

p.x = -1;
if (!env->isr->is_textured)
add_fill_floornceiling(env->sdl);
while (++(p.x) < WIN_X)
{
*(env->rc) = (t_rc){{RC->pos.y, RC->pos.x}, {RC->dir.y, RC->dir.x},
{RC->plane.y, RC->plane.x}, 0, {0, 0}, {0, 0}, {0, 0}, {0, 0}, 0,
{0, 0}, false, false, 0, 0, 0};
RC->xcamera = 2 * p.x / (double)WIN_X - 1;
env->rc->raydir = (fpoint){RC->dir.y + RC->plane.y * RC->xcamera,
env->rc->dir.x + env->rc->plane.x * env->rc->xcamera };
env->rc->map = (point){(int)env->rc->pos.y, (int)env->rc->pos.x};
RC->ddist = (fpoint){_ABS(1 / RC->raydir.y), _ABS(1 / RC->raydir.x)};
add_set_diststep(env->rc);
add_check_hit(env->rc, env->map->tab);
add_dist_to_wall(env->rc);
ISRT ? wolf_render_textured(env, &p) : wolf_render_colored(env, &p);
}
}
Binary file added srcs/raycaster/wolf_raycaster.o
Binary file not shown.
Binary file added srcs/raycaster/wolf_rc_rotatenmove.o
Binary file not shown.
4 changes: 2 additions & 2 deletions srcs/wolf_rotatenmove.c → srcs/raycaster/wolf_rotatenmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/11 01:03:30 by tmaluh #+# #+# */
/* Updated: 2019/02/27 22:43:06 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:05:27 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

bool wolf_is_tile(t_map *map, fpoint pos)
{
Expand Down
Binary file added srcs/raycaster/wolf_rotatenmove.o
Binary file not shown.
17 changes: 3 additions & 14 deletions srcs/wolf_rendering_colored.c → srcs/rendering/wolf_colored.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* wolf_rendering_colored.c :+: :+: :+: */
/* wolf_colored.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/14 13:22:34 by tmaluh #+# #+# */
/* Updated: 2019/02/27 22:32:52 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:22:34 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

static int add_choose_current_color(t_env *env)
{
Expand Down Expand Up @@ -44,14 +44,3 @@ void wolf_render_colored(t_env *env, point *p)
else
env->sdl->win_pixels[p->y * WIN_X + p->x] = current_color;
}

void wolf_fill_floor_if_colored_rc(t_sdl *sdl)
{
point p;

p.y = -1;
while (++(p.y) < WIN_Y && (p.x = -1))
while (++(p.x) < WIN_X)
sdl->win_pixels[p.y * WIN_X + p.x] =
(p.y >= WIN_Y / 2) ? IRGB_FLOOR : IRGB_SKY;
}
Binary file added srcs/rendering/wolf_colored.o
Binary file not shown.
24 changes: 21 additions & 3 deletions srcs/wolf_rendering_fog.c → srcs/rendering/wolf_fog.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* wolf_rendering_fog.c :+: :+: :+: */
/* wolf_fog.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/16 19:10:46 by tmaluh #+# #+# */
/* Updated: 2019/03/09 11:39:02 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:08:02 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

Uint32 wolf_fog_change(t_colors *c)
{
Expand All @@ -22,6 +22,24 @@ Uint32 wolf_fog_change(t_colors *c)
return (colors[*c]);
}

float wolf_fog_freq(int *freq, t_time *time)
{
const float freqs[] = {4.2, 4.25, 4.15, 4.17, 4.22, 4.3, 4.1, 4.16};

if (time->res > REFRESH_TORCH_FOG_FREQ)
{
time->res = 0;
*freq = ft_rand((sizeof(freqs) / sizeof(*freqs)) - 1);
}
else
{
time->old = time->current;
time->current = SDL_GetTicks();
time->res += (time->current - time->old) / 1000.0;
}
return (freqs[(*freq)]);
}

Uint32 wolf_fog(float dist_to_obj, Uint32 src_color, t_fog *fog)
{
float fog_amount;
Expand Down
Binary file added srcs/rendering/wolf_fog.o
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* wolf_rendering_fps_counter.c :+: :+: :+: */
/* wolf_fps_counter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/07 14:42:44 by tmaluh #+# #+# */
/* Updated: 2019/03/09 11:32:13 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:08:04 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

static void add_render_fps(SDL_Surface *text, iarr screen, bool pos)
{
Expand Down
Binary file added srcs/rendering/wolf_fps_counter.o
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* wolf_rendering_mainmenu.c :+: :+: :+: */
/* wolf_main_menu.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/27 11:01:40 by tmaluh #+# #+# */
/* Updated: 2019/03/07 16:11:42 by tmaluh ### ########.fr */
/* Updated: 2019/03/16 22:08:06 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/wolf3d.h"
#include "wolf3d.h"

void wolf_rendering_mainmenu(t_env *env)
{
Expand Down
Binary file added srcs/rendering/wolf_main_menu.o
Binary file not shown.
Loading

0 comments on commit ec85540

Please sign in to comment.