WIP: avant débug de set_arrow()

This commit is contained in:
Jean Sirmai 2023-09-22 19:26:13 +02:00
parent d7fb58872b
commit 17f220dabd
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 162 additions and 21 deletions

View File

@ -52,41 +52,50 @@ static int buffer_plans_size = 0;
// par model_space_size_x, y, z et le nombre de sites // par model_space_size_x, y, z et le nombre de sites
static GLuint arrows[] = { static GLuint arrows[] = {
1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
1, 1, 0, 0, 0, 1, 1, 1, 0, 0,
1, 2, 0, 0, 0, /* 1, 1, 0, 0, 0, */
1, 3, 0, 0, 0, /* 1, 2, 0, 0, 0, */
1, 4, 0, 0, 0, /* 1, 3, 0, 0, 0, */
1, 5, 0, 0, 0, /* 1, 4, 0, 0, 0, */
// load, site, x, y, z /* 1, 5, 0, 0, 0, */
// load, site, x, y, z
}; };
static void show_user_choices(long space_size_x, static int get_arrows_nb(){
long space_size_y, if (sizeof(arrows) == 0) return 0;
long space_size_z, else return sizeof(arrows) / sizeof(arrows[0]) / 5;
}
static void show_user_choices(int space_size_x,
int space_size_y,
int space_size_z,
int prefer) int prefer)
{ {
int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5; int arrows_nb = get_arrows_nb();
printf("model + user constraints : space size x,y,z = %ld,%ld,%ld ", space_size_x, space_size_y, space_size_z); printf("model + user constraints : space size x,y,z = %d,%d,%d ", space_size_x, space_size_y, space_size_z);
if (arrows_nb > 0) printf("[%d] arrows ", arrows_nb); if (arrows_nb > 0) printf("[%d] arrows ", arrows_nb);
if (prefer == 0) printf("prefer = %d <> show all grids ", prefer); if (prefer == 0) printf("prefer = %d <> show all grids ", prefer);
if (prefer == 1) printf("prefer = %d <> show no grid ", prefer); if (prefer == 1) printf("prefer = %d <> show no grid ", prefer);
if (prefer > 1) printf("pref_show_grids = %d ", prefer); if (prefer > 1) printf("pref_show_grids = %d ", prefer);
if (arrows_nb == 0) printf("\tbuffer_vertex_size = %d\t lines = %d\n", buffer_vertex_size, buffer_lines_size); if (arrows_nb == 0) printf("\tbuffer_vertex_size = %d\t lines = %d\n", buffer_vertex_size, buffer_lines_size);
if (arrows_nb > 0) printf("\n| < arrows array > \ if (arrows_nb > 0) printf("\n [ n] load | site x y z \n -------------------------------\n");
|\n[ n] load site x y z \n-----------------------------\n"); for (int i = 0; i < arrows_nb; i++) printf(" [%2d] = %2d | %2d %2d %2d %2d\n",\
for (int i = 0; i < arrows_nb; i++) printf("[%2d] = %2d, %2d, %2d, %2d, %2d\n",\
i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4)); i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
if (arrows_nb > 0) printf("-----------------------------\n");} if (arrows_nb > 0) printf(" -------------------------------\n");}
static int set_arrow (GLuint *arrows, int weight, int site, int x, int y, int z);
static void get_model_data_and_user_preferences() static void get_model_data_and_user_preferences()
{ {
model_space_size_x = 1; // 0 < model_space_size_x model_space_size_x = 2; // 0 < model_space_size_x
model_space_size_y = 1; // 0 < model_space_size_y model_space_size_y = 1; // 0 < model_space_size_y
model_space_size_z = 1; // 0 < model_space_size_z model_space_size_z = 1; // 0 < model_space_size_z
pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
// xyz, 0, x, y, z, xy, xz, yz, xyz // xyz, 0, x, y, z, xy, xz, yz, xyz
show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z, show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z,
pref_show_grids); pref_show_grids);
// set_arrow(arrows, 1, 1, 1, 0, 0);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -96,6 +105,138 @@ static void get_model_data_and_user_preferences()
#define DETAIL 0
static bool rewrite_arrow (GLuint *arrows, int address, int weight,
int site, int x, int y, int z)
{
if (DETAIL) printf("write the arrow weight to %d at (%d, %d, %d, %d)\n",\
weight, site, x, y, z);
*(arrows + address + 0) = weight;
return 1; /* replaces the load of the existing arrow by the load 'weight' */
}
static bool create_arrow (GLuint *arrows, int weight, int site, int x, int y, int z)
{
int arrows_nb = get_arrows_nb();
arrows_nb ++;
buffer_lines_size += (3 + 4) * 2;
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint));
if (1) printf("create a new arrow with weight = %d at (%d, %d, %d, %d)\n",\
weight, site, x, y, z);
*(arrows + arrows_nb * 5 + 0) = weight;
*(arrows + arrows_nb * 5 + 1) = site;
*(arrows + arrows_nb * 5 + 2) = x;
*(arrows + arrows_nb * 5 + 3) = y;
*(arrows + arrows_nb * 5 + 4) = z;
return 1;
}
static bool erase_arrow (GLuint *arrows, int address,
int site, int x, int y, int z)
{
int arrows_nb = get_arrows_nb();
if (DETAIL) printf("erase arrow at address %d with values (%d, %d, %d, %d)",\
address / 5, site, x, y, z);
if (DETAIL) printf(" last arrow is %d, %d, %d, %d, %d\n",
*(arrows + (arrows_nb - 1) * 5 + 0),
*(arrows + (arrows_nb - 1) * 5 + 1),
*(arrows + (arrows_nb - 1) * 5 + 2),
*(arrows + (arrows_nb - 1) * 5 + 3),
*(arrows + (arrows_nb - 1) * 5 + 4));
*(arrows + address + 0) = *(arrows + (arrows_nb - 1) * 5 + 0);
*(arrows + address + 1) = *(arrows + (arrows_nb - 1) * 5 + 1);
*(arrows + address + 2) = *(arrows + (arrows_nb - 1) * 5 + 2);
*(arrows + address + 3) = *(arrows + (arrows_nb - 1) * 5 + 3);
*(arrows + address + 4) = *(arrows + (arrows_nb - 1) * 5 + 4);
arrows_nb --;
buffer_lines_size -= (3 + 4) * 2;
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint));
return 1;
}
static int check_for_arrow (GLuint *arrows, int site, int x, int y, int z)
{
int arrows_nb = get_arrows_nb();
if (arrows_nb == 0) return -1;
int address = -1, f_weight = -1, f_site = -1, f_x = -1, f_y = -1, f_z = -1;
for (int i = 0; i < arrows_nb; i++)
{
f_weight = *(arrows + i * 5 + 0);
f_site = *(arrows + i * 5 + 1);
f_x = *(arrows + i * 5 + 2);
f_y = *(arrows + i * 5 + 3);
f_z = *(arrows + i * 5 + 4);
if (f_site == site && f_x == x && f_y == y && f_z == z) {
address = i * 5;
if (DETAIL) printf("arrows_nb = %d checked arrow (%d,%d,%d,%d) found at address %d (line %d)",\
arrows_nb, site, x, y, z, address, address / 5);
if (DETAIL && f_weight > 1) printf(" weight = %d", f_weight);
if (DETAIL) printf("\n");
}
}
return address; /* returns the address of the arrow if there is one
* or (-1) if there is none */
}
static void show_arrows_array (GLuint *arrows, int address, int weight, int site, int x, int y, int z)
{
int arrows_nb = get_arrows_nb();
printf("\n [ n] load | site x y z ----- < arrows_nb = %d > ------", arrows_nb);
if (arrows_nb == 0) printf("--------------------------- no arrows\n");
else if (address == -1) printf("--------------------------- create new arrow\n");
else printf("--------------------------- erase arrow at address = %d / 5\n", address);
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) @ [%d]",\
*(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) @ [%d]",\
*(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 && i != address / 5) printf(" >>>|");
printf("\n");
}
}
static int set_arrow (GLuint *arrows, int weight, int site, int x, int y, int z)
{
int address = (check_for_arrow (arrows, site, x, y, z));
show_arrows_array(arrows, address, weight, site, x, y, z);
if (address == -1 && weight == 0) return 0;
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 rewrite_arrow (arrows, address, weight, site, x, y, z);
return 0;
}
@ -197,7 +338,7 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id,
void graphics_write_line (GLuint a, GLuint b) void graphics_write_line (GLuint a, GLuint b)
{ {
buffer_lines_origin = g_realloc (buffer_lines_origin, buffer_lines_origin = g_realloc (buffer_lines_origin,
(buffer_lines_size + 2) * sizeof(GLuint)); (buffer_lines_size + 2) * sizeof(GLuint));
assert (buffer_lines_origin); assert (buffer_lines_origin);
@ -261,7 +402,7 @@ void graphics_write_color (GLfloat r, GLfloat g, GLfloat b)
void graphics_write_plan (GLuint a, GLuint b, GLuint c) void graphics_write_plan (GLuint a, GLuint b, GLuint c)
{ {
buffer_plans_origin = g_realloc (buffer_plans_origin, buffer_plans_origin = g_realloc (buffer_plans_origin,
(buffer_plans_size + 3) * sizeof(GLuint)); (buffer_plans_size + 3) * sizeof(GLuint));
assert (buffer_plans_origin); assert (buffer_plans_origin);
@ -552,7 +693,7 @@ bool graphics_init(const char *gl_area)
// If it does exist, g_reallocs it // If it does exist, g_reallocs it
} else { } else {
gl_area_array = g_realloc(gl_area_array, gl_area_array = g_realloc(gl_area_array,
(array_size + 1) (array_size + 1)
* sizeof(struct gl_area_entry *)); * sizeof(struct gl_area_entry *));
assert (gl_area_array); assert (gl_area_array);
if (gl_area_array == NULL) { if (gl_area_array == NULL) {
@ -645,13 +786,13 @@ void main_test_graphics (void)
int offset_after_grids = buffer_vertex_size / 3; int offset_after_grids = buffer_vertex_size / 3;
if (1) printf("buffer_vertex_offset_after grids = %d (x+1)*(y+1)*(z+1) = %ld\n",\ if (1) printf("buffer_vertex_offset_after grids = %d (x+1)*(y+1)*(z+1) = %ld\n",\
offset_after_grids, (x+1)*(y+1)*(z+1)); offset_after_grids, (x+1)*(y+1)*(z+1));
/* ARROWS */ /* ARROWS */
arrows_write_terminations (x, y, z); arrows_write_terminations (x, y, z);
int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5; int arrows_nb = get_arrows_nb();
for (int i = 0; i < arrows_nb; i++) { for (int i = 0; i < arrows_nb; i++) {
site = arrows[i * 5 + 1]; site = arrows[i * 5 + 1];