WIP: une petite 'Erreur de segmentation' de la fonction create_arrow() mais erase_arrow est OK et l'affichage aussi
This commit is contained in:
parent
1240dfed43
commit
7942e69f5e
|
@ -531,7 +531,7 @@ bool compute_space(long model_size_x, long model_size_y, long model_size_z,
|
||||||
GLuint *lines_origin, GLuint *plans_origin)
|
GLuint *lines_origin, GLuint *plans_origin)
|
||||||
|
|
||||||
{
|
{
|
||||||
show_user_choices(model_size_x, model_size_y, model_size_z,
|
if (0) show_user_choices(model_size_x, model_size_y, model_size_z,
|
||||||
arrows, model_arrows_nb,
|
arrows, model_arrows_nb,
|
||||||
// pref_mark_unit_space, pref_style_lines_planes, pref_style_mix_colors,
|
// pref_mark_unit_space, pref_style_lines_planes, pref_style_mix_colors,
|
||||||
pref_show_grid);
|
pref_show_grid);
|
||||||
|
|
|
@ -47,11 +47,11 @@
|
||||||
/* ----------------- V A R I A B L E S G L O B A L E S ------------------ */
|
/* ----------------- V A R I A B L E S G L O B A L E S ------------------ */
|
||||||
|
|
||||||
// int model_dim; < INUTILE : dim est fonction de model_space_size_x, y ,z) */
|
// int model_dim; < INUTILE : dim est fonction de model_space_size_x, y ,z) */
|
||||||
int model_space_size_x = 0;
|
long model_space_size_x = 0;
|
||||||
int model_space_size_y = 0;
|
long model_space_size_y = 0;
|
||||||
int model_space_size_z = 0;
|
long model_space_size_z = 0;
|
||||||
int arrows_nb = 0;
|
long arrows_nb = 0;
|
||||||
int central_stars_nb = 0;
|
long central_stars_nb = 0;
|
||||||
|
|
||||||
GLfloat *buffer_vertex_origin = NULL;
|
GLfloat *buffer_vertex_origin = NULL;
|
||||||
GLfloat *buffer_colors_origin = NULL;
|
GLfloat *buffer_colors_origin = NULL;
|
||||||
|
@ -66,10 +66,10 @@ GLuint *buffer_plans_origin = NULL;
|
||||||
int pref_show_grid = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
|
int pref_show_grid = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
|
||||||
int pref_test_diagonal = 0; // diagonal test
|
int pref_test_diagonal = 0; // diagonal test
|
||||||
|
|
||||||
int buffer_vertex_size = 0;
|
long buffer_vertex_size = 0;
|
||||||
int buffer_colors_size = 0;
|
long buffer_colors_size = 0;
|
||||||
int buffer_lines_size = 0; // previously in graphics.h struct gl_area_entry.GLuint line_indices_nb;
|
long buffer_lines_size = 0; // previously in graphics.h struct gl_area_entry.GLuint line_indices_nb;
|
||||||
int buffer_plans_size = 0; // previously in graphics.h struct gl_area_entry.GLuint plan_indices_nb;
|
long buffer_plans_size = 0; // previously in graphics.h struct gl_area_entry.GLuint plan_indices_nb;
|
||||||
|
|
||||||
|
|
||||||
/* ----------------- O P E N G L D E B U G M E S S A G E S ------------ */
|
/* ----------------- O P E N G L D E B U G M E S S A G E S ------------ */
|
||||||
|
@ -642,10 +642,10 @@ static void compute_buffers_sizes(int model_space_size_x,
|
||||||
|
|
||||||
// buffer_lines_size += 16 + 20; // draw a small cube with diagonals
|
// buffer_lines_size += 16 + 20; // draw a small cube with diagonals
|
||||||
|
|
||||||
// buffer_lines_size -= 2;
|
// buffer_lines_size -= 2; // == TEST LINES BUFFER SIZE
|
||||||
|
|
||||||
if (0) printf("allocated buffers sizes :%4d/3 = %3d vertices, %4d/3 = %3d colors,\
|
if (0) printf("allocated buffers sizes :%4ld/3 = %3ld vertices, %4ld/3 = %3ld colors,\
|
||||||
%4d/2 = %3d lines, %4d/3 = %3d plans.\n",
|
%4ld/2 = %3ld lines, %4ld/3 = %3ld plans.\n",
|
||||||
buffer_vertex_size, buffer_vertex_size / 3,
|
buffer_vertex_size, buffer_vertex_size / 3,
|
||||||
buffer_colors_size, buffer_colors_size / 3,
|
buffer_colors_size, buffer_colors_size / 3,
|
||||||
buffer_lines_size, buffer_lines_size / 2,
|
buffer_lines_size, buffer_lines_size / 2,
|
||||||
|
@ -653,23 +653,21 @@ static void compute_buffers_sizes(int model_space_size_x,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define DETAIL 0
|
||||||
static bool rewrite_arrow (GLuint *arrows, long address, long weight,
|
static bool rewrite_arrow (GLuint *arrows, long address, long weight,
|
||||||
long site, long x, long y, long z)
|
long site, long x, long y, long z)
|
||||||
{
|
{
|
||||||
printf("write the arrow weight to %ld at (%ld, %ld, %ld, %ld)\n",\
|
if (DETAIL) printf("write the arrow weight to %ld at (%ld, %ld, %ld, %ld)\n",\
|
||||||
weight, site, x, y, z);
|
weight, site, x, y, z);
|
||||||
|
|
||||||
*(arrows + address + 0) = weight;
|
*(arrows + address + 0) = weight;
|
||||||
|
|
||||||
show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z,
|
|
||||||
arrows, arrows_nb, pref_show_grid);
|
|
||||||
return 1; /* replaces the load of the existing arrow by the load 'weight' */
|
return 1; /* replaces the load of the existing arrow by the load 'weight' */
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool create_arrow (GLuint *arrows, long weight, long site, long x, long y, long z)
|
static bool create_arrow (GLuint *arrows, long weight, long site, long x, long y, long z)
|
||||||
{
|
{
|
||||||
printf("create a new arrow with weight = %ld at (%ld, %ld, %ld, %ld)\n",\
|
if (DETAIL) printf("create a new arrow with weight = %ld at (%ld, %ld, %ld, %ld)\n",\
|
||||||
weight, site, x, y, z);
|
weight, site, x, y, z);
|
||||||
|
|
||||||
arrows_nb ++;
|
arrows_nb ++;
|
||||||
|
@ -683,17 +681,15 @@ static bool create_arrow (GLuint *arrows, long weight, long site, long x, long y
|
||||||
|
|
||||||
buffer_lines_size += 14;
|
buffer_lines_size += 14;
|
||||||
|
|
||||||
show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z,
|
|
||||||
arrows, arrows_nb, pref_show_grid);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool erase_arrow (GLuint *arrows, long address,
|
static bool erase_arrow (GLuint *arrows, long address,
|
||||||
long site, long x, long y, long z)
|
long site, long x, long y, long z)
|
||||||
{
|
{
|
||||||
if (1) printf("erase arrow at address %ld with values (%ld, %ld, %ld, %ld)\n",\
|
if (DETAIL) printf("erase arrow at address %ld with values (%ld, %ld, %ld, %ld)",\
|
||||||
address / 5, site, x, y, z);
|
address / 5, site, x, y, z);
|
||||||
if (1) printf("last arrow is %d, %d, %d, %d, %d\n",
|
if (DETAIL) printf(" last arrow is %d, %d, %d, %d, %d\n",
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 0),
|
*(arrows + (arrows_nb - 1) * 5 + 0),
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 1),
|
*(arrows + (arrows_nb - 1) * 5 + 1),
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 2),
|
*(arrows + (arrows_nb - 1) * 5 + 2),
|
||||||
|
@ -710,8 +706,6 @@ static bool erase_arrow (GLuint *arrows, long address,
|
||||||
buffer_lines_size -= 14;
|
buffer_lines_size -= 14;
|
||||||
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint) * 2);
|
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint) * 2);
|
||||||
|
|
||||||
show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z,
|
|
||||||
arrows, arrows_nb, pref_show_grid);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,9 +721,11 @@ static long check_for_arrow (GLuint *arrows, long site, long x, long y, long z)
|
||||||
f_z = *(arrows + i * 5 + 4);
|
f_z = *(arrows + i * 5 + 4);
|
||||||
|
|
||||||
if (f_site == site && f_x == x && f_y == y && f_z == z) {
|
if (f_site == site && f_x == x && f_y == y && f_z == z) {
|
||||||
if (f_weight > 1) printf("weight = %ld ", f_weight);
|
|
||||||
address = i * 5;
|
address = i * 5;
|
||||||
printf("found at %ld (%ld / 5 = %ld)\n", address, address, address / 5);
|
if (DETAIL) printf("arrows_nb = %ld checked arrow (%ld,%ld,%ld,%ld) found at address %ld (line %ld)",\
|
||||||
|
arrows_nb, site, x, y, z, address, address / 5);
|
||||||
|
if (DETAIL && f_weight > 1) printf(" weight = %ld", f_weight);
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return address; /* returns the address of the arrow if there is one
|
return address; /* returns the address of the arrow if there is one
|
||||||
|
@ -737,9 +733,36 @@ static long check_for_arrow (GLuint *arrows, long site, long x, long y, long z)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void show_arrows_array (GLuint *arrows, long arrows_nb, long address, long weight, long site, long x, long y, long z)
|
||||||
|
{
|
||||||
|
printf("\n\n[ n] load | site x y z ----- < arrows_nb = %ld > -------", arrows_nb);
|
||||||
|
if (arrows_nb == address) printf(" graphic state ----------------\n");
|
||||||
|
else printf("------------------------------------------\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < arrows_nb; i++)
|
||||||
|
{
|
||||||
|
printf("[%2d] = %2d | %2d, %2d, %2d, %2d ",\
|
||||||
|
i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
|
||||||
|
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
|
||||||
|
if (weight == 0 && i == address / 5) printf(" <<<| < - > (%d, %d, %d, %d) @ [%ld]",\
|
||||||
|
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
|
||||||
|
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
|
||||||
|
if (weight > 0 && i == arrows_nb - 1) printf(" <<< < + > (%d, %d, %d, %d) @ [%ld]",\
|
||||||
|
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
|
||||||
|
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
|
||||||
|
if (weight == 0 && i > address / 5 && i < arrows_nb - 1) printf(" |");
|
||||||
|
if (weight == 0 && i == arrows_nb - 1) printf(" >>>|");
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool set_arrow (GLuint *arrows, long weight, long site, long x, long y, long z)
|
static bool set_arrow (GLuint *arrows, long weight, long site, long x, long y, long z)
|
||||||
{
|
{
|
||||||
|
|
||||||
long address = (check_for_arrow (arrows, site, x, y, z));
|
long address = (check_for_arrow (arrows, site, x, y, z));
|
||||||
|
if (1) show_arrows_array(arrows, arrows_nb, address, weight, site, x, y, z);
|
||||||
|
|
||||||
if (address == -1 && weight == 0) return 0;
|
if (address == -1 && weight == 0) return 0;
|
||||||
if (address == -1 && weight > 0) return create_arrow (arrows, weight, site, x, y, z);
|
if (address == -1 && weight > 0) return create_arrow (arrows, weight, site, x, y, z);
|
||||||
if (address >= 0 && weight == 0) return erase_arrow (arrows, address, site, x, y, z);
|
if (address >= 0 && weight == 0) return erase_arrow (arrows, address, site, x, y, z);
|
||||||
|
@ -830,13 +853,22 @@ void graphics_init_buffers(const void *gl_area)
|
||||||
set_arrow(arrows, 0, 2, 2, 1, 1);
|
set_arrow(arrows, 0, 2, 2, 1, 1);
|
||||||
set_arrow(arrows, 0, 3, 2, 2, 1);
|
set_arrow(arrows, 0, 3, 2, 2, 1);
|
||||||
|
|
||||||
set_arrow(arrows, 1, 0, 0, 0, 2);
|
set_arrow(arrows, 0, 0, 0, 0, 0);
|
||||||
set_arrow(arrows, 1, 1, 1, 0, 2);
|
set_arrow(arrows, 0, 1, 1, 0, 0);
|
||||||
set_arrow(arrows, 1, 2, 0, 0, 2);
|
set_arrow(arrows, 0, 1, 3, 0, 0);
|
||||||
set_arrow(arrows, 1, 3, 0, 1, 2);
|
set_arrow(arrows, 0, 0, 2, 0, 0);
|
||||||
|
set_arrow(arrows, 0, 4, 0, 1, 0);
|
||||||
|
set_arrow(arrows, 0, 5, 0, 1, 1);
|
||||||
|
|
||||||
|
// set_arrow(arrows, 1, 0, 0, 0, 2);
|
||||||
|
// set_arrow(arrows, 1, 1, 1, 0, 2);
|
||||||
|
/* set_arrow(arrows, 1, 2, 0, 0, 2); */
|
||||||
|
/* set_arrow(arrows, 1, 3, 0, 1, 2); */
|
||||||
|
|
||||||
// set_arrow(arrows, 2, 1, 1, 0, 2);
|
// set_arrow(arrows, 2, 1, 1, 0, 2);
|
||||||
|
|
||||||
|
if (1) show_arrows_array(arrows, arrows_nb, arrows_nb, -1, -1, -1, -1, -1);
|
||||||
|
|
||||||
draw_some_arrows (buffer_lines_origin, s,
|
draw_some_arrows (buffer_lines_origin, s,
|
||||||
model_space_size_z * model_space_size_y, model_space_size_z,
|
model_space_size_z * model_space_size_y, model_space_size_z,
|
||||||
arrows, arrows_nb);
|
arrows, arrows_nb);
|
||||||
|
|
Loading…
Reference in New Issue