From 425af054306f832fe8559a6f034ed81c5fd67f25 Mon Sep 17 00:00:00 2001 From: GeoffreyFrogeye Date: Mon, 12 May 2014 12:01:56 +0200 Subject: [PATCH] =?UTF-8?q?Update=20fin=20s=C3=A9ance=2012/05/2014?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Commencement des travaux sur l'analyse des arguments * Ajout d'un Makefile pour Windows fonctionnel On verra pour la correction du code plus tard. --- Makefile.win | 37 ++++++++++++++++++++++ README.md | 2 +- src/analyserCommande.cpp | 68 +++++++++++++++++++++++++++++++++------- src/testing.cpp | 21 ++++--------- 4 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 Makefile.win diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 0000000..817070b --- /dev/null +++ b/Makefile.win @@ -0,0 +1,37 @@ +# Variables +## Pour make +.PHONY: clean, mrproper +## Compilation +CXX = g++ +CXXFLAGS = -lmingw32 -lSDLmain -lSDL -static-libgcc -static-libstdc++ +CXXFLAGSDEBUG = -lmingw32 -lSDLmain -lSDL -static-libgcc -static-libstdc++ -DDEBUG +## Chemins +EXEPATH = bin/ +OBJPATH = obj/ +SRCPATH = src/ + +# Programmes possibles +main: $(EXEPATH)main +testing: $(EXEPATH)testing + +# Éxecutables +$(EXEPATH)main: $(OBJPATH)main.o $(OBJPATH)image.o + $(CXX) $^ -o $@ $(CXXFLAGS) + +$(EXEPATH)testing: $(OBJPATH)testing.o $(OBJPATH)image.o + $(CXX) $^ -o $@ $(CXXFLAGSDEBU2) + +# Dépendances +## Fichiers executables +$(OBJPATH)main.o: $(SRCPATH)main.cpp $(SRCPATH)affichageFenetre.cpp $(SRCPATH)image.cpp $(SRCPATH)traitementImage.cpp $(SRCPATH)analyserCommande.cpp + $(CXX) -c $< -o $@ $(CXXFLAGS) + +$(OBJPATH)testing.o: $(SRCPATH)testing.cpp $(SRCPATH)affichageFenetre.cpp $(SRCPATH)image.cpp $(SRCPATH)traitementImage.cpp $(SRCPATH)analyserCommande.cpp + $(CXX) -c $< -o $@ $(CXXFLAGSDEBUG) +## Bibliothèques +$(OBJPATH)image.o: $(SRCPATH)image.cpp + $(CXX) -c $< -o $@ + +# Meta +clean: + rm -rf $(OBJPATH)*.o \ No newline at end of file diff --git a/README.md b/README.md index d29532d..9d874c3 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Téléchargement : ```git clone https://github.com/GeoffreyFrogeye/PILG.git``` 2. Inclure **MinGW** dans la variable d'environnement ```%PATH%``` : ```set path=%path%;C:\MinGW\bin``` 3. Télécharger la [bibliothèque de développement SDL 1.2.15](http://www.libsdl.org/release/SDL-devel-1.2.15-mingw32.tar.gz), copier le contenu des dossier *lib* et *include* de l'archive téléchargée dans le dossier de **MinGW** 4. Télécharger la [bibliothèque d’exécution de SDL 1.2.15](http://www.libsdl.org/release/SDL-1.2.15-win32.zip) et placer *SDL.dll* dans le dossier *bin* -5. Compiler : ```mingw32-make``` +5. Compiler : ```mingw32-make -f Makefile.win``` L’exécutable se trouvera dans le dossier *bin* diff --git a/src/analyserCommande.cpp b/src/analyserCommande.cpp index 9055a81..fc4aa20 100644 --- a/src/analyserCommande.cpp +++ b/src/analyserCommande.cpp @@ -2,8 +2,9 @@ #include #include -int chaineVersEntier(string chaine) { - return (int) chaine[0]; +int chaineVersEntier(string chaine, int &entier) { + entier = chaine[0]; + return 0; } void afficherImage(Image image) { @@ -117,14 +118,52 @@ int analyserDecoupe(Commande &commande, vector< string > decoupe, Image const &i // for (int i = 0; i < decoupe.size(); i++) { // DEBUG // cout << "Argument " << i << " = " << decoupe[i] << endl; // } - commande.couleur = image.g_pixelVide(); commande.fonction = decoupe[0]; - // Analyse des arguments - // for (int i = 1; i < decoupe.size(); i++) { - // ... - // } + // // Analyse des arguments + for (int i = 1; i < decoupe.size(); i++) { + if (decoupe[i].at(0) == '-') { + if (decoupe[i] == "-x1" || decoupe[i] == "-x0" || decoupe[i] == "-x") { + commande.argumentsPresents.push_back("x1"); + if (chaineVersEntier(decoupe[i+1], commande.x1)) { + return 3; + } + i++; + } else if (decoupe[i] == "-y1" || decoupe[i] == "-y0" || decoupe[i] == "-y") { + commande.argumentsPresents.push_back("y1"); + if (chaineVersEntier(decoupe[i+1], commande.y1)) { + return 3; + } + i++; + } else if (decoupe[i] == "-x2") { + commande.argumentsPresents.push_back("x2"); + if (chaineVersEntier(decoupe[i+1], commande.x2)) { + return 3; + } + i++; + } else if (decoupe[i] == "-y2") { + commande.argumentsPresents.push_back("y2"); + if (chaineVersEntier(decoupe[i+1], commande.y2)) { + return 3; + } + i++; + } else if (decoupe[i] == "-couleur" || decoupe[i] == "-c") { + commande.argumentsPresents.push_back("couleur"); + commande.couleur = image.g_pixelVide(); + // Analyser deuxième partie + i++; + } else { + return 2; + } + } else { + return 1; + } + } + + for (int i = 0; i < commande.argumentsPresents.size(); i++) { // DEBUG + cout << "Argument présent " << i << " = " << commande.argumentsPresents[i] << endl; + } return 0; } @@ -140,12 +179,10 @@ bool argumentPresent(Commande commande, string argumentVoulu) { int executerCommande(Commande commande, Image &image) { if (commande.fonction == "rectangle") { - commande.couleur.v = image.g_maxComposante(); // DEBUG - rectangle(image, image, 5, 5, 10, 10, commande.couleur); // DEBUG if (argumentPresent(commande, "x1") && argumentPresent(commande, "x2") && argumentPresent(commande, "y1") && argumentPresent(commande, "y2") && argumentPresent(commande, "couleur")) { - // TODO + rectangle(image, image, commande.x1, commande.y1, commande.x2, commande.y2, commande.couleur); } else { return 2; } @@ -172,8 +209,17 @@ void procederCommande(vector< string > decoupe, Image &image) { messageErreur("Impossible d'éxecuter la fonction"); } break; + case 1: + messageErreur("Argument inconnu"); + break; + case 2: + messageErreur("Argument inconnu"); + break; + case 3: + messageErreur("Impossible de comprendre un argument"); + break; default: - messageErreur("Impossible d'analyse de la commande"); + messageErreur("Impossible d'analyser la commande"); break; } } diff --git a/src/testing.cpp b/src/testing.cpp index 76f8ab9..62cc52a 100644 --- a/src/testing.cpp +++ b/src/testing.cpp @@ -106,27 +106,18 @@ int main(int argc, char *args[]) { cout << "PILG - Test" << endl; // Message d'entrée et de test - // // Analyse de commandes - // if (argc > 1) { - // vector< string > decoupe; - // for (int i = 1; i < argc; i++) { - // decoupe.push_back(args[i]); - // } - // analyserDecoupe(decoupe); - // } else { - // boucleDeCommandes(); - // } + Image image = genererRoue(256, 128, 255); #define DIMENSIONS 256 Image imageOriginale = genererRoue(DIMENSIONS, DIMENSIONS, 255); Image image = imageOriginale.g_vide(); - while(1) { - for (float i = 0; i < 2 * PI; i += 0.1) { - pivoter(imageOriginale, image, DIMENSIONS/2, DIMENSIONS/2, i); - afficherImage(image); - } + // while(1) { + for (float i = 0; i < 2 * PI; i += 0.1) { + pivoter(imageOriginale, image, DIMENSIONS/2, DIMENSIONS/2, i); + afficherImage(image); } + // } // // Neige en dégradé