IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

plusieurs programmes principaux


Sujet :

C++

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    504
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 504
    Par défaut plusieurs programmes principaux
    bonsoir,

    j'analyse le code source d'un jeu et je remarque qu'il y a plusieurs programmes principaux


    voici un bout de code du programme principal :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
     
     
    // Main top level initialization
    bool fgMainInit( int argc, char **argv ) {
     
        // set default log levels
        sglog().setLogLevels( SG_ALL, SG_ALERT );
     
        string version;
    #ifdef FLIGHTGEAR_VERSION
        version = FLIGHTGEAR_VERSION;
    #else
        version = "unknown version";
    #endif
        SG_LOG( SG_GENERAL, SG_INFO, "FlightGear:  Version "
                << version );
        SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
     
        // Allocate global data structures.  This needs to happen before
        // we parse command line options
     
        globals = new FGGlobals;
     
        // seed the random number generator
        sg_srandom_time();
     
        FGControls *controls = new FGControls;
        globals->set_controls( controls );
     
        string_list *col = new string_list;
        globals->set_channel_options_list( col );
     
        fgValidatePath("", false);  // initialize static variables
        upper_case_property("/sim/presets/airport-id");
        upper_case_property("/sim/presets/runway");
        upper_case_property("/sim/tower/airport-id");
        upper_case_property("/autopilot/route-manager/input");
     
        // Scan the config file(s) and command line options to see if
        // fg_root was specified (ignore all other options for now)
        fgInitFGRoot(argc, argv);
     
        // Check for the correct base package version
        static char required_version[] = "2.0.0";
        string base_version = fgBasePackageVersion();
        if ( !(base_version == required_version) ) {
            // tell the operator how to use this application
     
            SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on windows
            cerr << endl << "Base package check failed ... " \
                 << "Found version " << base_version << " at: " \
                 << globals->get_fg_root() << endl;
            cerr << "Please upgrade to version: " << required_version << endl;
    #ifdef _MSC_VER
            cerr << "Hit a key to continue..." << endl;
            cin.get();
    #endif
            exit(-1);
        }
     
        // Load the configuration parameters.  (Command line options
        // override config file options.  Config file options override
        // defaults.)
        if ( !fgInitConfig(argc, argv) ) {
            SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
            exit(-1);
        }
     
        // Initialize the Window/Graphics environment.
        fgOSInit(&argc, argv);
        _bootstrap_OSInit++;
     
        fgRegisterWindowResizeHandler( &FGRenderer::resize );
        fgRegisterIdleHandler( &fgIdleFunction );
        fgRegisterDrawHandler( &FGRenderer::update );
     
    #ifdef FG_ENABLE_MULTIPASS_CLOUDS
        bool get_stencil_buffer = true;
    #else
        bool get_stencil_buffer = false;
    #endif
     
        // Initialize plib net interface
        netInit( &argc, argv );
     
        // Clouds3D requires an alpha channel
        // clouds may require stencil buffer
        fgOSOpenWindow(get_stencil_buffer);
     
        // Initialize the splash screen right away
        fntInit();
        fgSplashInit();
     
        // pass control off to the master event handler
        fgOSMainLoop();
     
        // we never actually get here ... but to avoid compiler warnings,
        // etc.
        return false;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    bool fgMainInit( int argc, char **argv )
    fgInitFGRoot(argc, argv);
    fgOSInit(&argc, argv);
    netInit( &argc, argv );

    1)pourquoi créer plusieurs programmes principaux?



    2) qu'elle est l'importance des argc et des argv ?

    merci !

  2. #2
    Membre émérite
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2009
    Messages
    552
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mars 2009
    Messages : 552
    Par défaut
    Bonjour,

    Il n'y a pas plusieurs programme principaux. Il y a plusieurs fonction d'initialisation qui prennent les mêmes arguments que la fonction main (argc, argv).

    argc : Le nombre d'arguments
    argv : Le tableau des arguments

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    // Load the configuration parameters.  (Command line options
    // override config file options.  Config file options override
    // defaults.)
    => Ces fonctions interprètent les arguments passés en ligne de commande.

    Le fait de séparer ces initialisations dans différentes fonctions est une question de modularité du code, pour le rendre plus clair.

    En espérant t'avoir aider, bon vol !

Discussions similaires

  1. Exécuter plusieurs programmes Prolog automatiquement
    Par alexglvr dans le forum Prolog
    Réponses: 2
    Dernier message: 06/12/2008, 12h49
  2. l'execution de plusieurs programme
    Par homomorphisme dans le forum C#
    Réponses: 2
    Dernier message: 04/07/2008, 12h20
  3. Lancement plusieurs programmes dans un seul "programme"
    Par stansoad0108 dans le forum Langage
    Réponses: 3
    Dernier message: 23/06/2008, 10h58
  4. [Compiler] Compilation de plusieurs programmes
    Par Contractofoued dans le forum MATLAB
    Réponses: 2
    Dernier message: 20/12/2007, 16h16
  5. appelle de plusieurs programme
    Par vince2005 dans le forum Langage
    Réponses: 3
    Dernier message: 05/04/2006, 21h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo