some norminette and some cleaning
This commit is contained in:
parent
02ff526212
commit
fd4fb3c93f
12 changed files with 102 additions and 79 deletions
23
src/input.c
23
src/input.c
|
|
@ -6,11 +6,13 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/11/07 18:37:52 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 19:03:15 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "input.h"
|
||||
#include "input_utils.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "const.h"
|
||||
|
||||
|
|
@ -37,33 +39,18 @@ static void set_action(int keycode, bool value)
|
|||
set_quit(NULL);
|
||||
}
|
||||
|
||||
int hook_keypress(int keycode)
|
||||
static int hook_keypress(int keycode)
|
||||
{
|
||||
set_action(keycode, true);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int hook_keyrelease(int keycode)
|
||||
static int hook_keyrelease(int keycode)
|
||||
{
|
||||
set_action(keycode, false);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int hook_mousemove(int x, int y)
|
||||
{
|
||||
static const t_point_int window_middle = {
|
||||
SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2};
|
||||
static bool first_call = true;
|
||||
const int dx = x - window_middle.x;
|
||||
|
||||
if (!first_call && dx)
|
||||
g_input_actions.rotate += dx;
|
||||
first_call = false;
|
||||
if (x != window_middle.x || y != window_middle.y)
|
||||
mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y);
|
||||
return (0);
|
||||
}
|
||||
|
||||
// TODO hide cursor without leak?
|
||||
void input_init(void *mlx_ptr, void *win_ptr)
|
||||
{
|
||||
|
|
|
|||
28
src/input_utils.c
Normal file
28
src/input_utils.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* input_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/07 19:02:04 by mc #+# #+# */
|
||||
/* Updated: 2024/11/07 19:02:15 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "input_utils.h"
|
||||
|
||||
static int hook_mousemove(int x, int y)
|
||||
{
|
||||
static const t_point_int window_middle = {
|
||||
SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2};
|
||||
static bool first_call = true;
|
||||
const int dx = x - window_middle.x;
|
||||
|
||||
if (!first_call && dx)
|
||||
g_input_actions.rotate += dx;
|
||||
first_call = false;
|
||||
if (x != window_middle.x || y != window_middle.y)
|
||||
mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y);
|
||||
return (0);
|
||||
}
|
||||
20
src/input_utils.h
Normal file
20
src/input_utils.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* input_utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/07 19:02:26 by mc #+# #+# */
|
||||
/* Updated: 2024/11/07 19:03:02 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INPUT_UTILS_H
|
||||
# define INPUT_UTILS_H
|
||||
|
||||
# include "input.h"
|
||||
|
||||
static int hook_mousemove(int x, int y);
|
||||
|
||||
#endif
|
||||
12
src/main.c
12
src/main.c
|
|
@ -6,17 +6,17 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 16:57:40 by mc #+# #+# */
|
||||
/* Updated: 2024/11/07 17:12:44 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 18:44:01 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "main.h"
|
||||
|
||||
# include "render.h"
|
||||
# include "move.h"
|
||||
# include "input.h"
|
||||
# include "const.h"
|
||||
# include "global.h"
|
||||
#include "render.h"
|
||||
#include "move.h"
|
||||
#include "input.h"
|
||||
#include "const.h"
|
||||
#include "global.h"
|
||||
|
||||
static int g_return_value = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/11/07 15:49:39 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 18:58:34 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -81,7 +81,8 @@ void map_destroy(t_map *map)
|
|||
d = 0;
|
||||
while (d < 4)
|
||||
{
|
||||
mlx_destroy_image(g_mlx, map->textures[d].image);
|
||||
if (map->textures[d].image)
|
||||
mlx_destroy_image(g_mlx, map->textures[d].image);
|
||||
free((void *)map->texture_srcs[d]);
|
||||
d++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/03 15:05:13 by mc #+# #+# */
|
||||
/* Updated: 2024/11/06 19:34:01 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 19:04:19 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -74,6 +74,6 @@ bool read_map_description(t_map *map, t_stream *stream);
|
|||
/// @param map Map to use.
|
||||
void map_init_objects(t_map *map);
|
||||
|
||||
bool load_textures(t_map *map);
|
||||
bool load_textures(t_map *map);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/03 15:02:09 by mc #+# #+# */
|
||||
/* Updated: 2024/11/06 19:33:31 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 18:59:07 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -74,41 +74,40 @@ bool read_string_parameter(const char *name, const char **dest,
|
|||
|
||||
static void read_map2(t_map *dest, bool *err, bool *rdf)
|
||||
{
|
||||
ft_memset(dest, '\0', sizeof(dest));
|
||||
ft_memset(dest, '\0', sizeof(t_map));
|
||||
dest->color_ceiling = 0xFF000000;
|
||||
dest->color_floor = 0xFF000000;
|
||||
*err = false;
|
||||
*rdf = false;
|
||||
}
|
||||
|
||||
bool read_map(t_map *dest, t_stream *s)
|
||||
bool read_map(t_map *d, t_stream *s)
|
||||
{
|
||||
bool err;
|
||||
bool rdf;
|
||||
bool err[2];
|
||||
int old_stream_i;
|
||||
|
||||
read_map2(dest, &err, &rdf);
|
||||
while (!rdf && !err && s->str[s->i])
|
||||
read_map2(d, &err[0], &err[1]);
|
||||
while (!err[1] && !err[0] && s->str[s->i])
|
||||
{
|
||||
old_stream_i = s->i;
|
||||
if ((read_expected_string("\n", s, &err), err)
|
||||
&& !read_string_parameter("NO", &dest->texture_srcs[NORTH], s, &rdf)
|
||||
&& !read_string_parameter("SO", &dest->texture_srcs[SOUTH], s, &rdf)
|
||||
&& !read_string_parameter("WE", &dest->texture_srcs[WEST], s, &rdf)
|
||||
&& !read_string_parameter("EA", &dest->texture_srcs[EAST], s, &rdf)
|
||||
&& !read_color_parameter("F", &dest->color_floor, s, &rdf)
|
||||
&& !read_color_parameter("C", &dest->color_ceiling, s, &rdf))
|
||||
if ((read_expected_string("\n", s, &err[0]), err[0])
|
||||
&& !read_string_parameter("NO", &d->texture_srcs[NORTH], s, &err[1])
|
||||
&& !read_string_parameter("SO", &d->texture_srcs[SOUTH], s, &err[1])
|
||||
&& !read_string_parameter("WE", &d->texture_srcs[WEST], s, &err[1])
|
||||
&& !read_string_parameter("EA", &d->texture_srcs[EAST], s, &err[1])
|
||||
&& !read_color_parameter("F", &d->color_floor, s, &err[1])
|
||||
&& !read_color_parameter("C", &d->color_ceiling, s, &err[1]))
|
||||
{
|
||||
s->i = old_stream_i;
|
||||
err = !read_map_description(dest, s);
|
||||
err[0] = !read_map_description(d, s);
|
||||
break ;
|
||||
}
|
||||
err = false;
|
||||
err[0] = false;
|
||||
}
|
||||
if (!rdf && !dest->cases)
|
||||
err = (write_err("Map description missing\n", NULL), true);
|
||||
(rdf || err) && (map_destroy(dest), false);
|
||||
return (!err && !rdf && dest->cases);
|
||||
if (!err[1] && !d->cases)
|
||||
err[0] = (write_err("Map description missing\n", NULL), true);
|
||||
(err[1] || err[0]) && (map_destroy(d), false);
|
||||
return (!err[0] && !err[1] && d->cases);
|
||||
}
|
||||
|
||||
void map_init_objects(t_map *map)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/11/07 00:08:13 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 19:05:06 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -103,15 +103,16 @@ bool read_map_description(t_map *map, t_stream *stream)
|
|||
return (true);
|
||||
}
|
||||
|
||||
bool load_textures(t_map *map)
|
||||
bool load_textures(t_map *map)
|
||||
{
|
||||
t_direction d;
|
||||
|
||||
d = 0;
|
||||
while (d < 4) {
|
||||
while (d < 4)
|
||||
{
|
||||
map->textures[d].image = mlx_xpm_file_to_image(g_mlx,
|
||||
(char *)(map->texture_srcs[d]),
|
||||
&map->textures[d].width, &map->textures[d].height);
|
||||
(char *)(map->texture_srcs[d]),
|
||||
&map->textures[d].width, &map->textures[d].height);
|
||||
d++;
|
||||
}
|
||||
return (true);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/29 14:02:37 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/31 17:25:34 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 18:44:16 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ u_int32_t *get_data_addr(void *img_ptr)
|
|||
if (bpp != 32 || endian != 0)
|
||||
{
|
||||
write_err("Wrong bpp or wrong endian when using mlx_get_data_addr().\n",
|
||||
NULL);
|
||||
NULL);
|
||||
return (NULL);
|
||||
}
|
||||
return (r);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue