Skip to content

Latest commit

 

History

History
208 lines (145 loc) · 4.21 KB

coaching_07.org

File metadata and controls

208 lines (145 loc) · 4.21 KB

G.Tech 1 – Projet#7 – C++ sous Linux / Git

Évaluation Git & Bash

Git

Vocabulaire

  • “Dépôt”
    1. Dépôt nu
    2. Dépôt avec copie de travail
  • “Working tree” / “Copie de travail” / “Dossier de travail”
  • “Index”
  • “Commit”
  • “Log”
  • “Diff”
  • “Remote”

Commandes initiales

  • git init NOUVEAU_DOSSIER
  • git clone URL NOUVEAU_DOSSIER

Commandes récurrentes locales

  • git add FICHIER
  • git commit
  • git commit FICHIER
  • git status -s
  • git diff
  • git diff --cached
  • git diff FICHIER
  • git diff --cached FICHIER
  • git log
  • git log FICHIER

Commandes pour intéregir avec d’autres dépôts

  • git push
  • git pull
  • git pull REMOTE BRANCH

Bash

  • Comprendre et maîtriser les commandes de base (et leurs options):
    • pwd
    • cd et son option -
    • ls et ses options -l et -a=
    • mkdir
    • rmdir
    • rm
    • cat
    • echo
  • Comprendre la signification des éléments de contruction des chemins vers fichiers et dossiers:
    • / en début de chemin
    • / ailleurs dans un chemin
    • ~
    • . ou ./
    • .. ou ../
    • *
  • Et leurs usages couplés tels que:
    • cd ~ ou cd
    • cd ../
    • cd -
    • mkdir dossier
    • cd dossier/
    • mkdir dossier && cd dossier/
    • rmdir dossier/
    • rm -r dossier/
    • ls
    • ls -l
    • ls -a
    • ls -al
    • ls ~
    • ls ../
    • ls ../dossier/
    • ls *.cpp
  • L’utilité de la touche TAB dans le Shell

Librairie SDL2: Frame rate et évènements clavier

Notion de “Frame rate”

Le frame rate est la vitesse, ou le taux, de rafraîchissement de l’écran d’un jeu.

Il s’exprime soit

  • en Hz: par exemple 50Hz pour 50 images par secondes
  • en ms (millisecondes): par exemple 20ms (= 1/50Hz)

Contrôle du Frame Rate dans une boucle de jeu

Principe

#include <SDL2/SDL.h>

... func(int frame_rate_ms, ...) {

  int frame_delay;
  Uint32 frame_start;

  // Start the main game loop:
  do {
    // Begin of current frame:
    frame_start = SDL_GetTicks();

    // Check for pressed keyboard keys:
    ...

    // Next iteration of the game:
    ...

    // Render the game:
    ...

    // Compute elapsed time since the begin of current frame:
    frame_delay = frame_rate_ms - (SDL_GetTicks() - frame_start);

    // Wait for some time in order to stabilise frame rate to ~20ms:
    if (frame_delay > 0)
      SDL_Delay(frame_delay);

  } while (...);
  ...
}

Vitesse de déplacement du Snake = “Nb frames / case”

#include <SDL2/SDL.h>

... func(int frame_rate_ms, int snake_speed_fpc, ...) {

  int frame_delay;
  Uint32 frame_start;

  // Start the main game loop:
  Uint32 iter = 0;
  do {
    // Begin of current frame:
    frame_start = SDL_GetTicks();

    // Check for pressed keyboard keys:  <--- IMPORTANT: Le clavier est toujours "lu" à 50Hz!
    ...

    // Make the game to evolve / snake to move, only every =snake_speed_fpc= frames:
    if (iter % snake_speed_fpc == 0) {
      // Next iteration of the game:
      ...
    }

    // Render the game:
    this->Draw();

    // Compute elapsed time since the begin of current frame:
    frame_delay = frame_rate_ms - (SDL_GetTicks() - frame_start);

    // Wait for some time in order to stabilise frame rate to ~20ms:
    if (frame_delay > 0)
      SDL_Delay(frame_delay);

    // Print a warning if the game is too slow with respect to the frame rate:
    if (frame_delay > frame_rate_ms)
      printf("WARNING: frame rate drop: %d ms\n", frame_delay - frame_rate_ms);

    // Check for Quit event:
    SDL_PollEvent(&event);
    iter++;
  } while (!(event.type == SDL_QUIT));
  ...
}

Valeurs typiques pour un premier test

Par exemple chez moi:

  • frame_rate_ms = 20
  • snake_speed_fpc = 7 (le jeu évolue toutes les 7 frames)

Outils de génération automatisé du diagrame UML des classes

Cf. howto-uml-setup.org.