diff --git a/Makefile b/Makefile index 6f38a2d..d6030bb 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,18 @@ NAME = so_long SRCS = src/ INCLUDES = includes/ -CODE = main error env input timedloop \ - data_assets data_sprites \ - display1 display2 display_utils sprite \ - room1 room2 room_utils1 room_utils2 point \ - object_character object_snas object_wall +CODE = $(addprefix main/, \ + main error env input timedloop \ + ) \ + $(addprefix display/, \ + data_assets data_sprites \ + display1 display2 display_utils sprite \ + ) \ + $(addprefix room/, \ + room1 room2 room_utils1 room_utils2 \ + object_character object_snas object_wall \ + ) \ + utils/point LIBRARIES = mlx libtf LIBRARIES_FILES = libtf/libtf.a LIBRARIES_LINK = mlx diff --git a/dev/map.md b/dev/map.md deleted file mode 100644 index 5d55507..0000000 --- a/dev/map.md +++ /dev/null @@ -1,49 +0,0 @@ -/!\ NEEDS UPDATE - -data\_assets -- `NB_ASSETS` -- `t_assetinfo` -- `g_assetsmap` -- `t_assetid`... -- `t_direction` -- `t_pixel` -- `t_component` -data\_sprites -- `NB_SPRITES` -- `t_spriteinfo` -- `t_spritesmap` -- `t_spriteid` -display -- `t_image` -- `display_init()` -- `display_erase()` -- `display_draw()` -- `display_flush()` -- `display_destroyall()` -env -- `WINDOW_WIDTH` -- `WINDOW_HEIGHT` -- `WINDOW_TITLE` -- `t_env` -- `g_env` -error -- `err()` -- `err_perror()` -- `finish()` -room -- `t_surface`... -- `t_object` -- `t_room` -- `t_roomcase` -- `room_fromfile()` -- `room_draw()` -- `room_free()` -sprite -- `t_sprite` -- `sprite_init()` -- `sprite_draw()` -main -- `main()` -- `expose_hook()` -- `close_hook()` -- `loop_hook()` diff --git a/includes/data_assets.h b/includes/display/data_assets.h similarity index 84% rename from includes/data_assets.h rename to includes/display/data_assets.h index 8250f9e..71d7cb6 100644 --- a/includes/data_assets.h +++ b/includes/display/data_assets.h @@ -6,22 +6,16 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */ -/* Updated: 2024/03/28 15:09:30 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:27:46 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef DATA_ASSETS_H # define DATA_ASSETS_H -# include -# include "libtf.h" - # define NB_ASSETS 36 -typedef uint32_t t_pixel; -typedef uint8_t t_component; - -typedef struct s_asset +typedef struct s_assetmeta { t_const_string src; int limit_left; @@ -29,9 +23,9 @@ typedef struct s_asset int limit_up; int limit_down; bool opaque; -} t_assetinfo; +} t_assetmeta; -extern const t_assetinfo g_assetsmap[NB_ASSETS]; +extern const t_assetmeta g_assetsmap[NB_ASSETS]; /** * Index for each asset. Must be in the same order than g_assetsmap. @@ -39,7 +33,7 @@ extern const t_assetinfo g_assetsmap[NB_ASSETS]; * The images of an object with directions must be in this order: * down, up, left, right */ -typedef enum e_assetid +typedef enum e_assetsmap_id { FLOOR_1, FLOOR_2, @@ -77,16 +71,7 @@ typedef enum e_assetid OBJECT_EXIT_USING2_5, OBJECT_EXIT_USING2_6, OBJECT_EXIT_USING2_7 -} t_assetid; - -typedef enum e_direction -{ - DOWN, - UP, - LEFT, - RIGHT, - NO_DIRECTION -} t_direction; +} t_assetsmap_id; # define OBJECT_SNAS OBJECT_SNAS_DOWN # define OBJECT_FIRSK OBJECT_FIRSK_DOWN diff --git a/includes/data_sprites.h b/includes/display/data_sprites.h similarity index 75% rename from includes/data_sprites.h rename to includes/display/data_sprites.h index e85a6a2..d8a5b7d 100644 --- a/includes/data_sprites.h +++ b/includes/display/data_sprites.h @@ -6,35 +6,33 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 12:43:24 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:38:37 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef DATA_SPRITES_H # define DATA_SPRITES_H -# include "data_assets.h" - # define NB_SPRITES 9 -typedef enum e_assettype +typedef enum e_spritetype { ANIMATION, // loops through all the sprites CHARACTER_STILL, // down up left and right positions -} t_assettype; +} t_spritetype; -typedef struct s_spriteinfo +typedef struct s_spritemeta { - t_assetid first_frame; - int nb_frames; - int origin_x; - int origin_y; - t_assettype type; -} t_spriteinfo; + t_assetsmap_id first_frame; + int nb_frames; + int origin_x; + int origin_y; + t_spritetype type; +} t_spritemeta; -extern const t_spriteinfo g_spritesmap[NB_SPRITES]; +extern const t_spritemeta g_spritesmap[NB_SPRITES]; -typedef enum e_spriteid +typedef enum e_spritesmap_id { CASE_WALL, CASE_FLOOR_1, @@ -45,6 +43,6 @@ typedef enum e_spriteid SPR_SNAS_LEFT, SPR_SNAS_RIGHT, SPR_WALL, -} t_spriteid; +} t_spritesmap_id; #endif diff --git a/includes/display.h b/includes/display/display.h similarity index 88% rename from includes/display.h rename to includes/display/display.h index 03957bd..b6ecc61 100644 --- a/includes/display.h +++ b/includes/display/display.h @@ -6,22 +6,18 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 14:32:08 by mcolonna #+# #+# */ -/* Updated: 2024/03/11 15:53:57 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:26:51 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef DISPLAY_H # define DISPLAY_H -# include -# include "libtf.h" -# include "data_assets.h" - typedef struct s_image { int width; int height; - t_assetinfo asset; + t_assetmeta asset; void *img; t_pixel *data; } t_image; @@ -41,7 +37,7 @@ void display_erase(void); * You must call display_flush() after drawing all images. * x,y is the top-left position of the image. */ -void display_draw(int x, int y, t_assetid asset); +void display_draw(int x, int y, t_assetsmap_id asset); /** * Draw all the screen in the buffer. diff --git a/includes/display/pixel.h b/includes/display/pixel.h new file mode 100644 index 0000000..aed9221 --- /dev/null +++ b/includes/display/pixel.h @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pixel.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 17:17:44 by mcolonna #+# #+# */ +/* Updated: 2024/04/02 17:18:22 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PIXEL_H +# define PIXEL_H + +typedef uint32_t t_pixel; +typedef uint8_t t_component; + +#endif diff --git a/includes/sprite.h b/includes/display/sprite.h similarity index 85% rename from includes/sprite.h rename to includes/display/sprite.h index 05e0c01..f25eb16 100644 --- a/includes/sprite.h +++ b/includes/display/sprite.h @@ -6,23 +6,20 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 22:13:20 by mcolonna #+# #+# */ -/* Updated: 2024/03/28 15:59:30 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:37:12 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef SPRITE_H # define SPRITE_H -# include "data_assets.h" -# include "data_sprites.h" - typedef struct s_sprite { - t_spriteinfo *info; + t_spritemeta *meta; int index; } t_sprite; -t_sprite sprite_init(t_spriteid spr); +t_sprite sprite_init(t_spritesmap_id spr); void sprite_draw(int x, int y, t_sprite *spr); diff --git a/includes/includes.h b/includes/includes.h new file mode 100644 index 0000000..040e18f --- /dev/null +++ b/includes/includes.h @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* includes.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 13:53:41 by mcolonna #+# #+# */ +/* Updated: 2024/04/02 18:26:03 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INCLUDES_H +# define INCLUDES_H + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include "libtf.h" +# include "mlx.h" + +# include "utils/direction.h" +# include "utils/point.h" + +# include "display/pixel.h" +# include "display/data_assets.h" +# include "display/data_sprites.h" +# include "display/display.h" +# include "display/sprite.h" + +# include "room/object.h" +# include "room/character.h" +# include "room/objects.h" +# include "room/room.h" + +# include "main/env.h" +# include "main/error.h" +# include "main/input.h" +# include "main/timedloop.h" +# include "main/main.h" + +#endif diff --git a/includes/env.h b/includes/main/env.h similarity index 91% rename from includes/env.h rename to includes/main/env.h index 94ae80b..4f101ad 100644 --- a/includes/env.h +++ b/includes/main/env.h @@ -6,16 +6,13 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 18:27:02 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:39:26 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef ENV_H # define ENV_H -# include "libtf.h" -# include "room.h" - # define WINDOW_WIDTH 600 # define WINDOW_HEIGHT 400 # define WINDOW_TITLE "undretale" diff --git a/includes/error.h b/includes/main/error.h similarity index 79% rename from includes/error.h rename to includes/main/error.h index 83b70da..6bd3d5f 100644 --- a/includes/error.h +++ b/includes/main/error.h @@ -6,18 +6,16 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 16:04:31 by mcolonna #+# #+# */ -/* Updated: 2024/03/11 13:23:02 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:04:00 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef ERROR_H # define ERROR_H -# include "libtf.h" - -void err(t_const_string msg); -void err_perror(t_const_string s); -void err_perror_str(t_const_string s, t_const_string msg); -void finish(void); +void error_err(t_const_string msg); +void error_perror(t_const_string s); +void error_str(t_const_string s, t_const_string msg); +void success(void); #endif diff --git a/includes/input.h b/includes/main/input.h similarity index 93% rename from includes/input.h rename to includes/main/input.h index b5c16b7..583d724 100644 --- a/includes/input.h +++ b/includes/main/input.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/26 12:16:32 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 18:32:38 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:39:38 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/includes/main/main.h b/includes/main/main.h new file mode 100644 index 0000000..0842b28 --- /dev/null +++ b/includes/main/main.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 13:39:54 by mcolonna #+# #+# */ +/* Updated: 2024/04/02 14:39:40 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MAIN_H +# define MAIN_H + +int main(void); + +#endif diff --git a/includes/timedloop.h b/includes/main/timedloop.h similarity index 93% rename from includes/timedloop.h rename to includes/main/timedloop.h index 3d14f9f..a5f9886 100644 --- a/includes/timedloop.h +++ b/includes/main/timedloop.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/26 15:02:16 by mcolonna #+# #+# */ -/* Updated: 2024/03/26 15:02:50 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:39:46 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/includes/object.h b/includes/room/character.h similarity index 52% rename from includes/object.h rename to includes/room/character.h index fa016a2..b22da39 100644 --- a/includes/object.h +++ b/includes/room/character.h @@ -1,50 +1,25 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* object.h :+: :+: :+: */ +/* character.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 15:29:58 by mcolonna ### ########.fr */ +/* Created: 2024/04/02 17:46:05 by mcolonna #+# #+# */ +/* Updated: 2024/04/02 17:46:46 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef OBJECT_H -# define OBJECT_H +#ifndef CHARACTER_H +# define CHARACTER_H -# include "point.h" -# include "data_assets.h" -# include "libtf.h" -# include "display.h" -# include "sprite.h" - -/**** OBJECT ****/ -typedef struct s_object t_object; - -typedef struct s_objecttype -{ - t_point (*loop)(t_object *, t_point pos); - void (*draw)(t_object *, int x, int y); -} t_objecttype; - -typedef struct s_object -{ - t_objecttype type; - void *data; - bool solid; -} t_object; - -typedef t_object (*t_object_init)(t_memclass); - -/**** CHARACTER ****/ typedef struct s_character_sprites { - t_spriteid still; - t_spriteid walk_left; - t_spriteid walk_right; - t_spriteid walk_up; - t_spriteid walk_down; + t_spritesmap_id still; + t_spritesmap_id walk_left; + t_spritesmap_id walk_right; + t_spritesmap_id walk_up; + t_spritesmap_id walk_down; } t_character_sprites; typedef struct s_character @@ -60,20 +35,4 @@ t_point character_loop(t_character *character, t_point pos, t_direction (*brain)(void)); t_character character_init(t_character_sprites *sprites); -/**** SNAS ****/ -typedef struct s_snas_data -{ - t_character character; -} t_snas_data; - -t_object snas_init(t_memclass mc); - -/**** WALL ****/ -typedef struct s_wall_data -{ - t_sprite spr; -} t_wall_data; - -t_object wall_init(t_memclass mc); - #endif diff --git a/includes/room/object.h b/includes/room/object.h new file mode 100644 index 0000000..523d5eb --- /dev/null +++ b/includes/room/object.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* object.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */ +/* Updated: 2024/04/02 17:49:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef OBJECT_H +# define OBJECT_H + +typedef struct s_object t_object; + +typedef struct s_objecttype +{ + t_point (*loop)(t_object *, t_point pos); + void (*draw)(t_object *, int x, int y); +} t_objecttype; + +typedef struct s_object +{ + t_objecttype type; + void *data; + bool solid; +} t_object; + +typedef t_object (*t_object_init)(t_memclass); + +#endif diff --git a/includes/room/objects.h b/includes/room/objects.h new file mode 100644 index 0000000..6607949 --- /dev/null +++ b/includes/room/objects.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* objects.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 17:47:01 by mcolonna #+# #+# */ +/* Updated: 2024/04/02 17:48:38 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef OBJECTS_H +# define OBJECTS_H + +// SNAS +typedef struct s_snas_data +{ + t_character character; +} t_snas_data; + +t_object snas_init(t_memclass mc); + +// WALL +typedef struct s_wall_data +{ + t_sprite spr; +} t_wall_data; + +t_object wall_init(t_memclass mc); + +#endif diff --git a/includes/room.h b/includes/room/room.h similarity index 86% rename from includes/room.h rename to includes/room/room.h index 267ece2..86ab5a7 100644 --- a/includes/room.h +++ b/includes/room/room.h @@ -6,17 +6,13 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 12:42:52 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:50:58 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef ROOM_H # define ROOM_H -# include "sprite.h" -# include "libtf.h" -# include "object.h" - typedef struct s_room { int width; @@ -26,12 +22,6 @@ typedef struct s_room t_memclass mc; } t_room; -typedef struct s_roomcase -{ - char c; - t_object_init object; -} t_roomcase; - t_room room_fromfile(t_const_string path); void room_loop(t_room room); diff --git a/includes/utils/direction.h b/includes/utils/direction.h new file mode 100644 index 0000000..75a4b64 --- /dev/null +++ b/includes/utils/direction.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* direction.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 17:28:40 by mcolonna #+# #+# */ +/* Updated: 2024/04/02 17:28:56 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef DIRECTION_H +# define DIRECTION_H + +typedef enum e_direction +{ + DOWN, + UP, + LEFT, + RIGHT, + NO_DIRECTION +} t_direction; + +#endif diff --git a/includes/point.h b/includes/utils/point.h similarity index 92% rename from includes/point.h rename to includes/utils/point.h index f7c75c4..813ac16 100644 --- a/includes/point.h +++ b/includes/utils/point.h @@ -6,15 +6,13 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 15:05:03 by mcolonna #+# #+# */ -/* Updated: 2024/03/27 18:22:51 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:39:41 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef POINT_H # define POINT_H -# include "data_assets.h" - typedef struct s_point { int x; diff --git a/src/data_assets.c b/src/display/data_assets.c similarity index 95% rename from src/data_assets.c rename to src/display/data_assets.c index edc2799..fa75e03 100644 --- a/src/data_assets.c +++ b/src/display/data_assets.c @@ -6,16 +6,16 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 16:27:06 by mcolonna #+# #+# */ -/* Updated: 2024/03/11 15:54:15 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:27:27 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "data_assets.h" +#include "includes.h" /** * Path of each asset relative to assets/, without extension. */ -const t_assetinfo g_assetsmap[NB_ASSETS] = { +const t_assetmeta g_assetsmap[NB_ASSETS] = { {"floor/1", 50, 100, 50, 100, true}, {"floor/2", 50, 100, 50, 100, true}, // WALL diff --git a/src/data_sprites.c b/src/display/data_sprites.c similarity index 89% rename from src/data_sprites.c rename to src/display/data_sprites.c index 416ca87..956c927 100644 --- a/src/data_sprites.c +++ b/src/display/data_sprites.c @@ -6,13 +6,13 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 12:39:30 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:37:34 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "data_sprites.h" +#include "includes.h" -const t_spriteinfo g_spritesmap[NB_SPRITES] = { +const t_spritemeta g_spritesmap[NB_SPRITES] = { {WALL_BORDER, 1, 50, 50, ANIMATION}, {FLOOR_1, 1, 50, 50, ANIMATION}, {FLOOR_2, 1, 50, 50, ANIMATION}, diff --git a/src/display1.c b/src/display/display1.c similarity index 90% rename from src/display1.c rename to src/display/display1.c index 606b2ca..d01a761 100644 --- a/src/display1.c +++ b/src/display/display1.c @@ -6,17 +6,12 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */ -/* Updated: 2024/03/11 13:03:37 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:03:21 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "display.h" +#include "includes.h" #include "display_utils.h" -#include "env.h" -#include "error.h" -#include "mlx.h" -#include "libtf.h" -#include void display_init(void) { @@ -30,7 +25,7 @@ void display_init(void) } g_screenbuf.img = mlx_new_image(g_env.mlx, WINDOW_WIDTH, WINDOW_HEIGHT); if (!g_screenbuf.img) - err("on mlx_new_image()"); + error_err("on mlx_new_image()"); g_screenbuf.width = WINDOW_WIDTH; g_screenbuf.height = WINDOW_HEIGHT; g_screenbuf.data = get_data_addr(g_screenbuf.img); diff --git a/src/display2.c b/src/display/display2.c similarity index 92% rename from src/display2.c rename to src/display/display2.c index 4b1452c..b38631e 100644 --- a/src/display2.c +++ b/src/display/display2.c @@ -6,17 +6,12 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */ -/* Updated: 2024/03/06 13:40:18 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:43:34 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "display.h" +#include "includes.h" #include "display_utils.h" -#include "env.h" -#include "error.h" -#include "mlx.h" -#include "libtf.h" -#include static inline void add_color(t_pixel *dest, t_pixel src) { @@ -98,7 +93,7 @@ static inline void display_draw_opaque(int x, int y, t_image img) } } -void display_draw(int x, int y, t_assetid asset) +void display_draw(int x, int y, t_assetsmap_id asset) { const t_image img = g_allassets[asset]; diff --git a/src/display_utils.c b/src/display/display_utils.c similarity index 83% rename from src/display_utils.c rename to src/display/display_utils.c index 8ff4bac..c943d3e 100644 --- a/src/display_utils.c +++ b/src/display/display_utils.c @@ -6,14 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/06 13:03:30 by mcolonna #+# #+# */ -/* Updated: 2024/03/06 13:48:02 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:03:15 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "display_utils.h" -#include "mlx.h" -#include "error.h" -#include "env.h" +#include "includes.h" t_image g_allassets[NB_ASSETS]; t_image g_screenbuf; @@ -27,7 +24,7 @@ t_pixel *get_data_addr(void *img) r = (t_pixel *)mlx_get_data_addr(img, &bpp, &size_line, &endian); if (!r || bpp != 32 || endian != 0) - err("wrong image format"); + error_err("wrong image format"); return (r); } @@ -50,17 +47,17 @@ void load_xpm_file_with_alpha(int i) t_string src_mask; void *mask; - tmp = str_join(err, g_env.mc, "assets/", g_assetsmap[i].src); - src = str_join(err, g_env.mc, tmp, ".xpm"); - src_mask = str_join(err, g_env.mc, tmp, ".alpha.xpm"); + tmp = str_join(error_err, g_env.mc, "assets/", g_assetsmap[i].src); + src = str_join(error_err, g_env.mc, tmp, ".xpm"); + src_mask = str_join(error_err, g_env.mc, tmp, ".alpha.xpm"); g_allassets[i].img = mlx_xpm_file_to_image(g_env.mlx, src, &(g_allassets[i].width), &g_allassets[i].height); if (!g_allassets[i].img) - err("image loading failed"); + error_err("image loading failed"); mask = mlx_xpm_file_to_image(g_env.mlx, src_mask, &(g_allassets[i].width), &g_allassets[i].height); if (!mask) - err("image loading failed"); + error_err("image loading failed"); apply_mask_to_image(g_allassets[i].img, mask, g_allassets[i].width * g_allassets[i].height); mlx_destroy_image(g_env.mlx, mask); diff --git a/includes/display_utils.h b/src/display/display_utils.h similarity index 93% rename from includes/display_utils.h rename to src/display/display_utils.h index 5e2de18..7d89a30 100644 --- a/includes/display_utils.h +++ b/src/display/display_utils.h @@ -6,15 +6,13 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/06 12:59:24 by mcolonna #+# #+# */ -/* Updated: 2024/03/06 13:47:02 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:39:19 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef DISPLAY_UTILS_H # define DISPLAY_UTILS_H -# include "display.h" - extern t_image g_allassets[NB_ASSETS]; extern t_image g_screenbuf; diff --git a/src/sprite.c b/src/display/sprite.c similarity index 69% rename from src/sprite.c rename to src/display/sprite.c index 8926931..9949fe9 100644 --- a/src/sprite.c +++ b/src/display/sprite.c @@ -6,19 +6,17 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 22:28:52 by mcolonna #+# #+# */ -/* Updated: 2024/03/28 16:02:01 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:02:35 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "sprite.h" -#include "display.h" -#include "error.h" +#include "includes.h" -t_sprite sprite_init(t_spriteid id) +t_sprite sprite_init(t_spritesmap_id id) { t_sprite r; - r.info = (t_spriteinfo *)(g_spritesmap + id); + r.meta = (t_spritemeta *)(g_spritesmap + id); r.index = 0; return (r); } @@ -26,19 +24,19 @@ t_sprite sprite_init(t_spriteid id) void sprite_draw(int x, int y, t_sprite *spr) { display_draw( - x - spr->info->origin_x, y - spr->info->origin_y, - spr->info->first_frame + spr->index); - if (spr->info->type == ANIMATION) + x - spr->meta->origin_x, y - spr->meta->origin_y, + spr->meta->first_frame + spr->index); + if (spr->meta->type == ANIMATION) { spr->index++; - if (spr->index >= spr->info->nb_frames) + if (spr->index >= spr->meta->nb_frames) spr->index = 0; } } void sprite_character_set_direction(t_sprite *spr, t_direction value) { - if (spr->info->type != CHARACTER_STILL) - err("the sprite must be a CHARACTER_STILL sprite."); + if (spr->meta->type != CHARACTER_STILL) + error_err("the sprite must be a CHARACTER_STILL sprite."); spr->index = value; } diff --git a/src/env.c b/src/main/env.c similarity index 90% rename from src/env.c rename to src/main/env.c index 2080c97..a232217 100644 --- a/src/env.c +++ b/src/main/env.c @@ -6,10 +6,10 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 16:32:36 by mcolonna #+# #+# */ -/* Updated: 2024/02/27 16:42:22 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:41:12 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "env.h" +#include "includes.h" t_env g_env; diff --git a/src/error.c b/src/main/error.c similarity index 80% rename from src/error.c rename to src/main/error.c index 8892638..598a3eb 100644 --- a/src/error.c +++ b/src/main/error.c @@ -6,17 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 16:05:21 by mcolonna #+# #+# */ -/* Updated: 2024/03/11 13:37:12 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:56:31 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include -#include -#include -#include "error.h" -#include "libtf.h" -#include "display.h" -#include "env.h" +#include "includes.h" static void end(int no) { @@ -25,7 +19,7 @@ static void end(int no) exit(no); } -void err(t_const_string msg) +void error_err(t_const_string msg) { print_line(err_remember, 2, "Error"); if (str_eq(msg, "errno")) @@ -35,7 +29,7 @@ void err(t_const_string msg) end(1); } -void err_perror(t_const_string s) +void error_perror(t_const_string s) { print_line(err_remember, 2, "Error"); print_str(err_remember, 2, s); @@ -44,7 +38,7 @@ void err_perror(t_const_string s) end(1); } -void err_perror_str(t_const_string s, t_const_string msg) +void error_str(t_const_string s, t_const_string msg) { print_line(err_remember, 2, "Error"); print_str(err_remember, 2, s); @@ -53,7 +47,7 @@ void err_perror_str(t_const_string s, t_const_string msg) end(1); } -void finish(void) +void success(void) { end(0); } diff --git a/src/input.c b/src/main/input.c similarity index 93% rename from src/input.c rename to src/main/input.c index 060892e..acca986 100644 --- a/src/input.c +++ b/src/main/input.c @@ -6,14 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/26 12:26:17 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 18:32:27 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:41:14 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "error.h" -#include "libtf.h" -#include "env.h" -#include +#include "includes.h" static int g_input_i = 0; static bool g_to_unpress[4] = {false, false, false, false}; diff --git a/src/main.c b/src/main/main.c similarity index 83% rename from src/main.c rename to src/main/main.c index a378179..e04dcb2 100644 --- a/src/main.c +++ b/src/main/main.c @@ -6,19 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 18:33:10 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:04:18 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "mlx.h" -#include "env.h" -#include "error.h" -#include "display.h" -#include "data_assets.h" -#include "room.h" -#include "input.h" -#include "timedloop.h" -#include +#include "includes.h" int expose_hook(void) { @@ -29,7 +21,7 @@ int expose_hook(void) int close_hook(void) { mlx_do_key_autorepeaton(g_env.mlx); - finish(); + success(); return (0); } @@ -50,15 +42,15 @@ int loop_hook(void) int main(void) { - g_env.mc = mem_newclass(err); + g_env.mc = mem_newclass(error_err); g_env.mlx = mlx_init(); if (!g_env.mlx) - err("mlx_init() failed"); + error_err("mlx_init() failed"); display_init(); g_env.win = mlx_new_window(g_env.mlx, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE); if (!g_env.win) - err("mlx_new_window() failed"); + error_err("mlx_new_window() failed"); g_env.room = room_fromfile("room/room.ber"); room_draw(g_env.room); mlx_expose_hook(g_env.win, expose_hook, NULL); diff --git a/src/timedloop.c b/src/main/timedloop.c similarity index 92% rename from src/timedloop.c rename to src/main/timedloop.c index a5228ef..4f5dfe6 100644 --- a/src/timedloop.c +++ b/src/main/timedloop.c @@ -6,12 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/26 14:54:49 by mcolonna #+# #+# */ -/* Updated: 2024/03/26 15:51:04 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:41:31 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include -#include "env.h" +#include "includes.h" static long get_nanos(void) { diff --git a/src/object_character.c b/src/room/object_character.c similarity index 92% rename from src/object_character.c rename to src/room/object_character.c index c739564..2e1fa20 100644 --- a/src/object_character.c +++ b/src/room/object_character.c @@ -6,19 +6,15 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 15:51:38 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:35:56 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "object.h" -#include "error.h" -#include "sprite.h" -#include "libtf.h" -#include "env.h" +#include "includes.h" static void character_initstate(t_character *character) { - const t_spriteid walk_sprites[] = { + const t_spritesmap_id walk_sprites[] = { character->sprites->walk_down, character->sprites->walk_up, character->sprites->walk_left, diff --git a/src/object_snas.c b/src/room/object_snas.c similarity index 90% rename from src/object_snas.c rename to src/room/object_snas.c index d9805ef..eb5fd18 100644 --- a/src/object_snas.c +++ b/src/room/object_snas.c @@ -6,15 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 18:29:12 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:02:48 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "object.h" -#include "error.h" -#include "sprite.h" -#include "libtf.h" -#include "env.h" +#include "includes.h" static t_direction snas_brain(void) { @@ -55,7 +51,7 @@ t_object snas_init(t_memclass mc) t_snas_data *data; r.type = type; - data = mem_alloc(err, mc, sizeof(t_snas_data)); + data = mem_alloc(error_err, mc, sizeof(t_snas_data)); data->character = character_init((t_character_sprites *)&sprites); r.data = data; r.solid = true; diff --git a/src/object_wall.c b/src/room/object_wall.c similarity index 86% rename from src/object_wall.c rename to src/room/object_wall.c index 533da27..35865af 100644 --- a/src/object_wall.c +++ b/src/room/object_wall.c @@ -6,15 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 15:52:32 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:02:25 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "object.h" -#include "error.h" -#include "sprite.h" -#include "libtf.h" -#include "env.h" +#include "includes.h" static t_point wall_loop(t_object *obj, t_point pos) { @@ -36,7 +32,7 @@ t_object wall_init(t_memclass mc) t_wall_data *data; r.type = type; - data = mem_alloc(err, mc, sizeof(t_wall_data)); + data = mem_alloc(error_err, mc, sizeof(t_wall_data)); data->spr = sprite_init(SPR_WALL); r.data = data; r.solid = true; diff --git a/src/room1.c b/src/room/room1.c similarity index 79% rename from src/room1.c rename to src/room/room1.c index da7873c..5a1ce3a 100644 --- a/src/room1.c +++ b/src/room/room1.c @@ -6,15 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 12:42:18 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 18:28:28 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include -#include "room.h" -#include "error.h" -#include "libtf.h" -#include "env.h" +#include "includes.h" #include "room_utils.h" static bool room_fromfile2( @@ -22,11 +18,11 @@ static bool room_fromfile2( { t_const_string line; t_roomcase *roomcase; - const t_memclass mc = mem_subclass(err, g_env.mc); + const t_memclass mc = mem_subclass(error_err, g_env.mc); line = read_line(err_remember, mc, fd); if (err_get()) - err_perror(path); + error_perror(path); if (!line) return (false); while (*line && *line != '\n') @@ -34,7 +30,8 @@ static bool room_fromfile2( roomcase = getroomcase(path, *line); if (roomcase->object) { - room->objects[*i] = mem_alloc(err, room->mc, sizeof(t_object)); + room->objects[*i] = mem_alloc(error_err, room->mc, + sizeof(t_object)); *(room->objects[*i]) = roomcase->object(room->mc); } else @@ -50,16 +47,18 @@ t_room room_fromfile(t_const_string path) { t_room r; int fd; - const t_memclass mc = mem_subclass(err, g_env.mc); + const t_memclass mc = mem_subclass(error_err, g_env.mc); int i; room_getsize(mc, &r, path); - r.mc = mem_subclass(err, g_env.mc); + r.mc = mem_subclass(error_err, g_env.mc); fd = open(path, O_RDONLY); if (fd == -1) - err_perror(path); - r.surfaces = mem_alloc(err, r.mc, r.width * r.height * sizeof(t_sprite)); - r.objects = mem_alloc(err, r.mc, r.width * r.height * sizeof(t_object *)); + error_perror(path); + r.surfaces = mem_alloc(error_err, r.mc, r.width * r.height + * sizeof(t_sprite)); + r.objects = mem_alloc(error_err, r.mc, r.width * r.height + * sizeof(t_object *)); i = 0; while (room_fromfile2(fd, path, &i, &r)) ; @@ -99,7 +98,7 @@ void room_loop(t_room room) t_point pos; t_object *object; t_point move; - const t_memclass mc = mem_subclass(err, g_env.mc); + const t_memclass mc = mem_subclass(error_err, g_env.mc); t_list objects_done; objects_done = list_createempty(mc); @@ -114,7 +113,7 @@ void room_loop(t_room room) { move = object->type.loop(object, pos); moveobject(room, pos, move); - list_add(err, &objects_done, object); + list_add(error_err, &objects_done, object); } pos.y++; } diff --git a/src/room2.c b/src/room/room2.c similarity index 90% rename from src/room2.c rename to src/room/room2.c index e435179..77c0f38 100644 --- a/src/room2.c +++ b/src/room/room2.c @@ -6,15 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */ -/* Updated: 2024/03/29 17:32:47 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:44:12 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include -#include "room.h" -#include "error.h" -#include "libtf.h" -#include "env.h" +#include "includes.h" #include "room_utils.h" t_object *room_getobjectfaced( diff --git a/includes/room_utils.h b/src/room/room_utils.h similarity index 89% rename from includes/room_utils.h rename to src/room/room_utils.h index 6d818aa..effd5f3 100644 --- a/includes/room_utils.h +++ b/src/room/room_utils.h @@ -6,15 +6,18 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/13 16:34:01 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 12:32:46 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:51:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef ROOM_UTILS_H # define ROOM_UTILS_H -# include "libtf.h" -# include "room.h" +typedef struct s_roomcase +{ + char c; + t_object_init object; +} t_roomcase; int getlinelen(t_const_string line); void room_getsize(t_memclass mc, t_room *r, t_const_string path); diff --git a/src/room_utils1.c b/src/room/room_utils1.c similarity index 87% rename from src/room_utils1.c rename to src/room/room_utils1.c index 593c0fb..57c445a 100644 --- a/src/room_utils1.c +++ b/src/room/room_utils1.c @@ -6,14 +6,12 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/13 16:26:28 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 12:44:30 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:58:59 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include +#include "includes.h" #include "room_utils.h" -#include "error.h" -#include "object.h" static t_roomcase g_roomcases[] = { {c: '0', object: NULL}, @@ -39,23 +37,23 @@ void room_getsize(t_memclass mc, t_room *r, t_const_string path) fd = open(path, O_RDONLY); if (fd == -1) - err_perror(path); + error_perror(path); line = read_line(err_remember, mc, fd); if (err_get()) - err_perror(path); + error_perror(path); if (!line) - err_perror_str(path, "room is empty"); + error_str(path, "room is empty"); r->width = getlinelen(line); r->height = 1; while (true) { line = read_line(err_remember, mc, fd); if (err_get()) - err_perror(path); + error_perror(path); if (!line) break ; if (getlinelen(line) != r->width) - err_perror_str(path, "the lines have different lengths"); + error_str(path, "the lines have different lengths"); r->height++; } } @@ -70,7 +68,7 @@ t_roomcase *getroomcase(t_const_string path, char c) if (g_roomcases[i].c == c) return (&g_roomcases[i]); } - err_perror_str(path, "unknown char"); + error_str(path, "unknown char"); return (NULL); } diff --git a/src/room_utils2.c b/src/room/room_utils2.c similarity index 93% rename from src/room_utils2.c rename to src/room/room_utils2.c index 8ae7389..14d7a20 100644 --- a/src/room_utils2.c +++ b/src/room/room_utils2.c @@ -6,12 +6,12 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/02 12:33:48 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 12:51:20 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 17:52:14 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ +#include "includes.h" #include "room_utils.h" -#include "data_sprites.h" void room_patch(t_room *room) { diff --git a/src/point.c b/src/utils/point.c similarity index 94% rename from src/point.c rename to src/utils/point.c index bbb3d0c..fe67142 100644 --- a/src/point.c +++ b/src/utils/point.c @@ -6,11 +6,11 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 15:24:37 by mcolonna #+# #+# */ -/* Updated: 2024/03/27 18:23:24 by mcolonna ### ########.fr */ +/* Updated: 2024/04/02 14:41:19 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "point.h" +#include "includes.h" t_point point_init(int x, int y) {