diff --git a/include/arrows.h b/include/arrows.h index c032fa4..45d4ea6 100644 --- a/include/arrows.h +++ b/include/arrows.h @@ -39,7 +39,7 @@ typedef struct arrow_t { }; int write_one_arrow_vertex (int space_X, int space_Y, int space_Z, - int weight, int site, int x, int y, int z); + int weight, int site, int x, int y, int z, int print); -int write_one_arrow_line(int offset_vertex); +int write_one_arrow_line(int offset_vertex, int print); diff --git a/include/displays.h b/include/displays.h index ebbf727..a9c15c6 100644 --- a/include/displays.h +++ b/include/displays.h @@ -41,7 +41,7 @@ void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int y, int void print_arrows_array (struct arrow_t *arrows, int arrows_nb, int invoked_by); 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, +void print_user_choices(struct arrow_t *arrows, int max_arrows_nb, int arrows_nb, int space_size_x, int space_size_y, int space_size_z, int show_array, int show_space_design); void print_evolution (struct arrow_t *arrows, int arrows_nb, int modified, int deleted, int show_array); @@ -75,3 +75,9 @@ void show_buffers_states(int space_X, int space_Y, int space_Z, long nb_batches_specified, int one_batch_size, int offset_after_grids, int buffer_vertex_size, int buffer_lines_size_after_cubes, int buffer_lines_size); + +void print_vertex_and_lines_buffers (struct arrow_t *arrows_ptr, int arrows_nb, + GLfloat *buffer_vertex_origin, long buffer_vertex_0_arrow, + GLfloat *buffer_lines_origin, long buffer_lines_0_arrow, + int address, int requested_weight, int current_weight, int site, int x, int y, int z); + diff --git a/src/graphics/arrows.c b/src/graphics/arrows.c index 63449ef..3dc2d7c 100644 --- a/src/graphics/arrows.c +++ b/src/graphics/arrows.c @@ -34,7 +34,7 @@ */ int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int, - int weight, int site, int arrow_x, int arrow_y, int arrow_z) + int weight, int site, int arrow_x, int arrow_y, int arrow_z, int print) { float max = fmax(space_X_int, space_Y_int); @@ -46,10 +46,8 @@ int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int, vy = (2 * j / space_Y_int - 1) * space_Y_int / max + (1 / max), vz = (2 * k / space_Z_int - 1) * space_Z_int / max + (1 / max); - int print = 0; - graphics_write_vertex(vx, vy, vz, print); - graphics_write_color(0.3f, 0.3f, 0.3f); + graphics_write_color(0.4f, 0.4f, 0.4f); // réduit légèrement les longueurs des flèches // pour qu'elles s'arrêtent avant les faces des cubes @@ -66,32 +64,29 @@ int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int, break; case ZENITH: graphics_write_vertex (vx, vy - (site % 2 - 1) * (1 / max) + (site % 2 - 1) * arrow_tip_padding, vz, print); - graphics_write_color(0.0f, 1.0f, 0.0f); + graphics_write_color(0.0f, 0.6f, 0.1f); break; case NADIR: graphics_write_vertex (vx, vy - (site % 2) * (1 / max) + (site % 2) * arrow_tip_padding, vz, print); - graphics_write_color(0.7f, 0.2f, 0.2f); + graphics_write_color(0.6f, 0.1f, 0.7f); break; case SOUTH: - graphics_write_vertex (vx, vy, vz + (site % 2 - 1) * (1 / max) - (site % 2 - 1) * arrow_tip_padding, print); - graphics_write_color(0.3f, 0.1f, 0.6f); + graphics_write_vertex (vx, vy, vz - (site % 2 - 1) * (1 / max) + (site % 2 - 1) * arrow_tip_padding, print); + graphics_write_color(1.0f, 1.0f, 0.0f); break; case NORTH: - graphics_write_vertex (vx, vy, vz + (site % 2) * (1 / max) - (site % 2) * arrow_tip_padding, print); - graphics_write_color(1.0f, 1.0f, 0.0f); + graphics_write_vertex (vx, vy, vz - (site % 2) * (1 / max) + (site % 2) * arrow_tip_padding, print); + graphics_write_color(0.05f, 0.4f, 1.0f); break; default: break; } - return 2; + return 2*3; } -int write_one_arrow_line(int offset_vertex) +int write_one_arrow_line(int offset_vertex, int print) { - int print = 0; graphics_write_line (offset_vertex + 0, offset_vertex + 1, print); return 2; } - - diff --git a/src/graphics/displays.c b/src/graphics/displays.c index 4b9b2ca..e5732a3 100644 --- a/src/graphics/displays.c +++ b/src/graphics/displays.c @@ -29,6 +29,93 @@ #include "../../include/displays.h" +/* TO REMEMBER : Ici, tout ce qui gène la lecture du code en cours de debugging + * #pragma omp parallel schedule(static, 12) + * void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) +{ +// assert : space dimensions (x,y,z) > 0 +// assert : arrows localization within space and sites +// assert : no more than one arrow per address +// notify : weights are replaced, NOT added (could be !) + * + * Init space and arrows (= initial state) + * and allows ulterior creations, suppressions or modifications of the arrows[] array + * + * Draws space and arrows + * + * // Initialisation du générateur pseudo-aléatoire + * // Attention, à ce stade, pas de vertex redondant +*/ + + + +/* in set_arrow() : */ + /* if (console) print_vertex_and_lines_buffers (arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); */ + /* if (0) print_vertex_and_lines_buffers (arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); */ + /* if (requested_weight == 0 && console) */ + /* printf(" - set_arrow() invoked with requested weight = %2d bf_vrtx = %d bf_ln = %d add: %d",\ */ + /* requested_weight, buffer_vertex_size / 3, buffer_lines_size / 2, address); */ + /* if (console) show_user_action(arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); */ + + +/* + * Calls one of the functions create_arrow(), erase_arrow() or rewrite_arrow() + * according to requested weight and address (coord site, x, y, z) + * + * May not call any of these three functions if : + * - Current_weight of an arrow located at the requested address == requested_weight + * - No arrow was found at the requested addres AND current_weight == requested_weight + */ +/* + * Removes an arrow at address (address) +*/ +/* + * Creates a new arrow at address (address) + * NB Weights (or loads) are NOT added +*/ + +/* + * Assigns a new load to the arrow at address (address) +*/ + + + + /*--------------------------------------------------------------------------------*/ + + /* I N I T I A L D A T A A R E N O W A L L S P E C I F I E D */ + + /* A N D C A N B E D R A W N */ + + /*--------------------------------------------------------------------------------*/ + + + + + /*--------------------------------------------------------------------------------*/ + + /* N E W D A T A W I L L N O W B E S P E C I F I E D */ + + /* A N D T H E N D R A W N E D */ + + /*--------------------------------------------------------------------------------*/ + + + /* If load == 0 then erase the arrow at this address v */ + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 0, 0, 0, 0, console); */ + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 1, 0, 0, 0, console); */ + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 2, 0, 0, 0, console); */ + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 3, 0, 0, 0, console); */ + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 4, 0, 0, 0, console); */ + /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 5, 0, 0, 0, console); */ + + + + + +/*--------------------------------------------------------------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------------------------------------------------------------*/ + /* Prints the arrows[] array * @@ -41,13 +128,14 @@ void print_arrows_array (struct arrow_t *arrows, int arrows_nb, int invoked_by) { printf(" [rank] load | site x y z ("); switch (invoked_by) { - case 0: printf("delete)"); break; - case 1: printf("create)"); break; - case 2: printf("modify)"); break; + case 0: printf("after deletion) arrows_nb : %d", arrows_nb); break; + case 1: printf("after creation) arrows_nb : %d", arrows_nb); break; + case 2: printf("after modification) arrows_nb : %d", arrows_nb); break; case 3: printf("address >= 0 && current_weight == requested_weight)"); break; case 4: printf("address == -1 && requested_weight == 0)"); break; case 5: printf("print_user_choices)"); break; case 6: printf("print_evolution)"); break; + case 7: printf("before deletion) arrows_nb : %d", arrows_nb); break; } for (int i = 0; i < arrows_nb; i++) printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, arrows[i].load,\ @@ -63,12 +151,12 @@ void print_arrows_array (struct arrow_t *arrows, int arrows_nb, int invoked_by) * 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, +void print_user_choices(struct arrow_t *arrows, int max_arrows_nb, 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 (%3d,%3d,%3d)\tarrows nb : %6d\t",\ - space_size_x, space_size_y, space_size_z, arrows_nb); + printf("model + user constraints :\tspace size x,y,z (%d,%d,%d)\tinitial (max) arrows nb : %d",\ + space_size_x, space_size_y, space_size_z, max_arrows_nb); if (show_space_design) printf(" (grilles alternées)"); printf("\n"); @@ -252,3 +340,47 @@ void print_user_action(struct arrow_t *arrows, int arrows_nb, int address, int r + + +static inline void print_buffers_array_head () {printf(" [rank] load | site x y z [address] buffer-vertex-1 buffer-vertex-2 buffer-lines\n");} +static inline void print_empty_buffers_array () {printf(" [NULL] ---- | ---- --- --- --- -1 --- --- ---\n");} + +static void print_one_arrow_in_buffers (struct arrow_t *arrows, + GLfloat *buffer_vertex_origin, long buffer_vertex_0_arrow, + GLfloat *buffer_lines_origin, long buffer_lines_0_arrow, + int i, int arrows_nb, int address) +{ + printf(" [%4d] = %2d | %2d, %2d, %2d, %2d, (%2d) %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %4f %4f\n",\ + i, + arrows[i].load, arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z, + address, + + buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 0], + buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 1], + buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 2], + + buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 3], + buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 4], + buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 5], + + buffer_lines_origin [buffer_lines_0_arrow + i * 2 + 0], + buffer_lines_origin [buffer_lines_0_arrow + i * 2 + 1]); +} + +void print_vertex_and_lines_buffers (struct arrow_t *arrows_ptr, int arrows_nb, + GLfloat *buffer_vertex_origin, long buffer_vertex_0_arrow, + GLfloat *buffer_lines_origin, long buffer_lines_0_arrow, + int address, int requested_weight, int current_weight, int site, int x, int y, int z) +{ + /* for (int i = 0; i < 6; i++) printf("%5.2f ", buffer_vertex_origin [buffer_vertex_0_arrow + i]); printf("\n"); */ + /* for (int i = 0; i < 6; i++) printf("%5.2f ", buffer_lines_origin [buffer_lines_0_arrow + i]); printf("\n"); */ + print_buffers_array_head (); + for (int i = 0; i < arrows_nb; i++) + print_one_arrow_in_buffers(arrows_ptr, buffer_vertex_origin, buffer_vertex_0_arrow, + buffer_lines_origin, buffer_lines_0_arrow, i, arrows_nb, address); + if (arrows_nb == 0) print_empty_buffers_array(); +} + + + + diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index d7270bb..7bcf869 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -35,17 +35,21 @@ #define VERTEX_SHADER_FILE "src/shaders/shader.vert" #define FRAG_SHADER_FILE "src/shaders/shader.frag" -static struct arrow_t *arrows_ptr; /* nom modifié pour pouvoir plus facilement distinguer le tableau - * des autres noms incluant "arrows" (de arrows_nb, par ex.) */ -static GLfloat *buffer_vertex_origin = NULL; -static GLfloat *buffer_colors_origin = NULL; -static GLuint *buffer_lines_origin = NULL; -static GLuint *buffer_plans_origin = NULL; +static struct arrow_t *arrows_ptr; +GLfloat *buffer_vertex_origin = NULL; +GLfloat *buffer_colors_origin = NULL; +GLuint *buffer_lines_origin = NULL; +GLuint *buffer_plans_origin = NULL; -static volatile int buffer_vertex_size = 0; -static volatile int buffer_lines_size = 0; -static volatile int buffer_colors_size = 0; -static volatile int buffer_plans_size = 0; +volatile long buffer_vertex_size = 0; +volatile long buffer_colors_size = 0; +volatile long buffer_lines_size = 0; +volatile long buffer_plans_size = 0; + +volatile long buffer_vertex_0_arrow = 0; +volatile long buffer_colors_0_arrow = 0; +volatile long buffer_lines_0_arrow = 0; +volatile long buffer_plans_0_arrow = 0; #define TEST 0 @@ -133,8 +137,8 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z, int print) buffer_vertex_origin[buffer_vertex_size + 1] = y; buffer_vertex_origin[buffer_vertex_size + 2] = z; - if (print) printf("In graphics_write_vertex() buffer_vertex_size => [%2d > %2d] (%6.3f,%6.3f,%6.3f)\n",\ - buffer_vertex_size + 0, buffer_vertex_size + 2, x, y, z); + if (print) printf("In graphics_write_vertex() buffer_vertex_size => [%2ld] [%2ld > %2ld] (%6.3f,%6.3f,%6.3f)\n",\ + buffer_vertex_size / 3, buffer_vertex_size + 0, buffer_vertex_size + 2, x, y, z); buffer_vertex_size += 3; } @@ -177,8 +181,8 @@ void graphics_write_line (GLuint a, GLuint b, int print) buffer_lines_origin[buffer_lines_size + 0] = a; buffer_lines_origin[buffer_lines_size + 1] = b; - if (print) printf("In graphics_write_line() buffer_lines_size => [%2d > %2d] (%2u > %2u)\n",\ - buffer_lines_size + 0, buffer_lines_size + 1, a, b); + if (print) printf("In graphics_write_line() buffer_lines_size => [%2ld] [%2ld > %2ld] (%3u > %3u )\n\n",\ + buffer_lines_size / 2, buffer_lines_size + 0, buffer_lines_size + 1, a, b); buffer_lines_size += 2; } @@ -549,25 +553,61 @@ bool graphics_shutdown(const void *gl_area) } -/* - * Assigns a new load to the arrow at address (address) -*/ -static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x, int y, int z) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x, int y, int z, int console) { + printf("WARNING in rewrite_arrow() <> address or address / 5 ? (et pourquoi ?)\n"); arrows_ptr[address].load = load; - print_arrows_array (arrows_ptr, arrows_nb, 2); + if (console) print_arrows_array (arrows_ptr, arrows_nb, 2); return arrows_nb; } -/* - * Creates a new arrow at address (address) - * NB Weights (or loads) are NOT added -*/ static inline int create_arrow (int arrows_nb, int space_X, int space_Y, int space_Z, - int load, int site, int x, int y, int z) + int load, int site, int x, int y, int z, + int console) { void *newptr = g_realloc(arrows_ptr, (arrows_nb + 1) * sizeof(struct arrow_t)); @@ -582,341 +622,173 @@ static inline int create_arrow (int arrows_nb, arrows_ptr[arrows_nb].y = y; arrows_ptr[arrows_nb].z = z; - if (0) printf("In create_arrow() buffer_vertex_size => [%2d > %2d]\n",\ - buffer_vertex_size + 0, buffer_vertex_size + 2); - - write_one_arrow_vertex(space_X, space_Y, space_Z, - load, site, x, y, z); - buffer_colors_size = buffer_vertex_size; - - write_one_arrow_line (buffer_vertex_size / 3 - 2); + write_one_arrow_vertex(space_X, space_Y, space_Z, load, site, x, y, z, console); + write_one_arrow_line (buffer_vertex_size / 3 - 2, console); arrows_nb ++; - print_arrows_array (arrows_ptr, arrows_nb, 1); + if (console) print_arrows_array (arrows_ptr, arrows_nb, 1); return arrows_nb; } -/* - * Removes an arrow at address (address) -*/ -static inline int erase_arrow (int arrows_nb, int address, int site, int x, int y, int z) +static inline int erase_arrow (int arrows_nb, int arrow_address_in_list, + GLuint site, GLint x, GLint y, GLint z, + int console) { + 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 (console) print_arrows_array (arrows_ptr, arrows_nb, 7); + + assert (arrows_nb); arrows_nb --; - if (1) + if (arrow_address_in_list < arrows_nb) { - arrows_ptr[address].load = arrows_ptr[arrows_nb].load; - arrows_ptr[address].site = arrows_ptr[arrows_nb].site; - arrows_ptr[address].x = arrows_ptr[arrows_nb].x; - arrows_ptr[address].y = arrows_ptr[arrows_nb].y; - arrows_ptr[address].z = arrows_ptr[arrows_nb].z; + int mem = arrows_ptr[arrow_address_in_list].site; + + arrows_ptr[arrow_address_in_list].load = arrows_ptr[arrows_nb].load; + arrows_ptr[arrow_address_in_list].site = arrows_ptr[arrows_nb].site; + arrows_ptr[arrow_address_in_list].x = arrows_ptr[arrows_nb].x; + arrows_ptr[arrow_address_in_list].y = arrows_ptr[arrows_nb].y; + arrows_ptr[arrow_address_in_list].z = arrows_ptr[arrows_nb].z; + + + if (console) printf("in erase_arrow() : arrows_nb decreases from %d to %d. the erased arrow was at address : %d\n\ + : arrows_ptr[%d].site (value: %d) was replaced by arrows_ptr[%d].site (value: %d)\n",\ + arrows_nb + 1, arrows_nb, arrow_address_in_list, arrow_address_in_list, mem, arrows_nb, arrows_ptr[arrows_nb].site); } - if (arrows_nb > 0) { - void *newptr = g_realloc(arrows_ptr, arrows_nb * sizeof(struct arrow_t)); + for (long i = 0; i < 6; i++) + buffer_vertex_origin [buffer_vertex_0_arrow + arrow_address_in_list * 6 + i] + = buffer_vertex_origin [buffer_vertex_size - 6 + i]; - if (newptr) - arrows_ptr = newptr; - else - perror("In erase arrow, can't allocate new arrow buffer !\n"); - } + for (long i = 0; i < 6; i++) + buffer_colors_origin [buffer_colors_0_arrow + arrow_address_in_list * 6 + i] + = buffer_colors_origin [buffer_colors_size - 6 + i]; - print_arrows_array (arrows_ptr, arrows_nb,0); + buffer_vertex_size -= 6; // <<< l'inverse de ce qui est fait dans : graphics_write_vertex() + buffer_colors_size -= 6; // <<< l'inverse de ce qui est fait dans : graphics_write_colors() + buffer_lines_size -= 2; // <<< l'inverse de ce qui est fait dans : graphics_write_line() + + void *new_arrows_vertex_ptr = g_realloc(buffer_vertex_origin, buffer_vertex_size * sizeof(GLfloat)); + if (new_arrows_vertex_ptr) buffer_vertex_origin = new_arrows_vertex_ptr; + else perror("In graphics.erase_arrow(), can't re_allocate for arrows vertex buffer.\n"); + + void *new_arrows_colors_ptr = g_realloc(buffer_colors_origin, buffer_colors_size * sizeof(GLfloat)); + if (new_arrows_colors_ptr) buffer_colors_origin = new_arrows_colors_ptr; + else perror("In graphics.erase_arrow(), can't re_allocate for arrows colors buffer.\n"); + + /* Il ne faut pas réécrire ce qui suit: ces lignes dessinent maintenant à partir d'autres vertex */ + /* void *new_arrows_lines_ptr = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLfloat)); */ + /* 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"); */ + + if (console) print_arrows_array (arrows_ptr, arrows_nb, 0); + if (console) printf("\n"); return arrows_nb; } -static inline void show_user_action(struct arrow_t *arrows_ptr, int arrows_nb, int address, int requested_weight, - int current_weight, int site, int x, int y, int z); -/* - * Calls one of the functions create_arrow(), erase_arrow() or rewrite_arrow() - * according to requested weight and address (coord site, x, y, z) - * - * May not call any of these three functions if : - * - Current_weight of an arrow located at the requested address == requested_weight - * - No arrow was found at the requested addres AND current_weight == requested_weight - */ -static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, - int space_X, int space_Y, int space_Z, - int requested_weight, int site, int x, int y, int z) + + +static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int space_X, int space_Y, int space_Z, + int requested_weight, int site, int arrow_x, int arrow_y, int arrow_z, int console) { int address = -1, current_weight = -1; -#pragma omp parallel schedule(static, 12) -{ - for (int i = 0; i < arrows_nb; i++) { - if ((site == arrows_ptr[i].site) - && (x == arrows_ptr[i].x) - && (y == arrows_ptr[i].y) - && (z == arrows_ptr[i].z)) + if (console) printf("in set_arrow (begin) arrows_nb = %d requested site: %d > ", arrows_nb, site); + 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++) + if ((site == arrows_ptr[i].site) + && (arrow_x == arrows_ptr[i].x) + && (arrow_y == arrows_ptr[i].y) + && (arrow_z == arrows_ptr[i].z)) { - address = i * 5; + address = i; current_weight = arrows_ptr[i].load; break; } + assert (address <= arrows_nb); + if (console) { + 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 && current_weight != requested_weight) printf(" >> rewrite_arrow() at site %d\n", site); + if (address == -1 && requested_weight == 0) printf(" >> no operation\n"); } -} - //printf("\n[%d]set_arrow() invoked with requested weight = %2d + ", arrows_nb, requested_weight); - - if (TEST) show_user_action(arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); - if (address == -1 && requested_weight > 0) - return create_arrow (arrows_nb, space_X, space_Y, space_Z, requested_weight, site, x, y, z); - - if (address >= 0 && requested_weight == 0) - return erase_arrow (arrows_nb, address, site, x, y, z); - + 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 + return erase_arrow (arrows_nb, address, site, arrow_x, arrow_y, arrow_z, console); if (address >= 0 && current_weight != requested_weight) - return rewrite_arrow (arrows_nb, address/5, requested_weight, site, x, y, z); - - if (! TEST && address >= 0 && current_weight == requested_weight) print_arrows_array(arrows_ptr, arrows_nb, 3); - - if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(arrows_ptr, arrows_nb, 4); + return rewrite_arrow (arrows_nb, address, requested_weight, site, arrow_x, arrow_y, arrow_z, console); + if (address >= 0 && current_weight == requested_weight && console) print_arrows_array(arrows_ptr, arrows_nb, 3); + if (address == -1 && requested_weight == 0 && console) print_arrows_array(arrows_ptr, arrows_nb, 4); return arrows_nb; } -/* - * Init space and arrows (= initial state) - * and allows ulterior creations, suppressions or modifications of the arrows[] array - * - * Draws space and arrows - */ -void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) + +void main_test_graphics (void) { -// assert : space dimensions (x,y,z) > 0 -// assert : arrows localization within space and sites -// assert : no more than one arrow per address -// notify : weights are replaced, NOT added (could be !) - - struct timespec ts; - srand(time(NULL)); // Initialisation du générateur pseudo-aléatoire - int rand(void); - void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min); - - int arbitrary = 5; - int space_X = 1 + rand() % arbitrary, - space_Y = 1 + rand() % arbitrary, - space_Z = 1 + rand() % arbitrary; - int density_max = space_X * space_Y * space_Z; + srand(time(NULL)); int rand(void); void srand(unsigned int seed); + int randomize = 7, console = 0, arrows_nb = 0, space_X = 1, space_Y = 1, space_Z = 1; + if (randomize) { + space_X = 1 + rand() % randomize; + space_Y = 1 + rand() % randomize; + space_Z = 1 + rand() % randomize; + } + int density_max = space_X * space_Y * space_Z, specified_arrows_nb = rand() % density_max; int max = fmax(space_X, space_Y); max = fmax(max, space_Z); - int print_arrows_data = 0; - - int load = 0, site = 0, x = 0, y = 0, z = 0; - int specif_arrows_nb = rand() % density_max / 2; - int arrows_nb = 0, cpt = 0, t_initial = 0; - - int print_inter_results = 0; - if (print_inter_results) clock_gettime(CLOCK_REALTIME, &ts); t_initial = ts.tv_sec; - if (print_inter_results) printf("%10d | ", specif_arrows_nb / 1000); - printf("I N I T I A L D A T A A R E N O W S P E C I F I E D\n"); - - - /*--------------------------------------------------------------------------------*/ - - /* I N I T I A L D A T A A R E N O W A L L S P E C I F I E D */ - - /* A N D C A N B E D R A W N */ - - /*--------------------------------------------------------------------------------*/ - - /* V E R T E X F I R S T */ - /* S P A C E */ - if (1) printf("buffer_vertex_size before writing 8 space_ridges_vertex : %3d (x 3 = %d)\n", buffer_vertex_size / 3, buffer_vertex_size); - write_space_ridges_vertex (buffer_vertex_size, space_X, space_Y, space_Z); - /* buffer_colors_size = buffer_vertex_size; */ - - if (1) printf("buffer_vertex_size after writing 8 space_ridges_vertex : %3d (x 3 = %d)\n", buffer_vertex_size / 3, buffer_vertex_size); - - write_grids_on_space_faces_vertex (space_X, space_Y, space_Z); - /* buffer_colors_size = buffer_vertex_size; */ - - if (1) printf("buffer_vertex_size after writing %3d space_faces_vertex : %3d (x 3 = %4d)\n\n", buffer_vertex_size / 3 - 8, buffer_vertex_size / 3, buffer_vertex_size); - /* if (0) printf("(space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4 = %3d (x 3 = %4d)\n\n",\ */ - /* (space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4, ((space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4) * 3); */ - - - /* A R R O W S */ - - /* if (1) printf("buffer_vertex_size before writing (%d) arrows_vertex : %d\n", arrows_nb, buffer_vertex_size / 3); */ - - /* for (int i = 0; i < arrows_nb; i++) { */ - /* load = arrows_ptr[i].load; */ - /* site = arrows_ptr[i].site; */ - /* x = arrows_ptr[i].x; */ - /* y = arrows_ptr[i].y; */ - /* z = arrows_ptr[i].z; */ - - /* write_one_arrow_vertex(space_X, space_Y, space_Z, */ - /* load, site, x, y, z); */ - /* buffer_colors_size = buffer_vertex_size; */ - /* } */ - - /* if (1) printf("buffer_vertex_size after writing (%d) arrows_vertex : %d\n", arrows_nb, buffer_vertex_size / 3); */ - - - /*---------------------------------------------------------------*/ - - /* L I N E S S E C O N D */ - - // buffer_vertex_size = 0; buffer_colors_size = 0; buffer_lines_size = 0; - - /* S P A C E */ - - if (0) printf("buffer_lines_size before writing 12 space_ridges_lines : %2d (* 2 = %2d)\n", buffer_lines_size / 2, buffer_lines_size); write_space_ridges_lines (); - if (0) printf("buffer_lines_size after writing 12 space_ridges_lines : %2d (* 2 = %2d)\n", buffer_lines_size / 2, buffer_lines_size); - - if (0) printf("buffer_lines_size before writing (n) space_faces_lines : %2d (* 2 = %2d)\n", buffer_lines_size / 2, buffer_lines_size); + write_grids_on_space_faces_vertex (space_X, space_Y, space_Z); write_grids_on_space_faces_lines (buffer_lines_size, space_X, space_Y, space_Z); - if (1) printf("buffer_lines_size after writing (n) space_faces_lines : %d (* 2 = %d)\n\n", buffer_lines_size / 2, buffer_lines_size); + + buffer_vertex_0_arrow = buffer_vertex_size; + buffer_colors_0_arrow = buffer_colors_size; + buffer_lines_0_arrow = buffer_lines_size; /* A R R O W S */ -/* #pragma omp parallel */ -/* { */ - /* while (arrows_nb < specif_arrows_nb){ */ + if (randomize) for (int i = 0; i < specified_arrows_nb; i++) arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, - rand() % arbitrary + 1, // load / weight - rand() % 6, // site, + 1, // load + rand() % 6, // site rand() % space_X, // x rand() % space_Y, // y - rand() % space_Z); // z + rand() % space_Z, // z + console); + else for (int i = 0; i < 6; i++) + arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 1, i, 0, 0, 0, 0); + int max_arrows_nb = arrows_nb; + 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, - rand() % arbitrary + 1, // load / weight - rand() % 6, // site, + rand() % 1, // load + rand() % 6, // site rand() % space_X, // x rand() % space_Y, // y - rand() % space_Z); // z + rand() % space_Z, // z + console); + else for (int i = 0; i < 6; i++) + arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, i, 0, 0, 0, 1); - /* clock_gettime(CLOCK_REALTIME, &ts); < Je n'arrive pas à afficher les temps en cours d'exécutuion */ - /* if (arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 22 == 0) printf(" %f\n%10d | ", specif_arrows_nb / 1000, ts.tv_sec - t_initial);} */ - if (print_inter_results && arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 24 == 0) printf("\n%10d | ", specif_arrows_nb / 1000);} - /* } */ -/* } */ - /* for (int i = 0; i < arrows_nb; i++) { */ - /* load = arrows_ptr[i].load; */ - /* site = arrows_ptr[i].site; */ - /* x = arrows_ptr[i].x; */ - /* y = arrows_ptr[i].y; */ - /* z = arrows_ptr[i].z; */ - - /* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */ - /* } */ - - - - - - - - - /* N E W D A T A W I L L N O W B E S P E C I F I E D */ - - /* A N D T H E N D R A W N E D */ + if (randomize) print_user_choices(arrows_ptr, max_arrows_nb, arrows_nb, space_X, space_Y, space_Z, 1, 0); /*--------------------------------------------------------------------------------*/ - print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); + /* F R E E */ - /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, */ - /* 0,//rand() % arbitrary + 1, // load / weight */ - /* 0,//rand() % 6, // site, */ - /* 0,//rand() % space_X, // x */ - /* 0,//rand() % space_Y, // y */ - /* 0);//rand() % space_Z); // z */ + /* ( F R E E 'S P A C E' : S E E G R A P H I C S H U T D O W N ) */ - /* print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */ + /*--------------------------------------------------------------------------------*/ - /* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, */ - /* 0,//rand() % arbitrary + 1, // load / weight */ - /* 1,//rand() % 6, // site, */ - /* 0,//rand() % space_X, // x */ - /* 0,//rand() % space_Y, // y */ - /* 0);//rand() % space_Z); // z */ - - /* print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */ - -/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, */ -/* 1,//rand() % arbitrary + 1, // load / weight */ -/* 2,//rand() % 6, // site, */ -/* 0,//rand() % space_X, // x */ -/* 0,//rand() % space_Y, // y */ -/* 0);//rand() % space_Z); // z */ - -/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, */ -/* 1,//rand() % arbitrary + 1, // load / weight */ -/* 3,//rand() % 6, // site, */ -/* 0,//rand() % space_X, // x */ -/* 0,//rand() % space_Y, // y */ -/* 0);//rand() % space_Z); // z */ - -/* printf("On devrait avoir deux flèches Y+Y- (Zénith-Nadir) dessinées (au lieu des deux flèches X+X- Est-Ouest)...\n"); */ - - /* print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */ - -// buffer_vertex_size -= 2; -// buffer_vertex_size += 3; - - -/* assert : arrows_nb > arbitrary; */ -/* int random_choice, modified = 0, deleted = 0; */ - -/* #pragma omp parallel */ -/* { */ -/* while (modified < arbitrary) { */ - -/* random_choice = rand() % 6; */ -/* if (random_choice == 0) deleted++; */ - -/* modified = set_arrow (arrows_ptr, arrows_nb + modified, */ -/* random_choice, // load / weight */ -/* rand() % 6, // site, */ -/* rand() % space_X, // x */ -/* rand() % space_Y, // y */ -/* rand() % space_Z); // z */ -/* } */ -/* } */ - -/* #pragma omp parallel */ -/* { */ -/* for (int i = 0; i < arrows_nb + modified; i++) { */ -/* load = arrows_ptr[i].load; */ -/* site = arrows_ptr[i].site; */ -/* x = arrows_ptr[i].x; */ -/* y = arrows_ptr[i].y; */ -/* z = arrows_ptr[i].z; */ - -/* buffer_vertex_size += write_one_arrow_vertex(space_X, space_Y, space_Z, */ -/* load, site, x, y, z); */ -/* buffer_colors_size = buffer_vertex_size; */ -/* } */ - -/* for (int i = 0; i < arrows_nb + modified; i++) { */ -/* load = arrows_ptr[i].load; */ -/* site = arrows_ptr[i].site; */ -/* x = arrows_ptr[i].x; */ -/* y = arrows_ptr[i].y; */ -/* z = arrows_ptr[i].z; */ - -/* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */ -/* } */ -/* } */ - -/* print_evolution (arrows_ptr, arrows_nb, arbitrary, deleted, print_arrows_data); */ - - -// ? free (space) TODO - - free(arrows_ptr); - arrows_ptr = NULL; - arrows_nb = 0; + free(arrows_ptr); arrows_ptr = NULL; arrows_nb = 0; } diff --git a/src/graphics/grid.c b/src/graphics/grid.c index 7baf7ef..d618888 100644 --- a/src/graphics/grid.c +++ b/src/graphics/grid.c @@ -41,14 +41,14 @@ int write_space_ridges_vertex (long offset_vertex, long x, long y, long z) graphics_write_vertex (offset_vertex + x / max, + y / max, + z / max, 0); - graphics_write_color (0.9f, 0.7f, 0.4f); - graphics_write_color (0.9f, 0.7f, 0.4f); - graphics_write_color (0.9f, 0.7f, 0.4f); - graphics_write_color (0.9f, 0.7f, 0.4f); - graphics_write_color (0.9f, 0.7f, 0.4f); - graphics_write_color (0.9f, 0.7f, 0.4f); - graphics_write_color (0.9f, 0.7f, 0.4f); - graphics_write_color (0.9f, 0.7f, 0.4f); + graphics_write_color (0.8f, 0.6f, 0.5f); + graphics_write_color (0.8f, 0.6f, 0.5f); + graphics_write_color (0.8f, 0.6f, 0.5f); + graphics_write_color (0.8f, 0.6f, 0.5f); + graphics_write_color (0.8f, 0.6f, 0.5f); + graphics_write_color (0.8f, 0.6f, 0.5f); + graphics_write_color (0.8f, 0.6f, 0.5f); + graphics_write_color (0.8f, 0.6f, 0.5f); return 8; } @@ -77,10 +77,10 @@ long write_grids_on_space_faces_vertex (long x, long y, long z) graphics_write_vertex ((2 * i / x - 1) * x / max, y / max, z / max, 0); graphics_write_vertex ((2 * i / x - 1) * x / max, y / max, - z / max, 0); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); } /* offset_vertex += (x - 1) * 4; */ /* offset_colors += (x - 1) * 4; */ @@ -92,10 +92,10 @@ long write_grids_on_space_faces_vertex (long x, long y, long z) graphics_write_vertex ( x / max, (2 * i / y - 1) * y / max, z / max, 0); graphics_write_vertex ( x / max, (2 * i / y - 1) * y / max, - z / max, 0); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); } /* offset_vertex += (y - 1) * 4; */ /* offset_colors += (y - 1) * 4; */ @@ -107,10 +107,10 @@ long write_grids_on_space_faces_vertex (long x, long y, long z) graphics_write_vertex ( x / max, y / max, (2 * i / z - 1) * z / max, 0); graphics_write_vertex ( x / max, - y / max, (2 * i / z - 1) * z / max, 0); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); - graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); + graphics_write_color (0.55f, 0.55f, 0.55f); } return (x + y + z - 3) * 3; diff --git a/src/ui/bac_a_sable.ui b/src/ui/bac_a_sable.ui new file mode 100644 index 0000000..aa50bb3 --- /dev/null +++ b/src/ui/bac_a_sable.ui @@ -0,0 +1,37 @@ + + + + + + + diff --git a/src/ui/window.c b/src/ui/window.c index 8463a32..f4ebee9 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -264,7 +264,7 @@ void ui_setup_glarea(GtkGLArea *target, GtkBox *target_controls) // The main "draw" call for GtkGLArea g_signal_connect(gl_area, "render", G_CALLBACK(on_render), NULL); - gtk_widget_set_hexpand(controls, TRUE); + //gtk_widget_set_hexpand(controls, TRUE); for(i = 0; i < N_AXIS; i++) gtk_box_append(GTK_BOX(controls), create_axis_slider(i));