WIP: Ok console; Ok graphisme (sauf inversion N/S) pour de petits nombres aléatoires

This commit is contained in:
Jean Sirmai 2023-11-03 16:50:51 +01:00
parent bbfd2fdd6c
commit 54bd80b9d0
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 17 additions and 32 deletions

View File

@ -622,18 +622,12 @@ static inline int create_arrow (int arrows_nb,
arrows_ptr[arrows_nb].y = y; arrows_ptr[arrows_nb].y = y;
arrows_ptr[arrows_nb].z = z; arrows_ptr[arrows_nb].z = z;
write_one_arrow_vertex(space_X, space_Y, space_Z, write_one_arrow_vertex(space_X, space_Y, space_Z, load, site, x, y, z, console);
load, site, x, y, z, console);
/* L'incrémentation de buffer_colors_size
* est faite dans graphics_write_color()
* > donc: ligne suivante inutile */
/* buffer_colors_size = buffer_vertex_size; */
write_one_arrow_line (buffer_vertex_size / 3 - 2, console); write_one_arrow_line (buffer_vertex_size / 3 - 2, console);
arrows_nb ++; arrows_nb ++;
if (0) print_arrows_array (arrows_ptr, arrows_nb, 1); if (console) print_arrows_array (arrows_ptr, arrows_nb, 1);
return arrows_nb; return arrows_nb;
} }
@ -645,7 +639,7 @@ static inline int erase_arrow (int arrows_nb, int arrow_address_in_list,
if (arrows_nb == 0) assert (buffer_lines_size == buffer_lines_0_arrow); // ? if (arrows_nb == 0) assert (buffer_lines_size == buffer_lines_0_arrow); // ?
if (arrows_nb == 0) {buffer_lines_size = buffer_lines_0_arrow; return 0;} if (arrows_nb == 0) {buffer_lines_size = buffer_lines_0_arrow; return 0;}
if (1) print_arrows_array (arrows_ptr, arrows_nb, 7); if (console) print_arrows_array (arrows_ptr, arrows_nb, 7);
assert (arrows_nb); assert (arrows_nb);
arrows_nb --; arrows_nb --;
@ -691,8 +685,8 @@ static inline int erase_arrow (int arrows_nb, int arrow_address_in_list,
/* if (new_arrows_lines_ptr) buffer_lines_origin = new_arrows_lines_ptr; */ /* 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"); */ /* else perror("In graphics.erase_arrow(), can't re_allocate for arrows lines buffer.\n"); */
if (1) print_arrows_array (arrows_ptr, arrows_nb, 0); if (console) print_arrows_array (arrows_ptr, arrows_nb, 0);
if (1) printf("\n"); if (console) printf("\n");
return arrows_nb; return arrows_nb;
} }
@ -704,8 +698,8 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int spac
{ {
int address = -1, current_weight = -1; int address = -1, current_weight = -1;
printf("in set_arrow (begin) arrows_nb = %d requested site: %d > ", arrows_nb, site); if (console) printf("in set_arrow (begin) arrows_nb = %d requested site: %d > ", arrows_nb, site);
for (int i = 0; i < arrows_nb; i++) {printf(" [%d] = %d ", i, arrows_ptr[i].site); if (site == arrows_ptr[i].site) break;} if (console) for (int i = 0; i < arrows_nb; i++) {printf(" [%d] = %d ", i, arrows_ptr[i].site); if (site == arrows_ptr[i].site) break;}
for (int i = 0; i < arrows_nb; i++) for (int i = 0; i < arrows_nb; i++)
if ((site == arrows_ptr[i].site) if ((site == arrows_ptr[i].site)
@ -718,11 +712,12 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int spac
break; break;
} }
assert (address <= arrows_nb); assert (address <= arrows_nb);
if (console) {
if (address == -1 && requested_weight > 0) printf(" >> create_arrow() at site %d\n", site); if (address == -1 && requested_weight > 0) printf(" >> create_arrow() at site %d\n", site);
if (address >= 0 && requested_weight == 0) printf(" >> erase_arrow() at site %d\n", site); if (address >= 0 && requested_weight == 0) printf(" >> erase_arrow() at site %d\n", site);
if (address >= 0 && current_weight != requested_weight) printf(" >> rewrite_arrow() at site %d\n", site); if (address >= 0 && current_weight != requested_weight) printf(" >> rewrite_arrow() at site %d\n", site);
if (address == -1 && requested_weight == 0) printf(" >> no operation\n"); if (address == -1 && requested_weight == 0) printf(" >> no operation\n");
}
if (address == -1 && requested_weight > 0) 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); return create_arrow (arrows_nb, space_X, space_Y, space_Z, requested_weight, site, arrow_x, arrow_y, arrow_z, console);
if (address >= 0 && requested_weight == 0) // address >= 0 if and only if arrows_nb > 0 if (address >= 0 && requested_weight == 0) // address >= 0 if and only if arrows_nb > 0
@ -740,15 +735,13 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int spac
void main_test_graphics (void) void main_test_graphics (void)
{ {
srand(time(NULL)); int rand(void); void srand(unsigned int seed); srand(time(NULL)); int rand(void); void srand(unsigned int seed);
int randomize = 0, console = 0, arrows_nb = 0, space_X = 1, space_Y = 1, space_Z = 1; int randomize = 7, console = 0, arrows_nb = 0, space_X = 1, space_Y = 1, space_Z = 1;
if (randomize) { if (randomize) {
space_X = 1 + rand() % randomize; space_X = 1 + rand() % randomize;
space_Y = 1 + rand() % randomize; space_Y = 1 + rand() % randomize;
space_Z = 1 + rand() % randomize; space_Z = 1 + rand() % randomize;
} }
int density_max = space_X * space_Y * space_Z, specified_arrows_nb = rand() % density_max; int density_max = space_X * space_Y * space_Z, specified_arrows_nb = rand() % density_max;
if (randomize) printf("density_max = %d; specified_arrows_nb = %d\n",\
density_max, specified_arrows_nb);
int max = fmax(space_X, space_Y); max = fmax(max, space_Z); int max = fmax(space_X, space_Y); max = fmax(max, space_Z);
/* S P A C E */ /* S P A C E */
@ -776,24 +769,16 @@ void main_test_graphics (void)
arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 1, i, 0, 0, 0, 0); arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 1, i, 0, 0, 0, 0);
int max_arrows_nb = arrows_nb; int max_arrows_nb = arrows_nb;
if (randomize); print_user_choices(arrows_ptr, max_arrows_nb, arrows_nb, space_X, space_Y, space_Z, 0, 0);
if (randomize) for (int i = 0; i < specified_arrows_nb * 6; i++) if (randomize) for (int i = 0; i < specified_arrows_nb * 6; i++)
arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z,
0, // load rand() % 1, // load
rand() % 6, // site rand() % 6, // site
rand() % space_X, // x rand() % space_X, // x
rand() % space_Y, // y rand() % space_Y, // y
rand() % space_Z, // z rand() % space_Z, // z
console); console);
/* else for (int i = 0; i < 1; i++) ; */ else for (int i = 0; i < 6; i++)
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, 0, 0, 0, 0, 1); */ arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, i, 0, 0, 0, 1);
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, 1, 0, 0, 0, 1); */
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, 2, 0, 0, 0, 1); */
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, 3, 0, 0, 0, 1); */
arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, 4, 0, 0, 0, 1);
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, 5, 0, 0, 0, 1); */
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, 6, 0, 0, 0, 1); */
if (randomize) print_user_choices(arrows_ptr, max_arrows_nb, arrows_nb, space_X, space_Y, space_Z, 1, 0); if (randomize) print_user_choices(arrows_ptr, max_arrows_nb, arrows_nb, space_X, space_Y, space_Z, 1, 0);