Skip to content

Commit

Permalink
[0.22.10] - removed mark dirty system
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddyMSchubert committed Jun 28, 2024
1 parent 2ea08c2 commit bb11aae
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 76 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### [0.22.10] - 28.06.2024 - Freddy
- Removed mark dirty system, it's quite unnecessary at this point anyways.

### [0.22.9] - 28.06.2024 - Freddy
- Fixed blight entity creating stack overflow when infinitely rotating stuck blight enitty

Expand Down
5 changes: 2 additions & 3 deletions include/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:37:47 by jkauker #+# #+# */
/* Updated: 2024/06/28 13:07:20 by jkauker ### ########.fr */
/* Updated: 2024/06/28 13:17:40 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -64,7 +64,6 @@
# define LOGGER_INFO 'i'
# define LOGGER_STEP 's'
# define LOGGER_ACTION 'a'
# define LOGGER_DIRTY 'd'

/* ----- EXIT CODES ----- */
# define EXIT_SUCCESS 0
Expand Down
3 changes: 1 addition & 2 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 08:45:22 by freddy #+# #+# */
/* Updated: 2024/06/27 22:37:27 by freddy ### ########.fr */
/* Updated: 2024/06/28 13:17:49 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -22,7 +22,6 @@
# define DEBUG false
# define LOG_WALLS false
# define TERMINAL_MAP true
# define MARK_DIRTY_LOGGING false

// --- Debug

Expand Down
5 changes: 2 additions & 3 deletions include/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* structs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:37:38 by jkauker #+# #+# */
/* Updated: 2024/06/28 12:58:43 by jkauker ### ########.fr */
/* Updated: 2024/06/28 13:16:01 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -121,7 +121,6 @@ typedef struct s_persistent_data
mlx_image_t *game_scene;
mlx_image_t *hud;
mlx_image_t *worldmap;
bool dirty;
bool **visible_walls;
double minimap_size;
mlx_texture_t *no_texture;
Expand Down
5 changes: 2 additions & 3 deletions src/2_setup/setup_mlx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* setup_mlx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkauker <jkauker@student.42heilbronn.de +#+ +:+ +#+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 08:41:35 by freddy #+# #+# */
/* Updated: 2024/06/26 15:26:46 by jkauker ### ########.fr */
/* Updated: 2024/06/28 13:17:53 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -76,7 +76,6 @@ void setup_mlx(void)
if (!mlx)
cub_exit("mlx setup failed.", -1);
data = game();
data->dirty = true;
data->mlx = mlx;
set_background();
load_textures();
Expand Down
19 changes: 0 additions & 19 deletions src/3_game_loop/a_game_logic/entities/blight_entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ void rotate_self(t_entity *self, int depth)
void move_self(t_entity *self)
{
t_vec2 new_pos;
t_vec2 oldpos;

oldpos = self->transform.pos;
self->transform.rot = scale_vector(self->transform.rot, 1);
if (random_val() < BLIGHT_MOVEMENT_ROTATION_SWITCH_CHANCE)
rotate_self(self, 0);
Expand All @@ -56,12 +54,6 @@ void move_self(t_entity *self)
}
else
rotate_self(self, 0);
if (oldpos.x != self->transform.pos.x || oldpos.y != self->transform.pos.y)
{
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Blight moved, marking dirty!");
}
}

void tick_blight(t_entity *self)
Expand All @@ -79,9 +71,6 @@ void tick_blight(t_entity *self)
self->frames_since_state_change = 0;
if (random_val() < BLIGHT_ATTACKING_START_CHANCE)
blight->state = BLIGHT_STATE_ATTACKING;
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Blight stopped, marking dirty!");
}
}
else if (blight->state == BLIGHT_STATE_STANDING)
Expand All @@ -98,7 +87,6 @@ void tick_blight(t_entity *self)
{
logger(LOGGER_ACTION, "Blight died!");
self->to_be_deleted = true;
game()->dirty = true;
}
}
else if (blight->state == BLIGHT_STATE_ATTACKING)
Expand Down Expand Up @@ -126,7 +114,6 @@ void on_collision_blight(t_entity *self, t_entity *other)
logger(LOGGER_ACTION, "Blight killed by projectile!");
blight->state = BLIGHT_STATE_DYING;
other->to_be_deleted = true;
game()->dirty = true;
}

// BLIGHT_DEATH_ANIMATION_FRAMES
Expand All @@ -150,9 +137,6 @@ mlx_texture_t *get_texture_blight(t_entity *self)
animation = game()->textures.earth_blight_death;
if (!animation.frame1)
cub_exit("Error: Blight death animation not found!", -1);
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Blight death animation, marking dirty!");
if (self->frames_since_state_change < BLIGHT_DEATH_ANIMATION_FRAMES / 3)
return (animation.frame1);
else if (self->frames_since_state_change < 2 * BLIGHT_DEATH_ANIMATION_FRAMES / 3)
Expand All @@ -173,9 +157,6 @@ mlx_texture_t *get_texture_blight(t_entity *self)
animation = game()->textures.earth_blight_attack;
if (!animation.frame1)
cub_exit("Error: Blight attack animation not found!", -1);
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Blight attack animation, marking dirty!");
if (self->frames_since_state_change < BLIGHT_ATTACK_ANIMATION_FRAMES / 3)
return (animation.frame1);
else if (self->frames_since_state_change < 2 * BLIGHT_ATTACK_ANIMATION_FRAMES / 3)
Expand Down
3 changes: 0 additions & 3 deletions src/3_game_loop/a_game_logic/entities/door_entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ void tick_door(t_entity *self)
door->door_open_progress -= DOOR_OPEN_SPEED;
self->transform.pos.x += ((door->open_pos.x - door->close_pos.x) * DOOR_OPEN_SPEED);
self->transform.pos.y += ((door->open_pos.y - door->close_pos.y) * DOOR_OPEN_SPEED);
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Door opening, set dirty to true!");
if (door->door_open_progress <= 0)
{
self->transform.pos = door->open_pos;
Expand Down
8 changes: 2 additions & 6 deletions src/3_game_loop/a_game_logic/entities/projectile_entity.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PROJECTILE_NTTntity.c :+: :+: :+: */
/* projectile_entity.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 13:56:45 by fschuber #+# #+# */
/* Updated: 2024/06/27 22:34:52 by freddy ### ########.fr */
/* Updated: 2024/06/28 13:18:24 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -35,13 +35,9 @@ void tick_projectile(t_entity *self)
if (!is_position_valid(new_pos.x, new_pos.y))
{
self->to_be_deleted = true;
game()->dirty = true;
return ;
}
self->transform.pos = new_pos;
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Projectile moved, set dirty to true!\n");
}

mlx_texture_t *get_texture_projectile(t_entity *self)
Expand Down
8 changes: 2 additions & 6 deletions src/3_game_loop/a_game_logic/hooks/key_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* key_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 10:23:50 by freddy #+# #+# */
/* Updated: 2024/06/28 12:32:55 by jkauker ### ########.fr */
/* Updated: 2024/06/28 13:18:35 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -18,10 +18,7 @@ static inline void inventory_press(mlx_key_data_t keydata)
if (keydata.key >= MLX_KEY_1 && keydata.key <= MLX_KEY_9 && keydata.action == MLX_PRESS)
{
if ((unsigned int)(player()->inv.num_available_items) > keydata.key - MLX_KEY_1)
{
player()->inv.current_index = keydata.key - MLX_KEY_1;
game()->dirty = true;
}
}
}

Expand All @@ -36,6 +33,5 @@ void key_hook(mlx_key_data_t keydata, void *param)
else if (keydata.key == MLX_KEY_R && keydata.action == MLX_PRESS)
setup_player();
inventory_press(keydata);
game()->dirty = true;
(void) param;
}
11 changes: 2 additions & 9 deletions src/3_game_loop/a_game_logic/hooks/loop_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 10:23:28 by freddy #+# #+# */
/* Updated: 2024/06/27 18:54:57 by freddy ### ########.fr */
/* Updated: 2024/06/28 13:18:50 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -33,18 +33,11 @@ void loop_hook(void *param)
// logger(LOGGER_WARNING, "skipped frame");
if ((int)curr_time != (int)prev_time || curr_frame != prev_frame)
{
game()->dirty = false;
handle_mouse_mv();
handle_player_move();
tick_entities();
collide_entities();
if (game()->dirty == true)
{
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "State is dirty, rendering anew!");
render();
game()->dirty = false;
}
render();
game()->prev_time = curr_time;
}
}
8 changes: 2 additions & 6 deletions src/3_game_loop/a_game_logic/hooks/mouse_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* mouse_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/11 15:50:17 by freddy #+# #+# */
/* Updated: 2024/06/28 13:07:40 by jkauker ### ########.fr */
/* Updated: 2024/06/28 13:18:56 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -23,9 +23,6 @@ void handle_mouse_mv(void)
mlx_get_mouse_pos(game()->mlx, &current_mouse_x, &current_mouse_y);
if (current_mouse_x == game()->prev_mouse_x)
return ;
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Mouse moved, set dirty to true!");
turn((current_mouse_x - game()->prev_mouse_x) * MOUSE_SENSITIVITY);
game()->prev_mouse_x = current_mouse_x;

Expand All @@ -45,7 +42,6 @@ void scroll_hook(double xdelta, double ydelta, void *param)
cycle_inventory(-1, false);
else
cycle_inventory(1, false);
game()->dirty = true;
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/3_game_loop/a_game_logic/hooks/player_movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* player_movement.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fschuber <fschuber@student.42.fr> +#+ +:+ +#+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/20 07:50:27 by fschuber #+# #+# */
/* Updated: 2024/06/28 10:05:29 by fschuber ### ########.fr */
/* Updated: 2024/06/28 13:19:01 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -106,11 +106,4 @@ void handle_player_move(void)
player()->transform.pos.x += mvmnt.x;
if (is_position_valid(player()->transform.pos.x, new_pos.y))
player()->transform.pos.y += mvmnt.y;
if (new_pos.x != player()->transform.pos.x || \
new_pos.y != player()->transform.pos.y)
{
game()->dirty = true;
if (MARK_DIRTY_LOGGING)
logger(LOGGER_DIRTY, "Player moved, set dirty to true!");
}
}
5 changes: 2 additions & 3 deletions src/3_game_loop/b_rendering/hud/inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* inventory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 13:56:58 by jkauker #+# #+# */
/* Updated: 2024/06/28 13:08:20 by jkauker ### ########.fr */
/* Updated: 2024/06/28 13:19:05 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -132,7 +132,6 @@ static inline void draw_current_selection(int start_x, int start_y)

void cycle_inventory(int direction, bool direct)
{
game()->dirty = true;
if (direction == 0 && !direct)
return ;
if (direct)
Expand Down
6 changes: 2 additions & 4 deletions src/util/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:49:10 by fschuber #+# #+# */
/* Updated: 2024/06/27 18:57:03 by freddy ### ########.fr */
/* Updated: 2024/06/28 13:19:15 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../include/cub3d.h"

/*
@brief prints a message to the console
@param type - 'e' for error, 'w' for warning, 'i' for info, 's' for step, 'a' for action, 'd' for dirty
@param type - 'e' for error, 'w' for warning, 'i' for info, 's' for step, 'a' for action
@param message - the message to print
*/
void logger(char type, char *message)
Expand All @@ -31,8 +31,6 @@ void logger(char type, char *message)
printf("%sSTEP%s: \t%s\n", ANSI_BOLD_GREEN, ANSI_RESET, message);
else if (type == 'a')
printf("%sACTION%s: %s\n", ANSI_BOLD_MAGENTA, ANSI_RESET, message);
else if (type == 'd')
printf("%sDIRTY%s: \t%s\n", ANSI_BOLD_BLUE, ANSI_RESET, message);
else
printf("%s%s%s\n", ANSI_COLOR_WHITE, ANSI_RESET, message);
}
Expand Down

0 comments on commit bb11aae

Please sign in to comment.