From 67508cd8304c45b44249efcf0aeae39e940427a9 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sun, 29 Oct 2023 22:12:38 +0100 Subject: [PATCH] =?UTF-8?q?WIP:=20if=20(address=5Fof=5Fthe=5Farrow=5Fto=5F?= =?UTF-8?q?erase=5Fin=5Fthe=5Farrows=5Flist=20=3D=3D=20arrows=5Fnb)=20?= =?UTF-8?q?=F0=9F=91=80=EF=B8=8F=20is=20a=20particular=20case=20?= =?UTF-8?q?=F0=9F=98=84=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/graphics.c | 83 ++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index f553544..84b4b64 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -669,56 +669,77 @@ static inline int create_arrow (int arrows_nb, return arrows_nb; } -static inline int erase_arrow (int arrows_nb, int address, +static inline int erase_arrow (int arrows_nb, int address_of_the_arrow_to_erase_in_the_arrows_list, int site, int x, int y, int z, int console) { assert (arrows_nb); - assert (address <= arrows_nb); arrows_nb --; + if (address_of_the_arrow_to_erase_in_the_arrows_list == arrows_nb) + { + 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"); - int mem = arrows_ptr[address].site; + 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"); - 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; + buffer_vertex_size -= 6; // <<< ceci n'est pas fait dans : graphics_write_vertex() + buffer_colors_size -= 6; // <<< ceci n'est pas fait dans : graphics_write_colors() + buffer_lines_size -= 2; // <<< ceci n'est pas fait dans : graphics_write_line() + + if (console) printf("in erase_arrow() : arrows_nb decreases from %d to %d. the erased arrow was at address : %d = %d : arrows_nb\n\ + buffer_vertex_size - 6 = %ld buffer_lines_size - 2 = %ld\n",\ + arrows_nb + 1, arrows_nb, address_of_the_arrow_to_erase_in_the_arrows_list, arrows_nb, buffer_vertex_size, buffer_lines_size); + + } else { + + int mem = arrows_ptr[address_of_the_arrow_to_erase_in_the_arrows_list].site; + + arrows_ptr[address_of_the_arrow_to_erase_in_the_arrows_list].load = arrows_ptr[arrows_nb].load; + arrows_ptr[address_of_the_arrow_to_erase_in_the_arrows_list].site = arrows_ptr[arrows_nb].site; + arrows_ptr[address_of_the_arrow_to_erase_in_the_arrows_list].x = arrows_ptr[arrows_nb].x; + arrows_ptr[address_of_the_arrow_to_erase_in_the_arrows_list].y = arrows_ptr[arrows_nb].y; + arrows_ptr[address_of_the_arrow_to_erase_in_the_arrows_list].z = arrows_ptr[arrows_nb].z; - 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); + 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_of_the_arrow_to_erase_in_the_arrows_list, address_of_the_arrow_to_erase_in_the_arrows_list, \ + 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"); + 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]; + for (long i = 0 + address_of_the_arrow_to_erase_in_the_arrows_list * 6; + i < 6 + address_of_the_arrow_to_erase_in_the_arrows_list * 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"); + 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]; + for (long i = 0; i < 6; i++) + buffer_colors_origin [buffer_colors_0_arrow + (address_of_the_arrow_to_erase_in_the_arrows_list + 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() */ - /* buffer_lines_size -= 2; // <<< ceci est fait dans : graphics_write_line() */ + /* buffer_vertex_size -= 6; // <<< ceci est fait dans : graphics_write_vertex() */ + /* buffer_colors_size -= 6; // <<< ceci est fait dans : graphics_write_colors() */ + /* buffer_lines_size -= 2; // <<< ceci est fait dans : graphics_write_line() */ - /* Il ne faut pas réécrire ce qui suit: ces lignes dessinent maintenant à partir d'autres vertex */ - /* void *new_arrows_lines_ptr = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLfloat)); */ - /* if (new_arrows_lines_ptr) buffer_lines_origin = new_arrows_lines_ptr; */ - /* else perror("In graphics.erase_arrow(), can't re_allocate for arrows lines buffer.\n"); */ + /* Il ne faut pas réécrire ce qui suit: ces lignes dessinent maintenant à partir d'autres vertex */ + /* void *new_arrows_lines_ptr = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLfloat)); */ + /* if (new_arrows_lines_ptr) buffer_lines_origin = new_arrows_lines_ptr; */ + /* else perror("In graphics.erase_arrow(), can't re_allocate for arrows lines buffer.\n"); */ - if (console) print_arrows_array (arrows_ptr, arrows_nb, 0); + if (console) print_arrows_array (arrows_ptr, arrows_nb, 0); + } return arrows_nb; }