aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
7 files changed, 46 insertions, 17 deletions
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);