Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (16 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/core/Core.cc

    r2171 r2485  
    4646    bool Core::bIsMaster_s      = false;
    4747
     48    Core* Core::singletonRef_s = 0;
     49
    4850    /**
    4951        @brief Constructor: Registers the object and sets the config-values.
     
    5355    {
    5456        RegisterRootObject(Core);
     57
     58        assert(Core::singletonRef_s == 0);
     59        Core::singletonRef_s = this;
     60        this->bInitializeRandomNumberGenerator_ = false;
     61
    5562        this->setConfigValues();
    56         isCreatingCoreSettings() = false;
    5763    }
    5864
     
    6268    Core::~Core()
    6369    {
    64         isCreatingCoreSettings() = true;
    65     }
    66 
    67     /**
    68         @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value.
    69     */
    70     bool& Core::isCreatingCoreSettings()
    71     {
    72         static bool bCreatingCoreSettings = true;
    73         return bCreatingCoreSettings;
    74     }
    75 
    76     /**
    77         @brief Returns a unique instance of Core.
    78         @return The instance
    79     */
    80     Core& Core::getInstance()
    81     {
    82         // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
    83         //if (Core::isCreatingCoreSettings())
    84         //{
    85         //    isCreatingCoreSettings() = false;
    86         //    //instance.setConfigValues();
    87         //}
    88 
    89         static bool firstTime = true;
    90         if (firstTime)
    91             isCreatingCoreSettings() = true;
    92 
    93         static Core instance;
    94         return instance;
     70        assert(Core::singletonRef_s);
     71        Core::singletonRef_s = 0;
    9572    }
    9673
     
    10481        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
    10582        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
     83        SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator);
    10684    }
    10785
     
    140118    int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
    141119    {
    142         if (!Core::isCreatingCoreSettings())
     120        switch (device)
    143121        {
    144             switch (device)
    145             {
    146             case OutputHandler::LD_All:
    147                 return Core::getInstance().softDebugLevel_;
    148             case OutputHandler::LD_Console:
    149                 return Core::getInstance().softDebugLevelConsole_;
    150             case OutputHandler::LD_Logfile:
    151                 return Core::getInstance().softDebugLevelLogfile_;
    152             case OutputHandler::LD_Shell:
    153                 return Core::getInstance().softDebugLevelShell_;
    154             default:
    155                 assert(0);
    156             }
     122        case OutputHandler::LD_All:
     123            return Core::getInstance().softDebugLevel_;
     124        case OutputHandler::LD_Console:
     125            return Core::getInstance().softDebugLevelConsole_;
     126        case OutputHandler::LD_Logfile:
     127            return Core::getInstance().softDebugLevelLogfile_;
     128        case OutputHandler::LD_Shell:
     129            return Core::getInstance().softDebugLevelShell_;
     130        default:
     131            assert(0);
     132            return 2;
    157133        }
    158 
    159         // Return a constant value while we're creating the object
    160         return 2;
    161134    }
    162135
     
    168141     void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
    169142     {
    170         if (!Core::isCreatingCoreSettings())
    171         {
    172             if (device == OutputHandler::LD_All)
    173                 Core::getInstance().softDebugLevel_ = level;
    174             else if (device == OutputHandler::LD_Console)
    175                 Core::getInstance().softDebugLevelConsole_ = level;
    176             else if (device == OutputHandler::LD_Logfile)
    177                 Core::getInstance().softDebugLevelLogfile_ = level;
    178             else if (device == OutputHandler::LD_Shell)
    179                 Core::getInstance().softDebugLevelShell_ = level;
     143        if (device == OutputHandler::LD_All)
     144            Core::getInstance().softDebugLevel_ = level;
     145        else if (device == OutputHandler::LD_Console)
     146            Core::getInstance().softDebugLevelConsole_ = level;
     147        else if (device == OutputHandler::LD_Logfile)
     148            Core::getInstance().softDebugLevelLogfile_ = level;
     149        else if (device == OutputHandler::LD_Shell)
     150            Core::getInstance().softDebugLevelShell_ = level;
    180151
    181             OutputHandler::setSoftDebugLevel(device, level);
    182         }
     152        OutputHandler::setSoftDebugLevel(device, level);
    183153     }
    184154
     
    188158    const std::string& Core::getLanguage()
    189159    {
    190         if (!Core::isCreatingCoreSettings())
    191             return Core::getInstance().language_;
    192 
    193         return Language::getLanguage().defaultLanguage_;
     160        return Core::getInstance().language_;
    194161    }
    195162
     
    209176        ResetConfigValue(language_);
    210177    }
     178
     179    void Core::initializeRandomNumberGenerator()
     180    {
     181        static bool bInitialized = false;
     182        if (!bInitialized && this->bInitializeRandomNumberGenerator_)
     183        {
     184            srand(time(0));
     185            rand();
     186            bInitialized = true;
     187        }
     188    }
    211189}
Note: See TracChangeset for help on using the changeset viewer.