From 01fcc4f69eed849556cea9193090017ea1dc7490 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 16 Oct 2023 21:32:14 +0200 Subject: [PATCH] =?UTF-8?q?REF:=20OK=20POUR=20DES=20PETITES=20VALEURS=20(R?= =?UTF-8?q?ANDOM)=20-=20VERTEX=20&=20LIGNES=20GROUP=C3=89ES?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/displays.h | 7 +- src/graphics/displays.c | 74 +++++++++++++++++++ src/graphics/graphics.c | 158 +--------------------------------------- 3 files changed, 81 insertions(+), 158 deletions(-) diff --git a/include/displays.h b/include/displays.h index 4a129c1..6a33d23 100644 --- a/include/displays.h +++ b/include/displays.h @@ -38,8 +38,11 @@ void show_arrows_array_head(int one_batch_size, long nb_batches_specified, int v void show_one_arrow_in_array(struct arrow_t *arrows, int i); void show_empty_arrows_array(); void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int y, int z); - - +void print_user_action(struct arrow_t *arrows, int arrows_nb, int address, int requested_weight, + int current_weight, int site, int x, int y, int z); +void print_user_choices(struct arrow_t *arrows, int arrows_nb, + int space_size_x, int space_size_y, int space_size_z, + int show_array, int show_space_design); /* * Prints the initial user choices : * - space dimension size and appearance (grids) diff --git a/src/graphics/displays.c b/src/graphics/displays.c index fc23e76..6d0cfc3 100644 --- a/src/graphics/displays.c +++ b/src/graphics/displays.c @@ -30,6 +30,43 @@ +/* Prints the arrows[] array + * + * For each arrow the following parameters are displayed : + * - rank in the array + * - load (or weight) + * - coordinates in space (site, x, y, z) + */ +static void print_arrows_array (struct arrow_t *arrows, int arrows_nb) +{ + printf(" [rank] load | site x y z"); + for (int i = 0; i < arrows_nb; i++) + printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, arrows[i].load,\ + arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z); + if (arrows_nb == 0) printf("\n [NULL] ---- | ---- --- --- ---"); + printf("\n"); +} + + +/* Prints the initial user choices : + * - space dimension size and appearance (grids) + * - arrows[] array + * NB The space may be empty or saturated with arrows or any value in between + * Only one arrow per possible coordinates with a load max equal to ? TODO + */ +void print_user_choices(struct arrow_t *arrows, int arrows_nb, + int space_size_x, int space_size_y, int space_size_z, + int show_array, int show_space_design) +{ + printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\tarrows nb = %d\t",\ + space_size_x, space_size_y, space_size_z, arrows_nb); + + if (show_space_design) printf("orientations grilles alternées"); + printf("\n"); + + if (show_array) print_arrows_array (arrows, arrows_nb); +} + /* * Prints the arrows[] array * @@ -154,3 +191,40 @@ void show_buffers_states(int space_X, int space_Y, int space_Z, nb_batches_specified * one_batch_size - (buffer_lines_size - buffer_lines_size_after_cubes) / 14); } + + +/* + * Prints the result of the function set_arrow() + * and indicates the reasons of the choice (call) this function makes (see this function) + */ +void print_user_action(struct arrow_t *arrows, int arrows_nb, int address, int requested_weight, + int current_weight, int site, int x, int y, int z) +{ + if (address == -1 && requested_weight > 0) { // *(arrows + i * 5 + 0) + printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); //arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]); + if (! TEST) printf("\n "); else printf(" "); + printf("=> CREATE"); return;} + + if (address >= 0 && requested_weight == 0) { + printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); + if (! TEST) printf("\n "); else printf(" "); + printf("=> ERASE"); return;} + + if (address >= 0 && current_weight != requested_weight) { + printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); + if (! TEST) printf("\n "); else printf(" "); + printf("=> MODIFY"); return;} + + if (address >= 0 && current_weight == requested_weight){ + printf("arrow (%2d,%2d,%2d,%2d) found at address %2d;", site, x, y, z, address); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5); + if (! TEST) printf("\n "); else printf(" "); + printf("requested_weight == current_weight => END"); return;} + + if (address == -1 && requested_weight == 0) { + printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]); + if (! TEST) printf("\n "); else printf(" "); + printf("=> END"); return;} +} + + + diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index e2492f2..e621e42 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -540,82 +540,6 @@ bool graphics_shutdown(const void *gl_area) return true; } - - - - - - - - - - - - - - - - - - - -/* - * Prints the arrows[] array - * - * For each arrow the following parameters are displayed : - * - rank in the array - * - load (or weight) - * - coordinates in space (site, x, y, z) - */ -static void print_arrows_array (struct arrow_t *arrows, int arrows_nb) -{ - printf(" [rank] load | site x y z"); - for (int i = 0; i < arrows_nb; i++) - printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, arrows[i].load,\ - arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z); - if (arrows_nb == 0) printf("\n [NULL] ---- | ---- --- --- ---"); - printf("\n"); -} - -/* - * Prints the initial user choices : - * - space dimension size and appearance (grids) - * - arrows[] array - * NB The space may be empty or saturated with arrows or any value in between - * Only one arrow per possible coordinates with a load max equal to ? TODO - */ -static void print_user_choices(struct arrow_t *arrows, int arrows_nb, - int space_size_x, int space_size_y, int space_size_z, - int show_array, int show_space_design) -{ - printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\tarrows nb = %d\t",\ - space_size_x, space_size_y, space_size_z, arrows_nb); - - if (show_space_design) printf("orientations grilles alternées"); - printf("\n"); - - if (show_array) print_arrows_array (arrows, arrows_nb); -} - - - - - - - - - - - - - - - - - - - - /* * Assigns a new load to the arrow at address (address) @@ -733,84 +657,6 @@ static inline int set_arrow (struct arrow_t *arrows, int arrows_nb, int requeste } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/* - * Prints the result of the function set_arrow() - * and indicates the reasons of the choice (call) this function makes (see this function) - */ -static void show_user_action(struct arrow_t *arrows, int arrows_nb, int address, int requested_weight, - int current_weight, int site, int x, int y, int z) -{ - if (address == -1 && requested_weight > 0) { // *(arrows + i * 5 + 0) - printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); //arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]); - if (! TEST) printf("\n "); else printf(" "); - printf("=> CREATE"); return;} - - if (address >= 0 && requested_weight == 0) { - printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); - if (! TEST) printf("\n "); else printf(" "); - printf("=> ERASE"); return;} - - if (address >= 0 && current_weight != requested_weight) { - printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); - if (! TEST) printf("\n "); else printf(" "); - printf("=> MODIFY"); return;} - - if (address >= 0 && current_weight == requested_weight){ - printf("arrow (%2d,%2d,%2d,%2d) found at address %2d;", site, x, y, z, address); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5); - if (! TEST) printf("\n "); else printf(" "); - printf("requested_weight == current_weight => END"); return;} - - if (address == -1 && requested_weight == 0) { - printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]); - if (! TEST) printf("\n "); else printf(" "); - printf("=> END"); return;} -} - - - -//#define RAND_MAX /* * Init space and arrows (= initial state) * and allows ulterior creations, suppressions or modifications of the arrows[] array @@ -836,7 +682,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) int density_max = space_X * space_Y * space_Z; int max = fmax(space_X, space_Y); max = fmax(max, space_Z); - int show_space_design = 0, print_arrows_array = 0; + int show_space_design = 0, print_arrows_data = 0; int load = 0, site = 0, x = 0, y = 0, z = 0; int specif_arrows_nb = rand() % density_max / 3; @@ -851,7 +697,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) rand() % space_Z); // z } - print_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, print_arrows_array, show_space_design); + print_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, show_space_design); /* DATA ARE NOW ALL SPECIFIED - DRAWING CAN START */