Compare commits

...

2 Commits

1 changed files with 96 additions and 111 deletions

View File

@ -35,7 +35,9 @@
#define VERTEX_SHADER_FILE "src/shaders/shader.vert"
#define FRAG_SHADER_FILE "src/shaders/shader.frag"
static struct arrow_t *sworra;
static struct arrow_t *sworrah; /* "arrows" était devenu un peu trop populaire :
* (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_colors_origin = NULL;
static GLuint *buffer_lines_origin = NULL;
@ -132,7 +134,8 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z)
buffer_vertex_origin[buffer_vertex_size + 1] = y;
buffer_vertex_origin[buffer_vertex_size + 2] = z;
if (0) printf("buffer_vertex_size = %d (%6.3f,%6.3f,%6.3f)\n", buffer_vertex_size, x, y, z);
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 += 3;
}
@ -549,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)
{
sworra[address].load = load;
sworrah[address].load = load;
print_arrows_array (sworra, arrows_nb, 2);
print_arrows_array (sworrah, arrows_nb, 2);
return arrows_nb;
}
@ -562,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)
{
void *newptr = g_realloc(sworra, (arrows_nb + 1) * sizeof(struct arrow_t));
void *newptr = g_realloc(sworrah, (arrows_nb + 1) * sizeof(struct arrow_t));
if (newptr)
sworra = newptr;
sworrah = newptr;
else
perror("In create arrow, can't allocate new arrow buffer !\n");
sworra[arrows_nb].load = load;
sworra[arrows_nb].site = site;
sworra[arrows_nb].x = x;
sworra[arrows_nb].y = y;
sworra[arrows_nb].z = z;
sworrah[arrows_nb].load = load;
sworrah[arrows_nb].site = site;
sworrah[arrows_nb].x = x;
sworrah[arrows_nb].y = y;
sworrah[arrows_nb].z = z;
arrows_nb ++;
print_arrows_array (sworra, arrows_nb, 1);
print_arrows_array (sworrah, arrows_nb, 1);
return arrows_nb;
}
@ -591,26 +594,26 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int
if (arrows_nb > 0)
{
sworra[address].load = sworra[arrows_nb].load;
sworra[address].site = sworra[arrows_nb].site;
sworra[address].x = sworra[arrows_nb].x;
sworra[address].y = sworra[arrows_nb].y;
sworra[address].z = sworra[arrows_nb].z;
sworrah[address].load = sworrah[arrows_nb].load;
sworrah[address].site = sworrah[arrows_nb].site;
sworrah[address].x = sworrah[arrows_nb].x;
sworrah[address].y = sworrah[arrows_nb].y;
sworrah[address].z = sworrah[arrows_nb].z;
}
/* void *newptr = g_realloc(sworra, arrows_nb * sizeof(struct arrow_t)); */
/* void *newptr = g_realloc(sworrah, arrows_nb * sizeof(struct arrow_t)); */
/* if (newptr) */
/* sworra = newptr; */
/* sworrah = newptr; */
/* else */
/* perror("In erase arrow, can't allocate new arrow buffer !\n"); */
print_arrows_array (sworra, arrows_nb,0);
print_arrows_array (sworrah, arrows_nb,0);
return arrows_nb;
}
static inline void show_user_action(struct arrow_t *sworra, 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);
/*
* Calls one of the functions create_arrow(), erase_arrow() or rewrite_arrow()
@ -620,27 +623,27 @@ static inline void show_user_action(struct arrow_t *sworra, int arrows_nb, int a
* - 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 *sworra, int arrows_nb, int requested_weight, int site, int x, int y, int z)
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;
#pragma omp parallel schedule(static, 12)
{
for (int i = 0; i < arrows_nb; i++) {
if ((site == sworra[i].site)
&& (x == sworra[i].x)
&& (y == sworra[i].y)
&& (z == sworra[i].z))
if ((site == sworrah[i].site)
&& (x == sworrah[i].x)
&& (y == sworrah[i].y)
&& (z == sworrah[i].z))
{
address = i * 5;
current_weight = sworra[i].load;
current_weight = sworrah[i].load;
break;
}
}
}
//printf("\n[%d]set_arrow() invoked with requested weight = %2d + ", arrows_nb, requested_weight);
if (TEST) show_user_action(sworra, 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)
return create_arrow (arrows_nb, requested_weight, site, x, y, z);
@ -651,9 +654,9 @@ static inline int set_arrow (struct arrow_t *sworra, int arrows_nb, int requeste
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(sworra, 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(sworra, arrows_nb, 4);
if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(sworrah, arrows_nb, 4);
return arrows_nb;
}
@ -678,8 +681,8 @@ 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);
int arbitrary = 3;
int space_X = 1,// + rand() % arbitrary,
space_Y = 1,// + rand() % arbitrary,
int space_X = 3,// + rand() % arbitrary,
space_Y = 2,// + rand() % arbitrary,
space_Z = 1;// + rand() % arbitrary;
int density_max = space_X * space_Y * space_Z;
int max = fmax(space_X, space_Y); max = fmax(max, space_Z);
@ -696,14 +699,14 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
#pragma omp parallel
{
/* while (arrows_nb < specif_arrows_nb){ */
arrows_nb = set_arrow (sworra, arrows_nb,
arrows_nb = set_arrow (sworrah, arrows_nb,
1,//rand() % arbitrary + 1, // load / weight
0,//rand() % 6, // site,
0,//rand() % space_X, // x
0,//rand() % space_Y, // y
0);//rand() % space_Z); // z
arrows_nb = set_arrow (sworra, arrows_nb,
arrows_nb = set_arrow (sworrah, arrows_nb,
1,//rand() % arbitrary + 1, // load / weight
1,//rand() % 6, // site,
0,//rand() % space_X, // x
@ -716,30 +719,6 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* } */
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");
}
// clock_t start, end;
/* Recording the starting clock tick.*/
// start = clock();
/* arbitrary = 26; */
/* space_X = arbitrary; space_Y = arbitrary; space_Z = arbitrary; */
/* density_max = space_X * space_Y * space_Z;
* C E T T E Q U A D R U P L E B O U C L E
* S A T U R E L ' E S P A C E S Y S T É M A T I Q U E M E N T */
/* for (int i =0; i < space_X; i++) */
/* for (int j =0; j < space_Y; j++) */
/* for (int k =0; k < space_Z; k++) */
/* for (int u =0; u < 6; u++) */
/* arrows_nb = set_arrow (sworra, arrows_nb, */
/* 1, // load / weight */
/* u,//i % 6, // site, */
/* i,//i % space_X, // x */
/* j,//i % space_Y, // y */
/* k//i % space_Z); */
/* ); */
// end = clock(); printf("Elapsed time %ld\n", end - start);
/* print_user_choices(sworra, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
/*--------------------------------------------------------------------------------*/
@ -751,105 +730,111 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* V E R T E X F I R S T */
int offset_vertex = 0, offset_colors = 0, offset_lines = 0;
/* S P A C E */
// float max = fmax(x, y); max = fmax(max, z);
offset_vertex += write_space_ridges_vertex (offset_vertex, space_X, space_Y, space_Z);
offset_colors = offset_vertex;
buffer_vertex_size += write_space_ridges_vertex (buffer_vertex_size, space_X, space_Y, space_Z);
buffer_colors_size = buffer_vertex_size;
if (0) printf("offset_vertex after writing_space_ridges_vertex : %d (x 3 = %d)\n\n", offset_vertex, offset_vertex * 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);
offset_vertex += write_grids_on_space_faces_vertex (space_X, space_Y, space_Z);
offset_colors = offset_vertex;
buffer_vertex_size += write_grids_on_space_faces_vertex (space_X, space_Y, space_Z);
buffer_colors_size = buffer_vertex_size;
if (0) printf("offset_vertex after writing_space_faces_vertex = %4d - 8 = %3d (x 3 = %4d)\n", offset_vertex, offset_vertex - 8, (offset_vertex - 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("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 (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);
/* A R R O W S */
for (int i = 0; i < arrows_nb; i++) {
load = sworra[i].load;
site = sworra[i].site;
x = sworra[i].x;
y = sworra[i].y;
z = sworra[i].z;
load = sworrah[i].load;
site = sworrah[i].site;
x = sworrah[i].x;
y = sworrah[i].y;
z = sworrah[i].z;
offset_vertex += write_one_arrow_vertex(offset_vertex,
buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size,
space_X, space_Y, space_Z,
load, site, x, y, z);
offset_colors = offset_vertex;
buffer_colors_size = buffer_vertex_size;
}
if (0) printf("offset_vertex after writing_arrows_vertex : %d (x 3 = %d) (arrows_nb = %d)\n", offset_vertex, offset_vertex * 3, 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);
/*---------------------------------------------------------------*/
/* L I N E S S E C O N D */
offset_vertex = 0; offset_colors = 0; offset_lines = 0;
// buffer_vertex_size = 0; buffer_colors_size = 0; buffer_lines_size = 0;
/* S P A C E */
offset_vertex += write_space_ridges_lines ();
buffer_vertex_size += write_space_ridges_lines ();
offset_vertex += write_grids_on_space_faces_lines (offset_vertex, space_X, space_Y, space_Z);
buffer_vertex_size += write_grids_on_space_faces_lines (buffer_vertex_size, space_X, space_Y, space_Z);
/* A R R O W S */
for (int i = 0; i < arrows_nb; i++) {
load = sworra[i].load;
site = sworra[i].site;
x = sworra[i].x;
y = sworra[i].y;
z = sworra[i].z;
load = sworrah[i].load;
site = sworrah[i].site;
x = sworrah[i].x;
y = sworrah[i].y;
z = sworrah[i].z;
offset_vertex += write_one_arrow_line (offset_vertex);
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 */
/* B E F O R E B E I N G D R A W N 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 */
/*--------------------------------------------------------------------------------*/
arrows_nb = set_arrow (sworra, arrows_nb,
arrows_nb = set_arrow (sworrah, arrows_nb,
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
/* print_user_choices(sworra, 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 (sworra, arrows_nb,
arrows_nb = set_arrow (sworrah, arrows_nb,
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
arrows_nb = set_arrow (sworra, arrows_nb,
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 (sworra, arrows_nb,
arrows_nb = set_arrow (sworrah, 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
/* print_user_choices(sworra, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
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");
// offset_vertex -= 2;
/* print_user_choices(sworrah, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
// buffer_vertex_size -= 2;
// buffer_vertex_size += 3;
@ -863,7 +848,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* random_choice = rand() % 6; */
/* if (random_choice == 0) deleted++; */
/* modified = set_arrow (sworra, arrows_nb + modified, */
/* modified = set_arrow (sworrah, arrows_nb + modified, */
/* random_choice, // load / weight */
/* rand() % 6, // site, */
/* rand() % space_X, // x */
@ -875,34 +860,34 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
/* #pragma omp parallel */
/* { */
/* for (int i = 0; i < arrows_nb + modified; i++) { */
/* load = sworra[i].load; */
/* site = sworra[i].site; */
/* x = sworra[i].x; */
/* y = sworra[i].y; */
/* z = sworra[i].z; */
/* load = sworrah[i].load; */
/* site = sworrah[i].site; */
/* x = sworrah[i].x; */
/* y = sworrah[i].y; */
/* z = sworrah[i].z; */
/* offset_vertex += write_one_arrow_vertex(offset_vertex, */
/* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */
/* space_X, space_Y, space_Z, */
/* load, site, x, y, z); */
/* offset_colors = offset_vertex; */
/* buffer_colors_size = buffer_vertex_size; */
/* } */
/* for (int i = 0; i < arrows_nb + modified; i++) { */
/* load = sworra[i].load; */
/* site = sworra[i].site; */
/* x = sworra[i].x; */
/* y = sworra[i].y; */
/* z = sworra[i].z; */
/* load = sworrah[i].load; */
/* site = sworrah[i].site; */
/* x = sworrah[i].x; */
/* y = sworrah[i].y; */
/* z = sworrah[i].z; */
/* offset_vertex += write_one_arrow_line (offset_vertex); */
/* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */
/* } */
/* } */
/* print_evolution (sworra, arrows_nb, arbitrary, deleted, print_arrows_data); */
/* print_evolution (sworrah, arrows_nb, arbitrary, deleted, print_arrows_data); */
// ? free (space) TODO
free(sworra);
sworra = NULL;
free(sworrah);
sworrah = NULL;
arrows_nb = 0;
}