Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 5, 2008, 9:50:26 PM (17 years ago)
Author:
rgrieder
Message:
  • getInstance is probably more suitable than getSingleton (as x3n has already done so in most of his classes) I changed it in Orxonox and GraphicsEngine. Maybe more to come.
  • Removed derivation from BaseObject in InputState (templates work well too, don't need a factory at all)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/orxonox/Orxonox.cc

    r1646 r1653  
    112112    , mode_(GameMode::GM_Unspecified)
    113113    , debugRefreshTime_(0.0f)
    114     , ogre_(0)
     114    , graphicsEngine_(0)
    115115    , inputManager_(0)
    116116    , radar_(0)
     
    157157      delete inputManager_;
    158158
    159     if (this->ogre_)
    160       delete ogre_;
     159    if (this->graphicsEngine_)
     160      delete graphicsEngine_;
    161161
    162162    if (network::Client::getSingleton())
     
    212212  }
    213213
    214 
    215   /**
    216    * Starts the whole Game.
    217    * @param path path to config (in home dir or something)
    218    */
    219   void Orxonox::start()
    220   {
    221 #ifdef _DEBUG
    222     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini");
     214    /**
     215    @brief
     216        Starts the whole Game.
     217    @param path
     218        path to config (in home dir or something)
     219    */
     220    void Orxonox::start()
     221    {
     222#if ORXONOX_DEBUG_MODE == 1
     223        ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini");
    223224#else
    224     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
     225        ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    225226#endif
    226     Factory::createClassHierarchy();
    227 
    228     setConfigValues();
    229 
    230     const Settings::CommandLineArgument* mode = Settings::getCommandLineArgument("mode");
    231     assert(mode);
    232     if (!mode->bHasDefaultValue_)
     227
     228        // creates the class hierarchy for all classes with factories
     229        Factory::createClassHierarchy();
     230
     231        setConfigValues();
     232
     233        const Settings::CommandLineArgument* mode = Settings::getCommandLineArgument("mode");
     234        assert(mode);
     235        if (!mode->bHasDefaultValue_)
     236        {
     237            Settings::setGameMode(mode->value_);
     238            this->mode_ = Settings::getGameMode();
     239        }
     240        COUT(3) << "Orxonox: Game mode is " << mode_.name << "." << std::endl;
     241
     242        const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath");
     243        assert(dataPath);
     244        if (!dataPath->bHasDefaultValue_)
     245        {
     246            if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\')
     247                Settings::tsetDataPath(dataPath->value_.getString() + "/");
     248            else
     249                Settings::tsetDataPath(dataPath->value_.getString());
     250        }
     251
     252        try
     253        {
     254            // initialise TCL
     255            TclBind::getInstance().setDataPath(Settings::getDataPath());
     256
     257            graphicsEngine_ = new GraphicsEngine();
     258            graphicsEngine_->setup();       // creates ogre root and other essentials
     259
     260            if (mode_.showsGraphics)
     261            {
     262                graphicsEngine_->loadRenderer();    // creates the render window
     263
     264                // TODO: Spread this so that this call only initialises things needed for the Console and GUI
     265                graphicsEngine_->initialiseResources();
     266
     267                // Calls the InputManager which sets up the input devices.
     268                // The render window width and height are used to set up the mouse movement.
     269                inputManager_ = new InputManager();
     270                inputManager_->initialise(graphicsEngine_->getWindowHandle(),
     271                    graphicsEngine_->getWindowWidth(), graphicsEngine_->getWindowHeight(), true, true, true);
     272                KeyBinder* keyBinder = new KeyBinder();
     273                keyBinder->loadBindings();
     274                inputManager_->createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder);
     275
     276                // Load the InGameConsole
     277                console_ = new InGameConsole();
     278                console_->initialise();
     279
     280                // load the CEGUI interface
     281                guiManager_ = new GUIManager();
     282                guiManager_->initialise();
     283            }
     284            else
     285            {
     286                // TODO: Initialise a not yet written console that operates in the shell we
     287                // started the game from.
     288                // We probably want to use std::cin to catch input (OIS uses DirectX or X server)
     289            }
     290
     291            bool showGUI = true;
     292            if (mode_.mode != GameMode::Unspecified)
     293            {
     294                showGUI = false;
     295                // a game mode was specified with the command line
     296                // we therefore load the game and level directly
     297
     298                if (!loadLevel(this->mode_))
     299                {
     300                    COUT(1) << "Loading with predefined mode failed. Showing main menu." << std::endl;
     301                    showGUI = true;
     302                    mode_ = GameMode::GM_Unspecified;
     303                }
     304            }
     305
     306            if (showGUI)
     307            {
     308                // show main menu
     309                GUIManager::getInstance().showGUI("MainMenu", 0);
     310                GraphicsEngine::getInstance().getViewport()->setCamera(GUIManager::getInstance().getCamera());
     311            }
     312        }
     313        catch (std::exception& ex)
     314        {
     315            COUT(1) << ex.what() << std::endl;
     316            COUT(1) << "Loading sequence aborted." << std::endl;
     317            return;
     318        }
     319
     320        modeRequest_ = mode_;
     321        // here happens the game
     322        startRenderLoop();
     323
     324        if (mode_.mode == GameMode::Client)
     325            network::Client::getSingleton()->closeConnection();
     326
     327        if (mode_.hasServer)
     328            server_g->close();
     329    }
     330
     331    /*static*/ void Orxonox::loadGame(const std::string& name)
    233332    {
    234       Settings::setGameMode(mode->value_);
    235       this->mode_ = Settings::getGameMode();
     333        const GameMode& mode = Settings::getGameMode(name);
     334        if (mode.mode == GameMode::None)
     335            return;
     336
     337        getSingleton().modeRequest_ = mode;
    236338    }
    237     COUT(3) << "Orxonox: Game mode is " << mode_.name << "." << std::endl;
    238 
    239     const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath");
    240     assert(dataPath);
    241     if (!dataPath->bHasDefaultValue_)
     339
     340    bool Orxonox::loadLevel(const GameMode& mode)
    242341    {
    243       if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\')
    244         Settings::tsetDataPath(dataPath->value_.getString() + "/");
    245       else
    246         Settings::tsetDataPath(dataPath->value_.getString());
     342        bool success = true;
     343
     344        if (mode.showsGraphics)
     345        {
     346            // create Ogre SceneManager for the level
     347            graphicsEngine_->createNewScene();
     348
     349            if (!loadPlayground())
     350                return false;
     351        }
     352
     353        switch (mode.mode)
     354        {
     355        case GameMode::Server:
     356            success &= serverLoad();
     357            break;
     358        case GameMode::Client:
     359            success &= clientLoad();
     360            break;
     361        case GameMode::Dedicated:
     362            success &= serverLoad();
     363            break;
     364        case GameMode::Standalone:
     365            success &= standaloneLoad();
     366            break;
     367        default: // never happens
     368            assert(false);
     369        }
     370
     371        if (success)
     372        {
     373            InputManager::getInstance().requestEnterState("game");
     374            this->mode_ = mode;
     375        }
     376
     377        return success;
    247378    }
    248 
    249     try
    250     {
    251         // initialise TCL
    252         TclBind::getInstance().setDataPath(Settings::getDataPath());
    253 
    254         ogre_ = new GraphicsEngine();
    255         ogre_->setup();       // creates ogre root and other essentials
    256 
    257         if (mode_.showsGraphics)
    258         {
    259           ogre_->loadRenderer();    // creates the render window
    260 
    261           // TODO: Spread this so that this call only initialises things needed for the Console and GUI
    262           ogre_->initialiseResources();
    263 
    264           // Calls the InputManager which sets up the input devices.
    265           // The render window width and height are used to set up the mouse movement.
    266           inputManager_ = new InputManager();
    267           inputManager_->initialise(ogre_->getWindowHandle(),
    268                 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true);
    269           KeyBinder* keyBinder = new KeyBinder();
    270           keyBinder->loadBindings();
    271           inputManager_->createSimpleInputState("game", 20)->setHandler(keyBinder);
    272 
    273           // Load the InGameConsole
    274           console_ = new InGameConsole();
    275           console_->initialise();
    276 
    277           // load the CEGUI interface
    278           guiManager_ = new GUIManager();
    279           guiManager_->initialise();
    280         }
    281 
    282         bool showGUI = true;
    283         if (mode_.mode != GameMode::Unspecified)
    284         {
    285           showGUI = false;
    286           // a game mode was specified with the command line
    287           // we therefore load the game and level directly
    288 
    289           if (!loadLevel(this->mode_))
    290           {
    291             COUT(1) << "Loading with predefined mode failed. Showing main menu." << std::endl;
    292             showGUI = true;
    293             mode_ = GameMode::GM_Unspecified;
    294           }
    295         }
    296        
    297         if (showGUI)
    298         {
    299           // show main menu
    300           GUIManager::getInstance().showGUI("MainMenu", 0);
    301           GraphicsEngine::getSingleton().getViewport()->setCamera(GUIManager::getInstance().getCamera());
    302         }
    303     }
    304     catch (std::exception& ex)
    305     {
    306       COUT(1) << ex.what() << std::endl;
    307       COUT(1) << "Loading sequence aborted." << std::endl;
    308       return;
    309     }
    310 
    311     modeRequest_ = mode_;
    312     // here happens the game
    313     startRenderLoop();
    314 
    315     if (mode_.mode == GameMode::Client)
    316       network::Client::getSingleton()->closeConnection();
    317 
    318     if (mode_.hasServer)
    319       server_g->close();
    320   }
    321 
    322   /*static*/ void Orxonox::loadGame(const std::string& name)
    323   {
    324       const GameMode& mode = Settings::getGameMode(name);
    325       if (mode.mode == GameMode::None)
    326           return;
    327 
    328       getSingleton().modeRequest_ = mode;
    329   }
    330 
    331   bool Orxonox::loadLevel(const GameMode& mode)
    332   {
    333       bool success = true;
    334 
    335       if (mode.showsGraphics)
    336       {
    337         // create Ogre SceneManager for the level
    338         ogre_->createNewScene();
    339 
    340         if (!loadPlayground())
    341             return false;
    342       }
    343 
    344       switch (mode.mode)
    345       {
    346       case GameMode::Server:
    347         success &= serverLoad();
    348         break;
    349       case GameMode::Client:
    350         success &= clientLoad();
    351         break;
    352       case GameMode::Dedicated:
    353         success &= serverLoad();
    354         break;
    355       case GameMode::Standalone:
    356         success &= standaloneLoad();
    357         break;
    358       default: // never happens
    359           assert(false);
    360       }
    361      
    362       if (success)
    363       {
    364         InputManager::getInstance().requestEnterState("game");
    365         this->mode_ = mode;
    366       }
    367 
    368       return success;
    369   }
    370379
    371380  /**
     
    528537        if (timeAfterTick > refreshStartTime + refreshTime)
    529538        {
    530           GraphicsEngine::getSingleton().setAverageTickTime(
     539          GraphicsEngine::getInstance().setAverageTickTime(
    531540              (float)tickTime * 0.001 / (frameCount - oldFrameCount));
    532541          float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
    533           GraphicsEngine::getSingleton().setAverageFramesPerSecond(avgFPS);
     542          GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
    534543
    535544          oldFrameCount = frameCount;
     
    552561          // make sure the window stays active even when not focused
    553562          // (probably only necessary on windows)
    554           GraphicsEngine::getSingleton().setWindowActivity(true);
     563          GraphicsEngine::getInstance().setWindowActivity(true);
    555564
    556565          // tick CEGUI
Note: See TracChangeset for help on using the changeset viewer.