From 874d237fc7bc406659f78f0c6eb90d8f5a4dea52 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sun, 29 Oct 2023 20:58:36 +0100 Subject: [PATCH] =?UTF-8?q?WIP:=20=3D>=20=20il=20faut=20faire=20un=20cas?= =?UTF-8?q?=20particulier=20(dans=20erase=5Farrow())=20si=20(address=20=3D?= =?UTF-8?q?=3D=20arrows=5Fnb)=20=F0=9F=91=80=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/graphics.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 4010469..f553544 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -137,7 +137,7 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z, int print) buffer_vertex_origin[buffer_vertex_size + 1] = y; buffer_vertex_origin[buffer_vertex_size + 2] = z; - if (print) printf("In graphics_write_vertex() buffer_vertex_size => [%2d] [%2d > %2d] (%6.3f,%6.3f,%6.3f)\n",\ + if (print) printf("In graphics_write_vertex() buffer_vertex_size => [%2ld] [%2ld > %2ld] (%6.3f,%6.3f,%6.3f)\n",\ buffer_vertex_size / 3, buffer_vertex_size + 0, buffer_vertex_size + 2, x, y, z); buffer_vertex_size += 3; @@ -181,7 +181,7 @@ void graphics_write_line (GLuint a, GLuint b, int print) buffer_lines_origin[buffer_lines_size + 0] = a; buffer_lines_origin[buffer_lines_size + 1] = b; - if (print) printf("In graphics_write_line() buffer_lines_size => [%2d] [%2d > %2d] (%3u > %3u )\n\n",\ + if (print) printf("In graphics_write_line() buffer_lines_size => [%2ld] [%2ld > %2ld] (%3u > %3u )\n\n",\ buffer_lines_size / 2, buffer_lines_size + 0, buffer_lines_size + 1, a, b); buffer_lines_size += 2; @@ -674,6 +674,7 @@ static inline int erase_arrow (int arrows_nb, int address, int console) { assert (arrows_nb); + assert (address <= arrows_nb); arrows_nb --; int mem = arrows_ptr[address].site; @@ -685,26 +686,27 @@ static inline int erase_arrow (int arrows_nb, int address, arrows_ptr[address].z = arrows_ptr[arrows_nb].z; - if (console) printf("in erase_arrow() : arrows_nb = %d > %d arrow to erase > (address = %d, site = %d)\n\ - : arrows_ptr[%d].site = %d >> %d (%d is last arrow.site)\n",\ - arrows_nb + 1, arrows_nb, address, address, site, mem, arrows_ptr[address].site, arrows_ptr[arrows_nb].site); - - for (long i = 0 + address * 6; i < 6 + address * 6; i++) - buffer_vertex_origin [buffer_vertex_0_arrow + i] - = buffer_vertex_origin [buffer_vertex_size - 6 + i]; - - for (long i = 0; i < 6; i++) - buffer_colors_origin [buffer_colors_0_arrow + (address + 4) * 6 + i] - = buffer_colors_origin [buffer_colors_size - 6 + i]; + if (console) printf("in erase_arrow() : arrows_nb decreases from %d to %d. the erased arrow was at address : %d\n\ + : arrows_ptr[%d].site (value: %d) was replaced by %d (%d was the value of the last arrow.site)\n",\ + arrows_nb + 1, arrows_nb, address, address, mem, arrows_ptr[arrows_nb].site, arrows_ptr[arrows_nb].site); void *new_arrows_vertex_ptr = g_realloc(buffer_vertex_origin, buffer_vertex_size * sizeof(GLfloat)); if (new_arrows_vertex_ptr) buffer_vertex_origin = new_arrows_vertex_ptr; else perror("In graphics.erase_arrow(), can't re_allocate for arrows vertex buffer.\n"); + for (long i = 0 + address * 6; i < 6 + address * 6; i++) + buffer_vertex_origin [buffer_vertex_0_arrow + i] + = buffer_vertex_origin [buffer_vertex_size - 6 + i]; + + void *new_arrows_colors_ptr = g_realloc(buffer_colors_origin, buffer_colors_size * sizeof(GLfloat)); if (new_arrows_colors_ptr) buffer_colors_origin = new_arrows_colors_ptr; else perror("In graphics.erase_arrow(), can't re_allocate for arrows colors buffer.\n"); + for (long i = 0; i < 6; i++) + buffer_colors_origin [buffer_colors_0_arrow + (address + 4) * 6 + i] + = buffer_colors_origin [buffer_colors_size - 6 + i]; + /* buffer_vertex_size -= 6; // <<< ceci est fait dans : graphics_write_vertex() */ /* buffer_colors_size -= 6; // <<< ceci est fait dans : graphics_write_colors() */ @@ -737,6 +739,7 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int spac current_weight = arrows_ptr[i].load; break; } + assert (address <= arrows_nb); if (address == -1 && requested_weight > 0) return create_arrow (arrows_nb, space_X, space_Y, space_Z, requested_weight, site, arrow_x, arrow_y, arrow_z, console); @@ -755,10 +758,10 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int spac void main_test_graphics (void) { srand(time(NULL)); int rand(void); void srand(unsigned int seed); int arbitrary = 4, randomize = 0, console = 0; - int space_X = 1, space_Y = 1, space_Z = 1, density_max = space_X * space_Y * space_Z; + int arrows_nb = 0, space_X = 1, space_Y = 1, space_Z = 1, density_max = space_X * space_Y * space_Z; if (randomize) {space_X = 1 + rand() % arbitrary; space_Y = 1 + rand() % arbitrary; space_Z = 1 + rand() % arbitrary;} int max = fmax(space_X, space_Y); max = fmax(max, space_Z); - int load = 0, site = 0, x = 0, y = 0, z = 0, arrows_nb = 0, specif_arrows_nb = rand() % density_max / 2; + /* int load = 0, site = 0, x = 0, y = 0, z = 0, specif_arrows_nb = rand() % density_max / 2; */ /*--------------------------------------------------------------------------------*/ @@ -811,9 +814,9 @@ void main_test_graphics (void) arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 0, 0, 0, 0, console); arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 1, 0, 0, 0, console); arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 2, 0, 0, 0, console); - /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 3, 0, 0, 0, console); */ - /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 4, 0, 0, 0, console); */ - /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 5, 0, 0, 0, console); */ + arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 3, 0, 0, 0, console); + arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 4, 0, 0, 0, console); + arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 5, 0, 0, 0, console);