WIP: in /graphics.c (1) g_realloc() only if (arrows_nb > 0) line 603 & (2) abnormal value of buffer_vertex_size (line 738)
This commit is contained in:
parent
3f708e2afc
commit
7813041ad5
|
@ -35,9 +35,8 @@
|
|||
#define VERTEX_SHADER_FILE "src/shaders/shader.vert"
|
||||
#define FRAG_SHADER_FILE "src/shaders/shader.frag"
|
||||
|
||||
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 struct arrow_t *arrovvs; /* 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;
|
||||
|
@ -134,7 +133,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 + 2] = z;
|
||||
|
||||
if (1) printf("In graphics_write_vertex() buffer_vertex_size = %d > %d (%6.3f,%6.3f,%6.3f)\n",\
|
||||
if (1) printf("In graphics_write_vertex() buffer_vertex_size = %2d > %2d (%6.3f,%6.3f,%6.3f)\n",\
|
||||
buffer_vertex_size, buffer_vertex_size + 3, x, y, z);
|
||||
|
||||
buffer_vertex_size += 3;
|
||||
|
@ -552,9 +551,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)
|
||||
{
|
||||
sworrah[address].load = load;
|
||||
arrovvs[address].load = load;
|
||||
|
||||
print_arrows_array (sworrah, arrows_nb, 2);
|
||||
print_arrows_array (arrovvs, arrows_nb, 2);
|
||||
|
||||
return arrows_nb;
|
||||
}
|
||||
|
@ -565,22 +564,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(sworrah, (arrows_nb + 1) * sizeof(struct arrow_t));
|
||||
void *newptr = g_realloc(arrovvs, (arrows_nb + 1) * sizeof(struct arrow_t));
|
||||
|
||||
if (newptr)
|
||||
sworrah = newptr;
|
||||
arrovvs = newptr;
|
||||
else
|
||||
perror("In create arrow, can't allocate new arrow buffer !\n");
|
||||
|
||||
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;
|
||||
arrovvs[arrows_nb].load = load;
|
||||
arrovvs[arrows_nb].site = site;
|
||||
arrovvs[arrows_nb].x = x;
|
||||
arrovvs[arrows_nb].y = y;
|
||||
arrovvs[arrows_nb].z = z;
|
||||
|
||||
arrows_nb ++;
|
||||
|
||||
print_arrows_array (sworrah, arrows_nb, 1);
|
||||
print_arrows_array (arrovvs, arrows_nb, 1);
|
||||
|
||||
return arrows_nb;
|
||||
}
|
||||
|
@ -592,28 +591,30 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int
|
|||
{
|
||||
arrows_nb --;
|
||||
|
||||
if (arrows_nb > 0)
|
||||
if (1)
|
||||
{
|
||||
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;
|
||||
arrovvs[address].load = arrovvs[arrows_nb].load;
|
||||
arrovvs[address].site = arrovvs[arrows_nb].site;
|
||||
arrovvs[address].x = arrovvs[arrows_nb].x;
|
||||
arrovvs[address].y = arrovvs[arrows_nb].y;
|
||||
arrovvs[address].z = arrovvs[arrows_nb].z;
|
||||
}
|
||||
|
||||
/* void *newptr = g_realloc(sworrah, arrows_nb * sizeof(struct arrow_t)); */
|
||||
if (arrows_nb > 0) {
|
||||
void *newptr = g_realloc(arrovvs, arrows_nb * sizeof(struct arrow_t));
|
||||
|
||||
/* if (newptr) */
|
||||
/* sworrah = newptr; */
|
||||
/* else */
|
||||
/* perror("In erase arrow, can't allocate new arrow buffer !\n"); */
|
||||
if (newptr)
|
||||
arrovvs = newptr;
|
||||
else
|
||||
perror("In erase arrow, can't allocate new arrow buffer !\n");
|
||||
}
|
||||
|
||||
print_arrows_array (sworrah, arrows_nb,0);
|
||||
print_arrows_array (arrovvs, arrows_nb,0);
|
||||
|
||||
return arrows_nb;
|
||||
}
|
||||
|
||||
static inline void show_user_action(struct arrow_t *sworrah, int arrows_nb, int address, int requested_weight,
|
||||
static inline void show_user_action(struct arrow_t *arrovvs, 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()
|
||||
|
@ -623,27 +624,27 @@ static inline void show_user_action(struct arrow_t *sworrah, int arrows_nb, int
|
|||
* - 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 *sworrah, 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 *arrovvs, 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 == sworrah[i].site)
|
||||
&& (x == sworrah[i].x)
|
||||
&& (y == sworrah[i].y)
|
||||
&& (z == sworrah[i].z))
|
||||
if ((site == arrovvs[i].site)
|
||||
&& (x == arrovvs[i].x)
|
||||
&& (y == arrovvs[i].y)
|
||||
&& (z == arrovvs[i].z))
|
||||
{
|
||||
address = i * 5;
|
||||
current_weight = sworrah[i].load;
|
||||
current_weight = arrovvs[i].load;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//printf("\n[%d]set_arrow() invoked with requested weight = %2d + ", arrows_nb, requested_weight);
|
||||
|
||||
if (TEST) show_user_action(sworrah, arrows_nb, address, requested_weight, current_weight, site, x, y, z);
|
||||
if (TEST) show_user_action(arrovvs, 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);
|
||||
|
@ -654,9 +655,9 @@ static inline int set_arrow (struct arrow_t *sworrah, int arrows_nb, int request
|
|||
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(sworrah, arrows_nb, 3);
|
||||
if (! TEST && address >= 0 && current_weight == requested_weight) print_arrows_array(arrovvs, arrows_nb, 3);
|
||||
|
||||
if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(sworrah, arrows_nb, 4);
|
||||
if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(arrovvs, arrows_nb, 4);
|
||||
|
||||
return arrows_nb;
|
||||
}
|
||||
|
@ -699,14 +700,14 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
|
|||
#pragma omp parallel
|
||||
{
|
||||
/* while (arrows_nb < specif_arrows_nb){ */
|
||||
arrows_nb = set_arrow (sworrah, arrows_nb,
|
||||
arrows_nb = set_arrow (arrovvs, 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 (sworrah, arrows_nb,
|
||||
arrows_nb = set_arrow (arrovvs, arrows_nb,
|
||||
1,//rand() % arbitrary + 1, // load / weight
|
||||
1,//rand() % 6, // site,
|
||||
0,//rand() % space_X, // x
|
||||
|
@ -732,35 +733,37 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
|
|||
|
||||
/* 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_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);
|
||||
|
||||
buffer_vertex_size += write_grids_on_space_faces_vertex (space_X, space_Y, space_Z);
|
||||
buffer_colors_size = buffer_vertex_size;
|
||||
/* 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_space_faces_vertex = %4d - 8 = %3d (x 3 = %4d)\n\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",\
|
||||
(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);
|
||||
/* 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 (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 */
|
||||
|
||||
for (int i = 0; i < arrows_nb; i++) {
|
||||
load = sworrah[i].load;
|
||||
site = sworrah[i].site;
|
||||
x = sworrah[i].x;
|
||||
y = sworrah[i].y;
|
||||
z = sworrah[i].z;
|
||||
/* for (int i = 0; i < arrows_nb; i++) { */
|
||||
/* load = arrovvs[i].load; */
|
||||
/* site = arrovvs[i].site; */
|
||||
/* x = arrovvs[i].x; */
|
||||
/* y = arrovvs[i].y; */
|
||||
/* z = arrovvs[i].z; */
|
||||
|
||||
buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size,
|
||||
space_X, space_Y, space_Z,
|
||||
load, site, x, y, z);
|
||||
buffer_colors_size = buffer_vertex_size;
|
||||
}
|
||||
/* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */
|
||||
/* 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_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 TODO (arrows_nb = %d)\n\n", buffer_vertex_size, arrows_nb); */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
|
@ -771,25 +774,27 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
|
|||
|
||||
/* 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 ();
|
||||
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 (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);
|
||||
/* int offset_test = 14; // 10 */
|
||||
/* // */
|
||||
/* 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 */
|
||||
|
||||
for (int i = 0; i < arrows_nb; i++) {
|
||||
load = sworrah[i].load;
|
||||
site = sworrah[i].site;
|
||||
x = sworrah[i].x;
|
||||
y = sworrah[i].y;
|
||||
z = sworrah[i].z;
|
||||
/* for (int i = 0; i < arrows_nb; i++) { */
|
||||
/* load = arrovvs[i].load; */
|
||||
/* site = arrovvs[i].site; */
|
||||
/* x = arrovvs[i].x; */
|
||||
/* y = arrovvs[i].y; */
|
||||
/* z = arrovvs[i].z; */
|
||||
|
||||
buffer_vertex_size += write_one_arrow_line (buffer_vertex_size);
|
||||
}
|
||||
/* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
|
@ -804,39 +809,43 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
|
|||
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
|
||||
arrows_nb = set_arrow (sworrah, arrows_nb,
|
||||
print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0);
|
||||
|
||||
arrows_nb = set_arrow (arrovvs, 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(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);
|
||||
|
||||
arrows_nb = set_arrow (sworrah, arrows_nb,
|
||||
arrows_nb = set_arrow (arrovvs, 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 (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
|
||||
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
|
||||
3,//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, */
|
||||
/* 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 */
|
||||
|
||||
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");
|
||||
/* arrows_nb = set_arrow (arrovvs, 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(sworrah, 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"); */
|
||||
|
||||
/* print_user_choices(arrovvs, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, 0); */
|
||||
|
||||
// buffer_vertex_size -= 2;
|
||||
// buffer_vertex_size += 3;
|
||||
|
@ -852,7 +861,7 @@ printf("On devrait avoir deux flèches Y+Y- (Zénith-Nadir) dessinées (au lieu
|
|||
/* random_choice = rand() % 6; */
|
||||
/* if (random_choice == 0) deleted++; */
|
||||
|
||||
/* modified = set_arrow (sworrah, arrows_nb + modified, */
|
||||
/* modified = set_arrow (arrovvs, arrows_nb + modified, */
|
||||
/* random_choice, // load / weight */
|
||||
/* rand() % 6, // site, */
|
||||
/* rand() % space_X, // x */
|
||||
|
@ -864,11 +873,11 @@ printf("On devrait avoir deux flèches Y+Y- (Zénith-Nadir) dessinées (au lieu
|
|||
/* #pragma omp parallel */
|
||||
/* { */
|
||||
/* for (int i = 0; i < arrows_nb + modified; i++) { */
|
||||
/* load = sworrah[i].load; */
|
||||
/* site = sworrah[i].site; */
|
||||
/* x = sworrah[i].x; */
|
||||
/* y = sworrah[i].y; */
|
||||
/* z = sworrah[i].z; */
|
||||
/* load = arrovvs[i].load; */
|
||||
/* site = arrovvs[i].site; */
|
||||
/* x = arrovvs[i].x; */
|
||||
/* y = arrovvs[i].y; */
|
||||
/* z = arrovvs[i].z; */
|
||||
|
||||
/* buffer_vertex_size += write_one_arrow_vertex(buffer_vertex_size, */
|
||||
/* space_X, space_Y, space_Z, */
|
||||
|
@ -877,21 +886,21 @@ printf("On devrait avoir deux flèches Y+Y- (Zénith-Nadir) dessinées (au lieu
|
|||
/* } */
|
||||
|
||||
/* for (int i = 0; i < arrows_nb + modified; i++) { */
|
||||
/* load = sworrah[i].load; */
|
||||
/* site = sworrah[i].site; */
|
||||
/* x = sworrah[i].x; */
|
||||
/* y = sworrah[i].y; */
|
||||
/* z = sworrah[i].z; */
|
||||
/* load = arrovvs[i].load; */
|
||||
/* site = arrovvs[i].site; */
|
||||
/* x = arrovvs[i].x; */
|
||||
/* y = arrovvs[i].y; */
|
||||
/* z = arrovvs[i].z; */
|
||||
|
||||
/* buffer_vertex_size += write_one_arrow_line (buffer_vertex_size); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* print_evolution (sworrah, arrows_nb, arbitrary, deleted, print_arrows_data); */
|
||||
/* print_evolution (arrovvs, arrows_nb, arbitrary, deleted, print_arrows_data); */
|
||||
|
||||
|
||||
// ? free (space) TODO
|
||||
free(sworrah);
|
||||
sworrah = NULL;
|
||||
free(arrovvs);
|
||||
arrovvs = NULL;
|
||||
arrows_nb = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue