aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--inc/cub3d.h12
-rw-r--r--map/map_one.cub2
-rw-r--r--src/ft_check_missing.c2
-rw-r--r--src/ft_free_words.c3
-rw-r--r--src/ft_get_res.c31
-rw-r--r--src/ft_get_screen_size.c16
-rw-r--r--src/ft_init_lists.c7
-rw-r--r--src/ft_parse_map.c2
-rw-r--r--src/ft_select_get.c2
10 files changed, 62 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 5a9900b..4b7afbb 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ SRCS_NAME += ft_exit.c
SRCS_NAME += ft_drawsquare.c
SRCS_NAME += ft_parse_map.c
SRCS_NAME += ft_select_get.c
+SRCS_NAME += ft_get_screen_size.c
SRCS_NAME += ft_get_res.c
SRCS_NAME += ft_get_tex.c
SRCS_NAME += ft_get_sprite.c
@@ -50,6 +51,7 @@ CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Werror
CFLAGS += -pedantic
+CFLAGS += -DFT_SCR_SIZE=\"${SCR_SZE}\"
ifdef ASAN
CFLAGS += ${DEBUG}
CFLAGS += ${FSANITIZE}
@@ -69,10 +71,14 @@ endif
MKDIR = mkdir -p
RM = rm -rf
OS = $(shell uname)
+ifeq (${OS}, Darwin)
+ SCR_SZE = $(shell xdpyinfo | grep dimensions | awk '{print $$2}')
+endif
#==============================================================================#
#--------------------------------- Rules --------------------------------------#
#==============================================================================#
${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}${INCS}
+ echo ${SCR_SIZE}
@${MKDIR} ${OBJS_DIR}
ifeq (${OS}, Darwin)
${CC} -c ${CFLAGS} -I${LFT_DIR}${INCS_DIR} -I${MLX_DIR} -I${INCS_DIR} -o $@ $<
diff --git a/inc/cub3d.h b/inc/cub3d.h
index f031c1c..cf35d92 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -32,14 +32,19 @@
# ifndef FT_ESC_KEY
# define FT_ESC_KEY 53
# endif
+# ifndef FT_SCR_SIZE
+# define FT_SCR_SIZE 1980x1080
+# endif
typedef struct s_win
{
void *wlx;
void *winptr;
uint8_t inited;
- int16_t x_size;
- int16_t y_size;
+ uint16_t x_max_size;
+ uint16_t y_max_size;
+ uint16_t x_size;
+ uint16_t y_size;
} t_win;
typedef struct s_img
@@ -103,6 +108,7 @@ int ft_exit(uint8_t exit_code, t_cub *clist);
void ft_drawsquare(int a, int b, int rgb, t_cub *clist);
void ft_parse_map(const char *map_path, t_cub *clist);
uint8_t ft_select_get(char **words, t_cub *clist);
+int8_t ft_get_screen_size(t_win *wlist);
int ft_get_res(char **words, t_cub *clist);
int ft_get_tex_no(char **words, t_cub *clist);
int ft_get_tex_so(char **words, t_cub *clist);
@@ -118,7 +124,7 @@ int ft_check_missing(t_cub *clist);
int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist);
size_t ft_get_line_len(char *line);
int ft_missing_error(const char *err, t_cub *clist);
-void ft_free_words(char **words);
+uint8_t ft_free_words(char **words);
int ft_map_error(t_cub *clist);
int ft_init_winlx(t_cub *clist);
void ft_drawmap(t_cub *clist);
diff --git a/map/map_one.cub b/map/map_one.cub
index f0bd991..fddb25c 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -1,4 +1,4 @@
-R 1720 880
+R 1880 900
NO ./path_to_the_north_texture
SO ./path_to_the_south_texture
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
index 32e2943..325af54 100644
--- a/src/ft_check_missing.c
+++ b/src/ft_check_missing.c
@@ -35,7 +35,7 @@ int
return (ft_missing_error("east side texture", clist));
else if (!clist->we_tex_path[0])
return (ft_missing_error("west side texture", clist));
- else if (clist->wlist->x_size < 0 || clist->wlist->y_size < 0)
+ else if (clist->wlist->x_size == 0 || clist->wlist->y_size == 0)
return (ft_missing_error("resolution", clist));
else if (clist->f_color < 0)
return (ft_missing_error("floor color", clist));
diff --git a/src/ft_free_words.c b/src/ft_free_words.c
index 99b7daf..de52244 100644
--- a/src/ft_free_words.c
+++ b/src/ft_free_words.c
@@ -13,7 +13,7 @@
#include <libft.h>
-void
+uint8_t
ft_free_words(char **words)
{
size_t i;
@@ -25,4 +25,5 @@ void
i++;
}
ft_memdel((void**)&words);
+ return (0);
}
diff --git a/src/ft_get_res.c b/src/ft_get_res.c
index 5b48688..25f87fd 100644
--- a/src/ft_get_res.c
+++ b/src/ft_get_res.c
@@ -14,8 +14,8 @@
#include <libft.h>
#include <cub3d.h>
-static void
- ft_checkdigit(const char *word, t_cub *clist)
+static int8_t
+ ft_checkdigit(const char *word)
{
size_t i;
@@ -23,21 +23,30 @@ static void
while (ft_isdigit(word[i]))
i++;
if (i != ft_strlen(word))
- ft_map_error(clist);
+ return (-1);
+ return (0);
}
int
ft_get_res(char **words, t_cub *clist)
{
- if (!(*words + 0) || !(*(words + 1))
- || !(*(words + 2)) || (*(words + 3)))
+ t_win *wlist = clist->wlist;
+ if (!(*words + 0) || !(*(words + 1)) ||
+ !(*(words + 2)) || (*(words + 3)))
+ return (-1);
+ if ((ft_checkdigit(words[1]) < 0) ||
+ (ft_checkdigit(words[2]) < 0))
+ return (-1);
+ wlist->x_size = ft_atoi(words[1]);
+ wlist->y_size = ft_atoi(words[2]);
+ if (wlist->x_size < 1
+ || wlist->y_size < 1)
return (-1);
- ft_checkdigit(words[1], clist);
- ft_checkdigit(words[2], clist);
- clist->wlist->x_size = ft_atoi(words[1]);
- clist->wlist->y_size = ft_atoi(words[2]);
- if (clist->wlist->x_size < 10
- || clist->wlist->y_size < 10)
+ if (ft_get_screen_size(wlist) < 0)
return (-1);
+ if (wlist->x_size > wlist->x_max_size)
+ wlist->x_size = wlist->x_max_size;
+ if (wlist->y_size > wlist->y_max_size)
+ wlist->y_size = wlist->y_max_size;
return (0);
}
diff --git a/src/ft_get_screen_size.c b/src/ft_get_screen_size.c
new file mode 100644
index 0000000..cd9b162
--- /dev/null
+++ b/src/ft_get_screen_size.c
@@ -0,0 +1,16 @@
+#include <libft.h>
+#include <cub3d.h>
+
+int8_t
+ft_get_screen_size(t_win *wlist)
+{
+ char **words;
+
+ if (!(words = ft_split(FT_SCR_SIZE, 'x')))
+ return (-1);
+ if (!(*words + 0) || !(*(words + 1)) || (*(words + 2)))
+ return (-1);
+ wlist->x_max_size = ft_atoi(words[0]);
+ wlist->y_max_size = ft_atoi(words[1]);
+ return (ft_free_words(words));
+}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 74c1b3d..175f5ee 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -16,6 +16,7 @@
#include <cub3d.h>
#include <stddef.h>
#include <stdlib.h>
+#include <limits.h>
t_win
*ft_init_win(void)
@@ -28,8 +29,10 @@ t_win
!(wlist->winptr = malloc(1)))
return (NULL);
wlist->inited = 0;
- wlist->x_size = -1;
- wlist->y_size = -1;
+ wlist->x_size = 0;
+ wlist->y_size = 0;
+ wlist->x_max_size = 0;
+ wlist->y_max_size = 0;
return (wlist);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index f5e491f..5a72bd8 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -120,7 +120,7 @@ void
ft_get_player_spawn(clist->plist, clist);
ft_check_missing(clist);
clist->scale = ((uint16_t)clist->wlist->x_size /
- (uint16_t)clist->map_w) - 2;
+ (uint16_t)clist->map_w) - 1;
ft_print_list(clist);
close(fd);
}
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index 3c14681..74cd000 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -21,7 +21,7 @@ ft_check_exists(const int8_t ret, t_cub *clist)
{
if (ret == 12)
return (12);
- if (ret == 0 && (clist->wlist->x_size != -1 || clist->wlist->y_size != -1))
+ if (ret == 0 && (clist->wlist->x_size != 0 || clist->wlist->y_size != 0))
return (-1);
else if (ret == 1 && (clist->no_tex_path[0]))
return (-1);