Compare commits

..

2 Commits

3 changed files with 79 additions and 33 deletions

View File

@ -39,7 +39,7 @@ typedef struct arrow_t {
}; };
int write_one_arrow_vertex (int space_X, int space_Y, int space_Z, 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);

View File

@ -34,7 +34,7 @@
*/ */
int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int, 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); float max = fmax(space_X_int, space_Y_int);
@ -46,8 +46,6 @@ 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), 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); 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_vertex(vx, vy, vz, print);
graphics_write_color(0.3f, 0.3f, 0.3f); graphics_write_color(0.3f, 0.3f, 0.3f);
@ -87,9 +85,8 @@ int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int,
} }
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); graphics_write_line (offset_vertex + 0, offset_vertex + 1, print);
return 2; return 2;
} }

View File

@ -138,8 +138,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 + 1] = y;
buffer_vertex_origin[buffer_vertex_size + 2] = z; 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",\ if (print) printf("In graphics_write_vertex() buffer_vertex_size => [%2d] [%2d > %2d] (%6.3f,%6.3f,%6.3f)\n",\
buffer_vertex_size + 0, buffer_vertex_size + 2, x, y, z); buffer_vertex_size / 3, buffer_vertex_size + 0, buffer_vertex_size + 2, x, y, z);
buffer_vertex_size += 3; buffer_vertex_size += 3;
} }
@ -182,8 +182,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 + 0] = a;
buffer_lines_origin[buffer_lines_size + 1] = b; buffer_lines_origin[buffer_lines_size + 1] = b;
if (print) printf("In graphics_write_line() buffer_lines_size => [%2d > %2d] (%2u > %2u)\n",\ if (print) printf("In graphics_write_line() buffer_lines_size => [%2d] [%2d > %2d] (%3u > %3u ) (= buffer_vertex_size / 3 - 2 > -1)\n",\
buffer_lines_size + 0, buffer_lines_size + 1, a, b); buffer_lines_size / 2, buffer_lines_size + 0, buffer_lines_size + 1, a, b);
buffer_lines_size += 2; buffer_lines_size += 2;
} }
@ -553,7 +553,8 @@ bool graphics_shutdown(const void *gl_area)
return true; return true;
} }
static inline void print_vertex_and_lines_buffers (struct arrow_t *arrows_ptr, int arrows_nb, int address, int requested_weight,
int current_weight, int site, int x, int y, int z);
/* /*
* Assigns a new load to the arrow at address (address) * Assigns a new load to the arrow at address (address)
*/ */
@ -587,18 +588,16 @@ 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;
if (0) printf("In create_arrow() buffer_vertex_size => [%2d > %2d]\n",\ int print = 1;
buffer_vertex_size + 0, buffer_vertex_size + 2);
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); load, site, x, y, z, print);
buffer_colors_size = buffer_vertex_size; buffer_colors_size = buffer_vertex_size;
write_one_arrow_line (buffer_vertex_size / 3 - 2); write_one_arrow_line (buffer_vertex_size / 3 - 2, print);
arrows_nb ++; arrows_nb ++;
if (0) print_arrows_array (arrows_ptr, arrows_nb, 1); if (1) print_arrows_array (arrows_ptr, arrows_nb, 1);
return arrows_nb; return arrows_nb;
} }
@ -624,6 +623,8 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int
if (arrows_nb > 0) { if (arrows_nb > 0) {
int some_nb = 12; if (arrows_nb == 1) some_nb = 9;
void *new_arrows_list_ptr = g_realloc(arrows_ptr, arrows_nb * sizeof(struct arrow_t)); void *new_arrows_list_ptr = g_realloc(arrows_ptr, arrows_nb * sizeof(struct arrow_t));
if (new_arrows_list_ptr) arrows_ptr = new_arrows_list_ptr; if (new_arrows_list_ptr) arrows_ptr = new_arrows_list_ptr;
else perror("In erase arrow, can't re_allocate for arrow list.\n"); else perror("In erase arrow, can't re_allocate for arrow list.\n");
@ -634,21 +635,24 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int
/* for (int i = 24; i < 36; i ++) printf(" %5.2f", buffer_vertex_origin[i]); printf("\n"); */ /* for (int i = 24; i < 36; i ++) printf(" %5.2f", buffer_vertex_origin[i]); printf("\n"); */
if (0) printf("buffer_vertex_0_arrow = %d arrows_nb * 3 = %d <<<<\n", buffer_vertex_0_arrow, arrows_nb * 3); if (0) printf("buffer_vertex_0_arrow = %d arrows_nb * 3 = %d <<<<\n", buffer_vertex_0_arrow, arrows_nb * 3);
void *new_arrows_vertex_ptr = g_realloc(buffer_vertex_origin, buffer_vertex_0_arrow + 9 * 3 * sizeof(GLfloat)); void *new_arrows_vertex_ptr = g_realloc(buffer_vertex_origin, buffer_vertex_0_arrow + some_nb * 3 * sizeof(GLfloat));
if (new_arrows_vertex_ptr) buffer_vertex_origin = new_arrows_vertex_ptr; if (new_arrows_vertex_ptr) buffer_vertex_origin = new_arrows_vertex_ptr;
else perror("In erase arrow, can't re_allocate for arrow vertex buffer.\n"); else perror("In erase arrow, can't re_allocate for arrow vertex buffer.\n");
if (0) printf("buffer_lines_0_arrow = %d arrows_nb * 2 = %d <<<<\n", buffer_lines_0_arrow, arrows_nb * 2); if (0) printf("buffer_lines_0_arrow = %d arrows_nb * 2 = %d <<<<\n", buffer_lines_0_arrow, arrows_nb * 2);
void *new_arrows_lines_ptr = g_realloc(buffer_lines_origin, buffer_lines_0_arrow + 9 * 2 * sizeof(GLfloat)); void *new_arrows_lines_ptr = g_realloc(buffer_lines_origin, buffer_lines_0_arrow + some_nb * 2 * sizeof(GLfloat));
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 erase arrow, can't re_allocate for arrow lines buffer.\n"); else perror("In erase arrow, can't re_allocate for arrow lines buffer.\n");
} }
printf(" >> bf_vrtx = %d bf_ln = %d\n", (buffer_vertex_size - 6) / 3, (buffer_lines_size - 4) / 2);
print_arrows_array (arrows_ptr, arrows_nb,0); print_arrows_array (arrows_ptr, arrows_nb,0);
return arrows_nb; return arrows_nb;
} }
static inline void print_vertex_and_lines_buffers(struct arrow_t *arrows_ptr, int arrows_nb, int address, int requested_weight,
int current_weight, int site, int x, int y, int z);
static inline void show_user_action(struct arrow_t *arrows_ptr, int arrows_nb, int address, int requested_weight, 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); int current_weight, int site, int x, int y, int z);
/* /*
@ -679,7 +683,10 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb,
} }
} }
} }
if (requested_weight == 0) printf(" - set_arrow() invoked with requested weight = %2d\n", requested_weight); // print_vertex_and_lines_buffers (arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z);
if (requested_weight == 0) 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 (TEST) show_user_action(arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); if (TEST) show_user_action(arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z);
@ -699,6 +706,39 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb,
return arrows_nb; return arrows_nb;
} }
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, 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 %6.2f %6.2f\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 * 3 + 0],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 3 + 1],
buffer_lines_origin [buffer_lines_0_arrow + i * 3 + 2],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 3 + 3],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 3 + 4],
buffer_lines_origin [buffer_lines_0_arrow + i * 3 + 5],
buffer_lines_origin [buffer_lines_0_arrow + i * 2 + 0],
buffer_lines_origin [buffer_lines_0_arrow + i * 2 + 1]);
}
static inline void print_vertex_and_lines_buffers (struct arrow_t *arrows_ptr, int arrows_nb, 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, i, arrows_nb, address);
if (arrows_nb == 0) print_empty_buffers_array();
}
/* /*
* Init space and arrows (= initial state) * Init space and arrows (= initial state)
@ -714,7 +754,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
// notify : weights are replaced, NOT added (could be !) // notify : weights are replaced, NOT added (could be !)
struct timespec ts; struct timespec ts;
srand(time(NULL)); // Initialisation du générateur pseudo-aléatoire srand(time(NULL)); // Initialisation du générateur pseudo-aléatoire
int rand(void); int rand(void);
void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min); void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min);
@ -804,7 +844,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
buffer_vertex_0_arrow = buffer_vertex_size; buffer_vertex_0_arrow = buffer_vertex_size;
buffer_lines_0_arrow = buffer_lines_size; buffer_lines_0_arrow = buffer_lines_size;
printf("buffer_vertex_0_arrow = %d (%d points) buffer_lines_0_arrow = %d (%d lines)\n",\ if (1) printf("buffer_vertex_0_arrow = %d (%d points) buffer_lines_0_arrow = %d (%d lines)\n",\
buffer_vertex_0_arrow, buffer_vertex_0_arrow / 3, buffer_lines_0_arrow, buffer_lines_0_arrow / 2); buffer_vertex_0_arrow, buffer_vertex_0_arrow / 3, buffer_lines_0_arrow, buffer_lines_0_arrow / 2);
/* A R R O W S */ /* A R R O W S */
@ -812,6 +852,9 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* #pragma omp parallel */ /* #pragma omp parallel */
/* { */ /* { */
/* while (arrows_nb < specif_arrows_nb){ */ /* while (arrows_nb < specif_arrows_nb){ */
arrows_nb = 0;
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,
rand() % arbitrary + 1, // load / weight rand() % arbitrary + 1, // load / weight
0,//rand() % 6, // site, 0,//rand() % 6, // site,
@ -836,15 +879,13 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* 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 */ /* 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 */ /* A N D T H E N D R A W N E D */
/*--------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------*/
if (1) print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); /* if (1) 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, arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z,
0,//rand() % arbitrary + 1, // load / weight 0,//rand() % arbitrary + 1, // load / weight
@ -853,14 +894,21 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
0,//rand() % space_Y, // y 0,//rand() % space_Y, // y
0);//rand() % space_Z); // z 0);//rand() % space_Z); // z
print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); /* 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, */ arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z,
/* 0,//rand() % arbitrary + 1, // load / weight */ rand() % arbitrary + 1, // load / weight
/* 1,//rand() % 6, // site, */ 2,//rand() % 6, // site,
/* 0,//rand() % space_X, // x */ 0,//rand() % space_X, // x
/* 0,//rand() % space_Y, // y */ 0,//rand() % space_Y, // y
/* 0);//rand() % space_Z); // z */ 0);//rand() % space_Z); // z
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); */ /* print_user_choices(arrows_ptr, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
@ -939,3 +987,4 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
arrows_ptr = NULL; arrows_ptr = NULL;
arrows_nb = 0; arrows_nb = 0;
} }