Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4766 in orxonox.OLD for orxonox/trunk/src/orxonox.cc


Ignore:
Timestamp:
Jul 2, 2005, 11:54:41 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: cleaned up orxonox.cc a bit, and now one has the ability to choose the resolution in the GUI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/orxonox.cc

    r4756 r4766  
    4343#include "cd_engine.h"
    4444
     45#include "substring.h"
    4546#include "class_list.h"
    4647
     
    5960{
    6061  this->setClassID(CL_ORXONOX, "Orxonox");
    61   this->setName("orxonox");
     62  this->setName("orxonox-main");
    6263
    6364  this->resourceManager = NULL;
    6465  this->objectManager = NULL;
    6566  this->eventHandler = NULL;
     67  this->iniParser = NULL;
    6668
    6769  this->argc = 0;
     
    7476Orxonox::~Orxonox ()
    7577{
    76   int i = 0;
    77   Orxonox::singletonRef = NULL;
     78  delete this->iniParser;
     79
    7880  delete GraphicsEngine::getInstance(); // deleting the Graphics
    7981  delete TextEngine::getInstance();
     
    8486  delete EventHandler::getInstance();
    8587  delete Factory::getFirst();
     88  delete SoundEngine::getInstance();
    8689
    8790  ClassList::debug(0);
    88 }
    89 
    90 /** \brief this is a singleton class to prevent duplicates */
    91 Orxonox* Orxonox::singletonRef = 0;
    92 
    93 /**
    94    \returns reference or new Object of Orxonox if not existent.
    95 */
    96 Orxonox* Orxonox::getInstance ()
    97 {
    98   if (singletonRef == NULL)
    99     singletonRef = new Orxonox();
    100   return singletonRef;
    101 }
    102 
    103 /**
    104    \brief this finds the config file
    105 
    106    Since the config file varies from user to user and since one may want to specify different config files
    107    for certain occasions or platforms this function finds the right config file for every occasion and stores
    108    it's path and name into configfilename
    109 */
    110 void Orxonox::getConfigFile (int argc, char** argv)
    111 {
    112   strcpy (configfilename, "~/.orxonox/orxonox.conf");
     91
     92  PRINT(3)("===================================================\n" \
     93      "Thanks for playing orxonox.\n" \
     94      "visit: http://www.orxonox.ethz.ch for new versions.\n" \
     95      "===================================================\n");
     96
     97  Orxonox::singletonRef = NULL;
     98}
     99
     100/**
     101 * @brief this is a singleton class to prevent duplicates
     102 */
     103Orxonox* Orxonox::singletonRef = NULL;
     104
     105/**
     106 * @brief this finds the config file
     107 * @returns the new config-fileName
     108 * Since the config file varies from user to user and since one may want to specify different config files
     109 * for certain occasions or platforms this function finds the right config file for every occasion and stores
     110 * it's path and name into configfilename
     111*/
     112const char* Orxonox::getConfigFile (int argc, char** argv)
     113{
     114  strcpy (this->configFileName, DEFAULT_CONFIG_FILE);
     115  this->iniParser = new IniParser(this->configFileName);
    113116}
    114117
     
    123126  // config file
    124127
    125   getConfigFile (argc, argv);
     128  // initialize the Config-file
     129  this->getConfigFile(argc, argv);
     130
     131
    126132  SDL_Init (SDL_INIT_TIMER);
    127133  // initialize everything
    128   printf("> Initializing resources\n");
    129134  if( initResources () == -1) return -1;
    130 
    131135  if( initVideo() == -1) return -1;
    132136  if( initSound() == -1) return -1;
    133   PRINT(3)("> Initializing input\n");
    134137  if( initInput() == -1) return -1;
    135   PRINT(3)("> Initializing networking\n");
    136138  if( initNetworking () == -1) return -1;
    137139  //printf("> Initializing world\n");
     
    149151
    150152  GraphicsEngine::getInstance();
    151   GraphicsEngine::getInstance()->setWindowName("orxonox " PACKAGE_VERSION, "orxonox " PACKAGE_VERSION);
    152 
    153   return 0;
    154 }
    155 
     153  GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, PACKAGE_NAME " " PACKAGE_VERSION);
     154
     155
     156  SubString resolution(this->iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480"), 'x');
     157  GraphicsEngine::getInstance()->setResolution(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);
     158
     159//  const char* fullscreen = this->iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, 0);
     160//  GraphicsEngine::getInstance()->setFullscreen(false);
     161
     162  return 0;
     163}
    156164
    157165/**
     
    168176
    169177/**
    170    \brief initializes input functions
     178 * @brief initializes input functions
    171179*/
    172180int Orxonox::initInput()
    173181{
     182  PRINT(3)("> Initializing input\n");
     183
    174184  this->eventHandler = EventHandler::getInstance();
    175185  this->eventHandler->init();
     
    180190
    181191/**
    182    \brief initializes network system
     192* @brief initializes network system
    183193*/
    184194int Orxonox::initNetworking()
    185195{
    186   printf("Not yet implemented\n");
    187   return 0;
    188 }
    189 
    190 
    191 /**
    192    \brief initializes and loads resource files
    193 */
    194 int Orxonox::initResources()
    195 {
    196    PRINT(3)("initializing ResourceManager\n");
    197    resourceManager = ResourceManager::getInstance();
     196  PRINT(3)("> Initializing networking\n");
     197
     198  printf("  ---Not yet implemented-FIXME--\n");
     199  return 0;
     200}
     201
     202
     203/**
     204 * @brief initializes and loads resource files
     205 */
     206 int Orxonox::initResources()
     207{
     208  PRINTF(3)("> Initializing resources\n");
     209
     210  PRINT(3)("initializing ResourceManager\n");
     211  resourceManager = ResourceManager::getInstance();
    198212
    199213  // create parser
    200    IniParser parser (DEFAULT_CONFIG_FILE);
    201    if( parser.getSection (CONFIG_SECTION_DATA) == -1)
    202    {
    203      PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
    204      return -1;
    205    }
    206    char namebuf[256];
    207    char valuebuf[256];
    208    memset (namebuf, 0, 256);
    209    memset (valuebuf, 0, 256);
    210 
    211    while( parser.nextVar (namebuf, valuebuf) != -1)
    212    {
    213      if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
    214      {
     214  if( this->iniParser->getSection (CONFIG_SECTION_DATA) == -1)
     215  {
     216    PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
     217    return -1;
     218  }
     219  char namebuf[256];
     220  char valuebuf[256];
     221  memset (namebuf, 0, 256);
     222  memset (valuebuf, 0, 256);
     223
     224  while( this->iniParser->nextVar (namebuf, valuebuf) != -1)
     225  {
     226    if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
     227    {
    215228          //  printf("Not yet implemented\n");
    216        if (!resourceManager->setDataDir(valuebuf))
    217        {
    218          PRINTF(1)("Data Could not be located\n");
    219          exit(-1);
    220        }
    221      }
    222 
    223      memset (namebuf, 0, 256);
    224      memset (valuebuf, 0, 256);
    225    }
    226 
    227    if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
    228    {
    229      PRINTF(1)("The DataDirectory %s could not be verified\nPlease Change in File %s Section %s Entry %s to a suitable value\n",
    230      resourceManager->getDataDir(),
    231      DEFAULT_CONFIG_FILE,
    232      CONFIG_SECTION_DATA,
    233      CONFIG_NAME_DATADIR);
    234      exit(-1);
    235    }
     229      if (!resourceManager->setDataDir(valuebuf))
     230      {
     231        PRINTF(1)("Data Could not be located\n");
     232        exit(-1);
     233      }
     234    }
     235
     236    memset (namebuf, 0, 256);
     237    memset (valuebuf, 0, 256);
     238  }
     239
     240  if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     241  {
     242    PRINTF(1)("The DataDirectory %s could not be verified\n" \
     243              "  Please Change in File %s Section %s Entry %s to a suitable value\n",
     244              resourceManager->getDataDir(),
     245              DEFAULT_CONFIG_FILE,
     246              CONFIG_SECTION_DATA,
     247              CONFIG_NAME_DATADIR);
     248    exit(-1);
     249  }
    236250   //! \todo this is a hack and should be loadable
    237    resourceManager->addImageDir(ResourceManager::getInstance()->getFullName("maps/"));
    238    resourceManager->debug();
    239 
    240    PRINT(3)("initializing TextEngine\n");
    241    TextEngine::getInstance();
    242 
    243    PRINT(3)("initializing ObjectManager\n");
    244    this->objectManager = ObjectManager::getInstance();
    245 
    246    CDEngine::getInstance();
    247 
    248    return 0;
    249 }
    250 
    251 
    252 
     251  resourceManager->addImageDir(ResourceManager::getInstance()->getFullName("maps/"));
     252  resourceManager->debug();
     253
     254  PRINT(3)("initializing TextEngine\n");
     255  TextEngine::getInstance();
     256
     257  PRINT(3)("initializing ObjectManager\n");
     258  this->objectManager = ObjectManager::getInstance();
     259
     260  CDEngine::getInstance();
     261
     262  return 0;
     263}
    253264
    254265/**
     
    299310bool showGui = false;
    300311
     312
     313
     314/**********************************
     315*** ORXONOX MAIN STARTING POINT ***
     316**********************************/
    301317/**
    302318   \brief main function
     
    306322int main(int argc, char** argv)
    307323{
    308 
    309324  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
    310325  int i;
     
    337352
    338353
     354
     355/**
     356 * starts orxonox
     357 * @param argc parameters count given to orxonox
     358 * @param argv parameters given to orxonox
     359 */
    339360int startOrxonox(int argc, char** argv)
    340361{
    341362  // checking for existence of the configuration-files
    342363  if (showGui ||
    343       !ResourceManager::isFile("~/.orxonox/orxonox.conf") ||
    344       ResourceManager::isFile("~/.orxonox/orxonox.lock"))
    345     {
    346       if (ResourceManager::isFile("~/.orxonox/orxonox.lock"))
    347         ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
     364      !ResourceManager::isFile(DEFAULT_CONFIG_FILE) ||
     365      ResourceManager::isFile(DEFAULT_LOCK_FILE))
     366    {
     367      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
     368        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
    348369
    349370      // starting the GUI
     
    359380  PRINT(0)(">>> Starting Orxonox <<<\n");
    360381
    361   ResourceManager::touchFile("~/.orxonox/orxonox.lock");
     382  ResourceManager::touchFile(DEFAULT_LOCK_FILE);
    362383
    363384  Orxonox *orx = Orxonox::getInstance();
Note: See TracChangeset for help on using the changeset viewer.