diff --git a/scenes/engine/EC/EC.h b/scenes/engine/EC/EC.h index 32f9387..6ac2eb4 100644 --- a/scenes/engine/EC/EC.h +++ b/scenes/engine/EC/EC.h @@ -143,7 +143,9 @@ typedef struct _BFSTileMap { typedef enum _WaterRunnerState { - LOWEST_POINT_SEARCH = 0, + BFS_RESET = 0, + BFS_START, + LOWEST_POINT_SEARCH, LOWEST_POINT_MOVEMENT, SCANLINE_FILL, }WaterRunerState_t; diff --git a/scenes/water_flow.c b/scenes/water_flow.c index 5314bf7..7276590 100644 --- a/scenes/water_flow.c +++ b/scenes/water_flow.c @@ -91,19 +91,24 @@ void update_water_runner_system(Scene_t* scene) switch (p_crunner->state) { - case LOWEST_POINT_SEARCH: - { + case BFS_RESET: for (size_t i = 0; i < p_crunner->bfs_tilemap.len; ++i) { p_crunner->bfs_tilemap.tilemap[i].from = -1; p_crunner->bfs_tilemap.tilemap[i].reachable = false; } + p_crunner->state = BFS_START; + // Want the fallthough + case BFS_START: memset(p_crunner->visited, 0, p_crunner->bfs_tilemap.len * sizeof(bool)); int32_t lowest_tile = p_crunner->current_tile; p_crunner->visited[p_crunner->current_tile] = true; p_crunner->bfs_tilemap.tilemap[p_crunner->current_tile].reachable = true; - sc_queue_add_last(&p_crunner->bfs_queue, p_crunner->current_tile); + p_crunner->state = LOWEST_POINT_SEARCH; + // Want the fallthough + case LOWEST_POINT_SEARCH: + { while (!sc_queue_empty(&p_crunner->bfs_queue)) { unsigned int curr_idx = sc_queue_peek_first(&p_crunner->bfs_queue); diff --git a/water_test.c b/water_test.c index ed99ea5..59036c7 100644 --- a/water_test.c +++ b/water_test.c @@ -257,7 +257,7 @@ static void toggle_block_system(Scene_t* scene) CWaterRunner_t* p_crunner; sc_map_foreach_value(&scene->ent_manager.component_map[CWATERRUNNER_T], p_crunner) { - p_crunner->state = LOWEST_POINT_SEARCH; + p_crunner->state = BFS_RESET; } } else if (IsMouseButtonReleased(MOUSE_RIGHT_BUTTON))