From fc271cf2efe9bb488a925eebe78c725c036b3ef0 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 16 Oct 2023 22:22:13 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20optimisation:=20les=20vertex=20d'abord,?= =?UTF-8?q?=20les=20lignes=20ensuite.=20(1=C3=A8r=20essai)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arrows.h | 6 +++- include/grid.h | 6 ++-- src/graphics/arrows.c | 18 ++++++++---- src/graphics/graphics.c | 46 +++++++++++++++++++++++++---- src/graphics/grid.c | 65 ++++++++++++++++++++++++++--------------- 5 files changed, 102 insertions(+), 39 deletions(-) diff --git a/include/arrows.h b/include/arrows.h index dd289d4..23a6f6d 100644 --- a/include/arrows.h +++ b/include/arrows.h @@ -38,7 +38,11 @@ typedef struct arrow_t { GLuint z; }; -int write_one_arrow(int offset_vertex, +int write_one_arrow_vertex (int offset_vertex, + int space_X, int space_Y, int space_Z, + int weight, int site, int x, int y, int z); + +int write_one_arrow_lines (int offset_vertex, int space_X, int space_Y, int space_Z, int weight, int site, int x, int y, int z); diff --git a/include/grid.h b/include/grid.h index ae7f021..e560148 100644 --- a/include/grid.h +++ b/include/grid.h @@ -34,7 +34,8 @@ * * @return void */ -int write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z); +int write_space_ridges_vertex (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z); +int write_space_ridges_lines (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z); /* * Writes grid lines on space faces @@ -43,5 +44,6 @@ int write_space_ridges (long offset_vertex, long offset_colors, long offset_line * * @return void */ -long write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style); +long write_grids_on_space_faces_vertex (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style); +long write_grids_on_space_faces_lines (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style); diff --git a/src/graphics/arrows.c b/src/graphics/arrows.c index ff736dc..4211a28 100644 --- a/src/graphics/arrows.c +++ b/src/graphics/arrows.c @@ -110,7 +110,7 @@ static void arrows_write_basis(long offset) /******************************************************************************/ -int write_one_arrow(int offset_vertex, +int write_one_arrow_vertex (int offset_vertex, int space_X_int, int space_Y_int, int space_Z_int, int weight, int site, int arrow_x, int arrow_y, int arrow_z) { @@ -149,11 +149,6 @@ int write_one_arrow(int offset_vertex, graphics_write_color(0.3f, 0.3f, 0.3f); graphics_write_color(0.3f, 0.3f, 0.3f); - /* graphics_write_line (offset_vertex + 0, offset_vertex + 1); */ - /* graphics_write_line (offset_vertex + 2, offset_vertex + 3); */ - /* graphics_write_line (offset_vertex + 4, offset_vertex + 5); */ - - GLfloat nuance = 0.24f; // X - X (EAST - WEST) axis - arrows tips (red - green) @@ -174,6 +169,17 @@ int write_one_arrow(int offset_vertex, graphics_write_color(0.0f + nuance * 2, 0.0f + nuance * 2, 1.0f - nuance); graphics_write_color(1.0f - nuance / 3, 1.0f - nuance / 3, 0.0f + nuance); + return 12; +} + + +int write_one_arrow_lines(int offset_vertex, + int space_X_int, int space_Y_int, int space_Z_int, + int weight, int site, int arrow_x, int arrow_y, int arrow_z) +{ + /* graphics_write_line (offset_vertex + 0, offset_vertex + 1); */ + /* graphics_write_line (offset_vertex + 2, offset_vertex + 3); */ + /* graphics_write_line (offset_vertex + 4, offset_vertex + 5); */ switch(site){ case EAST: case WEST: write_arrow_lines_east_west (offset_vertex, weight, site); break; diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index e621e42..42e0ca8 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -675,7 +675,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) int rand(void); void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min); - int arbitrary = 10; + int arbitrary = 1000; int space_X = 1 + rand() % arbitrary, space_Y = 1 + rand() % arbitrary, space_Z = 1 + rand() % arbitrary; @@ -699,17 +699,25 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) print_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, show_space_design); - /* DATA ARE NOW ALL SPECIFIED - DRAWING CAN START */ + /* D A T A A R E N O W A L L S P E C I F I E D */ + + /* D R A W I N G C A N S T A R T */ + + /*---------------------------------------------------------------*/ + + /* V E R T E X F I R S T */ int offset_vertex = 0, offset_colors = 0, offset_lines = 0; - offset_vertex += write_space_ridges (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z); + /* S P A C E */ + + offset_vertex += write_space_ridges_vertex (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z); offset_colors = offset_vertex; - offset_vertex += write_grids_on_space_faces (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, show_space_design); + offset_vertex += write_grids_on_space_faces_vertex (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, show_space_design); offset_colors = offset_vertex; - /* ARROWS */ + /* A R R O W S */ for (int i = 0; i < arrows_nb; i++) { load = arrows[i].load; @@ -718,12 +726,38 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) y = arrows[i].y; z = arrows[i].z; - offset_vertex += write_one_arrow(offset_vertex, + offset_vertex += write_one_arrow_vertex(offset_vertex, space_X, space_Y, space_Z, load, site, x, y, z); offset_colors = offset_vertex; } + + /*---------------------------------------------------------------*/ + + /* L I N E S S E C O N D */ + + offset_vertex = 0; offset_colors = 0; offset_lines = 0; + + /* S P A C E */ + + offset_vertex += write_space_ridges_lines (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z); + + offset_vertex += write_grids_on_space_faces_lines (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, show_space_design); + + /* A R R O W S */ + + for (int i = 0; i < arrows_nb; i++) { + load = arrows[i].load; + site = arrows[i].site; + x = arrows[i].x; + y = arrows[i].y; + z = arrows[i].z; + + offset_vertex += write_one_arrow_lines (offset_vertex, space_X, space_Y, space_Z, + load, site, x, y, z); + } + // ? free (space) TODO free(arrows); arrows = NULL; diff --git a/src/graphics/grid.c b/src/graphics/grid.c index 8c88042..7743bc5 100644 --- a/src/graphics/grid.c +++ b/src/graphics/grid.c @@ -25,7 +25,7 @@ #include "../../include/base.h" #include "../../include/graphics.h" -int write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z) +int write_space_ridges_vertex (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z) { float max = fmax(x, y); max = fmax(max, z); graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, - z / max); @@ -49,6 +49,11 @@ int write_space_ridges (long offset_vertex, long offset_colors, long offset_line graphics_write_color (0.9f, 0.2f, 0.1f); graphics_write_color (0.9f, 0.2f, 0.1f); + return 8; +} + +int write_space_ridges_lines (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z) +{ graphics_write_line ( 0, 1); graphics_write_line ( 7, 4); graphics_write_line ( 0, 2); graphics_write_line ( 7, 5); graphics_write_line ( 0, 3); graphics_write_line ( 7, 6); @@ -60,7 +65,7 @@ int write_space_ridges (long offset_vertex, long offset_colors, long offset_line return 8; } -long write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style) +long write_grids_on_space_faces_vertex (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style) { float i, max = fmax(x, y); max = fmax(max, z); @@ -77,19 +82,8 @@ long write_grids_on_space_faces (long offset_vertex, long offset_colors, long of graphics_write_color (0.5f, 0.5f, 0.5f); } - for (i = 0; i < x - 1; i ++) { - - if (style) - graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); - graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); - graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); - if (style) - graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); - } - offset_vertex += (x - 1) * 4; offset_colors += (x - 1) * 4; - if (style) offset_lines += (x - 1) * 2; else offset_lines += (x - 1) * 4; for (i = 1; i < y; i++) { // (y - 2) * 4 @@ -104,19 +98,8 @@ long write_grids_on_space_faces (long offset_vertex, long offset_colors, long of graphics_write_color (0.5f, 0.5f, 0.5f); } - for (i = 0; i < y - 1; i ++) { - - if (style) - graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); - if (style) - graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); - graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); - graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); - } - offset_vertex += (y - 1) * 4; offset_colors += (y - 1) * 4; - if (style) offset_lines += (y - 1) * 2; else offset_lines += (y - 1) * 4; for (i = 1; i < z; i++) { // (z - 2) * 4 @@ -131,6 +114,38 @@ long write_grids_on_space_faces (long offset_vertex, long offset_colors, long of graphics_write_color (0.5f, 0.5f, 0.5f); } + return (x + y + z - 3) * 4; +} + + +long write_grids_on_space_faces_lines (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style) +{ + float i, max = fmax(x, y); max = fmax(max, z); + + for (i = 0; i < x - 1; i ++) { + + if (style) + graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); + graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); + graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); + if (style) + graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); + } + + /* if (style) offset_lines += (x - 1) * 2; else offset_lines += (x - 1) * 4; */ + + for (i = 0; i < y - 1; i ++) { + + if (style) + graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); + if (style) + graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); + graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); + graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); + } + + /* if (style) offset_lines += (y - 1) * 2; else offset_lines += (y - 1) * 4; */ + for (i = 0; i < z - 1; i ++) { graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); @@ -141,6 +156,8 @@ long write_grids_on_space_faces (long offset_vertex, long offset_colors, long of graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); } + printf("write_grids_on_space_faces_lines\n"); + return (x + y + z - 3) * 4; /* if (style) offset_lines += 2 * (space_X + space_Y + space_Z - 3); */ /* else offset_lines += 4 * (space_X + space_Y + space_Z - 3); */