From df54fc5751e66360da6b844bbc733e15d28407ce Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 25 Oct 2023 16:31:46 +0200 Subject: [PATCH] WIP: (micro) lignes 622-634 mise en plac des g_realloc() vertex & lines buffers --- src/graphics/graphics.c | 45 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 7b626f4..6be89ca 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -47,6 +47,11 @@ static volatile int buffer_lines_size = 0; static volatile int buffer_colors_size = 0; static volatile int buffer_plans_size = 0; +static volatile int buffer_vertex_0_arrow = 0; +static volatile int buffer_lines_0_arrow = 0; +static volatile int buffer_colors_0_arrow = 0; +static volatile int buffer_plans_0_arrow = 0; + #define TEST 0 /* @@ -605,19 +610,28 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int { arrows_nb --; - if (1) - { - 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; - } + 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(arrows_ptr, arrows_nb * sizeof(struct arrow_t)); - if (newptr) arrows_ptr = newptr; - else perror("In erase arrow, can't re_allocate for arrow list.\n"); + + void *new_arrows_list_ptr = g_realloc(arrows_ptr, arrows_nb * sizeof(struct arrow_t)); + if (new_arrows_list_ptr) arrows_ptr = new_arrows_list_ptr; + else perror("In erase arrow, can't re_allocate for arrow list.\n"); + + printf("buffer_vertex_0_arrow = %d arrows_nb * 3 = %d <<<<\n", buffer_vertex_0_arrow, arrows_nb * 3); + void *new_arrows_vertex_ptr = g_realloc(buffer_vertex_origin, buffer_vertex_0_arrow + 9 * 3 * sizeof(GLfloat)); + if (new_arrows_vertex_ptr) buffer_vertex_origin = new_arrows_vertex_ptr; + else perror("In erase arrow, can't re_allocate for arrow vertex buffer.\n"); + + printf("buffer_lines_0_arrow = %d arrows_nb * 2 = %d <<<<\n", buffer_lines_0_arrow, arrows_nb * 2); + void *new_arrows_lines_ptr = g_realloc(buffer_lines_origin, buffer_lines_0_arrow + 9 * 2 * sizeof(GLfloat)); + if (new_arrows_lines_ptr) buffer_lines_origin = new_arrows_lines_ptr; + else perror("In erase arrow, can't re_allocate for arrow lines buffer.\n"); } print_arrows_array (arrows_ptr, arrows_nb,0); @@ -774,6 +788,15 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) write_grids_on_space_faces_lines (buffer_lines_size, space_X, space_Y, space_Z); if (0) printf("buffer_lines_size after writing (n) space_faces_lines : %d (* 2 = %d)\n\n", buffer_lines_size / 2, buffer_lines_size); + /* Ce programme définit et crée séquentiellement les caractéristiques puis les images de l'espace puis celles des flèches + * Pour pouvoir effacer une flèche (n'importe laquelle), + * il est nécéssaire de connaître la taille des buffers au moment de la création de la première flèche */ + + buffer_vertex_0_arrow = buffer_vertex_size; + buffer_lines_0_arrow = buffer_lines_size; + printf("buffer_vertex_0_arrow = %d (%d points) buffer_lines_0_arrow = %d (%d lines)\n",\ + buffer_vertex_0_arrow, buffer_vertex_0_arrow / 3, buffer_lines_0_arrow, buffer_lines_0_arrow / 2); + /* A R R O W S */ /* #pragma omp parallel */