gem-graph-client/gg/displays.c

296 lines
15 KiB
C
Raw Normal View History

2024-04-30 18:59:44 +02:00
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* This file is part of Gem-graph.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <time.h>
#include "../../include/graphics.h"
/* Prints the arrows[] array
*
* For each arrow the following parameters are displayed :
* - rank in the array
* - load (or weight)
* - coordinates in space (site, x, y, z)
*/
void print_arrows_array (struct arrow_t *arrows, int arrows_nb, int invoked_by)
{
printf(" [rank] load | site x y z (");
switch (invoked_by) {
case 0: printf("after deletion) arrows_nb : %d", arrows_nb); break;
case 1: printf("after creation) arrows_nb : %d", arrows_nb); break;
case 2: printf("after modification) arrows_nb : %d", arrows_nb); break;
case 3: printf("address >= 0 && current_weight == requested_weight)"); break;
case 4: printf("address == -1 && requested_weight == 0)"); break;
case 5: printf("print_user_choices)"); break;
case 6: printf("print_evolution)"); break;
case 7: printf("before deletion) arrows_nb : %d", arrows_nb); break;
}
for (int i = 0; i < arrows_nb; i++)
printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, arrows[i].load,\
arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z);
if (arrows_nb == 0) printf("\n [NULL] ---- | ---- --- --- ---");
printf("\n");
}
/* Prints the initial user choices :
* - space dimension size and appearance (grids)
* - arrows[] array
* NB The space may be empty or saturated with arrows or any value in between
* Only one arrow per possible coordinates with a load max equal to ? TODO
*/
void print_user_choices(struct arrow_t *arrows, int max_arrows_nb, int arrows_nb,
int space_size_x, int space_size_y, int space_size_z,
int show_array, int show_space_design)
{
printf("model + user constraints :\tspace size x,y,z (%d,%d,%d)\tinitial (max) arrows nb : %d",\
space_size_x, space_size_y, space_size_z, max_arrows_nb);
if (show_space_design) printf(" (grilles alternées)");
printf("\n");
if (show_array) print_arrows_array (arrows, arrows_nb, 5);
}
/* Prints the evolution after adding / removing arrows :
* - arrows[] array
* NB The space may be empty or saturated with arrows or any value in between
* Only one arrow per possible coordinates with a load max equal to ? TODO
*
*
* print_evolution (arrows, added, mem, deleted, print_arrows_data);
*/
void print_evolution (struct arrow_t *arrows, int arrows_nb, int modified, int deleted, int show_array)
{
printf("evolution\t\t\t\t\t\t\tarrows nb > %6d\t (%d added / %d deleted) (modified : %d)\n",\
arrows_nb + modified - deleted * 2, modified - deleted, deleted, modified);
if (show_array) print_arrows_array (arrows, arrows_nb, 6);
}
/*
* Prints the arrows[] array
*
* For each arrow the following parameters are displayed :
* - rank in the array
* - weight (or load)
* - coordinates in space (site, x, y, z)
*/
void show_arrows_array_head(int one_batch_size, long nb_batches_specified, int verbose) {
printf("\n [rank] load | site x y z");
if (verbose) printf(" one batch size = %d nb_batches_specified = %ld",\
one_batch_size, nb_batches_specified);
}
void show_one_arrow_in_array(struct arrow_t *arrows, int i) {
printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d",\
i, arrows[i].load, arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z);
}
void show_empty_arrows_array() {printf("\n [NULL] ---- | ---- --- --- ---");}
void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int y, int z)
{
show_arrows_array_head (0,0,0);
for (int i = 0; i < arrows_nb; i++)
show_one_arrow_in_array(arrows, i);
if (arrows_nb == 0) show_empty_arrows_array();
}
/*
* Prints the initial user choices :
* - space dimension size and appearance (grids)
* - arrows[] array
* NB The space may be empty or saturated with arrows or any value in between
* To assert : Only one arrow per possible coordinates with a load max equal to ?
*/
void show_user_choices(long copy_nb_arrows_specified,
int space_size_x, int space_size_y, int space_size_z,
int prefer, int arbitrary, int one_batch_size)
{
printf("\nnb arrows specified = %ld", copy_nb_arrows_specified);
printf(" space size (x,y,z) = (%d,%d,%d)", space_size_x, space_size_y, space_size_z);
printf(" arbitrary = %d one_batch_size = %d", arbitrary, one_batch_size);
if (prefer == 0) printf(" prefer = %d <> show all grids", prefer);
if (prefer == 1) printf(" prefer = %d <> show no grid", prefer);
if (prefer > 1) printf(" show grids according rule (%d)", prefer);
}
/*
* Prints the result of the function set_arrow()
* and indicates the reasons of the choice (call) this function makes (see this function)
*/
#define TEST 0
void show_user_action(struct arrow_t *arrows, int arrows_nb, int address, int requested_weight,
int current_weight, int site, int x, int y, int z)
{
if (address == -1 && requested_weight > 0) { // *(arrows + i * 5 + 0)
printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); //arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]);
if (! TEST) printf("\n "); else printf(" ");
printf("=> CREATE"); return;}
if (address >= 0 && requested_weight == 0) {
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight);
if (! TEST) printf("\n "); else printf(" ");
printf("=> ERASE"); return;}
if (address >= 0 && current_weight != requested_weight) {
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight);
if (! TEST) printf("\n "); else printf(" ");
printf("=> MODIFY"); return;}
if (address >= 0 && current_weight == requested_weight){
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d;", site, x, y, z, address); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5);
if (! TEST) printf("\n "); else printf(" ");
printf("requested_weight == current_weight => END"); return;}
if (address == -1 && requested_weight == 0) {
printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]);
if (! TEST) printf("\n "); else printf(" ");
printf("=> END"); return;}
}
/*
* Prints vertex and lines buffers_states (sizes) at major one_batch_sizes and at the end of a session.
* Major one_batch_sizes are creation of grids and creation of arrows
* Arithmetic verification is provided at each one_batch_size
*/
void show_buffers_states(int space_X, int space_Y, int space_Z,
long nb_batches_specified, int one_batch_size,
int offset_after_grids, int buffer_vertex_size,
int buffer_lines_size_after_cubes, int buffer_lines_size)
{
int offset_after_arrows = buffer_vertex_size / 3, difference = offset_after_arrows - offset_after_grids;
printf("\n - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
printf("\n buffer_vertex_offset_after grids = %9d\t%9d = (x+1)*(y+1)*(z+1); <--> (x,y,z = %d,%d,%d)",\
offset_after_grids, (space_X + 1)*(space_Y + 1)*(space_Z + 1), space_X, space_Y, space_Z);
printf("\n buffer_vertex_offset_after arrows = %9d\t%9d = %d + %d; <--> %d = 12 x %d (%d cubes)",\
offset_after_arrows, offset_after_arrows, offset_after_grids,\
difference, difference, difference / 12, difference / 12);
printf("\n buffer_lines_offset after cubes = %9d\t%9d = 2 * (%dx%d + %dx%d + %dx%d); <--> 2 * (x*y + x*z + y*z)",\
buffer_lines_size_after_cubes, ((space_X+1) * (space_Y+1) + (space_X+1) * (space_Z+1) + (space_Y+1) * (space_Z+1)) * 2,
space_X+1, space_Y+1, space_X+1, space_Z+1, space_Y+1, space_Z+1);
printf("\n buffer_lines_offset after arrows = %9d\t%9d = %d + %d; <--> %d = 14 x %d (%d arrows drawned)",\
buffer_lines_size, buffer_lines_size, buffer_lines_size_after_cubes,\
buffer_lines_size - buffer_lines_size_after_cubes,\
buffer_lines_size - buffer_lines_size_after_cubes, (buffer_lines_size - buffer_lines_size_after_cubes) / 14,\
(buffer_lines_size - buffer_lines_size_after_cubes) / 14);
if (nb_batches_specified * one_batch_size == 0) printf("\n");
else printf("\n WARNING Arrows of the same address, whatever their weight, are drawn in superimposition. Check their list.");
printf("\n It happens that NOT all the specified arrows (%ld) = (%ld x %d) are drawned (%d) ! WHY ? (d = %ld)\n",\
nb_batches_specified * one_batch_size, nb_batches_specified, one_batch_size, (buffer_lines_size - buffer_lines_size_after_cubes) / 14,\
nb_batches_specified * one_batch_size - (buffer_lines_size - buffer_lines_size_after_cubes) / 14);
}
/*
* Prints the result of the function set_arrow()
* and indicates the reasons of the choice (call) this function makes (see this function)
*/
void print_user_action(struct arrow_t *arrows, int arrows_nb, int address, int requested_weight,
int current_weight, int site, int x, int y, int z)
{
if (address == -1 && requested_weight > 0) { // *(arrows + i * 5 + 0)
printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); //arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]);
if (! TEST) printf("\n "); else printf(" ");
printf("=> CREATE"); return;}
if (address >= 0 && requested_weight == 0) {
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight);
if (! TEST) printf("\n "); else printf(" ");
printf("=> ERASE"); return;}
if (address >= 0 && current_weight != requested_weight) {
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight);
if (! TEST) printf("\n "); else printf(" ");
printf("=> MODIFY"); return;}
if (address >= 0 && current_weight == requested_weight){
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d;", site, x, y, z, address); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5);
if (! TEST) printf("\n "); else printf(" ");
printf("requested_weight == current_weight => END"); return;}
if (address == -1 && requested_weight == 0) {
printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]);
if (! TEST) printf("\n "); else printf(" ");
printf("=> END"); return;}
}
static inline void print_buffers_array_head () {printf(" [rank] load | site x y z [address] buffer-vertex-1 buffer-vertex-2 buffer-lines\n");}
static inline void print_empty_buffers_array () {printf(" [NULL] ---- | ---- --- --- --- -1 --- --- ---\n");}
static void print_one_arrow_in_buffers (struct arrow_t *arrows,
GLfloat *buffer_vertex_origin, long buffer_vertex_0_arrow,
GLfloat *buffer_lines_origin, long buffer_lines_0_arrow,
int i, int arrows_nb, int address)
{
printf(" [%4d] = %2d | %2d, %2d, %2d, %2d, (%2d) %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %4f %4f\n",\
i,
arrows[i].load, arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z,
address,
buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 0],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 1],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 2],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 3],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 4],
buffer_vertex_origin [buffer_vertex_0_arrow + i * 6 + 5],
buffer_lines_origin [buffer_lines_0_arrow + i * 2 + 0],
buffer_lines_origin [buffer_lines_0_arrow + i * 2 + 1]);
}
void print_vertex_and_lines_buffers (struct arrow_t *arrows_ptr, int arrows_nb,
GLfloat *buffer_vertex_origin, long buffer_vertex_0_arrow,
GLfloat *buffer_lines_origin, long buffer_lines_0_arrow,
int address, int requested_weight, int current_weight, int site, int x, int y, int z)
{
/* for (int i = 0; i < 6; i++) printf("%5.2f ", buffer_vertex_origin [buffer_vertex_0_arrow + i]); printf("\n"); */
/* for (int i = 0; i < 6; i++) printf("%5.2f ", buffer_lines_origin [buffer_lines_0_arrow + i]); printf("\n"); */
print_buffers_array_head ();
for (int i = 0; i < arrows_nb; i++)
print_one_arrow_in_buffers(arrows_ptr, buffer_vertex_origin, buffer_vertex_0_arrow,
buffer_lines_origin, buffer_lines_0_arrow, i, arrows_nb, address);
if (arrows_nb == 0) print_empty_buffers_array();
}