think im pretty much done here
This commit is contained in:
@@ -22,5 +22,17 @@
|
||||
"directory": "/home/magnus/code/c/projects/astar",
|
||||
"file": "/home/magnus/code/c/projects/astar/src/main.c",
|
||||
"output": "/home/magnus/code/c/projects/astar/target"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/gcc",
|
||||
"-c",
|
||||
"-o",
|
||||
"target",
|
||||
"src/visual.c"
|
||||
],
|
||||
"directory": "/home/magnus/code/c/projects/astar",
|
||||
"file": "/home/magnus/code/c/projects/astar/src/visual.c",
|
||||
"output": "/home/magnus/code/c/projects/astar/target"
|
||||
}
|
||||
]
|
||||
|
||||
+5
-5
@@ -238,14 +238,14 @@ Vector2* get_a_star_path(afield_t *field, Vector2 start, Vector2 goal, int max_s
|
||||
collapse_node_at(field, start);
|
||||
|
||||
assign_node_as_parent(field, goal, start);
|
||||
debug_print_field(field);
|
||||
// debug_print_field(field);
|
||||
|
||||
for (int x = 0; x < max_searches; x++) {
|
||||
Vector2 best = get_best_node(field);
|
||||
if (best.x == -1 || best.y == -1) {
|
||||
// all search paths exausted
|
||||
debug_print_field(field);
|
||||
printf("TARGET NOT REACHABLE!\n");
|
||||
// debug_print_field(field);
|
||||
// printf("TARGET NOT REACHABLE!\n");
|
||||
|
||||
*path_length = 0;
|
||||
return NULL;
|
||||
@@ -258,12 +258,12 @@ Vector2* get_a_star_path(afield_t *field, Vector2 start, Vector2 goal, int max_s
|
||||
|
||||
if (found) {
|
||||
// debug_print_field(field);
|
||||
printf("FOUND TARGET!\n");
|
||||
// printf("FOUND TARGET!\n");
|
||||
return reconstruct_path(field, start, goal, path_length);
|
||||
}
|
||||
}
|
||||
|
||||
printf("All searches wasted, target not found, quitting!\n");
|
||||
// printf("All searches wasted, target not found, quitting!\n");
|
||||
*path_length = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+13
-8
@@ -13,6 +13,8 @@ int run_visual(void) {
|
||||
|
||||
const int cellSize = screenWidth / GRID_SIZE;
|
||||
|
||||
bool live_view = true;
|
||||
|
||||
int path_len = -1;
|
||||
Vector2* path = NULL;
|
||||
|
||||
@@ -20,7 +22,6 @@ int run_visual(void) {
|
||||
|
||||
bool grid[GRID_SIZE][GRID_SIZE] = {0};
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
// Handle mouse clicks
|
||||
@@ -42,7 +43,8 @@ int run_visual(void) {
|
||||
grid[y][x] = false;
|
||||
}
|
||||
}
|
||||
if (IsKeyDown(KEY_SPACE)) {
|
||||
if (IsKeyPressed(KEY_R)) { live_view ^= 1; }
|
||||
if (IsKeyPressed(KEY_SPACE) || live_view) {
|
||||
int **collision = malloc(GRID_SIZE * sizeof(int*));
|
||||
for(int i = 0; i < GRID_SIZE; i++)
|
||||
collision[i] = malloc(GRID_SIZE * sizeof(int));
|
||||
@@ -61,12 +63,11 @@ int run_visual(void) {
|
||||
|
||||
if (path) { free(path); }
|
||||
path = do_full_a_star_search(GRID_SIZE, GRID_SIZE, collision, start, goal, 1000, &path_len);
|
||||
|
||||
if (!path) { printf("no path"); }
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
Color bg_col = {0x57, 0x57, 0x61, 0xff}; // #575761
|
||||
ClearBackground(bg_col);
|
||||
|
||||
// Draw grid
|
||||
for (int y = 0; y < GRID_SIZE; y++) {
|
||||
@@ -83,14 +84,18 @@ int run_visual(void) {
|
||||
Rectangle cell = { x * cellSize, y * cellSize, cellSize, cellSize };
|
||||
|
||||
if (cell_in_path) {
|
||||
DrawRectangleRec(cell, RED);
|
||||
Color path_col = {0x8A, 0xCB, 0x88, 0xff};
|
||||
DrawRectangleRec(cell, path_col);
|
||||
}
|
||||
|
||||
if (grid[y][x]) {
|
||||
DrawRectangleRec(cell, DARKBLUE);
|
||||
Color obs_col = {0x64, 0x83, 0x81, 0xff};
|
||||
DrawRectangleRec(cell, obs_col);
|
||||
}
|
||||
DrawRectangleLines(cell.x, cell.y, cell.width, cell.height, BLACK);
|
||||
|
||||
DrawRectangleLines(cell.x, cell.y, cell.width, cell.height, GRAY);
|
||||
DrawText(TextFormat("FPS: %i", GetFPS()), 10, 10, 32, BLACK);
|
||||
DrawText(TextFormat("LIVE: %s", live_view?"ON":"OFF"), 10, 40, 32, BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user