Skip to content

Commit

Permalink
meh, trying refactor wolf3d
Browse files Browse the repository at this point in the history
  • Loading branch information
Iipal committed Jun 11, 2019
1 parent 1e01804 commit 2a86d33
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 136 deletions.
78 changes: 34 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,73 @@
# By: tmaluh <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/02/06 14:43:13 by tmaluh #+# #+# #
# Updated: 2019/06/08 13:55:59 by tmaluh ### ########.fr #
# Updated: 2019/06/11 20:21:53 by tmaluh ### ########.fr #
# #
# **************************************************************************** #

NAME := wolf3d
NPWD := $(CURDIR)/$(NAME)

ECHO := echo
CC := gcc -march=native -mtune=native -flto -Ofast -pipe
CFLAGS := -Wall -Wextra -Werror -Wunused
IFLAGS := -I $(CURDIR)/includes/ -I $(CURDIR)/libft/includes
LIBSINC :=
LIBS :=

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
ECHO += -e

PACKAGE_MANAGER := sudo dnf
INSTALLED_LIBS_LIST := $(shell rpm -qa)
SDL2_NECCESSARY_LIBS := SDL2-devel-2.0.9-3.fc30.x86_64 \
SDL2_ttf-devel-2.0.15-2.fc30.x86_64 \
SDL2_mixer-devel-2.0.4-3.fc30.x86_64
endif
ifeq ($(UNAME_S),Darwin)
LIBSINC := --I ~/.brew/include
LIBS := -L ~/.brew/lib -rpath ~/.brew/lib

PACKAGE_MANAGER := brew
INSTALLED_LIBS_LIST := $(shell $(PACKAGE_MANAGER) list)
SDL2_NECCESSARY_LIBS := sdl2 sdl2_image sdl2_ttf
LIBSINC += -I ~/.brew/include
LIBS += -L ~/.brew/lib -rpath ~/.brew/lib
endif
LIBS += -lSDL2 -lSDL2_mixer -lSDL2_ttf -lm

LIBS := -lSDL2 -lSDL2_mixer -lSDL2_ttf -lm

SDL2_INSTALLED_LIBS := $(filter $(SDL2_NECCESSARY_LIBS), $(INSTALLED_LIBS_LIST))
SDL2_NOT_INSTALLED_LIBS := $(filter-out $(SDL2_INSTALLED_LIBS),$(SDL2_NECCESSARY_LIBS))

CC := gcc -march=native -mtune=native -flto -Ofast
CFLAGS := -Wall -Wextra -Werror -Wunused
IFLAGS := -I $(CURDIR)/includes/

SRC := $(abspath $(wildcard srcs/*.c))
SRC += $(abspath $(wildcard srcs/*/*.c))
SRC := $(abspath $(wildcard srcs/*.c srcs/*/*.c))
OBJ := $(SRC:.c=.o)

LIBFT := $(CURDIR)/libft/libft.a
LMAKE := make -C libft

DEL := rm -rf

WHITE := \033[0m
BGREEN := \033[42m
GREEN := \033[32m
RED := \033[31m
INVERT := \033[7m

SUCCESS = [$(GREEN)$(WHITE)]
SUCCESS := [$(GREEN)$(WHITE)]
SUCCESS2 := [$(INVERT)$(GREEN)$(WHITE)]

DEL := rm -rf

all: $(SDL2_NOT_INSTALLED_LIBS) $(NAME)

$(SDL2_NOT_INSTALLED_LIBS):
ifneq ($(SDL2_NOT_INSTALLED_LIBS),)
$(warning some SDL2 neccessary libs not founded, installing:)
$(PACKAGE_MANAGER) install $(SDL2_NOT_INSTALLED_LIBS)
endif
all: $(NAME)

$(OBJ): %.o: %.c
@$(ECHO) -n ' $@: '
@echo -n ' $@: '
@$(CC) -c $(CFLAGS) $(LIBSINC) $(IFLAGS) $< -o $@
@$(ECHO) "$(SUCCESS)"
@echo "$(SUCCESS)"

$(LIBFT):
@$(LMAKE)

$(NAME): $(LIBFT) $(OBJ)
@$(ECHO) -n ' <q.p> | $(NPWD): '
@echo -n ' <q.p> | $(NPWD): '
@$(CC) $(OBJ) $(LIBS) $(LIBFT) -o $(NAME)
@$(ECHO) "[$(INVERT)$(GREEN)$(WHITE)]"
@echo "$(SUCCESS2)"

del:
@$(DEL) $(OBJ)
@$(DEL) $(NAME)

pre: del all
@echo "$(INVERT)$(GREEN)Successed re-build.$(WHITE)"

pre: del all

$(CC_DEBUG):
@$(eval CC=$(CC_DEBUG))
debug_all: $(CC_DEBUG) pre
@echo "$(INVERT)$(NAME) $(GREEN)ready for debug.$(WHITE)"
debug: $(CC_DEBUG) all
@echo "$(INVERT)$(NAME) $(GREEN)ready for debug.$(WHITE)"

clean:
@$(DEL) $(OBJ)
Expand All @@ -91,8 +81,8 @@ clean:
fclean: clean
@$(LMAKE) fclean
@$(DEL) $(NAME)
@$(ECHO) "$(INVERT)$(RED)deleted$(WHITE)$(INVERT): $(NPWD)$(WHITE)"
@echo "$(INVERT)$(RED)deleted$(WHITE)$(INVERT): $(NPWD)$(WHITE)"

re: fclean all

.PHONY: all fclean clean re
.PHONY: all fclean clean re pre debug debug_all set_cc_debug
2 changes: 1 addition & 1 deletion includes/wolf3d_defines.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:34:31 by tmaluh #+# #+# */
/* Updated: 2019/04/09 20:00:50 by tmaluh ### ########.fr */
/* Updated: 2019/06/11 20:20:24 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
86 changes: 1 addition & 85 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/04/09 16:32:54 by tmaluh ### ########.fr */
/* Updated: 2019/06/11 20:20:51 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -33,90 +33,6 @@
*/
# define SELECTOR_START_Y ((WIN_Y - SELECTOR_Y) / 2.0)

/*
** Used for validate argmunets count;
** \param ac: Arguments counter.
** \param av: Arguments array.
*/
# define ISARGS(ac, av) {--ac;++av; NOTIS(E_USAGE, ac, exit(-1), 0);}

/*
** If \param ex true:
** \param do something.
*/
# define IFDO(ex, do) if ((ex)) { do; }

/*
** Print \param msg to stdout.
*/
# define MSG(msg) ft_putstr(msg)

/*
** Print \param msg to stdout followed by newline at end.
*/
# define MSGN(msg) ft_putendl(msg)

/*
** If \param ex false:
** Print \param msg followed by newline at end.
** \param do something.
** \param ret return value.
*/
# define NOTIS(msg, ex, do, ret) if (!(ex)) {MSGN(msg);do;return(ret);}

/*
** If \param ex false:
** Print \param msg followed by newline at end.
** \param do1 something.
** \param do2 something.
*/
# define NOTIS2(msg, ex, do1, do2) if (!(ex)) {MSGN(msg);do1;do2;}

/*
** If \param ex false return false.
*/
# define NOTIS_F(ex) if (!(ex)) return (false)

/*
** If \param ex true:
** \param do something.
** \param ret return value.
*/
# define IS(ex, do, ret) if ((ex)) {do; return (ret);}

/*
** If \param ex true:
** Print \param msg followed by newline at end.
** \param do something.
** \param ret return value.
*/
# define ISM(msg, ex, do, ret) if ((ex)) {MSGN(msg);do;return (ret);}

/*
** If \param ex true return false.
*/
# define IS_F(ex) if ((ex)) return (false)

/*
** Called ft_bzero(\param dest, size of \param type multiply by \param x).
*/
# define Z(type, dest, x) ft_bzero(dest, sizeof(type) * (x))

/*
** Allocating memroy and set all values to zero by calling Z macros.
** \param t data type.
** \param d destination variable.
** \param x counter how much \param t memory needed to allocate.
*/
# define ISZ(t, d, x) NOTIS_F(d = (t*)malloc(sizeof(t)*(x))); Z(t, d, x)

/*
** If \param trash isnt NULL:
** Free memory with \param del function call.
** And set \param trash to NULL.
*/
# define FREE(trash, del) if ((trash)) {del(trash); trash = NULL;}

/*
** --------------
** Math macroses:
Expand Down
9 changes: 5 additions & 4 deletions includes/wolf3d_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
/* By: tmaluh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/07 21:38:46 by tmaluh #+# #+# */
/* Updated: 2019/06/08 13:55:22 by tmaluh ### ########.fr */
/* Updated: 2019/06/11 20:27:39 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef WOLF3D_STRUCTS_H
# define WOLF3D_STRUCTS_H

# if defined __APPLE__ || defined __linux
# if defined __APPLE__ || defined __linux__
# include <SDL2/SDL.h>
# include <SDL2/SDL_ttf.h>
# include <SDL2/SDL_mixer.h>
# else
# error "Unsupported OS. Try to compile this on MacOS or Linux"
# endif

# include "libft.h"
# include "wolf3d_defines.h"
# include "../libft/includes/libft.h"

/*
** Uncommented cheats:
Expand Down Expand Up @@ -324,7 +324,8 @@ struct s_wolf3d_environment

/*
** (t_sdl*)sdl: All sdl stuff what needed to work with SDL2 framework.
** (t_isr*)isr: Full bool struct with flags for e\disable all binding features.
** (t_isr*)isr: Full bool struct with flags
** for en\disable all binding features & also.
** (t_map*)map: Map readed from file.
** (t_rc*)rc: All RayCasting data.
** (t_tex*)floor_and_sky: Texture map with floor and sky textures.
Expand Down
4 changes: 2 additions & 2 deletions srcs/main.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:19:04 by tmaluh #+# #+# */
/* Updated: 2019/04/10 11:05:19 by tmaluh ### ########.fr */
/* Updated: 2019/06/11 20:22:58 by tmaluh ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -30,7 +30,7 @@ int main(int argc, string argv[])
{
t_env *env;

ISM(E_DIR, ft_strcmp(*argv, WOLF_EXE_PATH), exit(EXIT_FAILURE), 0);
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);
Expand Down

0 comments on commit 2a86d33

Please sign in to comment.