From 04f6d1355b4a95ed2630d278c1653025c00432fc Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Wed, 5 Mar 2025 09:51:46 +0100 Subject: [PATCH 01/29] Commit initial - Projet territoire --- examples/territoire/territoire.cpp | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 examples/territoire/territoire.cpp diff --git a/examples/territoire/territoire.cpp b/examples/territoire/territoire.cpp new file mode 100644 index 0000000..7f4c4ed --- /dev/null +++ b/examples/territoire/territoire.cpp @@ -0,0 +1,2 @@ +// initial commit +//to do \ No newline at end of file From e87b84608bb30741b57f57bad64228a7aa4a879f Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Mon, 10 Mar 2025 16:32:16 +0100 Subject: [PATCH 02/29] Test_Godot --- project.godot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.godot b/project.godot index 725be9c..0436dd7 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.3", "Forward Plus") +config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From b2d4e2184d2f0e47512534952bab9e6e07e4e5c6 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Tue, 11 Mar 2025 08:33:40 +0100 Subject: [PATCH 03/29] add 2Dscene --- examples/territoire/test.tscn | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/territoire/test.tscn diff --git a/examples/territoire/test.tscn b/examples/territoire/test.tscn new file mode 100644 index 0000000..cc3ed51 --- /dev/null +++ b/examples/territoire/test.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://blnvvmlx5sccd"] + +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_85kph"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_lxh3h"] + +[node name="Test" type="Node2D"] + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_lxh3h") +glsl_file = "res://examples/territoire/territoire.cpp" +GLSL_code = "" +data = [NodePath("../Icon")] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(221, 191) +scale = Vector2(3.46875, 3) +texture = ExtResource("1_85kph") From 77f130a841aeb6175368721519d9e3dbb8e51686 Mon Sep 17 00:00:00 2001 From: Mathieu-Da-Costa Date: Tue, 11 Mar 2025 08:52:56 +0100 Subject: [PATCH 04/29] Create teri_test1.cpp --- examples/territoire/teri_test1.cpp | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/territoire/teri_test1.cpp diff --git a/examples/territoire/teri_test1.cpp b/examples/territoire/teri_test1.cpp new file mode 100644 index 0000000..0055cee --- /dev/null +++ b/examples/territoire/teri_test1.cpp @@ -0,0 +1,43 @@ + +#define ALIVE 0xFFFFFFFF +#define DEAD 0xFF0000FF + +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + if ( step == 0 ) { // initialisation ************************ + if ( current_pass == 0 ) { + data_1[p] = DEAD ; + if (data_0[p] < 0 || x==0 || y==0 || x==WSX-1 || y==WSY-1) + data_0[p] = DEAD ; + else + data_0[p] = ALIVE ; + } + } else { // in process ********************************* + if (current_pass == 0) + compute_next_step(x, y, p); + else + data_0[p] = data_1[p]; // The future is now + sleep(1); + } +} + +void compute_next_step(uint x, uint y, uint p) { + if ( x > 0 && y > 0 && x < WSX-1 && y < WSY - 1) { // in sandbox + uint n = 0 ; // Number of living neighbors + for (uint i = x-1; i <= x+1; i++) { + for (uint j = y-1; j <= y+1; j++) { + uint k = i + j * WSX; + if (k != p && data_0[k] == ALIVE ) + n++; + } + } + if (data_0[p] == DEAD) { + if ( n >= 1) + data_1[p] = ALIVE; // Birth + else + data_1[p] = DEAD ; + } + } +} \ No newline at end of file From 680e363e95ff96979099aff35bd696c03d1d3fad Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Tue, 11 Mar 2025 09:16:43 +0100 Subject: [PATCH 05/29] =?UTF-8?q?d=C3=A9but=20propagation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/territoire/territoire.cpp | 65 +++++++++++++++++++++++++++++- examples/territoire/test.tscn | 1 + 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/examples/territoire/territoire.cpp b/examples/territoire/territoire.cpp index 7f4c4ed..894ef86 100644 --- a/examples/territoire/territoire.cpp +++ b/examples/territoire/territoire.cpp @@ -1,2 +1,63 @@ -// initial commit -//to do \ No newline at end of file +#define MORT 0 +#define VIVANT 0xFFFFFFFF + +#define MIN_VOISINS_SURVIE 1 +#define MAX_VOISINS_SURVIE 2 +#define VOISINS_NAISSANCE 1 + +// Fonction pseudo-aléatoire basée sur les coordonnées +uint hash(uint x, uint y) { + uint a = x * 0x6A09E667; + uint b = y * 0xBB67AE85; + uint h = a + b; + h = (h ^ (h >> 16)) * 0x85EBCA6B; + h = (h ^ (h >> 13)) * 0xC2B2AE35; + h = h ^ (h >> 16); + return h; +} + +void main() { + // Récupération des coordonnées + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + if (step == 0) { + // Initialiser une seule cellule vivante à un emplacement spécifique + if (data_0[p] < 0) { + // Définir une cellule vivante au centre de la grille (par exemple) + if (x == WSX / 2 && y == WSY / 2) { // On place une cellule vivante au centre + data_0[p] = VIVANT; + } else { + data_0[p] = MORT; + } + } else { + data_0[p] = MORT; + } + } else { + int nb_voisins = 0; + + // Comptage des voisins vivants + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + if (!(dx == 0 && dy == 0)) { // Ne pas compter la cellule elle-même + int nx = int(x) + dx; + int ny = int(y) + dy; + + if (nx >= 0 && nx < WSX && ny >= 0 && ny < WSY) { + if (data_0[uint(nx + ny * WSX)] == VIVANT) { + nb_voisins++; + } + } + } + } + } + + // La cellule morte devient vivante si elle a 1 voisin vivant + if (data_0[p] == MORT) { + if (nb_voisins >= VOISINS_NAISSANCE) { + data_0[p] = VIVANT; + } + } + } +} diff --git a/examples/territoire/test.tscn b/examples/territoire/test.tscn index cc3ed51..d50ad25 100644 --- a/examples/territoire/test.tscn +++ b/examples/territoire/test.tscn @@ -7,6 +7,7 @@ [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] script = ExtResource("1_lxh3h") +WSX = 256 glsl_file = "res://examples/territoire/territoire.cpp" GLSL_code = "" data = [NodePath("../Icon")] From efdde4abc0fed4b6e36f09516f5caca06e41d05e Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Tue, 11 Mar 2025 09:31:09 +0100 Subject: [PATCH 06/29] Commit initial - Territoire envahir --- examples/territoire/envahir.cpp | 149 ++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 examples/territoire/envahir.cpp diff --git a/examples/territoire/envahir.cpp b/examples/territoire/envahir.cpp new file mode 100644 index 0000000..55a5d09 --- /dev/null +++ b/examples/territoire/envahir.cpp @@ -0,0 +1,149 @@ +// DEFINITIONS DES COULEURS ET ÉTATS +#define VIDE 0 +#define JOUEUR 0xFF0000FF // Rouge - Joueur humain +#define IA_1 0xFF00FF00 // Vert - IA 1 +#define IA_2 0xFFFF0000 // Bleu - IA 2 +#define IA_3 0xFFFFFF00 // Jaune - IA 3 + +// PARAMÈTRES DU JEU +#define FORCE_EXPANSION 0.15 // Probabilité d'expansion (0-1) +#define FORCE_CONQUETE 0.08 // Probabilité de conquête d'un territoire adverse (0-1) + +// Fonction pseudo-aléatoire basée sur les coordonnées et le step +int hash(int x, int y, int s) { + int a = x * 0x6A09E667; + int b = y * 0xBB67AE85; + int c = s * 0x3C6EF372; + int h = a + b + c; + h = (h ^ (h >> 16)) * 0x85EBCA6B; + h = (h ^ (h >> 13)) * 0xC2B2AE35; + h = h ^ (h >> 16); + return h; +} + +// Fonction pour déterminer si un événement aléatoire se produit +bool random_event(int x, int y, int step, float probability) { + int random_value = hash(x, y, step); + return (float(random_value) / 2147483647.0) < probability; +} + +void main() { + // Récupération des coordonnées + int x = int(gl_GlobalInvocationID.x); + int y = int(gl_GlobalInvocationID.y); + int p = x + y * int(WSX); + + if (step == 0) { + // INITIALISATION: PLACER LES TERRITOIRES DE DÉPART + if (x < int(WSX)/6 && y < int(WSY)/6) { + // Territoire du joueur (en haut à gauche) + data_0[p] = JOUEUR; + } else if (x > int(WSX)*5/6 && y < int(WSY)/6) { + // IA 1 (en haut à droite) + data_0[p] = IA_1; + } else if (x < int(WSX)/6 && y > int(WSY)*5/6) { + // IA 2 (en bas à gauche) + data_0[p] = IA_2; + } else if (x > int(WSX)*5/6 && y > int(WSY)*5/6) { + // IA 3 (en bas à droite) + data_0[p] = IA_3; + } else { + // Reste de la carte vide + data_0[p] = VIDE; + } + } else { + // LOGIQUE D'EXPANSION ET DE CONQUÊTE + int couleur_actuelle = data_0[p]; + + // SI LA CELLULE A UN PROPRIÉTAIRE + if (couleur_actuelle != VIDE) { + // TENTER D'ÉTENDRE LE TERRITOIRE + if (random_event(x, y, step, FORCE_EXPANSION)) { + // Choisir une direction aléatoire + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; + + // 8 directions possibles + switch (direction) { + case 0: dx = -1; dy = 0; break; // Gauche + case 1: dx = 1; dy = 0; break; // Droite + case 2: dx = 0; dy = -1; break; // Haut + case 3: dx = 0; dy = 1; break; // Bas + case 4: dx = -1; dy = -1; break; // Diagonale haut-gauche + case 5: dx = 1; dy = -1; break; // Diagonale haut-droite + case 6: dx = -1; dy = 1; break; // Diagonale bas-gauche + case 7: dx = 1; dy = 1; break; // Diagonale bas-droite + } + + // Calculer les nouvelles coordonnées + int nx = x + dx; + int ny = y + dy; + + // Vérifier les limites + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int voisin_p = nx + ny * int(WSX); + int couleur_voisin = data_0[voisin_p]; + + // Si le voisin est vide, l'occuper + if (couleur_voisin == VIDE) { + data_0[voisin_p] = couleur_actuelle; + } + // Si le voisin appartient à un autre joueur, tenter de le conquérir + else if (couleur_voisin != couleur_actuelle && random_event(x, y, step, FORCE_CONQUETE)) { + data_0[voisin_p] = couleur_actuelle; + } + } + } + } + // SI LA CELLULE EST VIDE + else { + // COMPTAGE DES VOISINS PAR COULEUR + int nb_voisins_joueur = 0; + int nb_voisins_ia1 = 0; + int nb_voisins_ia2 = 0; + int nb_voisins_ia3 = 0; + + // Parcours des 8 cellules voisines + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + if (!(dx == 0 && dy == 0)) { + int nx = x + dx; + int ny = y + dy; + + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int voisin = data_0[nx + ny * int(WSX)]; + if (voisin == JOUEUR) nb_voisins_joueur++; + else if (voisin == IA_1) nb_voisins_ia1++; + else if (voisin == IA_2) nb_voisins_ia2++; + else if (voisin == IA_3) nb_voisins_ia3++; + } + } + } + } + + // DÉTERMINER LE PROPRIÉTAIRE MAJORITAIRE PARMI LES VOISINS + int max_voisins = max(nb_voisins_joueur, max(nb_voisins_ia1, max(nb_voisins_ia2, nb_voisins_ia3))); + + // S'il y a au moins 2 voisins de la même couleur, coloniser + if (max_voisins >= 2) { + if (max_voisins == nb_voisins_joueur) data_0[p] = JOUEUR; + else if (max_voisins == nb_voisins_ia1) data_0[p] = IA_1; + else if (max_voisins == nb_voisins_ia2) data_0[p] = IA_2; + else if (max_voisins == nb_voisins_ia3) data_0[p] = IA_3; + } + + // INTERACTION AVEC LA SOURIS (SIMULATION) + // À chaque multiple de 100 steps, simuler un clic dans une zone aléatoire pour l'expansion du joueur + if (step % 100 == 0) { + // Calculer une position où le joueur "clique" + int click_x = (hash(0, step, 0) % int(WSX)); + int click_y = (hash(step, 0, 0) % int(WSY)); + + // Si nous sommes près de la position du "clic" et à proximité d'un territoire du joueur + if (abs(x - click_x) < 5 && abs(y - click_y) < 5 && nb_voisins_joueur > 0) { + data_0[p] = JOUEUR; // Conquête par le joueur + } + } + } + } +} \ No newline at end of file From 829bdf48d5e3473922bd188d1240b52eee4494be Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Tue, 11 Mar 2025 09:57:36 +0100 Subject: [PATCH 07/29] 11/03 fin de cours --- examples/territoire/territoire.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/territoire/territoire.cpp b/examples/territoire/territoire.cpp index 894ef86..119fe7f 100644 --- a/examples/territoire/territoire.cpp +++ b/examples/territoire/territoire.cpp @@ -5,7 +5,7 @@ #define MAX_VOISINS_SURVIE 2 #define VOISINS_NAISSANCE 1 -// Fonction pseudo-aléatoire basée sur les coordonnées + uint hash(uint x, uint y) { uint a = x * 0x6A09E667; uint b = y * 0xBB67AE85; @@ -17,15 +17,12 @@ uint hash(uint x, uint y) { } void main() { - // Récupération des coordonnées uint x = gl_GlobalInvocationID.x; uint y = gl_GlobalInvocationID.y; uint p = x + y * WSX; if (step == 0) { - // Initialiser une seule cellule vivante à un emplacement spécifique if (data_0[p] < 0) { - // Définir une cellule vivante au centre de la grille (par exemple) if (x == WSX / 2 && y == WSY / 2) { // On place une cellule vivante au centre data_0[p] = VIVANT; } else { @@ -40,7 +37,7 @@ void main() { // Comptage des voisins vivants for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { - if (!(dx == 0 && dy == 0)) { // Ne pas compter la cellule elle-même + if (!(dx == 0 && dy == 0)) { int nx = int(x) + dx; int ny = int(y) + dy; From 240468050a68e3073215937d652f2d3aee03bc4f Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Thu, 13 Mar 2025 04:49:07 +0100 Subject: [PATCH 08/29] Bonbon.cpp une extension gourmande de envahir --- examples/territoire/bonbon.cpp | 390 +++++++++++++++++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 examples/territoire/bonbon.cpp diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp new file mode 100644 index 0000000..2e43852 --- /dev/null +++ b/examples/territoire/bonbon.cpp @@ -0,0 +1,390 @@ +#define NEUTRE 0xFF808080 +#define JOUEUR 0xFF0000FF +#define IA_1 0xFF00FF00 +#define IA_2 0xFFFF0000 +#define IA_3 0xFFFFFF00 +#define BLANC 0xFFFFFFFF +#define NOIR 0xFF000000 + +#define CLICK_RADIUS 15 +#define AI_EXPANSION_RATE 0.03 + +// Stockage des coordonnees de la souris +#define MOUSE_STORAGE_X 0 +#define MOUSE_STORAGE_Y 1 +#define MOUSE_STORAGE_CLICKED 2 + +// Configuration de affichage du score +#define SCORE_Y int(WSY)/2 +#define DIGIT_WIDTH 8 +#define DIGIT_HEIGHT 12 +#define DIGIT_SPACING 10 + +int hash(int x, int y, int s) { + int a = x * 0x6A09E667; + int b = y * 0xBB67AE85; + int c = s * 0x3C6EF372; + int h = a + b + c; + h = (h ^ (h >> 16)) * 0x85EBCA6B; + h = (h ^ (h >> 13)) * 0xC2B2AE35; + h = h ^ (h >> 16); + return h; +} + +bool random_event(int x, int y, int step, float probability) { + int random_value = hash(x, y, step); + float normalized = float(random_value) / 2147483647.0; + return (normalized > 0.0 ? normalized : -normalized) < probability; +} + +// Dessine un segment horizontal +void drawHorizontalLine(int start_x, int y, int length, int color) { + for(int i = 0; i < length; i++) { + int pos = (start_x + i) + y * int(WSX); + if(start_x + i >= 0 && start_x + i < int(WSX) && y >= 0 && y < int(WSY)) { + data_0[pos] = color; + } + } +} + +// Dessine un segment vertical +void drawVerticalLine(int x, int start_y, int length, int color) { + for(int i = 0; i < length; i++) { + int pos = x + (start_y + i) * int(WSX); + if(x >= 0 && x < int(WSX) && start_y + i >= 0 && start_y + i < int(WSY)) { + data_0[pos] = color; + } + } +} + +// Dessine un chiffre +void drawDigit(int digit, int x, int y, int color) { + switch(digit) { + case 0: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); + drawVerticalLine(x, y, DIGIT_HEIGHT, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); + break; + case 1: + drawVerticalLine(x + DIGIT_WIDTH - 2, y, DIGIT_HEIGHT, color); + break; + case 2: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT/2, color); + drawVerticalLine(x, y + DIGIT_HEIGHT/2, DIGIT_HEIGHT/2, color); + break; + case 3: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); + break; + case 4: + drawVerticalLine(x, y, DIGIT_HEIGHT/2, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); + break; + case 5: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); + drawVerticalLine(x, y, DIGIT_HEIGHT/2, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y + DIGIT_HEIGHT/2, DIGIT_HEIGHT/2, color); + break; + case 6: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); + drawVerticalLine(x, y, DIGIT_HEIGHT, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y + DIGIT_HEIGHT/2, DIGIT_HEIGHT/2, color); + break; + case 7: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); + break; + case 8: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); + drawVerticalLine(x, y, DIGIT_HEIGHT, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); + break; + case 9: + drawHorizontalLine(x, y, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); + drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); + drawVerticalLine(x, y, DIGIT_HEIGHT/2, color); + drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); + break; + } +} + +// Dessine un nombre +void drawNumber(int num, int x, int y, int color) { + if(num == 0) { + drawDigit(0, x, y, color); + return; + } + + int temp = num; + int digits = 0; + + // Compter les chiffres + while(temp > 0) { + temp /= 10; + digits++; + } + + // Dessiner chaque chiffre + temp = num; + for(int i = 0; i < digits; i++) { + int digit = temp % 10; + drawDigit(digit, x + (digits-i-1) * DIGIT_SPACING, y, color); + temp /= 10; + } +} + +void main() { + int x = int(gl_GlobalInvocationID.x); + int y = int(gl_GlobalInvocationID.y); + int p = x + y * int(WSX); + + // Initialisation + if (step == 0) { + // Premiere rangee pour stocker les infos de la souris + if (y == 0 && x < 10) { + data_0[p] = -1; // Initialiser a -1 + } + // Territoire du joueur en haut a gauche + else if (x < int(WSX)/8 && y < int(WSY)/8) { + data_0[p] = JOUEUR; + } + // IA 1 en haut a droite + else if (x > int(WSX)*7/8 && y < int(WSY)/8) { + data_0[p] = IA_1; + } + // IA 2 en bas a gauche + else if (x < int(WSX)/8 && y > int(WSY)*7/8) { + data_0[p] = IA_2; + } + // IA 3 en bas a droite + else if (x > int(WSX)*7/8 && y > int(WSY)*7/8) { + data_0[p] = IA_3; + } + // Reste de la carte neutre + else { + data_0[p] = NEUTRE; + } + } + // Logique de jeu + else { + // Gestion du clic de souris + bool clicked = false; + + // Verifier si c est un nouveau clic seulement au debut de la frame + if (y == 0 && x == 0 && mousex >= 0 && mousey >= 0) { + int lastX = data_0[MOUSE_STORAGE_X]; + int lastY = data_0[MOUSE_STORAGE_Y]; + + // Si la position a change c est un nouveau clic + if (lastX != mousex || lastY != mousey) { + clicked = true; + data_0[MOUSE_STORAGE_X] = mousex; + data_0[MOUSE_STORAGE_Y] = mousey; + data_0[MOUSE_STORAGE_CLICKED] = 1; + } else { + data_0[MOUSE_STORAGE_CLICKED] = 0; + } + } + + clicked = data_0[MOUSE_STORAGE_CLICKED] == 1; + + // Interaction joueur expansion par clic + if (clicked && mousex >= 0 && mousey >= 0) { + // Distance au clic + float dist = sqrt(float((x - mousex) * (x - mousex) + (y - mousey) * (y - mousey))); + + // Zone expansion autour du clic + if (dist < CLICK_RADIUS) { + // Verifier si le clic est proche d un territoire du joueur + bool proche_joueur = false; + + for (int j = -3; j <= 3; j++) { + for (int i = -3; i <= 3; i++) { + int nx = mousex + i; + int ny = mousey + j; + + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int check_p = nx + ny * int(WSX); + if (data_0[check_p] == JOUEUR) { + proche_joueur = true; + break; + } + } + } + if (proche_joueur) break; + } + + // Si on est pres d un territoire du joueur on peut conquerir + if (proche_joueur) { + // Probabilite de conquete qui diminue avec la distance + float proba = 1.0 - (dist / CLICK_RADIUS); + + if (random_event(x, y, step, proba)) { + // Conquete facile de territoire neutre + if (data_0[p] == NEUTRE) { + data_0[p] = JOUEUR; + } + // Conquete plus difficile de territoire ennemi + else if (data_0[p] != JOUEUR && random_event(x, y, step, proba * 0.5)) { + data_0[p] = JOUEUR; + } + } + } + } + } + + // IA expansion automatique + if (step % 3 == 0) { // Ralentir IA pour equilibrer + // IA 1 Plus agressive + if (data_0[p] == IA_1 && random_event(x, y, step, AI_EXPANSION_RATE * 1.5)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; + + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; + } + + int nx = x + dx; + int ny = y + dy; + + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int voisin_p = nx + ny * int(WSX); + + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_1 && random_event(x, y, step, 0.2))) { + data_0[voisin_p] = IA_1; + } + } + } + + // IA 2 Expansion normale + else if (data_0[p] == IA_2 && random_event(x, y, step, AI_EXPANSION_RATE)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; + + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; + } + + int nx = x + dx; + int ny = y + dy; + + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int voisin_p = nx + ny * int(WSX); + + if (data_0[voisin_p] == NEUTRE) { + data_0[voisin_p] = IA_2; + } + } + } + + // IA 3 Plus defensive + else if (data_0[p] == IA_3 && random_event(x, y, step, AI_EXPANSION_RATE * 0.8)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; + + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; + } + + int nx = x + dx; + int ny = y + dy; + + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int voisin_p = nx + ny * int(WSX); + + if (data_0[voisin_p] == NEUTRE) { + data_0[voisin_p] = IA_3; + } + } + } + } + + // Calcul des scores une seule fois par frame + int score_joueur = 0; + int score_ia1 = 0; + int score_ia2 = 0; + int score_ia3 = 0; + + if (x == 0 && y == 1) { + for (int j = 0; j < int(WSY); j++) { + for (int i = 0; i < int(WSX); i++) { + int idx = i + j * int(WSX); + if (data_0[idx] == JOUEUR) score_joueur++; + else if (data_0[idx] == IA_1) score_ia1++; + else if (data_0[idx] == IA_2) score_ia2++; + else if (data_0[idx] == IA_3) score_ia3++; + } + } + + // Stocker les scores dans les pixels speciaux + data_0[int(WSX) - 4] = score_joueur; + data_0[int(WSX) - 3] = score_ia1; + data_0[int(WSX) - 2] = score_ia2; + data_0[int(WSX) - 1] = score_ia3; + } + + // Affichage des scores au milieu de ecran + if (y >= SCORE_Y - DIGIT_HEIGHT && y < SCORE_Y + DIGIT_HEIGHT*2) { + // Recuperer les scores + score_joueur = data_0[int(WSX) - 4]; + score_ia1 = data_0[int(WSX) - 3]; + score_ia2 = data_0[int(WSX) - 2]; + score_ia3 = data_0[int(WSX) - 1]; + + // Fond noir pour le score + if (y == SCORE_Y - 5) { + if (x > int(WSX)/2 - 50 && x < int(WSX)/2 + 150) { + data_0[p] = NOIR; + } + } + + // Afficher les scores + if (x == int(WSX)/2 - 45 && y == SCORE_Y) { + drawNumber(score_joueur, int(WSX)/2 - 45, SCORE_Y, JOUEUR); + drawNumber(score_ia1, int(WSX)/2 + 15, SCORE_Y, IA_1); + drawNumber(score_ia2, int(WSX)/2 - 45, SCORE_Y + DIGIT_HEIGHT + 5, IA_2); + drawNumber(score_ia3, int(WSX)/2 + 15, SCORE_Y + DIGIT_HEIGHT + 5, IA_3); + } + } + + // Highlight du curseur + if (x == mousex && y == mousey) { + data_0[p] = BLANC; + } + } +} \ No newline at end of file From 7c2bab41cdb78c8133f37953ca2426f27d4dadfb Mon Sep 17 00:00:00 2001 From: Mathieu-Da-Costa Date: Thu, 13 Mar 2025 08:49:41 +0100 Subject: [PATCH 09/29] Update teri_test1.cpp --- examples/territoire/teri_test1.cpp | 122 ++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 39 deletions(-) diff --git a/examples/territoire/teri_test1.cpp b/examples/territoire/teri_test1.cpp index 0055cee..1807d7e 100644 --- a/examples/territoire/teri_test1.cpp +++ b/examples/territoire/teri_test1.cpp @@ -1,43 +1,87 @@ +#define MORT 0 +#define VIVANT 0xFFFFFFFF +#define Rouge 0xFF0000FF +#define Vert 0xFF00FF00 +#define Bleu 0xFFFF0000 +#define Jaune 0xFFFFFF00 -#define ALIVE 0xFFFFFFFF -#define DEAD 0xFF0000FF +#define MIN_VOISINS_SURVIE 1 +#define MAX_VOISINS_SURVIE 2 +#define VOISINS_NAISSANCE 1 + + void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - if ( step == 0 ) { // initialisation ************************ - if ( current_pass == 0 ) { - data_1[p] = DEAD ; - if (data_0[p] < 0 || x==0 || y==0 || x==WSX-1 || y==WSY-1) - data_0[p] = DEAD ; - else - data_0[p] = ALIVE ; - } - } else { // in process ********************************* - if (current_pass == 0) - compute_next_step(x, y, p); - else - data_0[p] = data_1[p]; // The future is now - sleep(1); - } -} + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + if (step == 0) { + if (data_0[p] < 0) { + if (x == WSX / 2 && y == WSY / 2) { // On place une cellule vivante au centre + data_0[p] = VIVANT; + } else if (x == 1 && y== 1){ + data_0[p] = Rouge; + }else if(x == WSX-1 && y== 1){ + data_0[p] = Vert; + }else if(x == 1 && y== WSY-1){ + data_0[p] = Bleu; + }else if(x == WSX-1 && y== WSY-1){ + data_0[p] = Jaune; + } else { + data_0[p] = MORT; + } + } else { + data_0[p] = MORT; + } + } else { + int nb_voisins_V = 0; + int nb_voisins_R = 0; + int nb_voisins_J = 0; + int nb_voisins_B = 0; + int nb_voisins_G = 0; -void compute_next_step(uint x, uint y, uint p) { - if ( x > 0 && y > 0 && x < WSX-1 && y < WSY - 1) { // in sandbox - uint n = 0 ; // Number of living neighbors - for (uint i = x-1; i <= x+1; i++) { - for (uint j = y-1; j <= y+1; j++) { - uint k = i + j * WSX; - if (k != p && data_0[k] == ALIVE ) - n++; - } - } - if (data_0[p] == DEAD) { - if ( n >= 1) - data_1[p] = ALIVE; // Birth - else - data_1[p] = DEAD ; - } - } -} \ No newline at end of file + // Comptage des voisins vivants + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + if (!(dx == 0 && dy == 0)) { + int nx = int(x) + dx; + int ny = int(y) + dy; + + if (nx >= 0 && nx < WSX && ny >= 0 && ny < WSY) { + if (data_0[uint(nx + ny * WSX)] == VIVANT) { + nb_voisins_V++; + } + if (data_0[uint(nx + ny * WSX)] == Rouge) { + nb_voisins_R++; + } + if (data_0[uint(nx + ny * WSX)] == Vert) { + nb_voisins_G++; + } + if (data_0[uint(nx + ny * WSX)] == Bleu) { + nb_voisins_B++; + } + if (data_0[uint(nx + ny * WSX)] == Jaune) { + nb_voisins_J++; + } + } + } + } + } + + // La cellule morte devient vivante si elle a 1 voisin vivant + if (data_0[p] == MORT) { + if (nb_voisins_V >= 1) { + data_0[p] = VIVANT; + } else if(nb_voisins_R >= 1){ + data_0[p] = Rouge; + }else if(nb_voisins_J >= 1){ + data_0[p] = Jaune; + }else if(nb_voisins_G >= 1){ + data_0[p] = Vert; + }else if(nb_voisins_B >= 1){ + data_0[p] = Bleu; + } + } + } +} From 73de3bc731817029e247f59d6b02d4e3ee7a02f0 Mon Sep 17 00:00:00 2001 From: Mathieu-Da-Costa Date: Thu, 13 Mar 2025 09:42:46 +0100 Subject: [PATCH 10/29] Update teri_test1.cpp --- examples/territoire/teri_test1.cpp | 102 ++++++++++++++++------------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/examples/territoire/teri_test1.cpp b/examples/territoire/teri_test1.cpp index 1807d7e..0f93664 100644 --- a/examples/territoire/teri_test1.cpp +++ b/examples/territoire/teri_test1.cpp @@ -35,53 +35,61 @@ void main() { data_0[p] = MORT; } } else { - int nb_voisins_V = 0; - int nb_voisins_R = 0; - int nb_voisins_J = 0; - int nb_voisins_B = 0; - int nb_voisins_G = 0; + if (current_pass == 0) + compute_next_step(x, y, p); + else + data_0[p] = data_1[p]; // The future is now + } +} - // Comptage des voisins vivants - for (int dy = -1; dy <= 1; dy++) { - for (int dx = -1; dx <= 1; dx++) { - if (!(dx == 0 && dy == 0)) { - int nx = int(x) + dx; - int ny = int(y) + dy; +void compute_next_step(uint x, uint y, uint p){ + + int nb_voisins_V = 0; + int nb_voisins_R = 0; + int nb_voisins_J = 0; + int nb_voisins_B = 0; + int nb_voisins_G = 0; - if (nx >= 0 && nx < WSX && ny >= 0 && ny < WSY) { - if (data_0[uint(nx + ny * WSX)] == VIVANT) { - nb_voisins_V++; - } - if (data_0[uint(nx + ny * WSX)] == Rouge) { - nb_voisins_R++; - } - if (data_0[uint(nx + ny * WSX)] == Vert) { - nb_voisins_G++; - } - if (data_0[uint(nx + ny * WSX)] == Bleu) { - nb_voisins_B++; - } - if (data_0[uint(nx + ny * WSX)] == Jaune) { - nb_voisins_J++; - } - } - } - } - } + // Comptage des voisins vivants + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + if (!(dx == 0 && dy == 0)) { + int nx = int(x) + dx; + int ny = int(y) + dy; - // La cellule morte devient vivante si elle a 1 voisin vivant - if (data_0[p] == MORT) { - if (nb_voisins_V >= 1) { - data_0[p] = VIVANT; - } else if(nb_voisins_R >= 1){ - data_0[p] = Rouge; - }else if(nb_voisins_J >= 1){ - data_0[p] = Jaune; - }else if(nb_voisins_G >= 1){ - data_0[p] = Vert; - }else if(nb_voisins_B >= 1){ - data_0[p] = Bleu; - } - } - } -} + if (nx >= 0 && nx < WSX && ny >= 0 && ny < WSY) { + if (data_0[uint(nx + ny * WSX)] == VIVANT) { + nb_voisins_V++; + } + if (data_0[uint(nx + ny * WSX)] == Rouge) { + nb_voisins_R++; + } + if (data_0[uint(nx + ny * WSX)] == Vert) { + nb_voisins_G++; + } + if (data_0[uint(nx + ny * WSX)] == Bleu) { + nb_voisins_B++; + } + if (data_0[uint(nx + ny * WSX)] == Jaune) { + nb_voisins_J++; + } + } + } + } + } + + // La cellule morte devient vivante si elle a 1 voisin vivant + if (data_0[p] == MORT) { + if (nb_voisins_V >= 1) { + data_1[p] = VIVANT; + } else if(nb_voisins_R >= 1){ + data_1[p] = Rouge; + }else if(nb_voisins_J >= 1){ + data_1[p] = Jaune; + }else if(nb_voisins_G >= 1){ + data_1[p] = Vert; + }else if(nb_voisins_B >= 1){ + data_1[p] = Bleu; + } + } +} \ No newline at end of file From 294192b61b08b220c2a1861fdd80a6706941a97b Mon Sep 17 00:00:00 2001 From: Mathieu-Da-Costa Date: Thu, 13 Mar 2025 09:44:12 +0100 Subject: [PATCH 11/29] Update teri_test1.cpp --- examples/territoire/teri_test1.cpp | 65 +++++++++++++++--------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/examples/territoire/teri_test1.cpp b/examples/territoire/teri_test1.cpp index 0f93664..65e5f9c 100644 --- a/examples/territoire/teri_test1.cpp +++ b/examples/territoire/teri_test1.cpp @@ -10,37 +10,6 @@ #define MAX_VOISINS_SURVIE 2 #define VOISINS_NAISSANCE 1 - -void main() { - uint x = gl_GlobalInvocationID.x; - uint y = gl_GlobalInvocationID.y; - uint p = x + y * WSX; - - if (step == 0) { - if (data_0[p] < 0) { - if (x == WSX / 2 && y == WSY / 2) { // On place une cellule vivante au centre - data_0[p] = VIVANT; - } else if (x == 1 && y== 1){ - data_0[p] = Rouge; - }else if(x == WSX-1 && y== 1){ - data_0[p] = Vert; - }else if(x == 1 && y== WSY-1){ - data_0[p] = Bleu; - }else if(x == WSX-1 && y== WSY-1){ - data_0[p] = Jaune; - } else { - data_0[p] = MORT; - } - } else { - data_0[p] = MORT; - } - } else { - if (current_pass == 0) - compute_next_step(x, y, p); - else - data_0[p] = data_1[p]; // The future is now - } -} void compute_next_step(uint x, uint y, uint p){ @@ -92,4 +61,36 @@ void compute_next_step(uint x, uint y, uint p){ data_1[p] = Bleu; } } -} \ No newline at end of file +} + + +void main() { + uint x = gl_GlobalInvocationID.x; + uint y = gl_GlobalInvocationID.y; + uint p = x + y * WSX; + + if (step == 0) { + if (data_0[p] < 0) { + if (x == WSX / 2 && y == WSY / 2) { // On place une cellule vivante au centre + data_0[p] = VIVANT; + } else if (x == 1 && y== 1){ + data_0[p] = Rouge; + }else if(x == WSX-1 && y== 1){ + data_0[p] = Vert; + }else if(x == 1 && y== WSY-1){ + data_0[p] = Bleu; + }else if(x == WSX-1 && y== WSY-1){ + data_0[p] = Jaune; + } else { + data_0[p] = MORT; + } + } else { + data_0[p] = MORT; + } + } else { + if (current_pass == 0) + compute_next_step(x, y, p); + else + data_0[p] = data_1[p]; // The future is now + } +} From c779ada60af45c8274e2a1ad2482ea29d42ed3c1 Mon Sep 17 00:00:00 2001 From: Mathieu-Da-Costa Date: Thu, 13 Mar 2025 09:52:53 +0100 Subject: [PATCH 12/29] Update teri_test1.cpp --- examples/territoire/teri_test1.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/territoire/teri_test1.cpp b/examples/territoire/teri_test1.cpp index 65e5f9c..a6aa097 100644 --- a/examples/territoire/teri_test1.cpp +++ b/examples/territoire/teri_test1.cpp @@ -70,7 +70,8 @@ void main() { uint p = x + y * WSX; if (step == 0) { - if (data_0[p] < 0) { + if ( current_pass == 0 ) { + data_1[p] = DEAD ; if (x == WSX / 2 && y == WSY / 2) { // On place une cellule vivante au centre data_0[p] = VIVANT; } else if (x == 1 && y== 1){ @@ -84,9 +85,8 @@ void main() { } else { data_0[p] = MORT; } - } else { - data_0[p] = MORT; } + } } else { if (current_pass == 0) compute_next_step(x, y, p); From e098c91779e4d3cd23d83573bb66a29523d6c67a Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Thu, 13 Mar 2025 13:40:57 +0100 Subject: [PATCH 13/29] Start button --- examples/territoire/Button.gd | 0 examples/territoire/test.tscn | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 examples/territoire/Button.gd diff --git a/examples/territoire/Button.gd b/examples/territoire/Button.gd new file mode 100644 index 0000000..e69de29 diff --git a/examples/territoire/test.tscn b/examples/territoire/test.tscn index d50ad25..42a83ac 100644 --- a/examples/territoire/test.tscn +++ b/examples/territoire/test.tscn @@ -1,18 +1,19 @@ -[gd_scene load_steps=3 format=3 uid="uid://blnvvmlx5sccd"] +[gd_scene load_steps=2 format=3 uid="uid://blnvvmlx5sccd"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_85kph"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_lxh3h"] [node name="Test" type="Node2D"] -[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] -script = ExtResource("1_lxh3h") -WSX = 256 -glsl_file = "res://examples/territoire/territoire.cpp" -GLSL_code = "" -data = [NodePath("../Icon")] +[node name="ComputeShaderStudio2D" type="Node" parent="."] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(221, 191) -scale = Vector2(3.46875, 3) +position = Vector2(591, 287) +scale = Vector2(8.3125, 4.40625) texture = ExtResource("1_85kph") + +[node name="Button" type="Button" parent="."] +offset_left = 370.0 +offset_top = 590.0 +offset_right = 416.0 +offset_bottom = 621.0 +text = "Start" From 6b405900932af76b3cffac4c96a33376b1e2c813 Mon Sep 17 00:00:00 2001 From: Mathieu-Da-Costa Date: Thu, 13 Mar 2025 13:42:40 +0100 Subject: [PATCH 14/29] Update teri_test1.cpp --- examples/territoire/teri_test1.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/territoire/teri_test1.cpp b/examples/territoire/teri_test1.cpp index a6aa097..9803efd 100644 --- a/examples/territoire/teri_test1.cpp +++ b/examples/territoire/teri_test1.cpp @@ -71,7 +71,7 @@ void main() { if (step == 0) { if ( current_pass == 0 ) { - data_1[p] = DEAD ; + data_0[p] = MORT ; if (x == WSX / 2 && y == WSY / 2) { // On place une cellule vivante au centre data_0[p] = VIVANT; } else if (x == 1 && y== 1){ @@ -86,7 +86,7 @@ void main() { data_0[p] = MORT; } } - } + } else { if (current_pass == 0) compute_next_step(x, y, p); From dd9d9e937f9fd46ef17212403835504ae94843d0 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Thu, 13 Mar 2025 13:42:43 +0100 Subject: [PATCH 15/29] Update test.tscn --- examples/territoire/test.tscn | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/territoire/test.tscn b/examples/territoire/test.tscn index 42a83ac..6008544 100644 --- a/examples/territoire/test.tscn +++ b/examples/territoire/test.tscn @@ -1,19 +1,23 @@ -[gd_scene load_steps=2 format=3 uid="uid://blnvvmlx5sccd"] +[gd_scene load_steps=4 format=3 uid="uid://blnvvmlx5sccd"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_85kph"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_lxh3h"] +[ext_resource type="Script" path="res://examples/territoire/Button.gd" id="3_pvsff"] [node name="Test" type="Node2D"] [node name="ComputeShaderStudio2D" type="Node" parent="."] +script = ExtResource("1_lxh3h") [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(591, 287) -scale = Vector2(8.3125, 4.40625) +position = Vector2(576, 277) +scale = Vector2(8.49219, 4.14063) texture = ExtResource("1_85kph") [node name="Button" type="Button" parent="."] -offset_left = 370.0 -offset_top = 590.0 -offset_right = 416.0 -offset_bottom = 621.0 +offset_left = 389.0 +offset_top = 575.0 +offset_right = 435.0 +offset_bottom = 606.0 text = "Start" +script = ExtResource("3_pvsff") From ccf3373e214d6b7e0a3d4189df73686b9eba1728 Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Thu, 13 Mar 2025 13:42:44 +0100 Subject: [PATCH 16/29] Mes modifications au fichier project.godot --- project.godot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.godot b/project.godot index 0436dd7..725be9c 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From 8b7e8f46dd998bd711ba3760158d7ef4371cce39 Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Thu, 13 Mar 2025 13:47:37 +0100 Subject: [PATCH 17/29] =?UTF-8?q?R=C3=A9solution=20des=20conflits=20de=20f?= =?UTF-8?q?usion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 28 +++ examples/territoire/bonjour.cpp | 345 ++++++++++++++++++++++++++++++++ examples/territoire/test.tscn | 6 +- 3 files changed, 376 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/territoire/bonjour.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6ce8767 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,28 @@ +{ + "workbench.view.alwaysShowHeaderActions": true, + "workbench.tree.renderIndentGuides": "none", + "[pvs]": { + "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}|;:'\",.<>/" + }, + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "**/*.???~": true, + "**/.pvscontext": true, + "**/pvsbin": true, + "**/*.jprf": true, + "**/*.prf": true, + "**/orphaned-proofs.prf": true, + "**/*_adt.pvs": false, + "**/*.log": false, + "**/.vscode": true + }, + "files.readonlyInclude": { + "**/*.tccs": true, + "**/*.summary": true + } +} \ No newline at end of file diff --git a/examples/territoire/bonjour.cpp b/examples/territoire/bonjour.cpp new file mode 100644 index 0000000..b4208c6 --- /dev/null +++ b/examples/territoire/bonjour.cpp @@ -0,0 +1,345 @@ +// Format RGBA +#define RED 0xFF0000FF // Red +#define GREEN 0xFF00FF00 // Green +#define BLUE 0xFFFF0000 // Blue +#define YELLOW 0xFFFFFF00 // Yellow +#define BLACK 0xFF000000 // Black +#define WHITE 0xFFFFFFFF // White + +// Alternative ARGB format (uncomment if needed) +//#define RED 0xFFFF0000 // Red +//#define GREEN 0xFF00FF00 // Green +//#define BLUE 0xFF0000FF // Blue +//#define YELLOW 0xFFFFFF00 // Yellow +//#define BLACK 0xFF000000 // Black +//#define WHITE 0xFFFFFFFF // White + +#define PLAYER_SIZE 5 // Player radius +#define SPAWN_RATE 50 // Base enemy spawn rate +#define ENEMY_SPEED 0.8 // Base movement speed +#define DIFFICULTY_INC 100 // Frames per difficulty increase + +// Score display config +#define SCORE_Y 10 +#define DIGIT_WIDTH 8 +#define DIGIT_HEIGHT 12 +#define DIGIT_SPACING 10 + +int hash(int x, int y, int s) { + int a = x * 0x6A09E667; + int b = y * 0xBB67AE85; + int c = s * 0x3C6EF372; + int h = a + b + c; + h = (h ^ (h >> 16)) * 0x85EBCA6B; + h = (h ^ (h >> 13)) * 0xC2B2AE35; + h = h ^ (h >> 16); + return h; +} + +bool random_event(int x, int y, int step, float probability) { + int random_value = hash(x, y, step); + float normalized = float(random_value) / 2147483647.0; + return (normalized > 0.0 ? normalized : -normalized) < probability; +} + +void drawHLine(int startX, int y, int length, int color) { + for(int i = 0; i < length; i++) { + int pos = (startX + i) + y * int(WSX); + if(startX + i >= 0 && startX + i < int(WSX) && y >= 0 && y < int(WSY)) { + data_0[pos] = color; + } + } +} + +void drawVLine(int x, int startY, int length, int color) { + for(int i = 0; i < length; i++) { + int pos = x + (startY + i) * int(WSX); + if(x >= 0 && x < int(WSX) && startY + i >= 0 && startY + i < int(WSY)) { + data_0[pos] = color; + } + } +} + +void drawNumber(int num, int x, int y, int color) { + if (num == 0) { + drawHLine(x, y, 5, color); + drawHLine(x, y+6, 5, color); + drawVLine(x, y, 7, color); + drawVLine(x+4, y, 7, color); + return; + } + + int digits[10]; + int digit_count = 0; + int temp = num; + + while (temp > 0) { + digits[digit_count] = temp % 10; + temp /= 10; + digit_count++; + } + + for (int i = 0; i < digit_count; i++) { + int digit = digits[digit_count - i - 1]; + int dx = x + i * 8; + + if (digit == 0) { + drawHLine(dx, y, 5, color); + drawHLine(dx, y+6, 5, color); + drawVLine(dx, y, 7, color); + drawVLine(dx+4, y, 7, color); + } + else if (digit == 1) { + drawVLine(dx+2, y, 7, color); + } + else if (digit == 2) { + drawHLine(dx, y, 5, color); + drawHLine(dx, y+3, 5, color); + drawHLine(dx, y+6, 5, color); + drawVLine(dx+4, y, 4, color); + drawVLine(dx, y+3, 4, color); + } + else if (digit == 3) { + drawHLine(dx, y, 5, color); + drawHLine(dx, y+3, 5, color); + drawHLine(dx, y+6, 5, color); + drawVLine(dx+4, y, 7, color); + } + else if (digit == 4) { + drawVLine(dx, y, 4, color); + drawVLine(dx+4, y, 7, color); + drawHLine(dx, y+3, 5, color); + } + else if (digit == 5) { + drawHLine(dx, y, 5, color); + drawHLine(dx, y+3, 5, color); + drawHLine(dx, y+6, 5, color); + drawVLine(dx, y, 4, color); + drawVLine(dx+4, y+3, 4, color); + } + else if (digit == 6) { + drawHLine(dx, y, 5, color); + drawHLine(dx, y+3, 5, color); + drawHLine(dx, y+6, 5, color); + drawVLine(dx, y, 7, color); + drawVLine(dx+4, y+3, 4, color); + } + else if (digit == 7) { + drawHLine(dx, y, 5, color); + drawVLine(dx+4, y, 7, color); + } + else if (digit == 8) { + drawHLine(dx, y, 5, color); + drawHLine(dx, y+3, 5, color); + drawHLine(dx, y+6, 5, color); + drawVLine(dx, y, 7, color); + drawVLine(dx+4, y, 7, color); + } + else if (digit == 9) { + drawHLine(dx, y, 5, color); + drawHLine(dx, y+3, 5, color); + drawHLine(dx, y+6, 5, color); + drawVLine(dx, y, 4, color); + drawVLine(dx+4, y, 7, color); + } + } +} + +void main() { + int x = int(gl_GlobalInvocationID.x); + int y = int(gl_GlobalInvocationID.y); + int p = x + y * int(WSX); + + // Simplified color test + if (step < 5) { + // Simple color grid test + if (x < int(WSX)/2) { + if (y < int(WSY)/2) { + data_0[p] = GREEN; // Top-left: green + } else { + data_0[p] = YELLOW; // Bottom-left: yellow + } + } else { + if (y < int(WSY)/2) { + data_0[p] = BLUE; // Top-right: blue + } else { + data_0[p] = WHITE; // Bottom-right: white + } + } + + // Black grid lines + if (x == int(WSX)/2 || y == int(WSY)/2) { + data_0[p] = BLACK; + } + + // Player (red circle) + if (mousex >= 0 && mousey >= 0) { + float dist = sqrt(float((x - mousex) * (x - mousex) + (y - mousey) * (y - mousey))); + if (dist < 20) { + data_0[p] = RED; + } + } + + return; + } + + // Game initialization + if (step == 5) { + // Reserve storage area (first line) + if (y == 0 && x < 10) { + if (x == 0) data_0[p] = 1; // Game active flag (1=active, 0=over) + else if (x == 1) data_0[p] = 0; // Score (survival time) + else if (x == 2) data_0[p] = 0; // Difficulty + else data_0[p] = 0; + } else { + data_0[p] = BLACK; + } + } else { + // Check game state + bool game_active = (data_0[0] == 1); + int score = data_0[1]; + int difficulty = data_0[2]; + + // Update game state (only at 0,0) + if (x == 0 && y == 0) { + // Increase score if game is active + if (game_active) { + data_0[1]++; // Increment score + + // Increase difficulty periodically + if (step % DIFFICULTY_INC == 0) { + data_0[2]++; + } + } + } + + // Clear screen (except storage area) + if (!(y == 0 && x < 10)) { + data_0[p] = BLACK; + } + + // Active game logic + if (game_active) { + // Check if player still exists + if (x == 0 && y == 1) { + bool player_alive = false; + for (int j = 0; j < int(WSY); j++) { + for (int i = 0; i < int(WSX); i++) { + int idx = i + j * int(WSX); + if (data_0[idx] == RED) { + player_alive = true; + break; + } + } + if (player_alive) break; + } + + // If player is gone, game over + if (!player_alive && score > 10) { + data_0[0] = 0; + } + } + + // Draw player around mouse + if (mousex >= 0 && mousey >= 0) { + float dist = sqrt(float((x - mousex) * (x - mousex) + (y - mousey) * (y - mousey))); + if (dist < PLAYER_SIZE) { + data_0[p] = RED; + } + } + + // Spawn enemies from edges + if ((step + x + y) % max(5, SPAWN_RATE - difficulty) == 0) { + // Choose random edge + int border = hash(x, y, step) % 4; // 0=top, 1=right, 2=bottom, 3=left + + // Edge positions + if ((border == 0 && y == 0) || + (border == 1 && x == int(WSX)-1) || + (border == 2 && y == int(WSY)-1) || + (border == 3 && x == 0)) { + + // Spawn probability inversely proportional to edge length + int border_length = (border % 2 == 0) ? int(WSX) : int(WSY); + + if (random_event(x, y, step, 2.0 / float(border_length))) { + // Enemy type based on difficulty + int enemy_type = hash(x, y, step) % 3; + if (difficulty < 10) enemy_type = 0; + else if (difficulty < 20) enemy_type = hash(x, y, step) % 2; + + switch(enemy_type) { + case 0: data_0[p] = GREEN; break; + case 1: data_0[p] = BLUE; break; + case 2: data_0[p] = YELLOW; break; + } + } + } + } + + // Move enemies toward player + if (data_0[p] == GREEN || data_0[p] == BLUE || data_0[p] == YELLOW) { + // Calculate direction to player (or center if no mouse) + int target_x = (mousex >= 0) ? mousex : int(WSX) / 2; + int target_y = (mousey >= 0) ? mousey : int(WSY) / 2; + + float dx = float(target_x - x); + float dy = float(target_y - y); + float dist = sqrt(dx*dx + dy*dy); + + if (dist > 0) { + // Normalize + dx /= dist; + dy /= dist; + + // Speed based on type and difficulty + float speed = ENEMY_SPEED; + if (data_0[p] == BLUE) speed *= 1.2; + if (data_0[p] == YELLOW) speed *= 1.5; + + // Add speed bonus based on difficulty + speed *= (1.0 + float(difficulty) / 50.0); + + // New position + int new_x = int(float(x) + dx * speed); + int new_y = int(float(y) + dy * speed); + + // Check boundaries + if (new_x >= 0 && new_x < int(WSX) && new_y >= 0 && new_y < int(WSY)) { + int new_p = new_x + new_y * int(WSX); + + // Collision with player = game over + if (data_0[new_p] == RED) { + data_0[new_p] = GREEN; // Replace player + } + // Otherwise move enemy + else if (data_0[new_p] == BLACK) { + data_0[new_p] = data_0[p]; + data_0[p] = BLACK; + } + } + } + } + + // Display score in top-right + if (x == int(WSX) - 50 && y == 10) { + drawNumber(score, x, y, WHITE); + } + } + // Game over screen + else { + // Draw GAME OVER message + if (y == int(WSY)/2 - 10 && x == int(WSX)/2 - 50) { + // Simple line message + drawHLine(x, y, 100, WHITE); + drawHLine(x, y+7, 100, WHITE); + drawHLine(x, y+15, 100, WHITE); + } + + // Show final score + if (y == int(WSY)/2 + 10 && x == int(WSX)/2 - 20) { + drawNumber(score, x, y, WHITE); + } + } + } +} \ No newline at end of file diff --git a/examples/territoire/test.tscn b/examples/territoire/test.tscn index d50ad25..badf933 100644 --- a/examples/territoire/test.tscn +++ b/examples/territoire/test.tscn @@ -8,11 +8,11 @@ [node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] script = ExtResource("1_lxh3h") WSX = 256 -glsl_file = "res://examples/territoire/territoire.cpp" +glsl_file = "res://examples/territoire/teri_test1.cpp" GLSL_code = "" data = [NodePath("../Icon")] [node name="Icon" type="Sprite2D" parent="."] -position = Vector2(221, 191) -scale = Vector2(3.46875, 3) +position = Vector2(576.313, 332.812) +scale = Vector2(8.51074, 4.7373) texture = ExtResource("1_85kph") From 3529954e8932cd6ddaddcceb8b817ec57a00737f Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Thu, 13 Mar 2025 13:55:17 +0100 Subject: [PATCH 18/29] Suppression de bonjour.cpp --- examples/territoire/bonjour.cpp | 345 -------------------------------- 1 file changed, 345 deletions(-) delete mode 100644 examples/territoire/bonjour.cpp diff --git a/examples/territoire/bonjour.cpp b/examples/territoire/bonjour.cpp deleted file mode 100644 index b4208c6..0000000 --- a/examples/territoire/bonjour.cpp +++ /dev/null @@ -1,345 +0,0 @@ -// Format RGBA -#define RED 0xFF0000FF // Red -#define GREEN 0xFF00FF00 // Green -#define BLUE 0xFFFF0000 // Blue -#define YELLOW 0xFFFFFF00 // Yellow -#define BLACK 0xFF000000 // Black -#define WHITE 0xFFFFFFFF // White - -// Alternative ARGB format (uncomment if needed) -//#define RED 0xFFFF0000 // Red -//#define GREEN 0xFF00FF00 // Green -//#define BLUE 0xFF0000FF // Blue -//#define YELLOW 0xFFFFFF00 // Yellow -//#define BLACK 0xFF000000 // Black -//#define WHITE 0xFFFFFFFF // White - -#define PLAYER_SIZE 5 // Player radius -#define SPAWN_RATE 50 // Base enemy spawn rate -#define ENEMY_SPEED 0.8 // Base movement speed -#define DIFFICULTY_INC 100 // Frames per difficulty increase - -// Score display config -#define SCORE_Y 10 -#define DIGIT_WIDTH 8 -#define DIGIT_HEIGHT 12 -#define DIGIT_SPACING 10 - -int hash(int x, int y, int s) { - int a = x * 0x6A09E667; - int b = y * 0xBB67AE85; - int c = s * 0x3C6EF372; - int h = a + b + c; - h = (h ^ (h >> 16)) * 0x85EBCA6B; - h = (h ^ (h >> 13)) * 0xC2B2AE35; - h = h ^ (h >> 16); - return h; -} - -bool random_event(int x, int y, int step, float probability) { - int random_value = hash(x, y, step); - float normalized = float(random_value) / 2147483647.0; - return (normalized > 0.0 ? normalized : -normalized) < probability; -} - -void drawHLine(int startX, int y, int length, int color) { - for(int i = 0; i < length; i++) { - int pos = (startX + i) + y * int(WSX); - if(startX + i >= 0 && startX + i < int(WSX) && y >= 0 && y < int(WSY)) { - data_0[pos] = color; - } - } -} - -void drawVLine(int x, int startY, int length, int color) { - for(int i = 0; i < length; i++) { - int pos = x + (startY + i) * int(WSX); - if(x >= 0 && x < int(WSX) && startY + i >= 0 && startY + i < int(WSY)) { - data_0[pos] = color; - } - } -} - -void drawNumber(int num, int x, int y, int color) { - if (num == 0) { - drawHLine(x, y, 5, color); - drawHLine(x, y+6, 5, color); - drawVLine(x, y, 7, color); - drawVLine(x+4, y, 7, color); - return; - } - - int digits[10]; - int digit_count = 0; - int temp = num; - - while (temp > 0) { - digits[digit_count] = temp % 10; - temp /= 10; - digit_count++; - } - - for (int i = 0; i < digit_count; i++) { - int digit = digits[digit_count - i - 1]; - int dx = x + i * 8; - - if (digit == 0) { - drawHLine(dx, y, 5, color); - drawHLine(dx, y+6, 5, color); - drawVLine(dx, y, 7, color); - drawVLine(dx+4, y, 7, color); - } - else if (digit == 1) { - drawVLine(dx+2, y, 7, color); - } - else if (digit == 2) { - drawHLine(dx, y, 5, color); - drawHLine(dx, y+3, 5, color); - drawHLine(dx, y+6, 5, color); - drawVLine(dx+4, y, 4, color); - drawVLine(dx, y+3, 4, color); - } - else if (digit == 3) { - drawHLine(dx, y, 5, color); - drawHLine(dx, y+3, 5, color); - drawHLine(dx, y+6, 5, color); - drawVLine(dx+4, y, 7, color); - } - else if (digit == 4) { - drawVLine(dx, y, 4, color); - drawVLine(dx+4, y, 7, color); - drawHLine(dx, y+3, 5, color); - } - else if (digit == 5) { - drawHLine(dx, y, 5, color); - drawHLine(dx, y+3, 5, color); - drawHLine(dx, y+6, 5, color); - drawVLine(dx, y, 4, color); - drawVLine(dx+4, y+3, 4, color); - } - else if (digit == 6) { - drawHLine(dx, y, 5, color); - drawHLine(dx, y+3, 5, color); - drawHLine(dx, y+6, 5, color); - drawVLine(dx, y, 7, color); - drawVLine(dx+4, y+3, 4, color); - } - else if (digit == 7) { - drawHLine(dx, y, 5, color); - drawVLine(dx+4, y, 7, color); - } - else if (digit == 8) { - drawHLine(dx, y, 5, color); - drawHLine(dx, y+3, 5, color); - drawHLine(dx, y+6, 5, color); - drawVLine(dx, y, 7, color); - drawVLine(dx+4, y, 7, color); - } - else if (digit == 9) { - drawHLine(dx, y, 5, color); - drawHLine(dx, y+3, 5, color); - drawHLine(dx, y+6, 5, color); - drawVLine(dx, y, 4, color); - drawVLine(dx+4, y, 7, color); - } - } -} - -void main() { - int x = int(gl_GlobalInvocationID.x); - int y = int(gl_GlobalInvocationID.y); - int p = x + y * int(WSX); - - // Simplified color test - if (step < 5) { - // Simple color grid test - if (x < int(WSX)/2) { - if (y < int(WSY)/2) { - data_0[p] = GREEN; // Top-left: green - } else { - data_0[p] = YELLOW; // Bottom-left: yellow - } - } else { - if (y < int(WSY)/2) { - data_0[p] = BLUE; // Top-right: blue - } else { - data_0[p] = WHITE; // Bottom-right: white - } - } - - // Black grid lines - if (x == int(WSX)/2 || y == int(WSY)/2) { - data_0[p] = BLACK; - } - - // Player (red circle) - if (mousex >= 0 && mousey >= 0) { - float dist = sqrt(float((x - mousex) * (x - mousex) + (y - mousey) * (y - mousey))); - if (dist < 20) { - data_0[p] = RED; - } - } - - return; - } - - // Game initialization - if (step == 5) { - // Reserve storage area (first line) - if (y == 0 && x < 10) { - if (x == 0) data_0[p] = 1; // Game active flag (1=active, 0=over) - else if (x == 1) data_0[p] = 0; // Score (survival time) - else if (x == 2) data_0[p] = 0; // Difficulty - else data_0[p] = 0; - } else { - data_0[p] = BLACK; - } - } else { - // Check game state - bool game_active = (data_0[0] == 1); - int score = data_0[1]; - int difficulty = data_0[2]; - - // Update game state (only at 0,0) - if (x == 0 && y == 0) { - // Increase score if game is active - if (game_active) { - data_0[1]++; // Increment score - - // Increase difficulty periodically - if (step % DIFFICULTY_INC == 0) { - data_0[2]++; - } - } - } - - // Clear screen (except storage area) - if (!(y == 0 && x < 10)) { - data_0[p] = BLACK; - } - - // Active game logic - if (game_active) { - // Check if player still exists - if (x == 0 && y == 1) { - bool player_alive = false; - for (int j = 0; j < int(WSY); j++) { - for (int i = 0; i < int(WSX); i++) { - int idx = i + j * int(WSX); - if (data_0[idx] == RED) { - player_alive = true; - break; - } - } - if (player_alive) break; - } - - // If player is gone, game over - if (!player_alive && score > 10) { - data_0[0] = 0; - } - } - - // Draw player around mouse - if (mousex >= 0 && mousey >= 0) { - float dist = sqrt(float((x - mousex) * (x - mousex) + (y - mousey) * (y - mousey))); - if (dist < PLAYER_SIZE) { - data_0[p] = RED; - } - } - - // Spawn enemies from edges - if ((step + x + y) % max(5, SPAWN_RATE - difficulty) == 0) { - // Choose random edge - int border = hash(x, y, step) % 4; // 0=top, 1=right, 2=bottom, 3=left - - // Edge positions - if ((border == 0 && y == 0) || - (border == 1 && x == int(WSX)-1) || - (border == 2 && y == int(WSY)-1) || - (border == 3 && x == 0)) { - - // Spawn probability inversely proportional to edge length - int border_length = (border % 2 == 0) ? int(WSX) : int(WSY); - - if (random_event(x, y, step, 2.0 / float(border_length))) { - // Enemy type based on difficulty - int enemy_type = hash(x, y, step) % 3; - if (difficulty < 10) enemy_type = 0; - else if (difficulty < 20) enemy_type = hash(x, y, step) % 2; - - switch(enemy_type) { - case 0: data_0[p] = GREEN; break; - case 1: data_0[p] = BLUE; break; - case 2: data_0[p] = YELLOW; break; - } - } - } - } - - // Move enemies toward player - if (data_0[p] == GREEN || data_0[p] == BLUE || data_0[p] == YELLOW) { - // Calculate direction to player (or center if no mouse) - int target_x = (mousex >= 0) ? mousex : int(WSX) / 2; - int target_y = (mousey >= 0) ? mousey : int(WSY) / 2; - - float dx = float(target_x - x); - float dy = float(target_y - y); - float dist = sqrt(dx*dx + dy*dy); - - if (dist > 0) { - // Normalize - dx /= dist; - dy /= dist; - - // Speed based on type and difficulty - float speed = ENEMY_SPEED; - if (data_0[p] == BLUE) speed *= 1.2; - if (data_0[p] == YELLOW) speed *= 1.5; - - // Add speed bonus based on difficulty - speed *= (1.0 + float(difficulty) / 50.0); - - // New position - int new_x = int(float(x) + dx * speed); - int new_y = int(float(y) + dy * speed); - - // Check boundaries - if (new_x >= 0 && new_x < int(WSX) && new_y >= 0 && new_y < int(WSY)) { - int new_p = new_x + new_y * int(WSX); - - // Collision with player = game over - if (data_0[new_p] == RED) { - data_0[new_p] = GREEN; // Replace player - } - // Otherwise move enemy - else if (data_0[new_p] == BLACK) { - data_0[new_p] = data_0[p]; - data_0[p] = BLACK; - } - } - } - } - - // Display score in top-right - if (x == int(WSX) - 50 && y == 10) { - drawNumber(score, x, y, WHITE); - } - } - // Game over screen - else { - // Draw GAME OVER message - if (y == int(WSY)/2 - 10 && x == int(WSX)/2 - 50) { - // Simple line message - drawHLine(x, y, 100, WHITE); - drawHLine(x, y+7, 100, WHITE); - drawHLine(x, y+15, 100, WHITE); - } - - // Show final score - if (y == int(WSY)/2 + 10 && x == int(WSX)/2 - 20) { - drawNumber(score, x, y, WHITE); - } - } - } -} \ No newline at end of file From e053eff1f52c46e0b3fd1a93669c0c5e5f7d0978 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:04:45 +0100 Subject: [PATCH 19/29] idk --- examples/territoire/test.tscn | 5 +---- project.godot | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/territoire/test.tscn b/examples/territoire/test.tscn index a78abf4..80673a8 100644 --- a/examples/territoire/test.tscn +++ b/examples/territoire/test.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://blnvvmlx5sccd"] +[gd_scene load_steps=3 format=3 uid="uid://blnvvmlx5sccd"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_85kph"] [ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_lxh3h"] -[ext_resource type="Script" path="res://examples/territoire/Button.gd" id="3_pvsff"] [node name="Test" type="Node2D"] @@ -11,7 +10,6 @@ script = ExtResource("1_lxh3h") WSX = 256 glsl_file = "res://examples/territoire/teri_test1.cpp" GLSL_code = "" -data = [NodePath("../Icon")] [node name="Icon" type="Sprite2D" parent="."] position = Vector2(576.313, 332.812) @@ -24,4 +22,3 @@ offset_top = 575.0 offset_right = 435.0 offset_bottom = 606.0 text = "Start" -script = ExtResource("3_pvsff") diff --git a/project.godot b/project.godot index 1617345..0436dd7 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.4", "Forward Plus") +config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From d6ef82308ed12c804166270f484e8149e77907fe Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:20:17 +0100 Subject: [PATCH 20/29] Fix scene --- examples/example_1.tscn | 2 +- examples/simple_circle/simple_circle.tscn | 2 +- examples/territoire/sceneTerritoire.tscn | 30 +++++++++++++++++++++++ examples/territoire/test.tscn | 24 ------------------ 4 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 examples/territoire/sceneTerritoire.tscn delete mode 100644 examples/territoire/test.tscn diff --git a/examples/example_1.tscn b/examples/example_1.tscn index 88ce9e3..7d67949 100644 --- a/examples/example_1.tscn +++ b/examples/example_1.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://ddr6qtwy1pesd"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_6846p"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_s3fct"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_dmk8h"] diff --git a/examples/simple_circle/simple_circle.tscn b/examples/simple_circle/simple_circle.tscn index 8c68dd5..3a07914 100644 --- a/examples/simple_circle/simple_circle.tscn +++ b/examples/simple_circle/simple_circle.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://c63rtjh0eurgm"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_rlapi"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_rlapi"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_y7slp"] [node name="SimpleCircle" type="Node2D"] diff --git a/examples/territoire/sceneTerritoire.tscn b/examples/territoire/sceneTerritoire.tscn new file mode 100644 index 0000000..8a5cc22 --- /dev/null +++ b/examples/territoire/sceneTerritoire.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=3 format=3 uid="uid://cyk1jgtevq1pg"] + +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_fuy1w"] +[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_otyot"] + +[node name="T1" type="Node2D"] + +[node name="ComputeShaderStudio2D" type="Node" parent="." node_paths=PackedStringArray("data")] +script = ExtResource("1_fuy1w") +glsl_file = "res://examples/territoire/bonbon.cpp" +data = [NodePath("../Icon")] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(574, 285.5) +scale = Vector2(8.79688, 4.28906) +texture = ExtResource("2_otyot") + +[node name="Button" type="Button" parent="."] +offset_left = 255.0 +offset_top = 581.0 +offset_right = 355.0 +offset_bottom = 621.0 +text = "Start" + +[node name="Button2" type="Button" parent="."] +offset_left = 707.0 +offset_top = 582.0 +offset_right = 792.0 +offset_bottom = 622.0 +text = "Pause" diff --git a/examples/territoire/test.tscn b/examples/territoire/test.tscn deleted file mode 100644 index 80673a8..0000000 --- a/examples/territoire/test.tscn +++ /dev/null @@ -1,24 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://blnvvmlx5sccd"] - -[ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="1_85kph"] -[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_lxh3h"] - -[node name="Test" type="Node2D"] - -[node name="ComputeShaderStudio2D" type="Node" parent="."] -script = ExtResource("1_lxh3h") -WSX = 256 -glsl_file = "res://examples/territoire/teri_test1.cpp" -GLSL_code = "" - -[node name="Icon" type="Sprite2D" parent="."] -position = Vector2(576.313, 332.812) -scale = Vector2(8.51074, 4.7373) -texture = ExtResource("1_85kph") - -[node name="Button" type="Button" parent="."] -offset_left = 389.0 -offset_top = 575.0 -offset_right = 435.0 -offset_bottom = 606.0 -text = "Start" From 7b2e599d1b0a5952065d02fda1d3ee510e97f4da Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Thu, 13 Mar 2025 14:23:32 +0100 Subject: [PATCH 21/29] =?UTF-8?q?Bonbon=20explosif=20sucr=C3=A9=20expensif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/territoire/Button.gd | 0 examples/territoire/bonbon.cpp | 71 +++++++++++++++++++++++----------- project.godot | 2 +- 3 files changed, 49 insertions(+), 24 deletions(-) delete mode 100644 examples/territoire/Button.gd diff --git a/examples/territoire/Button.gd b/examples/territoire/Button.gd deleted file mode 100644 index e69de29..0000000 diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index 2e43852..46337af 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -6,13 +6,15 @@ #define BLANC 0xFFFFFFFF #define NOIR 0xFF000000 -#define CLICK_RADIUS 15 +#define CLICK_RADIUS 25 // Rayon d'expansion augmenté +#define EXPANSION_AMOUNT 30 // Quantité d'expansion lors d'un clic #define AI_EXPANSION_RATE 0.03 // Stockage des coordonnees de la souris #define MOUSE_STORAGE_X 0 #define MOUSE_STORAGE_Y 1 #define MOUSE_STORAGE_CLICKED 2 +#define MOUSE_BUTTON_PRESSED 3 // Configuration de affichage du score #define SCORE_Y int(WSY)/2 @@ -185,35 +187,40 @@ void main() { bool clicked = false; // Verifier si c est un nouveau clic seulement au debut de la frame - if (y == 0 && x == 0 && mousex >= 0 && mousey >= 0) { + if (y == 0 && x == 0) { int lastX = data_0[MOUSE_STORAGE_X]; int lastY = data_0[MOUSE_STORAGE_Y]; + bool lastButtonState = data_0[MOUSE_BUTTON_PRESSED] > 0; + bool currentButtonState = mouse_button > 0; - // Si la position a change c est un nouveau clic - if (lastX != mousex || lastY != mousey) { + // Detecter un clic seulement quand le bouton vient d'etre presse + if (currentButtonState && !lastButtonState) { clicked = true; - data_0[MOUSE_STORAGE_X] = mousex; - data_0[MOUSE_STORAGE_Y] = mousey; data_0[MOUSE_STORAGE_CLICKED] = 1; } else { data_0[MOUSE_STORAGE_CLICKED] = 0; } + + // Sauvegarder la position et l'etat du bouton + data_0[MOUSE_STORAGE_X] = mousex; + data_0[MOUSE_STORAGE_Y] = mousey; + data_0[MOUSE_BUTTON_PRESSED] = currentButtonState ? 1 : 0; } clicked = data_0[MOUSE_STORAGE_CLICKED] == 1; - // Interaction joueur expansion par clic + // Interaction joueur - expansion par clic if (clicked && mousex >= 0 && mousey >= 0) { // Distance au clic float dist = sqrt(float((x - mousex) * (x - mousex) + (y - mousey) * (y - mousey))); - // Zone expansion autour du clic + // Zone d'expansion massive autour du clic if (dist < CLICK_RADIUS) { - // Verifier si le clic est proche d un territoire du joueur + // Verifier si le clic est proche d'un territoire du joueur bool proche_joueur = false; - for (int j = -3; j <= 3; j++) { - for (int i = -3; i <= 3; i++) { + for (int j = -5; j <= 5; j++) { + for (int i = -5; i <= 5; i++) { int nx = mousex + i; int ny = mousey + j; @@ -228,26 +235,44 @@ void main() { if (proche_joueur) break; } - // Si on est pres d un territoire du joueur on peut conquerir + // Si on est pres d'un territoire du joueur, expansion importante if (proche_joueur) { - // Probabilite de conquete qui diminue avec la distance - float proba = 1.0 - (dist / CLICK_RADIUS); + // Facteur d'expansion qui diminue avec la distance + float expansion_factor = 1.0 - (dist / CLICK_RADIUS); - if (random_event(x, y, step, proba)) { - // Conquete facile de territoire neutre - if (data_0[p] == NEUTRE) { - data_0[p] = JOUEUR; - } - // Conquete plus difficile de territoire ennemi - else if (data_0[p] != JOUEUR && random_event(x, y, step, proba * 0.5)) { - data_0[p] = JOUEUR; + // Conquete facile et deterministe de territoire neutre + if (data_0[p] == NEUTRE) { + data_0[p] = JOUEUR; + } + // Conquete de territoire ennemi avec chance proportionnelle a la distance + else if (data_0[p] != JOUEUR && random_event(x, y, step, expansion_factor * 0.8)) { + data_0[p] = JOUEUR; + } + + // Expansion supplementaire dans un rayon plus petit + if (dist < CLICK_RADIUS * 0.6) { + // Pour chaque pixels voisins dans un petit rayon + for (int j = -2; j <= 2; j++) { + for (int i = -2; i <= 2; i++) { + int nx = x + i; + int ny = y + j; + + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int voisin_p = nx + ny * int(WSX); + + // Convertir les territoires neutres proches + if (data_0[voisin_p] == NEUTRE) { + data_0[voisin_p] = JOUEUR; + } + } + } } } } } } - // IA expansion automatique + // IA expansion automatique - garde ce comportement pour équilibrer le jeu if (step % 3 == 0) { // Ralentir IA pour equilibrer // IA 1 Plus agressive if (data_0[p] == IA_1 && random_event(x, y, step, AI_EXPANSION_RATE * 1.5)) { diff --git a/project.godot b/project.godot index 0436dd7..725be9c 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From a7f2015a148b7c5c658898aaf5ca895077ec7219 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:47:43 +0100 Subject: [PATCH 22/29] modif Bonbon --- examples/example_3.tscn | 4 +- examples/territoire/bonbon.cpp | 149 ----------------------- examples/territoire/sceneTerritoire.tscn | 3 + 3 files changed, 5 insertions(+), 151 deletions(-) diff --git a/examples/example_3.tscn b/examples/example_3.tscn index 680ce1e..df2b8a6 100644 --- a/examples/example_3.tscn +++ b/examples/example_3.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://cmucgsppcoo5e"] -[ext_resource type="Script" uid="uid://c8esqdv0y26yp" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] -[ext_resource type="Script" uid="uid://jw3o2qu3a0pl" path="res://examples/LabelStepPass.gd" id="2_4aq4t"] +[ext_resource type="Script" path="res://addons/compute_shader_studio/compute_shader_studio_2d.gd" id="1_eimw3"] +[ext_resource type="Script" path="res://examples/LabelStepPass.gd" id="2_4aq4t"] [ext_resource type="Texture2D" uid="uid://demftcowdd5c6" path="res://examples/icon.svg" id="2_4upxj"] [node name="CompShadStudioEx3" type="Node2D"] diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index 46337af..c743e46 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -16,12 +16,6 @@ #define MOUSE_STORAGE_CLICKED 2 #define MOUSE_BUTTON_PRESSED 3 -// Configuration de affichage du score -#define SCORE_Y int(WSY)/2 -#define DIGIT_WIDTH 8 -#define DIGIT_HEIGHT 12 -#define DIGIT_SPACING 10 - int hash(int x, int y, int s) { int a = x * 0x6A09E667; int b = y * 0xBB67AE85; @@ -59,96 +53,6 @@ void drawVerticalLine(int x, int start_y, int length, int color) { } } -// Dessine un chiffre -void drawDigit(int digit, int x, int y, int color) { - switch(digit) { - case 0: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); - drawVerticalLine(x, y, DIGIT_HEIGHT, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); - break; - case 1: - drawVerticalLine(x + DIGIT_WIDTH - 2, y, DIGIT_HEIGHT, color); - break; - case 2: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT/2, color); - drawVerticalLine(x, y + DIGIT_HEIGHT/2, DIGIT_HEIGHT/2, color); - break; - case 3: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); - break; - case 4: - drawVerticalLine(x, y, DIGIT_HEIGHT/2, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); - break; - case 5: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); - drawVerticalLine(x, y, DIGIT_HEIGHT/2, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y + DIGIT_HEIGHT/2, DIGIT_HEIGHT/2, color); - break; - case 6: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); - drawVerticalLine(x, y, DIGIT_HEIGHT, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y + DIGIT_HEIGHT/2, DIGIT_HEIGHT/2, color); - break; - case 7: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); - break; - case 8: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); - drawVerticalLine(x, y, DIGIT_HEIGHT, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); - break; - case 9: - drawHorizontalLine(x, y, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT/2, DIGIT_WIDTH, color); - drawHorizontalLine(x, y + DIGIT_HEIGHT - 1, DIGIT_WIDTH, color); - drawVerticalLine(x, y, DIGIT_HEIGHT/2, color); - drawVerticalLine(x + DIGIT_WIDTH - 1, y, DIGIT_HEIGHT, color); - break; - } -} - -// Dessine un nombre -void drawNumber(int num, int x, int y, int color) { - if(num == 0) { - drawDigit(0, x, y, color); - return; - } - - int temp = num; - int digits = 0; - - // Compter les chiffres - while(temp > 0) { - temp /= 10; - digits++; - } - - // Dessiner chaque chiffre - temp = num; - for(int i = 0; i < digits; i++) { - int digit = temp % 10; - drawDigit(digit, x + (digits-i-1) * DIGIT_SPACING, y, color); - temp /= 10; - } -} - void main() { int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); @@ -358,58 +262,5 @@ void main() { } } } - - // Calcul des scores une seule fois par frame - int score_joueur = 0; - int score_ia1 = 0; - int score_ia2 = 0; - int score_ia3 = 0; - - if (x == 0 && y == 1) { - for (int j = 0; j < int(WSY); j++) { - for (int i = 0; i < int(WSX); i++) { - int idx = i + j * int(WSX); - if (data_0[idx] == JOUEUR) score_joueur++; - else if (data_0[idx] == IA_1) score_ia1++; - else if (data_0[idx] == IA_2) score_ia2++; - else if (data_0[idx] == IA_3) score_ia3++; - } - } - - // Stocker les scores dans les pixels speciaux - data_0[int(WSX) - 4] = score_joueur; - data_0[int(WSX) - 3] = score_ia1; - data_0[int(WSX) - 2] = score_ia2; - data_0[int(WSX) - 1] = score_ia3; - } - - // Affichage des scores au milieu de ecran - if (y >= SCORE_Y - DIGIT_HEIGHT && y < SCORE_Y + DIGIT_HEIGHT*2) { - // Recuperer les scores - score_joueur = data_0[int(WSX) - 4]; - score_ia1 = data_0[int(WSX) - 3]; - score_ia2 = data_0[int(WSX) - 2]; - score_ia3 = data_0[int(WSX) - 1]; - - // Fond noir pour le score - if (y == SCORE_Y - 5) { - if (x > int(WSX)/2 - 50 && x < int(WSX)/2 + 150) { - data_0[p] = NOIR; - } - } - - // Afficher les scores - if (x == int(WSX)/2 - 45 && y == SCORE_Y) { - drawNumber(score_joueur, int(WSX)/2 - 45, SCORE_Y, JOUEUR); - drawNumber(score_ia1, int(WSX)/2 + 15, SCORE_Y, IA_1); - drawNumber(score_ia2, int(WSX)/2 - 45, SCORE_Y + DIGIT_HEIGHT + 5, IA_2); - drawNumber(score_ia3, int(WSX)/2 + 15, SCORE_Y + DIGIT_HEIGHT + 5, IA_3); - } - } - - // Highlight du curseur - if (x == mousex && y == mousey) { - data_0[p] = BLANC; - } } } \ No newline at end of file diff --git a/examples/territoire/sceneTerritoire.tscn b/examples/territoire/sceneTerritoire.tscn index 8a5cc22..d163060 100644 --- a/examples/territoire/sceneTerritoire.tscn +++ b/examples/territoire/sceneTerritoire.tscn @@ -28,3 +28,6 @@ offset_top = 582.0 offset_right = 792.0 offset_bottom = 622.0 text = "Pause" + +[connection signal="pressed" from="Button" to="ComputeShaderStudio2D" method="_on_button_play"] +[connection signal="pressed" from="Button2" to="ComputeShaderStudio2D" method="_on_button_step"] From 13516822a790a09f617b5bf7688738c49c135bd0 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Thu, 13 Mar 2025 15:22:32 +0100 Subject: [PATCH 23/29] modif Bonbon add black background better expansion for player on-click expansion --- examples/territoire/bonbon.cpp | 76 +++++++----------------- examples/territoire/sceneTerritoire.tscn | 7 +++ 2 files changed, 29 insertions(+), 54 deletions(-) diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index c743e46..2b29546 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -1,4 +1,4 @@ -#define NEUTRE 0xFF808080 +#define NEUTRE 0xFF000000 #define JOUEUR 0xFF0000FF #define IA_1 0xFF00FF00 #define IA_2 0xFFFF0000 @@ -8,7 +8,7 @@ #define CLICK_RADIUS 25 // Rayon d'expansion augmenté #define EXPANSION_AMOUNT 30 // Quantité d'expansion lors d'un clic -#define AI_EXPANSION_RATE 0.03 +#define AI_EXPANSION_RATE 0.02 // Stockage des coordonnees de la souris #define MOUSE_STORAGE_X 0 @@ -115,62 +115,30 @@ void main() { // Interaction joueur - expansion par clic if (clicked && mousex >= 0 && mousey >= 0) { - // Distance au clic - float dist = sqrt(float((x - mousex) * (x - mousex) + (y - mousey) * (y - mousey))); - - // Zone d'expansion massive autour du clic - if (dist < CLICK_RADIUS) { - // Verifier si le clic est proche d'un territoire du joueur - bool proche_joueur = false; + + if (data_0[p] == JOUEUR && random_event(x, y, step, AI_EXPANSION_RATE * 10000000)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; - for (int j = -5; j <= 5; j++) { - for (int i = -5; i <= 5; i++) { - int nx = mousex + i; - int ny = mousey + j; - - if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { - int check_p = nx + ny * int(WSX); - if (data_0[check_p] == JOUEUR) { - proche_joueur = true; - break; - } - } - } - if (proche_joueur) break; + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; } - // Si on est pres d'un territoire du joueur, expansion importante - if (proche_joueur) { - // Facteur d'expansion qui diminue avec la distance - float expansion_factor = 1.0 - (dist / CLICK_RADIUS); - - // Conquete facile et deterministe de territoire neutre - if (data_0[p] == NEUTRE) { - data_0[p] = JOUEUR; - } - // Conquete de territoire ennemi avec chance proportionnelle a la distance - else if (data_0[p] != JOUEUR && random_event(x, y, step, expansion_factor * 0.8)) { - data_0[p] = JOUEUR; - } + int nx = x + dx; + int ny = y + dy; + + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { + int voisin_p = nx + ny * int(WSX); - // Expansion supplementaire dans un rayon plus petit - if (dist < CLICK_RADIUS * 0.6) { - // Pour chaque pixels voisins dans un petit rayon - for (int j = -2; j <= 2; j++) { - for (int i = -2; i <= 2; i++) { - int nx = x + i; - int ny = y + j; - - if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { - int voisin_p = nx + ny * int(WSX); - - // Convertir les territoires neutres proches - if (data_0[voisin_p] == NEUTRE) { - data_0[voisin_p] = JOUEUR; - } - } - } - } + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != JOUEUR && random_event(x, y, step, 3))) { + data_0[voisin_p] = JOUEUR; } } } diff --git a/examples/territoire/sceneTerritoire.tscn b/examples/territoire/sceneTerritoire.tscn index d163060..6f49222 100644 --- a/examples/territoire/sceneTerritoire.tscn +++ b/examples/territoire/sceneTerritoire.tscn @@ -11,6 +11,7 @@ glsl_file = "res://examples/territoire/bonbon.cpp" data = [NodePath("../Icon")] [node name="Icon" type="Sprite2D" parent="."] +texture_filter = 1 position = Vector2(574, 285.5) scale = Vector2(8.79688, 4.28906) texture = ExtResource("2_otyot") @@ -29,5 +30,11 @@ offset_right = 792.0 offset_bottom = 622.0 text = "Pause" +[node name="HSlider" type="HSlider" parent="."] +offset_left = 401.0 +offset_top = 592.0 +offset_right = 652.0 +offset_bottom = 608.0 + [connection signal="pressed" from="Button" to="ComputeShaderStudio2D" method="_on_button_play"] [connection signal="pressed" from="Button2" to="ComputeShaderStudio2D" method="_on_button_step"] From 6fdf3eb236ebf8910e4c4d518fd9227742adaee2 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Thu, 13 Mar 2025 15:27:40 +0100 Subject: [PATCH 24/29] modif bonbon add possibility to eat other to IA 2 and 3 --- examples/territoire/bonbon.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index 2b29546..445a79a 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -3,12 +3,8 @@ #define IA_1 0xFF00FF00 #define IA_2 0xFFFF0000 #define IA_3 0xFFFFFF00 -#define BLANC 0xFFFFFFFF -#define NOIR 0xFF000000 -#define CLICK_RADIUS 25 // Rayon d'expansion augmenté -#define EXPANSION_AMOUNT 30 // Quantité d'expansion lors d'un clic -#define AI_EXPANSION_RATE 0.02 +#define AI_EXPANSION_RATE 0.2 // Stockage des coordonnees de la souris #define MOUSE_STORAGE_X 0 @@ -196,7 +192,7 @@ void main() { if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { int voisin_p = nx + ny * int(WSX); - if (data_0[voisin_p] == NEUTRE) { + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_2 && random_event(x, y, step, 0.2))) { data_0[voisin_p] = IA_2; } } @@ -224,7 +220,7 @@ void main() { if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { int voisin_p = nx + ny * int(WSX); - if (data_0[voisin_p] == NEUTRE) { + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_3 && random_event(x, y, step, 0.2))) { data_0[voisin_p] = IA_3; } } From d480232541e653734dc868188f0905f50bccdd11 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Mon, 17 Mar 2025 08:14:46 +0100 Subject: [PATCH 25/29] =?UTF-8?q?enlver=20gestion=20souris=20non=20n=C3=A9?= =?UTF-8?q?cessaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/territoire/bonbon.cpp | 33 +-------------------------------- project.godot | 2 +- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index 445a79a..840cfeb 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -6,12 +6,6 @@ #define AI_EXPANSION_RATE 0.2 -// Stockage des coordonnees de la souris -#define MOUSE_STORAGE_X 0 -#define MOUSE_STORAGE_Y 1 -#define MOUSE_STORAGE_CLICKED 2 -#define MOUSE_BUTTON_PRESSED 3 - int hash(int x, int y, int s) { int a = x * 0x6A09E667; int b = y * 0xBB67AE85; @@ -29,26 +23,6 @@ bool random_event(int x, int y, int step, float probability) { return (normalized > 0.0 ? normalized : -normalized) < probability; } -// Dessine un segment horizontal -void drawHorizontalLine(int start_x, int y, int length, int color) { - for(int i = 0; i < length; i++) { - int pos = (start_x + i) + y * int(WSX); - if(start_x + i >= 0 && start_x + i < int(WSX) && y >= 0 && y < int(WSY)) { - data_0[pos] = color; - } - } -} - -// Dessine un segment vertical -void drawVerticalLine(int x, int start_y, int length, int color) { - for(int i = 0; i < length; i++) { - int pos = x + (start_y + i) * int(WSX); - if(x >= 0 && x < int(WSX) && start_y + i >= 0 && start_y + i < int(WSY)) { - data_0[pos] = color; - } - } -} - void main() { int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); @@ -56,12 +30,7 @@ void main() { // Initialisation if (step == 0) { - // Premiere rangee pour stocker les infos de la souris - if (y == 0 && x < 10) { - data_0[p] = -1; // Initialiser a -1 - } - // Territoire du joueur en haut a gauche - else if (x < int(WSX)/8 && y < int(WSY)/8) { + if (x < int(WSX)/8 && y < int(WSY)/8) { data_0[p] = JOUEUR; } // IA 1 en haut a droite diff --git a/project.godot b/project.godot index 725be9c..0436dd7 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.3", "Forward Plus") +config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From 8101b685bf441d73a541abf8fa71207c482c2780 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Mon, 17 Mar 2025 08:30:32 +0100 Subject: [PATCH 26/29] last version --- examples/territoire/bonbon.cpp | 6 ++++++ examples/territoire/sceneTerritoire.tscn | 22 ++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index 840cfeb..039d67a 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -6,6 +6,12 @@ #define AI_EXPANSION_RATE 0.2 +// Stockage des coordonnees de la souris +#define MOUSE_STORAGE_X 0 +#define MOUSE_STORAGE_Y 1 +#define MOUSE_STORAGE_CLICKED 2 +#define MOUSE_BUTTON_PRESSED 3 + int hash(int x, int y, int s) { int a = x * 0x6A09E667; int b = y * 0xBB67AE85; diff --git a/examples/territoire/sceneTerritoire.tscn b/examples/territoire/sceneTerritoire.tscn index 6f49222..a6ea8aa 100644 --- a/examples/territoire/sceneTerritoire.tscn +++ b/examples/territoire/sceneTerritoire.tscn @@ -17,24 +17,18 @@ scale = Vector2(8.79688, 4.28906) texture = ExtResource("2_otyot") [node name="Button" type="Button" parent="."] -offset_left = 255.0 -offset_top = 581.0 -offset_right = 355.0 -offset_bottom = 621.0 +offset_left = 459.0 +offset_top = 578.0 +offset_right = 559.0 +offset_bottom = 618.0 text = "Start" [node name="Button2" type="Button" parent="."] -offset_left = 707.0 -offset_top = 582.0 -offset_right = 792.0 -offset_bottom = 622.0 +offset_left = 602.0 +offset_top = 578.0 +offset_right = 687.0 +offset_bottom = 618.0 text = "Pause" -[node name="HSlider" type="HSlider" parent="."] -offset_left = 401.0 -offset_top = 592.0 -offset_right = 652.0 -offset_bottom = 608.0 - [connection signal="pressed" from="Button" to="ComputeShaderStudio2D" method="_on_button_play"] [connection signal="pressed" from="Button2" to="ComputeShaderStudio2D" method="_on_button_step"] From 45769141ea8f2531fd6227811314c59616bb36f0 Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Mon, 17 Mar 2025 09:06:41 +0100 Subject: [PATCH 27/29] Ajout du score avec zone demilitarisee --- examples/territoire/.vscode/settings.json | 27 + examples/territoire/bonbon.cpp | 561 +++++++++++++----- .../territorial/.vscode/settings.json | 27 + project.godot | 2 +- 4 files changed, 477 insertions(+), 140 deletions(-) create mode 100644 examples/territoire/.vscode/settings.json create mode 100644 examples/territoire/territorial/.vscode/settings.json diff --git a/examples/territoire/.vscode/settings.json b/examples/territoire/.vscode/settings.json new file mode 100644 index 0000000..a07d7ea --- /dev/null +++ b/examples/territoire/.vscode/settings.json @@ -0,0 +1,27 @@ +{ + "workbench.view.alwaysShowHeaderActions": true, + "workbench.tree.renderIndentGuides": "none", + "[pvs]": { + "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}|;:'\",.<>/" + }, + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "**/*.???~": true, + "**/.pvscontext": true, + "**/pvsbin": true, + "**/*.jprf": true, + "**/*.prf": true, + "**/orphaned-proofs.prf": true, + "**/*_adt.pvs": false, + "**/*.log": false, + "**/.vscode": true + }, + "files.readonlyInclude": { + "**/*.tccs": true, + "**/*.summary": true + } +} \ No newline at end of file diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index 039d67a..f4041d3 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -4,6 +4,13 @@ #define IA_2 0xFFFF0000 #define IA_3 0xFFFFFF00 +// Couleurs pour afficher les scores +#define SCORE_BG_JOUEUR 0xFFDDDDFF +#define SCORE_BG_IA_1 0xFFDDFFDD +#define SCORE_BG_IA_2 0xFFFFDDDD +#define SCORE_BG_IA_3 0xFFFFFFDD +#define ZONE_DEMILITARISEE 0xFF888888 + #define AI_EXPANSION_RATE 0.2 // Stockage des coordonnees de la souris @@ -12,6 +19,24 @@ #define MOUSE_STORAGE_CLICKED 2 #define MOUSE_BUTTON_PRESSED 3 +// Stockage des scores +#define SCORE_JOUEUR 4 +#define SCORE_IA_1 5 +#define SCORE_IA_2 6 +#define SCORE_IA_3 7 + +// Taille de la zone demilitarisee +#define ZONE_DEM_SIZE 40 + +// Verifier si un point est dans la zone demilitarisee +bool is_demilitarized_zone(int x, int y) { + int centerX = int(WSX) / 2; + int centerY = int(WSY) / 2; + + return (x >= centerX - ZONE_DEM_SIZE / 2 && x < centerX + ZONE_DEM_SIZE / 2 && + y >= centerY - ZONE_DEM_SIZE / 2 && y < centerY + ZONE_DEM_SIZE / 2); +} + int hash(int x, int y, int s) { int a = x * 0x6A09E667; int b = y * 0xBB67AE85; @@ -29,177 +54,435 @@ bool random_event(int x, int y, int step, float probability) { return (normalized > 0.0 ? normalized : -normalized) < probability; } -void main() { +// Fonction pour calculer et mettre a jour les scores +void calculate_scores() { + if (gl_GlobalInvocationID.x == 0 && gl_GlobalInvocationID.y == 0) { + // Initialiser les scores a zero + data_0[SCORE_JOUEUR] = 0; + data_0[SCORE_IA_1] = 0; + data_0[SCORE_IA_2] = 0; + data_0[SCORE_IA_3] = 0; + + // Parcourir toute la grille pour compter les territoires + for (int i = 0; i < int(WSX) * int(WSY); i++) { + // Ne compter que les pixels qui ne sont pas dans la zone demilitarisee + int px = i % int(WSX); + int py = i / int(WSX); + + if (!is_demilitarized_zone(px, py)) { + if (data_0[i] == JOUEUR) { + data_0[SCORE_JOUEUR]++; + } else if (data_0[i] == IA_1) { + data_0[SCORE_IA_1]++; + } else if (data_0[i] == IA_2) { + data_0[SCORE_IA_2]++; + } else if (data_0[i] == IA_3) { + data_0[SCORE_IA_3]++; + } + } + } + } +} + +// Affiche un chiffre a la position donnee +void draw_digit(int digit, int startX, int startY, int color) { int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); int p = x + y * int(WSX); - // Initialisation - if (step == 0) { - if (x < int(WSX)/8 && y < int(WSY)/8) { - data_0[p] = JOUEUR; - } - // IA 1 en haut a droite - else if (x > int(WSX)*7/8 && y < int(WSY)/8) { - data_0[p] = IA_1; - } - // IA 2 en bas a gauche - else if (x < int(WSX)/8 && y > int(WSY)*7/8) { - data_0[p] = IA_2; - } - // IA 3 en bas a droite - else if (x > int(WSX)*7/8 && y > int(WSY)*7/8) { - data_0[p] = IA_3; - } - // Reste de la carte neutre - else { - data_0[p] = NEUTRE; + // Verification si nous sommes dans la region du chiffre + if (x >= startX && x < startX + 3 && y >= startY && y < startY + 5) { + int localX = x - startX; + int localY = y - startY; + bool pixel_on = false; + + // Representation minimaliste des chiffres en 3x5 pixels + switch (digit) { + case 0: + pixel_on = (localX == 0 || localX == 2 || localY == 0 || localY == 4) || + (localX == 1 && (localY == 0 || localY == 4)); + break; + case 1: + pixel_on = (localX == 1) || (localY == 4 && localX != 0); + break; + case 2: + pixel_on = (localY == 0 || localY == 2 || localY == 4) || + (localX == 2 && localY == 1) || (localX == 0 && localY == 3); + break; + case 3: + pixel_on = (localY == 0 || localY == 2 || localY == 4) || (localX == 2); + break; + case 4: + pixel_on = (localX == 0 && localY < 3) || (localX == 2) || (localY == 2); + break; + case 5: + pixel_on = (localY == 0 || localY == 2 || localY == 4) || + (localX == 0 && localY == 1) || (localX == 2 && localY == 3); + break; + case 6: + pixel_on = (localY == 0 || localY == 2 || localY == 4) || + (localX == 0) || (localX == 2 && localY > 2); + break; + case 7: + pixel_on = (localY == 0) || (localX == 2); + break; + case 8: + pixel_on = (localY == 0 || localY == 2 || localY == 4) || + (localX == 0 || localX == 2); + break; + case 9: + pixel_on = (localY == 0 || localY == 2 || localY == 4) || + (localX == 2) || (localX == 0 && localY < 3); + break; } - } - // Logique de jeu - else { - // Gestion du clic de souris - bool clicked = false; - // Verifier si c est un nouveau clic seulement au debut de la frame - if (y == 0 && x == 0) { - int lastX = data_0[MOUSE_STORAGE_X]; - int lastY = data_0[MOUSE_STORAGE_Y]; - bool lastButtonState = data_0[MOUSE_BUTTON_PRESSED] > 0; - bool currentButtonState = mouse_button > 0; - - // Detecter un clic seulement quand le bouton vient d'etre presse - if (currentButtonState && !lastButtonState) { - clicked = true; - data_0[MOUSE_STORAGE_CLICKED] = 1; + if (pixel_on) { + data_0[p] = color; + } + } +} + +// Fonction pour afficher les scores dans la zone demilitarisee +void draw_scores_in_demilitarized_zone() { + int x = int(gl_GlobalInvocationID.x); + int y = int(gl_GlobalInvocationID.y); + + if (is_demilitarized_zone(x, y)) { + int centerX = int(WSX) / 2; + int centerY = int(WSY) / 2; + int p = x + y * int(WSX); + + // Fond de la zone demilitarisee + data_0[p] = ZONE_DEMILITARISEE; + + // Recuperer les scores + int score_joueur = data_0[SCORE_JOUEUR]; + int score_ia_1 = data_0[SCORE_IA_1]; + int score_ia_2 = data_0[SCORE_IA_2]; + int score_ia_3 = data_0[SCORE_IA_3]; + + // Quadrant haut gauche - Joueur + if (x < centerX && y < centerY) { + data_0[p] = SCORE_BG_JOUEUR; + + // Afficher le score du joueur + // Calculer les chiffres individuels (jusqu'a 4 chiffres) + int thousands = score_joueur / 1000; + int hundreds = (score_joueur / 100) % 10; + int tens = (score_joueur / 10) % 10; + int ones = score_joueur % 10; + + // Position de depart pour l'affichage des chiffres + int startX = centerX - ZONE_DEM_SIZE / 2 + 3; + int startY = centerY - ZONE_DEM_SIZE / 2 + 3; + + // Afficher chaque chiffre + if (thousands > 0) { + draw_digit(thousands, startX, startY, JOUEUR); + draw_digit(hundreds, startX + 4, startY, JOUEUR); + draw_digit(tens, startX + 8, startY, JOUEUR); + draw_digit(ones, startX + 12, startY, JOUEUR); + } else if (hundreds > 0) { + draw_digit(hundreds, startX, startY, JOUEUR); + draw_digit(tens, startX + 4, startY, JOUEUR); + draw_digit(ones, startX + 8, startY, JOUEUR); + } else if (tens > 0) { + draw_digit(tens, startX + 2, startY, JOUEUR); + draw_digit(ones, startX + 6, startY, JOUEUR); } else { - data_0[MOUSE_STORAGE_CLICKED] = 0; + draw_digit(ones, startX + 4, startY, JOUEUR); } + } + // Quadrant haut droite - IA_1 + else if (x >= centerX && y < centerY) { + data_0[p] = SCORE_BG_IA_1; + + // Afficher le score de l'IA 1 + int thousands = score_ia_1 / 1000; + int hundreds = (score_ia_1 / 100) % 10; + int tens = (score_ia_1 / 10) % 10; + int ones = score_ia_1 % 10; - // Sauvegarder la position et l'etat du bouton - data_0[MOUSE_STORAGE_X] = mousex; - data_0[MOUSE_STORAGE_Y] = mousey; - data_0[MOUSE_BUTTON_PRESSED] = currentButtonState ? 1 : 0; + int startX = centerX + 3; + int startY = centerY - ZONE_DEM_SIZE / 2 + 3; + + if (thousands > 0) { + draw_digit(thousands, startX, startY, IA_1); + draw_digit(hundreds, startX + 4, startY, IA_1); + draw_digit(tens, startX + 8, startY, IA_1); + draw_digit(ones, startX + 12, startY, IA_1); + } else if (hundreds > 0) { + draw_digit(hundreds, startX, startY, IA_1); + draw_digit(tens, startX + 4, startY, IA_1); + draw_digit(ones, startX + 8, startY, IA_1); + } else if (tens > 0) { + draw_digit(tens, startX + 2, startY, IA_1); + draw_digit(ones, startX + 6, startY, IA_1); + } else { + draw_digit(ones, startX + 4, startY, IA_1); + } } - - clicked = data_0[MOUSE_STORAGE_CLICKED] == 1; - - // Interaction joueur - expansion par clic - if (clicked && mousex >= 0 && mousey >= 0) { + // Quadrant bas gauche - IA_2 + else if (x < centerX && y >= centerY) { + data_0[p] = SCORE_BG_IA_2; + + // Afficher le score de l'IA 2 + int thousands = score_ia_2 / 1000; + int hundreds = (score_ia_2 / 100) % 10; + int tens = (score_ia_2 / 10) % 10; + int ones = score_ia_2 % 10; + + int startX = centerX - ZONE_DEM_SIZE / 2 + 3; + int startY = centerY + 3; + + if (thousands > 0) { + draw_digit(thousands, startX, startY, IA_2); + draw_digit(hundreds, startX + 4, startY, IA_2); + draw_digit(tens, startX + 8, startY, IA_2); + draw_digit(ones, startX + 12, startY, IA_2); + } else if (hundreds > 0) { + draw_digit(hundreds, startX, startY, IA_2); + draw_digit(tens, startX + 4, startY, IA_2); + draw_digit(ones, startX + 8, startY, IA_2); + } else if (tens > 0) { + draw_digit(tens, startX + 2, startY, IA_2); + draw_digit(ones, startX + 6, startY, IA_2); + } else { + draw_digit(ones, startX + 4, startY, IA_2); + } + } + // Quadrant bas droite - IA_3 + else if (x >= centerX && y >= centerY) { + data_0[p] = SCORE_BG_IA_3; + + // Afficher le score de l'IA 3 + int thousands = score_ia_3 / 1000; + int hundreds = (score_ia_3 / 100) % 10; + int tens = (score_ia_3 / 10) % 10; + int ones = score_ia_3 % 10; + + int startX = centerX + 3; + int startY = centerY + 3; + + if (thousands > 0) { + draw_digit(thousands, startX, startY, IA_3); + draw_digit(hundreds, startX + 4, startY, IA_3); + draw_digit(tens, startX + 8, startY, IA_3); + draw_digit(ones, startX + 12, startY, IA_3); + } else if (hundreds > 0) { + draw_digit(hundreds, startX, startY, IA_3); + draw_digit(tens, startX + 4, startY, IA_3); + draw_digit(ones, startX + 8, startY, IA_3); + } else if (tens > 0) { + draw_digit(tens, startX + 2, startY, IA_3); + draw_digit(ones, startX + 6, startY, IA_3); + } else { + draw_digit(ones, startX + 4, startY, IA_3); + } + } + } +} - if (data_0[p] == JOUEUR && random_event(x, y, step, AI_EXPANSION_RATE * 10000000)) { - int direction = hash(x, y, step) % 8; - int dx = 0, dy = 0; - - switch (direction) { - case 0: dx = -1; dy = 0; break; - case 1: dx = 1; dy = 0; break; - case 2: dx = 0; dy = -1; break; - case 3: dx = 0; dy = 1; break; - case 4: dx = -1; dy = -1; break; - case 5: dx = 1; dy = -1; break; - case 6: dx = -1; dy = 1; break; - case 7: dx = 1; dy = 1; break; - } - - int nx = x + dx; - int ny = y + dy; - - if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { - int voisin_p = nx + ny * int(WSX); - - if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != JOUEUR && random_event(x, y, step, 3))) { - data_0[voisin_p] = JOUEUR; - } - } +void main() { + int x = int(gl_GlobalInvocationID.x); + int y = int(gl_GlobalInvocationID.y); + int p = x + y * int(WSX); + + // Initialisation + if (step == 0) { + // Verifier si le pixel est dans la zone demilitarisee + if (is_demilitarized_zone(x, y)) { + draw_scores_in_demilitarized_zone(); + } else { + // Initialisation normale pour les autres pixels + if (x < int(WSX)/8 && y < int(WSY)/8) { + data_0[p] = JOUEUR; + } + // IA 1 en haut a droite + else if (x > int(WSX)*7/8 && y < int(WSY)/8) { + data_0[p] = IA_1; + } + // IA 2 en bas a gauche + else if (x < int(WSX)/8 && y > int(WSY)*7/8) { + data_0[p] = IA_2; + } + // IA 3 en bas a droite + else if (x > int(WSX)*7/8 && y > int(WSY)*7/8) { + data_0[p] = IA_3; + } + // Reste de la carte neutre + else { + data_0[p] = NEUTRE; } } - // IA expansion automatique - garde ce comportement pour équilibrer le jeu - if (step % 3 == 0) { // Ralentir IA pour equilibrer - // IA 1 Plus agressive - if (data_0[p] == IA_1 && random_event(x, y, step, AI_EXPANSION_RATE * 1.5)) { - int direction = hash(x, y, step) % 8; - int dx = 0, dy = 0; + // Initialiser les scores + if (x == 0 && y == 0) { + data_0[SCORE_JOUEUR] = 0; + data_0[SCORE_IA_1] = 0; + data_0[SCORE_IA_2] = 0; + data_0[SCORE_IA_3] = 0; + } + } + // Logique de jeu + else { + // Si on est dans la zone demilitarisee, on affiche les scores + if (is_demilitarized_zone(x, y)) { + draw_scores_in_demilitarized_zone(); + } else { + // Sinon, logique de jeu normale + + // Gestion du clic de souris + bool clicked = false; + + // Verifier si c est un nouveau clic seulement au debut de la frame + if (y == 0 && x == 0) { + int lastX = data_0[MOUSE_STORAGE_X]; + int lastY = data_0[MOUSE_STORAGE_Y]; + bool lastButtonState = data_0[MOUSE_BUTTON_PRESSED] > 0; + bool currentButtonState = mouse_button > 0; - switch (direction) { - case 0: dx = -1; dy = 0; break; - case 1: dx = 1; dy = 0; break; - case 2: dx = 0; dy = -1; break; - case 3: dx = 0; dy = 1; break; - case 4: dx = -1; dy = -1; break; - case 5: dx = 1; dy = -1; break; - case 6: dx = -1; dy = 1; break; - case 7: dx = 1; dy = 1; break; + // Detecter un clic seulement quand le bouton vient d'etre presse + if (currentButtonState && !lastButtonState) { + clicked = true; + data_0[MOUSE_STORAGE_CLICKED] = 1; + } else { + data_0[MOUSE_STORAGE_CLICKED] = 0; } - int nx = x + dx; - int ny = y + dy; - - if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { - int voisin_p = nx + ny * int(WSX); + // Sauvegarder la position et l'etat du bouton + data_0[MOUSE_STORAGE_X] = mousex; + data_0[MOUSE_STORAGE_Y] = mousey; + data_0[MOUSE_BUTTON_PRESSED] = currentButtonState ? 1 : 0; + } + + clicked = data_0[MOUSE_STORAGE_CLICKED] == 1; + + // Interaction joueur - expansion par clic + if (clicked && mousex >= 0 && mousey >= 0) { + if (data_0[p] == JOUEUR && random_event(x, y, step, AI_EXPANSION_RATE * 10000000)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; - if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_1 && random_event(x, y, step, 0.2))) { - data_0[voisin_p] = IA_1; + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; + } + + int nx = x + dx; + int ny = y + dy; + + // Verifier que le pixel voisin n'est pas dans la zone demilitarisee + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY) && !is_demilitarized_zone(nx, ny)) { + int voisin_p = nx + ny * int(WSX); + + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != JOUEUR && random_event(x, y, step, 3))) { + data_0[voisin_p] = JOUEUR; + } } } } - // IA 2 Expansion normale - else if (data_0[p] == IA_2 && random_event(x, y, step, AI_EXPANSION_RATE)) { - int direction = hash(x, y, step) % 8; - int dx = 0, dy = 0; - - switch (direction) { - case 0: dx = -1; dy = 0; break; - case 1: dx = 1; dy = 0; break; - case 2: dx = 0; dy = -1; break; - case 3: dx = 0; dy = 1; break; - case 4: dx = -1; dy = -1; break; - case 5: dx = 1; dy = -1; break; - case 6: dx = -1; dy = 1; break; - case 7: dx = 1; dy = 1; break; - } - - int nx = x + dx; - int ny = y + dy; - - if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { - int voisin_p = nx + ny * int(WSX); + // IA expansion automatique - garde ce comportement pour equilibrer le jeu + if (step % 3 == 0) { // Ralentir IA pour equilibrer + // IA 1 Plus agressive + if (data_0[p] == IA_1 && random_event(x, y, step, AI_EXPANSION_RATE * 1.5)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; + + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; + } + + int nx = x + dx; + int ny = y + dy; - if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_2 && random_event(x, y, step, 0.2))) { - data_0[voisin_p] = IA_2; + // Verifier que le pixel voisin n'est pas dans la zone demilitarisee + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY) && !is_demilitarized_zone(nx, ny)) { + int voisin_p = nx + ny * int(WSX); + + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_1 && random_event(x, y, step, 0.2))) { + data_0[voisin_p] = IA_1; + } } } - } - - // IA 3 Plus defensive - else if (data_0[p] == IA_3 && random_event(x, y, step, AI_EXPANSION_RATE * 0.8)) { - int direction = hash(x, y, step) % 8; - int dx = 0, dy = 0; - switch (direction) { - case 0: dx = -1; dy = 0; break; - case 1: dx = 1; dy = 0; break; - case 2: dx = 0; dy = -1; break; - case 3: dx = 0; dy = 1; break; - case 4: dx = -1; dy = -1; break; - case 5: dx = 1; dy = -1; break; - case 6: dx = -1; dy = 1; break; - case 7: dx = 1; dy = 1; break; + // IA 2 Expansion normale + else if (data_0[p] == IA_2 && random_event(x, y, step, AI_EXPANSION_RATE)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; + + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; + } + + int nx = x + dx; + int ny = y + dy; + + // Verifier que le pixel voisin n'est pas dans la zone demilitarisee + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY) && !is_demilitarized_zone(nx, ny)) { + int voisin_p = nx + ny * int(WSX); + + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_2 && random_event(x, y, step, 0.2))) { + data_0[voisin_p] = IA_2; + } + } } - int nx = x + dx; - int ny = y + dy; - - if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY)) { - int voisin_p = nx + ny * int(WSX); + // IA 3 Plus defensive + else if (data_0[p] == IA_3 && random_event(x, y, step, AI_EXPANSION_RATE * 0.8)) { + int direction = hash(x, y, step) % 8; + int dx = 0, dy = 0; + + switch (direction) { + case 0: dx = -1; dy = 0; break; + case 1: dx = 1; dy = 0; break; + case 2: dx = 0; dy = -1; break; + case 3: dx = 0; dy = 1; break; + case 4: dx = -1; dy = -1; break; + case 5: dx = 1; dy = -1; break; + case 6: dx = -1; dy = 1; break; + case 7: dx = 1; dy = 1; break; + } - if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_3 && random_event(x, y, step, 0.2))) { - data_0[voisin_p] = IA_3; + int nx = x + dx; + int ny = y + dy; + + // Verifier que le pixel voisin n'est pas dans la zone demilitarisee + if (nx >= 0 && nx < int(WSX) && ny >= 0 && ny < int(WSY) && !is_demilitarized_zone(nx, ny)) { + int voisin_p = nx + ny * int(WSX); + + if (data_0[voisin_p] == NEUTRE || (data_0[voisin_p] != IA_3 && random_event(x, y, step, 0.2))) { + data_0[voisin_p] = IA_3; + } } } } } + + // Calculer les scores tous les steps + if (step % 1 == 0 && x == 0 && y == 0) { + calculate_scores(); + } } } \ No newline at end of file diff --git a/examples/territoire/territorial/.vscode/settings.json b/examples/territoire/territorial/.vscode/settings.json new file mode 100644 index 0000000..a07d7ea --- /dev/null +++ b/examples/territoire/territorial/.vscode/settings.json @@ -0,0 +1,27 @@ +{ + "workbench.view.alwaysShowHeaderActions": true, + "workbench.tree.renderIndentGuides": "none", + "[pvs]": { + "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}|;:'\",.<>/" + }, + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "**/*.???~": true, + "**/.pvscontext": true, + "**/pvsbin": true, + "**/*.jprf": true, + "**/*.prf": true, + "**/orphaned-proofs.prf": true, + "**/*_adt.pvs": false, + "**/*.log": false, + "**/.vscode": true + }, + "files.readonlyInclude": { + "**/*.tccs": true, + "**/*.summary": true + } +} \ No newline at end of file diff --git a/project.godot b/project.godot index 0436dd7..725be9c 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="compute_shader_studio" run/main_scene="res://examples/example_1.tscn" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://addons/compute_shader_studio/icon.png" [editor_plugins] From 49016b6c49c0c06237166cb92cef6e71e0c2a524 Mon Sep 17 00:00:00 2001 From: laissy-dev Date: Mon, 17 Mar 2025 09:19:48 +0100 Subject: [PATCH 28/29] Reduction /10 des scores globaux pour fix affichage --- examples/territoire/bonbon.cpp | 54 ++++++++++------------------------ 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index f4041d3..6e6cd6e 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -155,20 +155,19 @@ void draw_scores_in_demilitarized_zone() { // Fond de la zone demilitarisee data_0[p] = ZONE_DEMILITARISEE; - // Recuperer les scores - int score_joueur = data_0[SCORE_JOUEUR]; - int score_ia_1 = data_0[SCORE_IA_1]; - int score_ia_2 = data_0[SCORE_IA_2]; - int score_ia_3 = data_0[SCORE_IA_3]; + // Recuperer les scores et les diviser par 10 + int score_joueur = data_0[SCORE_JOUEUR] / 10; + int score_ia_1 = data_0[SCORE_IA_1] / 10; + int score_ia_2 = data_0[SCORE_IA_2] / 10; + int score_ia_3 = data_0[SCORE_IA_3] / 10; // Quadrant haut gauche - Joueur if (x < centerX && y < centerY) { data_0[p] = SCORE_BG_JOUEUR; // Afficher le score du joueur - // Calculer les chiffres individuels (jusqu'a 4 chiffres) - int thousands = score_joueur / 1000; - int hundreds = (score_joueur / 100) % 10; + // Calculer les chiffres individuels (jusqu'a 3 chiffres) + int hundreds = score_joueur / 100; int tens = (score_joueur / 10) % 10; int ones = score_joueur % 10; @@ -177,12 +176,7 @@ void draw_scores_in_demilitarized_zone() { int startY = centerY - ZONE_DEM_SIZE / 2 + 3; // Afficher chaque chiffre - if (thousands > 0) { - draw_digit(thousands, startX, startY, JOUEUR); - draw_digit(hundreds, startX + 4, startY, JOUEUR); - draw_digit(tens, startX + 8, startY, JOUEUR); - draw_digit(ones, startX + 12, startY, JOUEUR); - } else if (hundreds > 0) { + if (hundreds > 0) { draw_digit(hundreds, startX, startY, JOUEUR); draw_digit(tens, startX + 4, startY, JOUEUR); draw_digit(ones, startX + 8, startY, JOUEUR); @@ -198,20 +192,14 @@ void draw_scores_in_demilitarized_zone() { data_0[p] = SCORE_BG_IA_1; // Afficher le score de l'IA 1 - int thousands = score_ia_1 / 1000; - int hundreds = (score_ia_1 / 100) % 10; + int hundreds = score_ia_1 / 100; int tens = (score_ia_1 / 10) % 10; int ones = score_ia_1 % 10; int startX = centerX + 3; int startY = centerY - ZONE_DEM_SIZE / 2 + 3; - if (thousands > 0) { - draw_digit(thousands, startX, startY, IA_1); - draw_digit(hundreds, startX + 4, startY, IA_1); - draw_digit(tens, startX + 8, startY, IA_1); - draw_digit(ones, startX + 12, startY, IA_1); - } else if (hundreds > 0) { + if (hundreds > 0) { draw_digit(hundreds, startX, startY, IA_1); draw_digit(tens, startX + 4, startY, IA_1); draw_digit(ones, startX + 8, startY, IA_1); @@ -227,20 +215,14 @@ void draw_scores_in_demilitarized_zone() { data_0[p] = SCORE_BG_IA_2; // Afficher le score de l'IA 2 - int thousands = score_ia_2 / 1000; - int hundreds = (score_ia_2 / 100) % 10; + int hundreds = score_ia_2 / 100; int tens = (score_ia_2 / 10) % 10; int ones = score_ia_2 % 10; int startX = centerX - ZONE_DEM_SIZE / 2 + 3; int startY = centerY + 3; - if (thousands > 0) { - draw_digit(thousands, startX, startY, IA_2); - draw_digit(hundreds, startX + 4, startY, IA_2); - draw_digit(tens, startX + 8, startY, IA_2); - draw_digit(ones, startX + 12, startY, IA_2); - } else if (hundreds > 0) { + if (hundreds > 0) { draw_digit(hundreds, startX, startY, IA_2); draw_digit(tens, startX + 4, startY, IA_2); draw_digit(ones, startX + 8, startY, IA_2); @@ -256,20 +238,14 @@ void draw_scores_in_demilitarized_zone() { data_0[p] = SCORE_BG_IA_3; // Afficher le score de l'IA 3 - int thousands = score_ia_3 / 1000; - int hundreds = (score_ia_3 / 100) % 10; + int hundreds = score_ia_3 / 100; int tens = (score_ia_3 / 10) % 10; int ones = score_ia_3 % 10; int startX = centerX + 3; int startY = centerY + 3; - if (thousands > 0) { - draw_digit(thousands, startX, startY, IA_3); - draw_digit(hundreds, startX + 4, startY, IA_3); - draw_digit(tens, startX + 8, startY, IA_3); - draw_digit(ones, startX + 12, startY, IA_3); - } else if (hundreds > 0) { + if (hundreds > 0) { draw_digit(hundreds, startX, startY, IA_3); draw_digit(tens, startX + 4, startY, IA_3); draw_digit(ones, startX + 8, startY, IA_3); @@ -481,7 +457,7 @@ void main() { } // Calculer les scores tous les steps - if (step % 1 == 0 && x == 0 && y == 0) { + if (step % 10 == 0 && x == 0 && y == 0) { calculate_scores(); } } From 44dce678b24ef8414357c5b067c466162ae77ce2 Mon Sep 17 00:00:00 2001 From: HuguesLa <101565855+HuguesLa@users.noreply.github.com> Date: Mon, 17 Mar 2025 09:55:17 +0100 Subject: [PATCH 29/29] update parameters --- examples/territoire/bonbon.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/territoire/bonbon.cpp b/examples/territoire/bonbon.cpp index 6e6cd6e..8036a16 100644 --- a/examples/territoire/bonbon.cpp +++ b/examples/territoire/bonbon.cpp @@ -26,7 +26,7 @@ #define SCORE_IA_3 7 // Taille de la zone demilitarisee -#define ZONE_DEM_SIZE 40 +#define ZONE_DEM_SIZE 30 // Verifier si un point est dans la zone demilitarisee bool is_demilitarized_zone(int x, int y) { @@ -155,11 +155,11 @@ void draw_scores_in_demilitarized_zone() { // Fond de la zone demilitarisee data_0[p] = ZONE_DEMILITARISEE; - // Recuperer les scores et les diviser par 10 - int score_joueur = data_0[SCORE_JOUEUR] / 10; - int score_ia_1 = data_0[SCORE_IA_1] / 10; - int score_ia_2 = data_0[SCORE_IA_2] / 10; - int score_ia_3 = data_0[SCORE_IA_3] / 10; + // Recuperer les scores et les diviser par 16 + int score_joueur = data_0[SCORE_JOUEUR] / (int(WSX)/8); + int score_ia_1 = data_0[SCORE_IA_1] / (int(WSX)/8); + int score_ia_2 = data_0[SCORE_IA_2] / (int(WSX)/8); + int score_ia_3 = data_0[SCORE_IA_3] / (int(WSX)/8); // Quadrant haut gauche - Joueur if (x < centerX && y < centerY) { @@ -366,7 +366,7 @@ void main() { } // IA expansion automatique - garde ce comportement pour equilibrer le jeu - if (step % 3 == 0) { // Ralentir IA pour equilibrer + if (step % 5 == 0) { // Ralentir IA pour equilibrer // IA 1 Plus agressive if (data_0[p] == IA_1 && random_event(x, y, step, AI_EXPANSION_RATE * 1.5)) { int direction = hash(x, y, step) % 8; @@ -457,7 +457,7 @@ void main() { } // Calculer les scores tous les steps - if (step % 10 == 0 && x == 0 && y == 0) { + if (step % 30 == 0 && x == 0 && y == 0) { calculate_scores(); } }