WIP: Ça a l'air de marcher (modify, erase) sauf que 'erase' écrase toujours 7 lignes des grids
This commit is contained in:
parent
507583d87b
commit
8b141f8844
|
@ -608,40 +608,6 @@ 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)
|
|
||||||
{
|
|
||||||
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,
|
static void show_user_choices(GLuint *arrows, int arrows_nb,
|
||||||
int space_size_x, int space_size_y, int space_size_z,
|
int space_size_x, int space_size_y, int space_size_z,
|
||||||
|
@ -657,24 +623,70 @@ static void show_user_choices(GLuint *arrows, int arrows_nb,
|
||||||
< initial arrows data\n -------------------------------", arrows_nb);
|
< initial arrows data\n -------------------------------", arrows_nb);
|
||||||
for (int i = 0; i < arrows_nb; i++) printf("\n [%2d] = %2d | %2d %2d %2d %2d",\
|
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));
|
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");}
|
if (arrows_nb > 0) printf("\n -------------------------------");}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* static void show_arrows_array_old (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); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
static bool rewrite_arrow (GLuint *arrows, int arrows_nb, int address, int weight, int site, int x, int y, int z)
|
/* printf(" [rank] load | site x y z\n"); */
|
||||||
|
/* for (int i = 0; i < arrows_nb; i++) */
|
||||||
|
/* { */
|
||||||
|
/* if (address == -1 && weight == 0) printf("(address == -1 && weight == 0) > END"); */
|
||||||
|
/* if (address == -1 && weight > 0) {printf("(address == %d && weight == %d) > Create", address/5, weight); create_arrow (arrows, arrows_nb, weight, site, x, y, z);} */
|
||||||
|
/* if (address >= 0 && weight == 0) {printf("(address == %d && weight == %d) > Erase", address/5, weight); erase_arrow (arrows, arrows_nb, address, site, x, y, z);} */
|
||||||
|
/* if (address >= 0 && current_weight == weight) printf("(address found && current_weight == weight) > END"); */
|
||||||
|
/* if (address >= 0 && current_weight != weight) {printf("(address == %d && %d != %d) > Modify", address/5, current_weight, weight); */
|
||||||
|
/* rewrite_arrow (arrows, arrows_nb, address/5, weight, site, x, y, z);} */
|
||||||
|
|
||||||
|
/* 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 (address >= 0 && current_weigh != weight) */
|
||||||
|
/* 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_arrows_array (GLuint *arrows, int arrows_nb, int address, int current_weigh, int weight, int site, int x, int y, int z)
|
||||||
{
|
{
|
||||||
show_arrows_array(arrows, arrows_nb, address, *(arrows + address + 0), weight, site, x, y, z);
|
printf("\n [rank] load | site x y z");
|
||||||
|
for (int i = 0; i < arrows_nb; i++)
|
||||||
*(arrows + address + 0) = weight;
|
printf("\n [%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 (1) printf("the new arrow weight is %d at (%d, %d, %d, %d)\n", weight, site, x, y, z);
|
|
||||||
|
|
||||||
return 1; /* replaces the load of the existing arrow by the new load 'weight' */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool create_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z)
|
|
||||||
|
|
||||||
|
/* replaces the current load of the arrow at address (address) by the new load 'weight' */
|
||||||
|
static int rewrite_arrow (GLuint *arrows, int arrows_nb, int address, int weight, int site, int x, int y, int z)
|
||||||
|
{
|
||||||
|
*(arrows + address * 5 + 0) = weight;
|
||||||
|
show_arrows_array (arrows, arrows_nb, address, *(arrows + address + 0), weight, site, x, y, z);
|
||||||
|
return arrows_nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int create_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (0) printf("\ncreating the new arrow (%d, %d, %d, %d, %d)",\
|
if (0) printf("\ncreating the new arrow (%d, %d, %d, %d, %d)",\
|
||||||
weight, site, x, y, z);
|
weight, site, x, y, z);
|
||||||
|
@ -682,6 +694,8 @@ static bool create_arrow (GLuint *arrows, int arrows_nb, int weight, int site, i
|
||||||
buffer_lines_size += (3 + 4) * 2;
|
buffer_lines_size += (3 + 4) * 2;
|
||||||
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLuint));
|
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLuint));
|
||||||
|
|
||||||
|
arrows_nb --; //////////////////////////////////////////////// ?
|
||||||
|
|
||||||
*(arrows + arrows_nb * 5 + 0) = weight;
|
*(arrows + arrows_nb * 5 + 0) = weight;
|
||||||
*(arrows + arrows_nb * 5 + 1) = site;
|
*(arrows + arrows_nb * 5 + 1) = site;
|
||||||
*(arrows + arrows_nb * 5 + 2) = x;
|
*(arrows + arrows_nb * 5 + 2) = x;
|
||||||
|
@ -693,12 +707,13 @@ static bool create_arrow (GLuint *arrows, int arrows_nb, int weight, int site, i
|
||||||
printf("buffer_lines_size = %d\tarrow (%d, %d, %d, %d, %d) was created",\
|
printf("buffer_lines_size = %d\tarrow (%d, %d, %d, %d, %d) was created",\
|
||||||
buffer_lines_size, weight, site, x, y, z);
|
buffer_lines_size, weight, site, x, y, z);
|
||||||
|
|
||||||
return 1;
|
return arrows_nb;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool erase_arrow (GLuint *arrows, int arrows_nb, int address, int site, int x, int y, int z)
|
static int erase_arrow (GLuint *arrows, int arrows_nb, int address, int site, int x, int y, int z)
|
||||||
{
|
{
|
||||||
arrows_nb --;
|
arrows_nb --;
|
||||||
|
printf("\nerase_arrow (arrows_nb %d, address %d, site %d, x %d, y %d, z %d) \n", arrows_nb, address / 5, site, x, y, z);
|
||||||
|
|
||||||
if (arrows_nb > 0) {
|
if (arrows_nb > 0) {
|
||||||
*(arrows + address + 0) = *(arrows + arrows_nb * 5 + 0);
|
*(arrows + address + 0) = *(arrows + arrows_nb * 5 + 0);
|
||||||
|
@ -711,21 +726,16 @@ static bool erase_arrow (GLuint *arrows, int arrows_nb, int address, int site, i
|
||||||
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLuint));
|
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLuint));
|
||||||
|
|
||||||
show_arrows_array(arrows, arrows_nb, address, -1, 0, site, x, y, z);
|
show_arrows_array(arrows, arrows_nb, address, -1, 0, site, x, y, z);
|
||||||
|
return arrows_nb;
|
||||||
if (1) printf("arrow previously at address (%d) with values (%d, %d, %d, %d) was erased;\
|
|
||||||
last arrow is now : (%d, %d, %d, %d, %d)\n", address / 5, site, x, y, z, *(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));
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void set_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z)
|
static int set_arrow (GLuint *arrows, int arrows_nb, int requested_weight, int site, int x, int y, int z)
|
||||||
{
|
{
|
||||||
// assert pas de doublons flèche(s)
|
// assert : no more than one arrow per address pas de doublons de flèches
|
||||||
|
// assert : arrows localization within space and sites
|
||||||
int address = -1, current_weight = -1;
|
int address = -1, current_weight = -1;
|
||||||
|
|
||||||
for (int i = 0; i < arrows_nb; i++) {
|
for (int i = 0; i < arrows_nb; i++) {
|
||||||
|
@ -740,14 +750,21 @@ static void set_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\set_arrow() invoked with (arrows_nb = %d, address = %d, current_weight = %d) > ", arrows_nb, address/5, current_weight);
|
printf("\nset_arrow() invoked with requested weight = %d > ", requested_weight);
|
||||||
|
|
||||||
if (address == -1 && weight == 0) printf("(address == -1 && weight == 0) > END\n");
|
if (address == -1 && requested_weight == 0) {printf("no such arrow found && requested weight == 0 => END"); return arrows_nb;}
|
||||||
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 == -1 && requested_weight > 0) {printf("(no such arrow found && requested weight == %d) => Create", requested_weight); return create_arrow (arrows, arrows_nb, requested_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 && requested_weight == 0) {printf("arrow (%d,%d,%d,%d) found at address %d; current_weight = %d;\n\
|
||||||
if (address >= 0 && current_weight == weight) printf("(address = %d && current_weight == weight) > END\n", address/5);
|
requested weight == %d => Erase",\
|
||||||
if (address >= 0 && current_weight != weight) {printf("(address == %d && %d != %d) > Modify\n", address, current_weight, weight);
|
arrows[address + 1],arrows[address + 2],arrows[address + 3],arrows[address + 4], address/5, current_weight, requested_weight);
|
||||||
rewrite_arrow (arrows, arrows_nb, address/5, weight, site, x, y, z);}
|
return erase_arrow (arrows, arrows_nb, address, site, x, y, z);}
|
||||||
|
if (address >= 0 && current_weight == requested_weight) {printf("arrow (%d,%d,%d,%d) found at address %d; current_weight == requested_weight => END",\
|
||||||
|
arrows[address + 1],arrows[address + 2],arrows[address + 3],arrows[address + 4], address); return arrows_nb;}
|
||||||
|
if (address >= 0 && current_weight != requested_weight) {printf("arrow (%d,%d,%d,%d) found at address %d; current_weight = %d;\n\
|
||||||
|
current weight != requested weight => Modify",\
|
||||||
|
arrows[address + 1],arrows[address + 2],arrows[address + 3],arrows[address + 4], address/5, current_weight);
|
||||||
|
return rewrite_arrow (arrows, arrows_nb, address/5, requested_weight, site, x, y, z);}
|
||||||
|
return arrows_nb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -786,8 +803,9 @@ void main_test_graphics (void)
|
||||||
* are always defined (whether arrows are drawn or not). */
|
* are always defined (whether arrows are drawn or not). */
|
||||||
arrows_write_terminations (space_X, space_Y, space_Z);
|
arrows_write_terminations (space_X, space_Y, space_Z);
|
||||||
|
|
||||||
// set_arrow (arrows, arrows_nb, 0, 0, 0, 0, 0); arrows_nb --;
|
// arrows_nb = set_arrow (arrows, arrows_nb, 0, 0, 0, 0, 0);
|
||||||
set_arrow (arrows, arrows_nb, 1, 1, 3, 0, 0); arrows_nb ++;
|
arrows_nb = set_arrow (arrows, arrows_nb, 8, 1, 3, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 1, 0, 0);
|
||||||
|
|
||||||
int weight = 0, site = 0,
|
int weight = 0, site = 0,
|
||||||
stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0;
|
stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0;
|
||||||
|
@ -814,6 +832,7 @@ void main_test_graphics (void)
|
||||||
|
|
||||||
int offset_after_arrows = buffer_vertex_size / 3, difference = offset_after_arrows - offset_after_grids;
|
int offset_after_arrows = buffer_vertex_size / 3, difference = offset_after_arrows - offset_after_grids;
|
||||||
|
|
||||||
|
printf("\n - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||||
printf("\n buffer_vertex_offset_after grids = %6d\t%6d = (x+1)*(y+1)*(z+1); <--> (x,y,z = %d,%d,%d)",\
|
printf("\n buffer_vertex_offset_after grids = %6d\t%6d = (x+1)*(y+1)*(z+1); <--> (x,y,z = %d,%d,%d)",\
|
||||||
offset_after_grids, (space_X + 1)*(space_Y + 1)*(space_Z + 1), space_X, space_Y, space_Z);
|
offset_after_grids, (space_X + 1)*(space_Y + 1)*(space_Z + 1), space_X, space_Y, space_Z);
|
||||||
printf("\n buffer_vertex_offset_after arrows = %6d\t%6d = %d + %d; <--> %d = 12 x %d (there are %d cubes)",\
|
printf("\n buffer_vertex_offset_after arrows = %6d\t%6d = %d + %d; <--> %d = 12 x %d (there are %d cubes)",\
|
||||||
|
|
Loading…
Reference in New Issue