diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index c97f560..e6f1dea 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -35,7 +35,7 @@ #define VERTEX_SHADER_FILE "src/shaders/shader.vert" #define FRAG_SHADER_FILE "src/shaders/shader.frag" -static struct arrow_t *arrovvs; /* nom modifié pour pouvoir plus facilement distinguer le tableau +static struct arrow_t *arrows_ptr; /* nom modifié pour pouvoir plus facilement distinguer le tableau * des autres noms incluant "arrows" (de arrows_nb, par ex.) */ static GLfloat *buffer_vertex_origin = NULL; static GLfloat *buffer_colors_origin = NULL; @@ -133,7 +133,7 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z) buffer_vertex_origin[buffer_vertex_size + 1] = y; buffer_vertex_origin[buffer_vertex_size + 2] = z; - if (1) printf("In graphics_write_vertex() buffer_vertex_size = %2d > %2d (%6.3f,%6.3f,%6.3f)\n",\ + if (0) printf("In graphics_write_vertex() buffer_vertex_size = %2d > %2d (%6.3f,%6.3f,%6.3f)\n",\ buffer_vertex_size, buffer_vertex_size + 3, x, y, z); buffer_vertex_size += 3; @@ -177,7 +177,7 @@ void graphics_write_line (GLuint a, GLuint b) buffer_lines_origin[buffer_lines_size + 0] = a; buffer_lines_origin[buffer_lines_size + 1] = b; - if (1) printf("In graphics_write_line() buffer_lines_size = %2d > %2d\n",\ + if (0) printf("In graphics_write_line() buffer_lines_size = %2d > %2d\n",\ buffer_lines_size, buffer_lines_size + 2); buffer_lines_size += 2; @@ -554,9 +554,9 @@ bool graphics_shutdown(const void *gl_area) */ static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x, int y, int z) { - arrovvs[address].load = load; + arrows_ptr[address].load = load; - print_arrows_array (arrovvs, arrows_nb, 2); + print_arrows_array (arrows_ptr, arrows_nb, 2); return arrows_nb; } @@ -565,24 +565,33 @@ static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x, * Creates a new arrow at address (address) * NB Weights (or loads) are NOT added */ -static inline int create_arrow (int arrows_nb, int load, int site, int x, int y, int z) +static inline int create_arrow (int arrows_nb, + int space_X, int space_Y, int space_Z, + int load, int site, int x, int y, int z) { - void *newptr = g_realloc(arrovvs, (arrows_nb + 1) * sizeof(struct arrow_t)); + void *newptr = g_realloc(arrows_ptr, (arrows_nb + 1) * sizeof(struct arrow_t)); if (newptr) - arrovvs = newptr; + arrows_ptr = newptr; else perror("In create arrow, can't allocate new arrow buffer !\n"); - arrovvs[arrows_nb].load = load; - arrovvs[arrows_nb].site = site; - arrovvs[arrows_nb].x = x; - arrovvs[arrows_nb].y = y; - arrovvs[arrows_nb].z = z; + arrows_ptr[arrows_nb].load = load; + arrows_ptr[arrows_nb].site = site; + arrows_ptr[arrows_nb].x = x; + arrows_ptr[arrows_nb].y = y; + arrows_ptr[arrows_nb].z = z; + + write_one_arrow_vertex(buffer_vertex_size, + space_X, space_Y, space_Z, + load, site, x, y, z); + buffer_colors_size = buffer_vertex_size; + + write_one_arrow_line (buffer_vertex_size); arrows_nb ++; - print_arrows_array (arrovvs, arrows_nb, 1); + print_arrows_array (arrows_ptr, arrows_nb, 1); return arrows_nb; } @@ -596,28 +605,28 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int if (1) { - arrovvs[address].load = arrovvs[arrows_nb].load; - arrovvs[address].site = arrovvs[arrows_nb].site; - arrovvs[address].x = arrovvs[arrows_nb].x; - arrovvs[address].y = arrovvs[arrows_nb].y; - arrovvs[address].z = arrovvs[arrows_nb].z; + arrows_ptr[address].load = arrows_ptr[arrows_nb].load; + arrows_ptr[address].site = arrows_ptr[arrows_nb].site; + arrows_ptr[address].x = arrows_ptr[arrows_nb].x; + arrows_ptr[address].y = arrows_ptr[arrows_nb].y; + arrows_ptr[address].z = arrows_ptr[arrows_nb].z; } if (arrows_nb > 0) { - void *newptr = g_realloc(arrovvs, arrows_nb * sizeof(struct arrow_t)); + void *newptr = g_realloc(arrows_ptr, arrows_nb * sizeof(struct arrow_t)); if (newptr) - arrovvs = newptr; + arrows_ptr = newptr; else perror("In erase arrow, can't allocate new arrow buffer !\n"); } - print_arrows_array (arrovvs, arrows_nb,0); + print_arrows_array (arrows_ptr, arrows_nb,0); return arrows_nb; } -static inline void show_user_action(struct arrow_t *arrovvs, int arrows_nb, int address, int requested_weight, +static inline void show_user_action(struct arrow_t *arrows_ptr, int arrows_nb, int address, int requested_weight, int current_weight, int site, int x, int y, int z); /* * Calls one of the functions create_arrow(), erase_arrow() or rewrite_arrow() @@ -627,30 +636,32 @@ static inline void show_user_action(struct arrow_t *arrovvs, int arrows_nb, int * - Current_weight of an arrow located at the requested address == requested_weight * - No arrow was found at the requested addres AND current_weight == requested_weight */ -static inline int set_arrow (struct arrow_t *arrovvs, int arrows_nb, int requested_weight, int site, int x, int y, int z) // , int buffer_vertex_size +static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, + int space_X, int space_Y, int space_Z, + int requested_weight, int site, int x, int y, int z) { int address = -1, current_weight = -1; #pragma omp parallel schedule(static, 12) { for (int i = 0; i < arrows_nb; i++) { - if ((site == arrovvs[i].site) - && (x == arrovvs[i].x) - && (y == arrovvs[i].y) - && (z == arrovvs[i].z)) + if ((site == arrows_ptr[i].site) + && (x == arrows_ptr[i].x) + && (y == arrows_ptr[i].y) + && (z == arrows_ptr[i].z)) { address = i * 5; - current_weight = arrovvs[i].load; + current_weight = arrows_ptr[i].load; break; } } } //printf("\n[%d]set_arrow() invoked with requested weight = %2d + ", arrows_nb, requested_weight); - if (TEST) show_user_action(arrovvs, arrows_nb, address, requested_weight, current_weight, site, x, y, z); + if (TEST) show_user_action(arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); if (address == -1 && requested_weight > 0) - return create_arrow (arrows_nb, requested_weight, site, x, y, z); + return create_arrow (arrows_nb, space_X, space_Y, space_Z, requested_weight, site, x, y, z); if (address >= 0 && requested_weight == 0) return erase_arrow (arrows_nb, address, site, x, y, z); @@ -658,9 +669,9 @@ static inline int set_arrow (struct arrow_t *arrovvs, int arrows_nb, int request if (address >= 0 && current_weight != requested_weight) return rewrite_arrow (arrows_nb, address/5, requested_weight, site, x, y, z); - if (! TEST && address >= 0 && current_weight == requested_weight) print_arrows_array(arrovvs, arrows_nb, 3); + if (! TEST && address >= 0 && current_weight == requested_weight) print_arrows_array(arrows_ptr, arrows_nb, 3); - if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(arrovvs, arrows_nb, 4); + if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(arrows_ptr, arrows_nb, 4); return arrows_nb; } @@ -700,29 +711,8 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) int print_inter_results = 0; if (print_inter_results) clock_gettime(CLOCK_REALTIME, &ts); t_initial = ts.tv_sec; if (print_inter_results) printf("%10d | ", specif_arrows_nb / 1000); -#pragma omp parallel -{ - /* while (arrows_nb < specif_arrows_nb){ */ - arrows_nb = set_arrow (arrovvs, arrows_nb, - 1,//rand() % arbitrary + 1, // load / weight - 0,//rand() % 6, // site, - 0,//rand() % space_X, // x - 0,//rand() % space_Y, // y - 0);//rand() % space_Z); // z - - arrows_nb = set_arrow (arrovvs, arrows_nb, - 1,//rand() % arbitrary + 1, // load / weight - 1,//rand() % 6, // site, - 0,//rand() % space_X, // x - 0,//rand() % space_Y, // y - 0);//rand() % space_Z); // z - - /* clock_gettime(CLOCK_REALTIME, &ts); < Je n'arrive pas à afficher les temps en cours d'exécutuion */ - /* if (arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 22 == 0) printf(" %f\n%10d | ", specif_arrows_nb / 1000, ts.tv_sec - t_initial);} */ - if (print_inter_results && arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 24 == 0) printf("\n%10d | ", specif_arrows_nb / 1000);} - /* } */ printf("I N I T I A L D A T A A R E N O W S P E C I F I E D\n"); -} + /*--------------------------------------------------------------------------------*/ @@ -736,37 +726,38 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) /* S P A C E */ - if (1) printf("buffer_vertex_size before writing_space_ridges_vertex : %d (x 3 = %d)\n", buffer_vertex_size, buffer_vertex_size * 3); + if (1) printf("buffer_vertex_size before writing 8 space_ridges_vertex : %3d (x 3 = %d)\n", buffer_vertex_size / 3, buffer_vertex_size); write_space_ridges_vertex (buffer_vertex_size, space_X, space_Y, space_Z); /* buffer_colors_size = buffer_vertex_size; */ - if (1) printf("buffer_vertex_size after writing_space_ridges_vertex : %d (x 3 = %d)\n\n", buffer_vertex_size, buffer_vertex_size * 3); + if (1) printf("buffer_vertex_size after writing 8 space_ridges_vertex : %3d (x 3 = %d)\n", buffer_vertex_size / 3, buffer_vertex_size); write_grids_on_space_faces_vertex (space_X, space_Y, space_Z); /* buffer_colors_size = buffer_vertex_size; */ - if (1) printf("buffer_vertex_size after writing_space_faces_vertex = %4d - 8 = %3d (x 3 = %4d)\n\n", buffer_vertex_size, buffer_vertex_size - 8, (buffer_vertex_size - 8) * 3); + if (1) printf("buffer_vertex_size after writing %3d space_faces_vertex : %3d (x 3 = %4d)\n\n", buffer_vertex_size / 3 - 8, buffer_vertex_size / 3, buffer_vertex_size); /* if (0) printf("(space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4 = %3d (x 3 = %4d)\n\n",\ */ /* (space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4, ((space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4) * 3); */ /* A R R O W S */ - /* for (int i = 0; i < arrows_nb; i++) { */ - /* load = arrovvs[i].load; */ - /* site = arrovvs[i].site; */ - /* x = arrovvs[i].x; */ - /* y = arrovvs[i].y; */ - /* z = arrovvs[i].z; */ + /* if (1) printf("buffer_vertex_size before writing (%d) arrows_vertex : %d\n", arrows_nb, buffer_vertex_size / 3); */ - /* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */ - /* space_X, space_Y, space_Z, */ - /* load, site, x, y, z); */ + /* for (int i = 0; i < arrows_nb; i++) { */ + /* load = arrows_ptr[i].load; */ + /* site = arrows_ptr[i].site; */ + /* x = arrows_ptr[i].x; */ + /* y = arrows_ptr[i].y; */ + /* z = arrows_ptr[i].z; */ + + /* write_one_arrow_vertex(buffer_vertex_size, space_X, space_Y, space_Z, */ + /* load, site, x, y, z); */ /* buffer_colors_size = buffer_vertex_size; */ /* } */ - /* if (1) printf("buffer_vertex_size after writing_arrows_vertex : %d TODO (arrows_nb = %d)\n\n", buffer_vertex_size, arrows_nb); */ + /* if (1) printf("buffer_vertex_size after writing (%d) arrows_vertex : %d\n", arrows_nb, buffer_vertex_size / 3); */ /*---------------------------------------------------------------*/ @@ -777,26 +768,44 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) /* S P A C E */ - if (1) printf("buffer_lines_size before writing 12 space_ridges_lines : %d (* 2 = %d)\n", buffer_lines_size / 2, buffer_lines_size); + if (1) printf("buffer_lines_size before writing 12 space_ridges_lines : %2d (* 2 = %2d)\n", buffer_lines_size / 2, buffer_lines_size); write_space_ridges_lines (); - if (1) printf("buffer_lines_size after writing 12 space_ridges_lines : %d (* 2 = %d)\n\n", buffer_lines_size / 2, buffer_lines_size); + if (1) printf("buffer_lines_size after writing 12 space_ridges_lines : %2d (* 2 = %2d)\n", buffer_lines_size / 2, buffer_lines_size); - if (1) printf("buffer_lines_size before writing_space_faces_lines : %d (* 2 = %d)\n", buffer_lines_size / 2, buffer_lines_size); + if (1) printf("buffer_lines_size before writing (n) space_faces_lines : %2d (* 2 = %2d)\n", buffer_lines_size / 2, buffer_lines_size); write_grids_on_space_faces_lines (buffer_lines_size, space_X, space_Y, space_Z); - /* graphics_write_line (8, 9); */ - /* graphics_write_line (9, 10); */ - /* graphics_write_line (10, 11); */ - /* graphics_write_line (11, 8); */ - if (1) printf("buffer_lines_size after writing_space_faces_lines : %d (* 2 = %d)\n\n", buffer_lines_size / 2, buffer_lines_size); + if (1) printf("buffer_lines_size after writing (n) space_faces_lines : %d (* 2 = %d)\n\n", buffer_lines_size / 2, buffer_lines_size); /* A R R O W S */ +/* #pragma omp parallel */ +/* { */ + /* while (arrows_nb < specif_arrows_nb){ */ + arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, + 1,//rand() % arbitrary + 1, // load / weight + 0,//rand() % 6, // site, + 0,//rand() % space_X, // x + 0,//rand() % space_Y, // y + 0);//rand() % space_Z); // z + + arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, + 1,//rand() % arbitrary + 1, // load / weight + 1,//rand() % 6, // site, + 0,//rand() % space_X, // x + 0,//rand() % space_Y, // y + 0);//rand() % space_Z); // z + + /* clock_gettime(CLOCK_REALTIME, &ts); < Je n'arrive pas à afficher les temps en cours d'exécutuion */ + /* if (arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 22 == 0) printf(" %f\n%10d | ", specif_arrows_nb / 1000, ts.tv_sec - t_initial);} */ + if (print_inter_results && arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 24 == 0) printf("\n%10d | ", specif_arrows_nb / 1000);} + /* } */ +/* } */ /* for (int i = 0; i < arrows_nb; i++) { */ - /* load = arrovvs[i].load; */ - /* site = arrovvs[i].site; */ - /* x = arrovvs[i].x; */ - /* y = arrovvs[i].y; */ - /* z = arrovvs[i].z; */ + /* load = arrows_ptr[i].load; */ + /* site = arrows_ptr[i].site; */ + /* x = arrows_ptr[i].x; */ + /* y = arrows_ptr[i].y; */ + /* z = arrows_ptr[i].z; */ /* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */ /* } */ @@ -814,34 +823,34 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) /*--------------------------------------------------------------------------------*/ - print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); + print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); - arrows_nb = set_arrow (arrovvs, arrows_nb, - 0,//rand() % arbitrary + 1, // load / weight - 0,//rand() % 6, // site, - 0,//rand() % space_X, // x - 0,//rand() % space_Y, // y - 0);//rand() % space_Z); // z + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, */ + /* 0,//rand() % arbitrary + 1, // load / weight */ + /* 0,//rand() % 6, // site, */ + /* 0,//rand() % space_X, // x */ + /* 0,//rand() % space_Y, // y */ + /* 0);//rand() % space_Z); // z */ - print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); + /* print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */ - arrows_nb = set_arrow (arrovvs, arrows_nb, - 0,//rand() % arbitrary + 1, // load / weight - 1,//rand() % 6, // site, - 0,//rand() % space_X, // x - 0,//rand() % space_Y, // y - 0);//rand() % space_Z); // z + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, */ + /* 0,//rand() % arbitrary + 1, // load / weight */ + /* 1,//rand() % 6, // site, */ + /* 0,//rand() % space_X, // x */ + /* 0,//rand() % space_Y, // y */ + /* 0);//rand() % space_Z); // z */ - print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); + /* print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */ -/* arrows_nb = set_arrow (arrovvs, arrows_nb, */ +/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, */ /* 1,//rand() % arbitrary + 1, // load / weight */ /* 2,//rand() % 6, // site, */ /* 0,//rand() % space_X, // x */ /* 0,//rand() % space_Y, // y */ /* 0);//rand() % space_Z); // z */ -/* arrows_nb = set_arrow (arrovvs, arrows_nb, */ +/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, */ /* 1,//rand() % arbitrary + 1, // load / weight */ /* 3,//rand() % 6, // site, */ /* 0,//rand() % space_X, // x */ @@ -850,7 +859,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) /* printf("On devrait avoir deux flèches Y+Y- (Zénith-Nadir) dessinées (au lieu des deux flèches X+X- Est-Ouest)...\n"); */ - /* print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */ + /* print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */ // buffer_vertex_size -= 2; // buffer_vertex_size += 3; @@ -866,7 +875,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) /* random_choice = rand() % 6; */ /* if (random_choice == 0) deleted++; */ -/* modified = set_arrow (arrovvs, arrows_nb + modified, */ +/* modified = set_arrow (arrows_ptr, arrows_nb + modified, */ /* random_choice, // load / weight */ /* rand() % 6, // site, */ /* rand() % space_X, // x */ @@ -878,11 +887,11 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) /* #pragma omp parallel */ /* { */ /* for (int i = 0; i < arrows_nb + modified; i++) { */ -/* load = arrovvs[i].load; */ -/* site = arrovvs[i].site; */ -/* x = arrovvs[i].x; */ -/* y = arrovvs[i].y; */ -/* z = arrovvs[i].z; */ +/* load = arrows_ptr[i].load; */ +/* site = arrows_ptr[i].site; */ +/* x = arrows_ptr[i].x; */ +/* y = arrows_ptr[i].y; */ +/* z = arrows_ptr[i].z; */ /* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */ /* space_X, space_Y, space_Z, */ @@ -891,21 +900,22 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) /* } */ /* for (int i = 0; i < arrows_nb + modified; i++) { */ -/* load = arrovvs[i].load; */ -/* site = arrovvs[i].site; */ -/* x = arrovvs[i].x; */ -/* y = arrovvs[i].y; */ -/* z = arrovvs[i].z; */ +/* load = arrows_ptr[i].load; */ +/* site = arrows_ptr[i].site; */ +/* x = arrows_ptr[i].x; */ +/* y = arrows_ptr[i].y; */ +/* z = arrows_ptr[i].z; */ /* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */ /* } */ /* } */ -/* print_evolution (arrovvs, arrows_nb, arbitrary, deleted, print_arrows_data); */ +/* print_evolution (arrows_ptr, arrows_nb, arbitrary, deleted, print_arrows_data); */ // ? free (space) TODO - free(arrovvs); - arrovvs = NULL; + + free(arrows_ptr); + arrows_ptr = NULL; arrows_nb = 0; }