fix pbm with get_next_line

This commit is contained in:
asus
2024-01-19 18:52:58 +01:00
parent 78d6e35c7f
commit 60b4a82489
10 changed files with 127 additions and 118 deletions

105
README.md
View File

@@ -1,104 +1,5 @@
# run
# cube3D
**add minilibx and libft submodules :**
- git submodule init
- git submodule update
# todo
- resolve view buble
- add textures
# ressources
- [tuto mlx](https://harm-smits.github.io/42docs/libs/minilibx/getting_started.html)
- [tuto raycasting](https://lodev.org/cgtutor/raycasting.html)
- [tuto raycasting js](http://www.playfuljs.com/a-first-person-engine-in-265-lines)
- [tuto mlx and wolf3d](https://github.com/qst0/ft_libgfx)
- [tuto mlx images](https://github.com/keuhdall/images_example)
- [bmp images](https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html)
- [bmp images in c](https://stackoverflow.com/questions/2654480/writing-bmp-image-in-pure-c-c-without-other-libraries)
---
# keys numbers
```
+-------------.-------.-------+------.-------.-------+------.-------.-------+
| keys linux mac | keys linux mac | keys linux mac |
|-------------.-------.-------|------.-------.-------|------.-------.-------+
| direction keys | alpha keys | num keys |
|-------------.-------.-------|------.-------.-------|------.-------.-------+
| w forward . 119 . _____ | a . 97 . _____ | & (0). (38) . _____ |
| a left . 97 . _____ | b . 98 . _____ | é (1). (233) . _____ |
| s backward . 115 . _____ | c . 99 . _____ | " (2). (34) . _____ |
| d right . 100 . _____ | d . 100 . _____ | ' (3). (39) . _____ |
|-------------.-------.-------| e . 101 . _____ | ( (4). (40) . _____ |
| arrows keys | f . 102 . _____ | - (5). (45) . _____ |
|-------------.-------.-------| g . 103 . _____ | è (6). (232) . _____ |
| ← . 65361 . _____ | h . 104 . _____ | _ (7). (95) . _____ |
| → . 65363 . _____ | i . 105 . _____ | ç (8). (231) . _____ |
| ↓ . 65364 . _____ | j . 106 . _____ | à (9). (224) . _____ |
| ↑ . 65362 . _____ | k . 107 . _____ |------.-------.-------|
|-------------.-------.-------| l . 108 . _____ | other keys |
| special keys | m . 109 . _____ |------.-------.-------|
|-------------.-------.-------| n . 110 . _____ | < (>). 60 . _____ |
| esc . 65307 . _____ | o . 111 . _____ | > .(60) . _____ |
| suppr . 65535 . _____ | p . 112 . _____ | space. 32 . _____ |
| delete . 65288 . _____ | q . 113 . _____ | tab . 65289 . _____ |
| enter . 65293 . _____ | r . 114 . _____ | = (+). 61 . _____ |
|-------------.-------.-------| s . 115 . _____ | + .(61) . _____ |
| hot keys | t . 116 . _____ | - . 45 . _____ |
|-------------.-------.-------| u . 117 . _____ | . . |
| shift left . 65505 . _____ | v . 118 . _____ | . . |
| shift right . 65506 . _____ | w . 119 . _____ | . . |
| ctrl left . 65507 . _____ | x . 120 . _____ | . . |
| ctrl right . 65508 . _____ | y . 121 . _____ | . . |
| . . | z . 122 . _____ | . . |
+-------------.-------.-------+------.-------.-------+------.-------.-------+
```
---
# hook key masks
- https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html
```
x_event | x_mask | action
-------------------------------------------------
2 | 1L << 0 | key press
3 | 1L << 1 | key release
4 | | mouse press
5 | | mouse release
6 | | mouse move
12 | | expose event
17 | 1L << 17 | x button press (red button)
```
---
# fonctions externes autorisees :
- **open**
- **close**
- **read**
- **write**
- **malloc**
- **free**
- **perror**
- **strerror**
- **exit**
- **math lib** :
- **lm** -> needed at compilation to link the lib (eg: `gcc foo.c -o foo -lm`)
- **man**
- **man 3 math**
- **minilibx** :
- `minilibx_opengl.tgz`
- `minilibx_mms_20200219_beta.tgz`
- **to open an archive.tgz** :
- `gzip -d archive.tgz` -> turn it into archive.tar
- `tar -xf archive.tar` -> un-archive it
- how to add a man directory to the manual :
- cp man/man1 /usr/local/share/man/man1 (create man1 if necessary)
- mandb
- i didn't use any of both library above but the one for linux : https://github.com/42Paris/minilibx-linux (there are pbm with their man pages)
This is a 3D mini game, using raycasting, in imitation of Wolfenstein3D or Doom.
![]()

BIN
assets/cube3d_image.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 MiB

BIN
assets/cube3d_map.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 MiB

BIN
assets/cube3d_tour.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 MiB

View File

@@ -18,7 +18,7 @@
*/
/* nbr pixel player move */
# define PLR_MV 9
# define PLR_MV 4
/* degree of rotation of the player per press */
# define PLR_ROT 1
/* nbr key you can press at the same time */

View File

@@ -1,7 +1,7 @@
NO textures/fish.xpm
SO textures/fish.xpm
EA textures/fish.xpm
WE textures/fish.xpm
NO textures/grey.xpm
SO textures/grey.xpm
EA textures/grey.xpm
WE textures/grey.xpm
F 66,66,66
C 33,33,33

104
notes.md Normal file
View File

@@ -0,0 +1,104 @@
# run
**add minilibx and libft submodules :**
- git submodule init
- git submodule update
# todo
- resolve view buble
- add textures
# ressources
- [tuto mlx](https://harm-smits.github.io/42docs/libs/minilibx/getting_started.html)
- [tuto raycasting](https://lodev.org/cgtutor/raycasting.html)
- [tuto raycasting js](http://www.playfuljs.com/a-first-person-engine-in-265-lines)
- [tuto mlx and wolf3d](https://github.com/qst0/ft_libgfx)
- [tuto mlx images](https://github.com/keuhdall/images_example)
- [bmp images](https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html)
- [bmp images in c](https://stackoverflow.com/questions/2654480/writing-bmp-image-in-pure-c-c-without-other-libraries)
---
# keys numbers
```
+-------------.-------.-------+------.-------.-------+------.-------.-------+
| keys linux mac | keys linux mac | keys linux mac |
|-------------.-------.-------|------.-------.-------|------.-------.-------+
| direction keys | alpha keys | num keys |
|-------------.-------.-------|------.-------.-------|------.-------.-------+
| w forward . 119 . _____ | a . 97 . _____ | & (0). (38) . _____ |
| a left . 97 . _____ | b . 98 . _____ | é (1). (233) . _____ |
| s backward . 115 . _____ | c . 99 . _____ | " (2). (34) . _____ |
| d right . 100 . _____ | d . 100 . _____ | ' (3). (39) . _____ |
|-------------.-------.-------| e . 101 . _____ | ( (4). (40) . _____ |
| arrows keys | f . 102 . _____ | - (5). (45) . _____ |
|-------------.-------.-------| g . 103 . _____ | è (6). (232) . _____ |
| ← . 65361 . _____ | h . 104 . _____ | _ (7). (95) . _____ |
| → . 65363 . _____ | i . 105 . _____ | ç (8). (231) . _____ |
| ↓ . 65364 . _____ | j . 106 . _____ | à (9). (224) . _____ |
| ↑ . 65362 . _____ | k . 107 . _____ |------.-------.-------|
|-------------.-------.-------| l . 108 . _____ | other keys |
| special keys | m . 109 . _____ |------.-------.-------|
|-------------.-------.-------| n . 110 . _____ | < (>). 60 . _____ |
| esc . 65307 . _____ | o . 111 . _____ | > .(60) . _____ |
| suppr . 65535 . _____ | p . 112 . _____ | space. 32 . _____ |
| delete . 65288 . _____ | q . 113 . _____ | tab . 65289 . _____ |
| enter . 65293 . _____ | r . 114 . _____ | = (+). 61 . _____ |
|-------------.-------.-------| s . 115 . _____ | + .(61) . _____ |
| hot keys | t . 116 . _____ | - . 45 . _____ |
|-------------.-------.-------| u . 117 . _____ | . . |
| shift left . 65505 . _____ | v . 118 . _____ | . . |
| shift right . 65506 . _____ | w . 119 . _____ | . . |
| ctrl left . 65507 . _____ | x . 120 . _____ | . . |
| ctrl right . 65508 . _____ | y . 121 . _____ | . . |
| . . | z . 122 . _____ | . . |
+-------------.-------.-------+------.-------.-------+------.-------.-------+
```
---
# hook key masks
- https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html
```
x_event | x_mask | action
-------------------------------------------------
2 | 1L << 0 | key press
3 | 1L << 1 | key release
4 | | mouse press
5 | | mouse release
6 | | mouse move
12 | | expose event
17 | 1L << 17 | x button press (red button)
```
---
# fonctions externes autorisees :
- **open**
- **close**
- **read**
- **write**
- **malloc**
- **free**
- **perror**
- **strerror**
- **exit**
- **math lib** :
- **lm** -> needed at compilation to link the lib (eg: `gcc foo.c -o foo -lm`)
- **man**
- **man 3 math**
- **minilibx** :
- `minilibx_opengl.tgz`
- `minilibx_mms_20200219_beta.tgz`
- **to open an archive.tgz** :
- `gzip -d archive.tgz` -> turn it into archive.tar
- `tar -xf archive.tar` -> un-archive it
- how to add a man directory to the manual :
- cp man/man1 /usr/local/share/man/man1 (create man1 if necessary)
- mandb
- i didn't use any of both library above but the one for linux : https://github.com/42Paris/minilibx-linux (there are pbm with their man pages)

View File

@@ -102,7 +102,7 @@ int check_elements(t_game *game, char *file)
return (-1);
while (count < TOTAL_ELEMENTS)
{
get_next_line(fd, &line);
ft_gnl(fd, &line);
mb_add(line);
if (line && *line != '\n' && !check_element(game, line))
count++;

View File

@@ -15,15 +15,19 @@
static int size_map(t_map *map, int fd)
{
char *line;
int ret;
get_next_line(fd, &line);
ret = ft_gnl(fd, &line);
mb_add(line);
while (line)
while (ret > 0)
{
if ((*line == '\n' || *line == '\0') && map->size_x)
if (ret != 0 && map->size_x)
{
mb_free(line);
return (EXIT_FAILURE);
if (*line == '\n' || *line == '\0')
{
mb_free(line);
return (EXIT_FAILURE);
}
}
else if (*line != '\n' && (int)ft_strlen(line) > map->size_x)
{
@@ -35,7 +39,7 @@ static int size_map(t_map *map, int fd)
map->size_y++;
mb_free(line);
line = NULL;
get_next_line(fd, &line);
ret = ft_gnl(fd, &line);
mb_add(line);
}
return (EXIT_SUCCESS);
@@ -52,7 +56,7 @@ static int find_map(t_map *map, char *file)
return (-1);
while (count < TOTAL_ELEMENTS + 1)
{
get_next_line(fd, &map->tmp_str);
ft_gnl(fd, &map->tmp_str);
mb_add(map->tmp_str);
if (!map->tmp_str)
{
@@ -100,7 +104,7 @@ static void fill_map(t_map *map, int fd)
{
if (i > 0)
{
ret = get_next_line(fd, &map->tmp_str);
ret = ft_gnl(fd, &map->tmp_str);
mb_add(map->tmp_str);
}
map->content[i] = (char *)mb_alloc((map->size_x + 1) * sizeof(char));
@@ -110,7 +114,7 @@ static void fill_map(t_map *map, int fd)
map->content[i] = NULL;
while (ret)
{
ret = get_next_line(fd, &map->tmp_str);
ret = ft_gnl(fd, &map->tmp_str);
if (ret)
mb_add(map->tmp_str);
}