WIP: micro-commit minimes modifs de set_arrows() + cosmétique

This commit is contained in:
Jean Sirmai 2023-09-27 11:56:34 +02:00
parent fe8dccbe43
commit 507583d87b
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 78 additions and 99 deletions

View File

@ -609,7 +609,59 @@ bool graphics_shutdown(const void *gl_area)
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);
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);
if (arrows_nb == 0 && weight == 0) printf("buffer_lines_size = %d\tno arrow in space + no arrows to be created > end function set_arrow()\n", buffer_lines_size);
if (address == -1 && weight == 0) printf("buffer_lines_size = %d\tarrow not found + no arrows to be created > end function set_arrow()\n", buffer_lines_size);
if (address == -1 && weight > 0) printf("buffer_lines_size = %d\tarrow (%d, %d, %d, %d, %d) not found > new arrow will be created at line [%d]\n",\
buffer_lines_size, arrows_nb, weight, site, x, y, z);
if (address >= 0 && weight == 0) printf("buffer_lines_size = %d\tarrow found at line [%d] > will be erased\n", buffer_lines_size, address / 5);
if (address >= 0 && weight > 0) {
if (current_weigh != weight) printf("buffer_lines_size = %d\tarrow found at line [%d] > will be modified\n", buffer_lines_size, address / 5);
if (current_weigh == weight) printf("buffer_lines_size = %d\tarrow found at line [%d] > will not be modified\n", buffer_lines_size, address / 5);
}
printf(" [rank] load | site x y z\n");
for (int i = 0; i < arrows_nb; i++)
{
printf(" [%4d] = %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 (weight == 0 && i == address / 5) printf(" <<<| < - > (%d, %d, %d, %d) moved at [%2d]",\
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
if (weight > 0 && current_weigh != weight && i == arrows_nb - 1 && address >= 0)
printf(" <<< < + > (%d, %d, %d, %d) added at [%2d]",\
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
if (weight > 0 && current_weigh == weight && i == address / 5) printf(" <");
if (weight == 0 && i > address / 5 && i < arrows_nb - 1) printf(" |");
if (weight == 0 && i == arrows_nb - 1 && i != address / 5) printf(" |");
printf("\n");
}
}
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)
{
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("show grids according rule (%d)", prefer);
if (show_all) {
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 arrows 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 -------------------------------\n");}
}
static bool rewrite_arrow (GLuint *arrows, int arrows_nb, int address, int weight, int site, int x, int y, int z)
{
@ -670,13 +722,12 @@ static bool erase_arrow (GLuint *arrows, int arrows_nb, int address, int site, i
static int set_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z)
static void set_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z)
{
// assert pas de doublons flèche(s)
int address = -1, current_weight = -1;
if (arrows_nb > 0)
for (int i = 0; i < arrows_nb; i++) {
if ((site == *(arrows + i * 5 + 1))
&& (x == *(arrows + i * 5 + 2))
@ -689,87 +740,25 @@ static int set_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x
}
}
if (address == -1 && weight == 0) return 0;
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 && current_weight != weight) return rewrite_arrow (arrows, arrows_nb, address, weight, site, x, y, z);
return 0;
printf("\set_arrow() invoked with (arrows_nb = %d, address = %d, current_weight = %d) > ", arrows_nb, address/5, current_weight);
if (address == -1 && weight == 0) printf("(address == -1 && weight == 0) > END\n");
if (address == -1 && weight > 0) {printf("(address == %d && weight == %d) > Create\n", address/5, weight); create_arrow (arrows, arrows_nb, weight, site, x, y, z);}
if (address >= 0 && weight == 0) {printf("(address == %d && weight == %d) > Erase\n", address/5, weight); erase_arrow (arrows, arrows_nb, address, site, x, y, z);}
if (address >= 0 && current_weight == weight) printf("(address = %d && current_weight == weight) > END\n", address/5);
if (address >= 0 && current_weight != weight) {printf("(address == %d && %d != %d) > Modify\n", address, current_weight, weight);
rewrite_arrow (arrows, arrows_nb, address/5, weight, site, x, y, 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);
if (arrows_nb == 0 && weight == 0) printf("buffer_lines_size = %d\tno arrow in space + no arrows to be created > end function set_arrow()\n", buffer_lines_size);
if (address == -1 && weight == 0) printf("buffer_lines_size = %d\tarrow not found + no arrows to be created > end function set_arrow()\n", buffer_lines_size);
if (address == -1 && weight > 0) printf("buffer_lines_size = %d\tarrow (%d, %d, %d, %d, %d) not found > new arrow will be created at line [%d]\n",\
buffer_lines_size, arrows_nb, weight, site, x, y, z);
if (address >= 0 && weight == 0) printf("buffer_lines_size = %d\tarrow found at line [%d] > will be erased\n", buffer_lines_size, address / 5);
if (address >= 0 && weight > 0) {
if (current_weigh != weight) printf("buffer_lines_size = %d\tarrow found at line [%d] > will be modified\n", buffer_lines_size, address / 5);
if (current_weigh == weight) printf("buffer_lines_size = %d\tarrow found at line [%d] > will not be modified\n", buffer_lines_size, address / 5);
}
printf(" [rank] load | site x y z\n");
for (int i = 0; i < arrows_nb; i++)
{
printf(" [%4d] = %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 (weight == 0 && i == address / 5) printf(" <<<| < - > (%d, %d, %d, %d) moved at [%2d]",\
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
if (weight > 0 && current_weigh != weight && i == arrows_nb - 1 && address >= 0)
printf(" <<< < + > (%d, %d, %d, %d) added at [%2d]",\
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
if (weight > 0 && current_weigh == weight && i == address / 5) printf(" <");
if (weight == 0 && i > address / 5 && i < arrows_nb - 1) printf(" |");
if (weight == 0 && i == arrows_nb - 1 && i != address / 5) printf(" |");
printf("\n");
}
}
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)
{
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("show grids according rule (%d)", prefer);
if (show_all) {
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 -------------------------------\n");}
}
void main_test_graphics (void)
{
// assert : space dimensions (x,y,z) > 0 TODO
// assert : arrows localization within space and sites TODO
// assert : no more than one arrow per address TODO
// assert : space dimensions (x,y,z) > 0 TODO NOT checked before init
// assert : arrows localization within space and sites TODO NOT checked when invoking set_arrow()
// assert : no more than one arrow per address TODO NOT checked before init
// notify : weights are replaced, NOT added (could be !) TODO
int space_X = 4, space_Y = 1, space_Z = 1;
int pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
@ -781,34 +770,24 @@ void main_test_graphics (void)
1, 1, 3, 0, 0,
// load, site, x, y, z
};
int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5;
show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1);
/* GRID */
grid_write_intersections (space_X, space_Y, space_Z);
if (pref_show_grids % 2 == 0) grid_write_x (space_X, space_Y, space_Z);
if (pref_show_grids % 3 == 0) grid_write_y (space_X, space_Y, space_Z);
if (pref_show_grids % 5 == 0) grid_write_z (space_X, space_Y, space_Z);
if (pref_show_grids > 0) grid_write_ridges (space_X, space_Y, space_Z);
int offset_after_grids = buffer_vertex_size / 3;
int buffer_lines_size_after_cubes = buffer_lines_size;
int offset_up_to_this_cube_coords = 0, x, y, z;
/* ARROWS */
/* The 12 vertices required to draw 6 arrows in each cube
* are always defined (whether arrows are drawn or not). */
arrows_write_terminations (space_X, space_Y, space_Z);
// set_arrow (arrows, arrows_nb, 0, 0, 0, 0, 0); arrows_nb --;
// set_arrow (arrows, arrows_nb, 1, 0, 5, 0, 0); arrows_nb ++;
set_arrow (arrows, arrows_nb, 1, 1, 3, 0, 0); arrows_nb ++;
int weight = 0, site = 0,
stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0;