From 5932f0bcb60ea5168d9e2afb772cd56cc8e76a96 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 17:24:05 +0900 Subject: [PATCH 01/15] refactor(parser): simplify error handling and clarify naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove redundant NULL guards in internal functions (skip_whitespace, at_line_end, line_reader_next, line_reader_init, error_context_init) - Rename dispatch functions for clarity: dispatch_element → dispatch_line, dispatch_elements → dispatch_scene_element, dispatch_objects → dispatch_object - Use precise error codes: PARSE_ERR_FORMAT → PARSE_ERR_OVERFLOW for allocation failures (object_list_add, bump_path, line malloc) - Replace io_error boolean with error field carrying specific t_parse_result codes (PARSE_ERR_IO, PARSE_ERR_OVERFLOW) - Remove error_context_set_line/error_context_set_element wrappers, assign fields directly - Simplify line_reader_init to void (cannot fail) Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/parser.h | 9 +++------ src/parser/parse_bonus_options.c | 2 +- src/parser/parse_cone.c | 2 +- src/parser/parse_cylinder.c | 2 +- src/parser/parse_error.c | 28 ---------------------------- src/parser/parse_line_reader.c | 6 ++---- src/parser/parse_objects.c | 4 ++-- src/parser/parse_token.c | 4 ---- src/parser/parser.c | 16 ++++++---------- src/parser/parser_dispatch.c | 11 ++++++----- src/parser/parser_utils.c | 7 ++----- 11 files changed, 24 insertions(+), 67 deletions(-) diff --git a/includes/parser.h b/includes/parser.h index e508443..559cfbf 100644 --- a/includes/parser.h +++ b/includes/parser.h @@ -55,7 +55,7 @@ typedef struct s_line_reader int buf_len; int line_num; int line_too_long; - int io_error; + int error; } t_line_reader; /* @@ -73,7 +73,7 @@ typedef struct s_error_context * Line Reader API */ -int line_reader_init(t_line_reader *reader, int fd); +void line_reader_init(t_line_reader *reader, int fd); char *line_reader_next(t_line_reader *reader); int line_reader_get_line_num(t_line_reader *reader); @@ -99,9 +99,6 @@ int at_line_end(const char *str); */ void error_context_init(t_error_context *ctx); -void error_context_set_line(t_error_context *ctx, int line); -void error_context_set_element(t_error_context *ctx, - const char *type); void error_context_print(t_error_context *ctx); void error_write_int(int n); const char *get_error_message(t_parse_result code); @@ -129,7 +126,7 @@ t_parse_result validate_coordinate_range(const t_vec3 *vec); * @return 1 on success, 0 on error */ int parse_scene(const char *filename, t_scene *scene); -t_parse_result dispatch_element(char *line, t_scene *scene, +t_parse_result dispatch_line(char *line, t_scene *scene, t_error_context *ctx); int validate_extension(const char *filename); diff --git a/src/parser/parse_bonus_options.c b/src/parser/parse_bonus_options.c index 83cad7e..85c880e 100644 --- a/src/parser/parse_bonus_options.c +++ b/src/parser/parse_bonus_options.c @@ -54,7 +54,7 @@ static t_parse_result parse_bump_opt(const char *str, t_object *obj, free(obj->bump_path); obj->bump_path = ft_substr(start, 0, len); if (!obj->bump_path) - return (PARSE_ERR_FORMAT); + return (PARSE_ERR_OVERFLOW); *end = start + len; return (PARSE_OK); } diff --git a/src/parser/parse_cone.c b/src/parser/parse_cone.c index 0ad2656..c210fb6 100644 --- a/src/parser/parse_cone.c +++ b/src/parser/parse_cone.c @@ -88,5 +88,5 @@ t_parse_result parse_cone(char *line, t_scene *scene) if (object_list_add(&scene->objects, &obj)) return (PARSE_OK); free(obj.bump_path); - return (PARSE_ERR_FORMAT); + return (PARSE_ERR_OVERFLOW); } diff --git a/src/parser/parse_cylinder.c b/src/parser/parse_cylinder.c index df59e36..1d52125 100644 --- a/src/parser/parse_cylinder.c +++ b/src/parser/parse_cylinder.c @@ -114,5 +114,5 @@ t_parse_result parse_cylinder(char *line, t_scene *scene) if (object_list_add(&scene->objects, &obj)) return (PARSE_OK); free(obj.bump_path); - return (PARSE_ERR_FORMAT); + return (PARSE_ERR_OVERFLOW); } diff --git a/src/parser/parse_error.c b/src/parser/parse_error.c index 6130580..13de10a 100644 --- a/src/parser/parse_error.c +++ b/src/parser/parse_error.c @@ -20,39 +20,11 @@ */ void error_context_init(t_error_context *ctx) { - if (!ctx) - return ; ctx->line_num = 0; ctx->element_type = NULL; ctx->error_code = PARSE_OK; } -/** - * @brief Set the line number in error context. - * - * @param ctx Error context to update. - * @param line Line number (1-based). - */ -void error_context_set_line(t_error_context *ctx, int line) -{ - if (!ctx) - return ; - ctx->line_num = line; -} - -/** - * @brief Set the element type in error context. - * - * @param ctx Error context to update. - * @param type Element type string or NULL. - */ -void error_context_set_element(t_error_context *ctx, const char *type) -{ - if (!ctx) - return ; - ctx->element_type = type; -} - /** * @brief Print error message with context to stderr. * diff --git a/src/parser/parse_line_reader.c b/src/parser/parse_line_reader.c index caaba3a..4d3a90d 100644 --- a/src/parser/parse_line_reader.c +++ b/src/parser/parse_line_reader.c @@ -27,7 +27,7 @@ static int refill_buffer(t_line_reader *reader) reader->buf_pos = 0; if (reader->buf_len < 0) { - reader->io_error = 1; + reader->error = PARSE_ERR_IO; reader->buf_len = 0; } return (reader->buf_len); @@ -101,7 +101,7 @@ static char *finalize_line(char *line, int len, t_line_reader *reader) result = malloc(len + 1); if (!result) { - reader->io_error = 1; + reader->error = PARSE_ERR_OVERFLOW; return (NULL); } ft_strlcpy(result, line, len + 1); @@ -120,8 +120,6 @@ char *line_reader_next(t_line_reader *reader) int pos; int status; - if (!reader) - return (NULL); reader->line_num++; reader->line_too_long = 0; pos = 0; diff --git a/src/parser/parse_objects.c b/src/parser/parse_objects.c index ddd4b6b..2666e9e 100644 --- a/src/parser/parse_objects.c +++ b/src/parser/parse_objects.c @@ -100,7 +100,7 @@ t_parse_result parse_sphere(char *line, t_scene *scene) if (object_list_add(&scene->objects, &obj)) return (PARSE_OK); free(obj.bump_path); - return (PARSE_ERR_FORMAT); + return (PARSE_ERR_OVERFLOW); } /** @@ -165,5 +165,5 @@ t_parse_result parse_plane(char *line, t_scene *scene) if (object_list_add(&scene->objects, &obj)) return (PARSE_OK); free(obj.bump_path); - return (PARSE_ERR_FORMAT); + return (PARSE_ERR_OVERFLOW); } diff --git a/src/parser/parse_token.c b/src/parser/parse_token.c index b61968a..c6e992e 100644 --- a/src/parser/parse_token.c +++ b/src/parser/parse_token.c @@ -31,8 +31,6 @@ static int is_whitespace(char c) */ const char *skip_whitespace(const char *str) { - if (!str) - return (NULL); while (is_whitespace(*str)) str++; return (str); @@ -49,8 +47,6 @@ const char *skip_whitespace(const char *str) */ int at_line_end(const char *str) { - if (!str) - return (1); str = skip_whitespace(str); return (*str == '\0' || *str == '\n' || *str == '#'); } diff --git a/src/parser/parser.c b/src/parser/parser.c index 32c8501..8ba7c04 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -33,7 +33,7 @@ static int parse_line(char *line, t_scene *scene, t_error_context *ctx) t_parse_result result; ctx->element_type = NULL; - result = dispatch_element(line, scene, ctx); + result = dispatch_line(line, scene, ctx); if (result != PARSE_OK) { ctx->error_code = result; @@ -75,7 +75,7 @@ static int check_line_too_long(t_line_reader *reader, t_error_context *ctx) { if (reader->line_too_long) { - error_context_set_line(ctx, reader->line_num); + ctx->line_num = reader->line_num; ctx->error_code = PARSE_ERR_LINE_TOO_LONG; error_context_print(ctx); return (1); @@ -105,15 +105,15 @@ static int process_lines(t_line_reader *reader, t_scene *scene, return (0); if (line == NULL) break ; - error_context_set_line(ctx, reader->line_num); + ctx->line_num = reader->line_num; success = parse_line(line, scene, ctx); free(line); line = line_reader_next(reader); } free(line); - if (reader->io_error) + if (reader->error) { - ctx->error_code = PARSE_ERR_IO; + ctx->error_code = reader->error; error_context_print(ctx); return (0); } @@ -145,11 +145,7 @@ int parse_scene(const char *filename, t_scene *scene) if (fd < 0) return (error_print(ERR_FILE_OPEN), 0); error_context_init(&ctx); - if (!line_reader_init(&reader, fd)) - { - close(fd); - return (error_print(ERR_MALLOC), 0); - } + line_reader_init(&reader, fd); success = process_lines(&reader, scene, &ctx); close(fd); if (success) diff --git a/src/parser/parser_dispatch.c b/src/parser/parser_dispatch.c index f24ea32..a27c629 100644 --- a/src/parser/parser_dispatch.c +++ b/src/parser/parser_dispatch.c @@ -43,7 +43,7 @@ static int matches_prefix(char *line, const char *prefix, int len) * @param ctx Error context. * @return t_parse_result Result code. */ -static t_parse_result dispatch_objects(char *line, t_scene *scene, +static t_parse_result dispatch_object(char *line, t_scene *scene, t_error_context *ctx) { if (matches_prefix(line, "sp", 2)) @@ -77,7 +77,8 @@ static t_parse_result dispatch_objects(char *line, t_scene *scene, * @param ctx Error context. * @return t_parse_result Result code or -1 for objects. */ -static int dispatch_elements(char *line, t_scene *scene, t_error_context *ctx) +static int dispatch_scene_element(char *line, t_scene *scene, + t_error_context *ctx) { if (matches_prefix(line, "A", 1)) { @@ -105,7 +106,7 @@ static int dispatch_elements(char *line, t_scene *scene, t_error_context *ctx) * @param ctx Error context for reporting. * @return t_parse_result PARSE_OK or error code. */ -t_parse_result dispatch_element(char *line, t_scene *scene, +t_parse_result dispatch_line(char *line, t_scene *scene, t_error_context *ctx) { int result; @@ -113,8 +114,8 @@ t_parse_result dispatch_element(char *line, t_scene *scene, line = (char *)skip_whitespace(line); if (*line == '\0' || *line == '\n' || *line == '#') return (PARSE_OK); - result = dispatch_elements(line, scene, ctx); + result = dispatch_scene_element(line, scene, ctx); if (result >= 0) return ((t_parse_result)result); - return (dispatch_objects(line, scene, ctx)); + return (dispatch_object(line, scene, ctx)); } diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c index c335eed..478e7fd 100644 --- a/src/parser/parser_utils.c +++ b/src/parser/parser_utils.c @@ -20,17 +20,14 @@ * @param fd File descriptor to read from. * @return int 1 on success, 0 on failure. */ -int line_reader_init(t_line_reader *reader, int fd) +void line_reader_init(t_line_reader *reader, int fd) { - if (!reader || fd < 0) - return (0); reader->fd = fd; reader->buf_pos = 0; reader->buf_len = 0; reader->line_num = 0; reader->line_too_long = 0; - reader->io_error = 0; - return (1); + reader->error = 0; } /** From 737d4db2cad26b3a3c603cf9eb85b4bea822a5ef Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:33:37 +0900 Subject: [PATCH 02/15] rename(bvh_debug): rename bvh_vis module to bvh_debug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - bvh_vis/ → bvh_debug/, bvh_vis.h → bvh_debug.h - All bvh_vis_ prefixes → bvhd_ (shorter, consistent) - bvh_visualize() → bvhd_run() - Update Makefile SRCS and includes in main.c, render_loop.c Co-Authored-By: Claude Opus 4.6 (1M context) --- Makefile | 16 +++---- includes/{bvh_vis.h => bvh_debug.h} | 42 +++++++++---------- .../bvhd_format.c} | 6 +-- .../bvh_vis_init.c => bvh_debug/bvhd_init.c} | 26 ++++++------ .../bvh_vis_node.c => bvh_debug/bvhd_node.c} | 10 ++--- .../bvhd_prefix.c} | 12 +++--- .../bvhd_prefix_push.c} | 6 +-- .../bvhd_print.c} | 10 ++--- .../bvhd_stats.c} | 18 ++++---- .../bvh_vis_tree.c => bvh_debug/bvhd_tree.c} | 28 ++++++------- src/main.c | 4 +- src/render/render_loop.c | 4 +- 12 files changed, 91 insertions(+), 91 deletions(-) rename includes/{bvh_vis.h => bvh_debug.h} (66%) rename src/{bvh_vis/bvh_vis_format.c => bvh_debug/bvhd_format.c} (89%) rename src/{bvh_vis/bvh_vis_init.c => bvh_debug/bvhd_init.c} (80%) rename src/{bvh_vis/bvh_vis_node.c => bvh_debug/bvhd_node.c} (93%) rename src/{bvh_vis/bvh_vis_prefix.c => bvh_debug/bvhd_prefix.c} (87%) rename src/{bvh_vis/bvh_vis_prefix_push.c => bvh_debug/bvhd_prefix_push.c} (92%) rename src/{bvh_vis/bvh_vis_print.c => bvh_debug/bvhd_print.c} (86%) rename src/{bvh_vis/bvh_vis_stats.c => bvh_debug/bvhd_stats.c} (82%) rename src/{bvh_vis/bvh_vis_tree.c => bvh_debug/bvhd_tree.c} (77%) diff --git a/Makefile b/Makefile index 5c5dc4b..5b229ae 100644 --- a/Makefile +++ b/Makefile @@ -118,14 +118,14 @@ SRCS = $(SRC_DIR)/main.c \ $(SRC_DIR)/texture/texture_utils.c \ $(SRC_DIR)/math/vec3.c \ $(SRC_DIR)/math/vec3_ops.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_init.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_tree.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_node.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_format.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_stats.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_prefix.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_prefix_push.c \ - $(SRC_DIR)/bvh_vis/bvh_vis_print.c \ + $(SRC_DIR)/bvh_debug/bvhd_init.c \ + $(SRC_DIR)/bvh_debug/bvhd_tree.c \ + $(SRC_DIR)/bvh_debug/bvhd_node.c \ + $(SRC_DIR)/bvh_debug/bvhd_format.c \ + $(SRC_DIR)/bvh_debug/bvhd_stats.c \ + $(SRC_DIR)/bvh_debug/bvhd_prefix.c \ + $(SRC_DIR)/bvh_debug/bvhd_prefix_push.c \ + $(SRC_DIR)/bvh_debug/bvhd_print.c \ $(SRC_DIR)/utils/error.c \ $(SRC_DIR)/utils/format_helpers.c \ $(SRC_DIR)/utils/timer.c diff --git a/includes/bvh_vis.h b/includes/bvh_debug.h similarity index 66% rename from includes/bvh_vis.h rename to includes/bvh_debug.h index af4c280..428e45f 100644 --- a/includes/bvh_vis.h +++ b/includes/bvh_debug.h @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis.h :+: :+: :+: */ +/* bvh_debug.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#ifndef BVH_VIS_H -# define BVH_VIS_H +#ifndef BVH_DEBUG_H +# define BVH_DEBUG_H # include "spatial.h" @@ -65,39 +65,39 @@ typedef struct s_traverse_ctx } t_traverse_ctx; /* Public API */ -void bvh_visualize(t_bvh *bvh, t_vis_config *config, void *scene); -t_vis_config bvh_vis_default_config(void); +void bvhd_run(t_bvh *bvh, t_vis_config *config, void *scene); +t_vis_config bvhd_default_config(void); /* Initialization and configuration */ -int bvh_vis_get_terminal_width(void); -void check_edge_cases(t_bvh *bvh, t_vis_config *config); +int bvhd_get_terminal_width(void); +void bvhd_check_edges(t_bvh *bvh, t_vis_config *config); /* Tree traversal and display */ -void bvh_visualize_tree(t_bvh_node *node, t_traverse_ctx *ctx, +void bvhd_print_tree(t_bvh_node *node, t_traverse_ctx *ctx, t_bvh_stats *stats); /* Node formatting */ -t_node_info format_node_info(t_bvh_node *node); -int is_leaf_node(t_bvh_node *node); -void format_object_list(t_object_ref *objects, int count, +t_node_info bvhd_format_node(t_bvh_node *node); +int bvhd_is_leaf(t_bvh_node *node); +void bvhd_format_objects(t_object_ref *objects, int count, char *buffer, void *scene); /* Statistics */ -void bvh_collect_statistics(t_bvh_node *node, t_bvh_stats *stats); -void collect_stats_recursive(t_bvh_node *node, t_bvh_stats *stats, +void bvhd_collect_stats(t_bvh_node *node, t_bvh_stats *stats); +void bvhd_collect_recursive(t_bvh_node *node, t_bvh_stats *stats, int depth); -void print_statistics_summary(t_bvh_stats *stats); +void bvhd_print_stats(t_bvh_stats *stats); /* Prefix management */ -t_prefix_state prefix_init(void); -int prefix_push(t_prefix_state *state, int is_last); -void prefix_pop(t_prefix_state *state); -void prefix_print(t_prefix_state *state); -void prefix_destroy(t_prefix_state *state); +t_prefix_state bvhd_prefix_init(void); +int bvhd_prefix_push(t_prefix_state *state, int is_last); +void bvhd_prefix_pop(t_prefix_state *state); +void bvhd_prefix_print(t_prefix_state *state); +void bvhd_prefix_destroy(t_prefix_state *state); /* Output primitives */ -void print_node_line(t_prefix_state *prefix, t_node_info *info, +void bvhd_print_node(t_prefix_state *prefix, t_node_info *info, int is_last); -void print_warning_message(const char *message); +void bvhd_warn(const char *message); #endif diff --git a/src/bvh_vis/bvh_vis_format.c b/src/bvh_debug/bvhd_format.c similarity index 89% rename from src/bvh_vis/bvh_vis_format.c rename to src/bvh_debug/bvhd_format.c index 40b6076..9b8b139 100644 --- a/src/bvh_vis/bvh_vis_format.c +++ b/src/bvh_debug/bvhd_format.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_format.c :+: :+: :+: */ +/* bvhd_format.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include "minirt.h" #include @@ -22,7 +22,7 @@ * @param buffer Destination buffer (assumed large enough). * @param scene_ptr Pointer to the scene for ID lookup. */ -void format_object_list(t_object_ref *objects, int count, char *buffer, +void bvhd_format_objects(t_object_ref *objects, int count, char *buffer, void *scene_ptr) { int i; diff --git a/src/bvh_vis/bvh_vis_init.c b/src/bvh_debug/bvhd_init.c similarity index 80% rename from src/bvh_vis/bvh_vis_init.c rename to src/bvh_debug/bvhd_init.c index defce94..40500bc 100644 --- a/src/bvh_vis/bvh_vis_init.c +++ b/src/bvh_debug/bvhd_init.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_init.c :+: :+: :+: */ +/* bvhd_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include #include @@ -21,13 +21,13 @@ * * @return t_vis_config Default visualization configuration. */ -t_vis_config bvh_vis_default_config(void) +t_vis_config bvhd_default_config(void) { t_vis_config config; config.max_depth_display = -1; config.compact_mode = 0; - config.terminal_width = bvh_vis_get_terminal_width(); + config.terminal_width = bvhd_get_terminal_width(); config.show_warnings = 1; return (config); } @@ -39,7 +39,7 @@ t_vis_config bvh_vis_default_config(void) * * @return int Terminal width in columns. */ -int bvh_vis_get_terminal_width(void) +int bvhd_get_terminal_width(void) { struct winsize ws; @@ -58,14 +58,14 @@ int bvh_vis_get_terminal_width(void) * @param bvh BVH to visualize. * @param config Visualization configuration. */ -void check_edge_cases(t_bvh *bvh, t_vis_config *config) +void bvhd_check_edges(t_bvh *bvh, t_vis_config *config) { if (!bvh || !bvh->root || !config) return ; if (config->terminal_width < 80) { if (config->show_warnings) - print_warning_message("Terminal width < 80 chars, output may wrap"); + bvhd_warn("Terminal width < 80 chars, output may wrap"); } } @@ -79,7 +79,7 @@ void check_edge_cases(t_bvh *bvh, t_vis_config *config) * @param config Visualization configuration (optional). * @param scene Pointer to the scene used for object labels. */ -void bvh_visualize(t_bvh *bvh, t_vis_config *config, void *scene) +void bvhd_run(t_bvh *bvh, t_vis_config *config, void *scene) { t_prefix_state prefix; t_bvh_stats stats; @@ -90,20 +90,20 @@ void bvh_visualize(t_bvh *bvh, t_vis_config *config, void *scene) return ; if (!config) { - default_config = bvh_vis_default_config(); + default_config = bvhd_default_config(); config = &default_config; } - check_edge_cases(bvh, config); + bvhd_check_edges(bvh, config); stats.total_nodes = 0; stats.leaf_count = 0; stats.internal_count = 0; stats.max_depth = 0; stats.total_objects = 0; stats.avg_objects_per_leaf = 0.0; - prefix = prefix_init(); + prefix = bvhd_prefix_init(); ctx.prefix = &prefix; ctx.config = config; ctx.scene = scene; - bvh_visualize_tree(bvh->root, &ctx, &stats); - prefix_destroy(&prefix); + bvhd_print_tree(bvh->root, &ctx, &stats); + bvhd_prefix_destroy(&prefix); } diff --git a/src/bvh_vis/bvh_vis_node.c b/src/bvh_debug/bvhd_node.c similarity index 93% rename from src/bvh_vis/bvh_vis_node.c rename to src/bvh_debug/bvhd_node.c index 93c0087..9619391 100644 --- a/src/bvh_vis/bvh_vis_node.c +++ b/src/bvh_debug/bvhd_node.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_node.c :+: :+: :+: */ +/* bvhd_node.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include "minirt.h" #include "utils.h" #include @@ -21,7 +21,7 @@ * @param node BVH node to test. * @return int 1 if leaf, 0 otherwise. */ -int is_leaf_node(t_bvh_node *node) +int bvhd_is_leaf(t_bvh_node *node) { return (node->left == NULL && node->right == NULL); } @@ -83,12 +83,12 @@ static void format_bounds_str(t_aabb bounds, char *buf, size_t size, int comp) * @param node BVH node to format. * @return t_node_info Populated node info struct. */ -t_node_info format_node_info(t_bvh_node *node) +t_node_info bvhd_format_node(t_bvh_node *node) { t_node_info info; info.depth = node->depth; - if (is_leaf_node(node)) + if (bvhd_is_leaf(node)) ft_strlcpy(info.type, "Leaf", sizeof(info.type)); else ft_strlcpy(info.type, "Internal", sizeof(info.type)); diff --git a/src/bvh_vis/bvh_vis_prefix.c b/src/bvh_debug/bvhd_prefix.c similarity index 87% rename from src/bvh_vis/bvh_vis_prefix.c rename to src/bvh_debug/bvhd_prefix.c index aaf6bb9..d08bce0 100644 --- a/src/bvh_vis/bvh_vis_prefix.c +++ b/src/bvh_debug/bvhd_prefix.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_prefix.c :+: :+: :+: */ +/* bvhd_prefix.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include "libft.h" #include #include @@ -22,7 +22,7 @@ * * @return t_prefix_state Initialized prefix state. */ -t_prefix_state prefix_init(void) +t_prefix_state bvhd_prefix_init(void) { t_prefix_state state; @@ -46,7 +46,7 @@ t_prefix_state prefix_init(void) * * @param state Prefix state to update. */ -void prefix_pop(t_prefix_state *state) +void bvhd_prefix_pop(t_prefix_state *state) { if (state->length >= PREFIX_SEGMENT_LEN) { @@ -62,7 +62,7 @@ void prefix_pop(t_prefix_state *state) * * @param state Prefix state to print. */ -void prefix_print(t_prefix_state *state) +void bvhd_prefix_print(t_prefix_state *state) { if (state && state->buffer && state->length > 0) printf("%s", state->buffer); @@ -73,7 +73,7 @@ void prefix_print(t_prefix_state *state) * * @param state Prefix state to destroy. */ -void prefix_destroy(t_prefix_state *state) +void bvhd_prefix_destroy(t_prefix_state *state) { if (!state) return ; diff --git a/src/bvh_vis/bvh_vis_prefix_push.c b/src/bvh_debug/bvhd_prefix_push.c similarity index 92% rename from src/bvh_vis/bvh_vis_prefix_push.c rename to src/bvh_debug/bvhd_prefix_push.c index eaf1239..2e88d24 100644 --- a/src/bvh_vis/bvh_vis_prefix_push.c +++ b/src/bvh_debug/bvhd_prefix_push.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_prefix_push.c :+: :+: :+: */ +/* bvhd_prefix_push.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include "libft.h" #include #include @@ -46,7 +46,7 @@ static int prefix_grow(t_prefix_state *state) * @param is_last Non-zero if the current node is the last sibling. * @return int 1 on success, 0 on allocation failure. */ -int prefix_push(t_prefix_state *state, int is_last) +int bvhd_prefix_push(t_prefix_state *state, int is_last) { const char *prefix; int new_len; diff --git a/src/bvh_vis/bvh_vis_print.c b/src/bvh_debug/bvhd_print.c similarity index 86% rename from src/bvh_vis/bvh_vis_print.c rename to src/bvh_debug/bvhd_print.c index b3f6d2b..1fec785 100644 --- a/src/bvh_vis/bvh_vis_print.c +++ b/src/bvh_debug/bvhd_print.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_print.c :+: :+: :+: */ +/* bvhd_print.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include "libft.h" #include @@ -21,10 +21,10 @@ * @param info Formatted node info. * @param is_last Non-zero if this node is the last sibling. */ -void print_node_line(t_prefix_state *prefix, t_node_info *info, +void bvhd_print_node(t_prefix_state *prefix, t_node_info *info, int is_last) { - prefix_print(prefix); + bvhd_prefix_print(prefix); if (is_last) printf("└── "); else @@ -40,7 +40,7 @@ void print_node_line(t_prefix_state *prefix, t_node_info *info, * * @param message Warning text. */ -void print_warning_message(const char *message) +void bvhd_warn(const char *message) { ft_putstr_fd("Warning: ", 2); ft_putstr_fd((char *)message, 2); diff --git a/src/bvh_vis/bvh_vis_stats.c b/src/bvh_debug/bvhd_stats.c similarity index 82% rename from src/bvh_vis/bvh_vis_stats.c rename to src/bvh_debug/bvhd_stats.c index 76e2978..2541d95 100644 --- a/src/bvh_vis/bvh_vis_stats.c +++ b/src/bvh_debug/bvhd_stats.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_stats.c :+: :+: :+: */ +/* bvhd_stats.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include /** @@ -22,7 +22,7 @@ * @param stats Stats structure to update. * @param depth Current traversal depth. */ -void collect_stats_recursive(t_bvh_node *node, t_bvh_stats *stats, +void bvhd_collect_recursive(t_bvh_node *node, t_bvh_stats *stats, int depth) { if (!node || !stats) @@ -30,7 +30,7 @@ void collect_stats_recursive(t_bvh_node *node, t_bvh_stats *stats, stats->total_nodes++; if (depth > stats->max_depth) stats->max_depth = depth; - if (is_leaf_node(node)) + if (bvhd_is_leaf(node)) { stats->leaf_count++; stats->total_objects += node->object_count; @@ -38,9 +38,9 @@ void collect_stats_recursive(t_bvh_node *node, t_bvh_stats *stats, else { if (node->left) - collect_stats_recursive(node->left, stats, depth + 1); + bvhd_collect_recursive(node->left, stats, depth + 1); if (node->right) - collect_stats_recursive(node->right, stats, depth + 1); + bvhd_collect_recursive(node->right, stats, depth + 1); } } @@ -50,7 +50,7 @@ void collect_stats_recursive(t_bvh_node *node, t_bvh_stats *stats, * @param node Root node of the BVH. * @param stats Stats structure to populate. */ -void bvh_collect_statistics(t_bvh_node *node, t_bvh_stats *stats) +void bvhd_collect_stats(t_bvh_node *node, t_bvh_stats *stats) { if (!stats) return ; @@ -60,7 +60,7 @@ void bvh_collect_statistics(t_bvh_node *node, t_bvh_stats *stats) stats->max_depth = 0; stats->total_objects = 0; stats->avg_objects_per_leaf = 0.0; - collect_stats_recursive(node, stats, 0); + bvhd_collect_recursive(node, stats, 0); stats->internal_count = stats->total_nodes - stats->leaf_count; if (stats->leaf_count > 0) stats->avg_objects_per_leaf = (double)stats->total_objects @@ -72,7 +72,7 @@ void bvh_collect_statistics(t_bvh_node *node, t_bvh_stats *stats) * * @param stats Stats structure to print. */ -void print_statistics_summary(t_bvh_stats *stats) +void bvhd_print_stats(t_bvh_stats *stats) { if (!stats) return ; diff --git a/src/bvh_vis/bvh_vis_tree.c b/src/bvh_debug/bvhd_tree.c similarity index 77% rename from src/bvh_vis/bvh_vis_tree.c rename to src/bvh_debug/bvhd_tree.c index 06cdd8f..a830ec0 100644 --- a/src/bvh_vis/bvh_vis_tree.c +++ b/src/bvh_debug/bvhd_tree.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* bvh_vis_tree.c :+: :+: :+: */ +/* bvhd_tree.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,16 +10,16 @@ /* */ /* ************************************************************************** */ -#include "bvh_vis.h" +#include "bvh_debug.h" #include static void handle_node_display(t_bvh_node *node, t_traverse_ctx *ctx, t_node_info *info, int is_last) { - if (is_leaf_node(node)) - format_object_list(node->objects, node->object_count, info->objects, + if (bvhd_is_leaf(node)) + bvhd_format_objects(node->objects, node->object_count, info->objects, ctx->scene); - print_node_line(ctx->prefix, info, is_last); + bvhd_print_node(ctx->prefix, info, is_last); } /** @@ -39,23 +39,23 @@ static void traverse_recursive(t_bvh_node *node, t_traverse_ctx *ctx, if (!node) return ; - info = format_node_info(node); + info = bvhd_format_node(node); handle_node_display(node, ctx, &info, is_last); - if (!is_leaf_node(node)) + if (!bvhd_is_leaf(node)) { if (node->left) { - if (!prefix_push(ctx->prefix, is_last)) + if (!bvhd_prefix_push(ctx->prefix, is_last)) return ; traverse_recursive(node->left, ctx, !node->right); - prefix_pop(ctx->prefix); + bvhd_prefix_pop(ctx->prefix); } if (node->right) { - if (!prefix_push(ctx->prefix, is_last)) + if (!bvhd_prefix_push(ctx->prefix, is_last)) return ; traverse_recursive(node->right, ctx, 1); - prefix_pop(ctx->prefix); + bvhd_prefix_pop(ctx->prefix); } } } @@ -67,7 +67,7 @@ static void traverse_recursive(t_bvh_node *node, t_traverse_ctx *ctx, * @param ctx Traversal context for formatting. * @param stats Optional statistics structure to fill and print. */ -void bvh_visualize_tree(t_bvh_node *node, t_traverse_ctx *ctx, +void bvhd_print_tree(t_bvh_node *node, t_traverse_ctx *ctx, t_bvh_stats *stats) { if (!node) @@ -76,8 +76,8 @@ void bvh_visualize_tree(t_bvh_node *node, t_traverse_ctx *ctx, traverse_recursive(node, ctx, 1); if (stats) { - bvh_collect_statistics(node, stats); + bvhd_collect_stats(node, stats); printf("\n"); - print_statistics_summary(stats); + bvhd_print_stats(stats); } } diff --git a/src/main.c b/src/main.c index ed90649..231baa1 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ #include "parser.h" #include "render.h" #include "spatial.h" -#include "bvh_vis.h" +#include "bvh_debug.h" #include "texture.h" #include #include @@ -142,7 +142,7 @@ int main(int argc, char **argv) scene_build_bvh(scene); if (bvh_vis && scene->bvh) scene->bvh->visualize = 1; - bvh_visualize(scene->bvh, NULL, scene); + bvhd_run(scene->bvh, NULL, scene); if (!init_render(scene, &render)) return (1); if (!load_textures(scene, render)) diff --git a/src/render/render_loop.c b/src/render/render_loop.c index 4e5a7c1..22a0161 100644 --- a/src/render/render_loop.c +++ b/src/render/render_loop.c @@ -17,7 +17,7 @@ #include "keyguide.h" #include "metrics.h" #include "spatial.h" -#include "bvh_vis.h" +#include "bvh_debug.h" /** * @brief Rebuild the BVH if the dirty flag is set. @@ -32,7 +32,7 @@ static void rebuild_bvh_if_dirty(t_render *render) { scene_build_bvh(render->scene); render_clear_flag(render, RENDER_BVH_DIRTY); - bvh_visualize(render->scene->bvh, NULL, render->scene); + bvhd_run(render->scene->bvh, NULL, render->scene); } } From ef7f259ba5c85453e52701756cc00524b84f35e1 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:33:53 +0900 Subject: [PATCH 03/15] rename(spatial): rename scene_build_bvh to build_scene_bvh Align with verb-first naming convention used elsewhere. Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/spatial.h | 2 +- src/main.c | 2 +- src/render/render_loop.c | 2 +- src/spatial/bvh_init.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/spatial.h b/includes/spatial.h index 2ea0579..9fca66c 100644 --- a/includes/spatial.h +++ b/includes/spatial.h @@ -128,6 +128,6 @@ t_aabb get_object_bounds(t_object_ref ref, void *scene); t_vec3 get_object_center(t_object_ref ref, void *scene); /* Scene BVH initialization */ -void scene_build_bvh(t_scene *scene); +void build_scene_bvh(t_scene *scene); #endif diff --git a/src/main.c b/src/main.c index 231baa1..0ccc96d 100644 --- a/src/main.c +++ b/src/main.c @@ -139,7 +139,7 @@ int main(int argc, char **argv) return (printf("Usage: %s [--bvh-vis]\n", argv[0]), 1); if (!init_scene(filename, &scene)) return (1); - scene_build_bvh(scene); + build_scene_bvh(scene); if (bvh_vis && scene->bvh) scene->bvh->visualize = 1; bvhd_run(scene->bvh, NULL, scene); diff --git a/src/render/render_loop.c b/src/render/render_loop.c index 22a0161..e1ee67b 100644 --- a/src/render/render_loop.c +++ b/src/render/render_loop.c @@ -30,7 +30,7 @@ static void rebuild_bvh_if_dirty(t_render *render) { if (render_has_flag(render, RENDER_BVH_DIRTY)) { - scene_build_bvh(render->scene); + build_scene_bvh(render->scene); render_clear_flag(render, RENDER_BVH_DIRTY); bvhd_run(render->scene->bvh, NULL, render->scene); } diff --git a/src/spatial/bvh_init.c b/src/spatial/bvh_init.c index cf6217a..54a867f 100644 --- a/src/spatial/bvh_init.c +++ b/src/spatial/bvh_init.c @@ -130,7 +130,7 @@ static int alloc_bvh_refs(t_scene *scene, t_object_ref **refs, int pc, int bc) * * @param scene Scene containing objects and BVH state. */ -void scene_build_bvh(t_scene *scene) +void build_scene_bvh(t_scene *scene) { t_object_ref *refs; int pc; From b12670cd9db0862856499f9781bd46a91958d028 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:34:11 +0900 Subject: [PATCH 04/15] rename(intersect): drop _new suffix from intersect functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - intersect_object_new → intersect_object - intersect_cylinder_new → intersect_cylinder - intersect_cone_new → intersect_cone The _new suffix was a migration artifact; the old versions no longer exist, so the suffix adds no value. Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/intersect.h | 6 +++--- src/intersect/intersect_cone_cap.c | 2 +- src/intersect/intersect_cylinder.c | 2 +- src/intersect/intersect_object.c | 6 +++--- src/render/render_trace.c | 4 ++-- src/shadow/shadow_test.c | 4 ++-- src/spatial/bvh_any_hit.c | 2 +- src/spatial/bvh_traverse.c | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/includes/intersect.h b/includes/intersect.h index 680be26..00ffe99 100644 --- a/includes/intersect.h +++ b/includes/intersect.h @@ -16,10 +16,10 @@ # include "ray.h" /* Ray-object intersection functions */ -int intersect_object_new(t_ray *ray, t_object *obj, t_hit *hit); -int intersect_cylinder_new(t_ray *ray, t_cylinder_data *c, t_color color, +int intersect_object(t_ray *ray, t_object *obj, t_hit *hit); +int intersect_cylinder(t_ray *ray, t_cylinder_data *c, t_color color, t_hit *hit); -int intersect_cone_new(t_ray *ray, t_object *obj, t_hit *hit); +int intersect_cone(t_ray *ray, t_object *obj, t_hit *hit); int intersect_cone_body(t_ray *ray, t_cone_data *c, t_hit *hit); #endif diff --git a/src/intersect/intersect_cone_cap.c b/src/intersect/intersect_cone_cap.c index cde20e7..86d9fff 100644 --- a/src/intersect/intersect_cone_cap.c +++ b/src/intersect/intersect_cone_cap.c @@ -49,7 +49,7 @@ static void apply_cone_hit(t_hit *hit, t_hit *temp, t_color color, int *found) *found = 1; } -int intersect_cone_new(t_ray *ray, t_object *obj, t_hit *hit) +int intersect_cone(t_ray *ray, t_object *obj, t_hit *hit) { int found; t_hit temp; diff --git a/src/intersect/intersect_cylinder.c b/src/intersect/intersect_cylinder.c index d12e05c..5c022b8 100644 --- a/src/intersect/intersect_cylinder.c +++ b/src/intersect/intersect_cylinder.c @@ -152,7 +152,7 @@ static void apply_cyl_hit(t_hit *hit, t_hit *temp, t_color color, int *found) * @param hit Hit record to update. * @return int 1 if any intersection is found, 0 otherwise. */ -int intersect_cylinder_new(t_ray *ray, t_cylinder_data *c, t_color color, +int intersect_cylinder(t_ray *ray, t_cylinder_data *c, t_color color, t_hit *hit) { int found; diff --git a/src/intersect/intersect_object.c b/src/intersect/intersect_object.c index c2b2890..7d1a94c 100644 --- a/src/intersect/intersect_object.c +++ b/src/intersect/intersect_object.c @@ -101,7 +101,7 @@ static int intersect_plane_new(t_ray *ray, t_plane_data *p, t_color color, * @param hit Hit record to update. * @return int 1 if an intersection is found, 0 otherwise. */ -int intersect_object_new(t_ray *ray, t_object *obj, t_hit_record *hit) +int intersect_object(t_ray *ray, t_object *obj, t_hit_record *hit) { int result; @@ -111,10 +111,10 @@ int intersect_object_new(t_ray *ray, t_object *obj, t_hit_record *hit) else if (obj->type == OBJ_PLANE) result = intersect_plane_new(ray, &obj->data.plane, obj->color, hit); else if (obj->type == OBJ_CYLINDER) - result = intersect_cylinder_new(ray, &obj->data.cylinder, obj->color, + result = intersect_cylinder(ray, &obj->data.cylinder, obj->color, hit); else if (obj->type == OBJ_CONE) - result = intersect_cone_new(ray, obj, hit); + result = intersect_cone(ray, obj, hit); if (result) hit->obj = obj; return (result); diff --git a/src/render/render_trace.c b/src/render/render_trace.c index 17af471..f666be4 100644 --- a/src/render/render_trace.c +++ b/src/render/render_trace.c @@ -42,7 +42,7 @@ static int check_all_objects(t_scene *scene, t_ray *ray, t_hit *hit) obj = &scene->objects.items[i]; temp.distance = hit->distance; metrics_add_intersect_test(&scene->metrics); - if (intersect_object_new(ray, obj, &temp)) + if (intersect_object(ray, obj, &temp)) { *hit = temp; found = 1; @@ -77,7 +77,7 @@ static int intersect_planes(t_scene *scene, t_ray *ray, t_hit *hit) obj = &scene->objects.items[scene->bvh->plane_refs.indices[i]]; temp.distance = hit->distance; metrics_add_intersect_test(&scene->metrics); - if (intersect_object_new(ray, obj, &temp)) + if (intersect_object(ray, obj, &temp)) { *hit = temp; found = 1; diff --git a/src/shadow/shadow_test.c b/src/shadow/shadow_test.c index 3874efe..cecd4ec 100644 --- a/src/shadow/shadow_test.c +++ b/src/shadow/shadow_test.c @@ -38,7 +38,7 @@ static int check_object_shadow(t_scene *scene, t_ray *ray, t_hit *hit) { obj = &scene->objects.items[i]; metrics_add_shadow_intersect(&scene->metrics); - if (intersect_object_new(ray, obj, hit)) + if (intersect_object(ray, obj, hit)) return (1); i++; } @@ -69,7 +69,7 @@ static int check_plane_shadow(t_scene *scene, t_ray *ray, double mag) obj = &scene->objects.items[scene->bvh->plane_refs.indices[i]]; hit.distance = mag; metrics_add_shadow_intersect(&scene->metrics); - if (intersect_object_new(ray, obj, &hit)) + if (intersect_object(ray, obj, &hit)) return (1); i++; } diff --git a/src/spatial/bvh_any_hit.c b/src/spatial/bvh_any_hit.c index 2eff873..4464df4 100644 --- a/src/spatial/bvh_any_hit.c +++ b/src/spatial/bvh_any_hit.c @@ -51,7 +51,7 @@ static int leaf_any_hit(t_bvh_node *node, t_ray ray, double max_dist, { metrics_add_shadow_intersect(&((t_scene *)scene)->metrics); obj = &((t_scene *)scene)->objects.items[node->objects[i].index]; - if (intersect_object_new(&ray, obj, &temp_hit)) + if (intersect_object(&ray, obj, &temp_hit)) return (1); i++; } diff --git a/src/spatial/bvh_traverse.c b/src/spatial/bvh_traverse.c index 1fff9af..ffe8faa 100644 --- a/src/spatial/bvh_traverse.c +++ b/src/spatial/bvh_traverse.c @@ -51,7 +51,7 @@ static int bvh_leaf_intersect(t_bvh_node *node, t_ray ray, t_hit_record *hit, { metrics_add_intersect_test(&((t_scene *)scene)->metrics); obj = &((t_scene *)scene)->objects.items[node->objects[i].index]; - if (intersect_object_new(&ray, obj, &temp_hit)) + if (intersect_object(&ray, obj, &temp_hit)) { if (!hit_anything || temp_hit.distance < hit->distance) { From 8bfcf93ddc0a816442bf9274fa395e694aa1369f Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:34:26 +0900 Subject: [PATCH 05/15] rename(shadow): rename is_in_shadow to shadow_is_occluded Align with module-prefixed naming convention (shadow_*). Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/shadow.h | 2 +- src/shadow/shadow_calc.c | 2 +- src/shadow/shadow_test.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/shadow.h b/includes/shadow.h index b25a4f1..eb8b5e7 100644 --- a/includes/shadow.h +++ b/includes/shadow.h @@ -111,7 +111,7 @@ double calculate_shadow_factor(t_scene *scene, t_shadow_query query, * @param bias Shadow bias offset * @return 1 if in shadow, 0 if lit */ -int is_in_shadow(t_scene *scene, t_shadow_query query, +int shadow_is_occluded(t_scene *scene, t_shadow_query query, t_vec3 light_pos, double bias); #endif diff --git a/src/shadow/shadow_calc.c b/src/shadow/shadow_calc.c index c519aa1..9b0e0be 100644 --- a/src/shadow/shadow_calc.c +++ b/src/shadow/shadow_calc.c @@ -103,7 +103,7 @@ static int sample_shadow_ray(t_shadow_sample *params, int index) else tang = vec3_normalize(vec3_cross(light_dir, (t_vec3){1, 0, 0})); bitang = vec3_cross(light_dir, tang); - return (is_in_shadow(params->scene, params->query, vec3_add( + return (shadow_is_occluded(params->scene, params->query, vec3_add( params->light_pos, vec3_add(vec3_multiply(tang, offset.x), vec3_multiply(bitang, offset.y))), params->bias)); } diff --git a/src/shadow/shadow_test.c b/src/shadow/shadow_test.c index cecd4ec..f3cabd3 100644 --- a/src/shadow/shadow_test.c +++ b/src/shadow/shadow_test.c @@ -100,7 +100,7 @@ static void init_shadow_ray(t_ray *ray, t_shadow_query *query, * @param bias Bias distance to offset the shadow ray origin. * @return int 1 if the point is in shadow, 0 otherwise. */ -int is_in_shadow(t_scene *scene, t_shadow_query query, t_vec3 light_pos, +int shadow_is_occluded(t_scene *scene, t_shadow_query query, t_vec3 light_pos, double bias) { t_ray shadow_ray; From ab213baf9a7995103fb4b5854064ab625e59990a Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:34:41 +0900 Subject: [PATCH 06/15] rename(hud): add hud_ prefix to HUD functions for consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - format_and_print_vec3 → hud_print_vec3 - render_camera_fov → hud_render_camera_fov - render_light_bright → hud_render_light_bright - render_object_entry → hud_render_object_entry - keyguide_render_content2 → keyguide_render_objects_section (static) Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/hud_internal.h | 8 ++++---- src/hud/hud_obj_render.c | 2 +- src/hud/hud_objects.c | 2 +- src/hud/hud_render.c | 4 ++-- src/hud/hud_scene.c | 10 +++++----- src/hud/hud_text.c | 2 +- src/keyguide/keyguide_render.c | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/includes/hud_internal.h b/includes/hud_internal.h index 4c773a8..915f454 100644 --- a/includes/hud_internal.h +++ b/includes/hud_internal.h @@ -18,19 +18,19 @@ /* HUD text utilities */ void hud_mark_dirty(t_render *render); void hud_print_line(t_render *r, int *y, int color, char *text); -void format_and_print_vec3(t_render *render, int *y, +void hud_print_vec3(t_render *render, int *y, char *label, t_vec3 vec); int hud_append(char *dst, const char *src, int max); /* HUD scene info sections */ void hud_render_camera(t_render *render, int *y); -void render_camera_fov(t_render *render, int *y); +void hud_render_camera_fov(t_render *render, int *y); void hud_render_ambient(t_render *render, int *y); void hud_render_light(t_render *render, int *y); -void render_light_bright(t_render *render, int *y); +void hud_render_light_bright(t_render *render, int *y); /* HUD object list */ void hud_render_objects(t_render *render, int *y); -void render_object_entry(t_render *render, int idx, int *y, int color); +void hud_render_object_entry(t_render *render, int idx, int *y, int color); #endif diff --git a/src/hud/hud_obj_render.c b/src/hud/hud_obj_render.c index 6ad0428..752039c 100644 --- a/src/hud/hud_obj_render.c +++ b/src/hud/hud_obj_render.c @@ -65,7 +65,7 @@ static void fill_obj_id(char *buf, int *i, t_object *obj) * @param y Current y position (in/out). * @param color Text color for the entry. */ -void render_object_entry(t_render *render, int idx, int *y, int color) +void hud_render_object_entry(t_render *render, int idx, int *y, int color) { char buf[128]; int i; diff --git a/src/hud/hud_objects.c b/src/hud/hud_objects.c index 7982428..1e60bad 100644 --- a/src/hud/hud_objects.c +++ b/src/hud/hud_objects.c @@ -62,7 +62,7 @@ static void render_object_by_index(t_render *render, int g_idx, int *y) if (sel.index == render->selection.index && sel.type == render->selection.type) color = HUD_COLOR_HIGHLIGHT; - render_object_entry(render, g_idx, y, color); + hud_render_object_entry(render, g_idx, y, color); } /** diff --git a/src/hud/hud_render.c b/src/hud/hud_render.c index 69415a0..04387fa 100644 --- a/src/hud/hud_render.c +++ b/src/hud/hud_render.c @@ -27,12 +27,12 @@ void hud_render_content(t_render *render) y = HUD_MARGIN_Y + 20; hud_render_camera(render, &y); - render_camera_fov(render, &y); + hud_render_camera_fov(render, &y); y += HUD_LINE_HEIGHT / 2; hud_render_ambient(render, &y); y += HUD_LINE_HEIGHT / 2; hud_render_light(render, &y); - render_light_bright(render, &y); + hud_render_light_bright(render, &y); y += HUD_LINE_HEIGHT; hud_render_objects(render, &y); y += HUD_LINE_HEIGHT; diff --git a/src/hud/hud_scene.c b/src/hud/hud_scene.c index a7a3253..62a4ff7 100644 --- a/src/hud/hud_scene.c +++ b/src/hud/hud_scene.c @@ -25,8 +25,8 @@ void hud_render_camera(t_render *render, int *y) { hud_print_line(render, y, HUD_COLOR_TEXT, "Camera:"); - format_and_print_vec3(render, y, "pos", render->scene->camera.position); - format_and_print_vec3(render, y, "dir", render->scene->camera.direction); + hud_print_vec3(render, y, "pos", render->scene->camera.position); + hud_print_vec3(render, y, "dir", render->scene->camera.direction); } /** @@ -35,7 +35,7 @@ void hud_render_camera(t_render *render, int *y) * @param render Render context containing scene. * @param y Current y position (in/out). */ -void render_camera_fov(t_render *render, int *y) +void hud_render_camera_fov(t_render *render, int *y) { char buf[64]; int i; @@ -110,7 +110,7 @@ void hud_render_light(t_render *render, int *y) buf[i++] = ':'; buf[i] = '\0'; hud_print_line(render, y, HUD_COLOR_TEXT, buf); - format_and_print_vec3(render, y, "pos", + hud_print_vec3(render, y, "pos", render->scene->lights[render->scene->selected_light].position); } @@ -120,7 +120,7 @@ void hud_render_light(t_render *render, int *y) * @param render Render context containing scene. * @param y Current y position (in/out). */ -void render_light_bright(t_render *render, int *y) +void hud_render_light_bright(t_render *render, int *y) { char buf[128]; int i; diff --git a/src/hud/hud_text.c b/src/hud/hud_text.c index 1cc52c8..e00362c 100644 --- a/src/hud/hud_text.c +++ b/src/hud/hud_text.c @@ -25,7 +25,7 @@ void hud_print_line(t_render *r, int *y, int color, char *text) *y += HUD_LINE_HEIGHT; } -void format_and_print_vec3(t_render *render, int *y, +void hud_print_vec3(t_render *render, int *y, char *label, t_vec3 vec) { char buf[128]; diff --git a/src/keyguide/keyguide_render.c b/src/keyguide/keyguide_render.c index 80decb0..ce27b12 100644 --- a/src/keyguide/keyguide_render.c +++ b/src/keyguide/keyguide_render.c @@ -75,7 +75,7 @@ void keyguide_render_content(t_render *render) * @param render Render context containing key guide position. * @param y Current y position (in/out) for text rendering. */ -void keyguide_render_content2(t_render *render, int *y) +static void keyguide_render_objects_section(t_render *render, int *y) { *y += KEYGUIDE_SECTION_GAP + KEYGUIDE_LINE_HEIGHT; mlx_string_put(render->mlx.mlx, render->mlx.win, @@ -111,7 +111,7 @@ void keyguide_render(t_render *render) y = render->keyguide.y + 20 + 30 + KEYGUIDE_LINE_HEIGHT * KEYGUIDE_CONTENT1_LINES + KEYGUIDE_SECTION_GAP + KEYGUIDE_LINE_HEIGHT * 3; - keyguide_render_content2(render, &y); + keyguide_render_objects_section(render, &y); keyguide_render_extra(render, &y); render->keyguide.dirty = 0; } From ac6cee967e479a03aac37f61e556e6bfc9a2e1de Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:35:10 +0900 Subject: [PATCH 07/15] refactor(parser): consolidate small parser utility files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge single-purpose files back into their parent modules to reduce file count and improve locality: - parse_token.c → parser_utils.c (skip_whitespace, at_line_end) - parse_number_utils.c → parse_number.c (parse_int_part, parse_frac_part) - parse_error_msg.c → parse_error.c (error_write_int, get_error_message) - Replace parse_is_digit() with libft's ft_isdigit() Co-Authored-By: Claude Opus 4.6 (1M context) --- Makefile | 3 -- includes/parser.h | 1 - src/parser/parse_error.c | 48 ++++++++++++++++++++ src/parser/parse_error_msg.c | 72 ------------------------------ src/parser/parse_number.c | 43 +++++++++++++++++- src/parser/parse_number_utils.c | 78 --------------------------------- src/parser/parse_token.c | 52 ---------------------- src/parser/parser_utils.c | 13 ++++++ 8 files changed, 103 insertions(+), 207 deletions(-) delete mode 100644 src/parser/parse_error_msg.c delete mode 100644 src/parser/parse_number_utils.c delete mode 100644 src/parser/parse_token.c diff --git a/Makefile b/Makefile index 5b229ae..42940f4 100644 --- a/Makefile +++ b/Makefile @@ -49,11 +49,8 @@ SRCS = $(SRC_DIR)/main.c \ $(SRC_DIR)/parser/parse_cone.c \ $(SRC_DIR)/parser/parse_bonus_options.c \ $(SRC_DIR)/parser/parse_number.c \ - $(SRC_DIR)/parser/parse_number_utils.c \ - $(SRC_DIR)/parser/parse_token.c \ $(SRC_DIR)/parser/parse_line_reader.c \ $(SRC_DIR)/parser/parse_error.c \ - $(SRC_DIR)/parser/parse_error_msg.c \ $(SRC_DIR)/parser/parse_validation_strict.c \ $(SRC_DIR)/parser/parse_vector_validation.c \ $(SRC_DIR)/spatial/aabb.c \ diff --git a/includes/parser.h b/includes/parser.h index 559cfbf..939f9a7 100644 --- a/includes/parser.h +++ b/includes/parser.h @@ -83,7 +83,6 @@ int line_reader_get_line_num(t_line_reader *reader); t_parse_result parse_double(const char *str, double *value, const char **end); t_parse_result parse_int(const char *str, int *value, const char **end); -int parse_is_digit(char c); double parse_int_part(const char **str, int *has_digits); double parse_frac_part(const char **str, int *has_digits); diff --git a/src/parser/parse_error.c b/src/parser/parse_error.c index 13de10a..2630659 100644 --- a/src/parser/parse_error.c +++ b/src/parser/parse_error.c @@ -12,6 +12,54 @@ #include "parser.h" #include "error.h" +#include + +static void write_uint(unsigned int n) +{ + char c; + + if (n >= 10) + write_uint(n / 10); + c = '0' + (n % 10); + write(2, &c, 1); +} + +void error_write_int(int n) +{ + unsigned int u; + + if (n < 0) + { + write(2, "-", 1); + u = -(unsigned int)n; + } + else + u = (unsigned int)n; + write_uint(u); +} + +const char *get_error_message(t_parse_result code) +{ + static const char *msgs[] = { + "", + "Invalid format", + "Value out of range", + "Vector requires exactly 3 components", + "Duplicate declaration", + "Line too long (max 4096 characters)", + "Direction vector cannot be zero", + "Unexpected token at end of line", + "Unknown element identifier", + "Invalid number format", + "Missing required element", + "I/O error while reading file", + "Maximum element count exceeded" + }; + + if (code >= 0 && code < PARSE_ERR_COUNT) + return (msgs[code]); + return ("Unknown error"); +} /** * @brief Initialize error context with default values. diff --git a/src/parser/parse_error_msg.c b/src/parser/parse_error_msg.c deleted file mode 100644 index e762a45..0000000 --- a/src/parser/parse_error_msg.c +++ /dev/null @@ -1,72 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* parse_error_msg.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: yoshin +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2026/01/30 12:00:00 by yoshin #+# #+# */ -/* Updated: 2026/01/30 12:00:00 by yoshin ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "parser.h" -#include - -/** - * @brief Write an integer to stderr. - * - * @param n Integer to write. - */ -static void write_uint(unsigned int n) -{ - char c; - - if (n >= 10) - write_uint(n / 10); - c = '0' + (n % 10); - write(2, &c, 1); -} - -void error_write_int(int n) -{ - unsigned int u; - - if (n < 0) - { - write(2, "-", 1); - u = -(unsigned int)n; - } - else - u = (unsigned int)n; - write_uint(u); -} - -/** - * @brief Get error message for a parse result code. - * - * @param code Parse result code. - * @return const char* Error message string. - */ -const char *get_error_message(t_parse_result code) -{ - static const char *msgs[] = { - "", - "Invalid format", - "Value out of range", - "Vector requires exactly 3 components", - "Duplicate declaration", - "Line too long (max 4096 characters)", - "Direction vector cannot be zero", - "Unexpected token at end of line", - "Unknown element identifier", - "Invalid number format", - "Missing required element", - "I/O error while reading file", - "Maximum element count exceeded" - }; - - if (code >= 0 && code < PARSE_ERR_COUNT) - return (msgs[code]); - return ("Unknown error"); -} diff --git a/src/parser/parse_number.c b/src/parser/parse_number.c index ac5ad30..ac2b2f0 100644 --- a/src/parser/parse_number.c +++ b/src/parser/parse_number.c @@ -11,9 +11,50 @@ /* ************************************************************************** */ #include "parser.h" +#include "libft.h" #include #include +double parse_int_part(const char **str, int *has_digits) +{ + double result; + + result = 0.0; + while (ft_isdigit(**str)) + { + result = result * 10.0 + (**str - '0'); + (*str)++; + *has_digits = 1; + } + return (result); +} + +double parse_frac_part(const char **str, int *has_digits) +{ + double result; + double divisor; + int digits; + + result = 0.0; + divisor = 10.0; + digits = 0; + if (**str == '.') + { + (*str)++; + while (ft_isdigit(**str) && digits < 15) + { + result += (**str - '0') / divisor; + divisor *= 10.0; + (*str)++; + digits++; + } + if (digits == 0) + return (-1.0); + *has_digits = 1; + } + return (result); +} + /** * @brief Parse double value with format validation. * @@ -62,7 +103,7 @@ static int parse_int_digits(const char **str, int *result, int *has_digits) { int digit; - while (parse_is_digit(**str)) + while (ft_isdigit(**str)) { digit = **str - '0'; if (*result > (INT_MAX - digit) / 10) diff --git a/src/parser/parse_number_utils.c b/src/parser/parse_number_utils.c deleted file mode 100644 index feb5423..0000000 --- a/src/parser/parse_number_utils.c +++ /dev/null @@ -1,78 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* parse_number_utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: yoshin +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2026/01/30 12:00:00 by yoshin #+# #+# */ -/* Updated: 2026/01/30 12:00:00 by yoshin ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "parser.h" - -/** - * @brief Check if character is a digit. - * - * @param c Character to check. - * @return int 1 if digit, 0 otherwise. - */ -int parse_is_digit(char c) -{ - return (c >= '0' && c <= '9'); -} - -/** - * @brief Parse the integer part of a number. - * - * @param str Pointer to string pointer (updated). - * @param has_digits Set to 1 if any digits were parsed. - * @return double Parsed integer value. - */ -double parse_int_part(const char **str, int *has_digits) -{ - double result; - - result = 0.0; - while (parse_is_digit(**str)) - { - result = result * 10.0 + (**str - '0'); - (*str)++; - *has_digits = 1; - } - return (result); -} - -/** - * @brief Parse the fractional part of a number. - * - * @param str Pointer to string pointer (updated). - * @param has_digits Set to 1 if any digits were parsed. - * @return double Parsed fractional value. - */ -double parse_frac_part(const char **str, int *has_digits) -{ - double result; - double divisor; - int digits; - - result = 0.0; - divisor = 10.0; - digits = 0; - if (**str == '.') - { - (*str)++; - while (parse_is_digit(**str) && digits < 15) - { - result += (**str - '0') / divisor; - divisor *= 10.0; - (*str)++; - digits++; - } - if (digits == 0) - return (-1.0); - *has_digits = 1; - } - return (result); -} diff --git a/src/parser/parse_token.c b/src/parser/parse_token.c deleted file mode 100644 index c6e992e..0000000 --- a/src/parser/parse_token.c +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* parse_token.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: yoshin +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2026/01/30 12:00:00 by yoshin #+# #+# */ -/* Updated: 2026/01/30 12:00:00 by yoshin ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "parser.h" - -/** - * @brief Check if character is whitespace (space or tab). - * - * @param c Character to check. - * @return int 1 if whitespace, 0 otherwise. - */ -static int is_whitespace(char c) -{ - return (c == ' ' || c == '\t'); -} - -/** - * @brief Skip whitespace characters (space, tab). - * - * @param str Input string. - * @return const char* Pointer to first non-whitespace character. - */ -const char *skip_whitespace(const char *str) -{ - while (is_whitespace(*str)) - str++; - return (str); -} - -/** - * @brief Check if at end of meaningful content. - * - * Returns 1 if the current position is whitespace, null terminator, - * newline, or comment character. - * - * @param str Current position. - * @return int 1 if at line end, 0 otherwise. - */ -int at_line_end(const char *str) -{ - str = skip_whitespace(str); - return (*str == '\0' || *str == '\n' || *str == '#'); -} diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c index 478e7fd..660c88f 100644 --- a/src/parser/parser_utils.c +++ b/src/parser/parser_utils.c @@ -13,6 +13,19 @@ #include "minirt.h" #include "parser.h" +const char *skip_whitespace(const char *str) +{ + while (*str == ' ' || *str == '\t') + str++; + return (str); +} + +int at_line_end(const char *str) +{ + str = skip_whitespace(str); + return (*str == '\0' || *str == '\n' || *str == '#'); +} + /** * @brief Initialize line reader with file descriptor. * From 6745ab33dbc8bda7fbe9d625ef6c8c97b3f8bcbe Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:36:12 +0900 Subject: [PATCH 08/15] refactor(scene): inline flag helpers and make object_list_grow static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove scene_flags.c: scene_has_ambient, scene_has_camera, scene_set_flag, scene_clear_flag were trivial wrappers around bitwise ops — inline them at call sites - Make object_list_grow() static (only called within object_list.c) - Remove exported prototypes from minirt.h Co-Authored-By: Claude Opus 4.6 (1M context) --- Makefile | 1 - includes/minirt.h | 7 ----- src/parser/parse_elements.c | 8 ++--- src/parser/parser.c | 4 +-- src/scene/object_list.c | 2 +- src/scene/scene_flags.c | 63 ------------------------------------- 6 files changed, 7 insertions(+), 78 deletions(-) delete mode 100644 src/scene/scene_flags.c diff --git a/Makefile b/Makefile index 42940f4..961f62b 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,6 @@ endif SRCS = $(SRC_DIR)/main.c \ $(SRC_DIR)/scene/scene.c \ - $(SRC_DIR)/scene/scene_flags.c \ $(SRC_DIR)/scene/object_list.c \ $(SRC_DIR)/parser/parser.c \ $(SRC_DIR)/parser/parser_dispatch.c \ diff --git a/includes/minirt.h b/includes/minirt.h index 98dfe4f..89b1de5 100644 --- a/includes/minirt.h +++ b/includes/minirt.h @@ -113,13 +113,6 @@ void scene_destroy(t_scene *scene); int object_list_init(t_object_list *list, int capacity); void object_list_destroy(t_object_list *list); int object_list_add(t_object_list *list, t_object *obj); -int object_list_grow(t_object_list *list); - -/* Scene flag helpers */ -int scene_has_ambient(t_scene *scene); -int scene_has_camera(t_scene *scene); -void scene_set_flag(t_scene *scene, int flag); -void scene_clear_flag(t_scene *scene, int flag); /* Rendering */ void render_scene_to_buffer(t_scene *scene, t_render *render); diff --git a/src/parser/parse_elements.c b/src/parser/parse_elements.c index 4255d82..e60b65b 100644 --- a/src/parser/parse_elements.c +++ b/src/parser/parse_elements.c @@ -31,7 +31,7 @@ t_parse_result parse_ambient(char *line, t_scene *scene) double ratio; t_parse_result result; - if (scene_has_ambient(scene)) + if ((scene->flags & SCENE_HAS_AMBIENT)) return (PARSE_ERR_DUPLICATE); token = skip_whitespace(line + 2); result = parse_double(token, &ratio, &token); @@ -46,7 +46,7 @@ t_parse_result parse_ambient(char *line, t_scene *scene) return (result); if (!at_line_end(token)) return (PARSE_ERR_TRAILING_TOKEN); - scene_set_flag(scene, SCENE_HAS_AMBIENT); + scene->flags |= SCENE_HAS_AMBIENT; return (PARSE_OK); } @@ -107,7 +107,7 @@ t_parse_result parse_camera(char *line, t_scene *scene) t_parse_result result; int fov; - if (scene_has_camera(scene)) + if ((scene->flags & SCENE_HAS_CAMERA)) return (PARSE_ERR_DUPLICATE); token = skip_whitespace(line + 2); result = parse_camera_vecs(&token, scene); @@ -123,7 +123,7 @@ t_parse_result parse_camera(char *line, t_scene *scene) if (!at_line_end(token)) return (PARSE_ERR_TRAILING_TOKEN); init_camera_state(scene); - scene_set_flag(scene, SCENE_HAS_CAMERA); + scene->flags |= SCENE_HAS_CAMERA; return (PARSE_OK); } diff --git a/src/parser/parser.c b/src/parser/parser.c index 8ba7c04..cd684a5 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -53,9 +53,9 @@ static int parse_line(char *line, t_scene *scene, t_error_context *ctx) */ int validate_scene(t_scene *scene) { - if (!scene_has_ambient(scene)) + if (!(scene->flags & SCENE_HAS_AMBIENT)) return (error_print_ctx("Missing element: ", "ambient light (A)"), 0); - if (!scene_has_camera(scene)) + if (!(scene->flags & SCENE_HAS_CAMERA)) return (error_print_ctx("Missing element: ", "camera (C)"), 0); if (scene->light_count == 0) return (error_print_ctx("Missing element: ", "light (L)"), 0); diff --git a/src/scene/object_list.c b/src/scene/object_list.c index 323e384..3e3f0b5 100644 --- a/src/scene/object_list.c +++ b/src/scene/object_list.c @@ -66,7 +66,7 @@ void object_list_destroy(t_object_list *list) * @param list Object list to grow. * @return int 1 on success, 0 on failure. */ -int object_list_grow(t_object_list *list) +static int object_list_grow(t_object_list *list) { t_object *new_items; int new_capacity; diff --git a/src/scene/scene_flags.c b/src/scene/scene_flags.c deleted file mode 100644 index cb587d8..0000000 --- a/src/scene/scene_flags.c +++ /dev/null @@ -1,63 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* scene_flags.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: yoshin +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2026/01/27 12:00:00 by yoshin #+# #+# */ -/* Updated: 2026/01/27 12:00:00 by yoshin ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minirt.h" - -/** - * @brief Check if the scene has an ambient light definition. - * - * @param scene Scene to query. - * @return int 1 if ambient flag is set, 0 otherwise. - */ -int scene_has_ambient(t_scene *scene) -{ - if (!scene) - return (0); - return ((scene->flags & SCENE_HAS_AMBIENT) != 0); -} - -/** - * @brief Check if the scene has a camera definition. - * - * @param scene Scene to query. - * @return int 1 if camera flag is set, 0 otherwise. - */ -int scene_has_camera(t_scene *scene) -{ - if (!scene) - return (0); - return ((scene->flags & SCENE_HAS_CAMERA) != 0); -} - -/** - * @brief Set a scene flag bit. - * - * @param scene Scene to update. - * @param flag Flag bit to set. - */ -void scene_set_flag(t_scene *scene, int flag) -{ - if (scene) - scene->flags |= flag; -} - -/** - * @brief Clear a scene flag bit. - * - * @param scene Scene to update. - * @param flag Flag bit to clear. - */ -void scene_clear_flag(t_scene *scene, int flag) -{ - if (scene) - scene->flags &= ~flag; -} From 2c999f41daf6fa6874fccf56d2078f8409a4cd62 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:36:21 +0900 Subject: [PATCH 09/15] refactor(utils): move timer_elapsed_us to utils module - Move timer_elapsed_us declaration from metrics.h to utils.h - Remove timer_start (callers use gettimeofday directly) - Remove timer_elapsed_ms (unused) - metrics_frame.c: call gettimeofday directly Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/metrics.h | 5 ----- includes/utils.h | 4 ++++ src/metrics/metrics_frame.c | 3 ++- src/utils/timer.c | 23 +---------------------- 4 files changed, 7 insertions(+), 28 deletions(-) diff --git a/includes/metrics.h b/includes/metrics.h index 1c865c7..8b1fa33 100644 --- a/includes/metrics.h +++ b/includes/metrics.h @@ -52,11 +52,6 @@ typedef struct s_metrics t_bvh_metrics bvh; } t_metrics; -/* Timer utilities */ -void timer_start(struct timeval *tv); -long timer_elapsed_us(struct timeval *start); -double timer_elapsed_ms(struct timeval *start); - /* Metrics operations */ void metrics_init(t_metrics *metrics); void metrics_start_frame(t_metrics *metrics); diff --git a/includes/utils.h b/includes/utils.h index 4323791..f5c1fe3 100644 --- a/includes/utils.h +++ b/includes/utils.h @@ -14,6 +14,10 @@ # define UTILS_H # include +# include + +/* Timer utilities */ +long timer_elapsed_us(struct timeval *start); /* Format helpers for libft-compliant string formatting */ int format_id(char *buf, size_t size, const char *prefix, int n); diff --git a/src/metrics/metrics_frame.c b/src/metrics/metrics_frame.c index 448128f..b5a60b8 100644 --- a/src/metrics/metrics_frame.c +++ b/src/metrics/metrics_frame.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "metrics.h" +#include "utils.h" #include "libft.h" /** @@ -68,7 +69,7 @@ void metrics_start_frame(t_metrics *metrics) metrics->ray.shadow_intersect_tests = 0; metrics->bvh.nodes_visited = 0; metrics->bvh.tests_skipped = 0; - timer_start(&metrics->timing.start_time); + gettimeofday(&metrics->timing.start_time, NULL); } /** diff --git a/src/utils/timer.c b/src/utils/timer.c index c67a4b7..49948df 100644 --- a/src/utils/timer.c +++ b/src/utils/timer.c @@ -10,17 +10,7 @@ /* */ /* ************************************************************************** */ -#include "metrics.h" - -/** - * @brief Store the current time in a timeval. - * - * @param tv Timeval to fill. - */ -void timer_start(struct timeval *tv) -{ - gettimeofday(tv, 0); -} +#include "utils.h" /** * @brief Compute elapsed time in microseconds since start. @@ -38,14 +28,3 @@ long timer_elapsed_us(struct timeval *start) elapsed += (now.tv_usec - start->tv_usec); return (elapsed); } - -/** - * @brief Compute elapsed time in milliseconds since start. - * - * @param start Start time. - * @return double Elapsed milliseconds. - */ -double timer_elapsed_ms(struct timeval *start) -{ - return (timer_elapsed_us(start) / 1000.0); -} From 5afe9e90e59c59f9efd3aaba51f401d9347b2469 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:36:32 +0900 Subject: [PATCH 10/15] refactor(render): inline debounce timer wrapper functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove debounce_timer_start/reset/stop — these were one-line wrappers around gettimeofday/is_active assignments - Inline timer operations directly at call sites in render_debounce.c - Use timer_elapsed_us from utils.h in debounce_timer_expired and debounce_check_preview_throttle Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/render_debounce.h | 3 -- src/render/render_debounce.c | 16 +++++--- src/render/render_debounce_timer.c | 61 +++--------------------------- 3 files changed, 15 insertions(+), 65 deletions(-) diff --git a/includes/render_debounce.h b/includes/render_debounce.h index bc8dba6..11fdcce 100644 --- a/includes/render_debounce.h +++ b/includes/render_debounce.h @@ -58,9 +58,6 @@ void debounce_on_input(t_debounce_state *state, t_render *render); void debounce_update(t_debounce_state *state, t_render *render); /* Timer utilities */ -void debounce_timer_start(t_debounce_timer *timer); -void debounce_timer_reset(t_debounce_timer *timer); -void debounce_timer_stop(t_debounce_timer *timer); int debounce_timer_expired(t_debounce_timer *timer); int debounce_check_preview_throttle(t_debounce_state *state); diff --git a/src/render/render_debounce.c b/src/render/render_debounce.c index 7642f43..99786d1 100644 --- a/src/render/render_debounce.c +++ b/src/render/render_debounce.c @@ -12,6 +12,7 @@ #include "render_debounce.h" #include "render.h" +#include void debounce_init(t_debounce_state *state) { @@ -27,16 +28,18 @@ void debounce_on_input(t_debounce_state *state, t_render *render) if (state->state == DEBOUNCE_IDLE) { state->state = DEBOUNCE_ACTIVE; - debounce_timer_start(&state->timer); + gettimeofday(&state->timer.last_input_time, NULL); + state->timer.is_active = 1; } else if (state->state == DEBOUNCE_ACTIVE) - debounce_timer_reset(&state->timer); + gettimeofday(&state->timer.last_input_time, NULL); else if (state->state == DEBOUNCE_FINAL || state->state == DEBOUNCE_COOLDOWN) { state->state = DEBOUNCE_ACTIVE; state->timer.delay_ms = DEBOUNCE_DEFAULT_DELAY_MS; - debounce_timer_start(&state->timer); + gettimeofday(&state->timer.last_input_time, NULL); + state->timer.is_active = 1; } if (debounce_check_preview_throttle(state)) { @@ -52,7 +55,7 @@ static void debounce_handle_active(t_debounce_state *state, t_render *render) state->state = DEBOUNCE_FINAL; render_clear_flag(render, RENDER_LOW_QUALITY); render_set_flag(render, RENDER_DIRTY); - debounce_timer_stop(&state->timer); + state->timer.is_active = 0; } static void debounce_handle_cooldown(t_debounce_state *state) @@ -60,7 +63,7 @@ static void debounce_handle_cooldown(t_debounce_state *state) if (!debounce_timer_expired(&state->timer)) return ; state->state = DEBOUNCE_IDLE; - debounce_timer_stop(&state->timer); + state->timer.is_active = 0; } void debounce_update(t_debounce_state *state, t_render *render) @@ -72,7 +75,8 @@ void debounce_update(t_debounce_state *state, t_render *render) { state->state = DEBOUNCE_COOLDOWN; state->timer.delay_ms = DEBOUNCE_COOLDOWN_MS; - debounce_timer_start(&state->timer); + gettimeofday(&state->timer.last_input_time, NULL); + state->timer.is_active = 1; } else if (state->state == DEBOUNCE_COOLDOWN) debounce_handle_cooldown(state); diff --git a/src/render/render_debounce_timer.c b/src/render/render_debounce_timer.c index 35c9bd1..f4a2d5e 100644 --- a/src/render/render_debounce_timer.c +++ b/src/render/render_debounce_timer.c @@ -11,73 +11,22 @@ /* ************************************************************************** */ #include "render_debounce.h" -#include +#include "utils.h" -/** - * @brief Start the debounce timer. - * - * Marks the timer active and records the current timestamp. - * - * @param timer Debounce timer to start. - */ -void debounce_timer_start(t_debounce_timer *timer) -{ - gettimeofday(&timer->last_input_time, NULL); - timer->is_active = 1; -} - -/** - * @brief Reset the debounce timer timestamp. - * - * Updates last_input_time to the current time without changing active state. - * - * @param timer Debounce timer to reset. - */ -void debounce_timer_reset(t_debounce_timer *timer) -{ - gettimeofday(&timer->last_input_time, NULL); -} - -/** - * @brief Stop the debounce timer. - * - * Marks the timer inactive so expiration checks fail until restarted. - * - * @param timer Debounce timer to stop. - */ -void debounce_timer_stop(t_debounce_timer *timer) -{ - timer->is_active = 0; -} - -/** - * @brief Check whether the debounce delay has elapsed. - * - * Computes elapsed time since last_input_time and compares it to delay_ms. - * - * @param timer Debounce timer to query. - * @return int 1 if expired, 0 otherwise. - */ int debounce_check_preview_throttle(t_debounce_state *state) { - struct timeval now; - long elapsed_ms; + long elapsed_ms; - gettimeofday(&now, NULL); - elapsed_ms = (now.tv_sec - state->last_preview_time.tv_sec) * 1000; - elapsed_ms += (now.tv_usec - state->last_preview_time.tv_usec) / 1000; + elapsed_ms = timer_elapsed_us(&state->last_preview_time) / 1000; return (elapsed_ms >= DEBOUNCE_PREVIEW_MIN_INTERVAL_MS); } int debounce_timer_expired(t_debounce_timer *timer) { - struct timeval now; - long elapsed_ms; + long elapsed_ms; if (!timer->is_active) return (0); - gettimeofday(&now, NULL); - elapsed_ms = (now.tv_sec - timer->last_input_time.tv_sec) * 1000; - elapsed_ms += (now.tv_usec - timer->last_input_time.tv_usec) / 1000; + elapsed_ms = timer_elapsed_us(&timer->last_input_time) / 1000; return (elapsed_ms >= timer->delay_ms); } From b68804e6b68837b0f209240bda1d4b68099d735d Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 20:36:56 +0900 Subject: [PATCH 11/15] refactor(headers): relocate prototypes to appropriate headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - render_scene_to_buffer, create_camera_ray, trace_ray: minirt.h → render.h (render pipeline belongs in render module) - close_window, handle_key, handle_expose: render.h/input.h → mlx_context.h (MLX event callbacks belong with MLX context) Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/input.h | 3 --- includes/minirt.h | 4 ---- includes/mlx_context.h | 5 +++++ includes/render.h | 7 ++++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/includes/input.h b/includes/input.h index 4db43f6..63a3493 100644 --- a/includes/input.h +++ b/includes/input.h @@ -130,7 +130,4 @@ void handle_object_rotate(t_render *render, int keycode); /* Rodrigues rotation */ t_vec3 rodrigues_rotate(t_vec3 v, t_vec3 k, double angle); -/* Window expose handler */ -int handle_expose(void *param); - #endif diff --git a/includes/minirt.h b/includes/minirt.h index 89b1de5..2d3428b 100644 --- a/includes/minirt.h +++ b/includes/minirt.h @@ -114,9 +114,5 @@ int object_list_init(t_object_list *list, int capacity); void object_list_destroy(t_object_list *list); int object_list_add(t_object_list *list, t_object *obj); -/* Rendering */ -void render_scene_to_buffer(t_scene *scene, t_render *render); -t_ray create_camera_ray(t_camera *camera, double x, double y); -t_color trace_ray(t_scene *scene, t_ray *ray); #endif diff --git a/includes/mlx_context.h b/includes/mlx_context.h index 952f6dd..ee1962a 100644 --- a/includes/mlx_context.h +++ b/includes/mlx_context.h @@ -51,4 +51,9 @@ void mlx_img_destroy(t_mlx_img *img, void *mlx); /* Pixel operations */ void mlx_img_put_pixel(t_mlx_img *img, int x, int y, int color); +/* MLX event callbacks (src/display/) */ +int close_window(void *param); +int handle_key(int keycode, void *param); +int handle_expose(void *param); + #endif diff --git a/includes/render.h b/includes/render.h index 82d9fe3..3e3e4fe 100644 --- a/includes/render.h +++ b/includes/render.h @@ -97,9 +97,10 @@ int render_has_flag(t_render *render, int flag); void render_set_flag(t_render *render, int flag); void render_clear_flag(t_render *render, int flag); -/* Window event handlers */ -int close_window(void *param); -int handle_key(int keycode, void *param); +/* Render pipeline */ +void render_scene_to_buffer(t_scene *scene, t_render *render); +t_ray create_camera_ray(t_camera *camera, double x, double y); +t_color trace_ray(t_scene *scene, t_ray *ray); int render_loop(void *param); #endif From c825fd63f7c9c17a1568c5038257867db5308817 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 21:28:30 +0900 Subject: [PATCH 12/15] rename(scene): rename minirt.h to scene.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The header defines scene, camera, light, and object types — scene.h better reflects its actual content. Update all 40 source files that included minirt.h. Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/hud_internal.h | 2 +- includes/parser.h | 2 +- includes/render.h | 2 +- includes/{minirt.h => scene.h} | 7 +++---- includes/shading.h | 2 +- src/bvh_debug/bvhd_format.c | 2 +- src/bvh_debug/bvhd_node.c | 2 +- src/input/input_camera.c | 2 +- src/input/input_dispatch.c | 2 +- src/input/input_objects.c | 2 +- src/input/input_resize.c | 2 +- src/input/input_rotate.c | 2 +- src/intersect/intersect_cone_body.c | 2 +- src/intersect/intersect_cone_cap.c | 2 +- src/intersect/intersect_cylinder.c | 2 +- src/intersect/intersect_object.c | 2 +- src/main.c | 2 +- src/parser/parse_cone.c | 2 +- src/parser/parse_cylinder.c | 2 +- src/parser/parse_elements.c | 2 +- src/parser/parse_objects.c | 2 +- src/parser/parse_validation_strict.c | 2 +- src/parser/parse_vector_validation.c | 2 +- src/parser/parser.c | 2 +- src/parser/parser_dispatch.c | 2 +- src/parser/parser_utils.c | 2 +- src/render/render.c | 2 +- src/render/render_camera.c | 2 +- src/render/render_init.c | 2 +- src/render/render_loop.c | 2 +- src/render/render_trace.c | 2 +- src/scene/object_list.c | 2 +- src/scene/scene.c | 2 +- src/shading/shading_utils.c | 2 +- src/shadow/shadow_calc.c | 2 +- src/shadow/shadow_test.c | 2 +- src/spatial/aabb_bounds.c | 2 +- src/spatial/bvh_any_hit.c | 2 +- src/spatial/bvh_init.c | 2 +- src/spatial/bvh_traverse.c | 2 +- src/texture/bump_map_load.c | 2 +- 41 files changed, 43 insertions(+), 44 deletions(-) rename includes/{minirt.h => scene.h} (96%) diff --git a/includes/hud_internal.h b/includes/hud_internal.h index 915f454..3b3bb03 100644 --- a/includes/hud_internal.h +++ b/includes/hud_internal.h @@ -13,7 +13,7 @@ #ifndef HUD_INTERNAL_H # define HUD_INTERNAL_H -# include "minirt.h" +# include "scene.h" /* HUD text utilities */ void hud_mark_dirty(t_render *render); diff --git a/includes/parser.h b/includes/parser.h index 939f9a7..708020b 100644 --- a/includes/parser.h +++ b/includes/parser.h @@ -13,7 +13,7 @@ #ifndef PARSER_H # define PARSER_H -# include "minirt.h" +# include "scene.h" /* Constants */ diff --git a/includes/render.h b/includes/render.h index 3e3e4fe..7bf8d73 100644 --- a/includes/render.h +++ b/includes/render.h @@ -13,7 +13,7 @@ #ifndef RENDER_H # define RENDER_H -# include "minirt.h" +# include "scene.h" # include "mlx.h" # include "mlx_context.h" # include "render_debounce.h" diff --git a/includes/minirt.h b/includes/scene.h similarity index 96% rename from includes/minirt.h rename to includes/scene.h index 2d3428b..314ee73 100644 --- a/includes/minirt.h +++ b/includes/scene.h @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* minirt.h :+: :+: :+: */ +/* scene.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#ifndef MINIRT_H -# define MINIRT_H +#ifndef SCENE_H +# define SCENE_H # include # include @@ -114,5 +114,4 @@ int object_list_init(t_object_list *list, int capacity); void object_list_destroy(t_object_list *list); int object_list_add(t_object_list *list, t_object *obj); - #endif diff --git a/includes/shading.h b/includes/shading.h index 229d4e8..20c7bf6 100644 --- a/includes/shading.h +++ b/includes/shading.h @@ -13,7 +13,7 @@ #ifndef SHADING_H # define SHADING_H -# include "minirt.h" +# include "scene.h" # include "ray.h" /* Floating point color for intermediate calculations (0.0 - 1.0+) */ diff --git a/src/bvh_debug/bvhd_format.c b/src/bvh_debug/bvhd_format.c index 9b8b139..e4cc983 100644 --- a/src/bvh_debug/bvhd_format.c +++ b/src/bvh_debug/bvhd_format.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "bvh_debug.h" -#include "minirt.h" +#include "scene.h" #include /** diff --git a/src/bvh_debug/bvhd_node.c b/src/bvh_debug/bvhd_node.c index 9619391..c7cf034 100644 --- a/src/bvh_debug/bvhd_node.c +++ b/src/bvh_debug/bvhd_node.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "bvh_debug.h" -#include "minirt.h" +#include "scene.h" #include "utils.h" #include diff --git a/src/input/input_camera.c b/src/input/input_camera.c index 44354be..76f959e 100644 --- a/src/input/input_camera.c +++ b/src/input/input_camera.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" #include diff --git a/src/input/input_dispatch.c b/src/input/input_dispatch.c index 486467b..6f82a04 100644 --- a/src/input/input_dispatch.c +++ b/src/input/input_dispatch.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" #include "hud.h" diff --git a/src/input/input_objects.c b/src/input/input_objects.c index d30a55a..3d4da56 100644 --- a/src/input/input_objects.c +++ b/src/input/input_objects.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" diff --git a/src/input/input_resize.c b/src/input/input_resize.c index f7eed34..c4e8e23 100644 --- a/src/input/input_resize.c +++ b/src/input/input_resize.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" diff --git a/src/input/input_rotate.c b/src/input/input_rotate.c index a2950ef..6b20f0e 100644 --- a/src/input/input_rotate.c +++ b/src/input/input_rotate.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" #include diff --git a/src/intersect/intersect_cone_body.c b/src/intersect/intersect_cone_body.c index c4f45be..a9be342 100644 --- a/src/intersect/intersect_cone_body.c +++ b/src/intersect/intersect_cone_body.c @@ -12,7 +12,7 @@ #include "intersect.h" #include "vec3.h" -#include "minirt.h" +#include "scene.h" #include static int calc_cone_intersect(t_ray *ray, t_cone_data *c, t_cyl_calc *calc) diff --git a/src/intersect/intersect_cone_cap.c b/src/intersect/intersect_cone_cap.c index 86d9fff..6c6b96a 100644 --- a/src/intersect/intersect_cone_cap.c +++ b/src/intersect/intersect_cone_cap.c @@ -12,7 +12,7 @@ #include "intersect.h" #include "vec3.h" -#include "minirt.h" +#include "scene.h" #include static int intersect_cone_cap(t_ray *ray, t_cone_data *c, t_hit *hit) diff --git a/src/intersect/intersect_cylinder.c b/src/intersect/intersect_cylinder.c index 5c022b8..a60d1e0 100644 --- a/src/intersect/intersect_cylinder.c +++ b/src/intersect/intersect_cylinder.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "intersect.h" #include "vec3.h" #include diff --git a/src/intersect/intersect_object.c b/src/intersect/intersect_object.c index 7d1a94c..cc90bb9 100644 --- a/src/intersect/intersect_object.c +++ b/src/intersect/intersect_object.c @@ -12,7 +12,7 @@ #include "intersect.h" #include "vec3.h" -#include "minirt.h" +#include "scene.h" #include /** diff --git a/src/main.c b/src/main.c index 0ccc96d..b01c378 100644 --- a/src/main.c +++ b/src/main.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" #include "render.h" #include "spatial.h" diff --git a/src/parser/parse_cone.c b/src/parser/parse_cone.c index c210fb6..14cf1e2 100644 --- a/src/parser/parse_cone.c +++ b/src/parser/parse_cone.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" #include "vec3.h" #include "utils.h" diff --git a/src/parser/parse_cylinder.c b/src/parser/parse_cylinder.c index 1d52125..27f38e0 100644 --- a/src/parser/parse_cylinder.c +++ b/src/parser/parse_cylinder.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" #include "vec3.h" #include "utils.h" diff --git a/src/parser/parse_elements.c b/src/parser/parse_elements.c index e60b65b..6ca59b5 100644 --- a/src/parser/parse_elements.c +++ b/src/parser/parse_elements.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" #include "vec3.h" #include "error.h" diff --git a/src/parser/parse_objects.c b/src/parser/parse_objects.c index 2666e9e..2f6135d 100644 --- a/src/parser/parse_objects.c +++ b/src/parser/parse_objects.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" #include "vec3.h" #include "utils.h" diff --git a/src/parser/parse_validation_strict.c b/src/parser/parse_validation_strict.c index 92577b7..e1fb1d4 100644 --- a/src/parser/parse_validation_strict.c +++ b/src/parser/parse_validation_strict.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" #include "vec3.h" diff --git a/src/parser/parse_vector_validation.c b/src/parser/parse_vector_validation.c index 6f7a655..274a89e 100644 --- a/src/parser/parse_vector_validation.c +++ b/src/parser/parse_vector_validation.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" /** diff --git a/src/parser/parser.c b/src/parser/parser.c index cd684a5..1704a95 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" #include "error.h" #include diff --git a/src/parser/parser_dispatch.c b/src/parser/parser_dispatch.c index a27c629..0b03275 100644 --- a/src/parser/parser_dispatch.c +++ b/src/parser/parser_dispatch.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" /** diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c index 660c88f..8e90303 100644 --- a/src/parser/parser_utils.c +++ b/src/parser/parser_utils.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "parser.h" const char *skip_whitespace(const char *str) diff --git a/src/render/render.c b/src/render/render.c index 6bd168b..eb10d9d 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "ray.h" #include "render.h" #include "metrics.h" diff --git a/src/render/render_camera.c b/src/render/render_camera.c index c1abfb9..c0c8ca4 100644 --- a/src/render/render_camera.c +++ b/src/render/render_camera.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "vec3.h" #include "ray.h" diff --git a/src/render/render_init.c b/src/render/render_init.c index 0e87c81..2f6b25f 100644 --- a/src/render/render_init.c +++ b/src/render/render_init.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" #include "hud.h" diff --git a/src/render/render_loop.c b/src/render/render_loop.c index e1ee67b..3a4d987 100644 --- a/src/render/render_loop.c +++ b/src/render/render_loop.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" #include "hud.h" diff --git a/src/render/render_trace.c b/src/render/render_trace.c index f666be4..12bc024 100644 --- a/src/render/render_trace.c +++ b/src/render/render_trace.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "shading.h" #include "intersect.h" #include "spatial.h" diff --git a/src/scene/object_list.c b/src/scene/object_list.c index 3e3f0b5..e1801ad 100644 --- a/src/scene/object_list.c +++ b/src/scene/object_list.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include #include diff --git a/src/scene/scene.c b/src/scene/scene.c index 8a3c2f8..cb255b7 100644 --- a/src/scene/scene.c +++ b/src/scene/scene.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "spatial.h" #include diff --git a/src/shading/shading_utils.c b/src/shading/shading_utils.c index 155af87..7a24205 100644 --- a/src/shading/shading_utils.c +++ b/src/shading/shading_utils.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" /** * @brief Clamp RGB color components into the valid 0–255 range. diff --git a/src/shadow/shadow_calc.c b/src/shadow/shadow_calc.c index 9b0e0be..c34a528 100644 --- a/src/shadow/shadow_calc.c +++ b/src/shadow/shadow_calc.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "shadow.h" -#include "minirt.h" +#include "scene.h" #include "vec3.h" #include diff --git a/src/shadow/shadow_test.c b/src/shadow/shadow_test.c index f3cabd3..c5228bc 100644 --- a/src/shadow/shadow_test.c +++ b/src/shadow/shadow_test.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "shadow.h" -#include "minirt.h" +#include "scene.h" #include "vec3.h" #include "intersect.h" #include "metrics.h" diff --git a/src/spatial/aabb_bounds.c b/src/spatial/aabb_bounds.c index 2ab30b1..a46cbc0 100644 --- a/src/spatial/aabb_bounds.c +++ b/src/spatial/aabb_bounds.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "spatial.h" -#include "minirt.h" +#include "scene.h" #include /** diff --git a/src/spatial/bvh_any_hit.c b/src/spatial/bvh_any_hit.c index 4464df4..99c3dda 100644 --- a/src/spatial/bvh_any_hit.c +++ b/src/spatial/bvh_any_hit.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "spatial.h" -#include "minirt.h" +#include "scene.h" #include "intersect.h" #include "metrics.h" diff --git a/src/spatial/bvh_init.c b/src/spatial/bvh_init.c index 54a867f..a869b62 100644 --- a/src/spatial/bvh_init.c +++ b/src/spatial/bvh_init.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "spatial.h" -#include "minirt.h" +#include "scene.h" #include /** diff --git a/src/spatial/bvh_traverse.c b/src/spatial/bvh_traverse.c index ffe8faa..9be7458 100644 --- a/src/spatial/bvh_traverse.c +++ b/src/spatial/bvh_traverse.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "spatial.h" -#include "minirt.h" +#include "scene.h" #include "intersect.h" #include "metrics.h" diff --git a/src/texture/bump_map_load.c b/src/texture/bump_map_load.c index 2949b3b..b03f608 100644 --- a/src/texture/bump_map_load.c +++ b/src/texture/bump_map_load.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "texture.h" -#include "minirt.h" +#include "scene.h" #include "error.h" #include "mlx.h" #include From df33fcafe0482eb7f1c4517f79105a92ab518564 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 21:28:58 +0900 Subject: [PATCH 13/15] rename(display): rename mlx_context.h to display.h Align header name with its module directory (src/display/). Update include guard and all source files. Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/{mlx_context.h => display.h} | 6 +++--- includes/render.h | 2 +- src/display/display_destroy.c | 2 +- src/display/display_events.c | 2 +- src/display/display_init.c | 2 +- src/display/display_pixel.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename includes/{mlx_context.h => display.h} (94%) diff --git a/includes/mlx_context.h b/includes/display.h similarity index 94% rename from includes/mlx_context.h rename to includes/display.h index ee1962a..c0f488c 100644 --- a/includes/mlx_context.h +++ b/includes/display.h @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* mlx_context.h :+: :+: :+: */ +/* display.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yoshin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#ifndef MLX_CONTEXT_H -# define MLX_CONTEXT_H +#ifndef DISPLAY_H +# define DISPLAY_H /** * @brief MLX image data structure diff --git a/includes/render.h b/includes/render.h index 7bf8d73..52e3f38 100644 --- a/includes/render.h +++ b/includes/render.h @@ -15,7 +15,7 @@ # include "scene.h" # include "mlx.h" -# include "mlx_context.h" +# include "display.h" # include "render_debounce.h" /* Window resolution constants */ diff --git a/src/display/display_destroy.c b/src/display/display_destroy.c index 0cf1e02..a656e79 100644 --- a/src/display/display_destroy.c +++ b/src/display/display_destroy.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "mlx_context.h" +#include "display.h" #include "mlx.h" #include diff --git a/src/display/display_events.c b/src/display/display_events.c index 22645ad..0200e2a 100644 --- a/src/display/display_events.c +++ b/src/display/display_events.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "minirt.h" +#include "scene.h" #include "render.h" #include "input.h" #include "hud.h" diff --git a/src/display/display_init.c b/src/display/display_init.c index aa14392..bad9916 100644 --- a/src/display/display_init.c +++ b/src/display/display_init.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "mlx_context.h" +#include "display.h" #include "mlx.h" #include "libft.h" diff --git a/src/display/display_pixel.c b/src/display/display_pixel.c index 3284a7a..48b152a 100644 --- a/src/display/display_pixel.c +++ b/src/display/display_pixel.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "mlx_context.h" +#include "display.h" static void encode_pixel_bytes(char *dst, int color) { From 60a3ed2305bf423446d249c4d19aa9dccdc04947 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 21:29:09 +0900 Subject: [PATCH 14/15] rename(hud): rename ft_strcpy/ft_itoa_buf to hud_strcpy/hud_itoa_buf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are HUD-specific format helpers, not libft extensions — use the hud_ prefix. Move declarations from hud.h (public) to hud_internal.h (module-internal only). Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/hud.h | 6 ------ includes/hud_internal.h | 4 ++++ src/hud/hud_format.c | 23 ++++++++++++----------- src/hud/hud_format_helpers.c | 4 ++-- src/hud/hud_objects.c | 4 ++-- src/hud/hud_scene.c | 4 ++-- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/includes/hud.h b/includes/hud.h index 03f9a5b..582ddaa 100644 --- a/includes/hud.h +++ b/includes/hud.h @@ -175,12 +175,6 @@ void hud_get_selection_from_global(t_selection *sel, int idx, */ void hud_format_float(char *buffer, double value); -/* -** Internal helper functions for formatting (implemented using libft) -*/ -void ft_strcpy(char *dst, const char *src); -void ft_itoa_buf(char *buf, int n); - /* ** Format vec3 to string "(x, y, z)" with 2 decimal places. ** Example: {1.5, 2.3, 3.7} -> "(1.50, 2.30, 3.70)" diff --git a/includes/hud_internal.h b/includes/hud_internal.h index 3b3bb03..86a139c 100644 --- a/includes/hud_internal.h +++ b/includes/hud_internal.h @@ -33,4 +33,8 @@ void hud_render_light_bright(t_render *render, int *y); void hud_render_objects(t_render *render, int *y); void hud_render_object_entry(t_render *render, int idx, int *y, int color); +/* HUD format helpers */ +void hud_strcpy(char *dst, const char *src); +void hud_itoa_buf(char *buf, int n); + #endif diff --git a/src/hud/hud_format.c b/src/hud/hud_format.c index a6b646a..f9ecda0 100644 --- a/src/hud/hud_format.c +++ b/src/hud/hud_format.c @@ -11,12 +11,13 @@ /* ************************************************************************** */ #include "hud.h" +#include "hud_internal.h" static int hud_float_start(char *buffer, double *value) { if (*value != *value || *value > 1e15 || *value < -1e15) { - ft_strcpy(buffer, "---"); + hud_strcpy(buffer, "---"); return (-1); } if (*value < 0) @@ -49,13 +50,13 @@ void hud_format_float(char *buffer, double value) value = 999999.0; int_part = (int)value; frac_part = (int)((value - int_part) * 100 + 0.5); - ft_itoa_buf(buffer + i, int_part); + hud_itoa_buf(buffer + i, int_part); while (buffer[i]) i++; buffer[i++] = '.'; if (frac_part < 10) buffer[i++] = '0'; - ft_itoa_buf(buffer + i, frac_part); + hud_itoa_buf(buffer + i, frac_part); } /** @@ -73,12 +74,12 @@ void hud_format_vec3(char *buffer, t_vec3 vec) hud_format_float(buffer + i, vec.x); while (buffer[i]) i++; - ft_strcpy(buffer + i, ", "); + hud_strcpy(buffer + i, ", "); i += 2; hud_format_float(buffer + i, vec.y); while (buffer[i]) i++; - ft_strcpy(buffer + i, ", "); + hud_strcpy(buffer + i, ", "); i += 2; hud_format_float(buffer + i, vec.z); while (buffer[i]) @@ -97,17 +98,17 @@ void hud_format_color(char *buffer, t_color color) { int i; - ft_strcpy(buffer, "R:"); + hud_strcpy(buffer, "R:"); i = 2; - ft_itoa_buf(buffer + i, color.r); + hud_itoa_buf(buffer + i, color.r); while (buffer[i]) i++; - ft_strcpy(buffer + i, " G:"); + hud_strcpy(buffer + i, " G:"); i += 3; - ft_itoa_buf(buffer + i, color.g); + hud_itoa_buf(buffer + i, color.g); while (buffer[i]) i++; - ft_strcpy(buffer + i, " B:"); + hud_strcpy(buffer + i, " B:"); i += 3; - ft_itoa_buf(buffer + i, color.b); + hud_itoa_buf(buffer + i, color.b); } diff --git a/src/hud/hud_format_helpers.c b/src/hud/hud_format_helpers.c index 80e84e0..8ad0a3a 100644 --- a/src/hud/hud_format_helpers.c +++ b/src/hud/hud_format_helpers.c @@ -22,7 +22,7 @@ * @param dst Destination buffer. * @param src Source string. */ -void ft_strcpy(char *dst, const char *src) +void hud_strcpy(char *dst, const char *src) { ft_strlcpy(dst, src, ft_strlen(src) + 1); } @@ -35,7 +35,7 @@ void ft_strcpy(char *dst, const char *src) * @param buf Destination buffer. * @param n Integer to format. */ -void ft_itoa_buf(char *buf, int n) +void hud_itoa_buf(char *buf, int n) { char *str; diff --git a/src/hud/hud_objects.c b/src/hud/hud_objects.c index 1e60bad..be83531 100644 --- a/src/hud/hud_objects.c +++ b/src/hud/hud_objects.c @@ -31,11 +31,11 @@ static void render_object_header(t_render *render, int *y) buf[len++] = '-'; buf[len++] = ' '; len += hud_append(buf + len, "Objects (Page ", 64 - len); - ft_itoa_buf(buf + len, render->hud.current_page + 1); + hud_itoa_buf(buf + len, render->hud.current_page + 1); while (buf[len]) len++; buf[len++] = '/'; - ft_itoa_buf(buf + len, render->hud.total_pages); + hud_itoa_buf(buf + len, render->hud.total_pages); while (buf[len]) len++; len += hud_append(buf + len, ") ---", 64 - len); diff --git a/src/hud/hud_scene.c b/src/hud/hud_scene.c index 62a4ff7..55d1d5c 100644 --- a/src/hud/hud_scene.c +++ b/src/hud/hud_scene.c @@ -100,11 +100,11 @@ void hud_render_light(t_render *render, int *y) return ; i = 0; buf[i++] = 'L'; - ft_itoa_buf(buf + i, render->scene->selected_light + 1); + hud_itoa_buf(buf + i, render->scene->selected_light + 1); while (buf[i]) i++; buf[i++] = '/'; - ft_itoa_buf(buf + i, render->scene->light_count); + hud_itoa_buf(buf + i, render->scene->light_count); while (buf[i]) i++; buf[i++] = ':'; From 16cfd217a40ce9bc963ee7c91b1e75c3248015c8 Mon Sep 17 00:00:00 2001 From: yoshin Date: Fri, 27 Mar 2026 21:52:31 +0900 Subject: [PATCH 15/15] refactor(headers): minimize include dependencies across modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scene.h: remove transitive includes (libft.h, error.h, ray.h, unistd.h, fcntl.h, stdbool.h) — consumers include what they need - display.h: add mlx.h include (was duplicated in each display/*.c) - render.h: replace mlx.h with ray.h (mlx.h now comes via display.h) - hud_internal.h: replace scene.h with vec3.h + forward declaration of t_render to reduce coupling - Remove redundant includes from 50 source files (scene.h, render.h, mlx.h where already provided transitively by module headers) - Add explicit libft.h/error.h where needed after scene.h cleanup Co-Authored-By: Claude Opus 4.6 (1M context) --- includes/display.h | 2 ++ includes/hud_internal.h | 4 +++- includes/render.h | 2 +- includes/scene.h | 6 ------ src/bvh_debug/bvhd_format.c | 1 + src/bvh_debug/bvhd_node.c | 1 + src/display/display_destroy.c | 1 - src/display/display_events.c | 2 -- src/display/display_init.c | 1 - src/hud/hud_navigation.c | 1 - src/hud/hud_obj_render.c | 1 - src/hud/hud_objects.c | 1 - src/hud/hud_render.c | 1 - src/hud/hud_scene.c | 2 +- src/hud/hud_text.c | 1 - src/hud/hud_toggle.c | 1 - src/input/input_camera.c | 1 - src/input/input_dispatch.c | 1 - src/input/input_key_binds.c | 1 - src/input/input_key_binds_extra.c | 1 - src/input/input_objects.c | 1 - src/input/input_resize.c | 1 - src/input/input_rotate.c | 1 - src/intersect/intersect_cone_body.c | 1 - src/intersect/intersect_cone_cap.c | 1 - src/intersect/intersect_cylinder.c | 1 - src/intersect/intersect_object.c | 1 - src/keyguide/keyguide_init.c | 1 - src/keyguide/keyguide_render.c | 1 - src/main.c | 1 + src/parser/parse_bonus_options.c | 2 ++ src/parser/parse_cone.c | 4 ++-- src/parser/parse_cylinder.c | 4 ++-- src/parser/parse_elements.c | 2 -- src/parser/parse_line_reader.c | 2 ++ src/parser/parse_number.c | 1 + src/parser/parse_objects.c | 4 ++-- src/parser/parse_validation_strict.c | 3 +-- src/parser/parse_vector_validation.c | 2 +- src/parser/parser.c | 1 - src/parser/parser_dispatch.c | 2 +- src/parser/parser_utils.c | 1 - src/render/render.c | 3 +-- src/render/render_camera.c | 4 +--- src/render/render_init.c | 1 - src/render/render_loop.c | 1 - src/render/render_trace.c | 1 - src/scene/object_list.c | 1 + src/scene/scene.c | 1 + src/shading/shading.c | 1 - src/shadow/shadow_calc.c | 1 - src/shadow/shadow_test.c | 1 - src/texture/bump_map_perturb.c | 1 - src/texture/checkerboard.c | 1 - 54 files changed, 28 insertions(+), 59 deletions(-) diff --git a/includes/display.h b/includes/display.h index c0f488c..fbe5dd6 100644 --- a/includes/display.h +++ b/includes/display.h @@ -13,6 +13,8 @@ #ifndef DISPLAY_H # define DISPLAY_H +# include "mlx.h" + /** * @brief MLX image data structure * diff --git a/includes/hud_internal.h b/includes/hud_internal.h index 86a139c..e8c36c5 100644 --- a/includes/hud_internal.h +++ b/includes/hud_internal.h @@ -13,7 +13,9 @@ #ifndef HUD_INTERNAL_H # define HUD_INTERNAL_H -# include "scene.h" +# include "vec3.h" + +typedef struct s_render t_render; /* HUD text utilities */ void hud_mark_dirty(t_render *render); diff --git a/includes/render.h b/includes/render.h index 52e3f38..446bd6c 100644 --- a/includes/render.h +++ b/includes/render.h @@ -14,7 +14,7 @@ # define RENDER_H # include "scene.h" -# include "mlx.h" +# include "ray.h" # include "display.h" # include "render_debounce.h" diff --git a/includes/scene.h b/includes/scene.h index 314ee73..788bc4f 100644 --- a/includes/scene.h +++ b/includes/scene.h @@ -13,14 +13,8 @@ #ifndef SCENE_H # define SCENE_H -# include -# include -# include -# include "libft.h" -# include "error.h" # include "vec3.h" # include "objects.h" -# include "ray.h" # include "shadow.h" # include "metrics.h" diff --git a/src/bvh_debug/bvhd_format.c b/src/bvh_debug/bvhd_format.c index e4cc983..63723f6 100644 --- a/src/bvh_debug/bvhd_format.c +++ b/src/bvh_debug/bvhd_format.c @@ -13,6 +13,7 @@ #include "bvh_debug.h" #include "scene.h" #include +#include "libft.h" /** * @brief Format a list of object IDs into a buffer. diff --git a/src/bvh_debug/bvhd_node.c b/src/bvh_debug/bvhd_node.c index c7cf034..b80ddad 100644 --- a/src/bvh_debug/bvhd_node.c +++ b/src/bvh_debug/bvhd_node.c @@ -14,6 +14,7 @@ #include "scene.h" #include "utils.h" #include +#include "libft.h" /** * @brief Check whether a BVH node is a leaf. diff --git a/src/display/display_destroy.c b/src/display/display_destroy.c index a656e79..48664f0 100644 --- a/src/display/display_destroy.c +++ b/src/display/display_destroy.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "display.h" -#include "mlx.h" #include /** diff --git a/src/display/display_events.c b/src/display/display_events.c index 0200e2a..8929476 100644 --- a/src/display/display_events.c +++ b/src/display/display_events.c @@ -10,8 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" -#include "render.h" #include "input.h" #include "hud.h" #include "keyguide.h" diff --git a/src/display/display_init.c b/src/display/display_init.c index bad9916..c966418 100644 --- a/src/display/display_init.c +++ b/src/display/display_init.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "display.h" -#include "mlx.h" #include "libft.h" /** diff --git a/src/hud/hud_navigation.c b/src/hud/hud_navigation.c index 5ad1447..d895213 100644 --- a/src/hud/hud_navigation.c +++ b/src/hud/hud_navigation.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "hud.h" /** diff --git a/src/hud/hud_obj_render.c b/src/hud/hud_obj_render.c index 752039c..aec4e26 100644 --- a/src/hud/hud_obj_render.c +++ b/src/hud/hud_obj_render.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "hud.h" #include "hud_internal.h" diff --git a/src/hud/hud_objects.c b/src/hud/hud_objects.c index be83531..b4aa1b4 100644 --- a/src/hud/hud_objects.c +++ b/src/hud/hud_objects.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "hud.h" #include "hud_internal.h" diff --git a/src/hud/hud_render.c b/src/hud/hud_render.c index 04387fa..2676439 100644 --- a/src/hud/hud_render.c +++ b/src/hud/hud_render.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "hud.h" #include "hud_internal.h" diff --git a/src/hud/hud_scene.c b/src/hud/hud_scene.c index 55d1d5c..65c2b13 100644 --- a/src/hud/hud_scene.c +++ b/src/hud/hud_scene.c @@ -10,9 +10,9 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "hud.h" #include "hud_internal.h" +#include "libft.h" /** * @brief Render camera section in the HUD. diff --git a/src/hud/hud_text.c b/src/hud/hud_text.c index e00362c..b56aa05 100644 --- a/src/hud/hud_text.c +++ b/src/hud/hud_text.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "hud.h" void hud_mark_dirty(t_render *render) diff --git a/src/hud/hud_toggle.c b/src/hud/hud_toggle.c index d80534b..7450526 100644 --- a/src/hud/hud_toggle.c +++ b/src/hud/hud_toggle.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "hud.h" /** diff --git a/src/input/input_camera.c b/src/input/input_camera.c index 76f959e..44c5a32 100644 --- a/src/input/input_camera.c +++ b/src/input/input_camera.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" #include "input.h" #include diff --git a/src/input/input_dispatch.c b/src/input/input_dispatch.c index 6f82a04..1ff32ab 100644 --- a/src/input/input_dispatch.c +++ b/src/input/input_dispatch.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" #include "input.h" #include "hud.h" diff --git a/src/input/input_key_binds.c b/src/input/input_key_binds.c index 7cbdd3f..1373c37 100644 --- a/src/input/input_key_binds.c +++ b/src/input/input_key_binds.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "input.h" static void bind_key(t_key_binds *binds, int keycode, t_key_handler handler) diff --git a/src/input/input_key_binds_extra.c b/src/input/input_key_binds_extra.c index f123998..1b9d017 100644 --- a/src/input/input_key_binds_extra.c +++ b/src/input/input_key_binds_extra.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "render.h" #include "input.h" static void bind_key(t_key_binds *binds, int keycode, t_key_handler handler) diff --git a/src/input/input_objects.c b/src/input/input_objects.c index 3d4da56..014e4d3 100644 --- a/src/input/input_objects.c +++ b/src/input/input_objects.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" #include "input.h" diff --git a/src/input/input_resize.c b/src/input/input_resize.c index c4e8e23..254eeb4 100644 --- a/src/input/input_resize.c +++ b/src/input/input_resize.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" #include "input.h" diff --git a/src/input/input_rotate.c b/src/input/input_rotate.c index 6b20f0e..05c3c9a 100644 --- a/src/input/input_rotate.c +++ b/src/input/input_rotate.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" #include "input.h" #include diff --git a/src/intersect/intersect_cone_body.c b/src/intersect/intersect_cone_body.c index a9be342..7153555 100644 --- a/src/intersect/intersect_cone_body.c +++ b/src/intersect/intersect_cone_body.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "intersect.h" -#include "vec3.h" #include "scene.h" #include diff --git a/src/intersect/intersect_cone_cap.c b/src/intersect/intersect_cone_cap.c index 6c6b96a..26b4d8b 100644 --- a/src/intersect/intersect_cone_cap.c +++ b/src/intersect/intersect_cone_cap.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "intersect.h" -#include "vec3.h" #include "scene.h" #include diff --git a/src/intersect/intersect_cylinder.c b/src/intersect/intersect_cylinder.c index a60d1e0..84af0ed 100644 --- a/src/intersect/intersect_cylinder.c +++ b/src/intersect/intersect_cylinder.c @@ -12,7 +12,6 @@ #include "scene.h" #include "intersect.h" -#include "vec3.h" #include /** diff --git a/src/intersect/intersect_object.c b/src/intersect/intersect_object.c index cc90bb9..14a7e9e 100644 --- a/src/intersect/intersect_object.c +++ b/src/intersect/intersect_object.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "intersect.h" -#include "vec3.h" #include "scene.h" #include diff --git a/src/keyguide/keyguide_init.c b/src/keyguide/keyguide_init.c index ddc26bb..e3b0ee2 100644 --- a/src/keyguide/keyguide_init.c +++ b/src/keyguide/keyguide_init.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "keyguide.h" -#include "render.h" /** * @brief Initialize the key guide overlay state. diff --git a/src/keyguide/keyguide_render.c b/src/keyguide/keyguide_render.c index ce27b12..da82a3a 100644 --- a/src/keyguide/keyguide_render.c +++ b/src/keyguide/keyguide_render.c @@ -12,7 +12,6 @@ #include "keyguide.h" #include "hud.h" -#include "render.h" /** * @brief Render the camera controls section in the key guide. diff --git a/src/main.c b/src/main.c index b01c378..951bf10 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,7 @@ #include #include #include +#include "error.h" /** * @brief Parse CLI arguments and extract options/scene filename. diff --git a/src/parser/parse_bonus_options.c b/src/parser/parse_bonus_options.c index 85c880e..433b5a4 100644 --- a/src/parser/parse_bonus_options.c +++ b/src/parser/parse_bonus_options.c @@ -12,6 +12,8 @@ #include "parser.h" #include +#include "libft.h" +#include "error.h" static int starts_with(const char *str, const char *prefix) { diff --git a/src/parser/parse_cone.c b/src/parser/parse_cone.c index 14cf1e2..f84dc1b 100644 --- a/src/parser/parse_cone.c +++ b/src/parser/parse_cone.c @@ -10,11 +10,11 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" -#include "vec3.h" #include "utils.h" #include +#include "libft.h" +#include "error.h" static t_parse_result parse_cone_dims(const char **token, t_object *obj) { diff --git a/src/parser/parse_cylinder.c b/src/parser/parse_cylinder.c index 27f38e0..f6af7a0 100644 --- a/src/parser/parse_cylinder.c +++ b/src/parser/parse_cylinder.c @@ -10,11 +10,11 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" -#include "vec3.h" #include "utils.h" #include +#include "libft.h" +#include "error.h" /** * @brief Parse cylinder diameter and height from tokens. diff --git a/src/parser/parse_elements.c b/src/parser/parse_elements.c index 6ca59b5..5131747 100644 --- a/src/parser/parse_elements.c +++ b/src/parser/parse_elements.c @@ -10,9 +10,7 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" -#include "vec3.h" #include "error.h" #include diff --git a/src/parser/parse_line_reader.c b/src/parser/parse_line_reader.c index 4d3a90d..f2e5af7 100644 --- a/src/parser/parse_line_reader.c +++ b/src/parser/parse_line_reader.c @@ -13,6 +13,8 @@ #include "parser.h" #include #include +#include "libft.h" +#include "error.h" /** * @brief Refill the read buffer from file. diff --git a/src/parser/parse_number.c b/src/parser/parse_number.c index ac2b2f0..f0e133a 100644 --- a/src/parser/parse_number.c +++ b/src/parser/parse_number.c @@ -14,6 +14,7 @@ #include "libft.h" #include #include +#include "error.h" double parse_int_part(const char **str, int *has_digits) { diff --git a/src/parser/parse_objects.c b/src/parser/parse_objects.c index 2f6135d..324ede9 100644 --- a/src/parser/parse_objects.c +++ b/src/parser/parse_objects.c @@ -10,11 +10,11 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" -#include "vec3.h" #include "utils.h" #include +#include "libft.h" +#include "error.h" /** * @brief Count objects of a specific type in the scene. diff --git a/src/parser/parse_validation_strict.c b/src/parser/parse_validation_strict.c index e1fb1d4..dc1055e 100644 --- a/src/parser/parse_validation_strict.c +++ b/src/parser/parse_validation_strict.c @@ -10,9 +10,8 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" -#include "vec3.h" +#include "error.h" int in_range(double value, double min, double max) { diff --git a/src/parser/parse_vector_validation.c b/src/parser/parse_vector_validation.c index 274a89e..154d598 100644 --- a/src/parser/parse_vector_validation.c +++ b/src/parser/parse_vector_validation.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" +#include "error.h" /** * @brief Validate vector components are in range [-1,1]. diff --git a/src/parser/parser.c b/src/parser/parser.c index 1704a95..8666361 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" #include "error.h" #include diff --git a/src/parser/parser_dispatch.c b/src/parser/parser_dispatch.c index 0b03275..44fbd42 100644 --- a/src/parser/parser_dispatch.c +++ b/src/parser/parser_dispatch.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" +#include "error.h" /** * @brief Check if line matches element prefix. diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c index 8e90303..1ea0147 100644 --- a/src/parser/parser_utils.c +++ b/src/parser/parser_utils.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "parser.h" const char *skip_whitespace(const char *str) diff --git a/src/render/render.c b/src/render/render.c index eb10d9d..67b64c3 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -10,10 +10,9 @@ /* */ /* ************************************************************************** */ -#include "scene.h" -#include "ray.h" #include "render.h" #include "metrics.h" +#include "ray.h" /** * @brief Write a single pixel color into the MLX image buffer. diff --git a/src/render/render_camera.c b/src/render/render_camera.c index c0c8ca4..6f9d821 100644 --- a/src/render/render_camera.c +++ b/src/render/render_camera.c @@ -10,11 +10,9 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" -#include "vec3.h" -#include "ray.h" #include +#include "ray.h" /** * @brief Update camera basis cache if invalid. diff --git a/src/render/render_init.c b/src/render/render_init.c index 2f6b25f..fd8484f 100644 --- a/src/render/render_init.c +++ b/src/render/render_init.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" #include "input.h" #include "hud.h" diff --git a/src/render/render_loop.c b/src/render/render_loop.c index 3a4d987..ba1370c 100644 --- a/src/render/render_loop.c +++ b/src/render/render_loop.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "render.h" #include "input.h" #include "hud.h" diff --git a/src/render/render_trace.c b/src/render/render_trace.c index 12bc024..cb087d7 100644 --- a/src/render/render_trace.c +++ b/src/render/render_trace.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "scene.h" #include "shading.h" #include "intersect.h" #include "spatial.h" diff --git a/src/scene/object_list.c b/src/scene/object_list.c index e1801ad..48a7f92 100644 --- a/src/scene/object_list.c +++ b/src/scene/object_list.c @@ -13,6 +13,7 @@ #include "scene.h" #include #include +#include "libft.h" /** * @brief Initialize an object list with a given capacity. diff --git a/src/scene/scene.c b/src/scene/scene.c index cb255b7..15766a8 100644 --- a/src/scene/scene.c +++ b/src/scene/scene.c @@ -13,6 +13,7 @@ #include "scene.h" #include "spatial.h" #include +#include "libft.h" /** * @brief Free shadow offset LUT memory. diff --git a/src/shading/shading.c b/src/shading/shading.c index aa4f292..6fc8de2 100644 --- a/src/shading/shading.c +++ b/src/shading/shading.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "shading.h" -#include "vec3.h" #include "shadow.h" #include "texture.h" #include diff --git a/src/shadow/shadow_calc.c b/src/shadow/shadow_calc.c index c34a528..c11e6b4 100644 --- a/src/shadow/shadow_calc.c +++ b/src/shadow/shadow_calc.c @@ -12,7 +12,6 @@ #include "shadow.h" #include "scene.h" -#include "vec3.h" #include /** diff --git a/src/shadow/shadow_test.c b/src/shadow/shadow_test.c index c5228bc..d79e212 100644 --- a/src/shadow/shadow_test.c +++ b/src/shadow/shadow_test.c @@ -12,7 +12,6 @@ #include "shadow.h" #include "scene.h" -#include "vec3.h" #include "intersect.h" #include "metrics.h" #include "spatial.h" diff --git a/src/texture/bump_map_perturb.c b/src/texture/bump_map_perturb.c index aa5a4ab..6c1060f 100644 --- a/src/texture/bump_map_perturb.c +++ b/src/texture/bump_map_perturb.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "texture.h" -#include "vec3.h" #include static double sample_height(t_bump_map *bmap, int px, int py) diff --git a/src/texture/checkerboard.c b/src/texture/checkerboard.c index 55dfb4c..12423e1 100644 --- a/src/texture/checkerboard.c +++ b/src/texture/checkerboard.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "texture.h" -#include "vec3.h" #include static t_color checker_plane(t_object *obj, t_hit *hit)