Compare commits

..

No commits in common. "7813041ad550a24a8a7c586d5414adf4cd1cc466" and "9a1023b0b2f3032a337958520b2ee9b9083a2777" have entirely different histories.

1 changed files with 98 additions and 111 deletions

View File

@ -35,8 +35,9 @@
#define VERTEX_SHADER_FILE "src/shaders/shader.vert" #define VERTEX_SHADER_FILE "src/shaders/shader.vert"
#define FRAG_SHADER_FILE "src/shaders/shader.frag" #define FRAG_SHADER_FILE "src/shaders/shader.frag"
static struct arrow_t *arrovvs; /* nom modifié pour pouvoir plus facilement distinguer le tableau static struct arrow_t *sworrah; /* "arrows" était devenu un peu trop populaire :
* des autres noms incluant "arrows" (de arrows_nb, par ex.) */ * (je n'arrivais plus à facilement le distinguer de arrows_nb, par ex.)
* et le 'h' final donne une petite touche sauvage... */
static GLfloat *buffer_vertex_origin = NULL; static GLfloat *buffer_vertex_origin = NULL;
static GLfloat *buffer_colors_origin = NULL; static GLfloat *buffer_colors_origin = NULL;
static GLuint *buffer_lines_origin = NULL; static GLuint *buffer_lines_origin = NULL;
@ -116,7 +117,7 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id,
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* /*
* Writes values to describe a vertex at (x,y,z) intoq the vertex buffer * Writes values to describe a vertex at (x,y,z) into the vertex buffer
* *
* @param coords GLfloat(x,y,z) * @param coords GLfloat(x,y,z)
* *
@ -133,7 +134,7 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z)
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 (1) printf("In graphics_write_vertex() buffer_vertex_size = %2d > %2d (%6.3f,%6.3f,%6.3f)\n",\ if (1) printf("In graphics_write_vertex() buffer_vertex_size = %d > %d (%6.3f,%6.3f,%6.3f)\n",\
buffer_vertex_size, buffer_vertex_size + 3, x, y, z); buffer_vertex_size, buffer_vertex_size + 3, x, y, z);
buffer_vertex_size += 3; buffer_vertex_size += 3;
@ -551,9 +552,9 @@ bool graphics_shutdown(const void *gl_area)
*/ */
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)
{ {
arrovvs[address].load = load; sworrah[address].load = load;
print_arrows_array (arrovvs, arrows_nb, 2); print_arrows_array (sworrah, arrows_nb, 2);
return arrows_nb; return arrows_nb;
} }
@ -564,22 +565,22 @@ static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x,
*/ */
static inline int create_arrow (int arrows_nb, int load, int site, int x, int y, int z) static inline int create_arrow (int arrows_nb, int load, int site, int x, int y, int z)
{ {
void *newptr = g_realloc(arrovvs, (arrows_nb + 1) * sizeof(struct arrow_t)); void *newptr = g_realloc(sworrah, (arrows_nb + 1) * sizeof(struct arrow_t));
if (newptr) if (newptr)
arrovvs = newptr; sworrah = newptr;
else else
perror("In create arrow, can't allocate new arrow buffer !\n"); perror("In create arrow, can't allocate new arrow buffer !\n");
arrovvs[arrows_nb].load = load; sworrah[arrows_nb].load = load;
arrovvs[arrows_nb].site = site; sworrah[arrows_nb].site = site;
arrovvs[arrows_nb].x = x; sworrah[arrows_nb].x = x;
arrovvs[arrows_nb].y = y; sworrah[arrows_nb].y = y;
arrovvs[arrows_nb].z = z; sworrah[arrows_nb].z = z;
arrows_nb ++; arrows_nb ++;
print_arrows_array (arrovvs, arrows_nb, 1); print_arrows_array (sworrah, arrows_nb, 1);
return arrows_nb; return arrows_nb;
} }
@ -591,30 +592,28 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int
{ {
arrows_nb --; arrows_nb --;
if (1) if (arrows_nb > 0)
{ {
arrovvs[address].load = arrovvs[arrows_nb].load; sworrah[address].load = sworrah[arrows_nb].load;
arrovvs[address].site = arrovvs[arrows_nb].site; sworrah[address].site = sworrah[arrows_nb].site;
arrovvs[address].x = arrovvs[arrows_nb].x; sworrah[address].x = sworrah[arrows_nb].x;
arrovvs[address].y = arrovvs[arrows_nb].y; sworrah[address].y = sworrah[arrows_nb].y;
arrovvs[address].z = arrovvs[arrows_nb].z; sworrah[address].z = sworrah[arrows_nb].z;
} }
if (arrows_nb > 0) { /* void *newptr = g_realloc(sworrah, arrows_nb * sizeof(struct arrow_t)); */
void *newptr = g_realloc(arrovvs, arrows_nb * sizeof(struct arrow_t));
if (newptr) /* if (newptr) */
arrovvs = newptr; /* sworrah = newptr; */
else /* else */
perror("In erase arrow, can't allocate new arrow buffer !\n"); /* perror("In erase arrow, can't allocate new arrow buffer !\n"); */
}
print_arrows_array (arrovvs, arrows_nb,0); print_arrows_array (sworrah, arrows_nb,0);
return arrows_nb; return arrows_nb;
} }
static inline void show_user_action(struct arrow_t *arrovvs, int arrows_nb, int address, int requested_weight, static inline void show_user_action(struct arrow_t *sworrah, 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);
/* /*
* Calls one of the functions create_arrow(), erase_arrow() or rewrite_arrow() * Calls one of the functions create_arrow(), erase_arrow() or rewrite_arrow()
@ -624,27 +623,27 @@ static inline void show_user_action(struct arrow_t *arrovvs, int arrows_nb, int
* - Current_weight of an arrow located at the requested address == requested_weight * - 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 * - No arrow was found at the requested addres AND current_weight == requested_weight
*/ */
static inline int set_arrow (struct arrow_t *arrovvs, int arrows_nb, int requested_weight, int site, int x, int y, int z) // , int buffer_vertex_size static inline int set_arrow (struct arrow_t *sworrah, int arrows_nb, int requested_weight, int site, int x, int y, int z) // , int buffer_vertex_size
{ {
int address = -1, current_weight = -1; int address = -1, current_weight = -1;
#pragma omp parallel schedule(static, 12) #pragma omp parallel schedule(static, 12)
{ {
for (int i = 0; i < arrows_nb; i++) { for (int i = 0; i < arrows_nb; i++) {
if ((site == arrovvs[i].site) if ((site == sworrah[i].site)
&& (x == arrovvs[i].x) && (x == sworrah[i].x)
&& (y == arrovvs[i].y) && (y == sworrah[i].y)
&& (z == arrovvs[i].z)) && (z == sworrah[i].z))
{ {
address = i * 5; address = i * 5;
current_weight = arrovvs[i].load; current_weight = sworrah[i].load;
break; break;
} }
} }
} }
//printf("\n[%d]set_arrow() invoked with requested weight = %2d + ", arrows_nb, requested_weight); //printf("\n[%d]set_arrow() invoked with requested weight = %2d + ", arrows_nb, requested_weight);
if (TEST) show_user_action(arrovvs, arrows_nb, address, requested_weight, current_weight, site, x, y, z); if (TEST) show_user_action(sworrah, arrows_nb, address, requested_weight, current_weight, site, x, y, z);
if (address == -1 && requested_weight > 0) if (address == -1 && requested_weight > 0)
return create_arrow (arrows_nb, requested_weight, site, x, y, z); return create_arrow (arrows_nb, requested_weight, site, x, y, z);
@ -655,9 +654,9 @@ static inline int set_arrow (struct arrow_t *arrovvs, int arrows_nb, int request
if (address >= 0 && current_weight != requested_weight) if (address >= 0 && current_weight != requested_weight)
return rewrite_arrow (arrows_nb, address/5, requested_weight, site, x, y, z); return rewrite_arrow (arrows_nb, address/5, requested_weight, site, x, y, z);
if (! TEST && address >= 0 && current_weight == requested_weight) print_arrows_array(arrovvs, arrows_nb, 3); if (! TEST && address >= 0 && current_weight == requested_weight) print_arrows_array(sworrah, arrows_nb, 3);
if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(arrovvs, arrows_nb, 4); if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(sworrah, arrows_nb, 4);
return arrows_nb; return arrows_nb;
} }
@ -682,9 +681,9 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (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);
int arbitrary = 3; int arbitrary = 3;
int space_X = 2,// + rand() % arbitrary, int space_X = 3,// + rand() % arbitrary,
space_Y = 2,// + rand() % arbitrary, space_Y = 2,// + rand() % arbitrary,
space_Z = 2;// + rand() % arbitrary; space_Z = 1;// + rand() % arbitrary;
int density_max = space_X * space_Y * space_Z; int density_max = space_X * space_Y * space_Z;
int max = fmax(space_X, space_Y); max = fmax(max, space_Z); int max = fmax(space_X, space_Y); max = fmax(max, space_Z);
@ -700,14 +699,14 @@ 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 = set_arrow (arrovvs, arrows_nb, arrows_nb = set_arrow (sworrah, arrows_nb,
1,//rand() % arbitrary + 1, // load / weight 1,//rand() % arbitrary + 1, // load / weight
0,//rand() % 6, // site, 0,//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 (arrovvs, arrows_nb, arrows_nb = set_arrow (sworrah, arrows_nb,
1,//rand() % arbitrary + 1, // load / weight 1,//rand() % arbitrary + 1, // load / weight
1,//rand() % 6, // site, 1,//rand() % 6, // site,
0,//rand() % space_X, // x 0,//rand() % space_X, // x
@ -733,37 +732,35 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* S P A C E */ /* S P A C E */
if (1) printf("buffer_vertex_size before writing_space_ridges_vertex : %d (x 3 = %d)\n", buffer_vertex_size, buffer_vertex_size * 3);
buffer_vertex_size += write_space_ridges_vertex (buffer_vertex_size, space_X, space_Y, space_Z); buffer_vertex_size += write_space_ridges_vertex (buffer_vertex_size, space_X, space_Y, space_Z);
buffer_colors_size = buffer_vertex_size; buffer_colors_size = buffer_vertex_size;
if (1) printf("buffer_vertex_size after writing_space_ridges_vertex : %d (x 3 = %d)\n\n", buffer_vertex_size, buffer_vertex_size * 3); if (1) printf("buffer_vertex_size after writing_space_ridges_vertex : %d (x 3 = %d)\n\n", buffer_vertex_size, buffer_vertex_size * 3);
/* buffer_vertex_size += write_grids_on_space_faces_vertex (space_X, space_Y, space_Z); */ buffer_vertex_size += write_grids_on_space_faces_vertex (space_X, space_Y, space_Z);
/* buffer_colors_size = buffer_vertex_size; */ buffer_colors_size = buffer_vertex_size;
/* if (1) printf("buffer_vertex_size after writing_space_faces_vertex = %4d - 8 = %3d (x 3 = %4d)\n\n", buffer_vertex_size, buffer_vertex_size - 8, (buffer_vertex_size - 8) * 3); */ if (1) printf("buffer_vertex_size after writing_space_faces_vertex = %4d - 8 = %3d (x 3 = %4d)\n", buffer_vertex_size, buffer_vertex_size - 8, (buffer_vertex_size - 8) * 3);
/* if (0) printf("(space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4 = %3d (x 3 = %4d)\n\n",\ */ if (1) 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); */ (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 */ /* A R R O W S */
/* for (int i = 0; i < arrows_nb; i++) { */ for (int i = 0; i < arrows_nb; i++) {
/* load = arrovvs[i].load; */ load = sworrah[i].load;
/* site = arrovvs[i].site; */ site = sworrah[i].site;
/* x = arrovvs[i].x; */ x = sworrah[i].x;
/* y = arrovvs[i].y; */ y = sworrah[i].y;
/* z = arrovvs[i].z; */ z = sworrah[i].z;
/* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */ buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size,
/* space_X, space_Y, space_Z, */ space_X, space_Y, space_Z,
/* load, site, x, y, z); */ load, site, x, y, z);
/* buffer_colors_size = buffer_vertex_size; */ buffer_colors_size = buffer_vertex_size;
/* } */ }
/* if (1) printf("buffer_vertex_size after writing_arrows_vertex : %d TODO (arrows_nb = %d)\n\n", buffer_vertex_size, arrows_nb); */ if (1) printf("buffer_vertex_size after writing_arrows_vertex : %d (x 3 = %d) (arrows_nb = %d)\n", buffer_vertex_size, buffer_vertex_size * 3, arrows_nb);
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
@ -774,27 +771,21 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* S P A C E */ /* S P A C E */
printf("Un problème, là : D'où vient l'accroissement inattendu de buffer_vertex_size ?\n\
write_space_ridges_vertex() renvoie 8; write_space_ridges_lines() renvoie 12\n");
buffer_vertex_size += write_space_ridges_lines (); buffer_vertex_size += write_space_ridges_lines ();
if (1) printf("buffer_vertex_size after writing_space_ridges_lines : %d (x 3 = %d)\n\n", buffer_vertex_size, buffer_vertex_size * 3);
/* int offset_test = 14; // 10 */ buffer_vertex_size += write_grids_on_space_faces_lines (buffer_vertex_size, space_X, space_Y, space_Z);
/* // */
/* buffer_vertex_size += write_grids_on_space_faces_lines (offset_test, space_X, space_Y, space_Z); */
/* if (1) printf("buffer_vertex_size after writing_space_faces_lines : %d (x 3 = %d)\n\n", buffer_vertex_size, buffer_vertex_size * 3); */
/* A R R O W S */ /* A R R O W S */
/* for (int i = 0; i < arrows_nb; i++) { */ for (int i = 0; i < arrows_nb; i++) {
/* load = arrovvs[i].load; */ load = sworrah[i].load;
/* site = arrovvs[i].site; */ site = sworrah[i].site;
/* x = arrovvs[i].x; */ x = sworrah[i].x;
/* y = arrovvs[i].y; */ y = sworrah[i].y;
/* z = arrovvs[i].z; */ z = sworrah[i].z;
/* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */ buffer_vertex_size += write_one_arrow_line (buffer_vertex_size);
/* } */ }
@ -809,43 +800,39 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/*--------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------*/
print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); arrows_nb = set_arrow (sworrah, arrows_nb,
arrows_nb = set_arrow (arrovvs, arrows_nb,
0,//rand() % arbitrary + 1, // load / weight 0,//rand() % arbitrary + 1, // load / weight
0,//rand() % 6, // site, 0,//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
print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); /* print_user_choices(sworrah, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
arrows_nb = set_arrow (arrovvs, arrows_nb, arrows_nb = set_arrow (sworrah, arrows_nb,
0,//rand() % arbitrary + 1, // load / weight 0,//rand() % arbitrary + 1, // load / weight
1,//rand() % 6, // site, 1,//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
print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); arrows_nb = set_arrow (sworrah, 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 (arrovvs, arrows_nb, */ arrows_nb = set_arrow (sworrah, arrows_nb,
/* 1,//rand() % arbitrary + 1, // load / weight */ 1,//rand() % arbitrary + 1, // load / weight
/* 2,//rand() % 6, // site, */ 3,//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 (arrovvs, arrows_nb, */ 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");
/* 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(sworrah, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
/* print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
// buffer_vertex_size -= 2; // buffer_vertex_size -= 2;
// buffer_vertex_size += 3; // buffer_vertex_size += 3;
@ -861,7 +848,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* random_choice = rand() % 6; */ /* random_choice = rand() % 6; */
/* if (random_choice == 0) deleted++; */ /* if (random_choice == 0) deleted++; */
/* modified = set_arrow (arrovvs, arrows_nb + modified, */ /* modified = set_arrow (sworrah, arrows_nb + modified, */
/* random_choice, // load / weight */ /* random_choice, // load / weight */
/* rand() % 6, // site, */ /* rand() % 6, // site, */
/* rand() % space_X, // x */ /* rand() % space_X, // x */
@ -873,11 +860,11 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* #pragma omp parallel */ /* #pragma omp parallel */
/* { */ /* { */
/* for (int i = 0; i < arrows_nb + modified; i++) { */ /* for (int i = 0; i < arrows_nb + modified; i++) { */
/* load = arrovvs[i].load; */ /* load = sworrah[i].load; */
/* site = arrovvs[i].site; */ /* site = sworrah[i].site; */
/* x = arrovvs[i].x; */ /* x = sworrah[i].x; */
/* y = arrovvs[i].y; */ /* y = sworrah[i].y; */
/* z = arrovvs[i].z; */ /* z = sworrah[i].z; */
/* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */ /* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */
/* space_X, space_Y, space_Z, */ /* space_X, space_Y, space_Z, */
@ -886,21 +873,21 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* } */ /* } */
/* for (int i = 0; i < arrows_nb + modified; i++) { */ /* for (int i = 0; i < arrows_nb + modified; i++) { */
/* load = arrovvs[i].load; */ /* load = sworrah[i].load; */
/* site = arrovvs[i].site; */ /* site = sworrah[i].site; */
/* x = arrovvs[i].x; */ /* x = sworrah[i].x; */
/* y = arrovvs[i].y; */ /* y = sworrah[i].y; */
/* z = arrovvs[i].z; */ /* z = sworrah[i].z; */
/* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */ /* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */
/* } */ /* } */
/* } */ /* } */
/* print_evolution (arrovvs, arrows_nb, arbitrary, deleted, print_arrows_data); */ /* print_evolution (sworrah, arrows_nb, arbitrary, deleted, print_arrows_data); */
// ? free (space) TODO // ? free (space) TODO
free(arrovvs); free(sworrah);
arrovvs = NULL; sworrah = NULL;
arrows_nb = 0; arrows_nb = 0;
} }