Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -49,11 +48,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 \
Expand Down Expand Up @@ -118,14 +114,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
Expand Down
42 changes: 21 additions & 21 deletions includes/bvh_vis.h → includes/bvh_debug.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bvh_vis.h :+: :+: :+: */
/* bvh_debug.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yoshin <yoshin@student.42gyeongsan.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
Expand All @@ -10,8 +10,8 @@
/* */
/* ************************************************************************** */

#ifndef BVH_VIS_H
# define BVH_VIS_H
#ifndef BVH_DEBUG_H
# define BVH_DEBUG_H

# include "spatial.h"

Expand Down Expand Up @@ -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
13 changes: 10 additions & 3 deletions includes/mlx_context.h → includes/display.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx_context.h :+: :+: :+: */
/* display.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yoshin <yoshin@student.42gyeongsan.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
Expand All @@ -10,8 +10,10 @@
/* */
/* ************************************************************************** */

#ifndef MLX_CONTEXT_H
# define MLX_CONTEXT_H
#ifndef DISPLAY_H
# define DISPLAY_H

# include "mlx.h"

/**
* @brief MLX image data structure
Expand Down Expand Up @@ -51,4 +53,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
6 changes: 0 additions & 6 deletions includes/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
16 changes: 11 additions & 5 deletions includes/hud_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,30 @@
#ifndef HUD_INTERNAL_H
# define HUD_INTERNAL_H

# include "minirt.h"
# include "vec3.h"

typedef struct s_render t_render;

/* 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);

/* HUD format helpers */
void hud_strcpy(char *dst, const char *src);
void hud_itoa_buf(char *buf, int n);

#endif
3 changes: 0 additions & 3 deletions includes/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions includes/intersect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions includes/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions includes/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef PARSER_H
# define PARSER_H

# include "minirt.h"
# include "scene.h"

/* Constants */

Expand Down Expand Up @@ -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;

/*
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -99,9 +98,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);
Expand Down Expand Up @@ -129,7 +125,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);

Expand Down
13 changes: 7 additions & 6 deletions includes/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#ifndef RENDER_H
# define RENDER_H

# include "minirt.h"
# include "mlx.h"
# include "mlx_context.h"
# include "scene.h"
# include "ray.h"
# include "display.h"
# include "render_debounce.h"

/* Window resolution constants */
Expand Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions includes/render_debounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 3 additions & 21 deletions includes/minirt.h → includes/scene.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minirt.h :+: :+: :+: */
/* scene.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yoshin <yoshin@student.42gyeongsan.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
Expand All @@ -10,17 +10,11 @@
/* */
/* ************************************************************************** */

#ifndef MINIRT_H
# define MINIRT_H
#ifndef SCENE_H
# define SCENE_H

# include <unistd.h>
# include <fcntl.h>
# include <stdbool.h>
# include "libft.h"
# include "error.h"
# include "vec3.h"
# include "objects.h"
# include "ray.h"
# include "shadow.h"
# include "metrics.h"

Expand Down Expand Up @@ -113,17 +107,5 @@ 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);
t_ray create_camera_ray(t_camera *camera, double x, double y);
t_color trace_ray(t_scene *scene, t_ray *ray);

#endif
2 changes: 1 addition & 1 deletion includes/shading.h
Original file line number Diff line number Diff line change
Expand Up @@ -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+) */
Expand Down
2 changes: 1 addition & 1 deletion includes/shadow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion includes/spatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading
Loading