From c053f02b6c5bb0804441b34cbc85b05711e6b41e Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Tue, 26 Sep 2023 11:21:11 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20Bien=20mieux=20!=20=20erase=5Farrow()=20?= =?UTF-8?q?=C3=A0=20rectifier=20pour=20les=20valeurs=20z=C3=A9ro.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/graphics.c | 135 ++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 42cea74..3e90384 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -47,58 +47,35 @@ static volatile int buffer_plans_size = 0; static int pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc // xyz, 0, x, y, z, xy, xz, yz, xyz - static int xxx = 0; static int yyy = 0; static int zzz = 0; -// assert : l'emplacement des flèches est contraint -// par model_space_size_x, y, z et le nombre de sites -static GLuint arrows[] = { - 1, 0, 0, 0, 0, - /* 1, 1, 0, 0, 0, */ - /* 1, 1, 1, 0, 0, */ - /* 1, 2, 0, 0, 0, */ - /* 1, 3, 0, 0, 0, */ - /* 1, 4, 0, 0, 0, */ - /* 1, 5, 0, 0, 0, */ -// load, site, x, y, z -}; - -static int get_arrows_nb(){ - if (sizeof(arrows) == 0) return 0; - else return sizeof(arrows) / sizeof(arrows[0]) / 5; -} - -static void show_user_choices(int space_size_x, - int space_size_y, - int space_size_z, - int prefer, - int show_all) +static void show_user_choices(GLuint *arrows, int arrows_nb, + int space_size_x, int space_size_y, int space_size_z, + int prefer, int show_all) { - int arrows_nb = get_arrows_nb(); printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\t", space_size_x, space_size_y, space_size_z); if (prefer == 0) printf("prefer = %d <> show all grids", prefer); if (prefer == 1) printf("prefer = %d <> show no grid", prefer); if (prefer > 1) printf("pref_show_grids = %d", prefer); if (show_all) { - printf("\n\t\t\t\t\tbuffer_vertex_size = %d\t buffer_lines_size = %d", buffer_vertex_size, buffer_lines_size); - if (arrows_nb > 0) printf("\n [%2d] load | site x y z \n -------------------------------", arrows_nb); + printf("\n\t\t\t\t\t buffer_vertex_size = %d\t buffer_lines_size = %d", buffer_vertex_size, buffer_lines_size); + if (arrows_nb > 0) printf("\n [%2d] load | site x y z\ + < Initial data\n -------------------------------", arrows_nb); for (int i = 0; i < arrows_nb; i++) printf("\n [%2d] = %2d | %2d %2d %2d %2d",\ i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4)); if (arrows_nb > 0) printf("\n -------------------------------");} } -static int set_arrow (int weight, int site, int x, int y, int z); - -static void get_model_data_and_user_preferences() +static void get_model_data_and_user_preferences(GLuint *arrows, int arrows_nb) { xxx = 2; // 0 < model_space_size_x yyy = 1; // 0 < model_space_size_y zzz = 1; // 0 < model_space_size_z pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc // xyz, 0, x, y, z, xy, xz, yz, xyz - show_user_choices(xxx, yyy, zzz, pref_show_grids, 1); + show_user_choices(arrows, arrows_nb, xxx, yyy, zzz, pref_show_grids, 1); } /* -------------------------------------------------------------------------- */ @@ -137,7 +114,7 @@ static void get_model_data_and_user_preferences() -static bool rewrite_arrow (int address, int weight, int site, int x, int y, int z) +static bool rewrite_arrow (GLuint *arrows, int arrows_nb, int address, int weight, int site, int x, int y, int z) { if (0) printf("write the arrow weight to %d at (%d, %d, %d, %d)\n",\ weight, site, x, y, z); @@ -147,12 +124,14 @@ static bool rewrite_arrow (int address, int weight, int site, int x, int y, int return 1; /* replaces the load of the existing arrow by the load 'weight' */ } -static bool create_arrow (int weight, int site, int x, int y, int z) +static bool create_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z) { - int arrows_nb = get_arrows_nb(); buffer_lines_size += (3 + 4) * 2; buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint)); + printf("\nbuffer_lines_size = %d weight = %d site = %d x = %d y = %d z = %d ",\ + buffer_lines_size, weight, site, x, y, z); + *(arrows + arrows_nb * 5 + 0) = weight; *(arrows + arrows_nb * 5 + 1) = site; *(arrows + arrows_nb * 5 + 2) = x; @@ -162,32 +141,32 @@ static bool create_arrow (int weight, int site, int x, int y, int z) return 1; } -static bool erase_arrow (int address, int site, int x, int y, int z) +static bool erase_arrow (GLuint *arrows, int arrows_nb, int address, int site, int x, int y, int z) { - int arrows_nb = get_arrows_nb(); - if (0) printf("erase arrow at address %d with values (%d, %d, %d, %d)",\ + if (1) printf("erase arrow at address (%d) with values (%d, %d, %d, %d)",\ address / 5, site, x, y, z); - if (0) printf(" last arrow is %d, %d, %d, %d, %d\n", + if (1) printf(" last arrow is %d, %d, %d, %d, %d\n", *(arrows + (arrows_nb - 1) * 5 + 0), *(arrows + (arrows_nb - 1) * 5 + 1), *(arrows + (arrows_nb - 1) * 5 + 2), *(arrows + (arrows_nb - 1) * 5 + 3), *(arrows + (arrows_nb - 1) * 5 + 4)); - *(arrows + address + 0) = *(arrows + (arrows_nb - 1) * 5 + 0); - *(arrows + address + 1) = *(arrows + (arrows_nb - 1) * 5 + 1); - *(arrows + address + 2) = *(arrows + (arrows_nb - 1) * 5 + 2); - *(arrows + address + 3) = *(arrows + (arrows_nb - 1) * 5 + 3); - *(arrows + address + 4) = *(arrows + (arrows_nb - 1) * 5 + 4); - arrows_nb --; + if (arrows_nb > 0) { + *(arrows + address + 0) = *(arrows + arrows_nb * 5 + 0); + *(arrows + address + 1) = *(arrows + arrows_nb * 5 + 1); + *(arrows + address + 2) = *(arrows + arrows_nb * 5 + 2); + *(arrows + address + 3) = *(arrows + arrows_nb * 5 + 3); + *(arrows + address + 4) = *(arrows + arrows_nb * 5 + 4); + } buffer_lines_size -= (3 + 4) * 2; buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint)); return 1; } -static void show_arrows_array (int arrows_nb, int address, int current_weigh, int weight, int site, int x, int y, int z) +static void show_arrows_array (GLuint *arrows, int arrows_nb, int address, int current_weigh, int weight, int site, int x, int y, int z) { printf("\nset_arrow (%d | %2d %2d %2d %2d) <> ", weight, site, x, y, z); @@ -240,12 +219,11 @@ static void show_arrows_array (int arrows_nb, int address, int current_weigh, in -static int set_arrow (int weight, int site, int x, int y, int z) +static int set_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z) { - // assert pas de flèche(s) doublons + // assert pas de doublons flèche(s) - int address = -1, current_weight = -1, - arrows_nb = get_arrows_nb(); + int address = -1, current_weight = -1; if (arrows_nb > 0) for (int i = 0; i < arrows_nb; i++) { @@ -260,12 +238,12 @@ static int set_arrow (int weight, int site, int x, int y, int z) } } - show_arrows_array(arrows_nb, address, current_weight, weight, site, x, y, z); + show_arrows_array(arrows, arrows_nb, address, current_weight, weight, site, x, y, z); if (address == -1 && weight == 0) return 0; - if (address == -1 && weight > 0) return create_arrow (weight, site, x, y, z); - if (address >= 0 && weight == 0) return erase_arrow (address, site, x, y, z); - if (address >= 0 && weight > 0) return rewrite_arrow (address, weight, site, x, y, z); + if (address == -1 && weight > 0) return create_arrow (arrows, arrows_nb, weight, site, x, y, z); + if (address >= 0 && weight == 0) return erase_arrow (arrows, arrows_nb, address, site, x, y, z); + if (address >= 0 && weight > 0) return rewrite_arrow (arrows, arrows_nb, address, weight, site, x, y, z); return 0; } @@ -501,8 +479,6 @@ void graphics_init_buffers(const void *gl_area) struct gl_area_entry *entry; entry = graphics_find_glarea_from_ptr(gl_area); - get_model_data_and_user_preferences(); - //XXX main_test_graphics (); @@ -846,6 +822,25 @@ void main_test_graphics (void) if (0) printf("buffer_vertex_offset_before_grid = %d\n", buffer_vertex_size / 3); +// assert : l'emplacement des flèches est contraint +// par model_space_size_x, y, z et le nombre de sites. TODO +// assert : pas de doublons de flèches. TODO + + int arrows[] = { + 1, 0, 0, 0, 0, + /* 1, 1, 0, 0, 0, */ + /* 1, 1, 1, 0, 0, */ + /* 1, 2, 0, 0, 0, */ + /* 1, 3, 0, 0, 0, */ + /* 1, 4, 0, 0, 0, */ + /* 1, 5, 0, 0, 0, */ + // load, site, x, y, z + }; + + int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5; + + get_model_data_and_user_preferences(arrows, arrows_nb); + /* GRID */ grid_write_intersections (xxx, yyy, zzz); @@ -858,10 +853,11 @@ void main_test_graphics (void) int offset_after_grids = buffer_vertex_size / 3; int buffer_lines_size_after_cubes = buffer_lines_size; - /* ARROWS */ - arrows_write_terminations (xxx, yyy, zzz); + int offset_up_to_this_cube_coords = 0, x,y,z; - int arrows_nb = get_arrows_nb(), offset_up_to_this_cube_coords = 0, x,y,z; + /* ARROWS */ + + arrows_write_terminations (xxx, yyy, zzz); // Independent of the number of arrows for (int i = 0; i < arrows_nb; i++) { weight = arrows[i * 5 + 0]; @@ -882,13 +878,13 @@ void main_test_graphics (void) } } - /* set_arrow (0, 1, 1, 0, 0); */ - /* set_arrow (0, 1, 0, 0, 0); */ - /* set_arrow (0, 0, 0, 0, 0); */ + /* set_arrow (arrows, arrows_nb, 0, 1, 1, 0, 0); */ + /* set_arrow (arrows, arrows_nb, 0, 1, 0, 0, 0); */ + set_arrow (arrows, arrows_nb, 0, 0, 0, 0, 0); - /* set_arrow (1, 0, 1, 0, 0); */ - /* set_arrow (1, 1, 1, 0, 0); */ - /* set_arrow (1, 0, 0, 0, 0); */ + set_arrow (arrows, arrows_nb, 1, 0, 1, 0, 0); + /* set_arrow (arrows, arrows_nb, 1, 1, 1, 0, 0); */ + /* set_arrow (arrows, arrows_nb, 1, 0, 0, 0, 0); */ int offset_after_arrows = buffer_vertex_size / 3, difference = offset_after_arrows - offset_after_grids; @@ -897,12 +893,13 @@ void main_test_graphics (void) if (1) printf("\nbuffer_vertex_offset_after arrows = %d\t\t(%d - %d = %d, %d / 12 <> %d cubes)",\ offset_after_arrows, offset_after_arrows, offset_after_grids,\ difference, difference, difference / 12); - if (1) printf("\nbuffer_lines_size after cubes = %d\t\t(%d x %d = %d\t%d x %d = %d\t%d x %d = %d\t%d + %d + %d = %d x 2 = %d)",\ - buffer_lines_size_after_cubes, xxx+1, yyy+1, (xxx+1) * (yyy+1), xxx+1, zzz+1, (xxx+1) * (zzz+1), yyy+1, zzz+1, (yyy+1) * (zzz+1),\ - (xxx+1) * (yyy+1), (xxx+1) * (zzz+1), (yyy+1) * (zzz+1), (xxx+1) * (yyy+1) + (xxx+1) * (zzz+1) + (yyy+1) * (zzz+1),\ + if (1) printf("\nbuffer_lines_size after cubes = %d\t\t(%d x %d + %d x %d + %d x %d = %d) (x 2 = %d)",\ + buffer_lines_size_after_cubes, xxx+1, yyy+1, xxx+1, zzz+1, yyy+1, zzz+1,\ + (xxx+1) * (yyy+1) + (xxx+1) * (zzz+1) + (yyy+1) * (zzz+1),\ ((xxx+1) * (yyy+1) + (xxx+1) * (zzz+1) + (yyy+1) * (zzz+1)) * 2); - if (1) printf("\nbuffer_lines_size after arrows = %d\t\t(%d - %d = %d;\t3 + 4 = 7\t7 x 2 = 14\n", buffer_lines_size,\ - buffer_lines_size, buffer_lines_size_after_cubes, buffer_lines_size - buffer_lines_size_after_cubes); + if (1) printf("\nbuffer_lines_size after arrows = %d\t\t(%d - %d = %d;\t(3 + 4) x %d = %d (x 2 = %d)\n", buffer_lines_size,\ + buffer_lines_size, buffer_lines_size_after_cubes, buffer_lines_size - buffer_lines_size_after_cubes,\ + arrows_nb, arrows_nb * 7, arrows_nb * 14); if (0) printf("main_test_graphics [ok]\n"); }